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

Source Code for Module mcbase.libs.designeditor.rectangle

  1  # -*- coding: utf-8 -*- 
  2   
  3  ########################################################################## 
  4  # rectangle.py 
  5  # 
  6  # Dikdörtgen 
  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 -class Rectangle(ReportItem):
19
20 - def __init__(self, parent, editor, plugin):
21 ''' 22 Çizgi nesnesini oluşturur. 23 ''' 24 ReportItem.__init__(self, parent, editor, plugin) 25 26 self._properties = dict(Constants.DEFAULT_GRAPHICS_RECTANGLE_PROPERTIES) 27 28 self._pen = QPen() 29 self._pen.setJoinStyle(Qt.MiterJoin) 30 31 self._toolTipProperties['title'] = tr('Dikdörtgen') 32 self._foregroundColor = QColor()
33
34 - def setProperty(self, property, value):
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
57 - def propertyMeta(self):
58 ''' 59 Özellik editöründeki editörlerini döndürür. 60 ''' 61 meta = [ 62 ('Çizgi Kalınlığı', '', 'thickness', 'PSpinBox', (1, 10)), 63 ('Çizgi Stili', '', 'linestyle', 'PStyleComboBox', ([ 64 (Qt.SolidLine, 'Düz Çizgi'), 65 (Qt.DashLine, 'Kesik Çizgi'), 66 (Qt.DotLine, 'Noktalı Çizgi'), 67 (Qt.DashDotLine, 'Kesik-Noktalı Çizgi'), 68 ],)), 69 ('Köşe Şekli', '', 'cornertype', 'PComboBox', ([ 70 ('flat', 'Düz'), 71 ('round', 'Yuvarlak'), 72 ],)), 73 ('Köşe Stili', '', 'cornerstyle', 'PStyleComboBox', ([ 74 (Qt.MiterJoin, 'Düz'), 75 (Qt.RoundJoin, 'Yuvarlak'), 76 (Qt.BevelJoin, 'Üçgensel'), 77 ],)), 78 ('Kalem Rengi', '', 'foreground', 'PColorPicker', ()), 79 ] 80 81 return meta
82
83 - def dumpToDict(self):
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
98 - def restoreFromDict(self, dump, x, y):
99 ''' 100 Nesnenin özelliklerini dump'tan alarak nesneye ekler. 101 ''' 102 self.setPos(x, y) 103 104 width = self._plugin.unit().pointWidth(float(dump['width'])) 105 height = self._plugin.unit().pointHeight(float(dump['height'])) 106 107 self.setZValue(self._editor.getNextZ()) 108 self.setWidth(width) 109 self.setHeight(height) 110 111 for property, value in dump['properties'].items(): 112 self.setProperty(property, value)
113 114 @staticmethod
115 - def createFromDict(dump, parent, editor, x, y):
116 ''' 117 Dict tanımından yeni bir çizgi oluşturur. 118 ''' 119 width = float(dump['width']) 120 height = float(dump['height']) 121 122 rect = Rectangle(parent, editor, editor.plugin()) 123 rect.restoreFromDict(dump, x, y) 124 125 return rect
126
127 - def shape(self):
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 # Eğer gereğinden fazla küçülmüş ise. 164 if width < 1 or height < 1: 165 isManipulated = True 166 167 else: 168 # Eğer dikdörtgen seçili ise. 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 # Kesişen alanları çiziyoruz. 193 rects = self.collidingRects() 194 for rect in rects: 195 painter.fillRect(rect, QColor(255, 165, 0, 50))
196