Browse Source

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.
Le Tan 8 years ago
parent
commit
97dd8c43cc
6 changed files with 41 additions and 0 deletions
  1. 2 0
      src/resources/vnote.ini
  2. 11 0
      src/utils/vutils.cpp
  3. 1 0
      src/utils/vutils.h
  4. 7 0
      src/vconfigmanager.cpp
  5. 19 0
      src/vconfigmanager.h
  6. 1 0
      src/vedittab.cpp

+ 2 - 0
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

+ 11 - 0
src/utils/vutils.cpp

@@ -12,6 +12,7 @@
 #include <QFileInfo>
 #include <QImageReader>
 #include <QKeyEvent>
+#include <QScreen>
 
 const QVector<QPair<QString, QString>> VUtils::c_availableLanguages = {QPair<QString, QString>("en_US", "Englisth(US)"),
                                                                        QPair<QString, QString>("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;
+}

+ 1 - 0
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:
     // <value, name>

+ 7 - 0
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()

+ 19 - 0
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 &section, 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

+ 1 - 0
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);