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.

670 lines
24KB

  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, Qt, QPointF, QRectF, QTimer
  20. from PyQt5.QtGui import QCursor, QFont, QFontMetrics, QImage, QLinearGradient, QPainter, QPen
  21. from PyQt5.QtWidgets import QGraphicsItem, QMenu
  22. # ------------------------------------------------------------------------------------------------------------
  23. # Imports (Custom)
  24. from . import (
  25. canvas,
  26. features,
  27. options,
  28. port_dict_t,
  29. CanvasBoxType,
  30. ANTIALIASING_FULL,
  31. ACTION_PLUGIN_EDIT,
  32. ACTION_PLUGIN_SHOW_UI,
  33. ACTION_PLUGIN_CLONE,
  34. ACTION_PLUGIN_REMOVE,
  35. ACTION_PLUGIN_RENAME,
  36. ACTION_PLUGIN_REPLACE,
  37. ACTION_GROUP_INFO,
  38. ACTION_GROUP_JOIN,
  39. ACTION_GROUP_SPLIT,
  40. ACTION_GROUP_RENAME,
  41. ACTION_PORTS_DISCONNECT,
  42. ACTION_INLINE_DISPLAY,
  43. EYECANDY_FULL,
  44. PORT_MODE_NULL,
  45. PORT_MODE_INPUT,
  46. PORT_MODE_OUTPUT,
  47. PORT_TYPE_NULL,
  48. PORT_TYPE_AUDIO_JACK,
  49. PORT_TYPE_MIDI_ALSA,
  50. PORT_TYPE_MIDI_JACK,
  51. PORT_TYPE_PARAMETER,
  52. MAX_PLUGIN_ID_ALLOWED,
  53. )
  54. from .canvasboxshadow import CanvasBoxShadow
  55. from .canvasicon import CanvasIcon
  56. from .canvasport import CanvasPort
  57. from .theme import Theme
  58. from .utils import CanvasItemFX, CanvasGetFullPortName, CanvasGetPortConnectionList
  59. # ------------------------------------------------------------------------------------------------------------
  60. class cb_line_t(object):
  61. def __init__(self, line, connection_id):
  62. self.line = line
  63. self.connection_id = connection_id
  64. # ------------------------------------------------------------------------------------------------------------
  65. class CanvasBox(QGraphicsItem):
  66. def __init__(self, group_id, group_name, icon, parent=None):
  67. QGraphicsItem.__init__(self)
  68. self.setParentItem(parent)
  69. # Save Variables, useful for later
  70. self.m_group_id = group_id
  71. self.m_group_name = group_name
  72. # plugin Id, < 0 if invalid
  73. self.m_plugin_id = -1
  74. self.m_plugin_ui = False
  75. self.m_plugin_inline = False
  76. # Base Variables
  77. self.p_width = 50
  78. self.p_width_in = 0
  79. self.p_width_out = 0
  80. self.p_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing + 1
  81. self.m_last_pos = QPointF()
  82. self.m_splitted = False
  83. self.m_splitted_mode = PORT_MODE_NULL
  84. self.m_cursor_moving = False
  85. self.m_forced_split = False
  86. self.m_mouse_down = False
  87. self.m_port_list_ids = []
  88. self.m_connection_lines = []
  89. # Set Font
  90. self.m_font_name = QFont()
  91. self.m_font_name.setFamily(canvas.theme.box_font_name)
  92. self.m_font_name.setPixelSize(canvas.theme.box_font_size)
  93. self.m_font_name.setWeight(canvas.theme.box_font_state)
  94. self.m_font_port = QFont()
  95. self.m_font_port.setFamily(canvas.theme.port_font_name)
  96. self.m_font_port.setPixelSize(canvas.theme.port_font_size)
  97. self.m_font_port.setWeight(canvas.theme.port_font_state)
  98. # Icon
  99. if canvas.theme.box_use_icon:
  100. self.icon_svg = CanvasIcon(icon, self.m_group_name, self)
  101. else:
  102. self.icon_svg = None
  103. # Shadow
  104. if options.eyecandy:
  105. self.shadow = CanvasBoxShadow(self.toGraphicsObject())
  106. self.shadow.setFakeParent(self)
  107. self.setGraphicsEffect(self.shadow)
  108. else:
  109. self.shadow = None
  110. # Final touches
  111. self.setFlags(QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable)
  112. # Wait for at least 1 port
  113. if options.auto_hide_groups:
  114. self.setVisible(False)
  115. if options.auto_select_items:
  116. self.setAcceptHoverEvents(True)
  117. self.updatePositions()
  118. canvas.scene.addItem(self)
  119. QTimer.singleShot(0, self.fixPos)
  120. def getGroupId(self):
  121. return self.m_group_id
  122. def getGroupName(self):
  123. return self.m_group_name
  124. def isSplitted(self):
  125. return self.m_splitted
  126. def getSplittedMode(self):
  127. return self.m_splitted_mode
  128. def getPortCount(self):
  129. return len(self.m_port_list_ids)
  130. def getPortList(self):
  131. return self.m_port_list_ids
  132. def setAsPlugin(self, plugin_id, hasUI, hasInlineDisplay):
  133. self.m_plugin_id = plugin_id
  134. self.m_plugin_ui = hasUI
  135. self.m_plugin_inline = hasInlineDisplay
  136. def setIcon(self, icon):
  137. if self.icon_svg is not None:
  138. self.icon_svg.setIcon(icon, self.m_group_name)
  139. def setSplit(self, split, mode=PORT_MODE_NULL):
  140. self.m_splitted = split
  141. self.m_splitted_mode = mode
  142. def setGroupName(self, group_name):
  143. self.m_group_name = group_name
  144. self.updatePositions()
  145. def setShadowOpacity(self, opacity):
  146. if self.shadow:
  147. self.shadow.setOpacity(opacity)
  148. def addPortFromGroup(self, port_id, port_mode, port_type, port_name, is_alternate):
  149. if len(self.m_port_list_ids) == 0:
  150. if options.auto_hide_groups:
  151. if options.eyecandy == EYECANDY_FULL:
  152. CanvasItemFX(self, True, False)
  153. self.setVisible(True)
  154. new_widget = CanvasPort(self.m_group_id, port_id, port_name, port_mode, port_type, is_alternate, self)
  155. port_dict = port_dict_t()
  156. port_dict.group_id = self.m_group_id
  157. port_dict.port_id = port_id
  158. port_dict.port_name = port_name
  159. port_dict.port_mode = port_mode
  160. port_dict.port_type = port_type
  161. port_dict.is_alternate = is_alternate
  162. port_dict.widget = new_widget
  163. self.m_port_list_ids.append(port_id)
  164. return new_widget
  165. def removePortFromGroup(self, port_id):
  166. if port_id in self.m_port_list_ids:
  167. self.m_port_list_ids.remove(port_id)
  168. else:
  169. qCritical("PatchCanvas::CanvasBox.removePort(%i) - unable to find port to remove" % port_id)
  170. return
  171. if len(self.m_port_list_ids) > 0:
  172. self.updatePositions()
  173. elif self.isVisible():
  174. if options.auto_hide_groups:
  175. if options.eyecandy == EYECANDY_FULL:
  176. CanvasItemFX(self, False, False)
  177. else:
  178. self.setVisible(False)
  179. def addLineFromGroup(self, line, connection_id):
  180. new_cbline = cb_line_t(line, connection_id)
  181. self.m_connection_lines.append(new_cbline)
  182. def removeLineFromGroup(self, connection_id):
  183. for connection in self.m_connection_lines:
  184. if connection.connection_id == connection_id:
  185. self.m_connection_lines.remove(connection)
  186. return
  187. qCritical("PatchCanvas::CanvasBox.removeLineFromGroup(%i) - unable to find line to remove" % connection_id)
  188. def checkItemPos(self):
  189. if not canvas.size_rect.isNull():
  190. pos = self.scenePos()
  191. if not (canvas.size_rect.contains(pos) and
  192. canvas.size_rect.contains(pos + QPointF(self.p_width, self.p_height))):
  193. if pos.x() < canvas.size_rect.x():
  194. self.setPos(canvas.size_rect.x(), pos.y())
  195. elif pos.x() + self.p_width > canvas.size_rect.width():
  196. self.setPos(canvas.size_rect.width() - self.p_width, pos.y())
  197. pos = self.scenePos()
  198. if pos.y() < canvas.size_rect.y():
  199. self.setPos(pos.x(), canvas.size_rect.y())
  200. elif pos.y() + self.p_height > canvas.size_rect.height():
  201. self.setPos(pos.x(), canvas.size_rect.height() - self.p_height)
  202. def removeIconFromScene(self):
  203. if self.icon_svg is None:
  204. return
  205. item = self.icon_svg
  206. self.icon_svg = None
  207. canvas.scene.removeItem(item)
  208. del item
  209. def updatePositions(self):
  210. self.prepareGeometryChange()
  211. # Check Text Name size
  212. app_name_size = QFontMetrics(self.m_font_name).width(self.m_group_name) + 30
  213. self.p_width = max(200 if self.m_plugin_inline else 50, app_name_size)
  214. # Get Port List
  215. port_list = []
  216. for port in canvas.port_list:
  217. if port.group_id == self.m_group_id and port.port_id in self.m_port_list_ids:
  218. port_list.append(port)
  219. if len(port_list) == 0:
  220. self.p_height = canvas.theme.box_header_height
  221. self.p_width_in = 0
  222. self.p_width_out = 0
  223. else:
  224. max_in_width = max_out_width = 0
  225. port_spacing = canvas.theme.port_height + canvas.theme.port_spacing
  226. # Get Max Box Width, vertical ports re-positioning
  227. port_types = [PORT_TYPE_AUDIO_JACK, PORT_TYPE_MIDI_JACK, PORT_TYPE_MIDI_ALSA, PORT_TYPE_PARAMETER]
  228. last_in_type = last_out_type = PORT_TYPE_NULL
  229. last_in_pos = last_out_pos = canvas.theme.box_header_height + canvas.theme.box_header_spacing
  230. for port_type in port_types:
  231. for port in port_list:
  232. if port.port_type != port_type:
  233. continue
  234. size = QFontMetrics(self.m_font_port).width(port.port_name)
  235. if port.port_mode == PORT_MODE_INPUT:
  236. max_in_width = max(max_in_width, size)
  237. if port.port_type != last_in_type:
  238. if last_in_type != PORT_TYPE_NULL:
  239. last_in_pos += canvas.theme.port_spacingT
  240. last_in_type = port.port_type
  241. port.widget.setY(last_in_pos)
  242. last_in_pos += port_spacing
  243. elif port.port_mode == PORT_MODE_OUTPUT:
  244. max_out_width = max(max_out_width, size)
  245. if port.port_type != last_out_type:
  246. if last_out_type != PORT_TYPE_NULL:
  247. last_out_pos += canvas.theme.port_spacingT
  248. last_out_type = port.port_type
  249. port.widget.setY(last_out_pos)
  250. last_out_pos += port_spacing
  251. self.p_width = max(self.p_width, (100 if self.m_plugin_inline else 30) + max_in_width + max_out_width)
  252. self.p_width_in = max_in_width
  253. self.p_width_out = max_out_width
  254. #if self.m_plugin_inline:
  255. #self.p_width += 10
  256. # Horizontal ports re-positioning
  257. inX = canvas.theme.port_offset
  258. outX = self.p_width - max_out_width - canvas.theme.port_offset - 12
  259. for port_type in port_types:
  260. for port in port_list:
  261. if port.port_mode == PORT_MODE_INPUT:
  262. port.widget.setX(inX)
  263. port.widget.setPortWidth(max_in_width)
  264. elif port.port_mode == PORT_MODE_OUTPUT:
  265. port.widget.setX(outX)
  266. port.widget.setPortWidth(max_out_width)
  267. self.p_height = max(last_in_pos, last_out_pos)
  268. self.p_height += max(canvas.theme.port_spacing, canvas.theme.port_spacingT) - canvas.theme.port_spacing
  269. self.p_height += canvas.theme.box_pen.widthF()
  270. self.repaintLines(True)
  271. self.update()
  272. def repaintLines(self, forced=False):
  273. if self.pos() != self.m_last_pos or forced:
  274. for connection in self.m_connection_lines:
  275. connection.line.updateLinePos()
  276. self.m_last_pos = self.pos()
  277. def resetLinesZValue(self):
  278. for connection in canvas.connection_list:
  279. if connection.port_out_id in self.m_port_list_ids and connection.port_in_id in self.m_port_list_ids:
  280. z_value = canvas.last_z_value
  281. else:
  282. z_value = canvas.last_z_value - 1
  283. connection.widget.setZValue(z_value)
  284. def type(self):
  285. return CanvasBoxType
  286. def contextMenuEvent(self, event):
  287. event.accept()
  288. menu = QMenu()
  289. # Conenct menu stuff
  290. connMenu = QMenu("Connect", menu)
  291. our_port_types = []
  292. our_port_outs = {
  293. PORT_TYPE_AUDIO_JACK: [],
  294. PORT_TYPE_MIDI_JACK: [],
  295. PORT_TYPE_MIDI_ALSA: [],
  296. }
  297. for port in canvas.port_list:
  298. if port.group_id != self.m_group_id:
  299. continue
  300. if port.port_mode != PORT_MODE_OUTPUT:
  301. continue
  302. if port.port_id not in self.m_port_list_ids:
  303. continue
  304. if port.port_type not in our_port_types:
  305. our_port_types.append(port.port_type)
  306. our_port_outs[port.port_type].append((port.group_id, port.port_id))
  307. if len(our_port_types) != 0:
  308. act_x_conn = None
  309. for group in canvas.group_list:
  310. if self.m_group_id == group.group_id:
  311. continue
  312. has_ports = False
  313. target_ports = {
  314. PORT_TYPE_AUDIO_JACK: [],
  315. PORT_TYPE_MIDI_JACK: [],
  316. PORT_TYPE_MIDI_ALSA: [],
  317. }
  318. for port in canvas.port_list:
  319. if port.group_id != group.group_id:
  320. continue
  321. if port.port_mode != PORT_MODE_INPUT:
  322. continue
  323. if port.port_type not in our_port_types:
  324. continue
  325. has_ports = True
  326. target_ports[port.port_type].append((port.group_id, port.port_id))
  327. if not has_ports:
  328. continue
  329. act_x_conn = connMenu.addAction(group.group_name)
  330. act_x_conn.setData((our_port_outs, target_ports))
  331. act_x_conn.triggered.connect(canvas.qobject.PortContextMenuConnect)
  332. if act_x_conn is None:
  333. act_x_disc = connMenu.addAction("Nothing to connect to")
  334. act_x_disc.setEnabled(False)
  335. else:
  336. act_x_disc = connMenu.addAction("No output ports")
  337. act_x_disc.setEnabled(False)
  338. # Disconnect menu stuff
  339. discMenu = QMenu("Disconnect", menu)
  340. conn_list = []
  341. conn_list_ids = []
  342. for port_id in self.m_port_list_ids:
  343. tmp_conn_list = CanvasGetPortConnectionList(self.m_group_id, port_id)
  344. for tmp_conn_id, tmp_group_id, tmp_port_id in tmp_conn_list:
  345. if tmp_conn_id not in conn_list_ids:
  346. conn_list.append((tmp_conn_id, tmp_group_id, tmp_port_id))
  347. conn_list_ids.append(tmp_conn_id)
  348. if len(conn_list) > 0:
  349. for conn_id, group_id, port_id in conn_list:
  350. act_x_disc = discMenu.addAction(CanvasGetFullPortName(group_id, port_id))
  351. act_x_disc.setData(conn_id)
  352. act_x_disc.triggered.connect(canvas.qobject.PortContextMenuDisconnect)
  353. else:
  354. act_x_disc = discMenu.addAction("No connections")
  355. act_x_disc.setEnabled(False)
  356. menu.addMenu(connMenu)
  357. menu.addMenu(discMenu)
  358. act_x_disc_all = menu.addAction("Disconnect &All")
  359. act_x_sep1 = menu.addSeparator()
  360. act_x_info = menu.addAction("Info")
  361. act_x_rename = menu.addAction("Rename")
  362. act_x_sep2 = menu.addSeparator()
  363. act_x_split_join = menu.addAction("Join" if self.m_splitted else "Split")
  364. if not features.group_info:
  365. act_x_info.setVisible(False)
  366. if not features.group_rename:
  367. act_x_rename.setVisible(False)
  368. if not (features.group_info and features.group_rename):
  369. act_x_sep1.setVisible(False)
  370. if self.m_plugin_id >= 0 and self.m_plugin_id <= MAX_PLUGIN_ID_ALLOWED:
  371. menu.addSeparator()
  372. act_p_edit = menu.addAction("Edit")
  373. act_p_ui = menu.addAction("Show Custom UI")
  374. menu.addSeparator()
  375. act_p_clone = menu.addAction("Clone")
  376. act_p_rename = menu.addAction("Rename...")
  377. act_p_replace = menu.addAction("Replace...")
  378. act_p_remove = menu.addAction("Remove")
  379. if not self.m_plugin_ui:
  380. act_p_ui.setVisible(False)
  381. else:
  382. act_p_edit = act_p_ui = None
  383. act_p_clone = act_p_rename = None
  384. act_p_replace = act_p_remove = None
  385. haveIns = haveOuts = False
  386. for port in canvas.port_list:
  387. if port.group_id == self.m_group_id and port.port_id in self.m_port_list_ids:
  388. if port.port_mode == PORT_MODE_INPUT:
  389. haveIns = True
  390. elif port.port_mode == PORT_MODE_OUTPUT:
  391. haveOuts = True
  392. if not (self.m_splitted or bool(haveIns and haveOuts)):
  393. act_x_sep2.setVisible(False)
  394. act_x_split_join.setVisible(False)
  395. act_selected = menu.exec_(event.screenPos())
  396. if act_selected is None:
  397. pass
  398. elif act_selected == act_x_disc_all:
  399. for conn_id in conn_list_ids:
  400. canvas.callback(ACTION_PORTS_DISCONNECT, conn_id, 0, "")
  401. elif act_selected == act_x_info:
  402. canvas.callback(ACTION_GROUP_INFO, self.m_group_id, 0, "")
  403. elif act_selected == act_x_rename:
  404. canvas.callback(ACTION_GROUP_RENAME, self.m_group_id, 0, "")
  405. elif act_selected == act_x_split_join:
  406. if self.m_splitted:
  407. canvas.callback(ACTION_GROUP_JOIN, self.m_group_id, 0, "")
  408. else:
  409. canvas.callback(ACTION_GROUP_SPLIT, self.m_group_id, 0, "")
  410. elif act_selected == act_p_edit:
  411. canvas.callback(ACTION_PLUGIN_EDIT, self.m_plugin_id, 0, "")
  412. elif act_selected == act_p_ui:
  413. canvas.callback(ACTION_PLUGIN_SHOW_UI, self.m_plugin_id, 0, "")
  414. elif act_selected == act_p_clone:
  415. canvas.callback(ACTION_PLUGIN_CLONE, self.m_plugin_id, 0, "")
  416. elif act_selected == act_p_rename:
  417. canvas.callback(ACTION_PLUGIN_RENAME, self.m_plugin_id, 0, "")
  418. elif act_selected == act_p_replace:
  419. canvas.callback(ACTION_PLUGIN_REPLACE, self.m_plugin_id, 0, "")
  420. elif act_selected == act_p_remove:
  421. canvas.callback(ACTION_PLUGIN_REMOVE, self.m_plugin_id, 0, "")
  422. def keyPressEvent(self, event):
  423. if self.m_plugin_id >= 0 and event.key() == Qt.Key_Delete:
  424. event.accept()
  425. canvas.callback(ACTION_PLUGIN_REMOVE, self.m_plugin_id, 0, "")
  426. return
  427. QGraphicsItem.keyPressEvent(self, event)
  428. def hoverEnterEvent(self, event):
  429. if options.auto_select_items:
  430. if len(canvas.scene.selectedItems()) > 0:
  431. canvas.scene.clearSelection()
  432. self.setSelected(True)
  433. QGraphicsItem.hoverEnterEvent(self, event)
  434. def mouseDoubleClickEvent(self, event):
  435. if self.m_plugin_id >= 0:
  436. event.accept()
  437. canvas.callback(ACTION_PLUGIN_SHOW_UI if self.m_plugin_ui else ACTION_PLUGIN_EDIT, self.m_plugin_id, 0, "")
  438. return
  439. QGraphicsItem.mouseDoubleClickEvent(self, event)
  440. def mousePressEvent(self, event):
  441. canvas.last_z_value += 1
  442. self.setZValue(canvas.last_z_value)
  443. self.resetLinesZValue()
  444. self.m_cursor_moving = False
  445. if event.button() == Qt.RightButton:
  446. event.accept()
  447. canvas.scene.clearSelection()
  448. self.setSelected(True)
  449. self.m_mouse_down = False
  450. return
  451. elif event.button() == Qt.LeftButton:
  452. if self.sceneBoundingRect().contains(event.scenePos()):
  453. self.m_mouse_down = True
  454. else:
  455. # FIXME: Check if still valid: Fix a weird Qt behaviour with right-click mouseMove
  456. self.m_mouse_down = False
  457. event.ignore()
  458. return
  459. else:
  460. self.m_mouse_down = False
  461. QGraphicsItem.mousePressEvent(self, event)
  462. def mouseMoveEvent(self, event):
  463. if self.m_mouse_down:
  464. if not self.m_cursor_moving:
  465. self.setCursor(QCursor(Qt.SizeAllCursor))
  466. self.m_cursor_moving = True
  467. self.repaintLines()
  468. QGraphicsItem.mouseMoveEvent(self, event)
  469. def mouseReleaseEvent(self, event):
  470. if self.m_cursor_moving:
  471. self.unsetCursor()
  472. QTimer.singleShot(0, self.fixPos)
  473. self.m_mouse_down = False
  474. self.m_cursor_moving = False
  475. QGraphicsItem.mouseReleaseEvent(self, event)
  476. def fixPos(self):
  477. self.setX(round(self.x()))
  478. self.setY(round(self.y()))
  479. def boundingRect(self):
  480. return QRectF(0, 0, self.p_width, self.p_height)
  481. def paint(self, painter, option, widget):
  482. painter.save()
  483. painter.setRenderHint(QPainter.Antialiasing, bool(options.antialiasing == ANTIALIASING_FULL))
  484. rect = QRectF(0, 0, self.p_width, self.p_height)
  485. # Draw rectangle
  486. pen = QPen(canvas.theme.box_pen_sel if self.isSelected() else canvas.theme.box_pen)
  487. pen.setWidthF(pen.widthF() + 0.00001)
  488. painter.setPen(pen)
  489. lineHinting = pen.widthF() / 2
  490. if canvas.theme.box_bg_type == Theme.THEME_BG_GRADIENT:
  491. box_gradient = QLinearGradient(0, 0, 0, self.p_height)
  492. box_gradient.setColorAt(0, canvas.theme.box_bg_1)
  493. box_gradient.setColorAt(1, canvas.theme.box_bg_2)
  494. painter.setBrush(box_gradient)
  495. else:
  496. painter.setBrush(canvas.theme.box_bg_1)
  497. rect.adjust(lineHinting, lineHinting, -lineHinting, -lineHinting)
  498. painter.drawRect(rect)
  499. # Draw plugin inline display if supported
  500. if self.m_plugin_id >= 0 and self.m_plugin_id <= MAX_PLUGIN_ID_ALLOWED and self.m_plugin_inline:
  501. size = "%i:%i" % (self.p_width - self.p_width_in - self.p_width_out - 16,
  502. self.p_height - canvas.theme.box_header_height)
  503. data = canvas.callback(ACTION_INLINE_DISPLAY, self.m_plugin_id, 0, size)
  504. if data is not None:
  505. image = QImage(data['data'], data['width'], data['height'], data['stride'], QImage.Format_ARGB32)
  506. painter.drawImage(self.p_width_in + 7,
  507. canvas.theme.box_header_height
  508. + (self.p_height - canvas.theme.box_header_height) / 2
  509. - data['height'] / 2 - 1,
  510. image)
  511. # Draw pixmap header
  512. rect.setHeight(canvas.theme.box_header_height)
  513. if canvas.theme.box_header_pixmap:
  514. painter.setPen(Qt.NoPen)
  515. painter.setBrush(canvas.theme.box_bg_2)
  516. # outline
  517. rect.adjust(lineHinting, lineHinting, -lineHinting, -lineHinting)
  518. painter.drawRect(rect)
  519. rect.adjust(1, 1, -1, 0)
  520. painter.drawTiledPixmap(rect, canvas.theme.box_header_pixmap, rect.topLeft())
  521. # Draw text
  522. painter.setFont(self.m_font_name)
  523. if self.isSelected():
  524. painter.setPen(canvas.theme.box_text_sel)
  525. else:
  526. painter.setPen(canvas.theme.box_text)
  527. if canvas.theme.box_use_icon:
  528. textPos = QPointF(25, canvas.theme.box_text_ypos)
  529. else:
  530. appNameSize = QFontMetrics(self.m_font_name).width(self.m_group_name)
  531. rem = self.p_width - appNameSize
  532. textPos = QPointF(rem/2, canvas.theme.box_text_ypos)
  533. painter.drawText(textPos, self.m_group_name)
  534. self.repaintLines()
  535. painter.restore()
  536. # ------------------------------------------------------------------------------------------------------------