2 # SPDX-FileCopyrightText: 2011-2024 Filipe Coelho <falktx@falktx.com>
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # ------------------------------------------------------------------------------------------------------------
8 from qt_compat
import qt_config
11 from PyQt5
.QtCore
import qCritical
, QRectF
12 from PyQt5
.QtGui
import QPainter
13 from PyQt5
.QtSvg
import QGraphicsSvgItem
, QSvgRenderer
14 from PyQt5
.QtWidgets
import QGraphicsColorizeEffect
16 from PyQt6
.QtCore
import qCritical
, QRectF
17 from PyQt6
.QtGui
import QPainter
18 from PyQt6
.QtSvg
import QSvgRenderer
19 from PyQt6
.QtSvgWidgets
import QGraphicsSvgItem
20 from PyQt6
.QtWidgets
import QGraphicsColorizeEffect
22 # ------------------------------------------------------------------------------------------------------------
37 # ------------------------------------------------------------------------------------------------------------
39 class CanvasIcon(QGraphicsSvgItem
):
40 def __init__(self
, icon
, name
, parent
):
41 QGraphicsSvgItem
.__init
__(self
)
42 self
.setParentItem(parent
)
44 self
.m_renderer
= None
45 self
.p_size
= QRectF(0, 0, 0, 0)
47 self
.m_colorFX
= QGraphicsColorizeEffect(self
)
48 self
.m_colorFX
.setColor(canvas
.theme
.box_text
.color())
50 self
.setGraphicsEffect(self
.m_colorFX
)
51 self
.setIcon(icon
, name
)
53 def setIcon(self
, icon
, name
):
57 if icon
== ICON_APPLICATION
:
58 self
.p_size
= QRectF(3, 2, 19, 18)
60 if "audacious" in name
:
61 icon_path
= ":/scalable/pb_audacious.svg"
62 self
.p_size
= QRectF(5, 4, 16, 16)
63 elif "clementine" in name
:
64 icon_path
= ":/scalable/pb_clementine.svg"
65 self
.p_size
= QRectF(5, 4, 16, 16)
66 elif "distrho" in name
:
67 icon_path
= ":/scalable/pb_distrho.svg"
68 self
.p_size
= QRectF(5, 4, 16, 16)
70 icon_path
= ":/scalable/pb_jamin.svg"
71 self
.p_size
= QRectF(5, 3, 16, 16)
72 elif "mplayer" in name
:
73 icon_path
= ":/scalable/pb_mplayer.svg"
74 self
.p_size
= QRectF(5, 4, 16, 16)
76 icon_path
= ":/scalable/pb_vlc.svg"
77 self
.p_size
= QRectF(5, 3, 16, 16)
80 icon_path
= ":/scalable/pb_generic.svg"
81 self
.p_size
= QRectF(4, 3, 16, 16)
83 elif icon
== ICON_HARDWARE
:
84 icon_path
= ":/scalable/pb_hardware.svg"
85 self
.p_size
= QRectF(5, 2, 16, 16)
87 elif icon
== ICON_DISTRHO
:
88 icon_path
= ":/scalable/pb_distrho.svg"
89 self
.p_size
= QRectF(5, 4, 16, 16)
91 elif icon
== ICON_FILE
:
92 icon_path
= ":/scalable/pb_file.svg"
93 self
.p_size
= QRectF(5, 4, 16, 16)
95 elif icon
== ICON_PLUGIN
:
96 icon_path
= ":/scalable/pb_plugin.svg"
97 self
.p_size
= QRectF(5, 4, 16, 16)
99 elif icon
== ICON_LADISH_ROOM
:
100 # TODO - make a unique ladish-room icon
101 icon_path
= ":/scalable/pb_hardware.svg"
102 self
.p_size
= QRectF(5, 2, 16, 16)
105 self
.p_size
= QRectF(0, 0, 0, 0)
106 qCritical("PatchCanvas::CanvasIcon.setIcon(%s, %s) - unsupported icon requested" % (
107 icon2str(icon
), name
.encode()))
110 self
.m_renderer
= QSvgRenderer(icon_path
, canvas
.scene
)
111 self
.setSharedRenderer(self
.m_renderer
)
115 return CanvasIconType
117 def boundingRect(self
):
120 def paint(self
, painter
, option
, widget
):
121 if not self
.m_renderer
:
122 QGraphicsSvgItem
.paint(self
, painter
, option
, widget
)
126 painter
.setRenderHint(QPainter
.Antialiasing
, False)
127 painter
.setRenderHint(QPainter
.TextAntialiasing
, False)
128 self
.m_renderer
.render(painter
, self
.p_size
)
131 # ------------------------------------------------------------------------------------------------------------