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 *
17
18 import icons
19 import commands as cmd
20
21 -class Image(ReportItem):
22
23 - def __init__(self, parent, editor, plugin):
38
40 '''
41 Çizginin bir özelliğini değiştirir.
42 '''
43 ReportItem.setProperty(self, property, value)
44
45 if property == 'background':
46 if value is None:
47 self._color = QColor(200, 200, 200)
48 self._brush = QBrush(self._color, Qt.Dense5Pattern)
49
50 else:
51 self._color = QColor(long(value))
52 self._brush.setColor(self._color)
53
54 elif property == 'data':
55 self.setImageData(value)
56
57 elif property == 'aspectratio':
58 self._aspectRatio = Qt.AspectRatioMode(int(value))
59
78
80 '''
81 İçindeki resmin kapladığı alanı bulup döndürüyoruz.
82 '''
83 width = self._image.width() + 1
84 height = self._image.height() + 1
85
86 return QSizeF(width, height)
87
89 '''
90 İçeriği verilen resmi set eder.
91 '''
92 self._image = QImage()
93
94 if not self._image.loadFromData(data):
95 self._properties['data'] = None
96 self._image = icons.imagePixmap.toImage()
97
113
115 '''
116 Alanın içerisindeki yazı değişeceği zaman çalışır.
117 '''
118 self.scene().emit(SIGNAL('beginImageChooser(PyQt_PyObject)'), self)
119
135
136 @staticmethod
148
150 '''
151 Yerleştirilecek resmin ne kadarının kullanılabileceğini bulur.
152 '''
153 width = self.width() - 1
154 height = self.height() - 1
155 imageWidth = image.width()
156 imageHeight = image.height()
157
158 sx = 0
159 sy = 0
160 swidth = imageWidth
161 sheight = imageHeight
162
163
164 if self._properties['hjustify'] == 'hcenter':
165 if imageWidth > width:
166 sx = (imageWidth - width) / 2
167
168 elif self._properties['hjustify'] == 'rjust':
169 if imageWidth > width:
170 sx = imageWidth - width
171
172
173 if self._properties['vjustify'] == 'vcenter':
174 if imageHeight > height:
175 sy = (imageHeight - height) / 2
176
177 elif self._properties['vjustify'] == 'bjust':
178 if imageHeight > height:
179 sy = imageHeight - height
180
181 sx = max(0, sx)
182 sy = max(0, sy)
183 swidth = min(width, swidth)
184 sheight = min(height, sheight)
185
186 return QRectF(sx, sy, swidth, sheight)
187
189 '''
190 Yerleştirilecek resmin nesnenin neresine denk geldiğini bulur
191 '''
192 width = self.width()
193 height = self.height()
194
195 imageWidth = image.width()
196 imageHeight = image.height()
197
198 x = 0
199 y = 0
200
201
202 if self._properties['hjustify'] == 'hcenter':
203 x = (width / 2) - (imageWidth / 2)
204
205 elif self._properties['hjustify'] == 'rjust':
206 x = width - imageWidth
207
208
209 if self._properties['vjustify'] == 'vcenter':
210 y = (height / 2) - (imageHeight / 2)
211
212 elif self._properties['vjustify'] == 'bjust':
213 y = height - imageHeight
214
215 x = max(0, x)
216 y = max(0, y)
217
218 return QPointF(x, y)
219
220 - def paint(self, painter, option, widget):
221 '''
222 Dikdörtgenin şeklini çizer.
223 '''
224 rect = self.rect()
225
226 width = rect.width()
227 height = rect.height()
228
229 isManipulated = False
230
231
232 if width < 1 or height < 1:
233 isManipulated = True
234
235 else:
236
237 pen = QPen()
238
239
240 if option.state & QStyle.State_Selected:
241 pen.setColor(QColor(Qt.red))
242
243 else:
244 pen.setColor(self._color)
245
246 painter.fillRect(rect, self._brush)
247
248 image = self._image
249
250 if self._properties['data'] and self._properties['scaled'] == 'T':
251 image = image.scaled(width, height, self._aspectRatio, Qt.SmoothTransformation)
252
253 painter.drawImage(self.targetPoint(image), image, self.sourceRect(image))
254
255 painter.setPen(pen)
256 painter.drawRect(rect)
257
258
259 rects = self.collidingRects()
260 for rect in rects:
261 painter.fillRect(rect, QColor(255, 165, 0, 50))
262