// Implementation of QTreeArrow #include <clientapi.h> #include <qapplication.h> #include <qcanvas.h> #include <qpainter.h> #include "qtreeitem.h" #include "changesorter.h" #include "filehead.h" #include "filelogcache.h" #include "qtreerevtext.h" #include "qtreerevball.h" #include "qtreearrow.h" QTreeArrow::QTreeArrow( QTreeRevBall* source, QTreeRevBall* target, FLCArrowType type, Contrib contrib ) : QCanvasItem( source->canvas() ), atype( type ), acontrib( contrib ), mypen( QPen() ) { setZ( TREE_ZARROW ); // figure out color and width from type and contrib UpdatePen(); if ( source->y() == target->y() ) // same FileStripe { // Horizontal arrow. start = QPoint( source->x() + TREE_BALLRAD, source->y() ); end = QPoint( target->x() - TREE_BALLRAD, target->y() ); } else { if ( source->y() > target->y() ) // target is higher { // Lower left to upper right arrow. start = QPoint( source->x(), source->y() - TREE_BALLRAD ); end = QPoint( target->x(), target->y() + TREE_BALLRAD ); } else //target is lower { // Upper left to lower right. start = QPoint( source->x(), source->y() + TREE_BALLRAD ); end = QPoint( target->x(), target->y() - TREE_BALLRAD ); } } } QTreeArrow::~QTreeArrow() { } // Called on construction or after changing the color scheme. void QTreeArrow::UpdatePen() { switch ( atype ) { case edit: mycolor = QColor( TREE_COLARROWR ); break; case branch: mycolor = QColor( TREE_COLARROWB ); break; case copy: mycolor = QColor( TREE_COLARROWC ); break; case ignore: mycolor = QColor( TREE_COLARROWI ); break; case impure: mycolor = QColor( TREE_COLARROWE ); break; case merge: mycolor = QColor( TREE_COLARROWM ); break; case a_broken: mycolor = QColor( TREE_COLBALLE ); break; } mypen.setColor( mycolor ); switch ( acontrib ) { case all: mypen.setWidth( TREE_ARRWIDTH ); mypen.setStyle( SolidLine ); break; case some: mypen.setWidth( TREE_ARRWIDTH/2 ); mypen.setStyle( SolidLine ); break; case none: mypen.setWidth( TREE_ARRWIDTH/3 ); mypen.setStyle( DashLine ); break; case c_broken: mypen.setWidth( TREE_ARRWIDTH/3 ); mypen.setStyle( SolidLine ); } update(); } void QTreeArrow::draw( QPainter& p ) { p.setPen( mypen ); p.setBrush( QBrush::NoBrush ); if ( start.y() == end.y() ) // draw straight line { p.drawLine( start, QPoint( end.x() - TREE_ARRHEAD, end.y() ) ); QPointArray pa = QPointArray( 3 ); // triangular arrowhead pa.putPoints( 0, 3, end.x() - TREE_ARRHEAD, end.y() - TREE_ARRHEAD, end.x(), end.y(), end.x() - TREE_ARRHEAD, end.y() + TREE_ARRHEAD ); // Make sure triangle is filled and has a thin pen. p.setPen( QPen(mycolor) ); p.setBrush( QBrush(mycolor) ); p.drawConvexPolygon( pa, 0, 3 ); } else // draw cubic bezier { short offset; // leave room for arrowhead if (start.y() > end.y()) offset = TREE_ARRHEAD; // lower to upper else offset = -1*TREE_ARRHEAD; // upper to lower QPointArray bez, tri; bez = QPointArray(4); // bezier control points tri = QPointArray(3); // trianglular arrowhead // Draw the bezier. bez.putPoints( 0, 4, start.x(), start.y(), start.x() + ( end.x() - start.x() )/4, end.y() + offset - ( end.y() - start.y() )/4, end.x() - ( end.x() - start.x() )/4, start.y() + ( end.y() + offset - start.y() )/4, end.x(), end.y() + offset ); p.drawCubicBezier(bez); // Draw the arrowhead. if ( start.y() > end.y() ) // point up { tri.putPoints( 0, 3, end.x(), end.y(), end.x() + TREE_ARRHEAD, end.y() + TREE_ARRHEAD, end.x() - TREE_ARRHEAD, end.y() + TREE_ARRHEAD ); } else // point down { tri.putPoints( 0, 3, end.x(), end.y(), end.x() + TREE_ARRHEAD, end.y() - TREE_ARRHEAD, end.x() - TREE_ARRHEAD, end.y() - TREE_ARRHEAD ); } // Make sure triangle is filled and has a thin pen. p.setPen( QPen( mycolor ) ); p.setBrush( QBrush( mycolor ) ); p.drawConvexPolygon( tri, 0, 3 ); } } QRect QTreeArrow::boundingRect() const { QPoint tplt, btrt; if ( start.y() == end.y() ) { tplt = QPoint( start.x(), start.y() - TREE_ARRHEAD ); btrt = QPoint( end.x(), end.y() + TREE_ARRHEAD ); } else if ( start.y() > end.y() ) // lower left -> upper right { tplt = QPoint( start.x() - TREE_ARRHEAD, end.y() ); btrt = QPoint( end.x() + TREE_ARRHEAD, start.y() ); } else // top left -> lower right { tplt = QPoint( start.x() - TREE_ARRHEAD, start.y() ); btrt = QPoint( end.x() + TREE_ARRHEAD, end.y() ); } return QRect( tplt, btrt ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 2515 | Sam Stafford |
Work around Qt export-to-SVG bug. SVGs now save correctly. |
||
#1 | 2377 | Sam Stafford | P4QTree. |