Fix key selector (#238)

* SingleStrokeKeySequenceEdit: Emit keychange and show clear Button remove eventfilter

* Update Settings to remove clearbutton for combos and use Server URL for host path

* Remove keys on null input, Allow Shortcuts to be unbound

---------

Co-authored-by: Chris Rizzitello <crizzitello@ics.com>
main
crizzitello 2023-10-03 16:21:01 -04:00 committed by GitHub
parent 96e8a9a290
commit b170e8786b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 54 deletions

View File

@ -37,7 +37,7 @@ void AppConfig::setValue(const QString &key, const QString &value)
if (AppConfig::value(key) == value) if (AppConfig::value(key) == value)
return; return;
if (value.isEmpty()) if (value.isNull())
get()->appConfig->remove(key); get()->appConfig->remove(key);
else else
get()->appConfig->setValue(key, value); get()->appConfig->setValue(key, value);
@ -104,32 +104,45 @@ QString AppConfig::defaultValue(const QString &key)
if (key == CONFIG::APIURL) if (key == CONFIG::APIURL)
return QStringLiteral("http://localhost:8080"); return QStringLiteral("http://localhost:8080");
if (key == CONFIG::SHORTCUT_CAPTURECLIPBOARD) if (key == CONFIG::SHORTCUT_CAPTURECLIPBOARD) {
if(!get()->appSettings->value(key).isValid())
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
return QStringLiteral("Meta+Alt+v"); return QStringLiteral("Meta+Alt+v");
#elif defined Q_OS_WIN #elif defined Q_OS_WIN
return QStringLiteral("Alt+v"); return QStringLiteral("Alt+v");
#elif defined Q_OS_MAC #elif defined Q_OS_MAC
return QStringLiteral("Option+v"); return QStringLiteral("Option+v");
#endif #endif
else
return QString();
}
if(key == CONFIG::SHORTCUT_CAPTUREWINDOW)
#ifdef Q_OS_LINUX
return QStringLiteral("Meta+Alt+4");
#elif defined Q_OS_WIN
return QStringLiteral("Alt+4");
#elif defined Q_OS_MAC
return QStringLiteral("Option+shift+4");
#endif
if(key == CONFIG::SHORTCUT_SCREENSHOT) if(key == CONFIG::SHORTCUT_CAPTUREWINDOW) {
if(!get()->appSettings->value(key).isValid())
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
return QStringLiteral("Meta+Alt+3"); return QStringLiteral("Meta+Alt+4");
#elif defined Q_OS_WIN #elif defined Q_OS_WIN
return QStringLiteral("Alt+3"); return QStringLiteral("Alt+4");
#elif defined Q_OS_MAC #elif defined Q_OS_MAC
return QStringLiteral("Option+shift+3"); return QStringLiteral("Option+shift+4");
#endif #endif
else
return QString();
}
if(key == CONFIG::SHORTCUT_SCREENSHOT) {
if(!get()->appSettings->value(key).isValid())
#ifdef Q_OS_LINUX
return QStringLiteral("Meta+Alt+3");
#elif defined Q_OS_WIN
return QStringLiteral("Alt+3");
#elif defined Q_OS_MAC
return QStringLiteral("Option+shift+3");
#endif
else
return QString();
}
if(key == CONFIG::COMMAND_SCREENSHOT) if(key == CONFIG::COMMAND_SCREENSHOT)
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX

View File

@ -1,7 +1,7 @@
#include "singlestrokekeysequenceedit.h" #include "singlestrokekeysequenceedit.h"
SingleStrokeKeySequenceEdit::SingleStrokeKeySequenceEdit(QWidget* parent) : QKeySequenceEdit(parent){ SingleStrokeKeySequenceEdit::SingleStrokeKeySequenceEdit(QWidget* parent) : QKeySequenceEdit(parent){
this->installEventFilter(this); setClearButtonEnabled(true);
} }
// Note: this may prevent editingFinished from firing // Note: this may prevent editingFinished from firing
@ -10,18 +10,5 @@ void SingleStrokeKeySequenceEdit::keyPressEvent(QKeyEvent * evt) {
setKeySequence(keySequence()[0]); setKeySequence(keySequence()[0]);
previousSequence = keySequence(); // update the saved sequence once one has been set previousSequence = keySequence(); // update the saved sequence once one has been set
} Q_EMIT keySequenceChanged(previousSequence);
bool SingleStrokeKeySequenceEdit::eventFilter(QObject *object, QEvent *event) {
if (event->type() == QEvent::FocusIn) {
// save + remove the current sequence to provide the user with a prompt
previousSequence = keySequence();
clear();
}
if (event->type() == QEvent::FocusOut) {
// restore the current/saved sequence
setKeySequence(previousSequence);
Q_EMIT keySequenceChanged(previousSequence);
}
return QKeySequenceEdit::eventFilter(object, event);
} }

View File

@ -1,19 +1,17 @@
#pragma once #pragma once
#include <QObject>
#include <QKeySequenceEdit> #include <QKeySequenceEdit>
#include <QKeyEvent> #include <QKeyEvent>
class SingleStrokeKeySequenceEdit : public QKeySequenceEdit class SingleStrokeKeySequenceEdit : public QKeySequenceEdit
{ {
Q_OBJECT
public: public:
SingleStrokeKeySequenceEdit(QWidget* parent=nullptr); SingleStrokeKeySequenceEdit(QWidget* parent=nullptr);
protected: protected:
void keyPressEvent(QKeyEvent *evt) override; void keyPressEvent(QKeyEvent *evt) override;
bool eventFilter(QObject *object, QEvent *event) override;
private: private:
QKeySequence previousSequence; QKeySequence previousSequence;
}; };

View File

