some code to deal with dark mode and colors inherited from OS
This commit is contained in:
parent
d5444981c4
commit
05b2a82559
@ -24,7 +24,7 @@ if ($use_qt5 -eq "ON") {
|
|||||||
$qt_version = "5.15.2"
|
$qt_version = "5.15.2"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$qt_version = "6.5.0"
|
$qt_version = "6.4.3"
|
||||||
}
|
}
|
||||||
|
|
||||||
$maria_version = "10.6.12"
|
$maria_version = "10.6.12"
|
||||||
|
@ -48,12 +48,67 @@ void SkinFactory::loadCurrentSkin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SkinFactory::isStyleGoodForAlternativeStylePalette(const QString& style_name) const {
|
bool SkinFactory::isStyleGoodForAlternativeStylePalette(const QString& style_name) const {
|
||||||
static QRegularExpression re = QRegularExpression("^(fusion|windows|qt[56]ct-style)$");
|
static QRegularExpression re = QRegularExpression(QSL("^(fusion|windows|qt[56]ct-style)$"));
|
||||||
|
|
||||||
return re.match(style_name.toLower()).hasMatch();
|
return re.match(style_name.toLower()).hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: Taken from "QPlatformThemePrivate" Qt class.
|
||||||
|
// This is here because in Qt 6.5.0, they hardcoded
|
||||||
|
// DARK palette if user has enabled "dark mode" in OS.
|
||||||
|
QPalette qt_fusionPalette(bool darkAppearance) {
|
||||||
|
const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black;
|
||||||
|
const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239);
|
||||||
|
const QColor light = backGround.lighter(150);
|
||||||
|
const QColor mid = (backGround.darker(130));
|
||||||
|
const QColor midLight = mid.lighter(110);
|
||||||
|
const QColor base = darkAppearance ? backGround.darker(140) : Qt::white;
|
||||||
|
const QColor disabledBase(backGround);
|
||||||
|
const QColor dark = backGround.darker(150);
|
||||||
|
const QColor darkDisabled = QColor(209, 209, 209).darker(110);
|
||||||
|
const QColor text = darkAppearance ? windowText : Qt::black;
|
||||||
|
const QColor highlight = QColor(48, 140, 198);
|
||||||
|
const QColor hightlightedText = darkAppearance ? windowText : Qt::white;
|
||||||
|
const QColor disabledText = darkAppearance ? QColor(130, 130, 130) : QColor(190, 190, 190);
|
||||||
|
const QColor button = backGround;
|
||||||
|
const QColor shadow = dark.darker(135);
|
||||||
|
const QColor disabledShadow = shadow.lighter(150);
|
||||||
|
QColor placeholder = text;
|
||||||
|
placeholder.setAlpha(128);
|
||||||
|
|
||||||
|
QPalette fusionPalette(windowText, backGround, light, dark, mid, text, base);
|
||||||
|
fusionPalette.setBrush(QPalette::Midlight, midLight);
|
||||||
|
fusionPalette.setBrush(QPalette::Button, button);
|
||||||
|
fusionPalette.setBrush(QPalette::Shadow, shadow);
|
||||||
|
fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText);
|
||||||
|
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText);
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText);
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText);
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase);
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow);
|
||||||
|
|
||||||
|
fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, highlight);
|
||||||
|
fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, highlight);
|
||||||
|
fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(145, 145, 145));
|
||||||
|
|
||||||
|
fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);
|
||||||
|
|
||||||
|
if (darkAppearance) {
|
||||||
|
fusionPalette.setBrush(QPalette::Link, highlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fusionPalette;
|
||||||
|
}
|
||||||
|
|
||||||
void SkinFactory::loadSkinFromData(const Skin& skin) {
|
void SkinFactory::loadSkinFromData(const Skin& skin) {
|
||||||
|
#if QT_VERSION >= 0x060500 // Qt >= 6.5.0
|
||||||
|
auto system_color_scheme = qApp->styleHints()->colorScheme();
|
||||||
|
|
||||||
|
qDebugNN << LOGSEC_GUI << "OS defines color scheme:" << QUOTE_W_SPACE_DOT(system_color_scheme);
|
||||||
|
#endif
|
||||||
|
|
||||||
QString style_name = qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString();
|
QString style_name = qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString();
|
||||||
auto env = QProcessEnvironment::systemEnvironment();
|
auto env = QProcessEnvironment::systemEnvironment();
|
||||||
const QString env_forced_style = env.value(QSL("QT_STYLE_OVERRIDE"));
|
const QString env_forced_style = env.value(QSL("QT_STYLE_OVERRIDE"));
|
||||||
@ -123,6 +178,14 @@ void SkinFactory::loadSkinFromData(const Skin& skin) {
|
|||||||
QToolTip::setPalette(pal);
|
QToolTip::setPalette(pal);
|
||||||
qApp->setPalette(pal);
|
qApp->setPalette(pal);
|
||||||
}
|
}
|
||||||
|
// NOTE: Very hacky way of avoiding automatic "dark mode"
|
||||||
|
// palettes in some styles. Also in light mode,
|
||||||
|
// colors are now derived from system.
|
||||||
|
#if QT_VERSION >= 0x060500 // Qt >= 6.5.0
|
||||||
|
else /* if (qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark) */ {
|
||||||
|
qApp->setPalette(qt_fusionPalette(false));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!skin.m_rawData.isEmpty()) {
|
if (!skin.m_rawData.isEmpty()) {
|
||||||
if (qApp->styleSheet().simplified().isEmpty() && use_skin_colors) {
|
if (qApp->styleSheet().simplified().isEmpty() && use_skin_colors) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user