-
Notifications
You must be signed in to change notification settings - Fork 64
ptz-controls: Add hotkeys for selection relative preset recall #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
EdueskaWeiz
wants to merge
1
commit into
glikely:main
from
EdueskaWeiz:feat/preset-selection-hotkeys
+59
−0
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,6 +317,28 @@ PTZControls::PTZControls(QWidget *parent) : QFrame(parent), ui(new Ui::PTZContro | |
| hotkey = registerHotkey(QT_TO_UTF8(name), QT_TO_UTF8(description), preset_set_cb, this); | ||
| preset_hotkey_map[hotkey] = i; | ||
| } | ||
|
|
||
| registerHotkey( | ||
| "PTZ.PresetPrev", obs_module_text("PTZ.Action.Preset.Prev"), | ||
| [](void *ptz_data, obs_hotkey_id, obs_hotkey_t *, bool pressed) { | ||
| if (pressed) | ||
| static_cast<PTZControls *>(ptz_data)->presetStep(-1); | ||
| }, | ||
| this); | ||
| registerHotkey( | ||
| "PTZ.PresetNext", obs_module_text("PTZ.Action.Preset.Next"), | ||
| [](void *ptz_data, obs_hotkey_id, obs_hotkey_t *, bool pressed) { | ||
| if (pressed) | ||
| static_cast<PTZControls *>(ptz_data)->presetStep(1); | ||
| }, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto using |
||
| this); | ||
| registerHotkey( | ||
| "PTZ.PresetRecallSelected", obs_module_text("PTZ.Action.Preset.RecallSelected"), | ||
| [](void *ptz_data, obs_hotkey_id, obs_hotkey_t *, bool pressed) { | ||
| if (pressed) | ||
| static_cast<PTZControls *>(ptz_data)->presetRecallSelected(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There isn't a similar single helper for activating the item, but you could do this: |
||
| }, | ||
| this); | ||
| } | ||
|
|
||
| #if defined(ENABLE_JOYSTICK) | ||
|
|
@@ -979,6 +1001,38 @@ void PTZControls::presetReset(long long preset_id) | |
| callCurrentDevice("ptz_preset_clear", "preset_id", preset_id); | ||
| } | ||
|
|
||
| /* Move the preset selection without recalling anything, so that a controller | ||
| * can browse the preset list and then trigger it with a separate button. Wraps | ||
| * around at both ends; with nothing selected yet, step forwards from the top | ||
| * and backwards from the bottom. */ | ||
| void PTZControls::presetStep(int step) | ||
| { | ||
| auto model = ui->presetListView->model(); | ||
| if (!model) | ||
| return; | ||
| const int count = model->rowCount(); | ||
| if (count < 1) | ||
| return; | ||
| const int current = ui->presetListView->currentIndex().row(); | ||
| int next; | ||
| if (current < 0) | ||
| next = step > 0 ? 0 : count - 1; | ||
| else | ||
| next = ((current + step) % count + count) % count; | ||
| ui->presetListView->setCurrentIndex(model->index(next, 0)); | ||
| } | ||
|
|
||
| /* Recall whatever preset is currently highlighted in the list. The numbered | ||
| * PTZ.Recall<n> hotkeys address a fixed preset; this one follows the | ||
| * selection, which is what makes browse-then-activate possible from a | ||
| * joystick or a keyboard. */ | ||
| void PTZControls::presetRecallSelected() | ||
| { | ||
| auto id = presetIndexToId(ui->presetListView->currentIndex()); | ||
| if (id >= 0) | ||
| presetRecall(id); | ||
| } | ||
|
|
||
| int PTZControls::presetIndexToId(QModelIndex index) | ||
| { | ||
| if (index.isValid()) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the move logic is already implemented in CircularListView. You can drop the presetStep() helper and call
static_cast<PTZControls *>(ptz_data)->ui->presetListView->cursorUp()directly.