| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef DYNAMICSHORTCUTSWIDGET_H |
| 4 | #define DYNAMICSHORTCUTSWIDGET_H |
| 5 | |
| 6 | #include <QWidget> |
| 7 | |
| 8 | class QGridLayout; |
| 9 | class ShortcutCatcher; |
| 10 | |
| 11 | class DynamicShortcutsWidget : public QWidget { |
| 12 | Q_OBJECT |
| 13 | |
| 14 | public: |
| 15 | explicit DynamicShortcutsWidget(QWidget* parent = nullptr); |
| 16 | virtual ~DynamicShortcutsWidget(); |
| 17 | |
| 18 | // Updates shortcuts of all actions according to changes. |
| 19 | // NOTE: No access to settings is done here. |
| 20 | // Shortcuts are fetched from settings when applications starts |
| 21 | // and stored back to settings when application quits. |
| 22 | void updateShortcuts(); |
| 23 | |
| 24 | // Returns true if all shortcuts are unique, |
| 25 | // otherwise false. |
| 26 | bool areShortcutsUnique() const; |
| 27 | |
| 28 | // Populates this widget with shortcut widgets for given actions. |
| 29 | // NOTE: This gets initial shortcut for each action from its properties, NOT from |
| 30 | // the application settings, so shortcuts from settings need to be |
| 31 | // assigned to actions before calling this method. |
| 32 | void populate(QList<QAction*> actions); |
| 33 | |
| 34 | private slots: |
| 35 | void onShortcutChanged(const QKeySequence& sequence); |
| 36 | |
| 37 | signals: |
| 38 | void setupChanged(); |
| 39 | |
| 40 | private: |
| 41 | QGridLayout* m_layout; |
| 42 | QList<ShortcutCatcher*> m_actionBindings; |
| 43 | QHash<QKeySequence, ShortcutCatcher*> m_assignedShortcuts; |
| 44 | }; |
| 45 | |
| 46 | #endif // DYNAMICSHORTCUTSOVERVIEW_H |