1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# -*- 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)
|