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.

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