From 97dd8c43ccd739ad079c26d1c0630cb08d2ce7cd Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 28 Mar 2017 23:15:58 +0800 Subject: [PATCH] add config web_zoom_factor in vnote.ini When it is set to -1, VNote will calculate the zoom factor according to DPI. This fix is for the hidpi issue on Windows. It is not widely tested on macOS. --- src/resources/vnote.ini | 2 ++ src/utils/vutils.cpp | 11 +++++++++++ src/utils/vutils.h | 1 + src/vconfigmanager.cpp | 7 +++++++ src/vconfigmanager.h | 19 +++++++++++++++++++ src/vedittab.cpp | 1 + 6 files changed, 41 insertions(+) diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index 3590d42d..3383423f 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -15,6 +15,8 @@ editor_font_size=12 markdown_converter=2 enable_mermaid=false enable_mathjax=false +; -1 - calculate the factor +web_zoom_factor=-1 [session] tools_dock_checked=true diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 81d0b09b..6bfcf3be 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -12,6 +12,7 @@ #include #include #include +#include const QVector> VUtils::c_availableLanguages = {QPair("en_US", "Englisth(US)"), QPair("zh_CN", "Chinese")}; @@ -342,3 +343,13 @@ bool VUtils::isImageURLText(const QString &p_url) return QImageReader::supportedImageFormats().contains(info.suffix().toLower().toLatin1()); } +qreal VUtils::calculateScaleFactor() +{ + // const qreal refHeight = 1152; + // const qreal refWidth = 2048; + const qreal refDpi = 96; + + qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch(); + qreal factor = dpi / refDpi; + return factor < 1 ? 1 : factor; +} diff --git a/src/utils/vutils.h b/src/utils/vutils.h index c6b8681a..fade0985 100644 --- a/src/utils/vutils.h +++ b/src/utils/vutils.h @@ -42,6 +42,7 @@ public: static bool isValidLanguage(const QString &p_lang); static bool isImageURL(const QUrl &p_url); static bool isImageURLText(const QString &p_url); + static qreal calculateScaleFactor(); private: // diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 13eaf33e..c04c2129 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -87,6 +87,13 @@ void VConfigManager::initialize() m_enableMermaid = getConfigFromSettings("global", "enable_mermaid").toBool(); m_enableMathjax = getConfigFromSettings("global", "enable_mathjax").toBool(); + + m_webZoomFactor = getConfigFromSettings("global", "web_zoom_factor").toReal(); + if (m_webZoomFactor < 0) { + // Calculate the zoom factor based on DPI. + m_webZoomFactor = VUtils::calculateScaleFactor(); + qDebug() << "set WebZoomFactor to" << m_webZoomFactor; + } } void VConfigManager::readPredefinedColorsFromSettings() diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index 60e5ec2d..609f15d8 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -123,6 +123,9 @@ public: inline bool getEnableMathjax() const; inline void setEnableMathjax(bool p_enabled); + inline qreal getWebZoomFactor() const; + inline void setWebZoomFactor(qreal p_factor); + private: void updateMarkdownEditStyle(); QVariant getConfigFromSettings(const QString §ion, const QString &key); @@ -187,6 +190,9 @@ private: // Enable Mathjax. bool m_enableMathjax; + // Zoom factor of the QWebEngineView. + qreal m_webZoomFactor; + // The name of the config file in each directory static const QString dirConfigFileName; // The name of the default configuration file @@ -532,4 +538,17 @@ inline void VConfigManager::setEnableMathjax(bool p_enabled) setConfigToSettings("global", "enable_mathjax", m_enableMathjax); } +inline qreal VConfigManager::getWebZoomFactor() const +{ + return m_webZoomFactor; +} + +inline void VConfigManager::setWebZoomFactor(qreal p_factor) +{ + if (m_webZoomFactor == p_factor) { + return; + } + m_webZoomFactor = p_factor; + setConfigToSettings("global", "web_zoom_factor", m_webZoomFactor); +} #endif // VCONFIGMANAGER_H diff --git a/src/vedittab.cpp b/src/vedittab.cpp index 97ccc2fa..8f08cf07 100644 --- a/src/vedittab.cpp +++ b/src/vedittab.cpp @@ -265,6 +265,7 @@ void VEditTab::setupMarkdownPreview() webPreviewer = new QWebEngineView(this); VPreviewPage *page = new VPreviewPage(this); webPreviewer->setPage(page); + webPreviewer->setZoomFactor(vconfig.getWebZoomFactor()); QWebChannel *channel = new QWebChannel(this); channel->registerObject(QStringLiteral("content"), &document);