| 1 | /****************************************************************************
 | 
|---|
| 2 | ** $Id: qmessagebox.h 2 2005-11-16 15:49:26Z dmik $
 | 
|---|
| 3 | **
 | 
|---|
| 4 | ** Definition of QMessageBox class
 | 
|---|
| 5 | **
 | 
|---|
| 6 | ** Created : 950503
 | 
|---|
| 7 | **
 | 
|---|
| 8 | ** Copyright (C) 1992-2002 Trolltech AS.  All rights reserved.
 | 
|---|
| 9 | **
 | 
|---|
| 10 | ** This file is part of the dialogs module of the Qt GUI Toolkit.
 | 
|---|
| 11 | **
 | 
|---|
| 12 | ** This file may be distributed under the terms of the Q Public License
 | 
|---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
 | 
|---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
 | 
|---|
| 15 | **
 | 
|---|
| 16 | ** This file may be distributed and/or modified under the terms of the
 | 
|---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
 | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
 | 
|---|
| 19 | ** packaging of this file.
 | 
|---|
| 20 | **
 | 
|---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
 | 
|---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
 | 
|---|
| 23 | ** Agreement provided with the Software.
 | 
|---|
| 24 | **
 | 
|---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 | 
|---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 | 
|---|
| 27 | **
 | 
|---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 | 
|---|
| 29 | **   information about Qt Commercial License Agreements.
 | 
|---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
 | 
|---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
 | 
|---|
| 32 | **
 | 
|---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
 | 
|---|
| 34 | ** not clear to you.
 | 
|---|
| 35 | **
 | 
|---|
| 36 | **********************************************************************/
 | 
|---|
| 37 | 
 | 
|---|
| 38 | #ifndef QMESSAGEBOX_H
 | 
|---|
| 39 | #define QMESSAGEBOX_H
 | 
|---|
| 40 | 
 | 
|---|
| 41 | #ifndef QT_H
 | 
|---|
| 42 | #include "qdialog.h"
 | 
|---|
| 43 | #endif // QT_H
 | 
|---|
| 44 | 
 | 
|---|
| 45 | #ifndef QT_NO_MESSAGEBOX
 | 
|---|
| 46 | 
 | 
|---|
| 47 | class  QLabel;
 | 
|---|
| 48 | class  QPushButton;
 | 
|---|
| 49 | struct QMessageBoxData;
 | 
|---|
| 50 | 
 | 
|---|
| 51 | class Q_EXPORT QMessageBox : public QDialog
 | 
