KGantt

kganttgraphicsitem.h
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KGantt library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KGANTTGRAPHICSITEM_H
10#define KGANTTGRAPHICSITEM_H
11
12#include "kganttglobal.h"
13#include "kganttstyleoptionganttitem.h"
14
15#include <QGraphicsItem>
16#include <QDateTime>
17#include <QPersistentModelIndex>
18
19QT_BEGIN_NAMESPACE
21QT_END_NAMESPACE
22
23namespace KGantt {
24 class GraphicsScene;
25 class ConstraintGraphicsItem;
26
27 /* Can we fit every kind of item into one gfxitem class? */
28
29 /*!\class KGantt::GraphicsItem
30 * \internal
31 */
32 class KGANTT_EXPORT GraphicsItem : public QGraphicsItem {
33 public:
34 enum { Type = UserType + 42 };
35
36 explicit GraphicsItem( QGraphicsItem* parent = nullptr, GraphicsScene* scene = nullptr );
37 explicit GraphicsItem( const QModelIndex& idx, QGraphicsItem* parent = nullptr, GraphicsScene* scene = nullptr );
38 ~GraphicsItem() override;
39
40 /*reimp*/int type() const override;
41 /*reimp (non-virtual)*/ GraphicsScene* scene() const;
42
43 void updateItem( const Span& rowgeometry, const QPersistentModelIndex& idx );
44
45 //virtual ItemType itemType() const = 0;
46
47 //qreal dateTimeToSceneX( const QDateTime& dt ) const;
48 //QDateTime sceneXtoDateTime( qreal x ) const;
49
50 QRectF rect() const { return m_rect; }
51 void setRect( const QRectF& r );
52 void setBoundingRect( const QRectF& r );
53
54 virtual QString ganttToolTip() const;
55
56 const QPersistentModelIndex& index() const { return m_index; }
57 void setIndex( const QPersistentModelIndex& idx );
58
59 bool isEditable() const;
60 bool isUpdating() const { return m_isupdating; }
61
62 void addStartConstraint( ConstraintGraphicsItem* );
63 void addEndConstraint( ConstraintGraphicsItem* );
64 void removeStartConstraint( ConstraintGraphicsItem* );
65 void removeEndConstraint( ConstraintGraphicsItem* );
66 QList<ConstraintGraphicsItem*> startConstraints() const { return m_startConstraints; }
67 QList<ConstraintGraphicsItem*> endConstraints() const { return m_endConstraints; }
68
69 /*reimp*/ QRectF boundingRect() const override;
70 /*reimp*/ void paint( QPainter* painter, const QStyleOptionGraphicsItem* option,
71 QWidget* widget = nullptr ) override;
72
73 /*reimp*/ QVariant itemChange( GraphicsItemChange, const QVariant& value ) override;
74 protected:
75 /*reimp*/ void focusInEvent( QFocusEvent* event ) override;
76 /*reimp*/ void hoverMoveEvent( QGraphicsSceneHoverEvent* ) override;
77 /*reimp*/ void hoverLeaveEvent( QGraphicsSceneHoverEvent* ) override;
78 /*reimp*/ void mousePressEvent( QGraphicsSceneMouseEvent* ) override;
79 /*reimp*/ void mouseReleaseEvent( QGraphicsSceneMouseEvent* ) override;
80 /*reimp*/ void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ) override;
81 /*reimp*/ void mouseMoveEvent( QGraphicsSceneMouseEvent* ) override;
82
83 private:
84 void init();
85
86 QPointF startConnector( int relationType ) const;
87 QPointF endConnector( int relationType ) const;
88 void updateConstraintItems();
89 StyleOptionGanttItem getStyleOption() const;
90 void updateModel();
91 void updateItemFromMouse( const QPointF& scenepos );
92 void constraintsChanged();
93
94 QRectF m_rect;
95 QRectF m_boundingrect;
97 bool m_isupdating;
98 int m_istate;
99 QPointF m_presspos;
100 QPointF m_pressscenepos;
101 QGraphicsLineItem* m_dragline;
102 GraphicsItem* m_dragtarget;
103 QList<ConstraintGraphicsItem*> m_startConstraints;
104 QList<ConstraintGraphicsItem*> m_endConstraints;
105 };
106}
107
108#endif /* KGANTTGRAPHICSITEM_H */
109
A class representing a start point and a length.
QStyleOption subclass for gantt items.
Contains KGantt macros.
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.