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