1
2
3
4
5
6
7
8
9
10
11 from PyQt4.QtCore import *
12 from PyQt4.QtGui import *
13
14 from reportitem import *
15 from tools import *
16
17 -class TextArea(ReportItem):
18
19 - def __init__(self, parent, editor, plugin):
20 '''
21 Yazı alanını oluşturur.
22 '''
23 ReportItem.__init__(self, parent, editor, plugin)
24
25 self._properties = dict(self._plugin.textAreaDefaultProperties())
26
27 self._font = QFont(self._plugin.font())
28
29 self._foregroundColor = QColor()
30 self._backgroundColor = QColor()
31
33 '''
34 Alanın kullandığı fontu verir.
35 '''
36 return self._font
37
39 '''
40 Nesnenin üzerinde olan yazıyı verir.
41 '''
42 text = self._properties['text']
43
44 if type(text) == unicode:
45 return text
46
47 else:
48 return unicode(self._properties['text'], 'UTF-8', 'ignore')
49
50 - def pointSize(self):
51 '''
52 Font boyunu verir.
53 '''
54 return self._pointSize
55
56 - def setText(self, newText):
57 '''
58 Nesnenin yazısını değiştirir.
59 '''
60 self._properties['text'] = newText
61 self._toolTipProperties['title'] = tr(newText)
62
63 if self._plugin.requiresGridPosition():
64 self.adjustSize()
65
66 self.update()
67
69 '''
70 Alanı deforme eden kareleri oluşturur.
71 '''
72 if not self._plugin.requiresGridPosition():
73 ReportItem.createSizeHandlers(self)
74
75 - def setProperty(self, property, value):
76 '''
77 Alanın bir özelliğini değiştirir.
78 '''
79 ReportItem.setProperty(self, property, value)
80
81 if self._plugin.requiresGridPosition():
82 self.adjustSize()
83
84 if property == 'fontfamily':
85 self._font.setFamily(value)
86
87 elif property == 'fontsize':
88 self._font.setPointSize(int(value))
89
90 elif property == 'fontbold':
91 self._font.setBold(str(value) == 'T')
92
93 elif property == 'fontitalic':
94 self._font.setItalic(str(value) == 'T')
95
96 elif property == 'foreground':
97 if value is None:
98 self._foregroundColor = QColor()
99 else:
100 self._foregroundColor = QColor(long(value))
101
102 elif property == 'background':
103 if value is None:
104 self._backgroundColor = QColor()
105 else:
106 self._backgroundColor = QColor(long(value))
107
108 - def adjustSize(self):
109 '''
110 Alanın boyutlarını yazıya göre ayarlar.
111 '''
112 if self._plugin.requiresGridPosition():
113 self.setWidth(self._plugin.unit().pointWidth(len(self.text())))
114
115 - def getAdjustSize(self):
116 '''
117 İçindeki yazının kapladığı alanı bulup döndürüyoruz.
118 '''
119 fontMetrics = QFontMetrics(self._font)
120
121 width = fontMetrics.width(tr(self._properties['text']))
122 height = fontMetrics.height()
123
124 width = max(width, self._plugin.gridDx())
125 height = max(height, self._plugin.gridDy())
126
127 return QSizeF(width, height)
128
130 '''
131 Özellik editöründeki editörlerini döndürür.
132 '''
133 return self._plugin.textAreaPropertyMeta()
134
136 '''
137 Alanın içerisindeki yazı değişeceği zaman çalışır.
138 '''
139 pos = self.scenePos()
140 size = self.rect().size()
141 self.scene().emit(SIGNAL('beginTextAreaEditing(PyQt_PyObject, QPointF, QSizeF, QString)'),
142 self, pos, size, self.text())
143
144 - def dumpToDict(self):
145 '''
146 Alanın özelliklerini bir dict'e yazar.
147 '''
148 return self._plugin.dumpTextArea(self)
149
150 - def restoreFromDict(self, dump, x, y):
151 '''
152 Nesnenin özelliklerini dump'tan alarak nesneye ekler.
153 '''
154 self.setPos(x, y)
155 self.setZValue(self._editor.getNextZ())
156
157 self._plugin.restoreTextAreaFromDict(self, dump)
158
159 @staticmethod
160 - def createFromDict(dump, parent, editor, x, y):
161 '''
162 Dict tanımından yeni bir yazı alanı oluşturur.
163 '''
164 textArea = TextArea(parent, editor, editor.plugin())
165 textArea.restoreFromDict(dump, x, y)
166
167 return textArea
168
169 - def paint(self, painter, option, widget):
170 '''
171 Alanın şeklini çizer.
172 '''
173 rect = self.rect()
174
175 width = self.width()
176 height = self.height()
177 text = self.text()
178
179 isManipulated = False
180
181
182 if width < 1 or height < 1:
183 isManipulated = True
184
185 else:
186 textRect = QRectF(rect)
187 if not self._plugin.requiresGridPosition():
188 textRect = rect.adjusted(2, 0, 0, 0)
189
190 painter.setPen(Qt.black)
191
192 flags = self._plugin.paintingAlignmentFlags(self._properties)
193
194 bgColor = QColor('lavender')
195
196 if self._backgroundColor.isValid() and self._backgroundColor != Qt.white:
197 bgColor = self._backgroundColor
198
199 bgColor.setAlpha(90)
200 painter.fillRect(self.rect(), bgColor)
201 painter.setFont(self._font)
202
203 pen = QPen()
204
205 if self._foregroundColor.isValid() and self._foregroundColor != Qt.white:
206 pen.setColor(self._foregroundColor)
207
208 painter.setPen(pen)
209 painter.drawText(textRect, flags, tr(text))
210
211 if not self._plugin.requiresGridPosition():
212 if self._properties['drawframe'] == 'T':
213 painter.drawRect(rect)
214
215
216 if option.state & QStyle.State_Selected:
217
218
219
220 shadowColor = QColor(243, 243, 243, 90)
221
222 if isManipulated:
223 shadowColor = QColor(243, 0, 0, 90)
224
225 painter.fillRect(self.rect(), shadowColor)
226 pen = QPen(Qt.red)
227 pen.setStyle(Qt.DotLine)
228 painter.setPen(pen)
229 painter.drawRect(self.rect())
230
231
232 rects = self.collidingRects()
233 for rect in rects:
234 painter.fillRect(rect, QColor(255, 165, 0, 50))
235