20 #include <QAbstractButton>
21 #include <QApplication>
23 #include <QHBoxLayout>
25 #include <QLatin1String>
26 #include <QPushButton>
29 #include <QSizePolicy>
30 #include <QSpacerItem>
31 #include <QVBoxLayout>
56 QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
59 sizePolicy.setHorizontalStretch(0);
60 sizePolicy.setVerticalStretch(0);
61 sizePolicy.setHeightForWidth(
pixmapLabel->sizePolicy().hasHeightForWidth());
65 QSpacerItem *pixmapSpacer =
new QSpacerItem(0, 5, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
71 messageLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse);
73 QSpacerItem *checkBoxRightSpacer =
new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
74 QSpacerItem *buttonSpacer =
new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::Minimum);
77 checkBox->setText(CheckableMessageBox::tr(
"Do not ask again"));
80 buttonBox->setOrientation(Qt::Horizontal);
81 buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
83 QVBoxLayout *verticalLayout =
new QVBoxLayout();
85 verticalLayout->addItem(pixmapSpacer);
87 QHBoxLayout *horizontalLayout_2 =
new QHBoxLayout();
88 horizontalLayout_2->addLayout(verticalLayout);
91 QHBoxLayout *horizontalLayout =
new QHBoxLayout();
92 horizontalLayout->addWidget(
checkBox);
93 horizontalLayout->addItem(checkBoxRightSpacer);
95 QVBoxLayout *verticalLayout_2 =
new QVBoxLayout(q);
96 verticalLayout_2->addLayout(horizontalLayout_2);
97 verticalLayout_2->addLayout(horizontalLayout);
98 verticalLayout_2->addItem(buttonSpacer);
116 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
117 connect(
d->
buttonBox, SIGNAL(accepted()), SLOT(accept()));
118 connect(
d->
buttonBox, SIGNAL(rejected()), SLOT(reject()));
143 return QDialogButtonBox::NoButton;
223 foreach (QAbstractButton *b,
d->
buttonBox->buttons())
224 if (QPushButton *pb = qobject_cast<QPushButton *>(b))
231 return QDialogButtonBox::NoButton;
243 QDialogButtonBox::StandardButton
245 const QString &title,
246 const QString &question,
247 const QString &checkBoxText,
248 bool *checkBoxSetting,
249 QDialogButtonBox::StandardButtons buttons,
250 QDialogButtonBox::StandardButton defaultButton)
253 mb.setWindowTitle(title);
254 mb.
setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
265 QDialogButtonBox::StandardButton
267 const QString &title,
269 const QString &checkBoxText,
270 bool *checkBoxSetting,
271 QDialogButtonBox::StandardButtons buttons,
272 QDialogButtonBox::StandardButton defaultButton)
275 mb.setWindowTitle(title);
276 mb.
setIconPixmap(QMessageBox::standardIcon(QMessageBox::Information));
290 return static_cast<QMessageBox::StandardButton
>(int(db));
299 bool shouldNotAsk = settings->value(settingsSubKey,
false).toBool();
300 settings->endGroup();
310 const QString &text, QDialogButtonBox::StandardButtons buttons,
311 QDialogButtonBox::StandardButton defaultButton,
314 messageBox.setWindowTitle(title);
316 ? QMessageBox::Information
317 : QMessageBox::Question));
335 settings->setValue(settingsSubKey,
true);
336 settings->endGroup();
348 QDialogButtonBox::StandardButton
351 const QString &text, QSettings *settings,
352 const QString &settingsSubKey,
353 QDialogButtonBox::StandardButtons buttons,
354 QDialogButtonBox::StandardButton defaultButton,
355 QDialogButtonBox::StandardButton acceptButton)
358 if (!
askAgain(settings, settingsSubKey))
382 QDialogButtonBox::StandardButton
385 const QString &text, QSettings *settings,
386 const QString &settingsSubKey,
387 QDialogButtonBox::StandardButtons buttons,
388 QDialogButtonBox::StandardButton defaultButton)
391 if (!
askAgain(settings, settingsSubKey))
416 settings->remove(QString());
417 settings->endGroup();
428 bool hasSuppressed =
false;
430 foreach (
const QString &subKey, settings->childKeys())
432 if (settings->value(subKey,
false).toBool())
434 hasSuppressed =
true;
438 settings->endGroup();
439 return hasSuppressed;
static const char kDoNotAskAgainKey[]
QDialogButtonBox * buttonBox
CheckableMessageBoxPrivate(QDialog *q)
QAbstractButton * clickedButton
The CheckableMessageBox class implements a message box suitable for questions with a "Do not ask me a...
static QDialogButtonBox::StandardButton doNotAskAgainQuestion(QWidget *parent, const QString &title, const QString &text, QSettings *settings, const QString &settingsSubKey, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Yes|QDialogButtonBox::No, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::No, QDialogButtonBox::StandardButton acceptButton=QDialogButtonBox::Yes)
Shows a message box with given title and text, and a \gui {Do not ask again} check box.
static QMessageBox::StandardButton dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton)
static QString msgDoNotShowAgain()
Returns the standard \gui {Do not show again} check box text.
CheckableMessageBoxPrivate * d
QDialogButtonBox::StandardButtons buttons
QPushButton * button(QDialogButtonBox::StandardButton b) const
virtual ~CheckableMessageBox() Q_DECL_OVERRIDE
void setStandardButtons(QDialogButtonBox::StandardButtons s)
void slotClicked(QAbstractButton *b)
static void doNotAskAgain(QSettings *settings, const QString &settingsSubKey)
static void resetAllDoNotAskAgainQuestions(QSettings *settings)
Resets all suppression settings for doNotAskAgainQuestion() found in settings, so all these message b...
QDialogButtonBox::StandardButton clickedStandardButton() const
static QDialogButtonBox::StandardButton doNotShowAgainInformation(QWidget *parent, const QString &title, const QString &text, QSettings *settings, const QString &settingsSubKey, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::NoButton)
Shows a message box with given title and text, and a \gui {Do not show again} check box.
void setCheckBoxText(const QString &)
static void initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString &title, const QString &text, QDialogButtonBox::StandardButtons buttons, QDialogButtonBox::StandardButton defaultButton, DoNotAskAgainType type)
static bool hasSuppressedQuestions(QSettings *settings)
Returns whether any message boxes from doNotAskAgainQuestion() are suppressed in the settings.
void setText(const QString &)
void setCheckBoxVisible(bool)
static bool askAgain(QSettings *settings, const QString &settingsSubKey)
CheckableMessageBox(QWidget *parent)
bool isCheckBoxVisible() const
void setIconPixmap(const QPixmap &p)
static QString msgDoNotAskAgain()
Returns the standard \gui {Do not ask again} check box text.
QDialogButtonBox::StandardButtons standardButtons() const
static QDialogButtonBox::StandardButton question(QWidget *parent, const QString &title, const QString &question, const QString &checkBoxText, bool *checkBoxSetting, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Yes|QDialogButtonBox::No, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::No)
QDialogButtonBox::StandardButton defaultButton
QPushButton * addButton(const QString &text, QDialogButtonBox::ButtonRole role)
QAbstractButton * clickedButton() const
void setDefaultButton(QDialogButtonBox::StandardButton s)
static QDialogButtonBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, const QString &checkBoxText, bool *checkBoxSetting, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Ok, QDialogButtonBox::StandardButton defaultButton=QDialogButtonBox::NoButton)
#define translate(context, source)