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.

canvasicon.py 4.6KB

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