~openmw/openmw/openmw-packaging2

« back to all changes in this revision

Viewing changes to apps/opencs/model/prefs/shortcuteventhandler.hpp

  • Committer: Scott Howard
  • Date: 2016-09-15 20:56:29 UTC
  • Revision ID: showard@debian.org-20160915205629-3tvfxe47zrb41a91
Cron update. Git hash: 37278b5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
16
    /// Users of this class should install it as an event handler
 
17
    class ShortcutEventHandler : public QObject
 
18
    {
 
19
            Q_OBJECT
 
20
 
 
21
        public:
 
22
 
 
23
            ShortcutEventHandler(QObject* parent);
 
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
 
 
39
            enum MatchResult
 
40
            {
 
41
                Matches_WithMod,
 
42
                Matches_NoMod,
 
43
                Matches_Not
 
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
 
 
60
            WidgetMap mChildParentRelations;
 
61
            ShortcutMap mWidgetShortcuts;
 
62
 
 
63
        private slots:
 
64
 
 
65
            void widgetDestroyed();
 
66
    };
 
67
}
 
68
 
 
69
#endif