Version: 9.16.0
SUIT_ShortcutEditor.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef SUIT_SHORTCUTEDITOR_H
21#define SUIT_SHORTCUTEDITOR_H
22
23#include "SUIT.h"
24#include <QDialog>
25#include <QFrame>
26#include <QTreeWidget>
27#include <QHeaderView>
28#include <QTabWidget>
29#include <QTabBar>
30#include <QPainter>
31#include "SUIT_ShortcutMgr.h"
33#include <memory>
34#include <map>
35#include <set>
36#include <functional>
37
38
39class QLineEdit;
40class QLabel;
41class QPushButton;
42class QTreeWidgetItem;
43
45{
46 Q_OBJECT
47
48public:
49 SUIT_KeySequenceEdit(QWidget* = nullptr);
50 virtual ~SUIT_KeySequenceEdit() = default;
51
53 void setConfirmedKeySequence(const QKeySequence&);
54 void setEditedKeySequence(const QKeySequence&);
55 QKeySequence editedKeySequence() const;
56
58 bool isKeySequenceModified() const;
59
61 void restoreKeySequence();
62
64 static QString parseEvent(QKeyEvent* theEvent);
65
68 static bool isValidKey(int theKey);
69
70signals:
72
73
76
77private slots:
79 void onClear();
80
82 void onEditingFinished();
83
84protected:
86 virtual bool eventFilter(QObject* theObject, QEvent* theEvent);
87
88private:
89 void initialize();
90
91private:
94
95 // Last valid key sequence string from myKeySequenceLineEdit.
97};
98
102class QTextEdit;
103
104
106{
107 Q_OBJECT
108
109public:
114 virtual ~SUIT_EditKeySequenceDialog() = default;
115
116 void setModuleAndActionID(const QString& theModuleID, const QString& theInModuleActionID);
117 const QString& moduleID() const;
118 const QString& inModuleActionID() const;
119
120 void setModuleAndActionName(const QString& theModuleName, const QString& theActionName, const QString& theActionToolTip = "");
121
122 void setConfirmedKeySequence(const QKeySequence& theSequence);
123 QKeySequence editedKeySequence() const;
124
126 void updateConflictsMessage();
127
128 int exec();
129
130private slots:
131 void onEditingStarted();
132 void onEditingFinished();
133 void onRestoreFromShortcutMgr();
134 void onConfirm();
135
136private:
137 QString myModuleID;
141 QTextEdit* myTextEdit;
142};
143
144
147{
148 Q_OBJECT
149
150 friend class SUIT_ShortcutTree;
151
152private:
162 static std::map<SUIT_ShortcutContainer*, std::set<SUIT_ShortcutTabWidget*>> instances;
163
164public:
169 const std::set<QString>& theIDsOfModulesToShow,
170 std::shared_ptr<SUIT_ShortcutContainer> theContainer = std::shared_ptr<SUIT_ShortcutContainer>(),
171 QWidget* theParent = nullptr
172 );
173
175 virtual ~SUIT_ShortcutTabWidget();
176
178 void setShortcutsFromManager();
179
181 void setDefaultShortcuts();
182
184 void applyChangesToShortcutMgr();
185
186 std::shared_ptr<const SUIT_ShortcutContainer> shortcutContainer() const;
187
188 void onTreeItemDoubleClicked(SUIT_ShortcutTree* theTree, SUIT_ShortcutTreeItem* theItem);
189
190private:
191 void jumpToTreeItem(const QString& theModuleID, const QString& theInModuleID);
192
194 std::pair<QString, bool> getConfirmedKeySequence(const QString& theModuleID, const QString& theInModuleActionID) const;
195
197 void updateTabs(bool theHighlightModifiedTreeItems, bool theUpdateSyncTabWidgets);
198
199public:
201 const std::set<QString> myModuleIDs;
202
203private:
205 const std::shared_ptr<SUIT_ShortcutContainer> myShortcutContainer;
206
208
210 std::map<QString, SUIT_ShortcutTree*> myModuleTrees;
211
213 bool myIsPopulated; // If SUIT_ShortcutTabWidget::updateTabs(bool, bool) was called at least once.
214};
215
216
218{
219 Q_OBJECT
220
221public:
223
224 void mergeTabModifiedStatuses(const std::map<int, bool>& theTabModifiedStatuses);
225
226protected:
227 void paintEvent(QPaintEvent* theEvent);
228
229private:
231 std::map<int, bool> myTabModifiedStatuses;
232};
233
234
236{
237 Q_OBJECT
238
240
241public:
244 KeySequence, // Empty, if item is pure folder item.
247 NotExist // Columns with the index and greater are not exist.
248 };
249
250 enum class SortKey {
251 ID,
252 Name,
253 ToolTip,
254 KeySequence,
255 };
256
257 static SUIT_FoundActionTree::ColumnIdx toFoundActionTreeColIdx(const SUIT_ShortcutTree::ColumnIdx theColumnIdx);
258 static SUIT_ShortcutTree::SortKey toSortKey(const SUIT_ShortcutTree::ColumnIdx theColumnIdx);
259 static SUIT_ShortcutTree::ColumnIdx toColumnIdx(const SUIT_ShortcutTree::SortKey theSortKey);
261
262private:
267 SUIT_ShortcutTabWidget* theParent,
268 std::shared_ptr<const SUIT_ShortcutModuleAssets> theAssets,
269 const QString& theLang
270 );
273
274public:
275 virtual ~SUIT_ShortcutTree() = default;
276
277 SUIT_ShortcutTabWidget* parentTabWidget() const;
279 const QString& moduleID() const;
280
281 void setLang(const QString& theLang);
282 const QString& name() const;
283 const QString& toolTip() const;
284
285 void sort(SUIT_ShortcutTree::SortKey theLeadingKey, Qt::SortOrder theOrder);
286
287private:
288 void sortRecursive(QTreeWidgetItem* theParentItem);
289
291 bool updateItems(bool theHighlightModified);
292
294 bool updateChildrenItemsRecursively(
295 bool theHighlightModified,
296 QTreeWidgetItem* const theItem,
297 bool theItemIsInvisibleRoot = false
298 );
299
301 bool updateItemShortcut(
302 SUIT_ShortcutTreeItem* const theItem,
303 const std::map<QString, QKeySequence>& theModuleShortcuts,
304 bool theHighlightModified
305 ) const;
306
307 SUIT_ShortcutTreeItem* findItem(QStringList theRelativeIDTokens, const QTreeWidgetItem* theAncestorItem = nullptr) const;
308
310 std::set<SUIT_ShortcutTreeItem*, std::function<bool(SUIT_ShortcutTreeItem*, SUIT_ShortcutTreeItem*)>> getSortedChildren(QTreeWidgetItem* theParentItem);
311
315 void insertChild(
316 QTreeWidgetItem* theParentItem,
317 std::set<SUIT_ShortcutTreeItem*, std::function<bool(SUIT_ShortcutTreeItem*, SUIT_ShortcutTreeItem*)>>& theSortedChildren,
318 SUIT_ShortcutTreeItem* theChildItem
319 );
320
321private slots:
322 void onItemExpanded(QTreeWidgetItem* theItem);
323 void onItemCollapsed(QTreeWidgetItem* theItem);
324 void onHeaderItemClicked(int theColIdx);
325 void onItemDoubleClicked(QTreeWidgetItem* theWidgetItem, int theColIdx);
326
327public:
328 const std::shared_ptr<const SUIT_ShortcutModuleAssets> myAssets;
329
330private:
331 SUIT_ShortcutTabWidget* const myParentTabWidget; // Because dynamic_cast<SUIT_ShortcutTabWidget*>(QWidget::parentWidget()) == nullptr.
332
334 std::map<SUIT_ShortcutTree::SortKey, Qt::SortOrder> mySortSchema;
335
336 QString myName;
337 QString myToolTip;
338
339 bool myIsPopulated; // If SUIT_ShortcutTree::updateItems(bool) was called at least once.
340};
341
342
344{
345public:
347 SUIT_ShortcutTreeItem(const std::shared_ptr<const SUIT_ShortcutItemAssets> theAssets, const QString& theLang);
348
349 void setLang(const QString& theLang);
350
351 const QString& moduleID() const;
352 const QString& inModuleID() const;
353 const QString& lastTokenOfID() const;
354 bool isAction() const;
355 bool isFolder() const;
356
357 QString name() const;
358 const QString& path() const;
359 const QString& toolTip() const;
360 QString getValue(SUIT_ShortcutTree::SortKey theKey) const;
361 void setKeySequence(const QString& theKeySequence);
362 QString keySequence() const;
363
364 void styleAsFolder(bool theIsFolder);
365 void styleAsKeySequenceModified(bool theIsModified);
366
367 void setExpanded(bool theVal);
368 bool isExpanded() const;
369
370public:
371 const std::shared_ptr<const SUIT_ShortcutItemAssets> myAssets;
373
374private:
375 QString myPath;
376 QString myToolTip;
377};
378
379
381{
382public:
383 SUIT_ShortcutTreeHeaderItem(const std::map<SUIT_ShortcutTree::SortKey, Qt::SortOrder>& theSortSchema, SUIT_ShortcutTree::ColumnIdx theLeadingColIdx);
387
388 void setSortSchemaAndLeadingColIdx(const std::map<SUIT_ShortcutTree::SortKey, Qt::SortOrder>& theSortSchema, SUIT_ShortcutTree::ColumnIdx theLeadingColIdx);
389};
390
391#endif // SUIT_SHORTCUTEDITOR_H
#define SUIT_EXPORT
Definition: SUIT.h:36
For more information see QT documentation.
Definition: SUIT_ShortcutEditor.h:106
QLabel * myActionName
Definition: SUIT_ShortcutEditor.h:139
SUIT_KeySequenceEdit * myKeySequenceEdit
Definition: SUIT_ShortcutEditor.h:140
SUIT_EditKeySequenceDialog(const SUIT_EditKeySequenceDialog &)=delete
QTextEdit * myTextEdit
Definition: SUIT_ShortcutEditor.h:141
QString myInModuleActionID
Definition: SUIT_ShortcutEditor.h:138
QString myModuleID
Definition: SUIT_ShortcutEditor.h:137
SUIT_EditKeySequenceDialog & operator=(const SUIT_EditKeySequenceDialog &)=delete
virtual ~SUIT_EditKeySequenceDialog()=default
Definition: SUIT_FindActionDialog.h:71
ColumnIdx
Definition: SUIT_FindActionDialog.h:127
Definition: SUIT_ShortcutEditor.h:45
QLineEdit * myKeySequenceLineEdit
Definition: SUIT_ShortcutEditor.h:92
void restoreFromShortcutMgrClicked()
QString myConfirmedKeySequenceString
Definition: SUIT_ShortcutEditor.h:93
QString myPrevKeySequenceString
Definition: SUIT_ShortcutEditor.h:96
virtual ~SUIT_KeySequenceEdit()=default
Provides means to keep and edit shortcuts in compliance with the application logics....
Definition: SUIT_ShortcutMgr.h:70
Definition: SUIT_ShortcutEditor.h:218
void paintEvent(QPaintEvent *theEvent)
Definition: SUIT_ShortcutEditor.cxx:604
void mergeTabModifiedStatuses(const std::map< int, bool > &theTabModifiedStatuses)
Definition: SUIT_ShortcutEditor.cxx:597
std::map< int, bool > myTabModifiedStatuses
{tabIdx, isKeySequenceModified}[]
Definition: SUIT_ShortcutEditor.h:231
SUIT_ShortcutTabWidgetBar(SUIT_ShortcutTabWidget *theTabWidget)
Definition: SUIT_ShortcutEditor.cxx:595
Main element of Shotcut Editor GUI. Each tab presents a shortcut tree of a module.
Definition: SUIT_ShortcutEditor.h:147
const std::set< QString > myModuleIDs
Keeps IDs of modules, which will are shown on setShortcutsFromManager().
Definition: SUIT_ShortcutEditor.h:201
SUIT_ShortcutTabWidget & operator=(const SUIT_ShortcutTree &)=delete
bool myIsPopulated
Definition: SUIT_ShortcutEditor.h:213
SUIT_EditKeySequenceDialog * myEditDialog
Definition: SUIT_ShortcutEditor.h:212
std::map< QString, SUIT_ShortcutTree * > myModuleTrees
{moduleID, SUIT_ShortcutTree}.
Definition: SUIT_ShortcutEditor.h:210
const std::shared_ptr< SUIT_ShortcutContainer > myShortcutContainer
Allows to modify plenty of shortcuts and then apply them to SUIT_ShortcutMgr as a batch.
Definition: SUIT_ShortcutEditor.h:205
friend class SUIT_ShortcutTree
Definition: SUIT_ShortcutEditor.h:150
SUIT_FindActionWidget * myFindActionWidget
Definition: SUIT_ShortcutEditor.h:207
std::shared_ptr< const SUIT_ShortcutContainer > shortcutContainer() const
Definition: SUIT_ShortcutEditor.cxx:410
static std::map< SUIT_ShortcutContainer *, std::set< SUIT_ShortcutTabWidget * > > instances
Ensures that, if several SUIT_ShortcutTab instances coexist, all of them are updated when one of them...
Definition: SUIT_ShortcutEditor.h:162
Definition: SUIT_ShortcutEditor.h:381
void setSortSchemaAndLeadingColIdx(const std::map< SUIT_ShortcutTree::SortKey, Qt::SortOrder > &theSortSchema, SUIT_ShortcutTree::ColumnIdx theLeadingColIdx)
Definition: SUIT_ShortcutEditor.cxx:1178
SUIT_ShortcutTreeHeaderItem(const SUIT_ShortcutTreeHeaderItem &)=delete
~SUIT_ShortcutTreeHeaderItem()=default
SUIT_ShortcutTreeHeaderItem & operator=(const SUIT_ShortcutTreeHeaderItem &)=delete
SUIT_ShortcutTreeHeaderItem(const std::map< SUIT_ShortcutTree::SortKey, Qt::SortOrder > &theSortSchema, SUIT_ShortcutTree::ColumnIdx theLeadingColIdx)
Definition: SUIT_ShortcutEditor.cxx:1169
Definition: SUIT_ShortcutEditor.h:344
QString getValue(SUIT_ShortcutTree::SortKey theKey) const
Definition: SUIT_ShortcutEditor.cxx:1096
void styleAsKeySequenceModified(bool theIsModified)
Definition: SUIT_ShortcutEditor.cxx:1135
const QString & toolTip() const
Definition: SUIT_ShortcutEditor.cxx:1091
const QString & lastTokenOfID() const
Definition: SUIT_ShortcutEditor.cxx:1066
bool isAction() const
Definition: SUIT_ShortcutEditor.cxx:1071
const QString & path() const
Definition: SUIT_ShortcutEditor.cxx:1086
bool myIsExpanded
Definition: SUIT_ShortcutEditor.h:372
const QString & inModuleID() const
Definition: SUIT_ShortcutEditor.cxx:1061
const QString & moduleID() const
Definition: SUIT_ShortcutEditor.cxx:1056
QString myToolTip
Definition: SUIT_ShortcutEditor.h:376
void setLang(const QString &theLang)
Definition: SUIT_ShortcutEditor.cxx:1025
QString keySequence() const
Definition: SUIT_ShortcutEditor.cxx:1120
SUIT_ShortcutTreeItem(const std::shared_ptr< const SUIT_ShortcutItemAssets > theAssets, const QString &theLang)
Definition: SUIT_ShortcutEditor.cxx:1014
void styleAsFolder(bool theIsFolder)
Definition: SUIT_ShortcutEditor.cxx:1128
bool isFolder() const
Definition: SUIT_ShortcutEditor.cxx:1076
const std::shared_ptr< const SUIT_ShortcutItemAssets > myAssets
Definition: SUIT_ShortcutEditor.h:371
QString myPath
Definition: SUIT_ShortcutEditor.h:375
void setExpanded(bool theVal)
Definition: SUIT_ShortcutEditor.cxx:1157
void setKeySequence(const QString &theKeySequence)
Definition: SUIT_ShortcutEditor.cxx:1112
QString name() const
Definition: SUIT_ShortcutEditor.cxx:1081
bool isExpanded() const
Definition: SUIT_ShortcutEditor.cxx:1163
Definition: SUIT_ShortcutEditor.h:236
SUIT_ShortcutTree(const SUIT_ShortcutTree &)=delete
SortKey
Definition: SUIT_ShortcutEditor.h:250
SUIT_ShortcutTree & operator=(const SUIT_ShortcutTree &)=delete
QString myToolTip
Definition: SUIT_ShortcutEditor.h:337
bool myIsPopulated
Definition: SUIT_ShortcutEditor.h:339
QString myName
Definition: SUIT_ShortcutEditor.h:336
const std::shared_ptr< const SUIT_ShortcutModuleAssets > myAssets
Definition: SUIT_ShortcutEditor.h:328
virtual ~SUIT_ShortcutTree()=default
ColumnIdx
Definition: SUIT_ShortcutEditor.h:242
@ Name
Definition: SUIT_ShortcutEditor.h:243
@ ToolTip
Definition: SUIT_ShortcutEditor.h:245
@ KeySequence
Definition: SUIT_ShortcutEditor.h:244
SUIT_ShortcutTree::SortKey myLeadingSortKey
Definition: SUIT_ShortcutEditor.h:333
friend class SUIT_ShortcutTabWidget
Definition: SUIT_ShortcutEditor.h:239
const SUIT_ShortcutContainer & shortcutContainer() const
Definition: SUIT_ShortcutEditor.cxx:735
std::map< SUIT_ShortcutTree::SortKey, Qt::SortOrder > mySortSchema
Definition: SUIT_ShortcutEditor.h:334
SUIT_ShortcutTabWidget *const myParentTabWidget
Definition: SUIT_ShortcutEditor.h:331
static const QList< std::pair< SUIT_ShortcutTree::SortKey, Qt::SortOrder > > DEFAULT_SORT_SCHEMA
Definition: SUIT_ShortcutEditor.h:260