1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 19:45:34 +00:00
openmw/apps/opencs/model/prefs/shortcutmanager.hpp

74 lines
2.2 KiB
C++
Raw Normal View History

#ifndef CSM_PREFS_SHORTCUTMANAGER_H
#define CSM_PREFS_SHORTCUTMANAGER_H
#include <map>
2022-10-19 17:02:00 +00:00
#include <string>
#include <utility>
#include <QKeySequence>
#include <QObject>
#include <QString>
namespace CSMPrefs
{
class Shortcut;
class ShortcutEventHandler;
/// Class used to track and update shortcuts/sequences
class ShortcutManager : public QObject
{
2022-09-22 18:26:05 +00:00
Q_OBJECT
2022-09-22 18:26:05 +00:00
public:
ShortcutManager();
2022-09-22 18:26:05 +00:00
/// The shortcut class will do this automatically
void addShortcut(Shortcut* shortcut);
2022-09-22 18:26:05 +00:00
/// The shortcut class will do this automatically
void removeShortcut(Shortcut* shortcut);
bool getSequence(std::string_view name, QKeySequence& sequence) const;
void setSequence(std::string_view name, const QKeySequence& sequence);
2022-09-22 18:26:05 +00:00
bool getModifier(const std::string& name, int& modifier) const;
void setModifier(std::string_view name, int modifier);
2022-09-22 18:26:05 +00:00
std::string convertToString(const QKeySequence& sequence) const;
std::string convertToString(int modifier) const;
2022-09-22 18:26:05 +00:00
std::string convertToString(const QKeySequence& sequence, int modifier) const;
2022-09-22 18:26:05 +00:00
void convertFromString(const std::string& data, QKeySequence& sequence) const;
void convertFromString(const std::string& data, int& modifier) const;
2022-09-22 18:26:05 +00:00
void convertFromString(const std::string& data, QKeySequence& sequence, int& modifier) const;
2022-09-22 18:26:05 +00:00
/// Replaces "{sequence-name}" or "{modifier-name}" with the appropriate text
QString processToolTip(const QString& toolTip) const;
2022-09-22 18:26:05 +00:00
private:
// Need a multimap in case multiple shortcuts share the same name
typedef std::multimap<std::string, Shortcut*, std::less<>> ShortcutMap;
typedef std::map<std::string, QKeySequence, std::less<>> SequenceMap;
typedef std::map<std::string, int, std::less<>> ModifierMap;
2022-09-22 18:26:05 +00:00
typedef std::map<int, std::string> NameMap;
typedef std::map<std::string, int> KeyMap;
2022-09-22 18:26:05 +00:00
ShortcutMap mShortcuts;
SequenceMap mSequences;
ModifierMap mModifiers;
2022-09-22 18:26:05 +00:00
NameMap mNames;
KeyMap mKeys;
2022-09-22 18:26:05 +00:00
ShortcutEventHandler* mEventHandler;
2022-09-22 18:26:05 +00:00
void createLookupTables();
2022-09-22 18:26:05 +00:00
static const std::pair<int, const char*> QtKeys[];
};
}
#endif