game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
ShortcutManager Class Reference

Singleton manager for all keyboard shortcuts. More...

#include <shortcut_manager.h>

Inheritance diagram for ShortcutManager:
Collaboration diagram for ShortcutManager:

Public Member Functions

 ShortcutManager (const ShortcutManager &)=delete
QString checkConflict (const QKeySequence &shortcut, const QString &excludeActionId=QString()) const
 Check if a shortcut conflicts with existing ones.
bool exportToFile (const QString &filePath) const
 Export shortcuts to JSON file.
const ShortcutAction * getAction (const QString &actionId) const
 Get an action by ID.
std::vector< ShortcutAction > getActionsByCategory (const QString &category) const
 Get actions by category.
std::vector< ShortcutAction > getAllActions () const
 Get all registered actions.
QStringList getCategories () const
 Get all categories.
bool hasAction (const QString &actionId) const
 Check if an action is registered.
int importFromFile (const QString &filePath)
 Import shortcuts from JSON file.
void initialize (QWidget *mainWidget)
 Initialize manager with main widget for shortcut context.
bool isInitialized () const
 Check if manager is initialized.
void loadCustomizations ()
 Load custom shortcuts from settings.
ShortcutManager & operator= (const ShortcutManager &)=delete
bool registerAction (const ShortcutAction &action)
 Register a new shortcut action.
void resetAllToDefaults ()
 Reset all shortcuts to defaults.
void resetToDefault (const QString &actionId)
 Reset an action to its default shortcut.
void saveCustomizations ()
 Save custom shortcuts to settings.
void setActionEnabled (const QString &actionId, bool enabled)
 Enable or disable an action.
void setAllEnabled (bool enabled)
 Enable or disable all shortcuts (useful when dialogs are open).
void setCategoryEnabled (const QString &category, bool enabled)
 Enable or disable all actions in a category.
bool setShortcut (const QString &actionId, const QKeySequence &shortcut)
 Set a custom shortcut for an action.
void shortcutChanged (const QString &actionId, const QKeySequence &newShortcut)
 Emitted when a shortcut is changed.
void shortcutsReloaded ()
 Emitted when shortcuts are reloaded.
bool triggerAction (const QString &actionId)
 Trigger an action by ID.
void unregisterAction (const QString &actionId)
 Unregister a shortcut action.

Static Public Member Functions

static ShortcutManager & instance ()
 Get singleton instance.
static QString keySequenceToString (const QKeySequence &seq)
 Get display string for a key sequence.

Detailed Description

Singleton manager for all keyboard shortcuts.

Features:

  • Centralized shortcut registration
  • Conflict detection
  • Persistence of customizations
  • Enable/disable shortcuts by context
  • Export/import shortcut configurations

Definition at line 101 of file shortcut_manager.h.

Constructor & Destructor Documentation

◆ ShortcutManager()

ShortcutManager::ShortcutManager ( const ShortcutManager & )
delete

References ShortcutManager().

Referenced by ShortcutManager(), instance(), and operator=().

Member Function Documentation

◆ checkConflict()

QString ShortcutManager::checkConflict ( const QKeySequence & shortcut,
const QString & excludeActionId = QString() ) const

Check if a shortcut conflicts with existing ones.

Parameters
shortcutKey sequence to check
excludeActionIdOptional action ID to exclude from check
Returns
Conflicting action ID, or empty if no conflict

Definition at line 185 of file shortcut_manager.cpp.

Referenced by registerAction(), and setShortcut().

◆ exportToFile()

bool ShortcutManager::exportToFile ( const QString & filePath) const

Export shortcuts to JSON file.

Parameters
filePathOutput file path
Returns
True if export succeeded

Definition at line 298 of file shortcut_manager.cpp.

◆ getAction()

const ShortcutAction * ShortcutManager::getAction ( const QString & actionId) const

Get an action by ID.

Parameters
actionIdAction ID
Returns
Pointer to action or nullptr

Definition at line 95 of file shortcut_manager.cpp.

◆ getActionsByCategory()

std::vector< ShortcutAction > ShortcutManager::getActionsByCategory ( const QString & category) const

Get actions by category.

Parameters
categoryCategory name

Definition at line 114 of file shortcut_manager.cpp.

◆ getAllActions()

std::vector< ShortcutAction > ShortcutManager::getAllActions ( ) const

Get all registered actions.

Definition at line 103 of file shortcut_manager.cpp.

◆ getCategories()

QStringList ShortcutManager::getCategories ( ) const

Get all categories.

Definition at line 125 of file shortcut_manager.cpp.

◆ hasAction()

bool ShortcutManager::hasAction ( const QString & actionId) const

Check if an action is registered.

Parameters
actionIdAction ID to check

Definition at line 90 of file shortcut_manager.cpp.

Referenced by importFromFile().

◆ importFromFile()

int ShortcutManager::importFromFile ( const QString & filePath)

