2015-02-25 23:27:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
2015-02-26 22:34:33 +01:00
|
|
|
** All rights reserved. This program and the accompanying materials are made
|
|
|
|
** available under the terms of the GNU Lesser General Public License (LGPL)
|
|
|
|
** version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
2015-02-25 23:27:09 +01:00
|
|
|
**
|
2015-02-26 22:34:33 +01:00
|
|
|
** This library is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
** for more details.
|
2015-02-25 23:27:09 +01:00
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "checkablemessagebox.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QAbstractButton>
|
2015-02-25 23:27:09 +01:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QLatin1String>
|
2015-02-25 23:27:09 +01:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QSettings>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QSize>
|
|
|
|
#include <QSizePolicy>
|
|
|
|
#include <QSpacerItem>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <Qt>
|
|
|
|
|
2015-03-16 13:23:02 +01:00
|
|
|
static const char kDoNotAskAgainKey[] = "DoNotAskAgain";
|
|
|
|
|
|
|
|
namespace Utils
|
|
|
|
{
|
|
|
|
|
2015-02-25 23:27:09 +01:00
|
|
|
/*!
|
2015-03-16 13:23:02 +01:00
|
|
|
\class CheckableMessageBox
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
\brief The CheckableMessageBox class implements a message box suitable for
|
|
|
|
questions with a
|
|
|
|
"Do not ask me again" checkbox.
|
|
|
|
|
|
|
|
Emulates the QMessageBox API with
|
|
|
|
static conveniences. The message label can open external URLs.
|
|
|
|
*/
|
|
|
|
class CheckableMessageBoxPrivate
|
|
|
|
{
|
|
|
|
public:
|
2015-10-12 13:52:48 +02:00
|
|
|
explicit CheckableMessageBoxPrivate(QDialog *q)
|
2015-03-03 16:29:33 +01:00
|
|
|
: pixmapLabel(nullptr), messageLabel(nullptr), checkBox(nullptr), buttonBox(nullptr), clickedButton(nullptr)
|
2015-02-25 23:27:09 +01:00
|
|
|
{
|
|
|
|
QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
|
|
|
|
|
|
|
pixmapLabel = new QLabel(q);
|
|
|
|
sizePolicy.setHorizontalStretch(0);
|
|
|
|
sizePolicy.setVerticalStretch(0);
|
|
|
|
sizePolicy.setHeightForWidth(pixmapLabel->sizePolicy().hasHeightForWidth());
|
|
|
|
pixmapLabel->setSizePolicy(sizePolicy);
|
|
|
|
pixmapLabel->setVisible(false);
|
|
|
|
|
2015-03-16 13:23:02 +01:00
|
|
|
QSpacerItem *pixmapSpacer = new QSpacerItem(0, 5, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
messageLabel = new QLabel(q);
|
|
|
|
messageLabel->setMinimumSize(QSize(300, 0));
|
|
|
|
messageLabel->setWordWrap(true);
|
|
|
|
messageLabel->setOpenExternalLinks(true);
|
|
|
|
messageLabel->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse);
|
|
|
|
|
2015-03-16 13:23:02 +01:00
|
|
|
QSpacerItem *checkBoxRightSpacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
QSpacerItem *buttonSpacer = new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::Minimum);
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
checkBox = new QCheckBox(q);
|
|
|
|
checkBox->setText(CheckableMessageBox::tr("Do not ask again"));
|
|
|
|
|
|
|
|
buttonBox = new QDialogButtonBox(q);
|
|
|
|
buttonBox->setOrientation(Qt::Horizontal);
|
|
|
|
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout = new QVBoxLayout();
|
|
|
|
verticalLayout->addWidget(pixmapLabel);
|
|
|
|
verticalLayout->addItem(pixmapSpacer);
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout_2 = new QHBoxLayout();
|
|
|
|
horizontalLayout_2->addLayout(verticalLayout);
|
|
|
|
horizontalLayout_2->addWidget(messageLabel);
|
|
|
|
|
|
|
|
QHBoxLayout *horizontalLayout = new QHBoxLayout();
|
|
|
|
horizontalLayout->addWidget(checkBox);
|
|
|
|
horizontalLayout->addItem(checkBoxRightSpacer);
|
|
|
|
|
|
|
|
QVBoxLayout *verticalLayout_2 = new QVBoxLayout(q);
|
|
|
|
verticalLayout_2->addLayout(horizontalLayout_2);
|
|
|
|
verticalLayout_2->addLayout(horizontalLayout);
|
|
|
|
verticalLayout_2->addItem(buttonSpacer);
|
|
|
|
verticalLayout_2->addWidget(buttonBox);
|
|
|
|
}
|
|
|
|
|
|
|
|
QLabel *pixmapLabel;
|
|
|
|
QLabel *messageLabel;
|
|
|
|
QCheckBox *checkBox;
|
|
|
|
QDialogButtonBox *buttonBox;
|
|
|
|
QAbstractButton *clickedButton;
|
2015-03-03 16:29:33 +01:00
|
|
|
private:
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_DISABLE_COPY_MOVE(CheckableMessageBoxPrivate) // NOLINT
|
2015-02-25 23:27:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
d(new CheckableMessageBoxPrivate(this))
|
|
|
|
{
|
|
|
|
setModal(true);
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
connect(d->buttonBox, SIGNAL(accepted()), SLOT(accept()));
|
|
|
|
connect(d->buttonBox, SIGNAL(rejected()), SLOT(reject()));
|
2015-03-16 13:23:02 +01:00
|
|
|
connect(d->buttonBox, SIGNAL(clicked(QAbstractButton*)), SLOT(slotClicked(QAbstractButton*)));
|
2015-02-25 23:27:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CheckableMessageBox::~CheckableMessageBox()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::slotClicked(QAbstractButton *b)
|
|
|
|
{
|
|
|
|
d->clickedButton = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAbstractButton *CheckableMessageBox::clickedButton() const
|
|
|
|
{
|
|
|
|
return d->clickedButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton CheckableMessageBox::clickedStandardButton() const
|
|
|
|
{
|
|
|
|
if (d->clickedButton)
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return d->buttonBox->standardButton(d->clickedButton);
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
return QDialogButtonBox::NoButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CheckableMessageBox::text() const
|
|
|
|
{
|
|
|
|
return d->messageLabel->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setText(const QString &t)
|
|
|
|
{
|
|
|
|
d->messageLabel->setText(t);
|
|
|
|
}
|
|
|
|
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
QPixmap CheckableMessageBox::iconPixmap() const
|
|
|
|
{
|
2020-07-06 14:37:41 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
2020-07-06 15:35:54 +02:00
|
|
|
if (const QPixmap *p = d->pixmapLabel->pixmap())
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return QPixmap(*p);
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
return QPixmap();
|
2020-07-06 08:41:08 +02:00
|
|
|
#else
|
2020-07-06 15:35:54 +02:00
|
|
|
return d->pixmapLabel->pixmap(Qt::ReturnByValue);
|
2020-07-06 08:41:08 +02:00
|
|
|
#endif
|
2015-02-25 23:27:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
|
|
|
|
{
|
|
|
|
d->pixmapLabel->setPixmap(p);
|
|
|
|
d->pixmapLabel->setVisible(!p.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckableMessageBox::isChecked() const
|
|
|
|
{
|
|
|
|
return d->checkBox->isChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setChecked(bool s)
|
|
|
|
{
|
|
|
|
d->checkBox->setChecked(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CheckableMessageBox::checkBoxText() const
|
|
|
|
{
|
|
|
|
return d->checkBox->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setCheckBoxText(const QString &t)
|
|
|
|
{
|
|
|
|
d->checkBox->setText(t);
|
|
|
|
}
|
|
|
|
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
bool CheckableMessageBox::isCheckBoxVisible() const
|
|
|
|
{
|
|
|
|
return d->checkBox->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setCheckBoxVisible(bool v)
|
|
|
|
{
|
|
|
|
d->checkBox->setVisible(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButtons CheckableMessageBox::standardButtons() const
|
|
|
|
{
|
|
|
|
return d->buttonBox->standardButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s)
|
|
|
|
{
|
|
|
|
d->buttonBox->setStandardButtons(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton *CheckableMessageBox::button(QDialogButtonBox::StandardButton b) const
|
|
|
|
{
|
|
|
|
return d->buttonBox->button(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton *CheckableMessageBox::addButton(const QString &text, QDialogButtonBox::ButtonRole role)
|
|
|
|
{
|
|
|
|
return d->buttonBox->addButton(text, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton CheckableMessageBox::defaultButton() const
|
|
|
|
{
|
2018-04-03 10:15:58 +02:00
|
|
|
const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
|
|
|
|
for (auto b : buttons)
|
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
if (pb->isDefault())
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return d->buttonBox->standardButton(pb);
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-03 10:15:58 +02:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
return QDialogButtonBox::NoButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s)
|
|
|
|
{
|
2015-03-02 18:11:43 +01:00
|
|
|
if (QPushButton *b = d->buttonBox->button(s))
|
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
b->setDefault(true);
|
|
|
|
b->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton
|
|
|
|
CheckableMessageBox::question(QWidget *parent,
|
|
|
|
const QString &title,
|
|
|
|
const QString &question,
|
|
|
|
const QString &checkBoxText,
|
|
|
|
bool *checkBoxSetting,
|
|
|
|
QDialogButtonBox::StandardButtons buttons,
|
|
|
|
QDialogButtonBox::StandardButton defaultButton)
|
|
|
|
{
|
|
|
|
CheckableMessageBox mb(parent);
|
|
|
|
mb.setWindowTitle(title);
|
|
|
|
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question));
|
|
|
|
mb.setText(question);
|
|
|
|
mb.setCheckBoxText(checkBoxText);
|
|
|
|
mb.setChecked(*checkBoxSetting);
|
|
|
|
mb.setStandardButtons(buttons);
|
|
|
|
mb.setDefaultButton(defaultButton);
|
|
|
|
mb.exec();
|
|
|
|
*checkBoxSetting = mb.isChecked();
|
|
|
|
return mb.clickedStandardButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton
|
|
|
|
CheckableMessageBox::information(QWidget *parent,
|
|
|
|
const QString &title,
|
|
|
|
const QString &text,
|
|
|
|
const QString &checkBoxText,
|
|
|
|
bool *checkBoxSetting,
|
|
|
|
QDialogButtonBox::StandardButtons buttons,
|
|
|
|
QDialogButtonBox::StandardButton defaultButton)
|
|
|
|
{
|
|
|
|
CheckableMessageBox mb(parent);
|
|
|
|
mb.setWindowTitle(title);
|
|
|
|
mb.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Information));
|
|
|
|
mb.setText(text);
|
|
|
|
mb.setCheckBoxText(checkBoxText);
|
|
|
|
mb.setChecked(*checkBoxSetting);
|
|
|
|
mb.setStandardButtons(buttons);
|
|
|
|
mb.setDefaultButton(defaultButton);
|
|
|
|
mb.exec();
|
|
|
|
*checkBoxSetting = mb.isChecked();
|
|
|
|
return mb.clickedStandardButton();
|
|
|
|
}
|
|
|
|
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db)
|
|
|
|
{
|
|
|
|
return static_cast<QMessageBox::StandardButton>(int(db));
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:23:02 +01:00
|
|
|
bool CheckableMessageBox::askAgain(QSettings *settings, const QString &settingsSubKey)
|
2015-02-25 23:27:09 +01:00
|
|
|
{
|
|
|
|
//QTC_CHECK(settings);
|
2015-03-02 18:11:43 +01:00
|
|
|
if (settings)
|
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
|
|
|
bool shouldNotAsk = settings->value(settingsSubKey, false).toBool();
|
|
|
|
settings->endGroup();
|
|
|
|
if (shouldNotAsk)
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return false;
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:23:02 +01:00
|
|
|
void CheckableMessageBox::initDoNotAskAgainMessageBox(CheckableMessageBox &messageBox, const QString &title,
|
|
|
|
const QString &text, QDialogButtonBox::StandardButtons buttons,
|
|
|
|
QDialogButtonBox::StandardButton defaultButton,
|
|
|
|
DoNotAskAgainType type)
|
2015-02-25 23:27:09 +01:00
|
|
|
{
|
|
|
|
messageBox.setWindowTitle(title);
|
|
|
|
messageBox.setIconPixmap(QMessageBox::standardIcon(type == Information
|
|
|
|
? QMessageBox::Information
|
|
|
|
: QMessageBox::Question));
|
|
|
|
messageBox.setText(text);
|
|
|
|
messageBox.setCheckBoxVisible(true);
|
|
|
|
messageBox.setCheckBoxText(type == Information ? CheckableMessageBox::msgDoNotShowAgain()
|
|
|
|
: CheckableMessageBox::msgDoNotAskAgain());
|
|
|
|
messageBox.setChecked(false);
|
|
|
|
messageBox.setStandardButtons(buttons);
|
|
|
|
messageBox.setDefaultButton(defaultButton);
|
|
|
|
}
|
|
|
|
|
2015-03-16 13:23:02 +01:00
|
|
|
void CheckableMessageBox::doNotAskAgain(QSettings *settings, const QString &settingsSubKey)
|
2015-02-25 23:27:09 +01:00
|
|
|
{
|
|
|
|
if (!settings)
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return;
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
|
|
|
settings->setValue(settingsSubKey, true);
|
|
|
|
settings->endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Shows a message box with given \a title and \a text, and a \gui {Do not ask again} check box.
|
|
|
|
If the user checks the check box and accepts the dialog with the \a acceptButton,
|
|
|
|
further invocations of this function with the same \a settings and \a settingsSubKey will not
|
|
|
|
show the dialog, but instantly return \a acceptButton.
|
|
|
|
|
|
|
|
Returns the clicked button, or QDialogButtonBox::NoButton if the user rejects the dialog
|
|
|
|
with the escape key, or \a acceptButton if the dialog is suppressed.
|
|
|
|
*/
|
|
|
|
QDialogButtonBox::StandardButton
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
CheckableMessageBox::doNotAskAgainQuestion(QWidget *parent, const QString &title,
|
|
|
|
const QString &text, QSettings *settings,
|
|
|
|
const QString &settingsSubKey,
|
|
|
|
QDialogButtonBox::StandardButtons buttons,
|
|
|
|
QDialogButtonBox::StandardButton defaultButton,
|
|
|
|
QDialogButtonBox::StandardButton acceptButton)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (!askAgain(settings, settingsSubKey))
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return acceptButton;
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
CheckableMessageBox messageBox(parent);
|
|
|
|
initDoNotAskAgainMessageBox(messageBox, title, text, buttons, defaultButton, Question);
|
|
|
|
messageBox.exec();
|
|
|
|
if (messageBox.isChecked() && (messageBox.clickedStandardButton() == acceptButton))
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
doNotAskAgain(settings, settingsSubKey);
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
return messageBox.clickedStandardButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Shows a message box with given \a title and \a text, and a \gui {Do not show again} check box.
|
|
|
|
If the user checks the check box and quits the dialog, further invocations of this
|
|
|
|
function with the same \a settings and \a settingsSubKey will not show the dialog, but instantly return.
|
|
|
|
|
|
|
|
Returns the clicked button, or QDialogButtonBox::NoButton if the user rejects the dialog
|
|
|
|
with the escape key, or \a defaultButton if the dialog is suppressed.
|
|
|
|
*/
|
|
|
|
QDialogButtonBox::StandardButton
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
CheckableMessageBox::doNotShowAgainInformation(QWidget *parent, const QString &title,
|
|
|
|
const QString &text, QSettings *settings,
|
|
|
|
const QString &settingsSubKey,
|
|
|
|
QDialogButtonBox::StandardButtons buttons,
|
|
|
|
QDialogButtonBox::StandardButton defaultButton)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (!askAgain(settings, settingsSubKey))
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
return defaultButton;
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
CheckableMessageBox messageBox(parent);
|
|
|
|
initDoNotAskAgainMessageBox(messageBox, title, text, buttons, defaultButton, Information);
|
|
|
|
messageBox.exec();
|
|
|
|
if (messageBox.isChecked())
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
doNotAskAgain(settings, settingsSubKey);
|
2015-03-02 18:11:43 +01:00
|
|
|
}
|
2015-02-25 23:27:09 +01:00
|
|
|
|
|
|
|
return messageBox.clickedStandardButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Resets all suppression settings for doNotAskAgainQuestion() found in \a settings,
|
|
|
|
so all these message boxes are shown again.
|
|
|
|
*/
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
void CheckableMessageBox::resetAllDoNotAskAgainQuestions(QSettings *settings)
|
|
|
|
{
|
|
|
|
//Q_ASSERT(settings, return);
|
|
|
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
|
|
|
settings->remove(QString());
|
|
|
|
settings->endGroup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns whether any message boxes from doNotAskAgainQuestion() are suppressed
|
|
|
|
in the \a settings.
|
|
|
|
*/
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-02-25 23:27:09 +01:00
|
|
|
bool CheckableMessageBox::hasSuppressedQuestions(QSettings *settings)
|
|
|
|
{
|
|
|
|
//Q_ASSERT(settings, return false);
|
|
|
|
bool hasSuppressed = false;
|
|
|
|
settings->beginGroup(QLatin1String(kDoNotAskAgainKey));
|
2018-04-03 10:15:58 +02:00
|
|
|
for (auto &subKey : settings->childKeys())
|
2015-03-02 18:11:43 +01:00
|
|
|
{
|
|
|
|
if (settings->value(subKey, false).toBool())
|
|
|
|
{
|
2015-02-25 23:27:09 +01:00
|
|
|
hasSuppressed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings->endGroup();
|
|
|
|
return hasSuppressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the standard \gui {Do not ask again} check box text.
|
|
|
|
\sa doNotAskAgainQuestion()
|
|
|
|
*/
|
|
|
|
QString CheckableMessageBox::msgDoNotAskAgain()
|
|
|
|
{
|
|
|
|
return QApplication::translate("Utils::CheckableMessageBox", "Do not &ask again");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns the standard \gui {Do not show again} check box text.
|
|
|
|
\sa doNotShowAgainInformation()
|
|
|
|
*/
|
|
|
|
QString CheckableMessageBox::msgDoNotShowAgain()
|
|
|
|
{
|
|
|
|
return QApplication::translate("Utils::CheckableMessageBox", "Do not &show again");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Utils
|