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

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