// Implementation of QTreeRevBall.
#include <clientapi.h>
#include <qcanvas.h>
#include <qdialog.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qmessagebox.h>
#include <qpainter.h>
#include <qpushbutton.h>
#include "changesorter.h"
#include "filehead.h"
#include "filelogcache.h"
#include "qtreeitem.h"
#define QTREEREVDIALOG_H
#include "qtreerevdialog.h"
#include "qtreerevtext.h"
#include "qtreerevball.h"
QTreeRevBall::QTreeRevBall
( QCanvas* canv, FileRev* frev, int y, int vspace, bool trunc )
: QCanvasPolygonalItem( canv ), rev( frev )
{
// The FileRev needs to know what RevBall represents it.
rev->revball = this;
setPen( QPen( black, 2 ) );
// Set position.
setZ( TREE_ZBALL );
// If this is a truncated view, align the revballs relative to
// the set of changelists that will be displayed.
if ( trunc )
move( ( rev->fh->flc->changes->GetArrPos( rev->change ) - 1 )
* TREE_BALLSPACE + TREE_BALLSPACE/2, y + TREE_BALLRAD + 4 );
else
move( ( rev->fh->flc->changes->GetPos( rev->change ) - 1 )
* TREE_BALLSPACE + TREE_BALLSPACE/2, y + TREE_BALLRAD + 4 );
// Revision text goes in the middle of the ball.
revtext = new QTreeRevText( canv, rev->rev.Text() );
revtext->move( this->x()-revtext->boundingRect().width()/2,
this->y()-revtext->boundingRect().height()/2 );
if ( rev->type == DEL ) revtext->setColor( QColor( "whitesmoke" ) );
}
QTreeRevBall::~QTreeRevBall()
{
}
// Set color based on defs in qtreeitem.h.
void QTreeRevBall::UpdateBrush()
{
QColor color;
switch( rev->type )
{
case( ADD ):
case( BRANCH ):
color = QColor( TREE_COLBALLA );
break;
case( DEL ):
color = QColor( TREE_COLBALLD );
break;
case( EDIT ):
color = QColor( TREE_COLBALLE );
break;
case( INTEG ):
color = QColor( TREE_COLBALLI );
break;
}
setBrush( QBrush( color ) );
}
StrBuf QTreeRevBall::Name()
{
StrBuf filerev;
filerev.Set( rev->fh->name );
filerev.Append( "#" );
filerev.Append( rev->rev.Text() );
return filerev;
}
bool QTreeRevBall::IsBinary()
{
QString ftype = rev->ftype.Text();
return ftype.contains( "binary" );
}
// The areaPoints() and drawShape() methods are for the most part
// cribbed from qcanvas.cpp. The main difference is that the
// areaPoints() method takes the outline into account, thus fixing
// QCanvasEllipse's inability to support an outline. Drawing the
// revtext directly in drawShape() is just performance gravy.
QPointArray QTreeRevBall::areaPoints() const
{
QPointArray r;
// makeArc at 0,0, then translate to avoid math overflow
// This is a workaround for a Qt bug.
r.makeArc( int( -TREE_BALLRAD - 1 - pen().width() ),
int( -TREE_BALLRAD-1-pen().width() ),
( TREE_BALLRAD + pen().width() + 1 )*2,
( TREE_BALLRAD + pen().width() + 1 )*2,
0 ,360*16 );
r.translate( x(), y() );
r.resize( r.size() + 1 );
r.setPoint( r.size()-1, int( x() ), int( y() ) );
return r;
}
void QTreeRevBall::drawShape( QPainter& p )
{
p.drawEllipse( int( x() - TREE_BALLRAD + 0.5 ),
int( y() - TREE_BALLRAD + 0.5 ),
TREE_BALLRAD*2, TREE_BALLRAD*2 );
revtext->draw( p );
}
void QTreeRevBall::InfoDialog( QWidget* parent )
{
QDialog* dia = new QTreeRevDialog( parent, rev );
dia->exec();
delete dia;
}