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)
return;
if (value.isEmpty())
if (value.isNull())
get()->appConfig->remove(key);
else
get()->appConfig->setValue(key, value);
@ -104,7 +104,8 @@ QString AppConfig::defaultValue(const QString &key)
if (key == CONFIG::APIURL)
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
return QStringLiteral("Meta+Alt+v");
#elif defined Q_OS_WIN
@ -112,8 +113,13 @@ QString AppConfig::defaultValue(const QString &key)
#elif defined Q_OS_MAC
return QStringLiteral("Option+v");
#endif
else
return QString();
}
if(key == CONFIG::SHORTCUT_CAPTUREWINDOW)
if(key == CONFIG::SHORTCUT_CAPTUREWINDOW) {
if(!get()->appSettings->value(key).isValid())
#ifdef Q_OS_LINUX
return QStringLiteral("Meta+Alt+4");
#elif defined Q_OS_WIN
@ -121,8 +127,12 @@ QString AppConfig::defaultValue(const QString &key)
#elif defined Q_OS_MAC
return QStringLiteral("Option+shift+4");
#endif
else
return QString();
}
if(key == CONFIG::SHORTCUT_SCREENSHOT)
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
@ -130,6 +140,9 @@ QString AppConfig::defaultValue(const QString &key)
#elif defined Q_OS_MAC
return QStringLiteral("Option+shift+3");
#endif
else
return QString();
}
if(key == CONFIG::COMMAND_SCREENSHOT)
#ifdef Q_OS_LINUX

View File

@ -1,7 +1,7 @@
#include "singlestrokekeysequenceedit.h"
SingleStrokeKeySequenceEdit::SingleStrokeKeySequenceEdit(QWidget* parent) : QKeySequenceEdit(parent){
this->installEventFilter(this);
setClearButtonEnabled(true);
}
// Note: this may prevent editingFinished from firing
@ -10,18 +10,5 @@ void SingleStrokeKeySequenceEdit::keyPressEvent(QKeyEvent * evt) {
setKeySequence(keySequence()[0]);
previousSequence = keySequence(); // update the saved sequence once one has been set
}
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
#include <QObject>
#include <QKeySequenceEdit>
#include <QKeyEvent>
class SingleStrokeKeySequenceEdit : public QKeySequenceEdit
{
Q_OBJECT
public:
SingleStrokeKeySequenceEdit(QWidget* parent=nullptr);
protected:
void keyPressEvent(QKeyEvent *evt) override;
bool eventFilter(QObject *object, QEvent *event) override;
private:
QKeySequence previousSequence;
};

View File

@ -49,9 +49,6 @@ void Settings::buildUi() {
auto eviRepoBrowseButton = new QPushButton(tr("Browse"), this);
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);
connect(buttonBox, &QDialogButtonBox::accepted, this, &Settings::onSaveClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &Settings::onCancelClicked);
@ -60,17 +57,17 @@ void Settings::buildUi() {
+---------------+-------------+------------+-------------+
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] |
+---------------+-------------+------------+-------------+
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 |
+---------------+-------------+------------+-------------+
@ -86,16 +83,16 @@ void Settings::buildUi() {
gridLayout->addWidget(eviRepoBrowseButton, 0, 4);
// row 1
gridLayout->addWidget(new QLabel(tr("Access Key"), this), 1, 0);
gridLayout->addWidget(accessKeyTextBox, 1, 1, 1, 4);
gridLayout->addWidget(new QLabel(tr("Server URL"), this), 1, 0);
gridLayout->addWidget(hostPathTextBox, 1, 1, 1, 4);
// row 2
gridLayout->addWidget(new QLabel(tr("Secret Key"), this), 2, 0);
gridLayout->addWidget(secretKeyTextBox, 2, 1, 1, 4);
// row 3
gridLayout->addWidget(new QLabel(tr("Host Path"), this), 3, 0);
gridLayout->addWidget(hostPathTextBox, 3, 1, 1, 4);
gridLayout->addWidget(new QLabel(tr("Access Key"), this), 3, 0);
gridLayout->addWidget(accessKeyTextBox, 3, 1, 1, 4);
// row 4
gridLayout->addWidget(new QLabel(tr("Capture Area Command"), this), 4, 0);
@ -112,7 +109,6 @@ void Settings::buildUi() {
// row 6 (reserved for codeblocks)
gridLayout->addWidget(new QLabel(tr("Capture Clipboard Shortcut"), this), 6, 0);
gridLayout->addWidget(captureClipboardShortcutTextBox, 6, 1);
gridLayout->addWidget(clearHotkeysButton, 6, 2, 1, 3, Qt::AlignRight);
// row 7
gridLayout->addWidget(testConnectionButton, 7, 0);
@ -232,12 +228,6 @@ void Settings::onBrowseClicked() {
}
}
void Settings::onClearShortcutsClicked() {
captureAreaShortcutTextBox->clear();
captureWindowShortcutTextBox->clear();
captureClipboardShortcutTextBox->clear();
}
void Settings::onTestConnectionClicked() {
if (hostPathTextBox->text().isEmpty()
|| accessKeyTextBox->text().isEmpty()

View File

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