Skip to content

Commit

Permalink
fix: fix default palette on the KDE6 flatpak runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Dec 9, 2023
1 parent 0cf7199 commit 5164624
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ UI_DEBUG: DEFINES += UI_DEBUG
DEBUG_FPE: DEFINES += DEBUG_FPE
DEBUG_ASAN: CONFIG += sanitizer sanitize_address
USE_PULSEAUDIO: DEFINES += USE_PULSEAUDIO
USE_PORTALS: DEFINES += USE_PORTALS
FLATPAK: DEFINES += USE_PORTALS
FLATPAK: DEFINES += IS_FLATPAK
HEADLESS: DEFINES += HEADLESS
NO_CRASH_HANDLER: DEFINES += NO_CRASH_HANDLER

Expand Down
56 changes: 56 additions & 0 deletions src/utils/StyleHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ void StyleHelper::SetStyle()
else
{
loadIcons(false);
#ifndef IS_FLATPAK
QApplication::setPalette(m_host->style()->standardPalette());
#else
QApplication::setPalette(getDefaultLightPalette());
#endif
}

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

QPalette StyleHelper::getDefaultLightPalette() {
const bool darkAppearance = false;
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);
const QColor disabledHighlight(145, 145, 145);
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, disabledHighlight);

fusionPalette.setBrush(QPalette::Active, QPalette::Accent, highlight);
fusionPalette.setBrush(QPalette::Inactive, QPalette::Accent, highlight);
fusionPalette.setBrush(QPalette::Disabled, QPalette::Accent, disabledHighlight);

fusionPalette.setBrush(QPalette::PlaceholderText, placeholder);

// Use a more legible light blue on dark backgrounds than the default Qt::blue.
if (darkAppearance)
fusionPalette.setBrush(QPalette::Link, highlight);

return fusionPalette;
}

void StyleHelper::loadIcons(bool white)
{
emit iconColorChanged(white);
Expand Down
1 change: 1 addition & 0 deletions src/utils/StyleHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class StyleHelper :
int loadColor(int index,
int rgb_index);
void setPalette(const ColorStyle &s);
QPalette StyleHelper::getDefaultLightPalette();

private:
QObject *m_objhost;
Expand Down

0 comments on commit 5164624

Please sign in to comment.