diff --git a/src/apps/deskflow-gui/dialogs/ActionDialog.cpp b/src/apps/deskflow-gui/dialogs/ActionDialog.cpp index efc176f27..274a034d9 100644 --- a/src/apps/deskflow-gui/dialogs/ActionDialog.cpp +++ b/src/apps/deskflow-gui/dialogs/ActionDialog.cpp @@ -38,6 +38,9 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey & connect( ui->comboActionType, QOverload::of(&QComboBox::currentIndexChanged), this, &ActionDialog::actionTypeChanged ); + connect(ui->listScreens, &QListWidget::itemChanged, this, [&] { + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(canSave()); + }); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ActionDialog::accept); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ActionDialog::reject); @@ -78,8 +81,7 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey & void ActionDialog::accept() { - if (!ui->keySequenceWidget->valid() && ui->comboActionType->currentIndex() >= 0 && - ui->comboActionType->currentIndex() < 3) + if (!canSave()) return; m_action.setKeySequence(ui->keySequenceWidget->keySequence()); @@ -115,10 +117,12 @@ void ActionDialog::accept() void ActionDialog::keySequenceChanged() { ui->listScreens->setEnabled(!ui->keySequenceWidget->keySequence().isMouseButton()); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(canSave()); } void ActionDialog::actionTypeChanged(int index) { + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(canSave()); ui->keySequenceWidget->setVisible(isKeyAction(index)); ui->groupScreens->setVisible(isKeyAction(index)); ui->listScreens->setEnabled(!ui->keySequenceWidget->keySequence().isMouseButton()); @@ -133,4 +137,18 @@ bool ActionDialog::isKeyAction(int index) return ((index == ActionTypes::PressKey) || (index == ActionTypes::ReleaseKey) || (index == ActionTypes::ToggleKey)); } +bool ActionDialog::canSave() +{ + if (isKeyAction(ui->comboActionType->currentIndex())) { + const QList items = ui->listScreens->findItems("*", Qt::MatchWildcard); + int totalChecked = 0; + for (const auto &item : items) { + if (item->checkState() == Qt::Checked) + totalChecked++; + }; + return (!ui->keySequenceWidget->keySequence().toString().isEmpty() && (totalChecked > 0)); + } + return true; +} + ActionDialog::~ActionDialog() = default; diff --git a/src/apps/deskflow-gui/dialogs/ActionDialog.h b/src/apps/deskflow-gui/dialogs/ActionDialog.h index 4b7687c24..0a6c38d13 100644 --- a/src/apps/deskflow-gui/dialogs/ActionDialog.h +++ b/src/apps/deskflow-gui/dialogs/ActionDialog.h @@ -56,6 +56,7 @@ private: void keySequenceChanged(); void actionTypeChanged(int index); bool isKeyAction(int index); + bool canSave(); std::unique_ptr ui; Hotkey &m_hotkey;