Skip to content

Commit

Permalink
Fix local icon scale not being taken into consideration
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtryb committed May 5, 2024
1 parent d985476 commit 8ab4b82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
18 changes: 9 additions & 9 deletions shortcut_composer/templates/pie_menu_utils/pie_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class PieStyle:

def __init__(
self,
unscaled_label_style: LabelWidgetStyle,
label_style: LabelWidgetStyle,
pie_radius_callback: Callable[[], int],
deadzone_radius_callback: Callable[[], float],
settings_button_radius_callback: Callable[[], int],
accept_button_radius_callback: Callable[[], int],
background_opacity_callback: Callable[[], int],
) -> None:
self._unscaled_label_style = unscaled_label_style
self._label_style = label_style

self._pie_radius_callback = pie_radius_callback
self._deadzone_radius_callback = deadzone_radius_callback
Expand Down Expand Up @@ -56,12 +56,12 @@ def accept_button_radius(self) -> int:
@property
def widget_radius(self) -> int:
"""Radius of the entire widget, including base and the icons."""
return self.pie_radius + self._unscaled_label_style.icon_radius
return self.pie_radius + self._label_style.icon_radius

@property
def border_thickness(self) -> int:
"""Thickness of border of the pie."""
return self._unscaled_label_style.border_thickness
return self._label_style.border_thickness

@property
def decorator_thickness(self) -> int:
Expand All @@ -81,12 +81,12 @@ def inner_edge_radius(self) -> int:
@property
def active_color(self) -> QColor:
"""Color of active elements."""
return self._unscaled_label_style.active_color
return self._label_style.active_color

@property
def background_color(self) -> QColor:
"""Color of the widget background."""
opaque = self._unscaled_label_style.background_color
opaque = self._label_style.background_color
return QColor(
opaque.red(),
opaque.green(),
Expand All @@ -96,17 +96,17 @@ def background_color(self) -> QColor:
@property
def active_color_dark(self) -> QColor:
"""Color variation of active element."""
return self._unscaled_label_style.active_color_dark
return self._label_style.active_color_dark

@property
def border_color(self) -> QColor:
"""Color of the active pie border."""
return self._unscaled_label_style.border_color
return self._label_style.border_color

@property
def background_decorator_color(self) -> QColor:
"""Color of decorator near inner edge."""
color = self._unscaled_label_style.background_color
color = self._label_style.background_color
color = QColor(color.red()-5, color.green()-5, color.blue()-5, 60)
return color

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, pie_config: PieConfig) -> None:
active_color_callback=self._active_color,
background_color_callback=self._background_color)
self.pie_style = PieStyle(
unscaled_label_style=self.unscaled_label_style,
label_style=self.label_style,
pie_radius_callback=self._pie_radius,
deadzone_radius_callback=self._deadzone_radius,
settings_button_radius_callback=self._settings_button_radius,
Expand Down Expand Up @@ -59,7 +59,11 @@ def _icon_radius(self) -> int:
max_radius = round(
self.pie_style.pie_radius * math.pi / len(elements))

return min(self._unscaled_icon_radius(), max_radius)
desired_radius = round(
self._unscaled_icon_radius()
* self._pie_config.ICON_RADIUS_SCALE.read())

return min(desired_radius, max_radius)

def _border_thickness(self) -> int:
"""Return border thickness based on configured value."""
Expand Down
12 changes: 9 additions & 3 deletions shortcut_composer/templates/pie_menu_utils/pie_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import TypeVar, Generic

from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtGui import (
QDragEnterEvent,
QDragLeaveEvent,
Expand Down Expand Up @@ -67,6 +67,7 @@ def __init__(

self._config.PIE_RADIUS_SCALE.register_callback(self._reset)
self._config.ICON_RADIUS_SCALE.register_callback(self._reset)
self._config.ORDER.register_callback(self._reset)
Config.PIE_GLOBAL_SCALE.register_callback(self._reset)
Config.PIE_ICON_GLOBAL_SCALE.register_callback(self._reset)

Expand Down Expand Up @@ -170,5 +171,10 @@ def _type(self) -> type | None:

def _reset(self) -> None:
"""Set widget geometry according to style."""
diameter = 2*self._style_holder.pie_style.widget_radius
self.resize(diameter, diameter)
radius = self._style_holder.pie_style.widget_radius
difference = radius - self.width()//2
new_center = QPoint(
self.center_global.x() - difference,
self.center_global.y())
self.resize(2*radius, 2*radius)
self.move_center(new_center)

0 comments on commit 8ab4b82

Please sign in to comment.