#include <clientapi.h>
#include <qcanvas.h>
#include "qtreeitem.h"
#include "clientjobdescuser.h"
#include "qtreejobtext.h"
#include "changesorter.h"
#include "clientjobuser.h"
#include "qtreejobbar.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
QTreeJobBar::QTreeJobBar
( QCanvas* canvas, int width, int y,
ChangeSorter* changes, ClientApi* client, Error* e, bool trunc )
: QCanvasRectangle(canvas), head(new QTreeJobText(canvas)), tail(head),
jobdepth(0), currdepth(0)
{
setY( y );
setPen( QPen::NoPen );
char** args;
StrBuf* changenum;
client->GetPassword(); // workaround for P4API bug?
if ( trunc )
{
// truncated version, use arrowed changes
for ( int a = 1 ; a <= changes->ArrSize() ; a++ )
{
args = new char*[2];
changenum = new StrBuf(); // XXX - can't free till WaitTag()
changenum->Set( changes->GetArrChange( a ) );
args[0] = "-c";
args[1] = changenum->Text();
client->SetArgv( 2, args );
client->RunTag( "fixes", new ClientJobUser( e, this, a ) );
}
}
else
{
// normal version, use all changes
for ( int a = 1 ; a <= changes->Size() ; a++ )
{
args = new char*[2];
changenum = new StrBuf(); // XXX - can't free till WaitTag()
changenum->Set( changes->GetChange( a ) );
args[0] = "-c";
args[1] = changenum->Text();
client->SetArgv( 2, args );
client->RunTag( "fixes", new ClientJobUser( e, this, a ) );
}
}
client->WaitTag();
setSize( width, ( jobdepth + 1 )*tail->boundingRect().height() );
if ( height() < TREE_JOBHEIGHT ) setSize( width, TREE_JOBHEIGHT );
// black line at bottom of bar
bline = new QCanvasLine( canvas );
QRect r = rect();
bline->setPoints( r.left(), r.bottom(), r.right(), r.bottom() );
bline->setZ( 10 );
bline->show();
}
QTreeJobBar::~QTreeJobBar()
{
}
void QTreeJobBar::UpdateBrush()
{
setBrush( QColor( TREE_COLJBAR ) );
}
// Add a job to the bar - use currdepth to keep track of the y-coordinate.
void QTreeJobBar::AddJob(StrBuf& jobname, int pos, StrBuf& truename)
{
tail = tail->AddNext(jobname, truename);
if (pos == currpos)
{
currdepth++;
if (currdepth > jobdepth) jobdepth = currdepth;
}
else
{
currpos = pos;
currdepth = 0;
}
tail->move((pos-1)*TREE_BALLSPACE + (TREE_BALLSPACE-tail->boundingRect().width())/2,
y()+currdepth*tail->boundingRect().height());
tail->show();
}