KGantt

kganttitemdelegate.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 KGANTTITEMDELEGATE_H
10#define KGANTTITEMDELEGATE_H
11
12#include <QItemDelegate>
13#include <QBrush>
14#include <QPen>
15#include <QDebug>
16
17#include "kganttglobal.h"
18
19namespace KGantt {
20 class StyleOptionGanttItem;
21 class Constraint;
22
23 /*!\class KGantt::ItemDelegate kganttitemdelegate.h KGanttItemDelegate
24 *\ingroup KGantt
25 *\brief Class used to render gantt items in a KGantt::GraphicsView
26 *
27 */
28 class KGANTT_EXPORT ItemDelegate : public QItemDelegate {
29 Q_OBJECT
30 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( ItemDelegate )
31 public:
32 /*!\enum KGantt::ItemDelegate::InteractionState
33 * This enum is used for communication between the view and
34 * the delegate about user interaction with gantt items.
35 *
36 * \see KGantt::ItemDelegate::interactionStateFor
37 */
38 enum InteractionState { State_None = 0,
39 State_Move,
40 State_ExtendLeft,
41 State_ExtendRight,
42 State_DragConstraint
43 };
44
45 /*! Constructor. Creates an ItemDelegate with parent \a parent */
46 explicit ItemDelegate( QObject* parent = nullptr );
47
48 /*! Destructor */
49 ~ItemDelegate() override;
50
51 /*! Sets the default brush used for items of type \a type to
52 * \a brush. The default brush is used in the case when the model
53 * does not provide an explicit brush.
54 *
55 * \todo Move this to GraphicsView to make delegate stateless.
56 */
57 void setDefaultBrush( ItemType type, const QBrush& brush );
58
59 /*!\returns The default brush for item type \a type
60 *
61 * \todo Move this to GraphicsView to make delegate stateless.
62 */
63 QBrush defaultBrush( ItemType type ) const;
64
65 /*! Sets the default pen used for items of type \a type to
66 * \a pen. The default pen is used in the case when the model
67 * does not provide an explicit pen.
68 *
69 * \todo Move this to GraphicsView to make delegate stateless.
70 */
71 void setDefaultPen( ItemType type, const QPen& pen );
72
73 /*!\returns The default pen for item type \a type
74 *
75 * \todo Move this to GraphicsView to make delegate stateless.
76 */
77 QPen defaultPen( ItemType type ) const;
78
79 /*! \returns The bounding Span for the item identified by \a idx
80 * when rendered with options \a opt. This is often the same as the
81 * span given by the AbstractGrid for \a idx, but it might be larger
82 * in case there are additional texts or decorations on the item.
83 *
84 * Override this to implement new itemtypes or to change the look
85 * of the existing ones.
86 */
87 virtual Span itemBoundingSpan(const StyleOptionGanttItem& opt, const QModelIndex& idx) const;
88
89 /*! \return The bounding rectangle for the graphics used to represent
90 * a constraint between points \a start and \a end (typically an
91 * arrow)
92 */
93 virtual QRectF constraintBoundingRect( const QPointF& start, const QPointF& end, const Constraint &constraint ) const;
94
95 /*! \returns The interaction state for position \a pos on item \a idx
96 * when rendered with options \a opt. This is used to tell the view
97 * about how the item should react to mouse click/drag.
98 *
99 * Override to implement new items or interactions.
100 */
101 virtual InteractionState interactionStateFor( const QPointF& pos,
102 const StyleOptionGanttItem& opt,
103 const QModelIndex& idx ) const;
104
105 /*! Paints the gantt item \a idx using \a painter and \a opt
106 */
107 virtual void paintGanttItem( QPainter* p, const StyleOptionGanttItem& opt, const QModelIndex& idx );
108
109 /*! Paints the \a constraint between points \a start and \a end
110 * using \a painter and \a opt.
111 *
112 * \todo Review \a opt's type
113 */
114 virtual void paintConstraintItem( QPainter* p, const QStyleOptionGraphicsItem& opt,
115 const QPointF& start, const QPointF& end, const Constraint &constraint );
116
117
118 /*!\returns The tooltip for index \a idx
119 */
120 virtual QString toolTip( const QModelIndex &idx ) const;
121
122 protected:
123 void paintFinishStartConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
124 const QPointF& start, const QPointF& end, const Constraint &constraint );
125 QPolygonF finishStartLine( const QPointF& start, const QPointF& end ) const;
126 QPolygonF finishStartArrow( const QPointF& start, const QPointF& end ) const;
127
128 void paintFinishFinishConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
129 const QPointF& start, const QPointF& end, const Constraint &constraint );
130 QPolygonF finishFinishLine( const QPointF& start, const QPointF& end ) const;
131 QPolygonF finishFinishArrow( const QPointF& start, const QPointF& end ) const;
132
133 void paintStartStartConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
134 const QPointF& start, const QPointF& end, const Constraint &constraint );
135 QPolygonF startStartLine( const QPointF& start, const QPointF& end ) const;
136 QPolygonF startStartArrow( const QPointF& start, const QPointF& end ) const;
137
138 void paintStartFinishConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
139 const QPointF& start, const QPointF& end, const Constraint &constraint );
140 QPolygonF startFinishLine( const QPointF& start, const QPointF& end ) const;
141 QPolygonF startFinishArrow( const QPointF& start, const QPointF& end ) const;
142 };
143}
144
145#ifndef QT_NO_DEBUG_STREAM
146QDebug operator<<( QDebug dbg, KGantt::ItemDelegate::InteractionState );
147#endif
148
149#endif /* KGANTTITEMDELEGATE_H */
150
A class used to represent a dependency.
Class used to render gantt items in a KGantt::GraphicsView.
A class representing a start point and a length.
QStyleOption subclass for gantt items.
Q_SCRIPTABLE Q_NOREPLY void start()
Contains KGantt macros.
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:59:32 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.