Enable shortcuts with buttons invisible (#1580) (#1800)

* Make `ShortcutsWidget` load all shortcuts

`ShortcutsWidget" now loads shortcuts for all capture widgets,
regardless of enabled state in 'Interface settings'.

Also removed unnecessary indirection which made the API confusing:

- Removed `ConfigHandler::setShortcutsDefault` which was only called
  once on a temporary `ConfigHandler` and hence had no effect

- Removed function `ConfigHandler::shortcuts`

- `ShortcutsWidget` now calls `ConfigShortcuts::captureShortcutsDefault`
  directly instead of through `ConfigHandler::shortcuts`

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Enable shortcuts for hidden buttons

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* Fix crash if ButtonHandler has no buttons

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>

* obligatory clang-format

Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
Haris Gušić
2021-08-04 18:03:19 +02:00
committed by GitHub
parent 852b8c3fb7
commit 1c4f3bdb39
6 changed files with 22 additions and 34 deletions

View File

@@ -205,10 +205,13 @@ void CaptureWidget::updateButtons()
m_uiColor = m_config.uiMainColorValue();
m_contrastUiColor = m_config.uiContrastColorValue();
auto buttons = m_config.getButtons();
auto allButtonTypes = CaptureToolButton::getIterableButtonTypes();
auto visibleButtonTypes = m_config.getButtons();
QVector<CaptureToolButton*> vectorButtons;
for (const CaptureToolButton::ButtonType& t : buttons) {
// Add all buttons but hide those that were disabled in the Interface config
// This will allow keyboard shortcuts for those buttons to work
for (const CaptureToolButton::ButtonType& t : allButtonTypes) {
CaptureToolButton* b = new CaptureToolButton(t, this);
if (t == CaptureToolButton::TYPE_SELECTIONINDICATOR) {
m_sizeIndButton = b;
@@ -241,14 +244,20 @@ void CaptureWidget::updateButtons()
break;
}
connect(
b, &CaptureToolButton::pressedButton, this, &CaptureWidget::setState);
connect(b->tool(),
&CaptureTool::requestAction,
this,
&CaptureWidget::handleButtonSignal);
vectorButtons << b;
if (visibleButtonTypes.contains(t)) {
connect(b,
&CaptureToolButton::pressedButton,
this,
&CaptureWidget::setState);
vectorButtons << b;
} else {
b->hide();
}
}
m_buttonHandler->setButtons(vectorButtons);
}