2 // C++ Implementation: qtimermessagebox
7 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
9 // Copyright: See COPYING file that comes with this distribution
12 #include "qtimermessagebox.h"
13 #include <QTimerEvent>
14 #include <QPushButton>
16 QTimerMessageBox::QTimerMessageBox(QWidget
* parent
) :
17 QMessageBox(parent
), m_TimerID(-1), m_Timeout(0)
21 QTimerMessageBox::QTimerMessageBox(Icon icon
, const QString
& title
, const QString
& text
, StandardButtons buttons
, QWidget
* parent
, Qt::WindowFlags f
) :
22 QMessageBox(icon
, title
, text
, buttons
, parent
, f
), m_TimerID(-1), m_Timeout(0)
26 QTimerMessageBox::~QTimerMessageBox() {
30 void QTimerMessageBox::timerEvent(QTimerEvent
* event
) {
31 if (event
->timerId() == m_TimerID
) {
38 emit
aboutToTriggerTimeout();
39 defaultButton()->click();
44 inline void QTimerMessageBox::markDefaultButton() {
45 defaultButton()->setText(m_DefaultButtonText
+ " (" + QString::number(m_Timeout
) + ')');
48 inline void QTimerMessageBox::setTimeout(int timeout
) {
52 int QTimerMessageBox::exec(int timeout
) {
53 if (defaultButton()) {
55 m_DefaultButtonText
= defaultButton()->text();
57 m_TimerID
= startTimer(1000);
59 int result
= QMessageBox::exec();
65 return QMessageBox::exec();
68 inline QMessageBox::StandardButton
QTimerMessageBox::messagebox(QWidget
* parent
, Icon icon
, const QString
& title
, const QString
& text
, int timeout
, StandardButtons buttons
, StandardButton defaultButton
) {
69 QTimerMessageBox
messageBox(icon
, title
, text
, buttons
, parent
);
70 messageBox
.setDefaultButton(defaultButton
);
71 return (QMessageBox::StandardButton
)messageBox
.exec(timeout
);
74 QMessageBox::StandardButton
QTimerMessageBox::critical(QWidget
* parent
, const QString
& title
, const QString
& text
, int timeout
, StandardButtons buttons
, StandardButton defaultButton
) {
75 return messagebox(parent
, QMessageBox::Critical
, title
, text
, timeout
, buttons
, defaultButton
);
78 QMessageBox::StandardButton
QTimerMessageBox::information(QWidget
* parent
, const QString
& title
, const QString
& text
, int timeout
, StandardButtons buttons
, StandardButton defaultButton
) {
79 return messagebox(parent
, QMessageBox::Information
, title
, text
, timeout
, buttons
, defaultButton
);
82 QMessageBox::StandardButton
QTimerMessageBox::question(QWidget
* parent
, const QString
& title
, const QString
& text
, int timeout
, StandardButtons buttons
, StandardButton defaultButton
) {
83 return messagebox(parent
, QMessageBox::Question
, title
, text
, timeout
, buttons
, defaultButton
);
86 QMessageBox::StandardButton
QTimerMessageBox::warning(QWidget
* parent
, const QString
& title
, const QString
& text
, int timeout
, StandardButtons buttons
, StandardButton defaultButton
) {
87 return messagebox(parent
, QMessageBox::Warning
, title
, text
, timeout
, buttons
, defaultButton
);