mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Make switch knob smaller than path (#2008)
to ensure contrast when we move to a lighter window-bg color.
This commit is contained in:
parent
21812556a6
commit
99f4f68aca
1 changed files with 11 additions and 12 deletions
|
@ -14,8 +14,6 @@ class Switch(QAbstractButton):
|
||||||
The suppoorted slots are toggle(), for an animated transition, and setChecked().
|
The suppoorted slots are toggle(), for an animated transition, and setChecked().
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_margin: int = 2
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
radius: int = 10,
|
radius: int = 10,
|
||||||
|
@ -33,9 +31,10 @@ class Switch(QAbstractButton):
|
||||||
self._right_label = right_label
|
self._right_label = right_label
|
||||||
self._left_color = left_color
|
self._left_color = left_color
|
||||||
self._right_color = right_color
|
self._right_color = right_color
|
||||||
self._path_radius = radius - self._margin
|
self._path_radius = radius
|
||||||
self._knob_radius = self._left_position = self._position = radius
|
self._knob_radius = radius - 1
|
||||||
self._right_position = 3 * self._path_radius + self._margin
|
self._left_position = self._position = radius
|
||||||
|
self._right_position = 3 * self._path_radius
|
||||||
|
|
||||||
@pyqtProperty(int) # type: ignore
|
@pyqtProperty(int) # type: ignore
|
||||||
def position(self) -> int:
|
def position(self) -> int:
|
||||||
|
@ -65,8 +64,8 @@ class Switch(QAbstractButton):
|
||||||
|
|
||||||
def sizeHint(self) -> QSize:
|
def sizeHint(self) -> QSize:
|
||||||
return QSize(
|
return QSize(
|
||||||
4 * self._path_radius + 2 * self._margin,
|
4 * self._path_radius,
|
||||||
2 * self._path_radius + 2 * self._margin,
|
2 * self._path_radius,
|
||||||
)
|
)
|
||||||
|
|
||||||
def setChecked(self, checked: bool) -> None:
|
def setChecked(self, checked: bool) -> None:
|
||||||
|
@ -85,17 +84,17 @@ class Switch(QAbstractButton):
|
||||||
def _paint_path(self, painter: QPainter) -> None:
|
def _paint_path(self, painter: QPainter) -> None:
|
||||||
painter.setBrush(QBrush(self.path_color))
|
painter.setBrush(QBrush(self.path_color))
|
||||||
rectangle = QRectF(
|
rectangle = QRectF(
|
||||||
self._margin,
|
0,
|
||||||
self._margin,
|
0,
|
||||||
self.width() - 2 * self._margin,
|
self.width(),
|
||||||
self.height() - 2 * self._margin,
|
self.height(),
|
||||||
)
|
)
|
||||||
painter.drawRoundedRect(rectangle, self._path_radius, self._path_radius)
|
painter.drawRoundedRect(rectangle, self._path_radius, self._path_radius)
|
||||||
|
|
||||||
def _current_knob_rectangle(self) -> QRectF:
|
def _current_knob_rectangle(self) -> QRectF:
|
||||||
return QRectF(
|
return QRectF(
|
||||||
self.position - self._knob_radius, # type: ignore
|
self.position - self._knob_radius, # type: ignore
|
||||||
0,
|
1,
|
||||||
2 * self._knob_radius,
|
2 * self._knob_radius,
|
||||||
2 * self._knob_radius,
|
2 * self._knob_radius,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue