Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
ShortcutManager Class Referencefinal

Manages application-wide keyboard shortcuts using a singleton pattern. More...

#include <shortcut_manager.h>

Inheritance diagram for ShortcutManager:
Collaboration diagram for ShortcutManager:

Public Slots

void updateRegisteredShortcuts ()
 Updates the key sequences for all currently registered shortcuts.
 

Public Member Functions

ShortcutManageroperator= (const ShortcutManager &)=delete
 Deleted assignment operator to prevent assignment.
 
void RegisterShortcuts (QWidget *parent)
 Registers shortcuts specific to the provided parent widget.
 
 ShortcutManager (const ShortcutManager &)=delete
 Deleted copy constructor to prevent copying.
 

Static Public Member Functions

static ShortcutManagerGetInstance ()
 Gets the singleton instance of the ShortcutManager.
 

Private Member Functions

template<typename Func>
requires std::invocable<Func>
void CreateAndConnectShortcut (const QString &action_id, QWidget *parent, Func lambda)
 Template helper function to create and connect a QShortcut.
 
void RegisterChatViewShortcuts (ChatView *chat_view)
 Registers shortcuts specific to the WavelengthChatView.
 
void RegisterMainWindowShortcuts (QMainWindow *window, Navbar *navbar)
 Registers shortcuts specific to the main application window.
 
void RegisterSettingsViewShortcuts (SettingsView *settings_view)
 Registers shortcuts specific to the SettingsView.
 
 ShortcutManager (QObject *parent=nullptr)
 Private constructor to enforce the singleton pattern. Initializes the pointer to the WavelengthConfig singleton.
 
 ~ShortcutManager () override=default
 Private default destructor.
 

Private Attributes

WavelengthConfigconfig_
 Pointer to the WavelengthConfig singleton instance for retrieving shortcut sequences.
 
QMap< QWidget *, QMap< QString, QShortcut * > > registered_shortcuts_
 Stores all registered shortcuts, organized by parent widget.
 

Detailed Description

Manages application-wide keyboard shortcuts using a singleton pattern.

This class is responsible for registering, managing, and updating keyboard shortcuts for different parts of the application (e.g., main window, chat view, settings view). It retrieves shortcut sequences from WavelengthConfig and connects them to specific actions within the relevant widgets. It also allows for dynamic updating of shortcuts if the configuration changes.

Constructor & Destructor Documentation

◆ ShortcutManager() [1/2]

ShortcutManager::ShortcutManager ( const ShortcutManager & )
delete

Deleted copy constructor to prevent copying.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShortcutManager() [2/2]

ShortcutManager::ShortcutManager ( QObject * parent = nullptr)
explicitprivate

Private constructor to enforce the singleton pattern. Initializes the pointer to the WavelengthConfig singleton.

Parameters
parentOptional parent QObject.
Here is the call graph for this function:

◆ ~ShortcutManager()

ShortcutManager::~ShortcutManager ( )
overrideprivatedefault

Private default destructor.

Member Function Documentation

◆ CreateAndConnectShortcut()

template<typename Func>
requires std::invocable<Func>
void ShortcutManager::CreateAndConnectShortcut ( const QString & action_id,
QWidget * parent,
Func lambda )
private

Template helper function to create and connect a QShortcut.

Retrieves the key sequence for the given action_id from WavelengthConfig, creates a QShortcut associated with the parent widget, connects its activated() signal to the provided lambda function, and stores the shortcut in the registered_shortcuts_ map.

Template Parameters
FuncThe type of the callable (lambda function) to connect to the shortcut's activated signal.
Parameters
action_idThe unique identifier for the action (used to look up the key sequence in config).
parentThe widget to which the shortcut will be attached.
lambdaThe function or lambda to execute when the shortcut is activated.
Here is the caller graph for this function:

◆ GetInstance()

ShortcutManager * ShortcutManager::GetInstance ( )
static

Gets the singleton instance of the ShortcutManager.

Returns
Pointer to the singleton ShortcutManager instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

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

Deleted assignment operator to prevent assignment.

Here is the call graph for this function:

◆ RegisterChatViewShortcuts()

void ShortcutManager::RegisterChatViewShortcuts ( ChatView * chat_view)
private

Registers shortcuts specific to the WavelengthChatView.

Parameters
chat_viewPointer to the WavelengthChatView instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterMainWindowShortcuts()

void ShortcutManager::RegisterMainWindowShortcuts ( QMainWindow * window,
Navbar * navbar )
private

Registers shortcuts specific to the main application window.

Parameters
windowPointer to the QMainWindow instance.
navbarPointer to the Navbar instance within the main window.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterSettingsViewShortcuts()

void ShortcutManager::RegisterSettingsViewShortcuts ( SettingsView * settings_view)
private

Registers shortcuts specific to the SettingsView.

Parameters
settings_viewPointer to the SettingsView instance.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterShortcuts()

void ShortcutManager::RegisterShortcuts ( QWidget * parent)

Registers shortcuts specific to the provided parent widget.

Identifies the type of the parent widget (QMainWindow, WavelengthChatView, SettingsView) and calls the appropriate private registration method. Clear any previously registered shortcuts for this widget before registering new ones.

Parameters
parentThe widget for which to register shortcuts. Must not be null.
Here is the call graph for this function:

◆ updateRegisteredShortcuts

void ShortcutManager::updateRegisteredShortcuts ( )
slot

Updates the key sequences for all currently registered shortcuts.

Iterates through all registered widgets and their associated shortcuts, retrieves the latest key sequence from WavelengthConfig for each action ID, and updates the QShortcut object if the sequence has changed.

Here is the caller graph for this function:

Member Data Documentation

◆ config_

WavelengthConfig* ShortcutManager::config_
private

Pointer to the WavelengthConfig singleton instance for retrieving shortcut sequences.

◆ registered_shortcuts_

QMap<QWidget *, QMap<QString, QShortcut *> > ShortcutManager::registered_shortcuts_
private

Stores all registered shortcuts, organized by parent widget.

The outer map's key is the parent QWidget*.

The inner map's key is the action ID (QString, e.g., "MainWindow.OpenSettings"), and the value is the corresponding QShortcut* object.


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