File indexing completed on 2024-04-28 15:16:03

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 #ifndef MARBLE_PLUGINITEMDELEGATE_H
0007 #define MARBLE_PLUGINITEMDELEGATE_H
0008 
0009 #include <QAbstractItemDelegate>
0010 
0011 #include <QModelIndex>
0012 #include <QIcon>
0013 
0014 class QPainter;
0015 class QRect;
0016 class QStyleOptionButton;
0017 class QStyleOptionViewItem;
0018 
0019 namespace Marble
0020 {
0021 
0022 class PluginItemDelegate : public QAbstractItemDelegate
0023 {
0024     Q_OBJECT
0025 
0026  public:
0027     explicit PluginItemDelegate( QAbstractItemView *view, QObject * parent = nullptr );
0028     ~PluginItemDelegate() override;
0029     
0030     void paint( QPainter *painter,
0031                 const QStyleOptionViewItem& option,
0032                 const QModelIndex& index ) const override;
0033     QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex & index ) const override;
0034 
0035     void setAboutIcon( const QIcon& icon );
0036     void setConfigIcon( const QIcon& icon );
0037     
0038  Q_SIGNALS:
0039     /**
0040      * This signal is emitted if the user clicks on a "about"-button of an item in the view
0041      * passed to the constructor.
0042      */
0043     void aboutPluginClicked( const QModelIndex &index );
0044 
0045     /**
0046      * This signal is emitted if the user clicks on a "configure"-button of an item in the view
0047      * passed to the constructor.
0048      */
0049     void configPluginClicked( const QModelIndex &index );
0050 
0051  protected:
0052     bool editorEvent( QEvent *event,
0053                       QAbstractItemModel *model,
0054                       const QStyleOptionViewItem &option,
0055                       const QModelIndex &index ) override;
0056 
0057  private:
0058     enum ButtonType {
0059         About,
0060         Configure
0061     };
0062 
0063     static QStyleOptionButton checkboxOption( const QStyleOptionViewItem& option,
0064                                               const QModelIndex& index,
0065                                               int position = 0,
0066                                               Qt::AlignmentFlag alignment = Qt::AlignLeft );
0067     QStyleOptionButton buttonOption(   const QStyleOptionViewItem& option,
0068                                        const QModelIndex& index,
0069                                        PluginItemDelegate::ButtonType type,
0070                                        int position = 0,
0071                                        Qt::AlignmentFlag alignment = Qt::AlignLeft ) const;
0072     static QSize nameSize( const QModelIndex& index );
0073     
0074     static QRect alignRect( const QRect& object, const QRect& frame, int position, Qt::AlignmentFlag alignment );
0075 
0076     QModelIndex m_configPressedIndex;
0077     QModelIndex m_aboutPressedIndex;
0078 
0079     QIcon m_aboutIcon;
0080     QIcon m_configIcon;
0081 };
0082 
0083 }
0084 
0085 #endif