File indexing completed on 2024-05-12 15:54:28
0001 /* 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef KGANTTITEMDELEGATE_H 0021 #define KGANTTITEMDELEGATE_H 0022 0023 #include <QItemDelegate> 0024 #include <QBrush> 0025 #include <QPen> 0026 #include <QDebug> 0027 0028 #include "kganttglobal.h" 0029 0030 namespace KGantt { 0031 class StyleOptionGanttItem; 0032 class Constraint; 0033 0034 /*!\class KGantt::ItemDelegate kganttitemdelegate.h KGanttItemDelegate 0035 *\ingroup KGantt 0036 *\brief Class used to render gantt items in a KGantt::GraphicsView 0037 * 0038 */ 0039 class KGANTT_EXPORT ItemDelegate : public QItemDelegate { 0040 Q_OBJECT 0041 KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( ItemDelegate ) 0042 public: 0043 /*!\enum KGantt::ItemDelegate::InteractionState 0044 * This enum is used for communication between the view and 0045 * the delegate about user interaction with gantt items. 0046 * 0047 * \see KGantt::ItemDelegate::interactionStateFor 0048 */ 0049 enum InteractionState { State_None = 0, 0050 State_Move, 0051 State_ExtendLeft, 0052 State_ExtendRight, 0053 State_DragConstraint 0054 }; 0055 0056 /*! Constructor. Creates an ItemDelegate with parent \a parent */ 0057 explicit ItemDelegate( QObject* parent = nullptr ); 0058 0059 /*! Destructor */ 0060 virtual ~ItemDelegate(); 0061 0062 /*! Sets the default brush used for items of type \a type to 0063 * \a brush. The default brush is used in the case when the model 0064 * does not provide an explicit brush. 0065 * 0066 * \todo Move this to GraphicsView to make delegate stateless. 0067 */ 0068 void setDefaultBrush( ItemType type, const QBrush& brush ); 0069 0070 /*!\returns The default brush for item type \a type 0071 * 0072 * \todo Move this to GraphicsView to make delegate stateless. 0073 */ 0074 QBrush defaultBrush( ItemType type ) const; 0075 0076 /*! Sets the default pen used for items of type \a type to 0077 * \a pen. The default pen is used in the case when the model 0078 * does not provide an explicit pen. 0079 * 0080 * \todo Move this to GraphicsView to make delegate stateless. 0081 */ 0082 void setDefaultPen( ItemType type, const QPen& pen ); 0083 0084 /*!\returns The default pen for item type \a type 0085 * 0086 * \todo Move this to GraphicsView to make delegate stateless. 0087 */ 0088 QPen defaultPen( ItemType type ) const; 0089 0090 /*! \returns The bounding Span for the item identified by \a idx 0091 * when rendered with options \a opt. This is often the same as the 0092 * span given by the AbstractGrid for \a idx, but it might be larger 0093 * in case there are additional texts or decorations on the item. 0094 * 0095 * Override this to implement new itemtypes or to change the look 0096 * of the existing ones. 0097 */ 0098 virtual Span itemBoundingSpan(const StyleOptionGanttItem& opt, const QModelIndex& idx) const; 0099 0100 /*! \return The bounding rectangle for the graphics used to represent 0101 * a constraint between points \a start and \a end (typically an 0102 * arrow) 0103 */ 0104 virtual QRectF constraintBoundingRect( const QPointF& start, const QPointF& end, const Constraint &constraint ) const; 0105 0106 /*! \returns The interaction state for position \a pos on item \a idx 0107 * when rendered with options \a opt. This is used to tell the view 0108 * about how the item should react to mouse click/drag. 0109 * 0110 * Override to implement new items or interactions. 0111 */ 0112 virtual InteractionState interactionStateFor( const QPointF& pos, 0113 const StyleOptionGanttItem& opt, 0114 const QModelIndex& idx ) const; 0115 0116 /*! Paints the gantt item \a idx using \a painter and \a opt 0117 */ 0118 virtual void paintGanttItem( QPainter* p, const StyleOptionGanttItem& opt, const QModelIndex& idx ); 0119 0120 /*! Paints the \a constraint between points \a start and \a end 0121 * using \a painter and \a opt. 0122 * 0123 * \todo Review \a opt's type 0124 */ 0125 virtual void paintConstraintItem( QPainter* p, const QStyleOptionGraphicsItem& opt, 0126 const QPointF& start, const QPointF& end, const Constraint &constraint ); 0127 0128 0129 /*!\returns The tooltip for index \a idx 0130 */ 0131 virtual QString toolTip( const QModelIndex &idx ) const; 0132 0133 protected: 0134 void paintFinishStartConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt, 0135 const QPointF& start, const QPointF& end, const Constraint &constraint ); 0136 QPolygonF finishStartLine( const QPointF& start, const QPointF& end ) const; 0137 QPolygonF finishStartArrow( const QPointF& start, const QPointF& end ) const; 0138 0139 void paintFinishFinishConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt, 0140 const QPointF& start, const QPointF& end, const Constraint &constraint ); 0141 QPolygonF finishFinishLine( const QPointF& start, const QPointF& end ) const; 0142 QPolygonF finishFinishArrow( const QPointF& start, const QPointF& end ) const; 0143 0144 void paintStartStartConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt, 0145 const QPointF& start, const QPointF& end, const Constraint &constraint ); 0146 QPolygonF startStartLine( const QPointF& start, const QPointF& end ) const; 0147 QPolygonF startStartArrow( const QPointF& start, const QPointF& end ) const; 0148 0149 void paintStartFinishConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt, 0150 const QPointF& start, const QPointF& end, const Constraint &constraint ); 0151 QPolygonF startFinishLine( const QPointF& start, const QPointF& end ) const; 0152 QPolygonF startFinishArrow( const QPointF& start, const QPointF& end ) const; 0153 }; 0154 } 0155 0156 #ifndef QT_NO_DEBUG_STREAM 0157 QDebug operator<<( QDebug dbg, KGantt::ItemDelegate::InteractionState ); 0158 #endif 0159 0160 #endif /* KGANTTITEMDELEGATE_H */ 0161