Skip to content

Commit

Permalink
feat(browser): make zoom scaling DPI aware (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
yiding authored and trollixx committed Mar 13, 2019
1 parent 4bfa75a commit b106938
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/libs/browser/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ WebView::WebView(QWidget *parent)
: QWebView(parent)
{
page()->setNetworkAccessManager(Core::Application::instance()->networkManager());
// Applies any DPI based scaling.
setZoomLevel(defaultZoomLevel());
}

int WebView::zoomLevel() const
Expand All @@ -60,7 +62,10 @@ void WebView::setZoomLevel(int level)

m_zoomLevel = level;

setZoomFactor(availableZoomLevels().at(level) / 100.0);
// Scale the webview relative to the DPI of the screen.
const float dpiZoomFactor = logicalDpiY() / 96.0;

setZoomFactor(availableZoomLevels().at(level) / 100.0 * dpiZoomFactor);
emit zoomLevelChanged();
}

Expand All @@ -72,7 +77,7 @@ const QVector<int> &WebView::availableZoomLevels()
return zoomLevels;
}

const int &WebView::defaultZoomLevel()
int WebView::defaultZoomLevel()
{
static const int level = availableZoomLevels().indexOf(100);
return level;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/browser/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WebView final : public QWebView
void setZoomLevel(int level);

static const QVector<int> &availableZoomLevels();
static const int &defaultZoomLevel();
static int defaultZoomLevel();

public slots:
void zoomIn();
Expand All @@ -66,7 +66,7 @@ public slots:

QMenu *m_contextMenu = nullptr;
QUrl m_clickedLink;
int m_zoomLevel = defaultZoomLevel();
int m_zoomLevel = 0;
};

} // namespace Browser
Expand Down

0 comments on commit b106938

Please sign in to comment.