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