|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
Manages application-wide keyboard shortcuts using a singleton pattern. More...
#include <shortcut_manager.h>
Public Slots | |
| void | updateRegisteredShortcuts () |
| Updates the key sequences for all currently registered shortcuts. | |
Public Member Functions | |
| ShortcutManager & | operator= (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 ShortcutManager * | GetInstance () |
| 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 | |
| WavelengthConfig * | config_ |
| 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. | |
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.
|
delete |
Deleted copy constructor to prevent copying.
|
explicitprivate |
Private constructor to enforce the singleton pattern. Initializes the pointer to the WavelengthConfig singleton.
| parent | Optional parent QObject. |
|
overrideprivatedefault |
Private default destructor.
|
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.
| Func | The type of the callable (lambda function) to connect to the shortcut's activated signal. |
| action_id | The unique identifier for the action (used to look up the key sequence in config). |
| parent | The widget to which the shortcut will be attached. |
| lambda | The function or lambda to execute when the shortcut is activated. |
|
static |
Gets the singleton instance of the ShortcutManager.
|
delete |
Deleted assignment operator to prevent assignment.
|
private |
Registers shortcuts specific to the WavelengthChatView.
| chat_view | Pointer to the WavelengthChatView instance. |
|
private |
Registers shortcuts specific to the main application window.
| window | Pointer to the QMainWindow instance. |
| navbar | Pointer to the Navbar instance within the main window. |
|
private |
Registers shortcuts specific to the SettingsView.
| settings_view | Pointer to the SettingsView instance. |
| 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.
| parent | The widget for which to register shortcuts. Must not be null. |
|
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.
|
private |
Pointer to the WavelengthConfig singleton instance for retrieving shortcut sequences.
|
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.