Use QDialogButtonBox in KMessageWidget

QDialogButtonBox can auto-choose the order of the actions based on the
current interfaces guidelines, but in this case its a guessing game.

It does a half-decent job off guessing.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2014-07-02 22:59:32 +02:00 committed by Dirk Hohndel
parent c16d4ca5d5
commit 77a55db9d3

View file

@ -21,7 +21,7 @@
#include <QEvent> #include <QEvent>
#include <QGridLayout> #include <QGridLayout>
#include <QHBoxLayout> #include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QPainter> #include <QPainter>
#include <QShowEvent> #include <QShowEvent>
@ -92,27 +92,32 @@ void KMessageWidgetPrivate::createLayout()
layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop); layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
layout->addWidget(textLabel, 0, 1); layout->addWidget(textLabel, 0, 1);
QHBoxLayout *buttonLayout = new QHBoxLayout; QDialogButtonBox *buttonLayout = new QDialogButtonBox();
buttonLayout->addStretch(); //buttonLayout->addStretch();
Q_FOREACH (QToolButton *button, buttons) { Q_FOREACH (QToolButton *button, buttons) {
// For some reason, calling show() is necessary if wordwrap is true, // For some reason, calling show() is necessary if wordwrap is true,
// otherwise the buttons do not show up. It is not needed if // otherwise the buttons do not show up. It is not needed if
// wordwrap is false. // wordwrap is false.
button->show(); button->show();
buttonLayout->addWidget(button); buttonLayout->addButton(button, QDialogButtonBox::QDialogButtonBox::AcceptRole);
} }
buttonLayout->addWidget(closeButton); buttonLayout->addButton(closeButton, QDialogButtonBox::RejectRole);
layout->addItem(buttonLayout, 1, 0, 1, 2); layout->addWidget(buttonLayout, 1, 0, 1, 2, Qt::AlignHCenter | Qt::AlignTop);
} else { } else {
bool closeButtonVisible = closeButton->isVisible();
QHBoxLayout *layout = new QHBoxLayout(content); QHBoxLayout *layout = new QHBoxLayout(content);
layout->addWidget(iconLabel); layout->addWidget(iconLabel);
layout->addWidget(textLabel); layout->addWidget(textLabel);
QDialogButtonBox *buttonLayout = new QDialogButtonBox();
Q_FOREACH (QToolButton *button, buttons) { Q_FOREACH (QToolButton *button, buttons) {
layout->addWidget(button); buttonLayout->addButton(button, QDialogButtonBox::QDialogButtonBox::AcceptRole);
} }
layout->addWidget(closeButton); buttonLayout->addButton(closeButton, QDialogButtonBox::RejectRole);
// Something gets changed when added to the buttonLayout
closeButton->setVisible(closeButtonVisible);
layout->addWidget(buttonLayout);
}; };
if (q->isVisible()) { if (q->isVisible()) {