Skip to content

Commit 1f38313

Browse files
committed
Check and radio buttons: use blue color for checked items
1 parent ebd3ff2 commit 1f38313

File tree

3 files changed

+152
-114
lines changed

3 files changed

+152
-114
lines changed

style/adwaitahelper.cpp

Lines changed: 132 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,22 @@ QPalette Helper::palette(bool dark) const
245245
}
246246

247247
//____________________________________________________________________
248-
QColor Helper::indicatorOutlineColor(const QPalette &palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode, bool darkMode) const
248+
QColor Helper::indicatorOutlineColor(const QPalette &palette, bool mouseOver, bool hasFocus, qreal opacity, AnimationMode mode, CheckBoxState state, bool darkMode, bool inMenu) const
249249
{
250250
bool isDisabled = palette.currentColorGroup() == QPalette::Disabled;
251+
if (inMenu || state == CheckBoxState::CheckOff) {
251252

252-
if (isDisabled) {
253-
return buttonOutlineColor(palette, mouseOver, hasFocus, opacity, mode, darkMode);
254-
}
253+
if (isDisabled) {
254+
return buttonOutlineColor(palette, mouseOver, hasFocus, opacity, mode, darkMode);
255+
}
255256

256-
if (darkMode) {
257-
return darken(palette.color(QPalette::Window), 0.18);
257+
if (darkMode) {
258+
return darken(palette.color(QPalette::Window), 0.18);
259+
} else {
260+
return darken(palette.color(QPalette::Window), 0.24);
261+
}
258262
} else {
259-
return darken(palette.color(QPalette::Window), 0.24);
263+
return palette.color(QPalette::Highlight);
260264
}
261265
}
262266

@@ -389,50 +393,59 @@ QColor Helper::buttonBackgroundColor(const QPalette &palette, bool mouseOver, bo
389393
}
390394

391395
//
392-
QColor Helper::indicatorBackgroundColor(const QPalette &palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode, bool darkMode) const
396+
QColor Helper::indicatorBackgroundColor(const QPalette &palette, bool mouseOver, bool hasFocus, bool sunken, qreal opacity, AnimationMode mode, CheckBoxState state, bool darkMode, bool inMenu) const
393397
{
394398
bool isDisabled = palette.currentColorGroup() == QPalette::Disabled;
395399
QColor background(palette.color(QPalette::Window));
396400
// Normal-alt button for dark mode is darken(bg_color, 0.03)
397401
// Normal-alt button for normal mode is lighten(bg_color, 0.05)
398402
QColor indicatorColor(darkMode ? darken(background, 0.03) : lighten(background, 0.05));
399-
if (isDisabled) {
400-
// Defined in drawing.css - insensitive button
401-
// $insensitive_bg_color: mix($bg_color, $base_color, 60%);
402-
return mix(palette.color(QPalette::Active, QPalette::Window), palette.color(QPalette::Active, QPalette::Base), 0.6);
403-
}
404403

405-
if (mode == AnimationPressed) {
406-
if (darkMode) {
407-
// Active button for dark mode is darken(bg_color, 0.09)
408-
return mix(background, darken(background, 0.09), opacity);
409-
} else {
410-
// Active button for normal mode is darken(bg_color, 0.14)
411-
return mix(lighten(background, 0.0), darken(background, 0.14), opacity);
404+
if (inMenu || state == CheckOff) {
405+
if (isDisabled) {
406+
// Defined in drawing.css - insensitive button
407+
// $insensitive_bg_color: mix($bg_color, $base_color, 60%);
408+
return mix(palette.color(QPalette::Active, QPalette::Window), palette.color(QPalette::Active, QPalette::Base), 0.6);
412409
}
413-
} else if (sunken) {
414-
if (darkMode) {
415-
// Active button for dark mode is darken(bg_color, 0.09)
416-
return darken(background, 0.09);
417-
} else {
418-
// Active button for normal mode is darken(bg_color, 0.14)
419-
return darken(background, 0.14);
420-
}
421-
} else if (mode == AnimationHover) {
422-
if (darkMode) {
423-
// Hovered-alt button for dark mode is bg_color
424-
return mix(indicatorColor, background, opacity);
425-
} else {
426-
// Hovered-alt button for normal mode is lighten(bg_color, 0.09)
427-
return mix(indicatorColor, lighten(background, 0.09), opacity);
410+
411+
if (mode == AnimationPressed) {
412+
if (darkMode) {
413+
// Active button for dark mode is darken(bg_color, 0.09)
414+
return mix(background, darken(background, 0.09), opacity);
415+
} else {
416+
// Active button for normal mode is darken(bg_color, 0.14)
417+
return mix(lighten(background, 0.0), darken(background, 0.14), opacity);
418+
}
419+
} else if (sunken) {
420+
if (darkMode) {
421+
// Active button for dark mode is darken(bg_color, 0.09)
422+
return darken(background, 0.09);
423+
} else {
424+
// Active button for normal mode is darken(bg_color, 0.14)
425+
return darken(background, 0.14);
426+
}
427+
} else if (mode == AnimationHover) {
428+
if (darkMode) {
429+
// Hovered-alt button for dark mode is bg_color
430+
return mix(indicatorColor, background, opacity);
431+
} else {
432+
// Hovered-alt button for normal mode is lighten(bg_color, 0.09)
433+
return mix(indicatorColor, lighten(background, 0.09), opacity);
434+
}
435+
} else if (mouseOver) {
436+
if (darkMode) {
437+
// Hovered-alt button for dark mode is bg_color
438+
return background;
439+
} else {
440+
// Hovered-alt button for normal mode is lighten(bg_color, 0.09)
441+
return lighten(background, 0.09);
442+
}
428443
}
429-
} else if (mouseOver) {
444+
} else {
430445
if (darkMode) {
431-
// Hovered-alt button for dark mode is bg_color
432-
return background;
446+
return lighten(palette.color(QPalette::Highlight));
433447
} else {
434-
// Hovered-alt button for normal mode is lighten(bg_color, 0.09)
435-
return lighten(background, 0.09);
448+
return palette.color(QPalette::Highlight);
436449
}
437450
}
438451

@@ -501,13 +514,22 @@ QColor Helper::scrollBarHandleColor(const QPalette &palette, bool mouseOver, boo
501514
}
502515

503516
//______________________________________________________________________________
504-
QColor Helper::checkBoxIndicatorColor(const QPalette &palette, bool mouseOver, bool active, qreal opacity, AnimationMode mode) const
517+
QColor Helper::checkBoxIndicatorColor(const QPalette &palette, bool mouseOver, bool active, qreal opacity, AnimationMode mode, bool darkMode, bool inMenu) const
505518
{
506519
Q_UNUSED(mouseOver);
507520
Q_UNUSED(active);
508521
Q_UNUSED(opacity);
509522
Q_UNUSED(mode);
510-
return palette.text().color();
523+
524+
if (inMenu) {
525+
return palette.color(QPalette::Text);
526+
} else {
527+
if (active) {
528+
return palette.color(QPalette::HighlightedText);
529+
} else {
530+
return transparentize(palette.color(QPalette::ToolTipText), 0.2);
531+
}
532+
}
511533
}
512534

513535
//______________________________________________________________________________
@@ -850,7 +872,7 @@ void Helper::renderButtonFrame(QPainter *painter, const QRect &rect, const QColo
850872

851873
//______________________________________________________________________________
852874
void Helper::renderCheckBoxFrame(QPainter *painter, const QRect &rect, const QColor &color, const QColor &outline, const QColor &shadow,
853-
bool hasFocus, bool sunken, bool mouseOver, bool active, bool darkMode) const
875+
bool hasFocus, bool sunken, bool mouseOver, bool active, CheckBoxState state, bool darkMode, bool inMenu) const
854876
{
855877
// setup painter
856878
painter->setRenderHint(QPainter::Antialiasing, true);
@@ -868,60 +890,64 @@ void Helper::renderCheckBoxFrame(QPainter *painter, const QRect &rect, const QCo
868890
} else
869891
painter->setPen(Qt::NoPen);
870892

871-
// content
872-
if (color.isValid() && active) {
873-
QLinearGradient gradient(frameRect.bottomLeft(), frameRect.topLeft());
874-
if (sunken) {
875-
// Pressed-alt button in dark mode is not a gradient, just an image consting from same $color
876-
if (darkMode) {
877-
gradient.setColorAt(0, color);
878-
gradient.setColorAt(1, color);
879-
} else {
880-
// Pressed-alt button in normal mode is not a gradient, just an image consting from same $color
881-
gradient.setColorAt(0, color);
882-
gradient.setColorAt(1, color);
883-
}
884-
} else if (mouseOver) {
885-
if (darkMode) {
886-
QColor baseColor = color;
887-
// Hovered-alt button in dark mode is a gradient from $color to darken(bg_color, 0.04)
888-
gradient.setColorAt(0, darken(baseColor, 0.04));
889-
gradient.setColorAt(1, color);
893+
if (inMenu || state == CheckOff) {
894+
// content
895+
if (color.isValid() && active) {
896+
QLinearGradient gradient(frameRect.bottomLeft(), frameRect.topLeft());
897+
if (sunken) {
898+
// Pressed-alt button in dark mode is not a gradient, just an image consting from same $color
899+
if (darkMode) {
900+
gradient.setColorAt(0, color);
901+
gradient.setColorAt(1, color);
902+
} else {
903+
// Pressed-alt button in normal mode is not a gradient, just an image consting from same $color
904+
gradient.setColorAt(0, color);
905+
gradient.setColorAt(1, color);
906+
}
907+
} else if (mouseOver) {
908+
if (darkMode) {
909+
QColor baseColor = color;
910+
// Hovered-alt button in dark mode is a gradient from $color to darken(bg_color, 0.04)
911+
gradient.setColorAt(0, darken(baseColor, 0.04));
912+
gradient.setColorAt(1, color);
913+
} else {
914+
QColor baseColor = darken(color, 0.09);
915+
// Hovered-alt button in normal mode is a gradient from $color to lighten(bg_color, 0.04)
916+
gradient.setColorAt(0, color); // FIXME:
917+
gradient.setColorAt(1, lighten(baseColor, 0.04)); // should be vice-versa, but this way it seems to be more accurate
918+
}
890919
} else {
891-
QColor baseColor = darken(color, 0.09);
892-
// Hovered-alt button in normal mode is a gradient from $color to lighten(bg_color, 0.04)
893-
gradient.setColorAt(0, color); // FIXME:
894-
gradient.setColorAt(1, lighten(baseColor, 0.04)); // should be vice-versa, but this way it seems to be more accurate
920+
if (darkMode) {
921+
QColor baseColor = lighten(color, 0.03);
922+
// Normal-alt button in dark mode is a gradient from $color to darken(bg_color, 0.06)
923+
gradient.setColorAt(0, darken(baseColor, 0.06));
924+
gradient.setColorAt(1, color);
925+
} else {
926+
QColor baseColor = darken(color, 0.05);
927+
// Normal-alt button in normal mode is a gradient from $color to bg_color
928+
gradient.setColorAt(0, baseColor);
929+
gradient.setColorAt(1, color);
930+
}
895931
}
932+
painter->setBrush(gradient);
933+
} else if (!active) {
934+
painter->setBrush(color);
896935
} else {
897-
if (darkMode) {
898-
QColor baseColor = lighten(color, 0.03);
899-
// Normal-alt button in dark mode is a gradient from $color to darken(bg_color, 0.06)
900-
gradient.setColorAt(0, darken(baseColor, 0.06));
901-
gradient.setColorAt(1, color);
902-
} else {
903-
QColor baseColor = darken(color, 0.05);
904-
// Normal-alt button in normal mode is a gradient from $color to bg_color
905-
gradient.setColorAt(0, baseColor);
906-
gradient.setColorAt(1, color);
907-
}
936+
painter->setBrush(Qt::NoBrush);
908937
}
909-
painter->setBrush(gradient);
910-
} else if (!active) {
911-
painter->setBrush(color);
912938
} else {
913-
painter->setBrush(Qt::NoBrush);
939+
if (color.isValid()) {
940+
QLinearGradient gradient(frameRect.bottomLeft(), frameRect.topLeft());
941+
gradient.setColorAt(0, color);
942+
gradient.setColorAt(1, lighten(color, 0.04));
943+
painter->setBrush(gradient);
944+
} else {
945+
painter->setBrush(Qt::NoBrush);
946+
}
914947
}
915948

916949
// render
917950
painter->drawRoundedRect(frameRect, radius, radius);
918-
919-
if (!sunken && active && color.isValid()) {
920-
painter->setPen(color.lighter(140));
921-
painter->drawLine(frameRect.topLeft() + QPoint(3, 1), frameRect.topRight() + QPoint(-3, 1));
922-
painter->setPen(outline.darker(114));
923-
painter->drawLine(frameRect.bottomLeft() + QPointF(2.7, 0), frameRect.bottomRight() + QPointF(-2.7, 0));
924-
}
925951
}
926952

927953
//______________________________________________________________________________
@@ -1127,7 +1153,7 @@ void Helper::renderCheckBoxBackground(QPainter *painter, const QRect &rect, cons
11271153

11281154
//______________________________________________________________________________
11291155
void Helper::renderCheckBox(QPainter *painter, const QRect &rect, const QColor &background, const QColor &outline, const QColor &tickColor,
1130-
bool sunken, CheckBoxState state, bool mouseOver, qreal animation, bool active, bool darkMode) const
1156+
bool sunken, CheckBoxState state, bool mouseOver, qreal animation, bool active, bool darkMode, bool inMenu) const
11311157
{
11321158
// setup painter
11331159
painter->save();
@@ -1140,7 +1166,7 @@ void Helper::renderCheckBox(QPainter *painter, const QRect &rect, const QColor &
11401166

11411167
// content
11421168
{
1143-
renderCheckBoxFrame(painter, rect, background, outline, Qt::transparent, false, sunken, mouseOver, active, darkMode);
1169+
renderCheckBoxFrame(painter, rect, background, outline, Qt::transparent, false, sunken, mouseOver, active, state, darkMode, inMenu);
11441170
}
11451171

11461172
// mark
@@ -1215,7 +1241,7 @@ void Helper::renderRadioButtonBackground(QPainter *painter, const QRect &rect, c
12151241

12161242
//______________________________________________________________________________
12171243
void Helper::renderRadioButton(QPainter *painter, const QRect &rect, const QColor &background, const QColor &outline, const QColor &tickColor,
1218-
bool sunken, bool enabled, RadioButtonState state, qreal animation, bool mouseOver, bool darkMode) const
1244+
bool sunken, bool enabled, RadioButtonState state, qreal animation, bool mouseOver, bool darkMode, bool inMenu) const
12191245
{
12201246
// setup painter
12211247
painter->setRenderHint(QPainter::Antialiasing, true);
@@ -1224,8 +1250,7 @@ void Helper::renderRadioButton(QPainter *painter, const QRect &rect, const QColo
12241250
QRectF frameRect(rect);
12251251
frameRect.adjust(2, 2, -2, -2);
12261252

1227-
// content
1228-
{
1253+
if (inMenu || state == RadioOff) {
12291254
if (background.isValid() && enabled) {
12301255
QLinearGradient gradient(frameRect.bottomLeft(), frameRect.topLeft());
12311256
if (sunken) {
@@ -1266,6 +1291,20 @@ void Helper::renderRadioButton(QPainter *painter, const QRect &rect, const QColo
12661291

12671292
painter->setPen(QPen(outline, 1));
12681293

1294+
QRectF contentRect(frameRect.adjusted(0.5, 0.5, -0.5, -0.5));
1295+
painter->drawEllipse(contentRect);
1296+
} else {
1297+
if (background.isValid()) {
1298+
QLinearGradient gradient(frameRect.bottomLeft(), frameRect.topLeft());
1299+
gradient.setColorAt(0, background);
1300+
gradient.setColorAt(1, lighten(background, 0.04));
1301+
painter->setBrush(gradient);
1302+
} else {
1303+
painter->setBrush(Qt::NoBrush);
1304+
}
1305+
1306+
painter->setPen(QPen(outline, 1));
1307+
12691308
QRectF contentRect(frameRect.adjusted(0.5, 0.5, -0.5, -0.5));
12701309
painter->drawEllipse(contentRect);
12711310
}

0 commit comments

Comments
 (0)