diff --git a/src/gui/DialogyWidget.cpp b/src/gui/DialogyWidget.cpp index 33172d971..9cb038e7f 100644 --- a/src/gui/DialogyWidget.cpp +++ b/src/gui/DialogyWidget.cpp @@ -59,32 +59,23 @@ void DialogyWidget::keyPressEvent(QKeyEvent *e) } } -bool DialogyWidget::clickButton(QDialogButtonBox::StandardButton button) +bool DialogyWidget::clickButton(QDialogButtonBox::StandardButton standardButton) { - Q_ASSERT(button == QDialogButtonBox::Ok || button == QDialogButtonBox::Cancel); + QPushButton* pb = qobject_cast(focusWidget()); + if (pb && pb->isVisible() && pb->isEnabled() && pb->hasFocus()) { + pb->click(); + return true; + } QList buttonBoxes = findChildren(); for (int i = 0; i < buttonBoxes.size(); ++i) { QDialogButtonBox* buttonBox = buttonBoxes.at(i); - QPushButton* pb; - QPushButton* pbCancel = buttonBox->button(QDialogButtonBox::Cancel); - if (button == QDialogButtonBox::Ok) { - if (pbCancel && pbCancel->isVisible() && pbCancel->isEnabled() && pbCancel->hasFocus()) { - pbCancel->click(); - return true; - } - pb = buttonBox->button(button); - } - else { - pb = pbCancel; - } - - if (pb) { - if (pb->isVisible() && pb->isEnabled()) { - pb->click(); - return true; - } + pb = buttonBox->button(standardButton); + if (pb && pb->isVisible() && pb->isEnabled()) { + pb->click(); + return true; } } + return false; } diff --git a/src/gui/DialogyWidget.h b/src/gui/DialogyWidget.h index f5f8d2d13..0501c849e 100644 --- a/src/gui/DialogyWidget.h +++ b/src/gui/DialogyWidget.h @@ -32,7 +32,7 @@ protected: virtual void keyPressEvent(QKeyEvent *e); private: - bool clickButton(QDialogButtonBox::StandardButton button); + bool clickButton(QDialogButtonBox::StandardButton standardButton); };