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_VIEW_H 0008 #define KIS_DOCUMENT_SECTION_VIEW_H 0009 0010 #include <QTreeView> 0011 #include <QScroller> 0012 0013 #include "kritalayerdocker_export.h" 0014 0015 class QStyleOptionViewItem; 0016 class KisNodeModel; 0017 0018 /** 0019 * A widget displaying the Krita nodes (layers, masks, local selections, etc.) 0020 * 0021 * This class is designed as a Qt model-view widget. 0022 * 0023 * The Qt documentation explains the design and terminology for these classes: 0024 * https://doc.qt.io/qt-5/model-view-programming.html 0025 * 0026 * This widget should work correctly in your Qt designer .ui file. 0027 */ 0028 class KRITALAYERDOCKER_EXPORT NodeView : public QTreeView 0029 { 0030 Q_OBJECT 0031 Q_SIGNALS: 0032 /** 0033 * Emitted whenever the user clicks with the secondary mouse 0034 * button on an item. It is up to the application to design the 0035 * contents of the context menu and show it. 0036 */ 0037 void contextMenuRequested(const QPoint &globalPos, const QModelIndex &index); 0038 void selectionChanged(const QModelIndexList &); 0039 public: 0040 0041 enum ColumnIndex { 0042 DEFAULT_COL = 0, 0043 VISIBILITY_COL = 1, 0044 SELECTED_COL = 2, 0045 }; 0046 0047 /** 0048 * Create a new NodeView. 0049 */ 0050 explicit NodeView(QWidget *parent = 0); 0051 ~NodeView() override; 0052 0053 void setModel(QAbstractItemModel *model) override; 0054 void resizeEvent(QResizeEvent * event) override; 0055 void paintEvent (QPaintEvent *event) override; 0056 void drawBranches(QPainter *painter, const QRect &rect, 0057 const QModelIndex &index) const override; 0058 0059 void dropEvent(QDropEvent *ev) override; 0060 0061 void dragEnterEvent(QDragEnterEvent *e) override; 0062 0063 void dragMoveEvent(QDragMoveEvent *ev) override; 0064 0065 void dragLeaveEvent(QDragLeaveEvent *e) override; 0066 0067 /** 0068 * Add toggle actions for all the properties associated with the 0069 * current document section associated with the model index to the 0070 * specified menu. 0071 * 0072 * For instance, if a document section can be locked and visible, 0073 * the menu will be expanded with locked and visible toggle 0074 * actions. 0075 * 0076 * For instance 0077 @code 0078 NodeView * nodeView; 0079 QModelIndex index = getCurrentNode(); 0080 QMenu menu; 0081 if (index.isValid()) { 0082 sectionView->addPropertyActions(&menu, index); 0083 } else { 0084 menu.addAction(...); // Something to create a new document section, for example. 0085 } 0086 0087 @endcode 0088 * 0089 * @param menu A pointer to the menu that will be expanded with 0090 * the toggle actions 0091 * @param index The model index associated with the document 0092 * section that may or may not provide a number of toggle actions. 0093 */ 0094 void addPropertyActions(QMenu *menu, const QModelIndex &index); 0095 0096 void updateNode(const QModelIndex &index); 0097 0098 void toggleSolo(const QModelIndex &index); 0099 0100 protected: 0101 QItemSelectionModel::SelectionFlags selectionCommand(const QModelIndex &index, 0102 const QEvent *event) const override; 0103 0104 QModelIndex indexAt(const QPoint &point) const override; 0105 bool viewportEvent(QEvent *event) override; 0106 void contextMenuEvent(QContextMenuEvent *event) override; 0107 virtual void showContextMenu(const QPoint &globalPos, const QModelIndex &index); 0108 void startDrag (Qt::DropActions supportedActions) override; 0109 QPixmap createDragPixmap() const; 0110 0111 /** 0112 * Calculates the index of the nearest item to the cursor position 0113 */ 0114 int cursorPageIndex() const; 0115 0116 public Q_SLOTS: 0117 /// called with a theme change to refresh icon colors 0118 void slotUpdateIcons(); 0119 void slotScrollerStateChanged(QScroller::State state); 0120 void slotConfigurationChanged(); 0121 0122 protected Q_SLOTS: 0123 void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; 0124 void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>()) override; 0125 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; 0126 0127 private Q_SLOTS: 0128 void slotActionToggled(bool on, const QPersistentModelIndex &index, int property); 0129 0130 private: 0131 0132 /** 0133 * Permit to know if a slide is dragging 0134 * 0135 * @return boolean 0136 */ 0137 bool isDragging() const; 0138 0139 /** 0140 * Setter for the dragging flag 0141 * 0142 * @param flag boolean 0143 */ 0144 void setDraggingFlag(bool flag = true); 0145 0146 void updateSelectedCheckboxColumn(); 0147 0148 bool m_draggingFlag; 0149 0150 QStyleOptionViewItem optionForIndex(const QModelIndex &index) const; 0151 typedef KisNodeModel Model; 0152 class PropertyAction; 0153 class Private; 0154 Private* const d; 0155 }; 0156 0157 #endif