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.
This commit is contained in:
Le Tan 2017-03-28 23:15:58 +08:00
parent 485723d7a9
commit 97dd8c43cc
6 changed files with 41 additions and 0 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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>

View File

@ -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()

View File

@ -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

View File

@ -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);