2 ******************************************************************************
4 * @file checkablemessagebox.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
8 * @see The GNU Public License (GPL) Version 3
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "checkablemessagebox.h"
30 #include "ui_checkablemessagebox.h"
32 #include <QPushButton>
33 #include <QtCore/QDebug>
36 struct CheckableMessageBoxPrivate
{
37 CheckableMessageBoxPrivate() : clickedButton(0) {}
39 Ui::CheckableMessageBox ui
;
40 QAbstractButton
*clickedButton
;
43 CheckableMessageBox::CheckableMessageBox(QWidget
*parent
) :
45 m_d(new CheckableMessageBoxPrivate
)
48 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint
);
49 m_d
->ui
.setupUi(this);
50 m_d
->ui
.pixmapLabel
->setVisible(false);
51 connect(m_d
->ui
.buttonBox
, SIGNAL(accepted()), this, SLOT(accept()));
52 connect(m_d
->ui
.buttonBox
, SIGNAL(rejected()), this, SLOT(reject()));
53 connect(m_d
->ui
.buttonBox
, SIGNAL(clicked(QAbstractButton
*)), this, SLOT(slotClicked(QAbstractButton
*)));
56 CheckableMessageBox::~CheckableMessageBox()
61 void CheckableMessageBox::slotClicked(QAbstractButton
*b
)
63 m_d
->clickedButton
= b
;
66 QAbstractButton
*CheckableMessageBox::clickedButton() const
68 return m_d
->clickedButton
;
71 QDialogButtonBox::StandardButton
CheckableMessageBox::clickedStandardButton() const
73 if (m_d
->clickedButton
) {
74 return m_d
->ui
.buttonBox
->standardButton(m_d
->clickedButton
);
76 return QDialogButtonBox::NoButton
;
79 QString
CheckableMessageBox::text() const
81 return m_d
->ui
.messageLabel
->text();
84 void CheckableMessageBox::setText(const QString
&t
)
86 m_d
->ui
.messageLabel
->setText(t
);
89 QPixmap
CheckableMessageBox::iconPixmap() const
91 if (const QPixmap
* p
= m_d
->ui
.pixmapLabel
->pixmap()) {
97 void CheckableMessageBox::setIconPixmap(const QPixmap
&p
)
99 m_d
->ui
.pixmapLabel
->setPixmap(p
);
100 m_d
->ui
.pixmapLabel
->setVisible(!p
.isNull());
103 bool CheckableMessageBox::isChecked() const
105 return m_d
->ui
.checkBox
->isChecked();
108 void CheckableMessageBox::setChecked(bool s
)
110 m_d
->ui
.checkBox
->setChecked(s
);
113 QString
CheckableMessageBox::checkBoxText() const
115 return m_d
->ui
.checkBox
->text();
118 void CheckableMessageBox::setCheckBoxText(const QString
&t
)
120 m_d
->ui
.checkBox
->setText(t
);
123 QDialogButtonBox::StandardButtons
CheckableMessageBox::standardButtons() const
125 return m_d
->ui
.buttonBox
->standardButtons();
128 void CheckableMessageBox::setStandardButtons(QDialogButtonBox::StandardButtons s
)
130 m_d
->ui
.buttonBox
->setStandardButtons(s
);
133 QDialogButtonBox::StandardButton
CheckableMessageBox::defaultButton() const
135 foreach(QAbstractButton
* b
, m_d
->ui
.buttonBox
->buttons())
136 if (QPushButton
* pb
= qobject_cast
<QPushButton
*>(b
)) {
137 if (pb
->isDefault()) {
138 return m_d
->ui
.buttonBox
->standardButton(pb
);
141 return QDialogButtonBox::NoButton
;
144 void CheckableMessageBox::setDefaultButton(QDialogButtonBox::StandardButton s
)
146 if (QPushButton
* b
= m_d
->ui
.buttonBox
->button(s
)) {
152 QDialogButtonBox::StandardButton
CheckableMessageBox::question(QWidget
*parent
,
153 const QString
&title
,
154 const QString
&question
,
155 const QString
&checkBoxText
,
156 bool *checkBoxSetting
,
157 QDialogButtonBox::StandardButtons buttons
,
158 QDialogButtonBox::StandardButton defaultButton
)
160 CheckableMessageBox
mb(parent
);
162 mb
.setWindowTitle(title
);
163 mb
.setIconPixmap(QMessageBox::standardIcon(QMessageBox::Question
));
164 mb
.setText(question
);
165 mb
.setCheckBoxText(checkBoxText
);
166 mb
.setChecked(*checkBoxSetting
);
167 mb
.setStandardButtons(buttons
);
168 mb
.setDefaultButton(defaultButton
);
170 *checkBoxSetting
= mb
.isChecked();
171 return mb
.clickedStandardButton();
174 QMessageBox::StandardButton
CheckableMessageBox::dialogButtonBoxToMessageBoxButton(QDialogButtonBox::StandardButton db
)
176 return static_cast<QMessageBox::StandardButton
>(int(db
));