Salome HOME
Copyrights update
[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, const QString& caption, const QString& text,
36                                                    const QString& textButton0 )
37 {
38         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
39     int ret = QMessageBox::information( parent, caption, text, textButton0,
40                                         QString::null, QString::null, 0, 0 );
41     qApp->processEvents();
42     return ret;
43 }
44
45 /*!
46     Shows warning message box with one button [ static ]
47 */
48 int SUIT_MessageBox::warn1( QWidget* parent, const QString& caption, const QString& text,
49                                                    const QString& textButton0 )
50 {
51         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
52     int ret = QMessageBox::warning( parent, caption, text, textButton0,
53                                     QString::null, QString::null, 0, 0 );
54     qApp->processEvents();
55     return ret;
56 }
57
58 /*!
59     Shows error message box with one button [ static ]
60 */
61 int SUIT_MessageBox::error1( QWidget* parent, const QString& caption,
62                                                         const QString& text, const QString& textButton0 )
63 {
64         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
65     int ret = QMessageBox::critical( parent, caption, text, textButton0,
66                                      QString::null, QString::null, 0, 0 );
67     qApp->processEvents();
68     return ret;
69 }
70
71 /*!
72     Shows info message box with two buttons.
73     Returns id of the pressed button or -1 if escaped [ static ]
74 */
75 int SUIT_MessageBox::info2( QWidget* parent, const QString& caption,
76                                                    const QString& text, const QString& textButton0,
77                                                    const QString& textButton1, int idButton0, int idButton1, int idDefault )
78 {
79         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
80     if ( idDefault == idButton0 )
81         idDefault = 0;
82     else if ( idDefault == idButton1 )
83         idDefault = 1;
84     else
85         idDefault = 0;
86
87     int ret = QMessageBox::information( parent, caption, text, textButton0,
88                                         textButton1, QString::null, idDefault );
89     qApp->processEvents();
90     return ( ret == 0 ? idButton0 : idButton1 );
91 }
92
93 /*!
94     Shows warning message box with two buttons.
95     Returns id of the pressed button or -1 if escaped [ static ]
96 */
97 int SUIT_MessageBox::warn2( QWidget* parent, const QString& caption, const QString& text,
98                            const QString& textButton0, const QString& textButton1,
99                            int idButton0, int idButton1, int idDefault )
100 {
101         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
102
103     if ( idDefault == idButton0 )
104         idDefault = 0;
105     else if ( idDefault == idButton1 )
106         idDefault = 1;
107     else
108         idDefault = 0;
109
110     int ret = QMessageBox::warning( parent, caption, text, textButton0,
111                                     textButton1, QString::null, idDefault );
112     qApp->processEvents();
113     return ( ret == 0 ? idButton0 : idButton1 );
114 }
115
116 /*!
117     Shows error message box with two buttons
118     Returns id of the pressed button or -1 if escaped [ static ]
119 */
120 int SUIT_MessageBox::error2( QWidget* parent, const QString& caption, const QString& text,
121                             const QString& textButton0, const QString& textButton1,
122                             int idButton0, int idButton1, int idDefault )
123 {
124         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
125
126     if ( idDefault == idButton0 )
127         idDefault = 0;
128     else if ( idDefault == idButton1 )
129         idDefault = 1;
130     else
131         idDefault = 0;
132
133     int ret = QMessageBox::critical( parent, caption, text, textButton0,
134                                      textButton1, QString::null, idDefault );
135     qApp->processEvents();
136     return ( ret == 0 ? idButton0 : idButton1 );
137 }
138
139 /*!
140     Shows info message box with three buttons.
141     Returns id of the pressed button or -1 if escaped [ static ]
142 */
143 int SUIT_MessageBox::info3( QWidget* parent, const QString& caption, const QString& text,
144                            const QString& textButton0, const QString& textButton1,
145                            const QString& textButton2, int idButton0, int idButton1,
146                            int idButton2, int idDefault )
147 {
148         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
149
150     if ( idDefault == idButton0 )
151         idDefault = 0;
152     else if ( idDefault == idButton1 )
153         idDefault = 1;
154     else if ( idDefault == idButton2 )
155         idDefault = 2;
156     else
157         idDefault = 0;
158
159     int ret = QMessageBox::information( parent, caption, text, textButton0,
160                                         textButton1, textButton2, idDefault );
161     qApp->processEvents();
162     switch ( ret )
163     {
164         case 0:
165             return idButton0;
166         case 1:
167             return idButton1;
168         case 2:
169             return idButton2;
170     }
171     return -1;
172 }
173
174 /*!
175     Shows warning message box with three buttons.
176     Returns id of the pressed button or -1 if escaped [ static ]
177 */
178 int SUIT_MessageBox::warn3( QWidget* parent, const QString& caption, const QString& text,
179                            const QString& textButton0, const QString& textButton1,
180                            const QString& textButton2, int idButton0, int idButton1,
181                            int idButton2, int idDefault )
182 {
183         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
184
185     if ( idDefault == idButton0 )
186         idDefault = 0;
187     else if ( idDefault == idButton1 )
188         idDefault = 1;
189     else if ( idDefault == idButton2 )
190         idDefault = 2;
191     else
192         idDefault = 0;
193
194     int ret = QMessageBox::warning( parent, caption, text, textButton0,
195                                     textButton1, textButton2, idDefault );
196     qApp->processEvents();
197     switch ( ret )
198     {
199         case 0:
200             return idButton0;
201         case 1:
202             return idButton1;
203         case 2:
204             return idButton2;
205     }
206     return -1;
207 }
208
209 /*!
210     Shows error message box with three buttons.
211     Returns id of the pressed button or -1 if escaped [ static ]
212 */
213 int SUIT_MessageBox::error3( QWidget* parent, const QString& caption, const QString& text,
214                             const QString& textButton0, const QString& textButton1,
215                             const QString& textButton2, int idButton0, int idButton1,
216                             int idButton2, int idDefault )
217 {
218         SUIT_OverrideCursor cw( parent ? parent->cursor() : Qt::arrowCursor );
219
220     if ( idDefault == idButton0 )
221         idDefault = 0;
222     else if ( idDefault == idButton1 )
223         idDefault = 1;
224     else if ( idDefault == idButton2 )
225         idDefault = 2;
226     else
227         idDefault = 0;
228
229     int ret = QMessageBox::critical( parent, caption, text, textButton0,
230                                      textButton1, textButton2, idDefault );
231     qApp->processEvents();
232     switch ( ret )
233     {
234         case 0:
235             return idButton0;
236         case 1:
237             return idButton1;
238         case 2:
239             return idButton2;
240     }
241     return -1;
242 }