kdganttgraphicsitem.h

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 #ifndef KDGANTTGRAPHICSITEM_H
00026 #define KDGANTTGRAPHICSITEM_H
00027 
00028 #include "kdganttglobal.h"
00029 #include "kdganttstyleoptionganttitem.h"
00030 
00031 #include <QGraphicsItem>
00032 #include <QDateTime>
00033 #include <QPersistentModelIndex>
00034 
00035 class QGraphicsLineItem;
00036 
00037 namespace KDGantt {
00038     class GraphicsScene;
00039     class ConstraintGraphicsItem;
00040 
00041     /* Can we fit every kind of item into one gfxitem class? */
00042     class GraphicsItem : public QGraphicsItem {
00043     public:
00044         enum { Type = UserType + 42 };
00045 
00046         explicit GraphicsItem( QGraphicsItem* parent = 0, GraphicsScene* scene = 0 );
00047         explicit GraphicsItem( const QModelIndex& idx, QGraphicsItem* parent = 0, GraphicsScene* scene = 0 );
00048         virtual ~GraphicsItem();
00049 
00050         /*reimp*/int type() const;
00051         /*reimp (non-virtual)*/ GraphicsScene* scene() const;
00052 
00053         void updateItem( const Span& rowgeometry, const QPersistentModelIndex& idx );
00054 
00055         //virtual ItemType itemType() const = 0;
00056 
00057         //qreal dateTimeToSceneX( const QDateTime& dt ) const;
00058         //QDateTime sceneXtoDateTime( qreal x ) const;
00059 
00060         QRectF rect() const { return m_rect; }
00061         void setRect( const QRectF& r );
00062         void setBoundingRect( const QRectF& r );
00063 
00064         virtual QString ganttToolTip() const;
00065 
00066         const QPersistentModelIndex& index() const { return m_index; }
00067         void setIndex( const QPersistentModelIndex& idx );
00068 
00069         bool isEditable() const;
00070         bool isUpdating() const { return m_isupdating; }
00071 
00072         void addStartConstraint( ConstraintGraphicsItem* );
00073         void addEndConstraint( ConstraintGraphicsItem* );
00074         void removeStartConstraint( ConstraintGraphicsItem* );
00075         void removeEndConstraint( ConstraintGraphicsItem* );
00076         QList<ConstraintGraphicsItem*> startConstraints() const { return m_startConstraints; }
00077         QList<ConstraintGraphicsItem*> endConstraints() const { return m_endConstraints; }
00078 
00079         /*reimp*/ QRectF boundingRect() const;
00080         /*reimp*/ void paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
00081                               QWidget* widget = 0 );
00082 
00083         /*reimp*/ QVariant itemChange( GraphicsItemChange, const QVariant& value );
00084     protected:
00085         /*reimp*/ void focusInEvent( QFocusEvent* event );
00086         /*reimp*/ void hoverMoveEvent( QGraphicsSceneHoverEvent* );
00087         /*reimp*/ void hoverLeaveEvent( QGraphicsSceneHoverEvent* );
00088         /*reimp*/ void mousePressEvent( QGraphicsSceneMouseEvent* );
00089         /*reimp*/ void mouseReleaseEvent( QGraphicsSceneMouseEvent* );
00090         /*reimp*/ void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* );
00091         /*reimp*/ void mouseMoveEvent( QGraphicsSceneMouseEvent* );
00092 
00093     private:
00094         void init();
00095 
00096         QPointF startConnector( int relationType ) const;
00097         QPointF endConnector( int relationType ) const;
00098         void updateConstraintItems();
00099         StyleOptionGanttItem getStyleOption() const;
00100         void updateModel();
00101         void updateItemFromMouse( const QPointF& scenepos );
00102         void constraintsChanged();
00103 
00104         QRectF m_rect;
00105         QRectF m_boundingrect;
00106         QPersistentModelIndex m_index;
00107         bool m_isupdating;
00108         int m_istate;
00109         QPointF m_presspos;
00110         QPointF m_pressscenepos;
00111         QGraphicsLineItem* m_dragline;
00112         GraphicsItem* m_dragtarget;
00113         QList<ConstraintGraphicsItem*> m_startConstraints;
00114         QList<ConstraintGraphicsItem*> m_endConstraints;
00115     };
00116 }
00117 
00118 #endif /* KDGANTTGRAPHICSITEM_H */
00119 

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