Cleanup
[carla.git] / source / frontend / patchcanvas / canvaslinemov.py
blobbd1b39e95f5a34bc628f4e874a8fbf4ba2ee9170
1 #!/usr/bin/env python3
2 # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # ------------------------------------------------------------------------------------------------------------
6 # Imports (Global)
8 from qt_compat import qt_config
10 if qt_config == 5:
11 from PyQt5.QtCore import qWarning, Qt, QLineF
12 from PyQt5.QtGui import QPainter, QPen
13 from PyQt5.QtWidgets import QGraphicsLineItem
14 elif qt_config == 6:
15 from PyQt6.QtCore import qWarning, Qt, QLineF
16 from PyQt6.QtGui import QPainter, QPen
17 from PyQt6.QtWidgets import QGraphicsLineItem
19 # ------------------------------------------------------------------------------------------------------------
20 # Imports (Custom)
22 from . import (
23 canvas,
24 options,
25 port_mode2str,
26 port_type2str,
27 CanvasLineMovType,
28 PORT_MODE_INPUT,
29 PORT_MODE_OUTPUT,
30 PORT_TYPE_AUDIO_JACK,
31 PORT_TYPE_MIDI_ALSA,
32 PORT_TYPE_MIDI_JACK,
33 PORT_TYPE_PARAMETER,
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)
59 else:
60 qWarning("PatchCanvas::CanvasLineMov({}, {}, {}) - invalid port type".format(
61 port_mode2str(port_mode), port_type2str(port_type), parent))
62 pen = QPen(Qt.black)
64 pen.setCapStyle(Qt.RoundCap)
65 pen.setWidthF(pen.widthF() + 0.00001)
66 self.setPen(pen)
68 def updateLinePos(self, scenePos):
69 item_pos = [0, 0]
71 if self.m_port_mode == PORT_MODE_INPUT:
72 item_pos[0] = 0
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
77 else:
78 return
80 line = QLineF(item_pos[0], item_pos[1], scenePos.x() - self.p_lineX, scenePos.y() - self.p_lineY)
81 self.setLine(line)
83 def type(self):
84 return CanvasLineMovType
86 def paint(self, painter, option, widget):
87 painter.save()
88 painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
89 QGraphicsLineItem.paint(self, painter, option, widget)
90 painter.restore()
92 # ------------------------------------------------------------------------------------------------------------