refactor: ActionDialog: disable action saving while settings are invalid
This commit is contained in:
parent
7152119014
commit
f6dd2881c8
2 changed files with 21 additions and 2 deletions
|
|
@ -38,6 +38,9 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey &
|
||||||
connect(
|
connect(
|
||||||
ui->comboActionType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ActionDialog::actionTypeChanged
|
ui->comboActionType, QOverload<int>::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::accepted, this, &ActionDialog::accept);
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ActionDialog::reject);
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &ActionDialog::reject);
|
||||||
|
|
||||||
|
|
@ -78,8 +81,7 @@ ActionDialog::ActionDialog(QWidget *parent, const ServerConfig &config, Hotkey &
|
||||||
|
|
||||||
void ActionDialog::accept()
|
void ActionDialog::accept()
|
||||||
{
|
{
|
||||||
if (!ui->keySequenceWidget->valid() && ui->comboActionType->currentIndex() >= 0 &&
|
if (!canSave())
|
||||||
ui->comboActionType->currentIndex() < 3)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_action.setKeySequence(ui->keySequenceWidget->keySequence());
|
m_action.setKeySequence(ui->keySequenceWidget->keySequence());
|
||||||
|
|
@ -115,10 +117,12 @@ void ActionDialog::accept()
|
||||||
void ActionDialog::keySequenceChanged()
|
void ActionDialog::keySequenceChanged()
|
||||||
{
|
{
|
||||||
ui->listScreens->setEnabled(!ui->keySequenceWidget->keySequence().isMouseButton());
|
ui->listScreens->setEnabled(!ui->keySequenceWidget->keySequence().isMouseButton());
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(canSave());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionDialog::actionTypeChanged(int index)
|
void ActionDialog::actionTypeChanged(int index)
|
||||||
{
|
{
|
||||||
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(canSave());
|
||||||
ui->keySequenceWidget->setVisible(isKeyAction(index));
|
ui->keySequenceWidget->setVisible(isKeyAction(index));
|
||||||
ui->groupScreens->setVisible(isKeyAction(index));
|
ui->groupScreens->setVisible(isKeyAction(index));
|
||||||
ui->listScreens->setEnabled(!ui->keySequenceWidget->keySequence().isMouseButton());
|
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));
|
return ((index == ActionTypes::PressKey) || (index == ActionTypes::ReleaseKey) || (index == ActionTypes::ToggleKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ActionDialog::canSave()
|
||||||
|
{
|
||||||
|
if (isKeyAction(ui->comboActionType->currentIndex())) {
|
||||||
|
const QList<QListWidgetItem *> 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;
|
ActionDialog::~ActionDialog() = default;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ private:
|
||||||
void keySequenceChanged();
|
void keySequenceChanged();
|
||||||
void actionTypeChanged(int index);
|
void actionTypeChanged(int index);
|
||||||
bool isKeyAction(int index);
|
bool isKeyAction(int index);
|
||||||
|
bool canSave();
|
||||||
|
|
||||||
std::unique_ptr<Ui::ActionDialog> ui;
|
std::unique_ptr<Ui::ActionDialog> ui;
|
||||||
Hotkey &m_hotkey;
|
Hotkey &m_hotkey;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue