// Implementation of QTreeChangeView.
#include <clientapi.h>
#include <qbitmap.h>
#include <qcanvas.h>
#include <qcursor.h>
#include <qlabel.h>
#include <qdragobject.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qtooltip.h>
#include "qtreeitem.h"
#include "changesorter.h"
#include "filehead.h"
#include "filelogcache.h"
#include "clientchangeuser.h"
#include "qtreechangenum.h"
#include "qtreechangebar.h"
#include "clientjobdescuser.h"
#include "qtreejobtext.h"
#include "qtreejobbar.h"
#include "qtreerevtext.h"
#include "qtreerevball.h"
#include "qtreefiletext.h"
#include "qtreefilestripe.h"
#include "qtreearrow.h"
#include "qtreecanvas.h"
#include "qtreetooltip.h"
#define QTREEWINDOW_H
#include "qtreewindow.h"
#include "img/qembed.h"
#include "qtreechangeview.h"
QTreeChangeView::QTreeChangeView( QTreeCanvas* canvas, QTreeWindow* parent )
:QCanvasView ( canvas, parent, "changeview", WStyle_NoBorder ),
qtw( parent ), qtcanvas( canvas ), tips( QTreeToolTip( this ) )
{
maxheight = canvas->ChangeSize().height() + 4;
realheight = maxheight; // start with jobs visible
setMargins( TREE_ICONWIDTH, 0, 0, 0 );
InitIcons();
AdjustGeometry();
// We don't need no stinking scrollbars!
setVScrollBarMode( AlwaysOff );
setHScrollBarMode( AlwaysOff );
}
QTreeChangeView::~QTreeChangeView()
{
}
void QTreeChangeView::InitIcons()
{
QPixmap cicon = QPixmap( qembed_findData( "subchng.bmp" ) );
cicon.setMask( cicon.createHeuristicMask() );
changelabel = new QLabel( this );
changelabel->setGeometry( 1, 1,
TREE_ICONWIDTH, TREE_BARHEIGHT + 1 );
changelabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
changelabel->setPixmap( cicon );
changelabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
changelabel->setBackgroundColor( TREE_COLCBAR );
QPixmap jicon = QPixmap( qembed_findData( "jobs.bmp" ) );
jicon.setMask( jicon.createHeuristicMask() );
joblabel = new QLabel( this );
joblabel->setGeometry( 1, 1 + TREE_BARHEIGHT,
TREE_ICONWIDTH, maxheight - TREE_BARHEIGHT - 3 );
joblabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
joblabel->setPixmap( jicon );
joblabel->setFrameStyle( QFrame::Panel | QFrame::Plain );
joblabel->setBackgroundColor( TREE_COLCBAR );
}
void QTreeChangeView::AdjustGeometry()
{
setGeometry
(
0,
qtw->menubar->height(),
qtw->visibleWidth() + TREE_ICONWIDTH + 3,
realheight
);
}
void QTreeChangeView::contentsWheelEvent( QWheelEvent* e )
{
// Yes, to ignore the event, you call accept(). Not ignore().
e->accept();
}
void QTreeChangeView::contentsMouseDoubleClickEvent(QMouseEvent* e)
{
// Only left clicks. Right clicks might one day do somethin' else.
if ( e->button() == LeftButton )
e->accept();
else
{
e->ignore();
return;
}
// Do collision detection on the clicked point, and figure out which
// CanvasItem, if any, is one that we're interested in.
QCanvasItemList items = canvas()->collisions( e->pos() );
QCanvasItem* item = NULL;
while ( !items.empty() )
{
item = items.front();
if ( item->rtti() == RTTI_CHANGE || item->rtti() == RTTI_JOB ) break;
items.pop_front();
}
if ( item == NULL ) return;
QCursor myc = cursor();
setCursor( QCursor( WaitCursor ) );
// Cast the pointer and spawn the appropriate dialog.
switch ( item->rtti() )
{
case RTTI_CHANGE:
( (QTreeChangeNum*)item )->InfoDialog( qtw, qtw->client, qtw->error );
break;
case RTTI_JOB:
( (QTreeJobText*)item )->InfoDialog( qtw, qtw->client, qtw->error );
break;
}
setCursor( myc );
}
// Drag 'n drop support.
void QTreeChangeView::contentsMousePressEvent( QMouseEvent* e )
{
// The first half of this method looks a lot like
// contentsMouseDoubleClickEvent(), doens't it?
// Only drag with left button.
if ( e->button() == LeftButton )
e->accept();
else
{
e->ignore();
return;
}
// Do collision detection.
QCanvasItemList items = canvas()->collisions( e->pos() );
QCanvasItem* item = NULL;
while ( !items.empty() )
{
item = items.front();
if ( item->rtti() == RTTI_CHANGE ||
item->rtti() == RTTI_JOB ) break;
items.pop_front();
}
if ( item == NULL ||
( item->rtti() != RTTI_CHANGE && item->rtti() != RTTI_JOB ) )
{
// no object hit - do a gridline instead!
qtcanvas->GridLine( e->pos().x() );
qtcanvas->update();
return;
}
// start a dragging action
QTextDrag* d;
switch ( item->rtti() )
{
case RTTI_CHANGE:
d = new QTextDrag(
( (QTreeChangeNum*)item )->text(), this );
d->drag();
break;
case RTTI_JOB:
d = new QTextDrag(
( (QTreeJobText*)item )->jobname, this );
d->drag();
break;
}
}