OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
shortcuteventhandler.hpp
Go to the documentation of this file.
1 #ifndef CSM_PREFS_SHORTCUT_EVENT_HANDLER_H
2 #define CSM_PREFS_SHORTCUT_EVENT_HANDLER_H
3 
4 #include <map>
5 #include <vector>
6 
7 #include <QObject>
8 
9 class QEvent;
10 class QWidget;
11 
12 namespace CSMPrefs
13 {
14  class Shortcut;
15 
18  {
19  Q_OBJECT
20 
21  public:
22 
24 
25  void addShortcut(Shortcut* shortcut);
26  void removeShortcut(Shortcut* shortcut);
27 
28  protected:
29 
30  bool eventFilter(QObject* watched, QEvent* event);
31 
32  private:
33 
34  typedef std::vector<Shortcut*> ShortcutList;
35  // Child, Parent
36  typedef std::map<QWidget*, QWidget*> WidgetMap;
37  typedef std::map<QWidget*, ShortcutList> ShortcutMap;
38 
40  {
44  };
45 
46  void updateParent(QWidget* widget);
47 
48  bool activate(QWidget* widget, unsigned int mod, unsigned int button);
49 
50  bool deactivate(QWidget* widget, unsigned int mod, unsigned int button);
51 
52  bool checkModifier(unsigned int mod, unsigned int button, Shortcut* shortcut, bool activate);
53 
54  MatchResult match(unsigned int mod, unsigned int button, unsigned int value);
55 
56  // Prefers Matches_WithMod and a larger number of buttons
57  static bool sort(const std::pair<MatchResult, Shortcut*>& left,
58  const std::pair<MatchResult, Shortcut*>& right);
59 
62 
63  private slots:
64 
65  void widgetDestroyed();
66  };
67 }
68 
69 #endif
ShortcutMap mWidgetShortcuts
Definition: shortcuteventhandler.hpp:61
void updateParent(QWidget *widget)
Definition: shortcuteventhandler.cpp:131
void removeShortcut(Shortcut *shortcut)
Definition: shortcuteventhandler.cpp:44
Definition: shortcuteventhandler.hpp:41
WidgetMap mChildParentRelations
Definition: shortcuteventhandler.hpp:60
bool eventFilter(QObject *watched, QEvent *event)
Definition: shortcuteventhandler.cpp:56
Users of this class should install it as an event handler.
Definition: shortcuteventhandler.hpp:17
bool checkModifier(unsigned int mod, unsigned int button, Shortcut *shortcut, bool activate)
Definition: shortcuteventhandler.cpp:268
void addShortcut(Shortcut *shortcut)
Definition: shortcuteventhandler.cpp:20
Definition: shortcuteventhandler.hpp:42
std::map< QWidget *, QWidget * > WidgetMap
Definition: shortcuteventhandler.hpp:36
void widgetDestroyed()
Definition: shortcuteventhandler.cpp:331
MatchResult
Definition: shortcuteventhandler.hpp:39
static bool sort(const std::pair< MatchResult, Shortcut * > &left, const std::pair< MatchResult, Shortcut * > &right)
Definition: shortcuteventhandler.cpp:322
bool activate(QWidget *widget, unsigned int mod, unsigned int button)
Definition: shortcuteventhandler.cpp:149
std::map< QWidget *, ShortcutList > ShortcutMap
Definition: shortcuteventhandler.hpp:37
MatchResult match(unsigned int mod, unsigned int button, unsigned int value)
Definition: shortcuteventhandler.cpp:305
std::vector< Shortcut * > ShortcutList
Definition: shortcuteventhandler.hpp:34
bool deactivate(QWidget *widget, unsigned int mod, unsigned int button)
Definition: shortcuteventhandler.cpp:220
ShortcutEventHandler(QObject *parent)
Definition: shortcuteventhandler.cpp:15
Definition: shortcuteventhandler.hpp:43
A class similar in purpose to QShortcut, but with the ability to use mouse buttons.
Definition: shortcut.hpp:16