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 typedef QPair<QAction*, ShortcutCatcher*> ActionBinding;
12 
13 class DynamicShortcutsWidget : public QWidget {
14   Q_OBJECT
15 
16   public:
17     explicit DynamicShortcutsWidget(QWidget* parent = nullptr);
18     virtual ~DynamicShortcutsWidget();
19 
20     // Updates shortcuts of all actions according to changes.
21     // NOTE: No access to settings is done here.
22     // Shortcuts are fetched from settings when applications starts
23     // and stored back to settings when application quits.
24     void updateShortcuts();
25 
26     // Returns true if all shortcuts are unique,
27     // otherwise false.
28     bool areShortcutsUnique() const;
29 
30     // Populates this widget with shortcut widgets for given actions.
31     // NOTE: This gets initial shortcut for each action from its properties, NOT from
32     // the application settings, so shortcuts from settings need to be
33     // assigned to actions before calling this method.
34     void populate(QList<QAction*> actions);
35 
36   signals:
37     void setupChanged();
38 
39   private:
40     QGridLayout* m_layout;
41     QList<ActionBinding> m_actionBindings;
42 };
43 
44 #endif // DYNAMICSHORTCUTSOVERVIEW_H
45