- Timestamp:
- 10/09/08 13:55:29 (3 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
nodebox/branches/try-qt-painter/nodebox/graphics/qt.py
r494 r516 222 222 ColorMixin.__init__(self, **kwargs) 223 223 self._segment_cache = None 224 self._q path_segment_cache = None224 self._qPath_segment_cache = None 225 225 if path is None: 226 self._q path = QPainterPath()226 self._qPath = QPainterPath() 227 227 elif isinstance(path, (list,tuple)): 228 self._q path = QPainterPath()228 self._qPath = QPainterPath() 229 229 self.extend(path) 230 230 elif isinstance(path, BezierPath): 231 self._q path = QPainterPath(path._qpath)231 self._qPath = QPainterPath(path._qPath) 232 232 _copy_attrs(path, self, self.stateAttributes) 233 233 elif isinstance(path, QPainterPath): 234 self._q path = path234 self._qPath = path 235 235 else: 236 236 raise NodeBoxError, "Don't know what to do with %s." % path 237 237 238 238 def _get_path(self): 239 warnings.warn("The 'path' attribute is deprecated. Please use _q path instead.", DeprecationWarning, stacklevel=2)240 return self._q path239 warnings.warn("The 'path' attribute is deprecated. Please use _qPath instead.", DeprecationWarning, stacklevel=2) 240 return self._qPath 241 241 path = property(_get_path) 242 242 … … 248 248 def moveto(self, x, y): 249 249 self._segment_cache = None 250 self._q path_segment_cache = None251 self._q path.moveTo(x, y)250 self._qPath_segment_cache = None 251 self._qPath.moveTo(x, y) 252 252 253 253 def lineto(self, x, y): 254 254 self._segment_cache = None 255 self._q path_segment_cache = None256 self._q path.lineTo(x, y)255 self._qPath_segment_cache = None 256 self._qPath.lineTo(x, y) 257 257 258 258 def curveto(self, x1, y1, x2, y2, x3, y3): 259 259 self._segment_cache = None 260 self._q path_segment_cache = None261 self._q path.cubicTo(x1, y1, x2, y2, x3, y3)260 self._qPath_segment_cache = None 261 self._qPath.cubicTo(x1, y1, x2, y2, x3, y3) 262 262 263 263 def closepath(self): 264 264 self._segment_cache = None 265 self._q path_segment_cache = None266 self._q path.closeSubpath() # XXX: Is this correct?265 self._qPath_segment_cache = None 266 self._qPath.closeSubpath() # XXX: Is this correct? 267 267 268 268 def setlinewidth(self, width): … … 271 271 def _get_bounds(self): 272 272 try: 273 r = self._q path.boundingRect()273 r = self._qPath.boundingRect() 274 274 return (r.x(), r.y()), (r.width(), r.height()) 275 275 except: … … 280 280 281 281 def contains(self, x, y): 282 return self._q path.contains(QPointF(x,y))282 return self._qPath.contains(QPointF(x,y)) 283 283 284 284 ### Basic shapes ### … … 286 286 def rect(self, x, y, width, height): 287 287 self._segment_cache = None 288 self._q path_segment_cache = None289 self._q path.addRect(x, y, width, height)288 self._qPath_segment_cache = None 289 self._qPath.addRect(x, y, width, height) 290 290 291 291 def oval(self, x, y, width, height): 292 292 self._segment_cache = None 293 self._q path_segment_cache = None294 self._q path.addEllipse(x, y, width, height)293 self._qPath_segment_cache = None 294 self._qPath.addEllipse(x, y, width, height) 295 295 296 296 def line(self, x1, y1, x2, y2): 297 297 self._segment_cache = None 298 self._q path_segment_cache = None299 self._q path.moveTo(x1, y1)300 self._q path.lineTo(x2, y2)298 self._qPath_segment_cache = None 299 self._qPath.moveTo(x1, y1) 300 self._qPath.lineTo(x2, y2) 301 301 302 302 ### List methods ### 303 303 304 304 def __getitem__(self, index): 305 if self._q path_segment_cache == None:306 self._set_q path_segment_cache()307 cmd, el = self._q path_segment_cache[index]305 if self._qPath_segment_cache == None: 306 self._set_qPath_segment_cache() 307 cmd, el = self._qPath_segment_cache[index] 308 308 return PathElement(cmd, el) 309 309 … … 313 313 314 314 def __len__(self): 315 if self._qpath_segment_cache == None: 316 self._set_qpath_segment_cache() 317 return len(self._qpath_segment_cache) 318 319 def _set_qpath_segment_cache(self): 320 self._qpath_segment_cache = [] 321 length = self._qpath.elementCount() 322 temp = [] 323 for i in range(length): 324 el = self._qpath.elementAt(i) 325 if el.type in [LINETO, MOVETO, CURVETO, CLOSE]: 326 temp.append(i) 327 for i in temp: 328 el = self._qpath.elementAt(i) 329 if el.type in [LINETO, MOVETO, CLOSE]: 330 self._qpath_segment_cache.append((el.type, ((el.x, el.y),))) 315 if self._qPath_segment_cache == None: 316 self._set_qPath_segment_cache() 317 return len(self._qPath_segment_cache) 318 319 def _set_qPath_segment_cache(self): 320 self._qPath_segment_cache = [] 321 count = self._qPath.elementCount() 322 for i in xrange(count): 323 el = self._qPath.elementAt(i) 324 if el.type == CLOSE: 325 self._qPath_segment_cache.append((el.type, ())) 326 elif el.type in [LINETO, MOVETO]: 327 self._qPath_segment_cache.append((el.type, ((el.x, el.y),))) 331 328 elif el.type == CURVETO: 332 ctrl1 = self._q path.elementAt(i+1)333 ctrl2 = self._q path.elementAt(i+2)334 self._q path_segment_cache.append((el.type, ((el.x, el.y), (ctrl1.x, ctrl1.y), (ctrl2.x, ctrl2.y))))329 ctrl1 = self._qPath.elementAt(i+1) 330 ctrl2 = self._qPath.elementAt(i+2) 331 self._qPath_segment_cache.append((el.type, ((el.x, el.y), (ctrl1.x, ctrl1.y), (ctrl2.x, ctrl2.y)))) 335 332 336 333 def extend(self, pathElements): 337 334 self._segment_cache = None 338 self._q path_segment_cache = None335 self._qPath_segment_cache = None 339 336 for el in pathElements: 340 337 if isinstance(el, (list, tuple)): … … 352 349 def append(self, el): 353 350 self._segment_cache = None 354 self._q path_segment_cache = None351 self._qPath_segment_cache = None 355 352 if el.cmd == MOVETO: 356 353 self.moveto(el.x, el.y) … … 395 392 else: 396 393 painter.setPen(Qt.NoPen) 397 painter.drawPath(self._q path)394 painter.drawPath(self._qPath) 398 395 painter.restore() 399 396 … … 433 430 t.scale(min(width /pw, height / ph)) 434 431 t.translate(-px, -py) 435 self._q path = t.transformBezierPath(self)._qpath432 self._qPath = t.transformBezierPath(self)._qPath 436 433 437 434 ### Mathematics ### … … 476 473 self._qPath = bezier.insert_point(self, t)._qPath 477 474 self._segment_cache = None 478 self._q path_segment_cache = None475 self._qPath_segment_cache = None 479 476 480 477 ### Clipping operations ### 481 478 482 479 def intersects(self, other): 483 return self._q path.intersects(other._qpath)480 return self._qPath.intersects(other._qPath) 484 481 485 482 def union(self, other, flatness=0.6): 486 return BezierPath(self._ctx, self._q path.united(other._qpath))483 return BezierPath(self._ctx, self._qPath.united(other._qPath)) 487 484 488 485 def intersect(self, other, flatness=0.6): 489 return BezierPath(self._ctx, self._q path.intersected(other._qpath))486 return BezierPath(self._ctx, self._qPath.intersected(other._qPath)) 490 487 491 488 def difference(self, other, flatness=0.6): 492 return BezierPath(self._ctx, self._q path.subtracted(other._qpath))489 return BezierPath(self._ctx, self._qPath.subtracted(other._qPath)) 493 490 494 491 def xor(self, other, flatness=0.6): 495 union = self._q path.united(other._qpath)496 intersection = self._q path.intersected(other._qpath)492 union = self._qPath.united(other._qPath) 493 intersection = self._qPath.intersected(other._qPath) 497 494 return BezierPath(self._ctx, union.subtracted(intersection)) 498 495 … … 559 556 painter.save() 560 557 cp = self.path.transform.transformBezierPath(self.path) 561 painter.setClipPath(cp._q path)558 painter.setClipPath(cp._qPath) 562 559 for grob in self._grobs: 563 560 grob._draw(painter) … … 909 906 point = QPointF(*point) 910 907 elif isinstance(point, Point): 911 point = point._qPoint908 point = QPointF(point.x, point.y) 912 909 return self._qtransform.map(point) 913 910 … … 917 914 else: 918 915 raise NodeBoxError, "Can only transform BezierPaths" 919 path._q path = self._qtransform.map(path._qpath)916 path._qPath = self._qtransform.map(path._qPath) 920 917 return path 921 918
