1
2
3
4
5
6
7
8
9
10
11 from PyQt4.QtCore import *
12 from PyQt4.QtGui import *
13
14 from constants import *
15 from reportitem import *
16 from tools import *
19
20 - def __init__(self, parent, editor, plugin):
33
35 '''
36 Çizginin bir özelliğini değiştirir.
37 '''
38 ReportItem.setProperty(self, property, value)
39
40 if property == 'thickness':
41 self._pen.setWidth(int(value))
42
43 elif property == 'linestyle':
44 value = int(value)
45 self._pen.setStyle(Qt.PenStyle(value))
46
47 elif property == 'cornerstyle':
48 value = int(value)
49 self._pen.setJoinStyle(Qt.PenJoinStyle(value))
50
51 elif property == 'foreground':
52 if value is None:
53 self._foregroundColor = QColor()
54 else:
55 self._foregroundColor = QColor(long(value))
56
82
84 '''
85 Çizginin özelliklerini bir dict'e yazar.
86 '''
87 dump = {}
88
89 dump['class'] = 'Rectangle'
90 dump['x'] = self._plugin.unit().unitWidth(self.pos().x())
91 dump['y'] = self._plugin.unit().unitHeight(self.pos().y())
92 dump['width'] = self._plugin.unit().unitWidth(self.width())
93 dump['height'] = self._plugin.unit().unitWidth(self.height())
94 dump['properties'] = self.properties()
95
96 return dump
97
113
114 @staticmethod
126
128 '''
129 Dikdörtgen içindeki boş alanın şekle dahil olmaması için, bu method'u
130 yazıyoruz.
131 '''
132 thickness = max(2, int(self._properties['thickness']))
133
134 outerPath = QPainterPath()
135 innerPath = QPainterPath()
136
137 outerRect = QRectF(self.rect())
138 innerRect = QRectF(self.rect().adjusted(thickness, thickness, -thickness, -thickness))
139
140 if self._properties['cornertype'] == 'round':
141 outerPath.addRoundRect(outerRect, 25, 25)
142 innerPath.addRoundRect(innerRect, 25, 25)
143
144 else:
145 outerPath.addRect(outerRect)
146 innerPath.addRect(innerRect)
147
148 path = outerPath.subtracted(innerPath)
149
150 return path
151
152 - def paint(self, painter, option, widget):
153 '''
154 Dikdörtgenin şeklini çizer.
155 '''
156 rect = self.rect()
157
158 width = self.width()
159 height = self.height()
160
161 isManipulated = False
162
163
164 if width < 1 or height < 1:
165 isManipulated = True
166
167 else:
168
169 if option.state & QStyle.State_Selected:
170 self._pen.setColor(QColor(Qt.red))
171
172 else:
173 if self._foregroundColor.isValid() and self._foregroundColor != Qt.white:
174 self._pen.setColor(self._foregroundColor)
175
176 else:
177 self._pen.setColor(QColor(Qt.black))
178
179 painter.setPen(self._pen)
180
181 thickness = int(self._properties['thickness'])
182 margin = thickness / 2
183
184 rect = self.rect().adjusted(margin, margin, -margin, -margin)
185
186 if self._properties['cornertype'] == 'round':
187 painter.drawRoundRect(rect, 25, 25)
188
189 else:
190 painter.drawRect(rect)
191
192
193 rects = self.collidingRects()
194 for rect in rects:
195 painter.fillRect(rect, QColor(255, 165, 0, 50))
196