Package mcbase :: Package libs :: Package designeditor :: Module image
[hide private]
[frames] | no frames]

Source Code for Module mcbase.libs.designeditor.image

  1  # -*- coding: utf-8 -*- 
  2   
  3  ########################################################################## 
  4  # image.py 
  5  # 
  6  # Resim 
  7  # 
  8  # (C) 2007 Likya Yazılım ve Bilişim Hizmetleri Ltd. Şti. 
  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):
24 ''' 25 Çizgi nesnesini oluşturur. 26 ''' 27 ReportItem.__init__(self, parent, editor, plugin) 28 29 self._properties = dict(Constants.DEFAULT_GRAPHICS_IMAGE_PROPERTIES) 30 31 self._image = icons.imagePixmap.toImage() 32 33 self._color = QColor(200, 200, 200) 34 self._brush = QBrush(self._color, Qt.Dense5Pattern) 35 self._aspectRatio = Qt.KeepAspectRatio 36 37 self._toolTipProperties['title'] = tr('Resim')
38
39 - def setProperty(self, property, value):
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
60 - def propertyMeta(self):
61 ''' 62 Özellik editöründeki editörlerini döndürür. 63 ''' 64 meta = [ 65 ('Yatay Yaslama', '', 'hjustify', 'PComboBox', ([('ljust','Sola'), ('rjust','Sağa'), ('hcenter','Orta')],)), 66 ('Dikey Yaslama', '', 'vjustify', 'PComboBox', ([('tjust','Üste'), ('bjust','Aşağıya'), ('vcenter','Orta')],)), 67 ('Resim Boyu', '', 'scaled', 'PComboBox', ([('T', 'Çerçeve Boyu'), ('F', 'Kendi Boyu')],)), 68 ('Kenar Oranları', '', 'aspectratio', 'PComboBox', ([ 69 (Qt.KeepAspectRatio, 'Sabit'), 70 (Qt.IgnoreAspectRatio, 'Çerçeveye Uyarla'), 71 ],)), 72 ('Zemin Rengi', '', 'background', 'PColorPicker', ()), 73 ('Resim Seç', '', 'data', 'PImageChooser', ()), 74 ('Alan Seç', '', 'field', 'PFieldChooser', ('image',)), 75 ] 76 77 return meta
78
79 - def getAdjustSize(self):
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
88 - def setImageData(self, data):
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
98 - def dumpToDict(self):
99 ''' 100 Çizginin özelliklerini bir dict'e yazar. 101 ''' 102 dump = {} 103 104 dump['class'] = 'Image' 105 dump['x'] = self._plugin.unit().unitWidth(self.pos().x()) 106 dump['y'] = self._plugin.unit().unitHeight(self.pos().y()) 107 dump['width'] = self._plugin.unit().unitWidth(self.width()) 108 dump['height'] = self._plugin.unit().unitWidth(self.height()) 109 dump['status'] = self._editor.fieldStatusFromFrameCode(self._parent.frameCode()) 110 dump['properties'] = self.properties() 111 112 return dump
113
114 - def mouseDoubleClickEvent(self, e):
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
120 - def restoreFromDict(self, dump, x, y):
121 ''' 122 Nesnenin özelliklerini dump'tan alarak nesneye ekler. 123 ''' 124 self.setPos(x, y) 125 126 width = self._plugin.unit().pointWidth(float(dump['width'])) 127 height = self._plugin.unit().pointHeight(float(dump['height'])) 128 129 self.setZValue(self._editor.getNextZ()) 130 self.setWidth(width) 131 self.setHeight(height) 132 133 for property, value in dump['properties'].items(): 134 self.setProperty(property, value)
135 136 @staticmethod
137 - def createFromDict(dump, parent, editor, x, y):
138 ''' 139 Dict tanımından yeni bir çizgi oluşturur. 140 ''' 141 width = float(dump['width']) 142 height = float(dump['height']) 143 144 rect = Image(parent, editor, editor.plugin()) 145 rect.restoreFromDict(dump, x, y) 146 147 return rect
148
149 - def sourceRect(self, image):
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 # Yatay konumlandırma 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 # Dikey konumlandırma 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
188 - def targetPoint(self, image):
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 # Yatay konumlandırma 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 # Dikey konumlandırma 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 # Eğer gereğinden fazla küçülmüş ise. 232 if width < 1 or height < 1: 233 isManipulated = True 234 235 else: 236 237 pen = QPen() 238 239 # Eğer dikdörtgen seçili ise. 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 # Kesişen alanları çiziyoruz. 259 rects = self.collidingRects() 260 for rect in rects: 261 painter.fillRect(rect, QColor(255, 165, 0, 50))
262