Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Qtx / QtxDialog.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      QtxDialog.h
23 // Author:    Sergey TELKOV
24 //
25 #ifndef QTXDIALOG_H
26 #define QTXDIALOG_H
27
28 #include "Qtx.h"
29
30 #include <QDialog>
31 #include <QMap>
32
33 class QFrame;
34 class QLabel;
35 class QAbstractButton;
36
37 #ifdef WIN32
38 #pragma warning( disable:4251 )
39 #endif
40
41 class QTX_EXPORT QtxDialog : public QDialog
42 {
43   Q_OBJECT
44
45   class Area;
46   class Border;
47
48 public:
49   //! Buttons alignment type
50   typedef enum { Position,          //!< buttons are placed according their position
51                  Expand,            //!< buttons occupy all available space
52                  Uniform            //!< buttons are uniformly placed in the area
53   } PlacePolicy;
54   //! Buttons area
55   typedef enum { TopArea,           //!< horizontal area at the top side of the dialog box
56                  BottomArea,        //!< horizontal area at the bottom side of the dialog box
57                  LeftArea,          //!< vertical area at the left side of the dialog box
58                  RightArea          //!< vertical area at the right side of the dialog box
59   } ButtonArea;
60   //! Button position
61   typedef enum { Left,              //!< set button left-most
62                  Right,             //!< set button right-most
63                  Center,            //!< place button in the center
64                  Top = Left,        //!< set button top-most
65                  Bottom = Right     //!< set button bottom-most
66   } ButtonPosition;
67   //! Button ID flags
68   typedef enum { None      = 0x00000000,                      //!< no button used
69                  OK        = 0x00000001,                      //!< OK button
70                  Apply     = 0x00000002,                      //!< Apply button
71                  Cancel    = 0x00000004,                      //!< Cancel button
72                  Yes       = 0x00000008,                      //!< Yes button
73                  No        = 0x00000010,                      //!< No button
74                  Close     = 0x00000020,                      //!< Close button
75                  Help      = 0x00000040,                      //!< Help button
76                  OKCancel  = OK  | Cancel,                    //!< OK & Cancel button
77                  YesNo     = Yes | No,                        //!< Yes & No buttons
78                  Standard  = OK  | Cancel | Help,             //!< OK, Cancel & Help buttons
79                  All       = Standard | YesNo | Apply | Close //!< all buttons
80   } ButtonFlags;
81   //! Dialog box flags
82   typedef enum { Accept    = 0x000001, //!< allow dialog box accepting control
83                  Reject    = 0x000002, //!< allow dialog box rejecting control
84                  AlignOnce = 0x000004, //!< align dialog box only when it is first time shown
85                  SetFocus  = 0x000008  //!< allow to set focus on dialog box when it is shown (user can use setFocusProxy() and specify own initial focus widget)
86   } DialogFlags;
87   
88 public:
89   QtxDialog( QWidget* = 0, bool = false, bool = false, const int = Standard, Qt::WindowFlags = 0 );
90   virtual ~QtxDialog();
91   
92   void             setDialogFlags( const int );
93   void             clearDialogFlags( const int );
94   bool             testDialogFlags( const int ) const;
95   
96   void             setButtonFlags( const int );
97   void             clearButtonFlags( const int );
98   bool             testButtonFlags( const int ) const;
99   
100   int              buttonPosition( const int ) const;
101   void             setButtonPosition( const int, const int = -1 );
102   void             setPlacePosition( const int, const int );
103   
104   int              placePolicy( const int ) const;
105   void             setPlacePolicy( const int, const int );
106   void             setButtonPlace( const int, const int );
107   
108   QString          buttonText( const int );
109   void             setButtonText( const int, const QString& text );
110   
111   void             setButtonFocus( const int );
112   bool             hasButtonFocus( const int ) const;
113   
114   bool             isButtonEnabled( const int ) const;
115   void             setButtonEnabled( const bool, const int );
116   
117   bool             isBorderEnabled( const int ) const;
118   void             setBorderEnabled( const bool, const int );
119   
120   void             removeButton( const int );
121   int              insertButton( const QString&, const int = BottomArea );
122   
123   QIntList         userButtonIds() const;
124   QAbstractButton* userButton( const int ) const;
125   
126   uint             setAlignment( uint align );
127   static  void     setUnits( QLabel*, const QString& );
128   
129 signals:
130   void             dlgButton( int );
131   void             dlgParamChanged();
132   
133   void             dlgHelp();
134   void             dlgApply();
135   
136   void             dlgOk();
137   void             dlgNo();
138   void             dlgYes();
139   void             dlgClose();
140   void             dlgCancel();
141   
142 public slots:
143   void             update();
144   virtual void     setVisible( bool );
145
146 protected slots:
147   virtual void     accept();
148   virtual void     reject();
149
150 private slots:
151   void             onAccept();
152   void             onReject();
153   void             onButton();
154   void             onSizeGripDestroyed();
155   void             onDestroyed( QObject* );
156
157 protected:
158   typedef QMap<int, QAbstractButton*> ButtonMap;   //!< button map
159
160 protected:
161   QFrame*          mainFrame() const;
162   
163   virtual bool     acceptData() const;
164   virtual bool     rejectData() const;
165   
166   virtual QAbstractButton* createButton( QWidget* );
167   
168   QAbstractButton* button( const int ) const;
169   ButtonMap        buttons( const int = All ) const;
170   int              buttonId( const QAbstractButton* ) const;
171   int              buttonPosition( QAbstractButton* ) const;
172   
173   virtual void     showEvent( QShowEvent* );
174   virtual void     hideEvent( QHideEvent* );
175   virtual void     closeEvent( QCloseEvent* );
176   virtual void     childEvent( QChildEvent* );
177   virtual void     keyPressEvent( QKeyEvent* );
178   
179 private:
180   void             adjustButtons();
181   void             emitSignal();
182   
183 private:
184   typedef QMap<int, Area*> AreaMap;        //!< button area map
185   typedef QMap<int, int>   PositionMap;    //!< button position map
186   
187   friend class Area;
188
189 private:
190   AreaMap          myArea;                 //!< buttons areas map
191   ButtonMap        myButton;               //!< buttons map
192   PositionMap      myPosition;             //!< buttons position map
193   
194   bool             myInited;               //!< dialog's "initialized" flag
195   const QObject*   mySender;               //!< signal sender
196   uint             myAlignment;            //!< dialog box alignment type
197   QFrame*          myMainFrame;            //!< main frame
198   int              myButtonFlags;          //!< button flags
199   int              myDialogFlags;          //!< dialog flags
200 };
201
202 #ifdef WIN32
203 #pragma warning( default:4251 )
204 #endif
205
206 #endif