Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

canvaslinemov.py 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # PatchBay Canvas engine using QGraphicsView/Scene
  4. # Copyright (C) 2010-2019 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Imports (Global)
  19. from PyQt5.QtCore import qWarning, Qt, QLineF
  20. from PyQt5.QtGui import QPainter, QPen
  21. from PyQt5.QtWidgets import QGraphicsLineItem
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. from . import (
  25. canvas,
  26. options,
  27. port_mode2str,
  28. port_type2str,
  29. CanvasLineMovType,
  30. PORT_MODE_INPUT,
  31. PORT_MODE_OUTPUT,
  32. PORT_TYPE_AUDIO_JACK,
  33. PORT_TYPE_MIDI_ALSA,
  34. PORT_TYPE_MIDI_JACK,
  35. PORT_TYPE_PARAMETER,
  36. )
  37. # ------------------------------------------------------------------------------------------------------------
  38. class CanvasLineMov(QGraphicsLineItem):
  39. def __init__(self, port_mode, port_type, parent):
  40. QGraphicsLineItem.__init__(self, parent)
  41. self.m_port_mode = port_mode
  42. self.m_port_type = port_type
  43. # Port position doesn't change while moving around line
  44. self.p_lineX = self.scenePos().x()
  45. self.p_lineY = self.scenePos().y()
  46. self.p_width = self.parentItem().getPortWidth()
  47. if port_type == PORT_TYPE_AUDIO_JACK:
  48. pen = QPen(canvas.theme.line_audio_jack, 2)
  49. elif port_type == PORT_TYPE_MIDI_JACK:
  50. pen = QPen(canvas.theme.line_midi_jack, 2)
  51. elif port_type == PORT_TYPE_MIDI_ALSA:
  52. pen = QPen(canvas.theme.line_midi_alsa, 2)
  53. elif port_type == PORT_TYPE_PARAMETER:
  54. pen = QPen(canvas.theme.line_parameter, 2)
  55. else:
  56. qWarning("PatchCanvas::CanvasLineMov({}, {}, {}) - invalid port type".format(
  57. port_mode2str(port_mode), port_type2str(port_type), parent))
  58. pen = QPen(Qt.black)
  59. pen.setCapStyle(Qt.RoundCap)
  60. pen.setWidthF(pen.widthF() + 0.00001)
  61. self.setPen(pen)
  62. def updateLinePos(self, scenePos):
  63. item_pos = [0, 0]
  64. if self.m_port_mode == PORT_MODE_INPUT:
  65. item_pos[0] = 0
  66. item_pos[1] = float(canvas.theme.port_height)/2
  67. elif self.m_port_mode == PORT_MODE_OUTPUT:
  68. item_pos[0] = self.p_width + 12
  69. item_pos[1] = float(canvas.theme.port_height)/2
  70. else:
  71. return
  72. line = QLineF(item_pos[0], item_pos[1], scenePos.x() - self.p_lineX, scenePos.y() - self.p_lineY)
  73. self.setLine(line)
  74. def type(self):
  75. return CanvasLineMovType
  76. def paint(self, painter, option, widget):
  77. painter.save()
  78. painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing))
  79. QGraphicsLineItem.paint(self, painter, option, widget)
  80. painter.restore()
  81. # ------------------------------------------------------------------------------------------------------------