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