diff options
author | Joseph Donofry <joedonofry@gmail.com> | 2019-08-10 13:14:37 -0400 |
---|---|---|
committer | Joseph Donofry <joedonofry@gmail.com> | 2019-08-10 13:14:37 -0400 |
commit | d5bb0936bf8b16dc4a8b505192077576dbe96149 (patch) | |
tree | 48490289b2d3bfffa279f2097a4ed0471b8fcea2 /src | |
parent | Fix linting issues w/ the last commit (diff) | |
download | nheko-d5bb0936bf8b16dc4a8b505192077576dbe96149.tar.xz |
Use 'system' theme as default if QT_QPA_PLATFORMTHEME is set
On first launch, before the user has configured any settings, check the value of the QT_QPA_PLATFORMTHEME environment var. If it is set, use the system theme as the default instead of the light theme. This fixes #72.
Diffstat (limited to 'src')
-rw-r--r-- | src/UserSettingsPage.cpp | 4 | ||||
-rw-r--r-- | src/UserSettingsPage.h | 7 | ||||
-rw-r--r-- | src/Utils.cpp | 19 |
3 files changed, 22 insertions, 8 deletions
diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 49cb2c1f..30e6ea96 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -22,9 +22,11 @@ #include <QLabel> #include <QLineEdit> #include <QMessageBox> +#include <QProcessEnvironment> #include <QPushButton> #include <QScrollArea> #include <QSettings> +#include <QString> #include <QTextStream> #include "Config.h" @@ -49,7 +51,7 @@ UserSettings::load() isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); - theme_ = settings.value("user/theme", "light").toString(); + theme_ = settings.value("user/theme", defaultTheme_).toString(); font_ = settings.value("user/font_family", "default").toString(); emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index ffff1e20..dce12315 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -85,7 +85,7 @@ public: save(); } - QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } + QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool isTrayEnabled() const { return isTrayEnabled_; } bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } bool isGroupViewEnabled() const { return isGroupViewEnabled_; } @@ -100,6 +100,11 @@ signals: void groupViewStateChanged(bool state); private: + // Default to system theme if QT_QPA_PLATFORMTHEME var is set. + QString defaultTheme_ = + QProcessEnvironment::systemEnvironment().value("QT_QPA_PLATFORMTHEME", "").isEmpty() + ? "light" + : "system"; QString theme_; bool isTrayEnabled_; bool isStartInTrayEnabled_; diff --git a/src/Utils.cpp b/src/Utils.cpp index a3c15c96..5c664b7c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -4,6 +4,7 @@ #include <QComboBox> #include <QDesktopWidget> #include <QGuiApplication> +#include <QProcessEnvironment> #include <QScreen> #include <QSettings> #include <QTextDocument> @@ -387,14 +388,20 @@ QString utils::linkColor() { QSettings settings; - const auto theme = settings.value("user/theme", "light").toString(); - - if (theme == "light") + // Default to system theme if QT_QPA_PLATFORMTHEME var is set. + QString defaultTheme = + QProcessEnvironment::systemEnvironment().value("QT_QPA_PLATFORMTHEME", "").isEmpty() + ? "light" + : "system"; + const auto theme = settings.value("user/theme", defaultTheme).toString(); + + if (theme == "light") { return "#0077b5"; - else if (theme == "dark") + } else if (theme == "dark") { return "#38A3D8"; - - return QPalette().color(QPalette::Link).name(); + } else { + return QPalette().color(QPalette::Link).name(); + } } uint32_t |