Salome HOME
NRI : Merge from V1_2.
[modules/kernel.git] / src / SALOMEGUI / QAD_MessageBox.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : QAD_MessageBox.cxx
25 //  Author : UI team
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 /*!
31   \class QAD_MessageBox QAD_MessageBox.h
32   \brief Message dialog box for QAD-based application.
33 */
34
35 #include "QAD_MessageBox.h"
36
37 // QT Includes
38 #include <qmessagebox.h>
39 #include <qapplication.h>
40
41 /*!
42     Shows info message box with one button [ static ]
43 */
44 int QAD_MessageBox::info1 ( QWidget* parent, const QString& caption, const QString& text,
45                             const QString& textButton0 )
46 {
47     int ret = QMessageBox::information ( parent, caption, text, textButton0,
48                                          QString::null, QString::null, 0, 0);
49     qApp->processEvents();  /* update desktop */
50     return ret;
51 }
52
53 /*!
54     Shows warning message box with one button [ static ]
55 */
56 int QAD_MessageBox::warn1 ( QWidget* parent, const QString& caption, const QString& text,
57                        const QString& textButton0 )
58 {
59     int ret = QMessageBox::warning ( parent, caption, text, textButton0,
60                                      QString::null, QString::null, 0, 0);
61     qApp->processEvents();  /* update desktop */
62     return ret;
63 }
64
65 /*!
66     Shows error message box with one button [ static ]
67 */
68 int QAD_MessageBox::error1 ( QWidget* parent, const QString& caption, const QString& text,
69                        const QString& textButton0 )
70 {
71     int ret = QMessageBox::critical ( parent, caption, text, textButton0,
72                                       QString::null, QString::null, 0, 0);
73     qApp->processEvents();  /* update desktop */
74     return ret;
75 }
76
77 /*!
78     Shows info message box with two buttons.
79     Returns id of the pressed button or -1 if escaped [ static ]
80 */
81 int QAD_MessageBox::info2 ( QWidget* parent, const QString& caption, const QString& text,
82                        const QString& textButton0, const QString& textButton1,
83                        int idButton0, int idButton1, int idDefault )
84 {
85     if ( idDefault == idButton0 ) idDefault = 0;
86     else if ( idDefault == idButton1 ) idDefault = 1;
87     else idDefault = 0;
88     
89     int ret = QMessageBox::information ( parent, caption, text, textButton0,
90         textButton1, QString::null, idDefault );        
91     qApp->processEvents();  /* update desktop */
92     return ( ret == 0 ? idButton0 : idButton1 );
93 }
94
95 /*!
96     Shows warning message box with two buttons.
97     Returns id of the pressed button or -1 if escaped [ static ]
98 */
99 int QAD_MessageBox::warn2 ( QWidget* parent, const QString& caption, const QString& text,
100                        const QString& textButton0, const QString& textButton1,
101                        int idButton0, int idButton1, int idDefault )
102 {
103     if ( idDefault == idButton0 ) idDefault = 0;
104     else if ( idDefault == idButton1 ) idDefault = 1;
105     else idDefault = 0;
106     
107     int ret = QMessageBox::warning ( parent, caption, text, textButton0,
108         textButton1, QString::null, idDefault );
109     qApp->processEvents();  /* update desktop */
110     return ( ret == 0 ? idButton0 : idButton1 );
111 }
112
113 /*!
114     Shows error message box with two buttons 
115     Returns id of the pressed button or -1 if escaped [ static ]
116 */
117 int QAD_MessageBox::error2 ( QWidget* parent, const QString& caption, const QString& text,
118                        const QString& textButton0, const QString& textButton1,
119                        int idButton0, int idButton1, int idDefault )
120 {
121     if ( idDefault == idButton0 ) idDefault = 0;
122     else if ( idDefault == idButton1 ) idDefault = 1;
123     else idDefault = 0;
124     
125     int ret = QMessageBox::critical ( parent, caption, text, textButton0,
126         textButton1, QString::null, idDefault );
127     qApp->processEvents();  /* update desktop */
128     return ( ret == 0 ? idButton0 : idButton1 );
129 }
130
131 /*!
132     Shows info message box with three buttons.
133     Returns id of the pressed button or -1 if escaped [ static ]
134 */
135 int QAD_MessageBox::info3 ( QWidget* parent, const QString& caption, const QString& text,
136                        const QString& textButton0, const QString& textButton1,
137                        const QString& textButton2, int idButton0, int idButton1,
138                        int idButton2, int idDefault )
139 {
140     if ( idDefault == idButton0 ) idDefault = 0;
141     else if ( idDefault == idButton1 ) idDefault = 1;
142     else if ( idDefault == idButton2 ) idDefault = 2;
143     else idDefault = 0;
144     
145     int ret = QMessageBox::information ( parent, caption, text, textButton0,
146             textButton1, textButton2, idDefault );
147     qApp->processEvents();  /* update desktop */
148     switch ( ret ) 
149     {
150         case 0: return idButton0;
151         case 1: return idButton1;    
152         case 2: return idButton2;
153     }
154     return -1;   
155 }
156
157 /*!
158     Shows warning message box with three buttons.
159     Returns id of the pressed button or -1 if escaped [ static ]
160 */
161 int QAD_MessageBox::warn3 ( QWidget* parent, const QString& caption, const QString& text,
162                        const QString& textButton0, const QString& textButton1,
163                        const QString& textButton2, int idButton0, int idButton1,
164                        int idButton2, int idDefault )
165 {
166     if ( idDefault == idButton0 ) idDefault = 0;
167     else if ( idDefault == idButton1 ) idDefault = 1;
168     else if ( idDefault == idButton2 ) idDefault = 2;
169     else idDefault = 0;
170     
171     int ret = QMessageBox::warning ( parent, caption, text, textButton0,
172             textButton1, textButton2, idDefault );
173     qApp->processEvents();  /* update desktop */
174     switch ( ret ) 
175     {
176         case 0: return idButton0;
177         case 1: return idButton1;    
178         case 2: return idButton2;
179     }
180     return -1;   
181 }
182
183 /*!
184     Shows error message box with three buttons.
185     Returns id of the pressed button or -1 if escaped [ static ]
186 */
187 int QAD_MessageBox::error3 ( QWidget* parent, const QString& caption, const QString& text,
188                        const QString& textButton0, const QString& textButton1,
189                        const QString& textButton2, int idButton0, int idButton1,
190                        int idButton2, int idDefault )
191 {
192     if ( idDefault == idButton0 ) idDefault = 0;
193     else if ( idDefault == idButton1 ) idDefault = 1;
194     else if ( idDefault == idButton2 ) idDefault = 2;
195     else idDefault = 0;
196
197     int ret = QMessageBox::critical ( parent, caption, text, textButton0,
198             textButton1, textButton2, idDefault );
199     qApp->processEvents();  /* update desktop */
200     switch ( ret ) 
201     {
202         case 0: return idButton0;
203         case 1: return idButton1;    
204         case 2: return idButton2;
205     }
206     return -1;   
207 }