Cleanup
[carla.git] / source / frontend / patchcanvas / canvasbezierlinemov.py
blob8a5bcaf678a27ff1a9e9b247f335ca81fbe9fb7f
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, QPointF
12 from PyQt5.QtGui import QPainter, QPainterPath, QPen
13 from PyQt5.QtWidgets import QGraphicsPathItem
14 elif qt_config == 6:
15 from PyQt6.QtCore import qWarning, Qt, QPointF
16 from PyQt6.QtGui import QPainter, QPainterPath, QPen
17 from PyQt6.QtWidgets import QGraphicsPathItem
19 # ------------------------------------------------------------------------------------------------------------
20 # Imports (Custom)
22 from . import (
23 canvas,
24 options,
25 port_mode2str,
26 port_type2str,
27 CanvasBezierLineMovType,
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 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)
59 else:
60 qWarning("PatchCanvas::CanvasBezierLineMov({}, {}, {}) - invalid port type".format(
61 port_mode2str(port_mode), port_type2str(port_type), parent))
62 pen = QPen(Qt.black)
64 pen.setCapStyle(Qt.FlatCap)
65 pen.setWidthF(pen.widthF() + 0.00001)
66 self.setPen(pen)
68 def updateLinePos(self, scenePos):
69 if self.m_port_mode == PORT_MODE_INPUT:
70 old_x = 0
71 old_y = float(canvas.theme.port_height)/2
72 mid_x = abs(scenePos.x() - self.p_itemX) / 2
73 new_x = old_x - mid_x
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
78 new_x = old_x + mid_x
79 else:
80 return
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)
87 self.setPath(path)
89 def type(self):
90 return CanvasBezierLineMovType
92 def paint(self, painter, option, widget):
93 painter.save()
94 painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
95 QGraphicsPathItem.paint(self, painter, option, widget)
96 painter.restore()
98 # ------------------------------------------------------------------------------------------------------------