Skip to content

Commit 5164624

Browse files
committed
fix: fix default palette on the KDE6 flatpak runtime
1 parent 0cf7199 commit 5164624

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/src.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ UI_DEBUG: DEFINES += UI_DEBUG
2323
DEBUG_FPE: DEFINES += DEBUG_FPE
2424
DEBUG_ASAN: CONFIG += sanitizer sanitize_address
2525
USE_PULSEAUDIO: DEFINES += USE_PULSEAUDIO
26-
USE_PORTALS: DEFINES += USE_PORTALS
26+
FLATPAK: DEFINES += USE_PORTALS
27+
FLATPAK: DEFINES += IS_FLATPAK
2728
HEADLESS: DEFINES += HEADLESS
2829
NO_CRASH_HANDLER: DEFINES += NO_CRASH_HANDLER
2930

src/utils/StyleHelper.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ void StyleHelper::SetStyle()
4444
else
4545
{
4646
loadIcons(false);
47+
#ifndef IS_FLATPAK
4748
QApplication::setPalette(m_host->style()->standardPalette());
49+
#else
50+
QApplication::setPalette(getDefaultLightPalette());
51+
#endif
4852
}
4953

5054
QFile f(":/styles/default.qss");
@@ -99,6 +103,58 @@ void StyleHelper::setPalette(const ColorStyle &s)
99103
})").arg(s.disabled.name()));
100104
}
101105

106+
QPalette StyleHelper::getDefaultLightPalette() {
107+
const bool darkAppearance = false;
108+
const QColor windowText = darkAppearance ? QColor(240, 240, 240) : Qt::black;
109+
const QColor backGround = darkAppearance ? QColor(50, 50, 50) : QColor(239, 239, 239);
110+
const QColor light = backGround.lighter(150);
111+
const QColor mid = (backGround.darker(130));
112+
const QColor midLight = mid.lighter(110);
113+
const QColor base = darkAppearance ? backGround.darker(140) : Qt::white;
114+
const QColor disabledBase(backGround);
115+
const QColor dark = backGround.darker(150);
116+
const QColor darkDisabled = QColor(209, 209, 209).darker(110);
117+
const QColor text = darkAppearance ? windowText : Qt::black;
118+
const QColor highlight = QColor(48, 140, 198);
119+
const QColor hightlightedText = darkAppearance ? windowText : Qt::white;
120+
const QColor disabledText = darkAppearance ? QColor(130, 130, 130) : QColor(190, 190, 190);
121+
const QColor button = backGround;
122+
const QColor shadow = dark.darker(135);
123+
const QColor disabledShadow = shadow.lighter(150);
124+
const QColor disabledHighlight(145, 145, 145);
125+
QColor placeholder = text;
126+
placeholder.setAlpha(128);
127+
128+
QPalette fusionPalette(windowText, backGround, light, dark, mid, text, base);
129+
fusionPalette.setBrush(QPalette::Midlight, midLight);
130+
fusionPalette.setBrush(QPalette::Button, button);
131+
fusionPalette.setBrush(QPalette::Shadow, shadow);
132+
fusionPalette.setBrush(QPalette::HighlightedText, hightlightedText);
133+
134+
fusionPalette.setBrush(QPalette::Disabled, QPalette::Text, disabledText);
135+
fusionPalette.setBrush(QPalette::Disabled, QPalette::WindowText, disabledText);
136+
fusionPalette.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledText);
137+
fusionPalette.setBrush(QPalette::Disabled, QPalette::Base, disabledBase);
138+
fusionPalette.setBrush(QPalette::Disabled, QPalette::Dark, darkDisabled);
139+
fusionPalette.setBrush(QPalette::Disabled, QPalette::Shadow, disabledShadow);
140+
141+
fusionPalette.setBrush(QPalette::Active, QPalette::Highlight, highlight);
142+
fusionPalette.setBrush(QPalette::Inactive, QPalette::Highlight, highlight);
143+
fusionPalette.setBrush(QPalette::Disabled, QPalette::Highlight, disabledHighlight);
144+
145+
fusionPalette.setBrush(QPalette::Active, QPalette::Accent, highlight);
146+
fusionPalette.setBrush(QPalette::Inactive, QPalette::Accent, highlight);
147+
fusionPalette.setBrush(QPalette::Disabled, QPalette::Accent, disabledHighlight);
148+
149+
fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);
150+
151+
// Use a more legible light blue on dark backgrounds than the default Qt::blue.
152+
if (darkAppearance)
153+
fusionPalette.setBrush(QPalette::Link, highlight);
154+
155+
return fusionPalette;
156+
}
157+
102158
void StyleHelper::loadIcons(bool white)
103159
{
104160
emit iconColorChanged(white);

src/utils/StyleHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class StyleHelper :
3434
int loadColor(int index,
3535
int rgb_index);
3636
void setPalette(const ColorStyle &s);
37+
QPalette StyleHelper::getDefaultLightPalette();
3738

3839
private:
3940
QObject *m_objhost;

0 commit comments

Comments
 (0)