File indexing completed on 2024-05-12 04:20:44

0001 /*
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KGantt library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef KGANTTLEGEND_H
0010 #define KGANTTLEGEND_H
0011 
0012 #include <QAbstractItemView>
0013 
0014 #include "kganttglobal.h"
0015 #include "kganttstyleoptionganttitem.h"
0016 
0017 namespace KGantt 
0018 {
0019 
0020     /*!\class KGantt::Legend kganttlegend.h KGanttLegend
0021      * \ingroup KGantt
0022      * \brief Legend showing an image and a description for Gantt items
0023      *
0024      * This is an item view class showing a small Gantt item and it's
0025      * text defined by LegendRole.
0026      */
0027     class KGANTT_EXPORT Legend : public QAbstractItemView
0028     {
0029         Q_OBJECT
0030         KGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC( Legend )
0031     public:
0032         /*! Constructor. Creates a Legend with parent \a parent.
0033          * The QObject parent is not used for anything internally. */
0034         explicit Legend( QWidget* parent = nullptr );
0035 
0036         /*! Destructor. Does nothing */
0037         ~Legend() override;
0038 
0039         /*reimp*/ QModelIndex indexAt( const QPoint& point ) const override;
0040         /*reimp*/ QRect visualRect( const QModelIndex& index ) const override;
0041 
0042         /*reimp*/ void scrollTo( const QModelIndex&, ScrollHint = EnsureVisible ) override {}
0043 
0044         /*reimp*/ QSize sizeHint() const override;
0045         /*reimp*/ QSize minimumSizeHint() const override;
0046 
0047         /*reimp*/ void setModel( QAbstractItemModel* model ) override;
0048 
0049     protected:
0050         /*! Draws the legend item at \a index and all of it's children recursively 
0051          *  at \a pos onto \a painter.
0052          *  Reimplement this if you want to draw items in an user defined way.
0053          *  \returns the rectangle drawn.
0054          */
0055         virtual QRect drawItem( QPainter* painter, const QModelIndex& index, const QPoint& pos = QPoint() ) const;
0056 
0057         /*! Calculates the needed space for the legend item at \a index and, if \a recursive is true,
0058          *  all child items.
0059          */
0060         virtual QSize measureItem( const QModelIndex& index, bool recursive = true ) const;
0061 
0062         /*! Creates a StyleOptionGanttItem with all style options filled in
0063          *  except the target rectangles.
0064          */
0065         virtual StyleOptionGanttItem getStyleOption( const QModelIndex& index ) const;
0066 
0067         /*reimp*/ void paintEvent( QPaintEvent* event ) override;
0068 
0069         /*reimp*/ int horizontalOffset() const override { return 0; }
0070         /*reimp*/ bool isIndexHidden( const QModelIndex& ) const override { return false; }
0071         /*reimp*/ QModelIndex moveCursor( CursorAction, Qt::KeyboardModifiers ) override { return QModelIndex(); }
0072         /*reimp*/ void setSelection( const QRect&, QItemSelectionModel::SelectionFlags ) override {}
0073         /*reimp*/ int verticalOffset() const override { return 0; }
0074         /*reimp*/ QRegion visualRegionForSelection( const QItemSelection& ) const override { return QRegion(); }
0075 
0076     protected Q_SLOTS:
0077         /*! Triggers repainting of the legend.
0078          */
0079         virtual void modelDataChanged();
0080     };
0081 }
0082 
0083 #endif