Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / SALOMEGUI / QAD_MessageBox.cxx
1 using namespace std;
2 //  File      : QAD_MessageBox.cxx
3 //  Created   : 02.10.00
4 //  Author    : UI team
5 //  Descr     : Message dialog box for QAD-based application
6 //  Project   : SALOME
7 //  Module    : SALOMEGUI
8 //  Copyright : Open CASCADE
9 //  $Header$
10
11 /*!
12   \class QAD_MessageBox QAD_MessageBox.h
13   \brief Message dialog box for QAD-based application.
14 */
15
16 #include "QAD_MessageBox.h"
17
18 // QT Includes
19 #include <qmessagebox.h>
20 #include <qapplication.h>
21
22 /*!
23     Shows info message box with one button [ static ]
24 */
25 int QAD_MessageBox::info1 ( QWidget* parent, const QString& caption, const QString& text,
26                             const QString& textButton0 )
27 {
28     int ret = QMessageBox::information ( parent, caption, text, textButton0,
29                                          QString::null, QString::null, 0, 0);
30     qApp->processEvents();  /* update desktop */
31     return ret;
32 }
33
34 /*!
35     Shows warning message box with one button [ static ]
36 */
37 int QAD_MessageBox::warn1 ( QWidget* parent, const QString& caption, const QString& text,
38                        const QString& textButton0 )
39 {
40     int ret = QMessageBox::warning ( parent, caption, text, textButton0,
41                                      QString::null, QString::null, 0, 0);
42     qApp->processEvents();  /* update desktop */
43     return ret;
44 }
45
46 /*!
47     Shows error message box with one button [ static ]
48 */
49 int QAD_MessageBox::error1 ( QWidget* parent, const QString& caption, const QString& text,
50                        const QString& textButton0 )
51 {
52     int ret = QMessageBox::critical ( parent, caption, text, textButton0,
53                                       QString::null, QString::null, 0, 0);
54     qApp->processEvents();  /* update desktop */
55     return ret;
56 }
57
58 /*!
59     Shows info message box with two buttons.
60     Returns id of the pressed button or -1 if escaped [ static ]
61 */
62 int QAD_MessageBox::info2 ( QWidget* parent, const QString& caption, const QString& text,
63                        const QString& textButton0, const QString& textButton1,
64                        int idButton0, int idButton1, int idDefault )
65 {
66     if ( idDefault == idButton0 ) idDefault = 0;
67     else if ( idDefault == idButton1 ) idDefault = 1;
68     else idDefault = 0;
69     
70     int ret = QMessageBox::information ( parent, caption, text, textButton0,
71         textButton1, QString::null, idDefault );        
72     qApp->processEvents();  /* update desktop */
73     return ( ret == 0 ? idButton0 : idButton1 );
74 }
75
76 /*!
77     Shows warning message box with two buttons.
78     Returns id of the pressed button or -1 if escaped [ static ]
79 */
80 int QAD_MessageBox::warn2 ( QWidget* parent, const QString& caption, const QString& text,
81                        const QString& textButton0, const QString& textButton1,
82                        int idButton0, int idButton1, int idDefault )
83 {
84     if ( idDefault == idButton0 ) idDefault = 0;
85     else if ( idDefault == idButton1 ) idDefault = 1;
86     else idDefault = 0;
87     
88     int ret = QMessageBox::warning ( parent, caption, text, textButton0,
89         textButton1, QString::null, idDefault );
90     qApp->processEvents();  /* update desktop */
91     return ( ret == 0 ? idButton0 : idButton1 );
92 }
93
94 /*!
95     Shows error message box with two buttons 
96     Returns id of the pressed button or -1 if escaped [ static ]
97 */
98 int QAD_MessageBox::error2 ( QWidget* parent, const QString& caption, const QString& text,
99                        const QString& textButton0, const QString& textButton1,
100                        int idButton0, int idButton1, int idDefault )
101 {
102     if ( idDefault == idButton0 ) idDefault = 0;
103     else if ( idDefault == idButton1 ) idDefault = 1;
104     else idDefault = 0;
105     
106     int ret = QMessageBox::critical ( parent, caption, text, textButton0,
107         textButton1, QString::null, idDefault );
108     qApp->processEvents();  /* update desktop */
109     return ( ret == 0 ? idButton0 : idButton1 );
110 }
111
112 /*!
113     Shows info message box with three buttons.
114     Returns id of the pressed button or -1 if escaped [ static ]
115 */
116 int QAD_MessageBox::info3 ( QWidget* parent, const QString& caption, const QString& text,
117                        const QString& textButton0, const QString& textButton1,
118                        const QString& textButton2, int idButton0, int idButton1,
119                        int idButton2, int idDefault )
120 {
121     if ( idDefault == idButton0 ) idDefault = 0;
122     else if ( idDefault == idButton1 ) idDefault = 1;
123     else if ( idDefault == idButton2 ) idDefault = 2;
124     else idDefault = 0;
125     
126     int ret = QMessageBox::information ( parent, caption, text, textButton0,
127             textButton1, textButton2, idDefault );
128     qApp->processEvents();  /* update desktop */
129     switch ( ret ) 
130     {
131         case 0: return idButton0;
132         case 1: return idButton1;    
133         case 2: return idButton2;
134     }
135     return -1;   
136 }
137
138 /*!
139     Shows warning message box with three buttons.
140     Returns id of the pressed button or -1 if escaped [ static ]
141 */
142 int QAD_MessageBox::warn3 ( QWidget* parent, const QString& caption, const QString& text,
143                        const QString& textButton0, const QString& textButton1,
144                        const QString& textButton2, int idButton0, int idButton1,
145                        int idButton2, int idDefault )
146 {
147     if ( idDefault == idButton0 ) idDefault = 0;
148     else if ( idDefault == idButton1 ) idDefault = 1;
149     else if ( idDefault == idButton2 ) idDefault = 2;
150     else idDefault = 0;
151     
152     int ret = QMessageBox::warning ( parent, caption, text, textButton0,
153             textButton1, textButton2, idDefault );
154     qApp->processEvents();  /* update desktop */
155     switch ( ret ) 
156     {
157         case 0: return idButton0;
158         case 1: return idButton1;    
159         case 2: return idButton2;
160     }
161     return -1;   
162 }
163
164 /*!
165     Shows error message box with three buttons.
166     Returns id of the pressed button or -1 if escaped [ static ]
167 */
168 int QAD_MessageBox::error3 ( QWidget* parent, const QString& caption, const QString& text,
169                        const QString& textButton0, const QString& textButton1,
170                        const QString& textButton2, int idButton0, int idButton1,
171                        int idButton2, int idDefault )
172 {
173     if ( idDefault == idButton0 ) idDefault = 0;
174     else if ( idDefault == idButton1 ) idDefault = 1;
175     else if ( idDefault == idButton2 ) idDefault = 2;
176     else idDefault = 0;
177
178     int ret = QMessageBox::critical ( parent, caption, text, textButton0,
179             textButton1, textButton2, idDefault );
180     qApp->processEvents();  /* update desktop */
181     switch ( ret ) 
182     {
183         case 0: return idButton0;
184         case 1: return idButton1;    
185         case 2: return idButton2;
186     }
187     return -1;   
188 }