# -*- coding: utf-8 -*- """ """ from artv2.third_party.Qt import QtWidgets, QtGui, QtCore class ARTv2GraphicNode(QtWidgets.QGraphicsItem): # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def __init__(self, node, parent=None): super(ARTv2GraphicNode, self).__init__(parent) self.node = node self._title_color = QtCore.Qt.white self._title_font = QtGui.QFont("Ubuntu", 10) self.width = 180.0 self.height = 240.0 self._outline_size = 10.0 self._pen_default = QtGui.QPen(QtGui.QColor("#7f000000")) self._pen_selected = QtGui.QPen(QtGui.QColor("#FFFFA637")) self._title_height = 24.0 self._brush_title = QtGui.QBrush(QtGui.QColor("#FF313131")) self._brush_background = QtGui.QBrush(QtGui.QColor("#E3212121")) self._padding = 4.0 self._init_title() self.title = self.node.title self._init_interface() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def boundingRect(self): return QtCore.QRectF(0.0, 0.0, self.width, self.height).normalized() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def paint(self, painter, style, widget=None): # paint title node_title = QtGui.QPainterPath() node_title.setFillRule(QtCore.Qt.WindingFill) node_title.addRoundedRect(0.0, 0.0, self.width, self._title_height, self._outline_size, self._outline_size) node_title.addRect(0.0, self._title_height - self._outline_size, self._outline_size, self._outline_size) node_title.addRect(self.width - self._outline_size, self._title_height - self._outline_size, self._outline_size, self._outline_size) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(self._brush_title) painter.drawPath(node_title.simplified()) # paint content node_content = QtGui.QPainterPath() node_content.setFillRule(QtCore.Qt.WindingFill) node_content.addRoundedRect(0.0, self._title_height, self.width, self.height - self._title_height, self._outline_size, self._outline_size) node_content.addRect(0.0, self._title_height, self._outline_size, self._outline_size) node_content.addRect(self.width - self._outline_size, self._title_height, self._outline_size, self._outline_size) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(self._brush_background) painter.drawPath(node_content.simplified()) # paint outline node_outline = QtGui.QPainterPath() node_outline.addRoundedRect(0.0, 0.0, self.width, self.height, self._outline_size, self._outline_size) painter.setPen(self._pen_default if not self.isSelected() else self._pen_selected) painter.setBrush(QtCore.Qt.NoBrush) painter.drawPath(node_outline.simplified()) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _init_title(self): self.title_item = QtWidgets.QGraphicsTextItem(self) self.title_item.setDefaultTextColor(self._title_color) self.title_item.setFont(self._title_font) self.title_item.setPos(self._padding, 0) self.title_item.setTextWidth(self.width - (2 * self._padding)) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # def _init_interface(self): self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable) self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # @property def title(self): return self._title @title.setter def title(self, new_title): self._title = new_title self.title_item.setPlainText(self._title)