File indexing completed on 2024-06-09 04:26:02
0001 /** 0002 * SPDX-FileCopyrightText: 1997 Nicolas Hadacek <hadacek@kde.org> 0003 * SPDX-FileCopyrightText: 1998 Matthias Ettrich <ettrich@kde.org> 0004 * SPDX-FileCopyrightText: 2001 Ellis Whitehead <ellis@kde.org> 0005 * SPDX-FileCopyrightText: 2006 Hamish Rodda <rodda@kde.org> 0006 * SPDX-FileCopyrightText: 2007 Roberto Raggi <roberto@kdevelop.org> 0007 * SPDX-FileCopyrightText: 2007 Andreas Hartmetz <ahartmetz@gmail.com> 0008 * SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0009 * SPDX-FileCopyrightText: 2015 Michael Abrahams <miabraha@gmail.com> 0010 * 0011 * SPDX-License-Identifier: GPL-3.0-or-later 0012 */ 0013 0014 0015 #ifndef KISSHORTCUTSEDITOR_P 0016 #define KISSHORTCUTSEDITOR_P 0017 0018 #include "KisShortcutsEditor.h" 0019 #include <QTreeWidget> 0020 #include <QScroller> 0021 #include <ktreewidgetsearchline.h> 0022 0023 #include "KisShortcutsDialog_p.h" 0024 0025 // NEEDED FOR KisShortcutsEditorPrivate 0026 #include "ui_KisShortcutsDialog.h" 0027 0028 0029 0030 0031 /// Declared at the end of the file - provides the basic storage unit for this class 0032 class KisShortcutsEditorItem; 0033 0034 /** 0035 * @internal 0036 */ 0037 0038 class KisShortcutsEditorPrivate 0039 { 0040 public: 0041 0042 //! Represents the three hierarchies the dialog displays. 0043 enum hierarchyLevel {Root = 0, /* Base level node (Tools, Krita...) */ 0044 Program, /* We use this like "Path Tool, Default Tool," */ 0045 Action}; /* Individual actions */ 0046 0047 0048 0049 KisShortcutsEditorPrivate(KisShortcutsEditor *q); 0050 0051 void initGUI(KisShortcutsEditor::ActionTypes actionTypes, KisShortcutsEditor::LetterShortcuts allowLetterShortcuts); 0052 void appendToView(uint nList, const QString &title = QString()); 0053 //used in appendToView 0054 QTreeWidgetItem *findOrMakeItem(QTreeWidgetItem *parent, const QString &name); 0055 0056 // Set all shortcuts to their default values (bindings). 0057 void allDefault(); 0058 0059 // clear all shortcuts 0060 void clearConfiguration(); 0061 0062 //changeXXX were described as "conflict resolution functions" 0063 void changeKeyShortcut(KisShortcutsEditorItem *item, uint column, const QKeySequence &capture); 0064 0065 //this invokes the appropriate conflict resolution function 0066 void capturedShortcut(const QVariant &, const QModelIndex &); 0067 0068 /** 0069 * Add @p action at hierarchy level @p level. 0070 * 0071 * Filters out QActions (TODO: hmm) and unnamed actions before adding. 0072 * 0073 * @return true if the actions was successfully added 0074 */ 0075 bool addAction(QAction *action, QTreeWidgetItem *hier[], hierarchyLevel level); 0076 0077 void printShortcuts() const; 0078 0079 // TODO: Is this necessary w/o global actions? 0080 void setActionTypes(KisShortcutsEditor::ActionTypes actionTypes); 0081 0082 public: 0083 0084 // Members 0085 QList<KisKActionCollection *> actionCollections; 0086 KisShortcutsEditor *q; 0087 0088 Ui::KisShortcutsDialog ui; 0089 0090 KisShortcutsEditor::ActionTypes actionTypes; 0091 KisShortcutsEditorDelegate *delegate; 0092 }; 0093 0094 0095 0096 // Hack to make two protected methods public. 0097 // Used by both KisShortcutsEditorPrivate and KisShortcutsEditorDelegate 0098 class QTreeWidgetHack : public QTreeWidget 0099 { 0100 public: 0101 QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const 0102 { 0103 return QTreeWidget::itemFromIndex(index); 0104 } 0105 QModelIndex indexFromItem(QTreeWidgetItem *item, int column) const 0106 { 0107 return QTreeWidget::indexFromItem(item, column); 0108 } 0109 }; 0110 0111 0112 /** 0113 * A QTreeWidgetItem that can handle QActions. It also provides undo functionality. 0114 * 0115 * Call commit() to save pending changes. 0116 * 0117 * @internal 0118 */ 0119 class KisShortcutsEditorItem : public QTreeWidgetItem 0120 { 0121 public: 0122 0123 KisShortcutsEditorItem(QTreeWidgetItem *parent, QAction *action); 0124 0125 //! Destructor will erase unsaved changes. 0126 ~KisShortcutsEditorItem() override; 0127 0128 //! Undo the changes since the last commit. 0129 void undo(); 0130 0131 //! Commit the changes. 0132 void commit(); 0133 0134 QVariant data(int column, int role = Qt::DisplayRole) const override; 0135 bool operator<(const QTreeWidgetItem &other) const override; 0136 0137 QKeySequence keySequence(uint column) const; 0138 void setKeySequence(uint column, const QKeySequence &seq); 0139 0140 bool isModified(uint column) const; 0141 bool isModified() const; 0142 0143 void setNameBold(bool flag) 0144 { 0145 m_isNameBold = flag; 0146 } 0147 0148 private: 0149 friend class KisShortcutsEditorPrivate; 0150 0151 //! Recheck modified status - could have changed back to initial value 0152 void updateModified(); 0153 0154 //! The action this item is responsible for 0155 QAction *m_action; 0156 0157 //! Should the Name column be painted in bold? 0158 bool m_isNameBold{false}; 0159 0160 //@{ 0161 //! The original shortcuts before user changes. 0 means no change. 0162 QList<QKeySequence> *m_oldLocalShortcut{0}; 0163 //@} 0164 0165 //! The localized action name 0166 QString m_actionNameInTable; 0167 0168 //! The action id. Needed for exporting and importing 0169 QString m_id; 0170 0171 //! The collator, for sorting 0172 QCollator m_collator; 0173 }; 0174 0175 0176 0177 #endif // KISSHORTCUTSEDITOR_P