Browse Source

WebView: do not set background color to transparent

Setting background color of a web engine page to transparent will force
it to render using grayscale antialiasing.
Le Tan 7 years ago
parent
commit
2a7a4f864e

+ 1 - 1
src/dialog/vcopytextashtmldialog.cpp

@@ -31,7 +31,7 @@ void VCopyTextAsHtmlDialog::setupUI()
     m_textEdit->setProperty("LineEdit", true);
     m_textEdit->setProperty("LineEdit", true);
 
 
     m_htmlLabel = new QLabel(tr("HTML:"));
     m_htmlLabel = new QLabel(tr("HTML:"));
-    m_htmlViewer = VUtils::getWebEngineView();
+    m_htmlViewer = VUtils::getWebEngineView(g_config->getBaseBackground());
     m_htmlViewer->setContextMenuPolicy(Qt::NoContextMenu);
     m_htmlViewer->setContextMenuPolicy(Qt::NoContextMenu);
     m_htmlViewer->setMinimumSize(600, 400);
     m_htmlViewer->setMinimumSize(600, 400);
 
 

+ 1 - 1
src/dialog/vtipsdialog.cpp

@@ -23,7 +23,7 @@ VTipsDialog::VTipsDialog(const QString &p_tipFile,
 
 
 void VTipsDialog::setupUI(const QString &p_actionText)
 void VTipsDialog::setupUI(const QString &p_actionText)
 {
 {
-    m_viewer = VUtils::getWebEngineView();
+    m_viewer = VUtils::getWebEngineView(g_config->getBaseBackground());
     m_viewer->setContextMenuPolicy(Qt::NoContextMenu);
     m_viewer->setContextMenuPolicy(Qt::NoContextMenu);
 
 
     m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok);
     m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok);

+ 1 - 1
src/dialog/vupdater.cpp

@@ -35,7 +35,7 @@ void VUpdater::setupUI()
     m_proBar = new QProgressBar();
     m_proBar = new QProgressBar();
     m_proBar->setTextVisible(false);
     m_proBar->setTextVisible(false);
 
 
-    m_descriptionWV = VUtils::getWebEngineView();
+    m_descriptionWV = VUtils::getWebEngineView(g_config->getBaseBackground());
     m_descriptionWV->setContextMenuPolicy(Qt::NoContextMenu);
     m_descriptionWV->setContextMenuPolicy(Qt::NoContextMenu);
     m_descriptionWV->setHtml(VUtils::generateSimpleHtmlTemplate(VNote::s_sloganTemplate),
     m_descriptionWV->setHtml(VUtils::generateSimpleHtmlTemplate(VNote::s_sloganTemplate),
                              QUrl("qrc:/resources"));
                              QUrl("qrc:/resources"));

+ 2 - 0
src/main.cpp

@@ -234,6 +234,8 @@ int main(int argc, char *argv[])
 
 
     w.show();
     w.show();
 
 
+    g_config->setBaseBackground(w.palette().color(QPalette::Window));
+
     w.kickOffStartUpTimer(filePaths);
     w.kickOffStartUpTimer(filePaths);
 
 
     int ret = app.exec();
     int ret = app.exec();

+ 7 - 2
src/utils/vutils.cpp

@@ -1417,11 +1417,16 @@ void VUtils::setDynamicProperty(QWidget *p_widget, const char *p_prop, bool p_va
     p_widget->style()->polish(p_widget);
     p_widget->style()->polish(p_widget);
 }
 }
 
 
-QWebEngineView *VUtils::getWebEngineView(QWidget *p_parent)
+QWebEngineView *VUtils::getWebEngineView(const QColor &p_background, QWidget *p_parent)
 {
 {
     QWebEngineView *viewer = new QWebEngineView(p_parent);
     QWebEngineView *viewer = new QWebEngineView(p_parent);
     VPreviewPage *page = new VPreviewPage(viewer);
     VPreviewPage *page = new VPreviewPage(viewer);
-    page->setBackgroundColor(Qt::transparent);
+
+    // Setting the background to Qt::transparent will force GrayScale antialiasing.
+    if (p_background.isValid() && p_background != Qt::transparent) {
+        page->setBackgroundColor(p_background);
+    }
+
     viewer->setPage(page);
     viewer->setPage(page);
     viewer->setZoomFactor(g_config->getWebZoomFactor());
     viewer->setZoomFactor(g_config->getWebZoomFactor());
 
 

+ 1 - 1
src/utils/vutils.h

@@ -314,7 +314,7 @@ public:
     // Create and return a QComboBox.
     // Create and return a QComboBox.
     static QComboBox *getComboBox(QWidget *p_parent = nullptr);
     static QComboBox *getComboBox(QWidget *p_parent = nullptr);
 
 
-    static QWebEngineView *getWebEngineView(QWidget *p_parent = nullptr);
+    static QWebEngineView *getWebEngineView(const QColor &p_background, QWidget *p_parent = nullptr);
 
 
     static void setDynamicProperty(QWidget *p_widget, const char *p_prop, bool p_val = true);
     static void setDynamicProperty(QWidget *p_widget, const char *p_prop, bool p_val = true);
 
 

+ 16 - 0
src/vconfigmanager.h

@@ -584,6 +584,9 @@ public:
 
 
     bool versionChanged() const;
     bool versionChanged() const;
 
 
+    const QColor &getBaseBackground() const;
+    void setBaseBackground(const QColor &p_bg);
+
 private:
 private:
     // Look up a config from user and default settings.
     // Look up a config from user and default settings.
     QVariant getConfigFromSettings(const QString &section, const QString &key) const;
     QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@@ -1044,6 +1047,9 @@ private:
     // Whether the VNote instance has different version of vnote.ini.
     // Whether the VNote instance has different version of vnote.ini.
     bool m_versionChanged;
     bool m_versionChanged;
 
 
+    // Base background of MainWindow.
+    QColor m_baseBackground;
+
     // The name of the config file in each directory.
     // The name of the config file in each directory.
     static const QString c_dirConfigFile;
     static const QString c_dirConfigFile;
 
 
@@ -2714,4 +2720,14 @@ inline bool VConfigManager::versionChanged() const
 {
 {
     return m_versionChanged;
     return m_versionChanged;
 }
 }
+
+inline const QColor &VConfigManager::getBaseBackground() const
+{
+    return m_baseBackground;
+}
+
+inline void VConfigManager::setBaseBackground(const QColor &p_bg)
+{
+    m_baseBackground = p_bg;
+}
 #endif // VCONFIGMANAGER_H
 #endif // VCONFIGMANAGER_H

+ 2 - 1
src/vmdtab.cpp

@@ -450,7 +450,8 @@ void VMdTab::setupMarkdownViewer()
             this, &VMdTab::statusMessage);
             this, &VMdTab::statusMessage);
 
 
     // Avoid white flash before loading content.
     // Avoid white flash before loading content.
-    page->setBackgroundColor(Qt::transparent);
+    // Setting Qt::transparent will force GrayScale antialias rendering.
+    page->setBackgroundColor(g_config->getBaseBackground());
 
 
     m_document = new VDocument(m_file, m_webViewer);
     m_document = new VDocument(m_file, m_webViewer);
     m_documentID = m_document->registerIdentifier();
     m_documentID = m_document->registerIdentifier();