kdganttconstraintgraphicsitem.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Gantt library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Gantt licenses may use this file in
00012  ** accordance with the KD Gantt Commercial License Agreement provided with
00013  ** the Software.
00014  **
00015  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017  **
00018  ** See http://www.kdab.net/kdgantt for
00019  **   information about KD Gantt Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
00023  **
00024  **********************************************************************/
00025 #include "kdganttconstraintgraphicsitem.h"
00026 #include "kdganttconstraintmodel.h"
00027 #include "kdganttgraphicsscene.h"
00028 #include "kdganttitemdelegate.h"
00029 #include "kdganttsummaryhandlingproxymodel.h"
00030 
00031 #include <QPainter>
00032 #include <QDebug>
00033 
00034 using namespace KDGantt;
00035 
00040 ConstraintGraphicsItem::ConstraintGraphicsItem( const Constraint& c, QGraphicsItem* parent, GraphicsScene* scene )
00041     : QGraphicsItem( parent, scene ),  m_constraint( c )
00042 {
00043     setPos( QPointF( 0., 0. ) );
00044     setAcceptsHoverEvents( false );
00045     setAcceptedMouseButtons( Qt::NoButton );
00046     setZValue( 10. );
00047 }
00048 
00049 ConstraintGraphicsItem::~ConstraintGraphicsItem()
00050 {
00051 }
00052 
00053 int ConstraintGraphicsItem::type() const
00054 {
00055     return Type;
00056 }
00057 
00058 GraphicsScene* ConstraintGraphicsItem::scene() const
00059 {
00060     return qobject_cast<GraphicsScene*>( QGraphicsItem::scene() );
00061 }
00062 
00063 Constraint ConstraintGraphicsItem::proxyConstraint() const
00064 {
00065     return Constraint( scene()->summaryHandlingModel()->mapFromSource( m_constraint.startIndex() ),
00066                        scene()->summaryHandlingModel()->mapFromSource( m_constraint.endIndex() ),
00067                        m_constraint.type() );
00068 }
00069 
00070 QRectF ConstraintGraphicsItem::boundingRect() const
00071 {
00072     return scene()->itemDelegate()->constraintBoundingRect( m_start, m_end, m_constraint );
00073 }
00074 
00075 void ConstraintGraphicsItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
00076                                     QWidget* widget )
00077 {
00078     Q_UNUSED( widget );
00079 
00080     scene()->itemDelegate()->paintConstraintItem( painter, *option, m_start, m_end, m_constraint );
00081 }
00082 
00083 QString ConstraintGraphicsItem::ganttToolTip() const
00084 {
00085     return m_constraint.data( Qt::ToolTipRole ).toString();
00086 }
00087 
00088 void ConstraintGraphicsItem::setStart( const QPointF& start )
00089 {
00090     prepareGeometryChange();
00091     m_start = start;
00092     update();
00093 }
00094 
00095 void ConstraintGraphicsItem::setEnd( const QPointF& end )
00096 {
00097     prepareGeometryChange();
00098     m_end = end;
00099     update();
00100 }
00101 
00102 void ConstraintGraphicsItem::updateItem( const QPointF& start,const QPointF& end )
00103 {
00104     setStart( start );
00105     setEnd( end );
00106 }

Generated on Thu Mar 4 23:19:13 2010 for KD Chart 2 by  doxygen 1.5.4