|---|
| 52 | {
 | 
|---|
| 53 |     Q_OBJECT
 | 
|---|
| 54 |     Q_ENUMS( Icon )
 | 
|---|
| 55 |     Q_PROPERTY( QString text READ text WRITE setText )
 | 
|---|
| 56 |     Q_PROPERTY( Icon icon READ icon WRITE setIcon )
 | 
|---|
| 57 |     Q_PROPERTY( QPixmap iconPixmap READ iconPixmap WRITE setIconPixmap )
 | 
|---|
| 58 |     Q_PROPERTY( TextFormat textFormat READ textFormat WRITE setTextFormat )
 | 
|---|
| 59 | 
 | 
|---|
| 60 | public:
 | 
|---|
| 61 |     enum Icon { NoIcon = 0, Information = 1, Warning = 2, Critical = 3,
 | 
|---|
| 62 |                 Question = 4 };
 | 
|---|
| 63 | 
 | 
|---|
| 64 |     QMessageBox( QWidget* parent=0, const char* name=0 );
 | 
|---|
| 65 |     QMessageBox( const QString& caption, const QString &text, Icon icon,
 | 
|---|
| 66 |                  int button0, int button1, int button2,
 | 
|---|
| 67 |                  QWidget* parent=0, const char* name=0, bool modal=TRUE,
 | 
|---|
| 68 |                  WFlags f=WStyle_DialogBorder  );
 | 
|---|
| 69 |     ~QMessageBox();
 | 
|---|
| 70 | 
 | 
|---|
| 71 |     enum { NoButton = 0, Ok = 1, Cancel = 2, Yes = 3, No = 4, Abort = 5,
 | 
|---|
| 72 |            Retry = 6, Ignore = 7, YesAll = 8, NoAll = 9, ButtonMask = 0xff,
 | 
|---|
| 73 |            Default = 0x100, Escape = 0x200, FlagMask = 0x300 };
 | 
|---|
| 74 | 
 | 
|---|
| 75 |     static int information( QWidget *parent, const QString &caption,
 | 
|---|
| 76 |                             const QString& text,
 | 
|---|
| 77 |                             int button0, int button1=0, int button2=0 );
 | 
|---|
| 78 |     static int information( QWidget *parent, const QString &caption,
 | 
|---|
| 79 |                             const QString& text,
 | 
|---|
| 80 |                             const QString& button0Text = QString::null,
 | 
|---|
| 81 |                             const QString& button1Text = QString::null,
 | 
|---|
| 82 |                             const QString& button2Text = QString::null,
 | 
|---|
| 83 |                             int defaultButtonNumber = 0,
 | 
|---|
| 84 |                             int escapeButtonNumber = -1 );
 | 
|---|
| 85 | 
 | 
|---|
| 86 |     static int question( QWidget *parent, const QString &caption,
 | 
|---|
| 87 |                          const QString& text,
 | 
|---|
| 88 |                          int button0, int button1=0, int button2=0 );
 | 
|---|
| 89 |     static int question( QWidget *parent, const QString &caption,
 | 
|---|
| 90 |                          const QString& text,
 | 
|---|
| 91 |                          const QString& button0Text = QString::null,
 | 
|---|
| 92 |                          const QString& button1Text = QString::null,
 | 
|---|
| 93 |                          const QString& button2Text = QString::null,
 | 
|---|
| 94 |                          int defaultButtonNumber = 0,
 | 
|---|
| 95 |                          int escapeButtonNumber = -1 );
 | 
|---|
| 96 | 
 | 
|---|
| 97 |     static int warning( QWidget *parent, const QString &caption,
 | 
|---|
| 98 |                         const QString& text,
 | 
|---|
| 99 |                         int button0, int button1, int button2=0 );
 | 
|---|
| 100 |     static int warning( QWidget *parent, const QString &caption,
 | 
|---|
| 101 |                         const QString& text,
 | 
|---|
| 102 |                         const QString& button0Text = QString::null,
 | 
|---|
| 103 |                         const QString& button1Text = QString::null,
 | 
|---|
| 104 |                         const QString& button2Text = QString::null,
 | 
|---|
| 105 |                         int defaultButtonNumber = 0,
 | 
|---|
| 106 |                         int escapeButtonNumber = -1 );
 | 
|---|
| 107 | 
 | 
|---|
| 108 |     static int critical( QWidget *parent, const QString &caption,
 | 
|---|
| 109 |                          const QString& text,
 | 
|---|
| 110 |                          int button0, int button1, int button2=0 );
 | 
|---|
| 111 |     static int critical( QWidget *parent, const QString &caption,
 | 
|---|
| 112 |                          const QString& text,
 | 
|---|
| 113 |                          const QString& button0Text = QString::null,
 | 
|---|
| 114 |                          const QString& button1Text = QString::null,
 | 
|---|
| 115 |                          const QString& button2Text = QString::null,
 | 
|---|
| 116 |                          int defaultButtonNumber = 0,
 | 
|---|
| 117 |                          int escapeButtonNumber = -1 );
 | 
|---|
| 118 | 
 | 
|---|
| 119 |     static void about( QWidget *parent, const QString &caption,
 | 
|---|
| 120 |                        const QString& text );
 | 
|---|
| 121 | 
 | 
|---|
| 122 |     static void aboutQt( QWidget *parent,
 | 
|---|
| 123 |                          const QString& caption=QString::null );
 | 
|---|
| 124 | 
 | 
|---|
| 125 | /* OBSOLETE */
 | 
|---|
| 126 |     static int message( const QString &caption,
 | 
|---|
| 127 |                         const QString& text,
 | 
|---|
| 128 |                         const QString& buttonText=QString::null,
 | 
|---|
| 129 |                         QWidget *parent=0, const char * =0 ) {
 | 
|---|
| 130 |         return QMessageBox::information( parent, caption, text,
 | 
|---|
| 131 |                                      buttonText.isEmpty()
 | 
|---|
| 132 |                                      ? tr("OK") : buttonText ) == 0;
 | 
|---|
| 133 |     }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | /* OBSOLETE */
 | 
|---|
| 136 |     static bool query( const QString &caption,
 | 
|---|
| 137 |                        const QString& text,
 | 
|---|
| 138 |                        const QString& yesButtonText=QString::null,
 | 
|---|
| 139 |                        const QString& noButtonText=QString::null,
 | 
|---|
| 140 |                        QWidget *parent=0, const char * = 0 ) {
 | 
|---|
| 141 |         return QMessageBox::information( parent, caption, text,
 | 
|---|
| 142 |                                      yesButtonText.isEmpty()
 | 
|---|
| 143 |                                      ? tr("OK") : yesButtonText,
 | 
|---|
| 144 |                                      noButtonText ) == 0;
 | 
|---|
| 145 |     }
 | 
|---|
| 146 | 
 | 
|---|
| 147 |     QString     text() const;
 | 
|---|
| 148 |     void        setText( const QString &);
 | 
|---|
| 149 | 
 | 
|---|
| 150 |     Icon        icon() const;
 | 
|---|
| 151 | 
 | 
|---|
| 152 |     void        setIcon( Icon );
 | 
|---|
| 153 |     void        setIcon( const QPixmap & );
 | 
|---|
| 154 | 
 | 
|---|
| 155 |     const QPixmap *iconPixmap() const;
 | 
|---|
| 156 |     void        setIconPixmap( const QPixmap & );
 | 
|---|
| 157 | 
 | 
|---|
| 158 |     QString     buttonText( int button ) const;
 | 
|---|
| 159 |     void        setButtonText( int button, const QString &);
 | 
|---|
| 160 | 
 | 
|---|
| 161 |     void        adjustSize();
 | 
|---|
| 162 | 
 | 
|---|
| 163 | /* OBSOLETE */
 | 
|---|
| 164 |     static QPixmap standardIcon( Icon icon, GUIStyle );
 | 
|---|
| 165 | 
 | 
|---|
| 166 |     static QPixmap standardIcon( Icon icon );
 | 
|---|
| 167 | 
 | 
|---|
| 168 |     TextFormat textFormat() const;
 | 
|---|
| 169 |     void         setTextFormat( TextFormat );
 | 
|---|
| 170 | 
 | 
|---|
| 171 | protected:
 | 
|---|
| 172 |     void        resizeEvent( QResizeEvent * );
 | 
|---|
| 173 |     void        showEvent( QShowEvent * );
 | 
|---|
| 174 |     void        closeEvent( QCloseEvent * );
 | 
|---|
| 175 |     void        keyPressEvent( QKeyEvent * );
 | 
|---|
| 176 |     void        styleChanged( QStyle& );
 | 
|---|
| 177 | 
 | 
|---|
| 178 | private slots:
 | 
|---|
| 179 |     void        buttonClicked();
 | 
|---|
| 180 | 
 | 
|---|
| 181 | private:
 | 
|---|
| 182 |     void        init( int, int, int );
 | 
|---|
| 183 |     int         indexOf( int ) const;
 | 
|---|
| 184 |     void        resizeButtons();
 | 
|---|
| 185 |     QLabel     *label;
 | 
|---|
| 186 |     QMessageBoxData *mbd;
 | 
|---|
| 187 |     void       *reserved1;
 | 
|---|
| 188 |     void       *reserved2;
 | 
|---|
| 189 | 
 | 
|---|
| 190 | private:        // Disabled copy constructor and operator=
 | 
|---|
| 191 | #if defined(Q_DISABLE_COPY)
 | 
|---|
| 192 |     QMessageBox( const QMessageBox & );
 | 
|---|
| 193 |     QMessageBox &operator=( const QMessageBox & );
 | 
|---|
| 194 | #endif
 | 
|---|
| 195 | };
 | 
