1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef QTXSHORTCUTTREE_H
21 #define QTXSHORTCUTTREE_H
26 #include <QTreeWidget>
27 #include "SUIT_ShortcutMgr.h"
35 class QTreeWidgetItem;
37 class QTX_EXPORT QtxKeySequenceEdit : public QFrame
42 QtxKeySequenceEdit(QWidget* = nullptr);
43 virtual ~QtxKeySequenceEdit() = default;
45 void setConfirmedKeySequence(const QKeySequence&);
46 void setEditedKeySequence(const QKeySequence&);
47 QKeySequence editedKeySequence() const;
48 bool isKeySequenceModified() const;
49 void restoreKeySequence();
51 static QString parseEvent(QKeyEvent*);
52 static bool isValidKey(int);
55 void editingStarted();
56 void editingFinished();
57 void restoreFromShortcutMgrClicked();
61 void onEditingFinished();
64 virtual bool eventFilter(QObject*, QEvent*);
70 QLineEdit* myKeySequenceLineEdit;
71 QString myConfirmedKeySequenceString;
73 // Last valid key sequence string from myKeySequenceLineEdit.
74 QString myPrevKeySequenceString;
78 class QtxShortcutTree;
79 class QtxShortcutTreeItem;
83 class QTX_EXPORT QtxEditKeySequenceDialog : public QDialog
88 QtxEditKeySequenceDialog(QtxShortcutTree* theParent);
89 QtxEditKeySequenceDialog(const QtxEditKeySequenceDialog&) = delete;
90 QtxEditKeySequenceDialog& operator=(const QtxEditKeySequenceDialog&) = delete;
91 virtual ~QtxEditKeySequenceDialog() = default;
93 void setModuleAndActionID(const QString& theModuleID, const QString& theInModuleActionID);
94 const QString& moduleID() const;
95 const QString& inModuleActionID() const;
97 void setModuleAndActionName(const QString& theModuleName, const QString& theActionName);
99 void setConfirmedKeySequence(const QKeySequence& theSequence);
100 QKeySequence editedKeySequence() const;
102 void updateConflictsMessage();
107 void onEditingStarted();
108 void onEditingFinished();
109 void onRestoreFromShortcutMgr();
114 QString myInModuleActionID;
115 QLabel* myActionName;
116 QtxKeySequenceEdit* myKeySequenceEdit;
117 QTextEdit* myTextEdit;
121 class QTX_EXPORT QtxShortcutTree : public QTreeWidget
127 std::shared_ptr<SUIT_ShortcutContainer> theContainer = std::shared_ptr<SUIT_ShortcutContainer>(),
128 QWidget* theParent = nullptr
130 QtxShortcutTree(const QtxShortcutTree&) = delete;
131 QtxShortcutTree& operator=(const QtxShortcutTree&) = delete;
132 virtual ~QtxShortcutTree();
134 void setShortcutsFromManager();
135 void setDefaultShortcuts();
136 void applyChangesToShortcutMgr();
138 std::shared_ptr<const SUIT_ShortcutContainer> shortcutContainer() const;
141 void updateItems(bool theHighlightModified, bool theUpdateSyncTrees);
142 std::pair<QtxShortcutTreeItem*, int> findModuleFolderItem(const QString& theModuleID) const;
145 void onItemDoubleClicked(QTreeWidgetItem* theWidgetItem, int theColIdx);
148 /** Keeps IDs of modules, which will be shown on setShortcutsFromManager(). */
149 std::set<QString> myModuleIDs;
152 /** Allows to modify plenty of shortcuts and then apply them to SUIT_ShortcutMgr as a batch. */
153 const std::shared_ptr<SUIT_ShortcutContainer> myShortcutContainer;
155 QtxEditKeySequenceDialog* myEditDialog;
158 * Ensures that, if several QtxShortcutTree instances coexist,
159 * all of them are updated when one of them applies pending changes to SUIT_ShortcutMgr.
161 * Sharing of SUIT_ShortcutContainer allows to keep some trees synchronized even without
162 * applying changes to SUIT_ShortcutMgr. Why? See QtxPagePrefShortcutTreeItem.
164 * Access is not synchronized in assumption, that all instances live in the same thread.
166 static std::map<SUIT_ShortcutContainer*, std::set<QtxShortcutTree*>> instances;
170 class QtxShortcutTreeItem : public QTreeWidgetItem
173 QtxShortcutTreeItem(const QString& theModuleID, const QString& theInModuleActionID);
177 KeySequence = 1, // Empty, if item is used as folder.
181 static QtxShortcutTreeItem* createFolderItem(const QString& theModuleID);
182 static QtxShortcutTreeItem* createShortcutItem(const QString& theModuleID, const QString& theInModuleActionID);
183 virtual ~QtxShortcutTreeItem() = default;
185 bool isFolder() const;
186 void highlightKeySequenceAsModified(bool theHighlight);
188 void setName(const QString& theName);
189 QString name() const;
191 void setKeySequence(const QString& theKeySequence);
192 QString keySequence() const;
194 const QString myModuleID;
195 const QString myInModuleActionID; // Empty, if item is used as folder.
198 #endif // QTXSHORTCUTTREE_H