mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
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.
This commit is contained in:
parent
9b9f2cdea3
commit
2a7a4f864e
@ -31,7 +31,7 @@ void VCopyTextAsHtmlDialog::setupUI()
|
||||
m_textEdit->setProperty("LineEdit", true);
|
||||
|
||||
m_htmlLabel = new QLabel(tr("HTML:"));
|
||||
m_htmlViewer = VUtils::getWebEngineView();
|
||||
m_htmlViewer = VUtils::getWebEngineView(g_config->getBaseBackground());
|
||||
m_htmlViewer->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
m_htmlViewer->setMinimumSize(600, 400);
|
||||
|
||||
|
@ -23,7 +23,7 @@ VTipsDialog::VTipsDialog(const QString &p_tipFile,
|
||||
|
||||
void VTipsDialog::setupUI(const QString &p_actionText)
|
||||
{
|
||||
m_viewer = VUtils::getWebEngineView();
|
||||
m_viewer = VUtils::getWebEngineView(g_config->getBaseBackground());
|
||||
m_viewer->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
|
||||
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||
|
@ -35,7 +35,7 @@ void VUpdater::setupUI()
|
||||
m_proBar = new QProgressBar();
|
||||
m_proBar->setTextVisible(false);
|
||||
|
||||
m_descriptionWV = VUtils::getWebEngineView();
|
||||
m_descriptionWV = VUtils::getWebEngineView(g_config->getBaseBackground());
|
||||
m_descriptionWV->setContextMenuPolicy(Qt::NoContextMenu);
|
||||
m_descriptionWV->setHtml(VUtils::generateSimpleHtmlTemplate(VNote::s_sloganTemplate),
|
||||
QUrl("qrc:/resources"));
|
||||
|
@ -234,6 +234,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
w.show();
|
||||
|
||||
g_config->setBaseBackground(w.palette().color(QPalette::Window));
|
||||
|
||||
w.kickOffStartUpTimer(filePaths);
|
||||
|
||||
int ret = app.exec();
|
||||
|
@ -1417,11 +1417,16 @@ void VUtils::setDynamicProperty(QWidget *p_widget, const char *p_prop, bool p_va
|
||||
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);
|
||||
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->setZoomFactor(g_config->getWebZoomFactor());
|
||||
|
||||
|
@ -314,7 +314,7 @@ public:
|
||||
// Create and return a QComboBox.
|
||||
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);
|
||||
|
||||
|
@ -584,6 +584,9 @@ public:
|
||||
|
||||
bool versionChanged() const;
|
||||
|
||||
const QColor &getBaseBackground() const;
|
||||
void setBaseBackground(const QColor &p_bg);
|
||||
|
||||
private:
|
||||
// Look up a config from user and default settings.
|
||||
QVariant getConfigFromSettings(const QString §ion, const QString &key) const;
|
||||
@ -1044,6 +1047,9 @@ private:
|
||||
// Whether the VNote instance has different version of vnote.ini.
|
||||
bool m_versionChanged;
|
||||
|
||||
// Base background of MainWindow.
|
||||
QColor m_baseBackground;
|
||||
|
||||
// The name of the config file in each directory.
|
||||
static const QString c_dirConfigFile;
|
||||
|
||||
@ -2714,4 +2720,14 @@ inline bool VConfigManager::versionChanged() const
|
||||
{
|
||||
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
|
||||
|
@ -450,7 +450,8 @@ void VMdTab::setupMarkdownViewer()
|
||||
this, &VMdTab::statusMessage);
|
||||
|
||||
// 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_documentID = m_document->registerIdentifier();
|
||||
|
Loading…
x
Reference in New Issue
Block a user