13#include <QKeySequence>
78inline constexpr const char*
Global =
"Global";
80inline constexpr const char*
View =
"View";
82inline constexpr const char*
Panels =
"Panels";
83inline constexpr const char*
Tools =
"Tools";
122 return mainWidget_ !=
nullptr;
146 bool hasAction(
const QString& actionId)
const;
181 bool setShortcut(
const QString& actionId,
const QKeySequence& shortcut);
201 const QString& excludeActionId = QString())
const;
295 void createQShortcut(
const QString& actionId);
296 void updateQShortcut(
const QString& actionId);
297 void removeQShortcut(
const QString& actionId);
299 QWidget* mainWidget_ =
nullptr;
300 std::map<QString, ShortcutAction> actions_;
301 std::map<QString, std::unique_ptr<QShortcut>> shortcuts_;
302 bool allEnabled_ =
true;
333 action_.defaultShortcut = seq;
334 action_.currentShortcut = seq;
348 action_.isGlobal = g;
353 action_.
action = std::move(fn);
ShortcutBuilder & label(const QString &label)
ShortcutBuilder & description(const QString &desc)
ShortcutAction build() const
bool registerWith(ShortcutManager &manager) const
Build and register with the ShortcutManager.
ShortcutBuilder & category(const QString &cat)
ShortcutBuilder & action(std::function< void()> fn)
ShortcutBuilder & shortcut(const QKeySequence &seq)
ShortcutBuilder & global(bool g=true)
ShortcutBuilder(const QString &id)
ShortcutBuilder & canExecute(std::function< bool()> fn)
ShortcutBuilder & shortcut(const QString &seq)
Singleton manager for all keyboard shortcuts.
bool triggerAction(const QString &actionId)
Trigger an action by ID.
bool isInitialized() const
Check if manager is initialized.
void saveCustomizations()
Save custom shortcuts to settings.
QString checkConflict(const QKeySequence &shortcut, const QString &excludeActionId=QString()) const
Check if a shortcut conflicts with existing ones.
bool registerAction(const ShortcutAction &action)
Register a new shortcut action.
bool setShortcut(const QString &actionId, const QKeySequence &shortcut)
Set a custom shortcut for an action.
ShortcutManager(const ShortcutManager &)=delete
std::vector< ShortcutAction > getAllActions() const
Get all registered actions.
ShortcutManager & operator=(const ShortcutManager &)=delete
void resetAllToDefaults()
Reset all shortcuts to defaults.
void shortcutsReloaded()
Emitted when shortcuts are reloaded.
const ShortcutAction * getAction(const QString &actionId) const
Get an action by ID.
void setCategoryEnabled(const QString &category, bool enabled)
Enable or disable all actions in a category.
static ShortcutManager & instance()
Get singleton instance.
static QString keySequenceToString(const QKeySequence &seq)
Get display string for a key sequence.
void setAllEnabled(bool enabled)
Enable or disable all shortcuts (useful when dialogs are open).
void resetToDefault(const QString &actionId)
Reset an action to its default shortcut.
QStringList getCategories() const
Get all categories.
bool hasAction(const QString &actionId) const
Check if an action is registered.
std::vector< ShortcutAction > getActionsByCategory(const QString &category) const
Get actions by category.
void setActionEnabled(const QString &actionId, bool enabled)
Enable or disable an action.
void loadCustomizations()
Load custom shortcuts from settings.
void unregisterAction(const QString &actionId)
Unregister a shortcut action.
void initialize(QWidget *mainWidget)
Initialize manager with main widget for shortcut context.
int importFromFile(const QString &filePath)
Import shortcuts from JSON file.
bool exportToFile(const QString &filePath) const
Export shortcuts to JSON file.
void shortcutChanged(const QString &actionId, const QKeySequence &newShortcut)
Emitted when a shortcut is changed.
Predefined shortcut categories.
constexpr const char * View
constexpr const char * Tools
constexpr const char * Global
constexpr const char * Navigation
constexpr const char * GameActions
constexpr const char * Panels
Represents a single keyboard shortcut action.
QKeySequence currentShortcut
Current (possibly customized) key sequence.
QString category
Category for grouping (e.g., "Game Actions").
bool isCustomized() const
Check if shortcut has been customized.
bool isGlobal
Whether this is a global (application-wide) shortcut.
QString label
Display name (e.g., "Launch Game").
QString id
Unique identifier (e.g., "game.launch").
std::function< bool()> canExecute
Optional: returns false to disable temporarily.
bool isEnabled
Whether this shortcut is currently enabled.
std::function< void()> action
Action to execute.
QKeySequence defaultShortcut
Default key sequence.
void resetToDefault()
Reset to default shortcut.
QString description
Optional description.