30 #include <QPainterPath> 
   32 #include <QModelIndex> 
   33 #include <QAbstractItemModel> 
   34 #include <QApplication> 
   36 #ifndef QT_NO_DEBUG_STREAM 
   38 #define PRINT_INTERACTIONSTATE(x) \ 
   39     case x: dbg << #x; break; 
   55 #undef PRINT_INTERACTIONSTATE 
   59 using namespace KDGantt;
 
   77     QLinearGradient taskgrad( 0., 0., 0., QApplication::fontMetrics().height() );
 
   78     taskgrad.setColorAt( 0., Qt::green );
 
   79     taskgrad.setColorAt( 1., Qt::darkGreen );
 
   81     QLinearGradient summarygrad( 0., 0., 0., QApplication::fontMetrics().height() );
 
   82     summarygrad.setColorAt( 0., Qt::blue );
 
   83     summarygrad.setColorAt( 1., Qt::darkBlue );
 
   85     QLinearGradient eventgrad( 0., 0., 0., QApplication::fontMetrics().height() );
 
   86     eventgrad.setColorAt( 0., Qt::red );
 
   87     eventgrad.setColorAt( 1., Qt::darkRed );
 
   94     QPen pen( Qt::black, 1. );
 
  123     d->defaultbrush[type] = brush;
 
  132     return d->defaultbrush[type];
 
  143     d->defaultpen[type]=pen;
 
  152     return d->defaultpen[type];
 
  164                                  const QModelIndex& idx )
 const 
  166     if ( !idx.isValid() ) 
return Span();
 
  168     const QString txt = idx.model()->data( idx, Qt::DisplayRole ).toString();
 
  169     const int typ = idx.model()->data( idx, 
ItemTypeRole ).toInt();
 
  174         itemRect = QRectF( itemRect.left()-itemRect.height()/2.,
 
  180     int tw = opt.fontMetrics.width( txt );
 
  181     tw += 
static_cast<int>( itemRect.height()/2. );
 
  185         s = 
Span( itemRect.left()-tw, itemRect.width()+tw ); 
break;
 
  187         s = 
Span( itemRect.left(), itemRect.width()+tw ); 
break;
 
  189         s = 
Span( itemRect.left(), itemRect.width() ); 
break;
 
  202                                   const QModelIndex& idx )
 const 
  205     if ( !( idx.model()->flags( idx ) & Qt::ItemIsEditable ) ) 
return State_None;
 
  213     if ( opt.
itemRect.width() < 15 ) delta = 1.;
 
  214     if( pos.x() >= opt.
itemRect.left() && pos.x() < opt.
itemRect.left()+delta ) {
 
  216     } 
else   if( pos.x() <= opt.
itemRect.right() && pos.x() > opt.
itemRect.right()-delta ) {
 
  227                                    const QModelIndex& idx )
 
  229     if ( !idx.isValid() ) 
return;
 
  231     const QString& txt = opt.
