kdgantt
kdganttconstraintgraphicsitem.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "kdganttconstraintgraphicsitem.h"
00024 #include "kdganttconstraintmodel.h"
00025 #include "kdganttgraphicsscene.h"
00026 #include "kdganttitemdelegate.h"
00027 #include "kdganttsummaryhandlingproxymodel.h"
00028
00029 #include <QPainter>
00030 #include <QDebug>
00031
00032 using namespace KDGantt;
00033
00038 ConstraintGraphicsItem::ConstraintGraphicsItem( const Constraint& c, QGraphicsItem* parent, GraphicsScene* scene )
00039 : QGraphicsItem( parent, scene ), m_constraint( c )
00040 {
00041 qDebug() << "ConstraintGraphicsItem::ConstraintGraphicsItem()";
00042 setPos( QPointF( 0., 0. ) );
00043 setAcceptsHoverEvents( false );
00044 setAcceptedMouseButtons( Qt::NoButton );
00045 setZValue( 10. );
00046 }
00047
00048 ConstraintGraphicsItem::~ConstraintGraphicsItem()
00049 {
00050 }
00051
00052 int ConstraintGraphicsItem::type() const
00053 {
00054 return Type;
00055 }
00056
00057 GraphicsScene* ConstraintGraphicsItem::scene() const
00058 {
00059 return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() );
00060 }
00061
00062 Constraint ConstraintGraphicsItem::proxyConstraint() const
00063 {
00064 return Constraint( scene()->summaryHandlingModel()->mapFromSource( m_constraint.startIndex() ),
00065 scene()->summaryHandlingModel()->mapFromSource( m_constraint.endIndex() ),
00066 m_constraint.type() );
00067 }
00068
00069 QRectF ConstraintGraphicsItem::boundingRect() const
00070 {
00071 return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint );
00072 }
00073
00074 void ConstraintGraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
00075 QWidget* widget )
00076 {
00077 Q_UNUSED( widget );
00078
00079 scene()->itemDelegate()->paintConstraintItem( painter, *option, m_start, m_end, m_constraint );
00080 }
00081
00082 QString ConstraintGraphicsItem::ganttToolTip() const
00083 {
00084 return m_constraint.data( Qt::ToolTipRole ).toString();
00085 }
00086
00087 void ConstraintGraphicsItem::setStart( const QPointF& start )
00088 {
00089 prepareGeometryChange();
00090 m_start = start;
00091 update();
00092 }
00093
00094 void ConstraintGraphicsItem::setEnd( const QPointF& end )
00095 {
00096 prepareGeometryChange();
00097 m_end = end;
00098 update();
00099 }
00100
00101 void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end )
00102 {
00103 qDebug() << "ConstraintGraphicsItem::updateItem("<<start<<end<<")";
00104 setStart( start );
00105 setEnd( end );
00106 }
00107