OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
shortcutmanager.hpp
Go to the documentation of this file.
1 #ifndef CSM_PREFS_SHORTCUTMANAGER_H
2 #define CSM_PREFS_SHORTCUTMANAGER_H
3 
4 #include <map>
5 
6 #include <QKeySequence>
7 #include <QObject>
8 #include <QString>
9 
10 namespace CSMPrefs
11 {
12  class Shortcut;
13  class ShortcutEventHandler;
14 
16  class ShortcutManager : public QObject
17  {
18  Q_OBJECT
19 
20  public:
21 
23 
25  void addShortcut(Shortcut* shortcut);
26 
28  void removeShortcut(Shortcut* shortcut);
29 
30  bool getSequence(const std::string& name, QKeySequence& sequence) const;
31  void setSequence(const std::string& name, const QKeySequence& sequence);
32 
33  bool getModifier(const std::string& name, int& modifier) const;
34  void setModifier(const std::string& name, int modifier);
35 
36  std::string convertToString(const QKeySequence& sequence) const;
37  std::string convertToString(int modifier) const;
38 
39  std::string convertToString(const QKeySequence& sequence, int modifier) const;
40 
41  void convertFromString(const std::string& data, QKeySequence& sequence) const;
42  void convertFromString(const std::string& data, int& modifier) const;
43 
44  void convertFromString(const std::string& data, QKeySequence& sequence, int& modifier) const;
45 
47  QString processToolTip(const QString& toolTip) const;
48 
49  private:
50 
51  // Need a multimap in case multiple shortcuts share the same name
52  typedef std::multimap<std::string, Shortcut*> ShortcutMap;
53  typedef std::map<std::string, QKeySequence> SequenceMap;
54  typedef std::map<std::string, int> ModifierMap;
55  typedef std::map<int, std::string> NameMap;
56  typedef std::map<std::string, int> KeyMap;
57 
61 
64 
66 
67  void createLookupTables();
68 
69  static const std::pair<int, const char*> QtKeys[];
70  };
71 }
72 
73 #endif
void setSequence(const std::string &name, const QKeySequence &sequence)
Definition: shortcutmanager.cpp:58
std::string convertToString(const QKeySequence &sequence) const
Definition: shortcutmanager.cpp:115
SequenceMap mSequences
Definition: shortcutmanager.hpp:59
void convertFromString(const std::string &data, QKeySequence &sequence) const
Definition: shortcutmanager.cpp:177
void createLookupTables()
Definition: shortcutmanager.cpp:267
Users of this class should install it as an event handler.
Definition: shortcuteventhandler.hpp:17
std::map< std::string, int > KeyMap
Definition: shortcutmanager.hpp:56
QString processToolTip(const QString &toolTip) const
Replaces "{sequence-name}" or "{modifier-name}" with the appropriate text.
Definition: shortcutmanager.cpp:289
void setModifier(const std::string &name, int modifier)
Definition: shortcutmanager.cpp:93
void addShortcut(Shortcut *shortcut)
The shortcut class will do this automatically.
Definition: shortcutmanager.cpp:19
NameMap mNames
Definition: shortcutmanager.hpp:62
bool getSequence(const std::string &name, QKeySequence &sequence) const
Definition: shortcutmanager.cpp:45
KeyMap mKeys
Definition: shortcutmanager.hpp:63
std::map< std::string, int > ModifierMap
Definition: shortcutmanager.hpp:54
static const std::pair< int, const char * > QtKeys[]
Definition: shortcutmanager.hpp:69
std::multimap< std::string, Shortcut * > ShortcutMap
Definition: shortcutmanager.hpp:52
std::map< int, std::string > NameMap
Definition: shortcutmanager.hpp:55
ShortcutEventHandler * mEventHandler
Definition: shortcutmanager.hpp:65
Class used to track and update shortcuts/sequences.
Definition: shortcutmanager.hpp:16
ShortcutMap mShortcuts
Definition: shortcutmanager.hpp:58
ShortcutManager()
Definition: shortcutmanager.cpp:13
std::map< std::string, QKeySequence > SequenceMap
Definition: shortcutmanager.hpp:53
void removeShortcut(Shortcut *shortcut)
The shortcut class will do this automatically.
Definition: shortcutmanager.cpp:26
A class similar in purpose to QShortcut, but with the ability to use mouse buttons.
Definition: shortcut.hpp:16
bool getModifier(const std::string &name, int &modifier) const
Definition: shortcutmanager.cpp:80
ModifierMap mModifiers
Definition: shortcutmanager.hpp:60
const char * name
Definition: crashcatcher.cpp:59