|---|
| 196 | 
 | 
|---|
| 197 | /*
 | 
|---|
| 198 | *  Macro to be used at the beginning of main(), e.g.
 | 
|---|
| 199 | *
 | 
|---|
| 200 | *   #include <qapplication.h>
 | 
|---|
| 201 | *   #include <qmessagebox.h>
 | 
|---|
| 202 | *   int main( int argc, char**argv )
 | 
|---|
| 203 | *   {
 | 
|---|
| 204 | *     QT_REQUIRE_VERSION( argc, argv, "3.0.5" )
 | 
|---|
| 205 | *     ...
 | 
|---|
| 206 | *   }
 | 
|---|
| 207 | */
 | 
|---|
| 208 | #define QT_REQUIRE_VERSION( argc, argv, str ) { QString s=QString::fromLatin1(str);\
 | 
|---|
| 209 | QString sq=QString::fromLatin1(qVersion()); if ( (sq.section('.',0,0).toInt()<<16)+\
 | 
|---|
| 210 | (sq.section('.',1,1).toInt()<<8)+sq.section('.',2,2).toInt()<(s.section('.',0,0).toInt()<<16)+\
 | 
|---|
| 211 | (s.section('.',1,1).toInt()<<8)+s.section('.',2,2).toInt() ){if ( !qApp){ int c=0; new \
 | 
|---|
| 212 | QApplication(argc,argv);} QString s = QApplication::tr("Executable '%1' requires Qt "\
 | 
|---|
| 213 |  "%2, found Qt %3.").arg(QString::fromLatin1(qAppName())).arg(QString::fromLatin1(\
 | 
|---|
| 214 | str)).arg(QString::fromLatin1(qVersion()) ); QMessageBox::critical( 0, QApplication::tr(\
 | 
|---|
| 215 | "Incompatible Qt Library Error" ), s, QMessageBox::Abort,0 ); qFatal(s.ascii()); }}
 | 
|---|
| 216 | 
 | 
|---|
| 217 | 
 | 
|---|
| 218 | #endif // QT_NO_MESSAGEBOX
 | 
|---|
| 219 | 
 | 
|---|
| 220 | #endif // QMESSAGEBOX_H
 | 
|---|