mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
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.
This commit is contained in:
parent
7c7889a04d
commit
d5bb0936bf
3 changed files with 21 additions and 7 deletions
|
@ -22,9 +22,11 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QString>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
@ -49,7 +51,7 @@ UserSettings::load()
|
||||||
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
|
isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
|
||||||
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool();
|
||||||
isReadReceiptsEnabled_ = settings.value("user/read_receipts", 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();
|
font_ = settings.value("user/font_family", "default").toString();
|
||||||
emojiFont_ = settings.value("user/emoji_font_family", "default").toString();
|
emojiFont_ = settings.value("user/emoji_font_family", "default").toString();
|
||||||
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble();
|
||||||
|
|
|
@ -85,7 +85,7 @@ public:
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; }
|
QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; }
|
||||||
bool isTrayEnabled() const { return isTrayEnabled_; }
|
bool isTrayEnabled() const { return isTrayEnabled_; }
|
||||||
bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; }
|
bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; }
|
||||||
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
|
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
|
||||||
|
@ -100,6 +100,11 @@ signals:
|
||||||
void groupViewStateChanged(bool state);
|
void groupViewStateChanged(bool state);
|
||||||
|
|
||||||
private:
|
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_;
|
QString theme_;
|
||||||
bool isTrayEnabled_;
|
bool isTrayEnabled_;
|
||||||
bool isStartInTrayEnabled_;
|
bool isStartInTrayEnabled_;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QProcessEnvironment>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
@ -387,14 +388,20 @@ QString
|
||||||
utils::linkColor()
|
utils::linkColor()
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
const auto theme = settings.value("user/theme", "light").toString();
|
// 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")
|
if (theme == "light") {
|
||||||
return "#0077b5";
|
return "#0077b5";
|
||||||
else if (theme == "dark")
|
} else if (theme == "dark") {
|
||||||
return "#38A3D8";
|
return "#38A3D8";
|
||||||
|
} else {
|
||||||
return QPalette().color(QPalette::Link).name();
|
return QPalette().color(QPalette::Link).name();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
Loading…
Reference in a new issue