Import shortcuts from JSON file.

Parameters
filePathInput file path
Returns
Number of shortcuts imported

Definition at line 326 of file shortcut_manager.cpp.

References hasAction(), setShortcut(), and shortcutsReloaded().

◆ initialize()

void ShortcutManager::initialize ( QWidget * mainWidget)

Initialize manager with main widget for shortcut context.

Parameters
mainWidgetThe main window widget

Definition at line 34 of file shortcut_manager.cpp.

References loadCustomizations().

Referenced by ShortcutsController::setupKeyboardShortcuts().

◆ instance()

ShortcutManager & ShortcutManager::instance ( )
static

Get singleton instance.

Definition at line 21 of file shortcut_manager.cpp.

References ShortcutManager(), and instance().

Referenced by instance(), ShortcutCheatSheet::paintEvent(), and ShortcutsController::setupKeyboardShortcuts().

◆ isInitialized()

bool ShortcutManager::isInitialized ( ) const
inline

Check if manager is initialized.

Definition at line 120 of file shortcut_manager.h.

◆ keySequenceToString()

QString ShortcutManager::keySequenceToString ( const QKeySequence & seq)
static

Get display string for a key sequence.

Definition at line 372 of file shortcut_manager.cpp.

◆ loadCustomizations()

void ShortcutManager::loadCustomizations ( )

Load custom shortcuts from settings.

Definition at line 277 of file shortcut_manager.cpp.

Referenced by initialize(), and ShortcutsController::setupKeyboardShortcuts().

◆ operator=()

ShortcutManager & ShortcutManager::operator= ( const ShortcutManager & )
delete

References ShortcutManager().

◆ registerAction()

bool ShortcutManager::registerAction ( const ShortcutAction & action)

Register a new shortcut action.

Parameters
actionThe action to register
Returns
True if registered successfully

Definition at line 52 of file shortcut_manager.cpp.

References checkConflict(), ShortcutAction::currentShortcut, and ShortcutAction::id.

Referenced by ShortcutBuilder::registerWith().

◆ resetAllToDefaults()

void ShortcutManager::resetAllToDefaults ( )

Reset all shortcuts to defaults.

Definition at line 174 of file shortcut_manager.cpp.

References shortcutsReloaded().

◆ resetToDefault()

void ShortcutManager::resetToDefault ( const QString & actionId)

Reset an action to its default shortcut.

Parameters
actionIdAction ID

Definition at line 162 of file shortcut_manager.cpp.

References shortcutChanged().

◆ saveCustomizations()

void ShortcutManager::saveCustomizations ( )

Save custom shortcuts to settings.

Definition at line 257 of file shortcut_manager.cpp.

◆ setActionEnabled()

void ShortcutManager::setActionEnabled ( const QString & actionId,
bool enabled )

Enable or disable an action.

Parameters
actionIdAction ID
enabledWhether to enable

Definition at line 207 of file shortcut_manager.cpp.

◆ setAllEnabled()

void ShortcutManager::setAllEnabled ( bool enabled)

Enable or disable all shortcuts (useful when dialogs are open).

Parameters
enabledWhether to enable

Definition at line 239 of file shortcut_manager.cpp.

◆ setCategoryEnabled()

void ShortcutManager::setCategoryEnabled ( const QString & category,
bool enabled )

Enable or disable all actions in a category.

Parameters
categoryCategory name
enabledWhether to enable

Definition at line 222 of file shortcut_manager.cpp.

◆ setShortcut()

bool ShortcutManager::setShortcut ( const QString & actionId,
const QKeySequence & shortcut )

Set a custom shortcut for an action.

Parameters
actionIdAction ID
shortcutNew key sequence
Returns
True if set successfully (no conflicts)

Definition at line 141 of file shortcut_manager.cpp.

References checkConflict(), ShortcutAction::currentShortcut, and shortcutChanged().

Referenced by importFromFile().

◆ shortcutChanged()

void ShortcutManager::shortcutChanged ( const QString & actionId,
const QKeySequence & newShortcut )

Emitted when a shortcut is changed.

Referenced by resetToDefault(), and setShortcut().

◆ shortcutsReloaded()

void ShortcutManager::shortcutsReloaded ( )

Emitted when shortcuts are reloaded.

Referenced by importFromFile(), and resetAllToDefaults().

◆ triggerAction()

bool ShortcutManager::triggerAction ( const QString & actionId)

Trigger an action by ID.

Parameters
actionIdAction ID to trigger
Returns
True if action was triggered

Definition at line 380 of file shortcut_manager.cpp.

References ShortcutAction::action, ShortcutAction::canExecute, and ShortcutAction::isEnabled.

◆ unregisterAction()

void ShortcutManager::unregisterAction ( const QString & actionId)

Unregister a shortcut action.

Parameters
actionIdAction ID to remove

Definition at line 84 of file shortcut_manager.cpp.


The documentation for this class was generated from the following files: