Add theme update handling to manuscript build tool

This commit is contained in:
Veronica Berglyd Olsen
2025-10-26 02:00:04 +01:00
parent 9339c9ff62
commit e492c6575d
5 changed files with 76 additions and 34 deletions
+7 -5
View File
@@ -34,7 +34,7 @@ from novelwriter.types import QtNoPen, QtPaintAntiAlias, QtSizeFixed
class NSwitch(QAbstractButton):
"""Custom: Toggle Switch."""
__slots__ = ("_cOff", "_cOn", "_offset", "_rH", "_rR", "_xH", "_xR", "_xW")
__slots__ = ("_offset", "_rH", "_rR", "_xH", "_xR", "_xW")
def __init__(self, parent: QWidget, height: int = 0) -> None:
super().__init__(parent=parent)
@@ -45,13 +45,11 @@ class NSwitch(QAbstractButton):
self._rH = self._xH - 4
self._rR = self._xR - 2
self._cOn = SHARED.theme.accentCol
self._cOff = self.palette().alternateBase()
self.setCheckable(True)
self.setSizePolicy(QtSizeFixed, QtSizeFixed)
self.setFixedWidth(self._xW)
self.setFixedHeight(self._xH)
self.setUpdatesEnabled(True)
self._offset = self._xR
self.clicked.connect(self._onClick)
@@ -96,7 +94,7 @@ class NSwitch(QAbstractButton):
painter.setOpacity(1.0 if self.isEnabled() else 0.5)
painter.setPen(palette.highlight().color() if self.hasFocus() else palette.mid().color())
painter.setBrush(self._cOn if self.isChecked() else self._cOff)
painter.setBrush(SHARED.theme.accentCol if self.isChecked() else palette.alternateBase())
painter.drawRoundedRect(0, 0, self._xW, self._xH, self._xR, self._xR)
painter.setPen(QtNoPen)
@@ -110,6 +108,10 @@ class NSwitch(QAbstractButton):
self.setCursor(Qt.CursorShape.PointingHandCursor)
super().enterEvent(event)
##
# Internal Functions
##
@pyqtSlot(bool)
def _onClick(self, checked: bool) -> None:
"""Animate the toggle action."""