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
, QLineF
12 from PyQt5
.QtGui
import QPainter
, QPen
13 from PyQt5
.QtWidgets
import QGraphicsLineItem
15 from PyQt6
.QtCore
import qWarning
, Qt
, QLineF
16 from PyQt6
.QtGui
import QPainter
, QPen
17 from PyQt6
.QtWidgets
import QGraphicsLineItem
19 # ------------------------------------------------------------------------------------------------------------
36 # ------------------------------------------------------------------------------------------------------------
38 class CanvasLineMov(QGraphicsLineItem
):
39 def __init__(self
, port_mode
, port_type
, parent
):
40 QGraphicsLineItem
.__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_lineX
= self
.scenePos().x()
48 self
.p_lineY
= 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::CanvasLineMov({}, {}, {}) - invalid port type".format(
61 port_mode2str(port_mode
), port_type2str(port_type
), parent
))
64 pen
.setCapStyle(Qt
.RoundCap
)
65 pen
.setWidthF(pen
.widthF() + 0.00001)
68 def updateLinePos(self
, scenePos
):
71 if self
.m_port_mode
== PORT_MODE_INPUT
:
73 item_pos
[1] = float(canvas
.theme
.port_height
)/2
74 elif self
.m_port_mode
== PORT_MODE_OUTPUT
:
75 item_pos
[0] = self
.p_width
+ 12
76 item_pos
[1] = float(canvas
.theme
.port_height
)/2
80 line
= QLineF(item_pos
[0], item_pos
[1], scenePos
.x() - self
.p_lineX
, scenePos
.y() - self
.p_lineY
)
84 return CanvasLineMovType
86 def paint(self
, painter
, option
, widget
):
88 painter
.setRenderHint(QPainter
.Antialiasing
, bool(options
.antialiasing
))
89 QGraphicsLineItem
.paint(self
, painter
, option
, widget
)
92 # ------------------------------------------------------------------------------------------------------------