Chatterino
|
Word | Meaning |
---|---|
Shortcut | QShortcut object created from a hotkey. |
Hotkey | Template for creating shortcuts in the right categories. See Hotkey object. |
Category | Place where hotkeys' actions are executed. |
Action | Code that makes a hotkey do something. |
Keybinding or key combo | The keys you press on the keyboard to do something. |
Adding new hotkeys to a widget that already has hotkeys is quite easy.
getApp()->hotkeys->shortcutsForCategory(...)
, it is located in the addShortcuts()
methodHotkeyController::HotkeyMap
named actions
ActionNames.hpp
and add a definition for your hotkey with a nice user-friendly name. Be sure to double-check the argument count.Defaults are stored in HotkeyController.cpp
in the resetToDefaults()
method. To add a default just add a call to tryAddDefault
in the appropriate section. Make sure that the name you gave the hotkey is unique.
action
is the action you added before,category
— same category that is in the shortcutsForCategory
callname
— unique name of the default hotkeykeySequence
- key combo for the hotkeyIf you want to add hotkeys to new widget that doesn't already have them it's a bit more work.
HotkeyCategory
valueAdd a value for the HotkeyCategory
enum in HotkeyCategory.hpp
. If you widget is a popup, it's best to use the existing PopupWindow
category.
Add a string name and display name for the category in HotkeyController.hpp
to hotkeyCategoryNames
and hotkeyCategoryDisplayNames
.
To make sure shortcuts created from your hotkeys are only executed in the right places, you need to add a shortcut context for Qt. This is done in Hotkey.cpp
in Hotkey::getContext()
. See the ShortcutContext enum docs for possible values
addShortcuts
If the widget you're adding Hotkeys is a BaseWidget
or a BaseWindow
. You can override the addShortcuts()
method. You should also add a call to it in the constructor. Here is some template/example code:
Renaming defaults is currently not possible. If you were to rename one, it would get recreated for everyone probably leading to broken shortcuts, don't do this until a proper mechanism has been made.