* 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:
@@ -4,6 +4,7 @@
|
||||
#include "shortcutswidget.h"
|
||||
#include "setshortcutwidget.h"
|
||||
#include "src/core/qguiappcurrentscreen.h"
|
||||
#include "src/utils/configshortcuts.h"
|
||||
#include <QHeaderView>
|
||||
#include <QIcon>
|
||||
#include <QKeyEvent>
|
||||
@@ -36,7 +37,8 @@ ShortcutsWidget::ShortcutsWidget(QWidget* parent)
|
||||
m_layout = new QVBoxLayout(this);
|
||||
m_layout->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
|
||||
m_shortcuts = m_config.shortcuts();
|
||||
m_shortcuts = ConfigShortcuts().captureShortcutsDefault(
|
||||
CaptureToolButton::getIterableButtonTypes());
|
||||
initInfoTable();
|
||||
show();
|
||||
}
|
||||
|
||||
@@ -64,9 +64,6 @@ Controller::Controller()
|
||||
m_appLatestVersion = QStringLiteral(APP_VERSION).replace("v", "");
|
||||
qApp->setQuitOnLastWindowClosed(false);
|
||||
|
||||
// set default shortcusts if not set yet
|
||||
ConfigHandler().setShortcutsDefault();
|
||||
|
||||
// init tray icon
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||||
if (!ConfigHandler().disabledTrayIconValue()) {
|
||||
|
||||
@@ -666,33 +666,11 @@ QVector<int> ConfigHandler::fromButtonToInt(
|
||||
QVector<QStringList> ConfigHandler::shortcuts()
|
||||
{
|
||||
ConfigShortcuts configShortcuts;
|
||||
m_shortcuts = configShortcuts.captureShortcutsDefault(getButtons());
|
||||
m_shortcuts = configShortcuts.captureShortcutsDefault(
|
||||
CaptureToolButton::getIterableButtonTypes());
|
||||
return m_shortcuts;
|
||||
}
|
||||
|
||||
void ConfigHandler::setShortcutsDefault()
|
||||
{
|
||||
ConfigShortcuts configShortcuts;
|
||||
for (auto shortcutItem : shortcuts()) {
|
||||
QString shortcutName = shortcutItem.at(0);
|
||||
QString shortcutDescription = shortcutItem.at(1);
|
||||
QString shortcutValueDefault = shortcutItem.at(2);
|
||||
|
||||
QString shortcutValue = shortcut(shortcutName);
|
||||
|
||||
QKeySequence ks = QKeySequence();
|
||||
if (shortcutValue.isNull()) {
|
||||
ks = QKeySequence(shortcutValueDefault);
|
||||
if (!setShortcut(shortcutName, ks.toString())) {
|
||||
shortcutValue = shortcutValueDefault;
|
||||
}
|
||||
}
|
||||
|
||||
m_shortcuts << (QStringList() << shortcutName << shortcutDescription
|
||||
<< shortcutValue);
|
||||
}
|
||||
}
|
||||
|
||||
bool ConfigHandler::setShortcut(const QString& shortcutName,
|
||||
const QString& shortutValue)
|
||||
{
|
||||
|
||||
@@ -105,7 +105,6 @@ public:
|
||||
int undoLimit();
|
||||
|
||||
QVector<QStringList> shortcuts();
|
||||
void setShortcutsDefault();
|
||||
bool setShortcut(const QString&, const QString&);
|
||||
const QString& shortcut(const QString&);
|
||||
|
||||
|
||||
@@ -361,6 +361,9 @@ void ButtonHandler::setButtons(const QVector<CaptureToolButton*> v)
|
||||
|
||||
bool ButtonHandler::contains(const QPoint& p) const
|
||||
{
|
||||
if (m_vectorButtons.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
QPoint first(m_vectorButtons.first()->pos());
|
||||
QPoint last(m_vectorButtons.last()->pos());
|
||||
bool firstIsTopLeft = (first.x() <= last.x() && first.y() <= last.y());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user