2010-01-04 11:36:55 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-01-04 11:36:55 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2009-06-19 16:34:38 +02:00
|
|
|
#include "checkablemessagebox.h"
|
|
|
|
|
#include "ui_checkablemessagebox.h"
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
2011-03-02 17:13:33 +01:00
|
|
|
/*!
|
|
|
|
|
\class Utils::CheckableMessageBox
|
|
|
|
|
|
|
|
|
|
\brief A messagebox 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-06-19 16:34:38 +02:00
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
struct CheckableMessageBoxPrivate {
|
|
|
|
|
CheckableMessageBoxPrivate() : clickedButton(0) {}
|
|
|
|
|
|
|
|
|
|
Ui::CheckableMessageBox ui;
|
|
|
|
|
QAbstractButton *clickedButton;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CheckableMessageBox::CheckableMessageBox(QWidget *parent) :
|
|
|
|
|
QDialog(parent),
|
2011-09-07 14:26:11 +02:00
|
|
|
d(new CheckableMessageBoxPrivate)
|
2009-06-19 16:34:38 +02:00
|
|
|
{
|
|
|
|
|
setModal(true);
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.setupUi(this);
|
|
|
|
|
d->ui.pixmapLabel->setVisible(false);
|
|
|
|
|
connect(d->ui.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
|
connect(d->ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
|
connect(d->ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotClicked(QAbstractButton*)));
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckableMessageBox::~CheckableMessageBox()
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
delete d;
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::slotClicked(QAbstractButton *b)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->clickedButton = b;
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAbstractButton *CheckableMessageBox::clickedButton() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->clickedButton;
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDialogButtonBox::StandardButton CheckableMessageBox::clickedStandardButton() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
if (d->clickedButton)
|
|
|
|
|
return d->ui.buttonBox->standardButton(d->clickedButton);
|
2009-06-19 16:34:38 +02:00
|
|
|
return QDialogButtonBox::NoButton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CheckableMessageBox::text() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.messageLabel->text();
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setText(const QString &t)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.messageLabel->setText(t);
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPixmap CheckableMessageBox::iconPixmap() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
if (const QPixmap *p = d->ui.pixmapLabel->pixmap())
|
2009-06-19 16:34:38 +02:00
|
|
|
return QPixmap(*p);
|
|
|
|
|
return QPixmap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setIconPixmap(const QPixmap &p)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.pixmapLabel->setPixmap(p);
|
|
|
|
|
d->ui.pixmapLabel->setVisible(!p.isNull());
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CheckableMessageBox::isChecked() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.checkBox->isChecked();
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setChecked(bool s)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.checkBox->setChecked(s);
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CheckableMessageBox::checkBoxText() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.checkBox->text();
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setCheckBoxText(const QString &t)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.checkBox->setText(t);
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
bool CheckableMessageBox::isCheckBoxVisible() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.checkBox->isVisible();
|
2011-01-17 13:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setCheckBoxVisible(bool v)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.checkBox->setVisible(v);
|
2011-01-17 13:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-19 16:34:38 +02:00
|
|
|
QDialogButtonBox::StandardButtons CheckableMessageBox::standardButtons() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.buttonBox->standardButtons();
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->ui.buttonBox->setStandardButtons(s);
|
2009-06-19 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
QPushButton *CheckableMessageBox::button(QDialogButtonBox::StandardButton b) const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.buttonBox->button(b);
|
2011-01-17 13:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPushButton *CheckableMessageBox::addButton(const QString &text, QDialogButtonBox::ButtonRole role)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.buttonBox->addButton(text, role);
|
2011-01-17 13:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-19 16:34:38 +02:00
|
|
|
QDialogButtonBox::StandardButton CheckableMessageBox::defaultButton() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
foreach (QAbstractButton *b, d->ui.buttonBox->buttons())
|
2009-06-19 16:34:38 +02:00
|
|
|
if (QPushButton *pb = qobject_cast<QPushButton *>(b))
|
|
|
|
|
if (pb->isDefault())
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->ui.buttonBox->standardButton(pb);
|
2009-06-19 16:34:38 +02:00
|
|
|
return QDialogButtonBox::NoButton;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
if (QPushButton *b = d->ui.buttonBox->button(s)) {
|
2009-06-19 16:34:38 +02: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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMessageBox::StandardButton CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<QMessageBox::StandardButton>(int(db));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Utils
|