Changeset 516 for nodebox/branches

Show
Ignore:
Timestamp:
10/09/08 13:55:29 (3 months ago)
Author:
stefan
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • nodebox/branches/try-qt-painter/nodebox/graphics/qt.py

    r494 r516  
    222222        ColorMixin.__init__(self, **kwargs) 
    223223        self._segment_cache = None 
    224         self._qpath_segment_cache = None 
     224        self._qPath_segment_cache = None 
    225225        if path is None: 
    226             self._qpath = QPainterPath() 
     226            self._qPath = QPainterPath() 
    227227        elif isinstance(path, (list,tuple)): 
    228             self._qpath = QPainterPath() 
     228            self._qPath = QPainterPath() 
    229229            self.extend(path) 
    230230        elif isinstance(path, BezierPath): 
    231             self._qpath = QPainterPath(path._qpath) 
     231            self._qPath = QPainterPath(path._qPath) 
    232232            _copy_attrs(path, self, self.stateAttributes) 
    233233        elif isinstance(path, QPainterPath): 
    234             self._qpath = path 
     234            self._qPath = path 
    235235        else: 
    236236            raise NodeBoxError, "Don't know what to do with %s." % path 
    237237             
    238238    def _get_path(self): 
    239         warnings.warn("The 'path' attribute is deprecated. Please use _qpath instead.", DeprecationWarning, stacklevel=2) 
    240         return self._qpath 
     239        warnings.warn("The 'path' attribute is deprecated. Please use _qPath instead.", DeprecationWarning, stacklevel=2) 
     240        return self._qPath 
    241241    path = property(_get_path) 
    242242 
     
    248248    def moveto(self, x, y): 
    249249        self._segment_cache = None 
    250         self._qpath_segment_cache = None 
    251         self._qpath.moveTo(x, y) 
     250        self._qPath_segment_cache = None 
     251        self._qPath.moveTo(x, y) 
    252252 
    253253    def lineto(self, x, y): 
    254254        self._segment_cache = None 
    255         self._qpath_segment_cache = None 
    256         self._qpath.lineTo(x, y) 
     255        self._qPath_segment_cache = None 
     256        self._qPath.lineTo(x, y) 
    257257 
    258258    def curveto(self, x1, y1, x2, y2, x3, y3): 
    259259        self._segment_cache = None 
    260         self._qpath_segment_cache = None 
    261         self._qpath.cubicTo(x1, y1, x2, y2, x3, y3) 
     260        self._qPath_segment_cache = None 
     261        self._qPath.cubicTo(x1, y1, x2, y2, x3, y3) 
    262262 
    263263    def closepath(self): 
    264264        self._segment_cache = None 
    265         self._qpath_segment_cache = None 
    266         self._qpath.closeSubpath() # XXX: Is this correct? 
     265        self._qPath_segment_cache = None 
     266        self._qPath.closeSubpath() # XXX: Is this correct? 
    267267 
    268268    def setlinewidth(self, width): 
     
    271271    def _get_bounds(self): 
    272272        try: 
    273             r = self._qpath.boundingRect() 
     273            r = self._qPath.boundingRect() 
    274274            return (r.x(), r.y()), (r.width(), r.height()) 
    275275        except: 
     
    280280 
    281281    def contains(self, x, y): 
    282         return self._qpath.contains(QPointF(x,y)) 
     282        return self._qPath.contains(QPointF(x,y)) 
    283283         
    284284    ### Basic shapes ### 
     
    286286    def rect(self, x, y, width, height): 
    287287        self._segment_cache = None 
    288         self._qpath_segment_cache = None 
    289         self._qpath.addRect(x, y, width, height) 
     288        self._qPath_segment_cache = None 
     289        self._qPath.addRect(x, y, width, height) 
    290290         
    291291    def oval(self, x, y, width, height): 
    292292        self._segment_cache = None 
    293         self._qpath_segment_cache = None 
    294         self._qpath.addEllipse(x, y, width, height) 
     293        self._qPath_segment_cache = None 
     294        self._qPath.addEllipse(x, y, width, height) 
    295295         
    296296    def line(self, x1, y1, x2, y2): 
    297297        self._segment_cache = None 
    298         self._qpath_segment_cache = None 
    299         self._qpath.moveTo(x1, y1) 
    300         self._qpath.lineTo(x2, y2) 
     298        self._qPath_segment_cache = None 
     299        self._qPath.moveTo(x1, y1) 
     300        self._qPath.lineTo(x2, y2) 
    301301 
    302302    ### List methods ### 
    303303 
    304304    def __getitem__(self, index): 
    305         if self._qpath_segment_cache == None: 
    306             self._set_qpath_segment_cache() 
    307         cmd, el = self._qpath_segment_cache[index] 
     305        if self._qPath_segment_cache == None: 
     306            self._set_qPath_segment_cache() 
     307        cmd, el = self._qPath_segment_cache[index] 
    308308        return PathElement(cmd, el) 
    309309 
     
    313313 
    314314    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),))) 
    331328            elif el.type == CURVETO: 
    332                 ctrl1 = self._qpath.elementAt(i+1) 
    333                 ctrl2 = self._qpath.elementAt(i+2) 
    334                 self._qpath_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)))) 
    335332 
    336333    def extend(self, pathElements): 
    337334        self._segment_cache = None 
    338         self._qpath_segment_cache = None 
     335        self._qPath_segment_cache = None 
    339336        for el in pathElements: 
    340337            if isinstance(el, (list, tuple)): 
     
    352349    def append(self, el): 
    353350        self._segment_cache = None 
    354         self._qpath_segment_cache = None 
     351        self._qPath_segment_cache = None 
    355352        if el.cmd == MOVETO: 
    356353            self.moveto(el.x, el.y) 
     
    395392        else: 
    396393            painter.setPen(Qt.NoPen) 
    397         painter.drawPath(self._qpath) 
     394        painter.drawPath(self._qPath) 
    398395        painter.restore() 
    399396         
     
    433430                t.scale(min(width /pw, height / ph)) 
    434431        t.translate(-px, -py) 
    435         self._qpath = t.transformBezierPath(self)._qpath 
     432        self._qPath = t.transformBezierPath(self)._qPath 
    436433         
    437434    ### Mathematics ### 
     
    476473        self._qPath = bezier.insert_point(self, t)._qPath 
    477474        self._segment_cache = None 
    478         self._qpath_segment_cache = None 
     475        self._qPath_segment_cache = None 
    479476 
    480477    ### Clipping operations ### 
    481478 
    482479    def intersects(self, other): 
    483         return self._qpath.intersects(other._qpath) 
     480        return self._qPath.intersects(other._qPath) 
    484481 
    485482    def union(self, other, flatness=0.6): 
    486         return BezierPath(self._ctx, self._qpath.united(other._qpath)) 
     483        return BezierPath(self._ctx, self._qPath.united(other._qPath)) 
    487484 
    488485    def intersect(self, other, flatness=0.6): 
    489         return BezierPath(self._ctx, self._qpath.intersected(other._qpath)) 
     486        return BezierPath(self._ctx, self._qPath.intersected(other._qPath)) 
    490487 
    491488    def difference(self, other, flatness=0.6): 
    492         return BezierPath(self._ctx, self._qpath.subtracted(other._qpath)) 
     489        return BezierPath(self._ctx, self._qPath.subtracted(other._qPath)) 
    493490 
    494491    def xor(self, other, flatness=0.6): 
    495         union = self._qpath.united(other._qpath) 
    496         intersection = self._qpath.intersected(other._qpath) 
     492        union = self._qPath.united(other._qPath) 
     493        intersection = self._qPath.intersected(other._qPath) 
    497494        return BezierPath(self._ctx, union.subtracted(intersection)) 
    498495 
     
    559556        painter.save() 
    560557        cp = self.path.transform.transformBezierPath(self.path) 
    561         painter.setClipPath(cp._qpath) 
     558        painter.setClipPath(cp._qPath) 
    562559        for grob in self._grobs: 
    563560            grob._draw(painter) 
     
    909906            point = QPointF(*point) 
    910907        elif isinstance(point, Point): 
    911             point = point._qPoint 
     908            point = QPointF(point.x, point.y) 
    912909        return self._qtransform.map(point) 
    913910 
     
    917914        else: 
    918915            raise NodeBoxError, "Can only transform BezierPaths" 
    919         path._qpath = self._qtransform.map(path._qpath) 
     916        path._qPath = self._qtransform.map(path._qPath) 
    920917        return path 
    921918