kdganttitemdelegate.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2010 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 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 KDGANTTITEMDELEGATE_H
00024 #define KDGANTTITEMDELEGATE_H
00025 
00026 #include <QItemDelegate>
00027 #include <QBrush>
00028 #include <QPen>
00029 #include <QDebug>
00030 
00031 #include "../kdchart_export.h"
00032 #include "kdganttglobal.h"
00033 
00034 namespace KDGantt {
00035     class StyleOptionGanttItem;
00036     class Constraint;
00037 
00038     class KDCHART_EXPORT ItemDelegate : public QItemDelegate {
00039         Q_OBJECT
00040         KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( ItemDelegate )
00041     public:
00042         enum InteractionState { State_None = 0,
00043                                 State_Move,
00044                                 State_ExtendLeft,
00045                                 State_ExtendRight,
00046                                 State_DragConstraint
00047         };
00048 
00049         explicit ItemDelegate( QObject* parent = 0 );
00050         virtual ~ItemDelegate();
00051 
00052         void setDefaultBrush( ItemType type, const QBrush& brush );
00053         QBrush defaultBrush( ItemType type ) const;
00054 
00055         void setDefaultPen( ItemType type, const QPen& pen );
00056         QPen defaultPen( ItemType type ) const;
00057 
00058         virtual Span itemBoundingSpan(const StyleOptionGanttItem& opt, const QModelIndex& idx) const;
00059         virtual QRectF constraintBoundingRect( const QPointF& start, const QPointF& end, const Constraint &constraint ) const;
00060         virtual InteractionState interactionStateFor( const QPointF& pos,
00061                                                       const StyleOptionGanttItem& opt,
00062                                                       const QModelIndex& idx ) const;
00063 
00064         virtual void paintGanttItem( QPainter* p, const StyleOptionGanttItem& opt, const QModelIndex& idx );
00065         virtual void paintConstraintItem( QPainter* p, const QStyleOptionGraphicsItem& opt,
00066                                           const QPointF& start, const QPointF& end, const Constraint &constraint );
00067         
00068         virtual QString toolTip( const QModelIndex &idx ) const;
00069 
00070     protected:
00071         void paintFinishStartConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
00072                 const QPointF& start, const QPointF& end, const Constraint &constraint );
00073         QPolygonF finishStartLine( const QPointF& start, const QPointF& end ) const;
00074         QPolygonF finishStartArrow( const QPointF& start, const QPointF& end ) const;
00075 
00076         void paintFinishFinishConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
00077                 const QPointF& start, const QPointF& end, const Constraint &constraint );
00078         QPolygonF finishFinishLine( const QPointF& start, const QPointF& end ) const;
00079         QPolygonF finishFinishArrow( const QPointF& start, const QPointF& end ) const;
00080         
00081         void paintStartStartConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
00082                 const QPointF& start, const QPointF& end, const Constraint &constraint );
00083         QPolygonF startStartLine( const QPointF& start, const QPointF& end ) const;
00084         QPolygonF startStartArrow( const QPointF& start, const QPointF& end ) const;
00085         
00086         void paintStartFinishConstraint( QPainter* p, const QStyleOptionGraphicsItem& opt,
00087                 const QPointF& start, const QPointF& end, const Constraint &constraint );
00088         QPolygonF startFinishLine( const QPointF& start, const QPointF& end ) const;
00089         QPolygonF startFinishArrow( const QPointF& start, const QPointF& end ) const;
00090 
00091         
00092     };
00093 }
00094 
00095 #ifndef QT_NO_DEBUG_STREAM
00096 QDebug operator<<( QDebug dbg, KDGantt::ItemDelegate::InteractionState );
00097 #endif
00098 
00099 #endif /* KDGANTTITEMDELEGATE_H */
00100