mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
Prevent copies when querying theme
This commit is contained in:
parent
f21bf5f97e
commit
497c3df50e
4 changed files with 38 additions and 18 deletions
|
@ -663,7 +663,7 @@ UserSettings::applyTheme()
|
||||||
} else {
|
} else {
|
||||||
stylefile.setFileName(QStringLiteral(":/styles/styles/system.qss"));
|
stylefile.setFileName(QStringLiteral(":/styles/styles/system.qss"));
|
||||||
}
|
}
|
||||||
QApplication::setPalette(Theme::paletteFromTheme(this->theme().toStdString()));
|
QApplication::setPalette(Theme::paletteFromTheme(this->theme()));
|
||||||
|
|
||||||
stylefile.open(QFile::ReadOnly);
|
stylefile.open(QFile::ReadOnly);
|
||||||
QString stylesheet = QString(stylefile.readAll());
|
QString stylesheet = QString(stylefile.readAll());
|
||||||
|
|
|
@ -38,21 +38,41 @@ Nheko::updateUserProfile()
|
||||||
QPalette
|
QPalette
|
||||||
Nheko::colors() const
|
Nheko::colors() const
|
||||||
{
|
{
|
||||||
return Theme::paletteFromTheme(UserSettings::instance()->theme().toStdString());
|
return Theme::paletteFromTheme(UserSettings::instance()->theme());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPalette
|
QPalette
|
||||||
Nheko::inactiveColors() const
|
Nheko::inactiveColors() const
|
||||||
{
|
{
|
||||||
auto p = colors();
|
auto theme = UserSettings::instance()->theme();
|
||||||
p.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
if (theme == QLatin1String("light")) {
|
||||||
return p;
|
static QPalette lightInactive = [] {
|
||||||
|
auto lightInactive = Theme::paletteFromTheme(u"light");
|
||||||
|
lightInactive.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
||||||
|
return lightInactive;
|
||||||
|
}();
|
||||||
|
return lightInactive;
|
||||||
|
} else if (theme == QLatin1String("dark")) {
|
||||||
|
static QPalette darkInactive = [] {
|
||||||
|
auto darkInactive = Theme::paletteFromTheme(u"dark");
|
||||||
|
darkInactive.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
||||||
|
return darkInactive;
|
||||||
|
}();
|
||||||
|
return darkInactive;
|
||||||
|
} else {
|
||||||
|
static QPalette originalInactive = [] {
|
||||||
|
auto originalInactive = Theme::paletteFromTheme(u"system");
|
||||||
|
originalInactive.setCurrentColorGroup(QPalette::ColorGroup::Inactive);
|
||||||
|
return originalInactive;
|
||||||
|
}();
|
||||||
|
return originalInactive;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Theme
|
Theme
|
||||||
Nheko::theme() const
|
Nheko::theme() const
|
||||||
{
|
{
|
||||||
return Theme(UserSettings::instance()->theme().toStdString());
|
return Theme(UserSettings::instance()->theme());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -61,10 +81,10 @@ Nheko::openLink(QString link) const
|
||||||
QUrl url(link);
|
QUrl url(link);
|
||||||
// Open externally if we couldn't handle it internally
|
// Open externally if we couldn't handle it internally
|
||||||
if (!ChatPage::instance()->handleMatrixUri(url)) {
|
if (!ChatPage::instance()->handleMatrixUri(url)) {
|
||||||
const QStringList allowedUrlSchemes = {
|
static const QStringList allowedUrlSchemes = {
|
||||||
"http",
|
QStringLiteral("http"),
|
||||||
"https",
|
QStringLiteral("https"),
|
||||||
"mailto",
|
QStringLiteral("mailto"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (allowedUrlSchemes.contains(url.scheme()))
|
if (allowedUrlSchemes.contains(url.scheme()))
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
Q_DECLARE_METATYPE(Theme)
|
Q_DECLARE_METATYPE(Theme)
|
||||||
|
|
||||||
QPalette
|
QPalette
|
||||||
Theme::paletteFromTheme(std::string_view theme)
|
Theme::paletteFromTheme(QStringView theme)
|
||||||
{
|
{
|
||||||
[[maybe_unused]] static auto meta = qRegisterMetaType<Theme>("Theme");
|
[[maybe_unused]] static auto meta = qRegisterMetaType<Theme>("Theme");
|
||||||
static QPalette original;
|
static QPalette original;
|
||||||
if (theme == "light") {
|
if (theme == u"light") {
|
||||||
static QPalette lightActive = [] {
|
static QPalette lightActive = [] {
|
||||||
QPalette lightActive(
|
QPalette lightActive(
|
||||||
/*windowText*/ QColor(0x33, 0x33, 0x33),
|
/*windowText*/ QColor(0x33, 0x33, 0x33),
|
||||||
|
@ -33,7 +33,7 @@ Theme::paletteFromTheme(std::string_view theme)
|
||||||
return lightActive;
|
return lightActive;
|
||||||
}();
|
}();
|
||||||
return lightActive;
|
return lightActive;
|
||||||
} else if (theme == "dark") {
|
} else if (theme == u"dark") {
|
||||||
static QPalette darkActive = [] {
|
static QPalette darkActive = [] {
|
||||||
QPalette darkActive(
|
QPalette darkActive(
|
||||||
/*windowText*/ QColor(0xca, 0xcc, 0xd1),
|
/*windowText*/ QColor(0xca, 0xcc, 0xd1),
|
||||||
|
@ -60,16 +60,16 @@ Theme::paletteFromTheme(std::string_view theme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Theme::Theme(std::string_view theme)
|
Theme::Theme(QStringView theme)
|
||||||
{
|
{
|
||||||
auto p = paletteFromTheme(theme);
|
auto p = paletteFromTheme(theme);
|
||||||
separator_ = p.mid().color();
|
separator_ = p.mid().color();
|
||||||
if (theme == "light") {
|
if (theme == u"light") {
|
||||||
sidebarBackground_ = QColor(0x23, 0x36, 0x49);
|
sidebarBackground_ = QColor(0x23, 0x36, 0x49);
|
||||||
alternateButton_ = QColor(0xcc, 0xcc, 0xcc);
|
alternateButton_ = QColor(0xcc, 0xcc, 0xcc);
|
||||||
red_ = QColor(0xa8, 0x23, 0x53);
|
red_ = QColor(0xa8, 0x23, 0x53);
|
||||||
orange_ = QColor(0xfc, 0xbe, 0x05);
|
orange_ = QColor(0xfc, 0xbe, 0x05);
|
||||||
} else if (theme == "dark") {
|
} else if (theme == u"dark") {
|
||||||
sidebarBackground_ = QColor(0x2d, 0x31, 0x39);
|
sidebarBackground_ = QColor(0x2d, 0x31, 0x39);
|
||||||
alternateButton_ = QColor(0x41, 0x4A, 0x59);
|
alternateButton_ = QColor(0x41, 0x4A, 0x59);
|
||||||
red_ = QColor(0xa8, 0x23, 0x53);
|
red_ = QColor(0xa8, 0x23, 0x53);
|
||||||
|
|
|
@ -66,8 +66,8 @@ class Theme : public QPalette
|
||||||
Q_PROPERTY(QColor orange READ orange CONSTANT)
|
Q_PROPERTY(QColor orange READ orange CONSTANT)
|
||||||
public:
|
public:
|
||||||
Theme() {}
|
Theme() {}
|
||||||
explicit Theme(std::string_view theme);
|
explicit Theme(QStringView theme);
|
||||||
static QPalette paletteFromTheme(std::string_view theme);
|
static QPalette paletteFromTheme(QStringView theme);
|
||||||
|
|
||||||
QColor sidebarBackground() const { return sidebarBackground_; }
|
QColor sidebarBackground() const { return sidebarBackground_; }
|
||||||
QColor alternateButton() const { return alternateButton_; }
|
QColor alternateButton() const { return alternateButton_; }
|
||||||
|
|
Loading…
Reference in a new issue