Skip to content

Commit

Permalink
audqt: Dark theme adjustments
Browse files Browse the repository at this point in the history
- Darken base color slightly from #383838 to #303030
- Fix very low contrast of toggle buttons (e.g. shuffle/repeat)
- Make widget QProxyStyles inherit from DarkStyle
  • Loading branch information
jlindgren90 committed Apr 16, 2024
1 parent 26e690c commit 7741ee9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/libaudqt/audqt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ EXPORT QVBoxLayout * make_vbox(QWidget * parent, int spacing)

EXPORT void setup_proxy_style(QProxyStyle * style)
{
// set the correct base style ("fusion" or native)
// set the correct base style (dark or native)
if (!strcmp(aud_get_str("audqt", "theme"), "dark"))
style->setBaseStyle(QStyleFactory::create("fusion"));
style->setBaseStyle(create_dark_style());
else
style->setBaseStyle(nullptr);

Expand Down
35 changes: 34 additions & 1 deletion src/libaudqt/dark-theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QProxyStyle>
#include <QStyle>
#include <QStyleFactory>
#include <QStyleOption>

namespace audqt {

Expand Down Expand Up @@ -92,6 +93,10 @@ class DarkStyle : public QProxyStyle
void polish(QWidget * widget) override { QProxyStyle::polish(widget); }
void polish(QPalette & palette) override;

void drawPrimitive(PrimitiveElement elem, const QStyleOption * option,
QPainter * painter,
const QWidget * widget) const override;

/* Qt 6.3+ no longer uses the theme icon "window-close" for tabs,
* but instead forces a built-in icon. Override it back. */
#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
Expand All @@ -111,6 +116,8 @@ void DarkStyle::polish(QPalette & palette)
// normal colors
// clang-format off
palette.setColor(QPalette::WindowText, QColor(0xf0, 0xf0, 0xf0));
// note that QFusionStyle brightens the Button color significantly:
// #2c2c2c actually results in a gradient from #3f3f3f to #363636
palette.setColor(QPalette::Button, QColor(0x2c, 0x2c, 0x2c));
palette.setColor(QPalette::Light, QColor(0x70, 0x70, 0x70));
palette.setColor(QPalette::Midlight, QColor(0x60, 0x60, 0x60));
Expand All @@ -120,7 +127,7 @@ void DarkStyle::polish(QPalette & palette)
palette.setColor(QPalette::BrightText, QColor(0xf0, 0xf0, 0xf0));
palette.setColor(QPalette::ButtonText, QColor(0xf0, 0xf0, 0xf0));
palette.setColor(QPalette::Base, QColor(0x20, 0x20, 0x20));
palette.setColor(QPalette::Window, QColor(0x38, 0x38, 0x38));
palette.setColor(QPalette::Window, QColor(0x30, 0x30, 0x30));
palette.setColor(QPalette::Shadow, QColor(0x00, 0x00, 0x00));
palette.setColor(QPalette::Highlight, QColor(0x15, 0x53, 0x9e)); // matches Adwaita-dark
palette.setColor(QPalette::HighlightedText, QColor(0xff, 0xff, 0xff));
Expand All @@ -146,6 +153,32 @@ void DarkStyle::polish(QPalette & palette)
// clang-format on
}

void DarkStyle::drawPrimitive(PrimitiveElement elem,
const QStyleOption * option, QPainter * painter,
const QWidget * widget) const
{
if (elem == PE_PanelButtonCommand &&
((option->state & (State_Sunken | State_On))))
{
// QFusionStyle draws pressed buttons with very low contrast,
// which makes it difficult to see if shuffle/repeat are active.
// As a workaround, darken them via palette adjustment.
QStyleOption option_copy = *option;
option_copy.palette.setColor(QPalette::Button,
QColor(0x1c, 0x1c, 0x1c));
QProxyStyle::drawPrimitive(elem, &option_copy, painter, widget);
}
else
{
QProxyStyle::drawPrimitive(elem, option, painter, widget);
}
}

QStyle *create_dark_style()
{
return new DarkStyle();
}

void enable_dark_theme()
{
QApplication::setStyle(new DarkStyle());
Expand Down
2 changes: 2 additions & 0 deletions src/libaudqt/libaudqt-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class QPoint;
class QScreen;
class QString;
class QStyle;

namespace audqt
{
Expand All @@ -33,6 +34,7 @@ namespace audqt
void set_icon_theme();

/* dark-theme.cc */
QStyle *create_dark_style();
void enable_dark_theme();
void disable_dark_theme();

Expand Down

0 comments on commit 7741ee9

Please sign in to comment.