text;
 
  234     boundingRect.setY( itemRect.y() );
 
  235     boundingRect.setHeight( itemRect.height() );
 
  243     if ( opt.state & QStyle::State_Selected ) pen.setWidth( 2*pen.width() );
 
  244     painter->setPen( pen );
 
  247     qreal pw = painter->pen().width()/2.;
 
  250         if ( itemRect.isValid() ) {
 
  252             qreal pw = painter->pen().width()/2.;
 
  255             r.translate( 0., r.height()/6. );
 
  256             r.setHeight( 2.*r.height()/3. );
 
  257             painter->setBrushOrigin( itemRect.topLeft() );
 
  259             painter->translate( 0.5, 0.5 );
 
  260             painter->drawRect( r );
 
  264                 qreal h = r.height();
 
  265                 QRectF cr( r.x(), r.y()+h/4.,
 
  266                            r.width()*completion/100., h/2.+1  );
 
  267                 QColor compcolor( painter->pen().color() );
 
  268                 compcolor.setAlpha( 150 );
 
  269                 painter->fillRect( cr, compcolor );
 
  278             painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
 
  285             const QRectF r = QRectF( opt.
itemRect ).adjusted( -pw, -pw, pw, pw );
 
  287             const qreal delta = r.height()/2.;
 
  288             path.moveTo( r.topLeft() );
 
  289             path.lineTo( r.topRight() );
 
  290             path.lineTo( QPointF( r.right(), r.top() + 2.*delta ) );
 
  292             path.quadTo( QPointF( r.right()-.5*delta, r.top() + delta ), QPointF( r.right()-2.*delta, r.top() + delta ) );
 
  294             path.lineTo( QPointF( r.left() + 2.*delta, r.top() + delta ) );
 
  295             path.quadTo( QPointF( r.left()+.5*delta, r.top() + delta ), QPointF( r.left(), r.top() + 2.*delta ) );
 
  297             painter->setBrushOrigin( itemRect.topLeft() );
 
  299             painter->translate( 0.5, 0.5 );
 
  300             painter->drawPath( path );
 
  308             painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
 
  314             const qreal pw = painter->pen().width() / 2. - 1;
 
  315             const QRectF r = QRectF( opt.
itemRect ).adjusted( -pw, -pw, pw, pw ).translated( -opt.
itemRect.height()/2, 0 );
 
  317             const qreal delta = 
static_cast< int >( r.height() / 2 );
 
  318             path.moveTo( delta, 0. );
 
  319             path.lineTo( 2.*delta, delta );
 
  320             path.lineTo( delta, 2.*delta );
 
  321             path.lineTo( 0., delta );
 
  324             painter->translate( r.topLeft() );
 
  325             painter->translate( 0, 0.5 );
 
  326             painter->drawPath( path );
 
  334             painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
 
  336             painter->setBrush( Qt::NoBrush );
 
  337             painter->setPen( Qt::black );
 
  339             painter->setPen( Qt::red );
 
  340             painter->drawRect( r );
 
  351 static const qreal 
PW = 1.5;
 
  360     if ( start.x() > end.x()-
TURN ) {
 
  361         if ( start.y() < end.y() ) {
 
  362             poly << QPointF( start.x()+
TURN, start.y()-
TURN/2. )
 
  363                  << QPointF( end.x()-
TURN, end.y()+
TURN/2. );
 
  365             poly << QPointF( start.x()+
TURN, start.y()+
TURN/2. )
 
  366                  << QPointF( end.x()-
TURN, end.y()-
TURN/2. );
 
  369         if ( start.y() < end.y() ) {
 
  370             poly << QPointF( start.x(), start.y()-
TURN/2. )
 
  371                  << QPointF( end.x(), end.y()+
TURN/2. );
 
  373             poly << QPointF( start.x(), start.y()+
TURN/2. )
 
  374                  << QPointF( end.x(), end.y()-
TURN/2. );
 
  377     return poly.boundingRect().adjusted( -
PW, -
PW, 
PW, 
PW );
 
  387                                         const QPointF& start, 
const QPointF& end, 
const QPen& pen )
 
  390     qreal midx = end.x() - 
TURN;
 
  391     qreal midy = ( end.y()-start.y() )/2. + start.y();
 
  393     painter->setPen( pen );
 
  394     painter->setBrush( pen.color() );
 
  396     if ( start.x() > end.x()-
TURN ) {
 
  399                  << QPointF( start.x()+
TURN, start.y() )
 
  400                  << QPointF( start.x()+
TURN, midy )
 
  401                  << QPointF( end.x()-
TURN, midy )
 
  402                  << QPointF( end.x()-
TURN, end.y() )
 
  404         painter->drawPolyline( poly );
 
  407               << QPointF( end.x()-
TURN/2., end.y()-
TURN/2. )
 
  408               << QPointF( end.x()-
TURN/2., end.y()+
TURN/2. );
 
  409         painter->drawPolygon( arrow );
 
  413              << QPointF( midx, start.y() )
 
  414              << QPointF( midx, end.y() )
 
  416         painter->drawPolyline( poly );
 
  419               << QPointF( end.x()-
TURN/2., end.y()-
TURN/2. )
 
  420               << QPointF( end.x()-
TURN/2., end.y()+
TURN/2. );
 
  421         painter->drawPolygon( arrow );
 
  425 #include "moc_kdganttitemdelegate.cpp" 
QHash< ItemType, QPen > defaultpen
 
QDebug operator<<(QDebug dbg, KDGantt::ItemDelegate::InteractionState state)
 
void setDefaultPen(ItemType type, const QPen &pen)
 
virtual InteractionState interactionStateFor(const QPointF &pos, const StyleOptionGanttItem &opt, const QModelIndex &idx) const 
 
virtual Span itemBoundingSpan(const StyleOptionGanttItem &opt, const QModelIndex &idx) const 
 
QHash< ItemType, QBrush > defaultbrush
 
A class representing a start point and a length. 
 
QBrush defaultBrush(ItemType type) const 
 
QPen defaultPen(ItemType type) const 
 
virtual QRectF constraintBoundingRect(const QPointF &start, const QPointF &end) const 
 
#define PRINT_INTERACTIONSTATE(x)
 
void setDefaultBrush(ItemType type, const QBrush &brush)
 
QStyleOption subclass for gantt items. 
 
virtual void paintGanttItem(QPainter *p, const StyleOptionGanttItem &opt, const QModelIndex &idx)
 
ItemDelegate(QObject *parent=0)
 
virtual void paintConstraintItem(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const QPen &pen)