Make dialogy widget work with arbitrary buttons in button boxes.

This commit is contained in:
Florian Geyer 2012-04-24 21:56:00 +02:00 committed by Felix Geyer
parent 5ce9b5da78
commit 7a3a783eeb
2 changed files with 12 additions and 21 deletions

View File

@ -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<QPushButton*>(focusWidget());
if (pb && pb->isVisible() && pb->isEnabled() && pb->hasFocus()) {
pb->click();
return true;
}
QList<QDialogButtonBox*> buttonBoxes = findChildren<QDialogButtonBox*>();
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;
}

View File

@ -32,7 +32,7 @@ protected:
virtual void keyPressEvent(QKeyEvent *e);
private:
bool clickButton(QDialogButtonBox::StandardButton button);
bool clickButton(QDialogButtonBox::StandardButton standardButton);
};