Skip to content

Commit

Permalink
icon selector
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 3, 2023
1 parent 8d3c153 commit 12d6679
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()))
32 changes: 23 additions & 9 deletions src/main/python/plotlyst/view/widget/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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())

Expand All @@ -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:
Expand Down

0 comments on commit 12d6679

Please sign in to comment.