Skip to content

Commit

Permalink
penwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Sep 1, 2023
1 parent 4cf84cf commit f03cc95
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from src.main.python.plotlyst.view.common import tool_btn
from src.main.python.plotlyst.view.icons import IconRegistry
from src.main.python.plotlyst.view.widget.graphics import BaseItemEditor, SolidPenStyleSelector, DashPenStyleSelector, \
DotPenStyleSelector, ConnectorItem
DotPenStyleSelector, ConnectorItem, PenWidthEditor


class ConnectorEditor(BaseItemEditor):
Expand All @@ -45,11 +45,16 @@ def __init__(self, parent=None):
self._lineBtnGroup.addButton(self._dotLine)
self._lineBtnGroup.buttonClicked.connect(self._penStyleChanged)

self._sbWidth = PenWidthEditor()
self._sbWidth.valueChanged.connect(self._widthChanged)

self._toolbar.layout().addWidget(self._btnColor)
self._toolbar.layout().addWidget(vline())
self._toolbar.layout().addWidget(self._solidLine)
self._toolbar.layout().addWidget(self._dashLine)
self._toolbar.layout().addWidget(self._dotLine)
self._toolbar.layout().addWidget(vline())
self._toolbar.layout().addWidget(self._sbWidth)

def setItem(self, connector: ConnectorItem):
self._connector = connector
Expand All @@ -58,3 +63,6 @@ def _penStyleChanged(self):
btn = self._lineBtnGroup.checkedButton()
if btn:
self._connector.setPenStyle(btn.penStyle())

def _widthChanged(self, value: int):
self._connector.setPenWidth(value)
28 changes: 21 additions & 7 deletions src/main/python/plotlyst/view/widget/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
QKeyEvent, QPolygonF, QPaintEvent
from PyQt6.QtWidgets import QGraphicsView, QAbstractGraphicsShapeItem, QGraphicsItem, QGraphicsPathItem, QFrame, \
QToolButton, QApplication, QGraphicsScene, QGraphicsSceneMouseEvent, QStyleOptionGraphicsItem, QWidget, \
QGraphicsRectItem, QGraphicsSceneHoverEvent, QGraphicsPolygonItem, QAbstractButton
QGraphicsRectItem, QGraphicsSceneHoverEvent, QGraphicsPolygonItem, QAbstractButton, QSlider
from overrides import overrides
from qthandy import hbox, margins, sp, incr_icon, vbox

Expand Down Expand Up @@ -148,12 +148,12 @@ def __init__(self, source: QAbstractGraphicsShapeItem, target: QAbstractGraphics
else:
self.setPen(QPen(QColor(Qt.GlobalColor.darkBlue), 2))

arrowhead = QPolygonF([
QPointF(-10, -5),
QPointF(0, 0),
QPointF(-10, 5),
self._arrowhead = QPolygonF([
QPointF(0, -5),
QPointF(10, 0),
QPointF(0, 5),
])
self._arrowheadItem = QGraphicsPolygonItem(arrowhead, self)
self._arrowheadItem = QGraphicsPolygonItem(self._arrowhead, self)
self._arrowheadItem.setPen(QPen(QColor(Qt.GlobalColor.darkBlue), 1))
self._arrowheadItem.setBrush(QColor(Qt.GlobalColor.darkBlue))

Expand All @@ -169,7 +169,13 @@ def setPenWidth(self, width: int):
pen = self.pen()
pen.setWidth(width)
self.setPen(pen)
self.update()

arrowPen = self._arrowheadItem.pen()
prevWidth = arrowPen.width()
arrowPen.setWidth(width)
self._arrowheadItem.setScale(1.0 + (width - prevWidth) / 10)

self.rearrange()

def rearrange(self):
self.setPos(self._source.sceneBoundingRect().center())
Expand Down Expand Up @@ -647,3 +653,11 @@ class DotPenStyleSelector(PenStyleSelector):
@overrides
def penStyle(self) -> Qt.PenStyle:
return Qt.PenStyle.DotLine


class PenWidthEditor(QSlider):
def __init__(self, parent=None):
super().__init__(parent)
self.setMinimum(1)
self.setMaximum(10)
self.setOrientation(Qt.Orientation.Horizontal)

0 comments on commit f03cc95

Please sign in to comment.