Skip to content

Commit

Permalink
Apply additional zoom to the webview based on screen DPI.
Browse files Browse the repository at this point in the history
Also change `defaultZoomLevel()`'s `const int &` return type to just `int`.

Test Plan:
On Linux:
In KDE, forced DPI to 96 and 120. Restarting the app shows initial
webview scaled to 1x and 1.25x respectively.
In Gnome 3, use Tweaks to set font scaling to 1.25, restart the app.
  • Loading branch information
yiding committed Feb 14, 2019
1 parent 4fd2723 commit 0a7bd9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/libs/browser/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
using namespace Zeal::Browser;

WebView::WebView(QWidget *parent)
: QWebView(parent)
: QWebView(parent), m_zoomLevel(0)
{
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.
qreal 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 @@ -41,7 +41,7 @@ class WebView : public QWebView
void setZoomLevel(int level);

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

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

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

} // namespace Browser
Expand Down

0 comments on commit 0a7bd9f

Please sign in to comment.