Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default zoom of webview based on DPI. #1080

Merged
merged 2 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
yiding marked this conversation as resolved.
Show resolved Hide resolved

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