Skip to content

Commit

Permalink
restore connector editor
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 2, 2023
1 parent c2952de commit ffdf887
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
57 changes: 47 additions & 10 deletions src/main/python/plotlyst/view/widget/character/network/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from typing import Optional

from PyQt6.QtCore import pyqtSignal
from PyQt6.QtWidgets import QButtonGroup
from PyQt6.QtWidgets import QButtonGroup, QToolButton
from qthandy import vline

from src.main.python.plotlyst.core.domain import RelationsNetwork, Relation
Expand All @@ -34,21 +34,41 @@ class RelationSelector(SecondarySelectorWidget):
relationSelected = pyqtSignal(Relation)

def __init__(self, network: RelationsNetwork, parent=None):
super().__init__(parent)
super().__init__(parent, optional=True)
self._network = network
self._romance = Relation('Romance', icon='ei.heart', icon_color='#d1495b')
self._friendship = Relation('Friendship', icon='fa5s.user-friends', icon_color='#457b9d')
self._sidekick = Relation('Sidekick', icon='ei.asl', icon_color='#b0a990')
self._guide = Relation('Guide', icon='mdi.compass-rose', icon_color='#80ced7')
self._newRelationButton(self._romance, 0, 0)
self._newRelationButton(self._friendship, 0, 1)
self._newRelationButton(self._sidekick, 0, 2)
self._newRelationButton(self._guide, 1, 0)

def _newRelationButton(self, relation: Relation, row: int, col: int):
self._btnRomance = self._newRelationButton(self._romance, 0, 0)
self._btnFriendship = self._newRelationButton(self._friendship, 0, 1)
self._btnSidekick = self._newRelationButton(self._sidekick, 0, 2)
self._btnGuide = self._newRelationButton(self._guide, 1, 0)

def _newRelationButton(self, relation: Relation, row: int, col: int) -> QToolButton:
btn = self._newButton(IconRegistry.from_name(relation.icon), relation.text, row, col)
btn.clicked.connect(lambda: self.relationSelected.emit(relation))

return btn

def selectRelation(self, relation: Relation):
if relation == self._romance:
self._btnRomance.setChecked(True)
elif relation == self._friendship:
self._btnFriendship.setChecked(True)
elif relation == self._sidekick:
self._btnSidekick.setChecked(True)
elif relation == self._guide:
self._btnGuide.setChecked(True)
else:
self.reset()

def reset(self):
btn = self._btnGroup.checkedButton()
if btn:
btn.setChecked(False)


class ConnectorEditor(BaseItemEditor):
def __init__(self, network: RelationsNetwork, parent=None):
Expand Down Expand Up @@ -87,15 +107,32 @@ def __init__(self, network: RelationsNetwork, parent=None):
self._toolbar.layout().addWidget(self._sbWidth)

def setItem(self, connector: ConnectorItem):
self._connector = None
self._hideSecondarySelectors()

self._sbWidth.setValue(connector.penWidth())
relation = connector.relation()
if relation:
self._relationSelector.selectRelation(relation)
else:
self._relationSelector.reset()

penStyle = connector.penStyle()
for line in [self._solidLine, self._dashLine, self._dotLine]:
if penStyle == line.penStyle():
line.setChecked(True)
break
self._connector = connector

def _relationChanged(self, relation: Relation):
self._connector.setRelation(relation)
if self._connector:
self._connector.setRelation(relation)

def _penStyleChanged(self):
btn = self._lineBtnGroup.checkedButton()
if btn:
if btn and self._connector:
self._connector.setPenStyle(btn.penStyle())

def _widthChanged(self, value: int):
self._connector.setPenWidth(value)
if self._connector:
self._connector.setPenWidth(value)
16 changes: 14 additions & 2 deletions src/main/python/plotlyst/view/widget/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,18 @@ def __init__(self, source: QAbstractGraphicsShapeItem, target: QAbstractGraphics

self.rearrange()

def penStyle(self) -> Qt.PenStyle:
return self.pen().style()

def setPenStyle(self, penStyle: Qt.PenStyle):
pen = self.pen()
pen.setStyle(penStyle)
self.setPen(pen)
self.update()

def penWidth(self) -> int:
return self.pen().width()

def setPenWidth(self, width: int):
pen = self.pen()
pen.setWidth(width)
Expand All @@ -208,6 +214,9 @@ def setPenWidth(self, width: int):

self.rearrange()

def relation(self) -> Optional[Relation]:
return self._relation

def setRelation(self, relation: Relation):
pen = self.pen()
color = QColor(relation.icon_color)
Expand Down Expand Up @@ -632,15 +641,18 @@ def __init__(self, parent=None):
class SecondarySelectorWidget(QFrame):
selected = pyqtSignal(NetworkItemType)

def __init__(self, parent=None):
def __init__(self, parent=None, optional: bool = False):
super().__init__(parent)
self.setProperty('relaxed-white-bg', True)
self.setProperty('rounded', True)
shadow(self)
self._grid = grid(self, h_spacing=5, v_spacing=3)
margins(self, left=5, right=5)

self._btnGroup = QButtonGroup()
if optional:
self._btnGroup = ExclusiveOptionalButtonGroup()
else:
self._btnGroup = QButtonGroup()

def _newButton(self, icon: QIcon, tooltip: str, row: int,
col: int) -> QToolButton:
Expand Down

0 comments on commit ffdf887

Please sign in to comment.