Skip to content

Commit aaa3fe7

Browse files
committed
fix(ui): add always_dark property for buttons, used for banner action button
1 parent 6d5e385 commit aaa3fe7

4 files changed

Lines changed: 38 additions & 17 deletions

File tree

‎src/tagstudio/qt/views/banner_view.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tagstudio.i18n.translations import Translations
99
from tagstudio.qt.controllers.rounded_progress_bar import RoundedProgressBar
1010
from tagstudio.qt.controllers.stable_label import StableLabel
11+
from tagstudio.qt.views.styles.tagstudio_style import set_always_dark
1112
from tagstudio.qt.views.styles.widget_effects import DEBOSSED_OUTLINE_WIDTH
1213

1314

@@ -41,6 +42,7 @@ def __init__(self) -> None:
4142
self.action_button = QPushButton(Translations["entries.generic.refresh_alt"])
4243
self.action_button.setObjectName("bannerActionButton")
4344
self.action_button.setFocusPolicy(Qt.FocusPolicy.TabFocus)
45+
set_always_dark(self.action_button)
4446
content_row.addWidget(self.action_button)
4547

4648
content_row.addStretch(1)

‎src/tagstudio/qt/views/styles/stylesheets.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def banner_notice_style() -> str:
274274

275275
return f"""
276276
#banner QLabel {{ color: rgba{text_color.toTuple()}; background: transparent; }}
277+
QPushButton#bannerActionButton {{ color: rgba{text_color.toTuple()}; }}
277278
{banner_close_button_style()}
278279
"""
279280

‎src/tagstudio/qt/views/styles/tagstudio_style.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def set_checked_by_icon(button: QPushButton, by_icon: bool) -> None:
157157
button.update()
158158

159159

