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.

132 lines
4.4KB

  1. #!/usr/bin/env python3
  2. # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
  3. # SPDX-License-Identifier: GPL-2.0-or-later
  4. # ------------------------------------------------------------------------------------------------------------
  5. # Imports (Global)
  6. from qt_compat import qt_config
  7. if qt_config == 5:
  8. from PyQt5.QtCore import qCritical, QRectF
  9. from PyQt5.QtGui import QPainter
  10. from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer
  11. from PyQt5.QtWidgets import QGraphicsColorizeEffect
  12. elif qt_config == 6:
  13. from PyQt6.QtCore import qCritical, QRectF
  14. from PyQt6.QtGui import QPainter
  15. from PyQt6.QtSvg import QSvgRenderer
  16. from PyQt6.QtSvgWidgets import QGraphicsSvgItem
  17. from PyQt6.QtWidgets import QGraphicsColorizeEffect
  18. # ------------------------------------------------------------------------------------------------------------
  19. # Imports (Custom)
  20. from . import (
  21. canvas,
  22. icon2str,
  23. CanvasIconType,
  24. ICON_APPLICATION,
  25. ICON_HARDWARE,
  26. ICON_DISTRHO,
  27. ICON_FILE,
  28. ICON_PLUGIN,
  29. ICON_LADISH_ROOM,
  30. )
  31. # ------------------------------------------------------------------------------------------------------------
  32. class CanvasIcon(QGraphicsSvgItem):
  33. def __init__(self, icon, name, parent):
  34. QGraphicsSvgItem.__init__(self)
  35. self.setParentItem(parent)
  36. self.m_renderer = None
  37. self.p_size = QRectF(0, 0, 0, 0)
  38. self.m_colorFX = QGraphicsColorizeEffect(self)
  39. self.m_colorFX.setColor(canvas.theme.box_text.color())
  40. self.setGraphicsEffect(self.m_colorFX)
  41. self.setIcon(icon, name)
  42. def setIcon(self, icon, name):
  43. name = name.lower()
  44. icon_path = ""
  45. if icon == ICON_APPLICATION:
  46. self.p_size = QRectF(3, 2, 19, 18)
  47. if "audacious" in name:
  48. icon_path = ":/scalable/pb_audacious.svg"
  49. self.p_size = QRectF(5, 4, 16, 16)
  50. elif "clementine" in name:
  51. icon_path = ":/scalable/pb_clementine.svg"
  52. self.p_size = QRectF(5, 4, 16, 16)
  53. elif "distrho" in name:
  54. icon_path = ":/scalable/pb_distrho.svg"
  55. self.p_size = QRectF(5, 4, 16, 16)
  56. elif "jamin" in name:
  57. icon_path = ":/scalable/pb_jamin.svg"
  58. self.p_size = QRectF(5, 3, 16, 16)
  59. elif "mplayer" in name:
  60. icon_path = ":/scalable/pb_mplayer.svg"
  61. self.p_size = QRectF(5, 4, 16, 16)
  62. elif "vlc" in name:
  63. icon_path = ":/scalable/pb_vlc.svg"
  64. self.p_size = QRectF(5, 3, 16, 16)
  65. else:
  66. icon_path = ":/scalable/pb_generic.svg"
  67. self.p_size = QRectF(4, 3, 16, 16)
  68. elif icon == ICON_HARDWARE:
  69. icon_path = ":/scalable/pb_hardware.svg"
  70. self.p_size = QRectF(5, 2, 16, 16)
  71. elif icon == ICON_DISTRHO:
  72. icon_path = ":/scalable/pb_distrho.svg"
  73. self.p_size = QRectF(5, 4, 16, 16)
  74. elif icon == ICON_FILE:
  75. icon_path = ":/scalable/pb_file.svg"
  76. self.p_size = QRectF(5, 4, 16, 16)
  77. elif icon == ICON_PLUGIN:
  78. icon_path = ":/scalable/pb_plugin.svg"
  79. self.p_size = QRectF(5, 4, 16, 16)
  80. elif icon == ICON_LADISH_ROOM:
  81. # TODO - make a unique ladish-room icon
  82. icon_path = ":/scalable/pb_hardware.svg"
  83. self.p_size = QRectF(5, 2, 16, 16)
  84. else:
  85. self.p_size = QRectF(0, 0, 0, 0)
  86. qCritical("PatchCanvas::CanvasIcon.setIcon(%s, %s) - unsupported icon requested" % (
  87. icon2str(icon), name.encode()))
  88. return
  89. self.m_renderer = QSvgRenderer(icon_path, canvas.scene)
  90. self.setSharedRenderer(self.m_renderer)
  91. self.update()
  92. def type(self):
  93. return CanvasIconType
  94. def boundingRect(self):
  95. return self.p_size
  96. def paint(self, painter, option, widget):
  97. if not self.m_renderer:
  98. QGraphicsSvgItem.paint(self, painter, option, widget)
  99. return
  100. painter.save()
  101. painter.setRenderHint(QPainter.Antialiasing, False)
  102. painter.setRenderHint(QPainter.TextAntialiasing, False)
  103. self.m_renderer.render(painter, self.p_size)
  104. painter.restore()
  105. # ------------------------------------------------------------------------------------------------------------