Salome HOME
Join modifications from branch BR_3_1_0deb
[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 **  Class:   SUIT_MessageBox
21 **  Descr:   Message dialog box for SUIT-based application
22 **  Module:  SUIT
23 **  Created: UI team, 02.10.00
24 *********************************************************************/
25
26 #include "SUIT_MessageBox.h"
27 #include "SUIT_OverrideCursor.h"
28
29 #include <qmessagebox.h>
30 #include <qapplication.h>
31
32 /*!
33     Shows info message box with one button [ static ]
34 */
35 int SUIT_MessageBox::info1( QWidget* parent, 
36                             const QString& caption, 
37                             const QString& text,
38                             const QString& textButton0 )
39 {
40   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
41   int ret = QMessageBox::information( parent, caption, text, textButton0,
42                                       QString::null, QString::null, 0, 0 );
43   qApp->processEvents();
44   return ret;
45 }
46
47 /*!
48     Shows warning message box with one button [ static ]
49 */
50 int SUIT_MessageBox::warn1( QWidget* parent, 
51                             const QString& caption, 
52                             const QString& text,
53                             const QString& textButton0 )
54 {
55   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
56   int ret = QMessageBox::warning( parent, caption, text, textButton0,
57                                   QString::null, QString::null, 0, 0 );
58   qApp->processEvents();
59   return ret;
60 }
61
62 /*!
63     Shows error message box with one button [ static ]
64 */
65 int SUIT_MessageBox::error1( QWidget* parent, 
66                              const QString& caption,
67                              const QString& text,
68                              const QString& textButton0 )
69 {
70   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
71   int ret = QMessageBox::critical( parent, caption, text, textButton0,
72                                    QString::null, QString::null, 0, 0 );
73   qApp->processEvents();
74   return ret;
75 }
76
77 /*!
78     Shows question message box with one button [ static ]
79 */
80 int SUIT_MessageBox::question1( QWidget* parent, 
81                                 const QString& caption,
82                                 const QString& text, 
83                                 const QString& textButton0 )
84 {
85   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
86   int ret = QMessageBox::question( parent, caption, text, textButton0,
87                                    QString::null, QString::null, 0, 0 );
88   qApp->processEvents();
89   return ret;
90 }
91
92 /*!
93     Shows info message box with two buttons.
94     Returns id of the pressed button or -1 if escaped [ static ]
95 */
96 int SUIT_MessageBox::info2( QWidget* parent, 
97                             const QString& caption,
98                             const QString& text, 
99                             const QString& textButton0,
100                             const QString& textButton1, 
101                             int idButton0, int idButton1, int idDefault )
102 {
103   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
104   if ( idDefault == idButton0 )
105     idDefault = 0;
106   else if ( idDefault == idButton1 )
107     idDefault = 1;
108   else
109     idDefault = 0;
110   
111   int ret = QMessageBox::information( parent, caption, text, textButton0,
112                                       textButton1, QString::null, idDefault );
113   qApp->processEvents();
114   return ( ret == 0 ? idButton0 : idButton1 );
115 }
116
117 /*!
118   Shows warning message box with two buttons.
119     Returns id of the pressed button or -1 if escaped [ static ]
120 */
121 int SUIT_MessageBox::warn2( QWidget* parent, 
122                             const QString& caption,
123                             const QString& text,
124                             const QString& textButton0, 
125                             const QString& textButton1,
126                             int idButton0, int idButton1, int idDefault )
127 {
128   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
129   
130   if ( idDefault == idButton0 )
131     idDefault = 0;
132   else if ( idDefault == idButton1 )
133     idDefault = 1;
134   else
135     idDefault = 0;
136   
137   int ret = QMessageBox::warning( parent, caption, text, textButton0,
138                                   textButton1, QString::null, idDefault );
139   qApp->processEvents();
140   return ( ret == 0 ? idButton0 : idButton1 );
141 }
142
143 /*!
144     Shows error message box with two buttons
145     Returns id of the pressed button or -1 if escaped [ static ]
146 */
147 int SUIT_MessageBox::error2( QWidget* parent, 
148                              const QString& caption, 
149                              const QString& text,
150                              const QString& textButton0, 
151                              const QString& textButton1,
152                              int idButton0, int idButton1, int idDefault )
153 {
154   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
155   
156   if ( idDefault == idButton0 )
157     idDefault = 0;
158   else if ( idDefault == idButton1 )
159     idDefault = 1;
160   else
161     idDefault = 0;
162   
163   int ret = QMessageBox::critical( parent, caption, text, textButton0,
164                                    textButton1, QString::null, idDefault );
165   qApp->processEvents();
166   return ( ret == 0 ? idButton0 : idButton1 );
167 }
168
169 /*!
170     Shows question message box with two buttons
171     Returns id of the pressed button or -1 if escaped [ static ]
172 */
173 int SUIT_MessageBox::question2( QWidget* parent, 
174                                 const QString& caption, 
175                                 const QString& text,
176                                 const QString& textButton0, 
177                                 const QString& textButton1,
178                                 int idButton0, int idButton1, int idDefault )
179 {
180   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
181   
182   if ( idDefault == idButton0 )
183     idDefault = 0;
184   else if ( idDefault == idButton1 )
185     idDefault = 1;
186   else
187     idDefault = 0;
188   
189   int ret = QMessageBox::question( parent, caption, text, textButton0,
190                                    textButton1, QString::null, idDefault );
191   qApp->processEvents();
192   return ( ret == 0 ? idButton0 : idButton1 );
193 }
194
195 /*!
196     Shows info message box with three buttons.
197     Returns id of the pressed button or -1 if escaped [ static ]
198 */
199 int SUIT_MessageBox::info3( QWidget* parent, 
200                             const QString& caption,
201                             const QString& text,
202                             const QString& textButton0, 
203                             const QString& textButton1,
204                             const QString& textButton2, 
205                             int idButton0, int idButton1,
206                             int idButton2, int idDefault )
207 {
208   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
209   
210   if ( idDefault == idButton0 )
211     idDefault = 0;
212   else if ( idDefault == idButton1 )
213     idDefault = 1;
214   else if ( idDefault == idButton2 )
215     idDefault = 2;
216   else
217     idDefault = 0;
218   
219   int ret = QMessageBox::information( parent, caption, text, textButton0,
220                                       textButton1, textButton2, idDefault );
221   qApp->processEvents();
222   switch ( ret )
223     {
224     case 0:
225       return idButton0;
226     case 1:
227       return idButton1;
228     case 2:
229       return idButton2;
230     }
231   return -1;
232 }
233
234 /*!
235     Shows warning message box with three buttons.
236     Returns id of the pressed button or -1 if escaped [ static ]
237 */
238 int SUIT_MessageBox::warn3( QWidget* parent, 
239                             const QString& caption, 
240                             const QString& text,
241                             const QString& textButton0, 
242                             const QString& textButton1,
243                             const QString& textButton2, 
244                             int idButton0, int idButton1,
245                             int idButton2, int idDefault )
246 {
247   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
248   
249   if ( idDefault == idButton0 )
250     idDefault = 0;
251   else if ( idDefault == idButton1 )
252     idDefault = 1;
253   else if ( idDefault == idButton2 )
254     idDefault = 2;
255   else
256     idDefault = 0;
257   
258   int ret = QMessageBox::warning( parent, caption, text, textButton0,
259                                   textButton1, textButton2, idDefault );
260   qApp->processEvents();
261   switch ( ret )
262     {
263     case 0:
264       return idButton0;
265     case 1:
266       return idButton1;
267     case 2:
268       return idButton2;
269     }
270   return -1;
271 }
272
273 /*!
274     Shows error message box with three buttons.
275     Returns id of the pressed button or -1 if escaped [ static ]
276 */
277 int SUIT_MessageBox::error3( QWidget* parent, 
278                              const QString& caption, 
279                              const QString& text,
280                              const QString& textButton0, 
281                              const QString& textButton1,
282                              const QString& textButton2, 
283                              int idButton0, int idButton1,
284                              int idButton2, int idDefault )
285 {
286   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
287   
288   if ( idDefault == idButton0 )
289     idDefault = 0;
290   else if ( idDefault == idButton1 )
291     idDefault = 1;
292   else if ( idDefault == idButton2 )
293     idDefault = 2;
294   else
295     idDefault = 0;
296   
297   int ret = QMessageBox::critical( parent, caption, text, textButton0,
298                                    textButton1, textButton2, idDefault );
299   qApp->processEvents();
300   switch ( ret )
301     {
302     case 0:
303       return idButton0;
304     case 1:
305       return idButton1;
306     case 2:
307       return idButton2;
308     }
309   return -1;
310 }
311
312 /*!
313     Shows question message box with three buttons.
314     Returns id of the pressed button or -1 if escaped [ static ]
315 */
316 int SUIT_MessageBox::question3( QWidget* parent, 
317                                 const QString& caption, 
318                                 const QString& text,
319                                 const QString& textButton0, 
320                                 const QString& textButton1,
321                                 const QString& textButton2, 
322                                 int idButton0, int idButton1,
323                                 int idButton2, int idDefault )
324 {
325   SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
326   
327   if ( idDefault == idButton0 )
328     idDefault = 0;
329   else if ( idDefault == idButton1 )
330     idDefault = 1;
331   else if ( idDefault == idButton2 )
332     idDefault = 2;
333   else
334     idDefault = 0;
335   
336   int ret = QMessageBox::question( parent, caption, text, textButton0,
337                                    textButton1, textButton2, idDefault );
338   qApp->processEvents();
339   switch ( ret )
340     {
341     case 0:
342       return idButton0;
343     case 1:
344       return idButton1;
345     case 2:
346       return idButton2;
347     }
348   return -1;
349 }