160+
def set_always_dark(button: QPushButton) -> None:
161+
"""Draw a button's panel in the dark theme's style, regardless of theme set."""
162+
button.setProperty("always_dark", True) # noqa: FBT003
163+
button.update()
164+
165+
160166
def set_swatch(button: QAbstractButton) -> None:
161167
"""Draw a checkbox or radio button's indicator as a raised color swatch."""
162168
button.setProperty("is_swatch", True) # noqa: FBT003
@@ -215,7 +221,8 @@ def drawPrimitive(
215221
if joined_edges:
216222
self._draw_joined_panel(option, painter, radius, joined_edges)
217223
else:
218-
self._draw_panel(option, painter, radius)
224+
always_dark = bool(widget.property("always_dark"))
225+
self._draw_panel(option, painter, radius, always_dark=always_dark)
219226
else:
220227
radius = self._radius(widget, RADIUS)
221228
self._draw_capsule(option, painter, colors, radius)
@@ -391,12 +398,15 @@ def _draw_panel(
391398
painter: QPainter,
392399
radius: float,
393400
style: SurfaceStyle = SurfaceStyle.EMBOSSED,
401+
always_dark: bool = False,
394402
) -> None:
395403
is_down = bool(option.state & (_State.State_Sunken | _State.State_On))
396404
under_mouse = bool(option.state & _State.State_MouseOver)
397405
painter.save()
398406
self._fade_if_disabled(option, painter)
399-
self._effect.paint_surface(painter, option.rect, radius, is_down, under_mouse, style)
407+
self._effect.paint_surface(
408+
painter, option.rect, radius, is_down, under_mouse, style, always_dark
409+
)
400410
painter.restore()
401411

402412
def _draw_joined_panel(

‎src/tagstudio/qt/views/styles/widget_effects.py‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ def widget_drop_shadow(widget: QWidget) -> None:
180180
widget.setGraphicsEffect(shadow)
181181

182182

183-
def _embossed_fill(is_down: bool, under_mouse: bool) -> QColor:
183+
def _embossed_fill(is_down: bool, under_mouse: bool, is_dark: bool) -> QColor:
184184
"""An embossed surface's fill color."""
185-
is_dark = is_dark_theme()
186185
alpha = _EMBOSSED_FILL_ALPHA_DARK if is_dark else _EMBOSSED_FILL_ALPHA_LIGHT
187186
if is_down:
188187
alpha //= 2
@@ -264,12 +263,16 @@ def paint_surface(
264263
is_down: bool = False,
265264
under_mouse: bool = False,
266265
style: SurfaceStyle = SurfaceStyle.EMBOSSED,
266+
always_dark: bool = False,
267267
) -> None:
268268

269269
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
270270
strength = _gradient_strength(rect.height(), style)
271-
self._paint_background(painter, rect, radius, is_down, under_mouse, style, strength)
272-
self.paint_outlines(painter, rect, radius, is_down, under_mouse, style)
271+
is_dark = always_dark or is_dark_theme()
272+
self._paint_background(
273+
painter, rect, radius, is_down, under_mouse, is_dark, style, strength
274+
)
275+
self.paint_outlines(painter, rect, radius, is_down, under_mouse, style, always_dark)
273276

274277
def paint_outlines(
275278
self,
@@ -279,6 +282,7 @@ def paint_outlines(
279282
is_down: bool = False,
280283
under_mouse: bool = False,
281284
style: SurfaceStyle = SurfaceStyle.EMBOSSED,
285+
always_dark: bool = False,
282286
) -> None:
283287
"""Paint a surface's inner and outer outlines.
284288
@@ -287,8 +291,11 @@ def paint_outlines(
287291
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
288292
rectf = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5)
289293
strength = _gradient_strength(rect.height(), style)
290-
self._paint_outer_outline(painter, rectf, radius, is_down, under_mouse, style, strength)
291-
self._paint_inner_outline(painter, rectf, radius, is_down, style, strength)
294+
is_dark = always_dark or is_dark_theme()
295+
self._paint_outer_outline(
296+
painter, rectf, radius, is_down, under_mouse, is_dark, style, strength
297+
)
298+
self._paint_inner_outline(painter, rectf, radius, is_down, is_dark, style, strength)
292299

293300
def paint_debossed(self, painter: QPainter, rect: QRect, radius: float, color: QColor) -> None:
294301
"""Paint a colored debossed surface."""
@@ -320,6 +327,7 @@ def _paint_background(
320327
radius: float,
321328
is_down: bool,
322329
under_mouse: bool,
330+
is_dark: bool,
323331
style: SurfaceStyle = SurfaceStyle.EMBOSSED,
324332
strength: float = 1.0,
325333
) -> None:
@@ -336,15 +344,15 @@ def _paint_background(
336344
else:
337345
top_alpha = _EMBOSSED_GRADIENT_TOP_ALPHA
338346

339-
painter.setBrush(_embossed_fill(is_down, under_mouse))
347+
painter.setBrush(_embossed_fill(is_down, under_mouse, is_dark))
340348
painter.drawPath(path)
341349
gradient = QLinearGradient(
342350
rectf.topLeft() if not is_down else rectf.bottomLeft(),
343351
rectf.bottomLeft() if not is_down else rectf.topLeft(),
344352
)
345353
bottom_alpha = (
346354
_EMBOSSED_GRADIENT_BOTTOM_ALPHA_DARK
347-
if is_dark_theme()
355+
if is_dark
348356
else _EMBOSSED_GRADIENT_BOTTOM_ALPHA_LIGHT
349357
)
350358
_set_stops(
@@ -355,9 +363,7 @@ def _paint_background(
355363
elif style == SurfaceStyle.DEBOSSED:
356364
gradient = QLinearGradient(rectf.topLeft(), rectf.bottomLeft())
357365
top_alpha, bottom_alpha = (
358-
_DEBOSSED_GRADIENT_ALPHAS_DARK
359-
if is_dark_theme()
360-
else _DEBOSSED_GRADIENT_ALPHAS_LIGHT
366+
_DEBOSSED_GRADIENT_ALPHAS_DARK if is_dark else _DEBOSSED_GRADIENT_ALPHAS_LIGHT
361367
)
362368
_set_stops(
363369
gradient, QColor(0, 0, 0, top_alpha), QColor(0, 0, 0, bottom_alpha), strength
@@ -373,6 +379,7 @@ def _paint_outer_outline(
373379
radius: float,
374380
is_down: bool,
375381
under_mouse: bool,
382+
is_dark: bool,
376383
style: SurfaceStyle = SurfaceStyle.EMBOSSED,
377384
strength: float = 1.0,
378385
) -> None:
@@ -382,7 +389,7 @@ def _paint_outer_outline(
382389

383390
gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft())
384391
if style == SurfaceStyle.EMBOSSED:
385-
if is_dark_theme():
392+
if is_dark:
386393
top_alpha, bottom_alpha = _EMBOSSED_OUTER_OUTLINE_ALPHAS_DARK
387394
elif under_mouse and not is_down:
388395
top_alpha, bottom_alpha = _EMBOSSED_OUTER_OUTLINE_ALPHAS_HOVER_LIGHT
@@ -394,7 +401,7 @@ def _paint_outer_outline(
394401
elif style == SurfaceStyle.DEBOSSED:
395402
top_alpha, bottom_alpha = (
396403
_DEBOSSED_OUTER_OUTLINE_ALPHAS_DARK
397-
if is_dark_theme()
404+
if is_dark
398405
else _DEBOSSED_OUTER_OUTLINE_ALPHAS_LIGHT
399406
)
400407
_set_stops(
@@ -417,6 +424,7 @@ def _paint_inner_outline(
417424
rect: QRectF,
418425
radius: float,
419426
is_down: bool,
427+
is_dark: bool,
420428
style: SurfaceStyle = SurfaceStyle.EMBOSSED,
421429
strength: float = 1.0,
422430
) -> None:
@@ -434,7 +442,7 @@ def _paint_inner_outline(
434442
if style == SurfaceStyle.EMBOSSED:
435443
top_alpha, bottom_alpha = (
436444
_EMBOSSED_INNER_OUTLINE_ALPHAS_DARK
437-
if is_dark_theme()
445+
if is_dark
438446
else _EMBOSSED_INNER_OUTLINE_ALPHAS_LIGHT
439447
)
440448
_set_stops(
@@ -446,7 +454,7 @@ def _paint_inner_outline(
446454
elif style == SurfaceStyle.DEBOSSED:
447455
top_alpha, bottom_alpha = (
448456
_DEBOSSED_INNER_OUTLINE_ALPHAS_DARK
449-
if is_dark_theme()
457+
if is_dark
450458
else _DEBOSSED_INNER_OUTLINE_ALPHAS_LIGHT
451459
)
452460
_set_stops(

0 commit comments

Comments
 (0)