aboutsummaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2018-04-09 14:50:10 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2018-04-10 16:28:35 +0000
commit7160b8358980d5d6f246a4e7ac2d70dd195444e9 (patch)
treef68531456d6a27a3d78225f0852b1f3b3e6918c4 /src/app
parent12d25f8061384dcfc1a9d8b64819d046eb3995ba (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/app')
-rw-r--r--src/app/main.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/src/app/main.cpp b/src/app/main.cpp
index b96d39225c..f095e373bc 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"));