From 12d6679662d4968c3865273f86825f452c5c7227 Mon Sep 17 00:00:00 2001 From: Zsolt Kovari Date: Sun, 3 Sep 2023 12:07:56 +0200 Subject: [PATCH] icon selector --- .../view/widget/character/network/editor.py | 9 ++++++ .../python/plotlyst/view/widget/graphics.py | 32 +++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/python/plotlyst/view/widget/character/network/editor.py b/src/main/python/plotlyst/view/widget/character/network/editor.py index 33ba5e00a..8af72aae2 100644 --- a/src/main/python/plotlyst/view/widget/character/network/editor.py +++ b/src/main/python/plotlyst/view/widget/character/network/editor.py @@ -27,6 +27,7 @@ from src.main.python.plotlyst.core.domain import RelationsNetwork, Relation from src.main.python.plotlyst.view.common import tool_btn, action +from src.main.python.plotlyst.view.dialog.utility import IconSelectorDialog from src.main.python.plotlyst.view.icons import IconRegistry from src.main.python.plotlyst.view.widget.graphics import BaseItemEditor, SolidPenStyleSelector, DashPenStyleSelector, \ DotPenStyleSelector, ConnectorItem, PenWidthEditor, RelationsButton @@ -65,6 +66,8 @@ def __init__(self, network: RelationsNetwork, parent=None): self._btnColor = tool_btn(IconRegistry.from_name('fa5s.circle', color='darkBlue'), 'Change style', transparent_=True) + self._btnIcon = tool_btn(IconRegistry.from_name('mdi.emoticon-outline'), 'Change icon', transparent_=True) + self._btnIcon.clicked.connect(self._showIconSelector) self._solidLine = SolidPenStyleSelector() self._dashLine = DashPenStyleSelector() @@ -84,6 +87,7 @@ def __init__(self, network: RelationsNetwork, parent=None): self._toolbar.layout().addWidget(self._btnRelationType) self._toolbar.layout().addWidget(vline()) self._toolbar.layout().addWidget(self._btnColor) + self._toolbar.layout().addWidget(self._btnIcon) self._toolbar.layout().addWidget(vline()) self._toolbar.layout().addWidget(self._solidLine) self._toolbar.layout().addWidget(self._dashLine) @@ -121,3 +125,8 @@ def _penStyleChanged(self): def _widthChanged(self, value: int): if self._connector: self._connector.setPenWidth(value) + + def _showIconSelector(self): + result = IconSelectorDialog().display() + if result and self._connector: + self._connector.setIcon(IconRegistry.from_name(result[0], result[1].name())) \ No newline at end of file diff --git a/src/main/python/plotlyst/view/widget/graphics.py b/src/main/python/plotlyst/view/widget/graphics.py index 2be89ea18..2792b6f4b 100644 --- a/src/main/python/plotlyst/view/widget/graphics.py +++ b/src/main/python/plotlyst/view/widget/graphics.py @@ -65,11 +65,12 @@ def __init__(self, parent=None): super().__init__(parent) self._size: int = 32 self._icon: Optional[QIcon] = None - self._color: str = 'blue' + self._color: str = 'black' - def setIcon(self, icon_name: str, color: str): - self._icon = IconRegistry.from_name(icon_name, color) - self._color = color + def setIcon(self, icon: QIcon, borderColor: Optional[str] = None): + self._icon = icon + if borderColor: + self._color = borderColor self.update() @overrides @@ -177,11 +178,13 @@ def __init__(self, source: AbstractSocketItem, target: AbstractSocketItem, self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable) self._source = source self._target = target + self._color: str = 'darkblue' + self._relation: Optional[Relation] = None + self._icon: Optional[QIcon] = None if pen: self.setPen(pen) else: - self.setPen(QPen(QColor(Qt.GlobalColor.darkBlue), 2)) - self._relation: Optional[Relation] = None + self.setPen(QPen(QColor(self._color), 2)) self._arrowhead = QPolygonF([ QPointF(0, -5), @@ -235,11 +238,22 @@ def setRelation(self, relation: Relation): self._arrowheadItem.setPen(arrowPen) self._relation = relation - self._iconBadge.setIcon(relation.icon, relation.icon_color) + self._icon = IconRegistry.from_name(relation.icon, relation.icon_color) + self._color = relation.icon_color + self._iconBadge.setIcon(self._icon, self._color) self._iconBadge.setVisible(True) self.rearrange() + def icon(self) -> Optional[QIcon]: + return self._icon + + def setIcon(self, icon: QIcon): + self._icon = icon + self._iconBadge.setIcon(self._icon, self._color) + self._iconBadge.setVisible(True) + self.rearrange() + def rearrange(self): self.setPos(self._source.sceneBoundingRect().center()) @@ -261,12 +275,12 @@ def rearrange(self): path.quadTo(0, height / 2, width, height) else: path.quadTo(width / 2, -height / 2, width, height) - angle = math.degrees(math.atan2(-height / 2, width/2)) + angle = math.degrees(math.atan2(-height / 2, width / 2)) self._arrowheadItem.setPos(width, height) self._arrowheadItem.setRotation(-angle) - if self._relation: + if self._icon: if line: point = path.pointAtPercent(0.4) else: