2 # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # ------------------------------------------------------------------------------------------------------------
8 from qt_compat
import qt_config
11 from PyQt5
.QtCore
import qWarning
, Qt
, QPointF
12 from PyQt5
.QtGui
import QPainter
, QPainterPath
, QPen
13 from PyQt5
.QtWidgets
import QGraphicsPathItem
15 from PyQt6
.QtCore
import qWarning
, Qt
, QPointF
16 from PyQt6
.QtGui
import QPainter
, QPainterPath
, QPen
17 from PyQt6
.QtWidgets
import QGraphicsPathItem
19 # ------------------------------------------------------------------------------------------------------------
27 CanvasBezierLineMovType
,
36 # ------------------------------------------------------------------------------------------------------------
38 class CanvasBezierLineMov(QGraphicsPathItem
):
39 def __init__(self
, port_mode
, port_type
, parent
):
40 QGraphicsPathItem
.__init
__(self
)
41 self
.setParentItem(parent
)
43 self
.m_port_mode
= port_mode
44 self
.m_port_type
= port_type
46 # Port position doesn't change while moving around line
47 self
.p_itemX
= self
.scenePos().x()
48 self
.p_itemY
= self
.scenePos().y()
49 self
.p_width
= parent
.getPortWidth()
51 if port_type
== PORT_TYPE_AUDIO_JACK
:
52 pen
= QPen(canvas
.theme
.line_audio_jack
, 2)
53 elif port_type
== PORT_TYPE_MIDI_JACK
:
54 pen
= QPen(canvas
.theme
.line_midi_jack
, 2)
55 elif port_type
== PORT_TYPE_MIDI_ALSA
:
56 pen
= QPen(canvas
.theme
.line_midi_alsa
, 2)
57 elif port_type
== PORT_TYPE_PARAMETER
:
58 pen
= QPen(canvas
.theme
.line_parameter
, 2)
60 qWarning("PatchCanvas::CanvasBezierLineMov({}, {}, {}) - invalid port type".format(
61 port_mode2str(port_mode
), port_type2str(port_type
), parent
))
64 pen
.setCapStyle(Qt
.FlatCap
)
65 pen
.setWidthF(pen
.widthF() + 0.00001)
68 def updateLinePos(self
, scenePos
):
69 if self
.m_port_mode
== PORT_MODE_INPUT
:
71 old_y
= float(canvas
.theme
.port_height
)/2
72 mid_x
= abs(scenePos
.x() - self
.p_itemX
) / 2
74 elif self
.m_port_mode
== PORT_MODE_OUTPUT
:
75 old_x
= self
.p_width
+ 12
76 old_y
= float(canvas
.theme
.port_height
)/2
77 mid_x
= abs(scenePos
.x() - (self
.p_itemX
+ old_x
)) / 2
82 final_x
= scenePos
.x() - self
.p_itemX
83 final_y
= scenePos
.y() - self
.p_itemY
85 path
= QPainterPath(QPointF(old_x
, old_y
))
86 path
.cubicTo(new_x
, old_y
, new_x
, final_y
, final_x
, final_y
)
90 return CanvasBezierLineMovType
92 def paint(self
, painter
, option
, widget
):
94 painter
.setRenderHint(QPainter
.Antialiasing
, bool(options
.antialiasing
))
95 QGraphicsPathItem
.paint(self
, painter
, option
, widget
)
98 # ------------------------------------------------------------------------------------------------------------