kdgantt
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 used under the terms of the GNU General Public 00007 ** License versions 2.0 or 3.0 as published by the Free Software 00008 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 00009 ** included in the packaging of this file. Alternatively you may (at 00010 ** your option) use any later version of the GNU General Public 00011 ** License if such license has been publicly approved by 00012 ** Klarälvdalens Datakonsult AB (or its successors, if any). 00013 ** 00014 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, 00015 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR 00016 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights 00017 ** not expressly granted herein. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 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 00101 QRectF m_rect; 00102 QRectF m_boundingrect; 00103 QPersistentModelIndex m_index; 00104 bool m_isupdating; 00105 int m_istate; 00106 QPointF m_presspos; 00107 QPointF m_pressscenepos; 00108 QGraphicsLineItem* m_dragline; 00109 GraphicsItem* m_dragtarget; 00110 QList<ConstraintGraphicsItem*> m_startConstraints; 00111 QList<ConstraintGraphicsItem*> m_endConstraints; 00112 }; 00113 } 00114 00115 #endif /* KDGANTTGRAPHICSITEM_H */ 00116
KDE 4.2 API Reference