diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2018-04-09 14:50:10 +0200 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2018-04-10 16:28:35 +0000 |
commit | 7160b8358980d5d6f246a4e7ac2d70dd195444e9 (patch) | |
tree | f68531456d6a27a3d78225f0852b1f3b3e6918c4 /src | |
parent | 12d25f8061384dcfc1a9d8b64819d046eb3995ba (diff) |
Allow to disable or enable high DPI scaling
An option is added to the Options dialog:
* Allow to enable high DPI scaling on Linux
* Allow to disable high DPI scaling on Windows
On macOS+retina, high DPI scaling applied automatically
and we do not show the option on macOS.
I had to duplicate the logic for parsing -settingspath,
because the code has to run before QApplication is created.
Task-number: QTCREATORBUG-20232
Change-Id: I4e94fc54391fe99e30d4778ec2a178529961eed7
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/app/main.cpp | 48 | ||||
-rw-r--r-- | src/plugins/coreplugin/generalsettings.cpp | 16 | ||||
-rw-r--r-- | src/plugins/coreplugin/generalsettings.ui | 65 |
3 files changed, 99 insertions, 30 deletions
diff --git a/src/app/main.cpp b/src/app/main.cpp index b96d39225c5..f095e373bc7 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -58,6 +58,8 @@ #include <QStandardPaths> #include <QTemporaryDir> +#include <memory> + #ifdef ENABLE_QT_BREAKPAD #include <qtsystemexceptionhandler.h> #endif @@ -165,18 +167,6 @@ static inline int askMsgSendFailed() QMessageBox::Retry); } -static void setHighDpiEnvironmentVariable() -{ - static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; - if (Utils::HostOsInfo().isWindowsHost() - && !qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO) // legacy in 5.6, but still functional - && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR") - && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") - && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) { - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - } -} - // taken from utils/fileutils.cpp. We can not use utils here since that depends app_version.h. static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) @@ -303,6 +293,38 @@ static inline QSettings *userSettings() return createUserSettings(); } +static void setHighDpiEnvironmentVariable(int argc, char **argv) +{ + + if (Utils::HostOsInfo().isMacHost()) + return; + + std::vector<std::string> arguments(argv, argv + argc); + auto it = arguments.begin(); + QString settingsPath; + while (it != arguments.end()) { + const QString &arg = QString::fromStdString(*it); + it = ++it; + if (arg == SETTINGS_OPTION && it != arguments.end()) + settingsPath = QDir::fromNativeSeparators(QString::fromStdString(*it)); + } + if (!settingsPath.isEmpty()) + QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, settingsPath); + std::unique_ptr<QSettings> settings(createUserSettings()); + + const bool defaultValue = Utils::HostOsInfo().isWindowsHost(); + const bool enableHighDpiScaling = settings->value("Core/EnableHighDpiScaling", defaultValue).toBool(); + + static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; + if (enableHighDpiScaling + && !qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO) // legacy in 5.6, but still functional + && !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR") + && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") + && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) { + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + } +} + void loadFonts() { const QDir dir(resourcePath() + "/fonts/"); @@ -325,7 +347,7 @@ int main(int argc, char **argv) Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() + "/" + Core::Constants::IDE_CASED_ID + "-XXXXXX"); - setHighDpiEnvironmentVariable(); + setHighDpiEnvironmentVariable(argc, argv); QLoggingCategory::setFilterRules(QLatin1String("qtc.*.debug=false\nqtc.*.info=false")); diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index 2a0036616e6..f830f7c46e7 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -29,6 +29,7 @@ #include "infobar.h" #include <utils/checkablemessagebox.h> +#include <utils/hostosinfo.h> #include <utils/stylehelper.h> #include <QCoreApplication> @@ -44,6 +45,8 @@ using namespace Utils; namespace Core { namespace Internal { +const char settingsKeyDPI[] = "Core/EnableHighDpiScaling"; + GeneralSettings::GeneralSettings() : m_page(0), m_dialog(0) { @@ -103,6 +106,19 @@ QWidget *GeneralSettings::widget() m_page->colorButton->setColor(StyleHelper::requestedBaseColor()); m_page->resetWarningsButton->setEnabled(canResetWarnings()); + if (Utils::HostOsInfo().isMacHost()) { + m_page->dpiLabel->setVisible(false); + m_page->dpiCheckbox->setVisible(false); + } else { + const bool defaultValue = Utils::HostOsInfo().isWindowsHost(); + m_page->dpiCheckbox->setChecked(ICore::settings()->value(settingsKeyDPI, defaultValue).toBool()); + connect(m_page->dpiCheckbox, &QCheckBox::toggled, this, [](bool checked) { + ICore::settings()->setValue(settingsKeyDPI, checked); + QMessageBox::information(ICore::mainWindow(), tr("Restart Required"), + tr("The high DPI settings will take effect after restart.")); + }); + } + connect(m_page->resetColorButton, &QAbstractButton::clicked, this, &GeneralSettings::resetInterfaceColor); connect(m_page->resetWarningsButton, &QAbstractButton::clicked, diff --git a/src/plugins/coreplugin/generalsettings.ui b/src/plugins/coreplugin/generalsettings.ui index 333be51ac76..0302314d645 100644 --- a/src/plugins/coreplugin/generalsettings.ui +++ b/src/plugins/coreplugin/generalsettings.ui @@ -24,6 +24,20 @@ </property> </widget> </item> + <item row="2" column="0"> + <widget class="QLabel" name="languageLabel"> + <property name="text"> + <string>Language:</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="themeLabel"> + <property name="text"> + <string>Theme:</string> + </property> + </widget> + </item> <item row="0" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> @@ -70,20 +84,13 @@ </item> </layout> </item> - <item row="1" column="0"> - <widget class="QLabel" name="themeLabel"> - <property name="text"> - <string>Theme:</string> + <item row="4" column="0"> + <widget class="QPushButton" name="resetWarningsButton"> + <property name="toolTip"> + <string>Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter).</string> </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="Core::Internal::ThemeChooser" name="themeChooser" native="true"/> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="languageLabel"> <property name="text"> - <string>Language:</string> + <string comment="Button text">Reset Warnings</string> </property> </widget> </item> @@ -114,13 +121,37 @@ </item> </layout> </item> + <item row="1" column="1"> + <widget class="Core::Internal::ThemeChooser" name="themeChooser" native="true"/> + </item> + <item row="3" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QCheckBox" name="dpiCheckbox"> + <property name="text"> + <string>Enable high DPI scaling</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>285</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> <item row="3" column="0"> - <widget class="QPushButton" name="resetWarningsButton"> - <property name="toolTip"> - <string>Re-enable warnings that were suppressed by selecting "Do Not Show Again" (for example, missing highlighter).</string> - </property> + <widget class="QLabel" name="dpiLabel"> <property name="text"> - <string comment="Button text">Reset Warnings</string> + <string>High DPI scaling:</string> </property> </widget> </item> |