gcc 4.4 build fix
[qbat.git] / qtimermessagebox.cpp
blobf166dbdd925c0ac945b5adf19cb4b15024a35334
1 //
2 // C++ Implementation: qtimermessagebox
3 //
4 // Description:
5 //
6 //
7 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
8 //
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() {
27 killTimer(m_TimerID);
30 void QTimerMessageBox::timerEvent(QTimerEvent * event) {
31 if (event->timerId() == m_TimerID) {
32 if (m_Timeout > 0) {
33 markDefaultButton();
34 m_Timeout--;
36 else {
37 killTimer(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) {
49 m_Timeout = timeout;
52 int QTimerMessageBox::exec(int timeout) {
53 if (defaultButton() && timeout > 0) {
54 setTimeout(timeout);
55 m_DefaultButtonText = defaultButton()->text();
57 m_TimerID = startTimer(1000);
59 int result = QMessageBox::exec();
61 killTimer(m_TimerID);
62 return result;
64 else
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);