From 1951b30b116ca59b80f33991f9e7d5a186ded349 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 7 Nov 2018 20:31:53 +0800 Subject: [PATCH] OpenGL: add option in settings on Windows to specify OpenGL implementation --- src/dialog/vsettingsdialog.cpp | 46 ++++++++++++++++++++++++++++++++++ src/dialog/vsettingsdialog.h | 8 ++++++ src/main.cpp | 33 ++++++++++++++++++++---- src/resources/vnote.ini | 9 +++++-- src/vconfigmanager.cpp | 41 ++++++++++++++++++++++++++++-- src/vconfigmanager.h | 23 ++++++++++------- 6 files changed, 142 insertions(+), 18 deletions(-) diff --git a/src/dialog/vsettingsdialog.cpp b/src/dialog/vsettingsdialog.cpp index 2aa8998b..751ba94c 100644 --- a/src/dialog/vsettingsdialog.cpp +++ b/src/dialog/vsettingsdialog.cpp @@ -331,6 +331,12 @@ VGeneralTab::VGeneralTab(QWidget *p_parent) m_keyboardLayoutCombo = VUtils::getComboBox(this); m_keyboardLayoutCombo->setToolTip(tr("Choose the keyboard layout mapping to use in shortcuts")); + // OpenGL option. +#if defined(Q_OS_WIN) + m_openGLCombo = VUtils::getComboBox(this); + m_openGLCombo->setToolTip(tr("Choose the OpenGL implementation to load (restart VNote to make it work)")); +#endif + QPushButton *editLayoutBtn = new QPushButton(tr("Edit"), this); connect(editLayoutBtn, &QPushButton::clicked, this, [this]() { @@ -351,6 +357,10 @@ VGeneralTab::VGeneralTab(QWidget *p_parent) optionLayout->addRow(tr("Quick access:"), qaLayout); optionLayout->addRow(tr("Keyboard layout mapping:"), klLayout); +#if defined(Q_OS_WIN) + optionLayout->addRow(tr("OpenGL:"), m_openGLCombo); +#endif + QVBoxLayout *mainLayout = new QVBoxLayout(); mainLayout->addLayout(optionLayout); @@ -434,6 +444,10 @@ bool VGeneralTab::loadConfiguration() return false; } + if (!loadOpenGL()) { + return false; + } + return true; } @@ -459,6 +473,10 @@ bool VGeneralTab::saveConfiguration() return false; } + if (!saveOpenGL()) { + return false; + } + return true; } @@ -589,6 +607,34 @@ bool VGeneralTab::saveKeyboardLayoutMapping() return true; } +bool VGeneralTab::loadOpenGL() +{ +#if defined(Q_OS_WIN) + m_openGLCombo->clear(); + + m_openGLCombo->addItem(tr("System"), OpenGLDefault); + m_openGLCombo->addItem(tr("DesktopOpenGL"), OpenGLDesktop); + m_openGLCombo->addItem(tr("OpenGLES"), OpenGLAngle); + m_openGLCombo->addItem(tr("SoftwareOpenGL"), OpenGLSoftware); + + int opt = VConfigManager::getWindowsOpenGL(); + int idx = m_openGLCombo->findData(opt); + if (idx == -1) { + idx = 0; + } + m_openGLCombo->setCurrentIndex(idx); +#endif + return true; +} + +bool VGeneralTab::saveOpenGL() +{ +#if defined(Q_OS_WIN) + VConfigManager::setWindowsOpenGL(m_openGLCombo->currentData().toInt()); +#endif + return true; +} + VLookTab::VLookTab(QWidget *p_parent) : QWidget(p_parent) { diff --git a/src/dialog/vsettingsdialog.h b/src/dialog/vsettingsdialog.h index 4540a9db..256ba5cf 100644 --- a/src/dialog/vsettingsdialog.h +++ b/src/dialog/vsettingsdialog.h @@ -46,6 +46,9 @@ private: bool loadKeyboardLayoutMapping(); bool saveKeyboardLayoutMapping(); + bool loadOpenGL(); + bool saveOpenGL(); + // Language QComboBox *m_langCombo; @@ -67,6 +70,11 @@ private: // Keyboard layout mappings. QComboBox *m_keyboardLayoutCombo; +#if defined(Q_OS_WIN) + // Windows OpenGL. + QComboBox *m_openGLCombo; +#endif + static const QVector c_availableLangs; }; diff --git a/src/main.cpp b/src/main.cpp index 45ab1457..cdc4715d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,15 +127,38 @@ int main(int argc, char *argv[]) QTextCodec::setCodecForLocale(codec); } - // Set openGL version. - // Or set environment QT_OPENGL to "angle/desktop/software". - // QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); // This only takes effect on Win, X11 and Android. // It will disturb original scaling. Just disable it for now. // QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + // Set openGL version. + // Or set environment QT_OPENGL to "angle/desktop/software". + // QCoreApplication::setAttribute(Qt::AA_UseOpenGLES, true); +#if defined(Q_OS_WIN) + int winOpenGL = VConfigManager::getWindowsOpenGL(); + qInfo() << "OpenGL option" << winOpenGL; + switch (winOpenGL) { + case 1: + QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + break; + + case 2: + QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); + break; + + case 3: + QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); + break; + + case 0: + V_FALLTHROUGH; + default: + break; + } +#endif + QApplication app(argc, argv); // The file path passed via command line arguments. @@ -186,8 +209,8 @@ int main(int argc, char *argv[]) // Check the openSSL. if (checkSSL) { - qDebug() << "openGL" << QOpenGLContext::openGLModuleType(); - qDebug() << "openSSL" + qInfo() << "openGL" << QOpenGLContext::openGLModuleType(); + qInfo() << "openSSL" << QSslSocket::sslLibraryBuildVersionString() << QSslSocket::sslLibraryVersionNumber(); } diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index b8b51f2f..a165ff70 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -2,8 +2,6 @@ ; Theme name theme=v_pure -welcome_page_path=:/resources/welcome.html - ; CSS style name for Markdown template ; Empty to use theme's css style css_style= @@ -278,6 +276,13 @@ split_file_list=false ; Whether split file list out of the tag explorer split_tag_file_list=false +; OpenGL option for Windows +; 0 - no set; +; 1 - desktop; +; 2 - angle; +; 3 - software; +windows_opengl=0 + [editor] ; Auto indent as previous line auto_indent=true diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index 23587e86..9e7d03d1 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -9,6 +9,8 @@ #include #include #include +#include + #include "utils/vutils.h" #include "vstyleparser.h" #include "vpalette.h" @@ -86,8 +88,6 @@ void VConfigManager::initialize() m_defaultEditPalette = QTextEdit().palette(); - welcomePagePath = getConfigFromSettings("global", "welcome_page_path").toString(); - markdownExtensions = hoedown_extensions(HOEDOWN_EXT_TABLES | HOEDOWN_EXT_FENCED_CODE | HOEDOWN_EXT_HIGHLIGHT | HOEDOWN_EXT_AUTOLINK | HOEDOWN_EXT_QUOTE | HOEDOWN_EXT_MATH | HOEDOWN_EXT_MATH_EXPLICIT); @@ -1680,3 +1680,40 @@ void VConfigManager::checkVersion() setConfigToSettings("global", key, c_version); } } + +int VConfigManager::getWindowsOpenGL() +{ + const char *codecForIni = "UTF-8"; + + QScopedPointer userSet(new QSettings(QSettings::IniFormat, + QSettings::UserScope, + orgName, + appName)); + userSet->setIniCodec(codecForIni); + + QString fullKey("global/windows_opengl"); + QVariant val = userSet->value(fullKey); + if (!val.isNull()) { + return val.toInt(); + } + + // Default vnote.ini from resource file. + QScopedPointer defaultSet(new QSettings(c_defaultConfigFilePath, + QSettings::IniFormat)); + defaultSet->setIniCodec(codecForIni); + return defaultSet->value(fullKey).toInt(); +} + +void VConfigManager::setWindowsOpenGL(int p_openGL) +{ + const char *codecForIni = "UTF-8"; + + QScopedPointer userSet(new QSettings(QSettings::IniFormat, + QSettings::UserScope, + orgName, + appName)); + userSet->setIniCodec(codecForIni); + + QString fullKey("global/windows_opengl"); + userSet->setValue(fullKey, p_openGL); +} diff --git a/src/vconfigmanager.h b/src/vconfigmanager.h index a99bdd28..296adcfb 100644 --- a/src/vconfigmanager.h +++ b/src/vconfigmanager.h @@ -74,6 +74,14 @@ enum AutoScrollAlways = 2 }; +enum +{ + OpenGLDefault = 0, + OpenGLDesktop = 1, + OpenGLAngle = 2, + OpenGLSoftware = 3 +}; + class VConfigManager : public QObject { public: @@ -101,6 +109,12 @@ public: static QString getDocumentPathOrHomePath(); + // Get windows_opengl config. + // Because we may call this before QApplication initialization, we only + // read/write the config to the user folder. + static int getWindowsOpenGL(); + static void setWindowsOpenGL(int p_openGL); + // Constants static const QString orgName; static const QString appName; @@ -126,8 +140,6 @@ public: QHash getCodeBlockStyles() const; - QString getWelcomePagePath() const; - QString getLogFilePath() const; // Get the css style URL for web view. @@ -711,8 +723,6 @@ private: QVector mdHighlightingStyles; QHash m_codeBlockStyles; - QString welcomePagePath; - // Index of current notebook. int curNotebookIndex; @@ -1164,11 +1174,6 @@ inline QHash VConfigManager::getCodeBlockStyles() cons return m_codeBlockStyles; } -inline QString VConfigManager::getWelcomePagePath() const -{ - return welcomePagePath; -} - inline QFont VConfigManager::getBaseEditFont() const { return baseEditFont;