00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2011 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 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 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #ifndef KDGANTTGRAPHICSITEM_H 00024 #define KDGANTTGRAPHICSITEM_H 00025 00026 #include "kdganttglobal.h" 00027 #include "kdganttstyleoptionganttitem.h" 00028 00029 #include <QGraphicsItem> 00030 #include <QDateTime> 00031 #include <QPersistentModelIndex> 00032 00033 class QGraphicsLineItem; 00034 00035 namespace KDGantt { 00036 class GraphicsScene; 00037 class ConstraintGraphicsItem; 00038 00039 /* Can we fit every kind of item into one gfxitem class? */ 00040 class GraphicsItem : public QGraphicsItem { 00041 public: 00042 enum { Type = UserType + 42 }; 00043 00044 explicit GraphicsItem( QGraphicsItem* parent = 0, GraphicsScene* scene = 0 ); 00045 explicit GraphicsItem( const QModelIndex& idx, QGraphicsItem* parent = 0, GraphicsScene* scene = 0 ); 00046 virtual ~GraphicsItem(); 00047 00048 /*reimp*/int type() const; 00049 /*reimp (non-virtual)*/ GraphicsScene* scene() const; 00050 00051 void updateItem( const Span& rowgeometry, const QPersistentModelIndex& idx ); 00052 00053 //virtual ItemType itemType() const = 0; 00054 00055 //qreal dateTimeToSceneX( const QDateTime& dt ) const; 00056 //QDateTime sceneXtoDateTime( qreal x ) const; 00057 00058 QRectF rect() const { return m_rect; } 00059 void setRect( const QRectF& r ); 00060 void setBoundingRect( const QRectF& r ); 00061 00062 virtual QString ganttToolTip() const; 00063 00064 const QPersistentModelIndex& index() const { return m_index; } 00065 void setIndex( const QPersistentModelIndex& idx ); 00066 00067 bool isEditable() const; 00068 bool isUpdating() const { return m_isupdating; } 00069 00070 void addStartConstraint( ConstraintGraphicsItem* ); 00071 void addEndConstraint( ConstraintGraphicsItem* ); 00072 void removeStartConstraint( ConstraintGraphicsItem* ); 00073 void removeEndConstraint( ConstraintGraphicsItem* ); 00074 QList<ConstraintGraphicsItem*> startConstraints() const { return m_startConstraints; } 00075 QList<ConstraintGraphicsItem*> endConstraints() const { return m_endConstraints; } 00076 00077 /*reimp*/ QRectF boundingRect() const; 00078 /*reimp*/ void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, 00079 QWidget* widget = 0 ); 00080 00081 /*reimp*/ QVariant itemChange( GraphicsItemChange, const QVariant& value ); 00082 protected: 00083 /*reimp*/ void focusInEvent( QFocusEvent* event ); 00084 /*reimp*/ void hoverMoveEvent( QGraphicsSceneHoverEvent* ); 00085 /*reimp*/ void hoverLeaveEvent( QGraphicsSceneHoverEvent* ); 00086 /*reimp*/ void mousePressEvent( QGraphicsSceneMouseEvent* ); 00087 /*reimp*/ void mouseReleaseEvent( QGraphicsSceneMouseEvent* ); 00088 /*reimp*/ void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ); 00089 /*reimp*/ void mouseMoveEvent( QGraphicsSceneMouseEvent* ); 00090 00091 private: 00092 void init(); 00093 00094 QPointF startConnector( int relationType ) const; 00095 QPointF endConnector( int relationType ) const; 00096 void updateConstraintItems(); 00097 StyleOptionGanttItem getStyleOption() const; 00098 void updateModel(); 00099 void updateItemFromMouse( const QPointF& scenepos ); 00100 void constraintsChanged(); 00101 00102 QRectF m_rect; 00103 QRectF m_boundingrect; 00104 QPersistentModelIndex m_index; 00105 bool m_isupdating; 00106 int m_istate; 00107 QPointF m_presspos; 00108 QPointF m_pressscenepos; 00109 QGraphicsLineItem* m_dragline; 00110 GraphicsItem* m_dragtarget; 00111 QList<ConstraintGraphicsItem*> m_startConstraints; 00112 QList<ConstraintGraphicsItem*> m_endConstraints; 00113 }; 00114 } 00115 00116 #endif /* KDGANTTGRAPHICSITEM_H */ 00117