diff --git a/src/plugins/core/gui/plugindetailsview.cpp b/src/plugins/core/gui/plugindetailsview.cpp index dbab32cc8..9f0a16d7f 100644 --- a/src/plugins/core/gui/plugindetailsview.cpp +++ b/src/plugins/core/gui/plugindetailsview.cpp @@ -18,10 +18,43 @@ #include #include #include +#include +#include DWIDGET_USE_NAMESPACE using namespace dpfservice; +class AutoZoomWebEngineView : public QWebEngineView { +public: + explicit AutoZoomWebEngineView(QWidget *parent = nullptr) + : QWebEngineView(parent) {} + +protected: + void resizeEvent(QResizeEvent *event) override { + QWebEngineView::resizeEvent(event); + + // first resize is full screen + if (isFirstResize) { + isFirstResize = false; + return; + } + + QSize newSize = event->size(); + qreal zoomFactor = calculateZoomFactor(newSize); + setZoomFactor(zoomFactor); + } + + qreal calculateZoomFactor(const QSize &size) { + if (size.width() > maxWidth) + maxWidth = size.width(); + qreal zoomFactor = static_cast(size.width()) / maxWidth; + return zoomFactor; + } +private: + int maxWidth = 0; + bool isFirstResize = true; +}; + DetailsView::DetailsView(QWidget *parent) : DWidget(parent) { @@ -135,7 +168,7 @@ void DetailsView::setupUi() logoLabel->setPixmap(logo.pixmap(QSize(96, 96))); auto webViewLayout = new QHBoxLayout(); - webView = new QWebEngineView(this); + webView = new AutoZoomWebEngineView(this); webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); webViewLayout->addWidget(webView); diff --git a/src/plugins/core/gui/plugindetailsview.h b/src/plugins/core/gui/plugindetailsview.h index f0ed50c13..3e7aedb9d 100644 --- a/src/plugins/core/gui/plugindetailsview.h +++ b/src/plugins/core/gui/plugindetailsview.h @@ -14,7 +14,6 @@ QT_BEGIN_NAMESPACE class QGridLayout; class QVBoxLayout; class QSpacerItem; -class QWebEngineView; class QLabel; QT_END_NAMESPACE @@ -22,6 +21,8 @@ DWIDGET_BEGIN_NAMESPACE class DTextEdit; class DLabel; DWIDGET_END_NAMESPACE + +class AutoZoomWebEngineView; class DetailsView : public DTK_WIDGET_NAMESPACE::DWidget { Q_OBJECT @@ -50,7 +51,7 @@ private slots: DTK_WIDGET_NAMESPACE::DPushButton *loadBtn {nullptr}; dpf::PluginMetaObjectPointer pluginMetaInfo; - QWebEngineView *webView {nullptr}; + AutoZoomWebEngineView *webView {nullptr}; QLabel *logoLabel {nullptr}; };