File indexing completed on 2024-12-22 04:14:51

0001 /*
0002   SPDX-FileCopyrightText: 2006 Gábor Lehel <illissius@gmail.com>
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KIS_DOCUMENT_SECTION_DELEGATE_H
0008 #define KIS_DOCUMENT_SECTION_DELEGATE_H
0009 
0010 #include <QAbstractItemDelegate>
0011 class NodeView;
0012 
0013 class KisNodeModel;
0014 
0015 /**
0016  * See KisNodeModel and NodeView.
0017  *
0018  * A delegate provides the gui machinery, using Qt's model/view terminology.
0019  * This class is owned by NodeView to do the work of generating the
0020  * graphical representation of each item.
0021  */
0022 class NodeDelegate: public QAbstractItemDelegate
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit NodeDelegate(NodeView *view, QObject *parent = 0);
0028     ~NodeDelegate() override;
0029 
0030     void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0031     void drawBranches(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0032     QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0033     bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
0034 
0035     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
0036     void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
0037     void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const override;
0038 
0039     void toggleSolo(const QModelIndex &index);
0040 
0041     void slotUpdateIcon();
0042 
0043 Q_SIGNALS:
0044     void resetVisibilityStasis();
0045 
0046 protected:
0047     bool eventFilter(QObject *object, QEvent *event) override;
0048 
0049 private:
0050     typedef KisNodeModel Model;
0051     typedef NodeView View;
0052     class Private;
0053     Private* const d;
0054 
0055     static QStyleOptionViewItem getOptions(const QStyleOptionViewItem &option, const QModelIndex &index);
0056     void drawProgressBar(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0057 
0058     void drawColorLabel(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0059     void drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0060 
0061     QRect thumbnailClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0062     void drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0063 
0064     QRect iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0065     QRect textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0066     void drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0067     void drawIcons(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0068 
0069     QRect visibilityClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0070     void drawVisibilityIcon(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0071 
0072     QRect decorationClickRect(const QStyleOptionViewItem &option, const QModelIndex &index) const;
0073     void drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0074     void drawExpandButton(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0075     void drawAnimatedDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const;
0076 
0077     void drawSelectedButton(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index,
0078                             QStyle *style) const;
0079 
0080     // In here we handle the intricacies required to tie the state of selection and "current" index.
0081     void changeSelectionAndCurrentIndex(const QModelIndex &index);
0082 
0083 public Q_SLOTS:
0084     void slotConfigChanged();
0085 private Q_SLOTS:
0086     void slotResetState();
0087 };
0088 
0089 #endif