Skip to content

Commit

Permalink
fix: plugin detail view show incorrect
Browse files Browse the repository at this point in the history
Log:
Change-Id: I8f9e36795800fe320ea30b1c05eec861fe26d97a
  • Loading branch information
deepin-mozart committed Jun 5, 2024
1 parent 0953afb commit a5e1665
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/plugins/core/gui/plugindetailsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <QWebEngineSettings>
#endif
#include <QDir>
#include <QScreen>
#include <QGuiApplication>

DWIDGET_USE_NAMESPACE
using namespace dpfservice;
Expand All @@ -29,33 +31,35 @@ using namespace dpfservice;
class AutoZoomWebEngineView : public QWebEngineView {
public:
explicit AutoZoomWebEngineView(QWidget *parent = nullptr)
: QWebEngineView(parent) {
page()->settings()->setAttribute(QWebEngineSettings::ShowScrollBars, false);
connect(page(), &QWebEnginePage::loadFinished, [this](bool ok) {
if (ok) {
page()->runJavaScript("document.body.scrollWidth", [this](const QVariant &widthResult) {
pageWidth = widthResult.toInt();
});
}
}
);
}
: QWebEngineView(parent)
{
page()->settings()->setAttribute(QWebEngineSettings::ShowScrollBars, false);
}

protected:
void resizeEvent(QResizeEvent *event) override {
QWebEngineView::resizeEvent(event);

QSize newSize = event->size();
qreal zoomFactor = calculateZoomFactor(newSize);
int pageWidth = static_cast<int>(QGuiApplication::primaryScreen()->size().width() * webPageWidthScale);

qreal zoomFactor = calculateZoomFactor(event->size(), pageWidth);
setZoomFactor(zoomFactor);
}

qreal calculateZoomFactor(const QSize &size) {
qreal calculateZoomFactor(const QSize &size, int pageWidth)
{
if (pageWidth == 0)
return 1;

qreal zoomFactor = static_cast<qreal>(size.width()) / pageWidth;
if (zoomFactor > 1) {
zoomFactor = 1;
}
return zoomFactor;
}

private:
int pageWidth = 0;
qreal webPageWidthScale = 0.8;
};
#endif

Expand Down

0 comments on commit a5e1665

Please sign in to comment.