23 #include "kdganttitemdelegate_p.h" 29 #include <QPainterPath> 31 #include <QModelIndex> 32 #include <QAbstractItemModel> 33 #include <QApplication> 35 #ifndef QT_NO_DEBUG_STREAM 37 #define PRINT_INTERACTIONSTATE(x) \ 38 case x: dbg << #x; break; 54 #undef PRINT_INTERACTIONSTATE 73 ItemDelegate::Private::Private()
76 QLinearGradient taskgrad( 0., 0., 0., QApplication::fontMetrics().height() );
77 taskgrad.setColorAt( 0., Qt::green );
78 taskgrad.setColorAt( 1., Qt::darkGreen );
80 QLinearGradient summarygrad( 0., 0., 0., QApplication::fontMetrics().height() );
81 summarygrad.setColorAt( 0., Qt::blue );
82 summarygrad.setColorAt( 1., Qt::darkBlue );
84 QLinearGradient eventgrad( 0., 0., 0., QApplication::fontMetrics().height() );
85 eventgrad.setColorAt( 0., Qt::red );
86 eventgrad.setColorAt( 1., Qt::darkRed );
93 QPen pen( Qt::black, 1. );
100 QPen ItemDelegate::Private::constraintPen(
const QPointF& start,
const QPointF& end,
const Constraint& constraint )
106 if ( start.x() < end.x() ) {
107 pen = QPen( Qt::black );
110 pen = QPen( Qt::red );
115 if ( dataPen.canConvert( QVariant::Pen ) ) {
116 pen = dataPen.value< QPen >();
144 d->defaultbrush[type] = brush;
153 return d->defaultbrush[type];
164 d->defaultpen[type]=pen;
173 return d->defaultpen[type];
180 if ( !idx.isValid() )
return QString();
182 const QAbstractItemModel* model = idx.model();
183 if ( !model )
return QString();
184 QString tip = model->data( idx, Qt::ToolTipRole ).toString();
185 if ( !tip.isNull() )
return tip;
186 else return tr(
"%1 -> %2: %3" )
189 .arg( model->data( idx, Qt::DisplayRole ).toString() );
201 const QModelIndex& idx )
const 203 if ( !idx.isValid() )
return Span();
205 const QString txt = idx.model()->data( idx, Qt::DisplayRole ).toString();
206 const int typ = idx.model()->data( idx,
ItemTypeRole ).toInt();
211 itemRect = QRectF( itemRect.left()-itemRect.height()/2.,
217 int tw = opt.fontMetrics.width( txt );
218 tw +=
static_cast<int>( itemRect.height()/2. );
222 s =
Span( itemRect.left()-tw, itemRect.width()+tw );
break;
224 s =
Span( itemRect.left(), itemRect.width()+tw );
break;
227 s =
Span( itemRect.left(), itemRect.width() );
break;
240 const QModelIndex& idx )
const 243 if ( !( idx.model()->flags( idx ) & Qt::ItemIsEditable ) )
return State_None;
252 itemRect = QRectF( itemRect.topLeft() - QPointF( itemRect.height() / 2.0, 0 ), QSizeF( itemRect.height(),
253 itemRect.height() ) );
256 if ( !itemRect.contains(pos) )
return State_None;
261 if ( itemRect.width() < 15 ) delta = 1.;
262 if ( pos.x() >= itemRect.left() && pos.x() < itemRect.left()+delta ) {
264 }
else if ( pos.x() <= itemRect.right() && pos.x() > itemRect.right()-delta ) {
275 const QModelIndex& idx )
277 if ( !idx.isValid() )
return;
279 const QString& txt = opt.
text;
282 boundingRect.setY( itemRect.y() );
283 boundingRect.setHeight( itemRect.height() );
291 if ( opt.state & QStyle::State_Selected ) pen.setWidth( 2*pen.width() );
292 painter->setPen( pen );
295 bool drawText =
true;
296 qreal pw = painter->pen().width()/2.;
299 if ( itemRect.isValid() ) {
301 qreal pw = painter->pen().width()/2.;
304 r.translate( 0., r.height()/6. );
305 r.setHeight( 2.*r.height()/3. );
306 painter->setBrushOrigin( itemRect.topLeft() );
308 painter->translate( 0.5, 0.5 );
309 painter->drawRect( r );
313 qreal h = r.height();
314 QRectF cr( r.x(), r.y()+h/4.,
315 r.width()*completion/100., h/2.+1 );
316 QColor compcolor( painter->pen().color() );
317 compcolor.setAlpha( 150 );
318 painter->fillRect( cr, compcolor );
327 const QRectF r = QRectF( opt.
itemRect ).adjusted( -pw, -pw, pw, pw );
329 const qreal deltaY = r.height()/2.;
330 const qreal deltaXBezierControl = .25*qMin( r.width(), r.height() );
331 const qreal deltaX = qMin( r.width()/(qreal)2., r.height() );
332 path.moveTo( r.topLeft() );
333 path.lineTo( r.topRight() );
334 path.lineTo( QPointF( r.right(), r.top() + 2.*deltaY ) );
336 path.quadTo( QPointF( r.right()-deltaXBezierControl, r.top() + deltaY ), QPointF( r.right()-deltaX, r.top() + deltaY ) );
338 path.lineTo( QPointF( r.left() + deltaX, r.top() + deltaY ) );
339 path.quadTo( QPointF( r.left()+deltaXBezierControl, r.top() + deltaY ), QPointF( r.left(), r.top() + 2.*deltaY ) );
341 painter->setBrushOrigin( itemRect.topLeft() );
343 painter->translate( 0.5, 0.5 );
344 painter->drawPath( path );
351 const qreal pw = painter->pen().width() / 2. - 1;
352 const QRectF r = QRectF( opt.
itemRect ).adjusted( -pw, -pw, pw, pw ).translated( -opt.
itemRect.height()/2, 0 );
354 const qreal delta =
static_cast< int >( r.height() / 2 );
355 path.moveTo( delta, 0. );
356 path.lineTo( 2.*delta, delta );
357 path.lineTo( delta, 2.*delta );
358 path.lineTo( 0., delta );
361 painter->translate( r.topLeft() );
362 painter->translate( 0, 0.5 );
363 painter->drawPath( path );
366 painter->setBrush( Qt::NoBrush );
367 painter->setPen( Qt::black );
369 painter->setPen( Qt::red );
370 painter->drawRect( r );
387 painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
394 static const qreal
PW = 1.5;
417 return poly.boundingRect().adjusted( -
PW, -
PW,
PW,
PW );
427 const QPointF& start,
const QPointF& end,
const Constraint &constraint )
450 const QPen pen =
d->constraintPen( start, end, constraint );
452 painter->setPen( pen );
453 painter->setBrush( pen.color() );
462 qreal midx = end.x() -
TURN;
463 qreal midy = ( end.y()-start.y() )/2. + start.y();
465 if ( start.x() > end.x()-
TURN ) {
467 << QPointF( start.x()+
TURN, start.y() )
468 << QPointF( start.x()+
TURN, midy )
469 << QPointF( end.x()-
TURN, midy )
470 << QPointF( end.x()-
TURN, end.y() )
474 << QPointF( midx, start.y() )
475 << QPointF( midx, end.y() )
487 << QPointF( end.x()-
TURN/2., end.y()-
TURN/2. )
488 << QPointF( end.x()-
TURN/2., end.y()+
TURN/2. );
496 const QPen pen =
d->constraintPen( start, end, constraint );
498 painter->setPen( pen );
499 painter->setBrush( pen.color() );
508 qreal midx = end.x() +
TURN;
509 qreal midy = ( end.y()-start.y() )/2. + start.y();
511 if ( start.x() > end.x()+
TURN ) {
513 << QPointF( start.x()+
TURN, start.y() )
514 << QPointF( start.x()+
TURN, end.y() )
518 << QPointF( midx, start.y() )
519 << QPointF( midx, midy )
520 << QPointF( end.x()+
TURN, midy )
521 << QPointF( end.x()+
TURN, end.y() )
533 << QPointF( end.x()+
TURN/2., end.y()-
TURN/2. )
534 << QPointF( end.x()+
TURN/2., end.y()+
TURN/2. );
542 const QPen pen =
d->constraintPen( start, end, constraint );
544 painter->setPen( pen );
545 painter->setBrush( pen.color() );
558 if ( start.x() > end.x() ) {
560 << QPointF( end.x()-
TURN, start.y() )
561 << QPointF( end.x()-
TURN, end.y() )
565 << QPointF( start.x()-
TURN, start.y() )
566 << QPointF( start.x()-
TURN, end.y() )
567 << QPointF( end.x()-
TURN, end.y() )
579 << QPointF( end.x()-
TURN/2., end.y()-
TURN/2. )
580 << QPointF( end.x()-
TURN/2., end.y()+
TURN/2. );
588 const QPen pen =
d->constraintPen( start, end, constraint );
590 painter->setPen( pen );
591 painter->setBrush( pen.color() );
602 qreal midx = end.x() +
TURN;
603 qreal midy = ( end.y()-start.y() )/2. + start.y();
605 if ( start.x()-
TURN > end.x()+
TURN ) {
607 << QPointF( midx, start.y() )
608 << QPointF( midx, end.y() )
612 << QPointF( start.x()-
TURN, start.y() )
613 << QPointF( start.x()-
TURN, midy )
614 << QPointF( midx, midy )
615 << QPointF( end.x()+
TURN, end.y() )
627 << QPointF( end.x()+
TURN/2., end.y()-
TURN/2. )
628 << QPointF( end.x()+
TURN/2., end.y()+
TURN/2. );
633 #include "moc_kdganttitemdelegate.cpp"
void paintFinishStartConstraint(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
QDebug operator<<(QDebug dbg, KDGantt::ItemDelegate::InteractionState state)
virtual InteractionState interactionStateFor(const QPointF &pos, const StyleOptionGanttItem &opt, const QModelIndex &idx) const
QPolygonF finishFinishLine(const QPointF &start, const QPointF &end) const
QPolygonF startFinishLine(const QPointF &start, const QPointF &end) const
virtual QString toolTip(const QModelIndex &idx) const
QVariant data(int role) const
A class used to represent a dependency.
ItemDelegate(QObject *parent=0)
QPolygonF finishStartArrow(const QPointF &start, const QPointF &end) const
QBrush defaultBrush(ItemType type) const
void paintFinishFinishConstraint(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
A class representing a start point and a length.
virtual QRectF constraintBoundingRect(const QPointF &start, const QPointF &end, const Constraint &constraint) const
QPen defaultPen(ItemType type) const
void setDefaultBrush(ItemType type, const QBrush &brush)
virtual void paintGanttItem(QPainter *p, const StyleOptionGanttItem &opt, const QModelIndex &idx)
void paintStartStartConstraint(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
void setDefaultPen(ItemType type, const QPen &pen)
RelationType relationType() const
QStyleOption subclass for gantt items.
virtual void paintConstraintItem(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
#define PRINT_INTERACTIONSTATE(x)
QPolygonF finishFinishArrow(const QPointF &start, const QPointF &end) const
QPolygonF startStartArrow(const QPointF &start, const QPointF &end) const
void paintStartFinishConstraint(QPainter *p, const QStyleOptionGraphicsItem &opt, const QPointF &start, const QPointF &end, const Constraint &constraint)
Class only listed here to document inheritance of some KDChart classes.
QPolygonF startFinishArrow(const QPointF &start, const QPointF &end) const
virtual Span itemBoundingSpan(const StyleOptionGanttItem &opt, const QModelIndex &idx) const
QPolygonF startStartLine(const QPointF &start, const QPointF &end) const
QPolygonF finishStartLine(const QPointF &start, const QPointF &end) const