]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxWorkstack.h
Salome HOME
Windows porting
[modules/gui.git] / src / Qtx / QtxWorkstack.h
1 // File:      QtxWorkstack.h
2 // Author:    Sergey TELKOV
3
4 #ifndef QTXWORKSTACK_H
5 #define QTXWORKSTACK_H
6
7 #include "Qtx.h"
8
9 #include <qhbox.h>
10 #include <qwidget.h>
11 #include <qtabbar.h>
12 #include <qwidgetlist.h>
13
14 class QAction;
15 class QTabBar;
16 class QPainter;
17 class QSplitter;
18 class QPushButton;
19 class QWidgetStack;
20
21 class QtxWorkstackArea;
22 class QtxWorkstackDrag;
23 class QtxWorkstackChild;
24 class QtxWorkstackTabBar;
25
26 #ifdef WIN32
27 #pragma warning( disable:4251 )
28 #endif
29
30 class QTX_EXPORT QtxWorkstack : public QWidget
31 {
32   Q_OBJECT
33
34 public:
35   enum { SplitVertical, SplitHorizontal, Close };
36     
37   enum SplitType {
38     SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one
39     SPLIT_AT,   //!< widgets before a given widget stays in they workarea, others are moved into a new one
40     SPLIT_MOVE  //!< given widget is moved into a new workarea, others stay in an old one
41   };
42
43 public:
44   QtxWorkstack( QWidget* = 0 );
45   virtual ~QtxWorkstack();
46
47   QWidgetList         windowList() const;
48   QWidgetList         splitWindowList() const;
49
50   QWidget*            activeWindow() const;
51
52   int                 accel( const int ) const;
53   void                setAccel( const int, const int );
54
55   void                split( const int );
56
57   // STV: Useless function. wid->setFocus() should be used instead.
58   // void OnTop( QWidget* wid);
59
60   void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
61   void Attract( QWidget* wid1, QWidget* wid2, const bool all );
62   void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
63   void SetRelativePositionInSplitter( QWidget* wid, const double pos );
64
65 signals:
66   void                windowActivated( QWidget* );
67
68 public slots:
69   void                splitVertical();
70   void                splitHorizontal();
71   
72 private slots:
73   void                onCloseWindow();
74   void                onDestroyed( QObject* );
75   void                onWindowActivated( QWidget* );
76   void                onContextMenuRequested( QPoint );
77   void                onDeactivated( QtxWorkstackArea* );
78
79 protected:
80   virtual void        childEvent( QChildEvent* );
81   virtual void        customEvent( QCustomEvent* );
82
83 private:
84   QSplitter*          splitter( QtxWorkstackArea* ) const;
85   void                splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
86   void                areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
87
88   QSplitter*          wrapSplitter( QtxWorkstackArea* );
89   void                insertWidget( QWidget*, QWidget*, QWidget* );
90
91   QtxWorkstackArea*   areaAt( const QPoint& ) const;
92
93   QtxWorkstackArea*   targetArea();
94   QtxWorkstackArea*   activeArea() const;
95   QtxWorkstackArea*   currentArea() const;
96
97   void                setActiveArea( QtxWorkstackArea* );
98   QtxWorkstackArea*   neighbourArea( QtxWorkstackArea* ) const;
99
100   QtxWorkstackArea*   createArea( QWidget* ) const;
101
102   void                updateState();
103   void                updateState( QSplitter* );
104
105   void                distributeSpace( QSplitter* ) const;
106   int                 setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
107                                                            const int need_pos, const int splitter_pos );
108
109 private:
110   QWidget*            myWin;
111   QtxWorkstackArea*   myArea;
112   QSplitter*          mySplit;
113
114   QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
115
116   friend class QtxWorkstackArea;
117   friend class QtxWorkstackDrag;
118 };
119
120 class QtxWorkstackArea : public QWidget
121 {
122   Q_OBJECT
123
124 public:
125   QtxWorkstackArea( QWidget* );
126   virtual ~QtxWorkstackArea();
127
128   bool                isEmpty() const;
129
130   void                insertWidget( QWidget*, const int = -1 );
131   void                removeWidget( QWidget* );
132
133   QWidget*            activeWidget() const;
134   void                setActiveWidget( QWidget* );
135
136   bool                contains( QWidget* ) const;
137
138   QWidgetList         widgetList() const;
139
140   bool                isActive() const;
141   void                updateActiveState();
142
143   QtxWorkstack*       workstack() const;
144
145   virtual bool        eventFilter( QObject*, QEvent* );
146
147   QRect               floatRect() const;
148   QRect               floatTab( const int ) const;
149
150   int                 tabAt( const QPoint& ) const;
151
152 signals:
153   void                activated( QWidget* );
154   void                contextMenuRequested( QPoint );
155   void                deactivated( QtxWorkstackArea* );
156
157 public slots:
158   virtual void        show();
159   virtual void        hide();
160
161 private slots:
162   void                onClose();
163   void                onSelected( int );
164
165   void                onDragActiveTab();
166   void                onChildDestroyed( QObject* );
167   void                onChildShown( QtxWorkstackChild* );
168   void                onChildHided( QtxWorkstackChild* );
169   void                onChildActivated( QtxWorkstackChild* );
170   void                onChildCaptionChanged( QtxWorkstackChild* );
171
172 protected:
173   virtual void        customEvent( QCustomEvent* );
174   virtual void        focusInEvent( QFocusEvent* );
175   virtual void        mousePressEvent( QMouseEvent* );
176
177 private:
178   enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
179
180 private:
181   void                updateState();
182   void                updateCurrent();
183   void                updateTab( QWidget* );
184
185   QWidget*            widget( const int ) const;
186   int                 widgetId( QWidget* ) const;
187   bool                widgetVisibility( QWidget* ) const;
188
189   void                setWidgetActive( QWidget* );
190   void                setWidgetShown( QWidget*, const bool );
191
192   int                 generateId() const;
193
194   bool                isBlocked( QWidget* ) const;
195   void                setBlocked( QWidget*, const bool );
196
197   QtxWorkstackChild*  child( QWidget* ) const;
198
199 private:
200   struct WidgetInfo
201   {
202     WidgetInfo() : id( 0 ), vis( false ) {}
203     int id; bool vis;
204   };
205
206   typedef QMap<QWidget*, bool>               BlockMap;
207   typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
208   typedef QMap<QWidget*, WidgetInfo>         WidgetInfoMap;
209
210 private:
211   QtxWorkstackTabBar* myBar;
212   QPushButton*        myClose;
213   QWidgetStack*       myStack;
214
215   QWidgetList         myList;
216   WidgetInfoMap       myInfo;
217   ChildMap            myChild;
218   BlockMap            myBlock;
219 };
220
221 class QtxWorkstackChild : public QHBox
222 {
223   Q_OBJECT
224
225 public:
226   QtxWorkstackChild( QWidget*, QWidget* = 0 );
227   virtual ~QtxWorkstackChild();
228
229   QWidget*            widget() const;
230
231   virtual bool        eventFilter( QObject*, QEvent* );
232
233 signals:
234   void                shown( QtxWorkstackChild* );
235   void                hided( QtxWorkstackChild* );
236   void                activated( QtxWorkstackChild* );
237   void                captionChanged( QtxWorkstackChild* );
238
239 private slots:
240   void                onDestroyed( QObject* );
241
242 protected:
243   virtual void        childEvent( QChildEvent* );
244
245 private:
246   QWidget*            myWidget;
247 };
248
249 class QtxWorkstackTabBar : public QTabBar
250 {
251   Q_OBJECT
252
253 public:
254   QtxWorkstackTabBar( QWidget* = 0 );
255   virtual ~QtxWorkstackTabBar();
256
257   QRect               tabRect( const int ) const;
258
259   void                setActive( const bool );
260
261 signals:
262   void                dragActiveTab();
263   void                contextMenuRequested( QPoint );
264
265 protected:
266   virtual void        mouseMoveEvent( QMouseEvent* );
267   virtual void        mousePressEvent( QMouseEvent* );
268   virtual void        mouseReleaseEvent( QMouseEvent* );
269   virtual void        contextMenuEvent( QContextMenuEvent* );
270
271   virtual void        paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
272
273 private:
274   int                 myId;
275 };
276
277 class QtxWorkstackDrag : public QObject
278 {
279   Q_OBJECT
280
281 public:
282   QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
283   virtual ~QtxWorkstackDrag();
284
285   virtual bool        eventFilter( QObject*, QEvent* );
286
287 private:
288   void                dropWidget();
289
290   void                updateTarget( const QPoint& );
291   QtxWorkstackArea*   detectTarget( const QPoint&, int& ) const;
292   void                setTarget( QtxWorkstackArea*, const int );
293
294   void                drawRect();
295   void                endDrawRect();
296   void                startDrawRect();
297
298 private:
299   QtxWorkstack*       myWS;
300   QtxWorkstackChild*  myChild;
301
302   int                 myTab;
303   QtxWorkstackArea*   myArea;
304   QPainter*           myPainter;
305   
306 };
307
308 #ifdef WIN32
309 #pragma warning( default:4251 )
310 #endif
311
312 #endif