Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/gui.git] / src / SUIT / SUIT_MessageBox.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19
20 /*!
21   \class:   SUIT_MessageBox
22   Message dialog box for SUIT-based application
23   Module:  SUIT
24   Created: UI team, 02.10.00
25 */
26
27 #include "SUIT_MessageBox.h"
28 #include "SUIT_OverrideCursor.h"
29
30 #include <qmessagebox.h>
31 #include <qapplication.h>
32
33 /*!
34     Shows info message box with one button [ static ]
35 */
36 int SUIT_MessageBox::info1( QWidget* parent, 
37                             const QString& caption, 
38                             const QString& text,
39                             const QString& textButton0 )
40 {
41   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
42   int ret = QMessageBox::information( parent, caption, text, textButton0,
43                                       QString::null, QString::null, 0, 0 );
44   qApp->processEvents();
45   return ret;
46 }
47
48 /*!
49     Shows warning message box with one button [ static ]
50 */
51 int SUIT_MessageBox::warn1( QWidget* parent, 
52                             const QString& caption, 
53                             const QString& text,
54                             const QString& textButton0 )
55 {
56   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
57   int ret = QMessageBox::warning( parent, caption, text, textButton0,
58                                   QString::null, QString::null, 0, 0 );
59   qApp->processEvents();
60   return ret;
61 }
62
63 /*!
64     Shows error message box with one button [ static ]
65 */
66 int SUIT_MessageBox::error1( QWidget* parent, 
67                              const QString& caption,
68                              const QString& text,
69                              const QString& textButton0 )
70 {
71   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
72   int ret = QMessageBox::critical( parent, caption, text, textButton0,
73                                    QString::null, QString::null, 0, 0 );
74   qApp->processEvents();
75   return ret;
76 }
77
78 /*!
79     Shows question message box with one button [ static ]
80 */
81 int SUIT_MessageBox::question1( QWidget* parent, 
82                                 const QString& caption,
83                                 const QString& text, 
84                                 const QString& textButton0 )
85 {
86   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
87   int ret = QMessageBox::question( parent, caption, text, textButton0,
88                                    QString::null, QString::null, 0, 0 );
89   qApp->processEvents();
90   return ret;
91 }
92
93 /*!
94     Shows info message box with two buttons.
95     Returns id of the pressed button or -1 if escaped [ static ]
96 */
97 int SUIT_MessageBox::info2( QWidget* parent, 
98                             const QString& caption,
99                             const QString& text, 
100                             const QString& textButton0,
101                             const QString& textButton1, 
102                             int idButton0, int idButton1, int idDefault )
103 {
104   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
105   if ( idDefault == idButton0 )
106     idDefault = 0;
107   else if ( idDefault == idButton1 )
108     idDefault = 1;
109   else
110     idDefault = 0;
111   
112   int ret = QMessageBox::information( parent, caption, text, textButton0,
113                                       textButton1, QString::null, idDefault );
114   qApp->processEvents();
115   return ( ret == 0 ? idButton0 : idButton1 );
116 }
117
118 /*!
119   Shows warning message box with two buttons.
120     Returns id of the pressed button or -1 if escaped [ static ]
121 */
122 int SUIT_MessageBox::warn2( QWidget* parent, 
123                             const QString& caption,
124                             const QString& text,
125                             const QString& textButton0, 
126                             const QString& textButton1,
127                             int idButton0, int idButton1, int idDefault )
128 {
129   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
130   
131   if ( idDefault == idButton0 )
132     idDefault = 0;
133   else if ( idDefault == idButton1 )
134     idDefault = 1;
135   else
136     idDefault = 0;
137   
138   int ret = QMessageBox::warning( parent, caption, text, textButton0,
139                                   textButton1, QString::null, idDefault );
140   qApp->processEvents();
141   return ( ret == 0 ? idButton0 : idButton1 );
142 }
143
144 /*!
145     Shows error message box with two buttons
146     Returns id of the pressed button or -1 if escaped [ static ]
147 */
148 int SUIT_MessageBox::error2( QWidget* parent, 
149                              const QString& caption, 
150                              const QString& text,
151                              const QString& textButton0, 
152                              const QString& textButton1,
153                              int idButton0, int idButton1, int idDefault )
154 {
155   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
156   
157   if ( idDefault == idButton0 )
158     idDefault = 0;
159   else if ( idDefault == idButton1 )
160     idDefault = 1;
161   else
162     idDefault = 0;
163   
164   int ret = QMessageBox::critical( parent, caption, text, textButton0,
165                                    textButton1, QString::null, idDefault );
166   qApp->processEvents();
167   return ( ret == 0 ? idButton0 : idButton1 );
168 }
169
170 /*!
171     Shows question message box with two buttons
172     Returns id of the pressed button or -1 if escaped [ static ]
173 */
174 int SUIT_MessageBox::question2( QWidget* parent, 
175                                 const QString& caption, 
176                                 const QString& text,
177                                 const QString& textButton0, 
178                                 const QString& textButton1,
179                                 int idButton0, int idButton1, int idDefault )
180 {
181   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
182   
183   if ( idDefault == idButton0 )
184     idDefault = 0;
185   else if ( idDefault == idButton1 )
186     idDefault = 1;
187   else
188     idDefault = 0;
189   
190   int ret = QMessageBox::question( parent, caption, text, textButton0,
191                                    textButton1, QString::null, idDefault );
192   qApp->processEvents();
193   return ( ret == 0 ? idButton0 : idButton1 );
194 }
195
196 /*!
197     Shows info message box with three buttons.
198     Returns id of the pressed button or -1 if escaped [ static ]
199 */
200 int SUIT_MessageBox::info3( QWidget* parent, 
201                             const QString& caption,
202                             const QString& text,
203                             const QString& textButton0, 
204                             const QString& textButton1,
205                             const QString& textButton2, 
206                             int idButton0, int idButton1,
207                             int idButton2, int idDefault )
208 {
209   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
210   
211   if ( idDefault == idButton0 )
212     idDefault = 0;
213   else if ( idDefault == idButton1 )
214     idDefault = 1;
215   else if ( idDefault == idButton2 )
216     idDefault = 2;
217   else
218     idDefault = 0;
219   
220   int ret = QMessageBox::information( parent, caption, text, textButton0,
221                                       textButton1, textButton2, idDefault );
222   qApp->processEvents();
223   switch ( ret )
224     {
225     case 0:
226       return idButton0;
227     case 1:
228       return idButton1;
229     case 2:
230       return idButton2;
231     }
232   return -1;
233 }
234
235 /*!
236     Shows warning message box with three buttons.
237     Returns id of the pressed button or -1 if escaped [ static ]
238 */
239 int SUIT_MessageBox::warn3( QWidget* parent, 
240                             const QString& caption, 
241                             const QString& text,
242                             const QString& textButton0, 
243                             const QString& textButton1,
244                             const QString& textButton2, 
245                             int idButton0, int idButton1,
246                             int idButton2, int idDefault )
247 {
248   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
249   
250   if ( idDefault == idButton0 )
251     idDefault = 0;
252   else if ( idDefault == idButton1 )
253     idDefault = 1;
254   else if ( idDefault == idButton2 )
255     idDefault = 2;
256   else
257     idDefault = 0;
258   
259   int ret = QMessageBox::warning( parent, caption, text, textButton0,
260                                   textButton1, textButton2, idDefault );
261   qApp->processEvents();
262   switch ( ret )
263     {
264     case 0:
265       return idButton0;
266     case 1:
267       return idButton1;
268     case 2:
269       return idButton2;
270     }
271   return -1;
272 }
273
274 /*!
275     Shows error message box with three buttons.
276     Returns id of the pressed button or -1 if escaped [ static ]
277 */
278 int SUIT_MessageBox::error3( QWidget* parent, 
279                              const QString& caption, 
280                              const QString& text,
281                              const QString& textButton0, 
282                              const QString& textButton1,
283                              const QString& textButton2, 
284                              int idButton0, int idButton1,
285                              int idButton2, int idDefault )
286 {
287   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
288   
289   if ( idDefault == idButton0 )
290     idDefault = 0;
291   else if ( idDefault == idButton1 )
292     idDefault = 1;
293   else if ( idDefault == idButton2 )
294     idDefault = 2;
295   else
296     idDefault = 0;
297   
298   int ret = QMessageBox::critical( parent, caption, text, textButton0,
299                                    textButton1, textButton2, idDefault );
300   qApp->processEvents();
301   switch ( ret )
302     {
303     case 0:
304       return idButton0;
305     case 1:
306       return idButton1;
307     case 2:
308       return idButton2;
309     }
310   return -1;
311 }
312
313 /*!
314     Shows question message box with three buttons.
315     Returns id of the pressed button or -1 if escaped [ static ]
316 */
317 int SUIT_MessageBox::question3( QWidget* parent, 
318                                 const QString& caption, 
319                                 const QString& text,
320                                 const QString& textButton0, 
321                                 const QString& textButton1,
322                                 const QString& textButton2, 
323                                 int idButton0, int idButton1,
324                                 int idButton2, int idDefault )
325 {
326   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
327   
328   if ( idDefault == idButton0 )
329     idDefault = 0;
330   else if ( idDefault == idButton1 )
331     idDefault = 1;
332   else if ( idDefault == idButton2 )
333     idDefault = 2;
334   else
335     idDefault = 0;
336   
337   int ret = QMessageBox::question( parent, caption, text, textButton0,
338                                    textButton1, textButton2, idDefault );
339   qApp->processEvents();
340   switch ( ret )
341     {
342     case 0:
343       return idButton0;
344     case 1:
345       return idButton1;
346     case 2:
347       return idButton2;
348     }
349   return -1;
350 }