@ -49,9 +49,6 @@ void Settings::buildUi() {
auto eviRepoBrowseButton = new QPushButton(tr("Browse"), this); auto eviRepoBrowseButton = new QPushButton(tr("Browse"), this);
connect(eviRepoBrowseButton, &QPushButton::clicked, this, &Settings::onBrowseClicked); connect(eviRepoBrowseButton, &QPushButton::clicked, this, &Settings::onBrowseClicked);
auto clearHotkeysButton = new QPushButton(tr("Clear Shortcuts"), this);
connect(clearHotkeysButton, &QPushButton::clicked, this, &Settings::onClearShortcutsClicked);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel, this); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel, this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &Settings::onSaveClicked); connect(buttonBox, &QDialogButtonBox::accepted, this, &Settings::onSaveClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &Settings::onCancelClicked); connect(buttonBox, &QDialogButtonBox::rejected, this, &Settings::onCancelClicked);
@ -60,17 +57,17 @@ void Settings::buildUi() {
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
0 | Evi Repo Lbl | [Evi Repo TB] | browseBtn | 0 | Evi Repo Lbl | [Evi Repo TB] | browseBtn |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
1 | A. Key Label | [A. Key TB] | 1 | Host Label | [Host TB] |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
2 | S. Key Label | [S. Key TB] | 2 | A. Key Label | [A. Key TB] |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
3 | Host Label | [Host TB] | 3 | S. Key Label | [S. Key TB] |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
4 | Cap A Cmd Lbl | [CapACmdTB] | CapASh lbl | [CapASh TB] | 4 | Cap A Cmd Lbl | [CapACmdTB] | CapASh lbl | [CapASh TB] |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
5 | Cap W Cmd Lbl | [CapWCmdTB] | CapWSh lbl | [CapWSh TB] | 5 | Cap W Cmd Lbl | [CapWCmdTB] | CapWSh lbl | [CapWSh TB] |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
6 | CodeblkSh Lbl | [CodeblkSh TB] | Clear Hotkey Btn | 6 | CodeblkSh Lbl | [CodeblkSh TB] |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
7 | Test Conn Btn | StatusLabel | 7 | Test Conn Btn | StatusLabel |
+---------------+-------------+------------+-------------+ +---------------+-------------+------------+-------------+
@ -86,16 +83,16 @@ void Settings::buildUi() {
gridLayout->addWidget(eviRepoBrowseButton, 0, 4); gridLayout->addWidget(eviRepoBrowseButton, 0, 4);
// row 1 // row 1
gridLayout->addWidget(new QLabel(tr("Access Key"), this), 1, 0); gridLayout->addWidget(new QLabel(tr("Server URL"), this), 1, 0);
gridLayout->addWidget(accessKeyTextBox, 1, 1, 1, 4); gridLayout->addWidget(hostPathTextBox, 1, 1, 1, 4);
// row 2 // row 2
gridLayout->addWidget(new QLabel(tr("Secret Key"), this), 2, 0); gridLayout->addWidget(new QLabel(tr("Secret Key"), this), 2, 0);
gridLayout->addWidget(secretKeyTextBox, 2, 1, 1, 4); gridLayout->addWidget(secretKeyTextBox, 2, 1, 1, 4);
// row 3 // row 3
gridLayout->addWidget(new QLabel(tr("Host Path"), this), 3, 0); gridLayout->addWidget(new QLabel(tr("Access Key"), this), 3, 0);
gridLayout->addWidget(hostPathTextBox, 3, 1, 1, 4); gridLayout->addWidget(accessKeyTextBox, 3, 1, 1, 4);
// row 4 // row 4
gridLayout->addWidget(new QLabel(tr("Capture Area Command"), this), 4, 0); gridLayout->addWidget(new QLabel(tr("Capture Area Command"), this), 4, 0);
@ -112,7 +109,6 @@ void Settings::buildUi() {
// row 6 (reserved for codeblocks) // row 6 (reserved for codeblocks)
gridLayout->addWidget(new QLabel(tr("Capture Clipboard Shortcut"), this), 6, 0); gridLayout->addWidget(new QLabel(tr("Capture Clipboard Shortcut"), this), 6, 0);
gridLayout->addWidget(captureClipboardShortcutTextBox, 6, 1); gridLayout->addWidget(captureClipboardShortcutTextBox, 6, 1);
gridLayout->addWidget(clearHotkeysButton, 6, 2, 1, 3, Qt::AlignRight);
// row 7 // row 7
gridLayout->addWidget(testConnectionButton, 7, 0); gridLayout->addWidget(testConnectionButton, 7, 0);
@ -232,12 +228,6 @@ void Settings::onBrowseClicked() {
} }
} }
void Settings::onClearShortcutsClicked() {
captureAreaShortcutTextBox->clear();
captureWindowShortcutTextBox->clear();
captureClipboardShortcutTextBox->clear();
}
void Settings::onTestConnectionClicked() { void Settings::onTestConnectionClicked() {
if (hostPathTextBox->text().isEmpty() if (hostPathTextBox->text().isEmpty()
|| accessKeyTextBox->text().isEmpty() || accessKeyTextBox->text().isEmpty()

View File

@ -78,6 +78,5 @@ class Settings : public AShirtDialog {
QKeySequenceEdit* captureClipboardShortcutTextBox = nullptr; QKeySequenceEdit* captureClipboardShortcutTextBox = nullptr;
LoadingButton* testConnectionButton = nullptr; LoadingButton* testConnectionButton = nullptr;
QPushButton* eviRepoBrowseButton = nullptr; QPushButton* eviRepoBrowseButton = nullptr;
QPushButton* clearHotkeysButton = nullptr;
QErrorMessage* couldNotSaveSettingsMsg = nullptr; QErrorMessage* couldNotSaveSettingsMsg = nullptr;
}; };