Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / Qtx / QtxDialog.h
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/ or email : webmaster.salome@opencascade.com
18 //
19 // File:      QtxDialog.hxx
20 // Author:    Sergey TELKOV
21
22 #ifndef QTXDIALOG_H
23 #define QTXDIALOG_H
24
25 #include "Qtx.h"
26
27 #include <qmap.h>
28 #include <qdialog.h>
29 #include <qvaluelist.h>
30
31 class QFrame;
32 class QLabel;
33 class QButton;
34
35 #ifdef WIN32
36 #pragma warning( disable:4251 )
37 #endif
38
39 class QTX_EXPORT QtxDialog : public QDialog
40 {
41           Q_OBJECT
42
43           class Area;
44           class Border;
45
46 public:
47     typedef enum { Position, Expand, Uniform } PlacePolicy;
48     typedef enum { TopArea, BottomArea, LeftArea, RightArea } ButtonArea;
49     typedef enum { Left, Right, Center, Top = Left, Bottom = Right } ButtonPosition;
50
51     typedef enum { None      = 0x00000000,
52                    OK        = 0x00000001,
53                    Apply     = 0x00000002,
54                    Cancel    = 0x00000004,
55                    Yes       = 0x00000008,
56                    No        = 0x00000010,
57                    Close     = 0x00000020,
58                    Help      = 0x00000040,
59                    OKCancel  = OK  | Cancel,
60                    YesNo     = Yes | No,
61                    Standard  = OK  | Cancel | Help,
62                    All       = Standard | YesNo | Apply | Close } ButtonFlags;
63
64     typedef enum { Accept    = 0x000001,
65                                            Reject    = 0x000002,
66                                            AlignOnce = 0x000004,
67                    SetFocus  = 0x000008 } DialogFlags;
68
69 public:
70     QtxDialog( QWidget* = 0, const char* = 0, bool = false,
71                bool = false, const int = Standard, WFlags = 0 );
72     virtual ~QtxDialog();
73
74     void             setDialogFlags( const int );
75     void             clearDialogFlags( const int );
76     bool             testDialogFlags( const int ) const;
77
78     void             setButtonFlags( const int );
79     void             clearButtonFlags( const int );
80     bool             testButtonFlags( const int ) const;
81
82     int              buttonPosition( const int ) const;
83     void             setButtonPosition( const int, const int = -1 );
84     void             setPlacePosition( const int, const int );
85
86     int              placePolicy( const int ) const;
87     void             setPlacePolicy( const int, const int );
88     void             setButtonPlace( const int, const int );
89
90     QString          buttonText( const int );
91     void             setButtonText( const int, const QString& text );
92
93     void             setButtonFocus( const int );
94     bool             hasButtonFocus( const int ) const;
95
96     bool             isButtonEnabled( const int ) const;
97     void             setButtonEnabled( const bool, const int );
98
99     bool             isBorderEnabled( const int ) const;
100     void             setBorderEnabled( const bool, const int );
101
102     void             removeButton( const int );
103     int              insertButton( const QString&, const int = BottomArea );
104
105     QValueList<int>  userButtonIds() const;
106     QButton*         userButton( const int ) const;
107
108     virtual void     show();
109     virtual void     hide();
110
111     uint             setAlignment( uint align );
112     static  void     setUnits( QLabel*, const QString& );
113
114 signals:
115     void             dlgButton( int );
116     void             dlgParamChanged();
117
118     void             dlgHelp();
119     void             dlgApply();
120
121     void             dlgOk();
122     void             dlgNo();
123     void             dlgYes();
124     void             dlgClose();
125     void             dlgCancel();
126
127 public slots:
128     void             update();
129
130 protected slots:
131     virtual void     accept();
132     virtual void     reject();
133
134 private slots:
135     void             onAccept();
136     void             onReject();
137     void             onButton();
138     void             onSizeGripDestroyed();
139     void             onDestroyed( QObject* );
140
141 protected:
142     typedef QMap<int, QButton*> ButtonMap;
143
144 protected:
145     QFrame*          mainFrame() const;
146
147     virtual bool     acceptData() const;
148     virtual bool     rejectData() const;
149
150     virtual QButton* createButton( QWidget* );
151
152     QButton*         button( const int ) const;
153     ButtonMap        buttons( const int = All ) const;
154     int              buttonId( const QButton* ) const;
155     int              buttonPosition( QButton* ) const;
156
157     virtual void     showEvent( QShowEvent* );
158     virtual void     hideEvent( QHideEvent* );
159     virtual void     closeEvent( QCloseEvent* );
160     virtual void     childEvent( QChildEvent* );
161     virtual void     keyPressEvent( QKeyEvent* );
162
163 private:
164           void             adjustButtons();
165     void             emitSignal();
166
167 private:
168     typedef QMap<int, Area*> AreaMap;
169     typedef QMap<int, int>   PositionMap;
170
171     friend class Area;
172
173 private:
174     AreaMap          myArea;
175     ButtonMap        myButton;
176     PositionMap      myPosition;
177
178     bool             myInited;
179     const QObject*   mySender;
180     uint             myAlignment;
181     QFrame*          myMainFrame;
182     int              myButtonFlags;
183     int              myDialogFlags;
184 };
185
186 #ifdef WIN32
187 #pragma warning( default:4251 )
188 #endif
189
190 #endif