Salome HOME
Comments moved into cxx-files. Method QtxWorkstack::onTop() removed.
[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   typedef QMap<QWidget*, bool>               BlockMap;
201   typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
202   typedef struct { int id; bool vis; }       WidgetInfo;
203   typedef QMap<QWidget*, WidgetInfo>         WidgetInfoMap;
204
205 private:
206   QtxWorkstackTabBar* myBar;
207   QPushButton*        myClose;
208   QWidgetStack*       myStack;
209
210   QWidgetList         myList;
211   WidgetInfoMap       myInfo;
212   ChildMap            myChild;
213   BlockMap            myBlock;
214 };
215
216 class QtxWorkstackChild : public QHBox
217 {
218   Q_OBJECT
219
220 public:
221   QtxWorkstackChild( QWidget*, QWidget* = 0 );
222   virtual ~QtxWorkstackChild();
223
224   QWidget*            widget() const;
225
226   virtual bool        eventFilter( QObject*, QEvent* );
227
228 signals:
229   void                shown( QtxWorkstackChild* );
230   void                hided( QtxWorkstackChild* );
231   void                activated( QtxWorkstackChild* );
232   void                captionChanged( QtxWorkstackChild* );
233
234 private slots:
235   void                onDestroyed( QObject* );
236
237 protected:
238   virtual void        childEvent( QChildEvent* );
239
240 private:
241   QWidget*            myWidget;
242 };
243
244 class QtxWorkstackTabBar : public QTabBar
245 {
246   Q_OBJECT
247
248 public:
249   QtxWorkstackTabBar( QWidget* = 0 );
250   virtual ~QtxWorkstackTabBar();
251
252   QRect               tabRect( const int ) const;
253
254   void                setActive( const bool );
255
256 signals:
257   void                dragActiveTab();
258   void                contextMenuRequested( QPoint );
259
260 protected:
261   virtual void        mouseMoveEvent( QMouseEvent* );
262   virtual void        mousePressEvent( QMouseEvent* );
263   virtual void        mouseReleaseEvent( QMouseEvent* );
264   virtual void        contextMenuEvent( QContextMenuEvent* );
265
266   virtual void        paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
267
268 private:
269   int                 myId;
270 };
271
272 class QtxWorkstackDrag : public QObject
273 {
274   Q_OBJECT
275
276 public:
277   QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
278   virtual ~QtxWorkstackDrag();
279
280   virtual bool        eventFilter( QObject*, QEvent* );
281
282 private:
283   void                dropWidget();
284
285   void                updateTarget( const QPoint& );
286   QtxWorkstackArea*   detectTarget( const QPoint&, int& ) const;
287   void                setTarget( QtxWorkstackArea*, const int );
288
289   void                drawRect();
290   void                endDrawRect();
291   void                startDrawRect();
292
293 private:
294   QtxWorkstack*       myWS;
295   QtxWorkstackChild*  myChild;
296
297   int                 myTab;
298   QtxWorkstackArea*   myArea;
299   QPainter*           myPainter;
300   
301 };
302
303 #ifdef WIN32
304 #pragma warning( default:4251 )
305 #endif
306
307 #endif