Salome HOME
Popup item "Refresh"
[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 QTabBar;
15 class QPainter;
16 class QSplitter;
17 class QPushButton;
18 class QWidgetStack;
19
20 class QtxWorkstackArea;
21 class QtxWorkstackDrag;
22 class QtxWorkstackChild;
23 class QtxWorkstackTabBar;
24
25 class QTX_EXPORT QtxWorkstack : public QWidget
26 {
27   Q_OBJECT
28
29   enum { SplitVertical, SplitHorizontal, Close };
30
31 public:
32   QtxWorkstack( QWidget* = 0 );
33   virtual ~QtxWorkstack();
34
35   QWidgetList         windowList() const;
36   QWidgetList         splitWindowList() const;
37
38   QWidget*            activeWindow() const;
39
40   void                split( const int );
41
42 signals:
43   void                windowActivated( QWidget* );
44
45 public slots:
46   void                splitVertical();
47   void                splitHorizontal();
48
49 private slots:
50   void                onPopupActivated( int );
51   void                onDestroyed( QObject* );
52   void                onWindowActivated( QWidget* );
53   void                onContextMenuRequested( QPoint );
54   void                onDeactivated( QtxWorkstackArea* );
55
56 protected:
57   virtual void        childEvent( QChildEvent* );
58   virtual void        customEvent( QCustomEvent* );
59
60 private:
61   QSplitter*          splitter( QtxWorkstackArea* ) const;
62   void                splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
63   void                areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
64
65   QSplitter*          wrapSplitter( QtxWorkstackArea* );
66   void                insertWidget( QWidget*, QWidget*, QWidget* );
67
68   QtxWorkstackArea*   areaAt( const QPoint& ) const;
69
70   QtxWorkstackArea*   targetArea();
71   QtxWorkstackArea*   activeArea() const;
72   QtxWorkstackArea*   currentArea() const;
73
74   void                setActiveArea( QtxWorkstackArea* );
75   QtxWorkstackArea*   neighbourArea( QtxWorkstackArea* ) const;
76
77   QtxWorkstackArea*   createArea( QWidget* ) const;
78
79   void                updateState();
80   void                updateState( QSplitter* );
81
82 private:
83   QWidget*            myWin;
84   QtxWorkstackArea*   myArea;
85   QSplitter*          mySplit;
86
87   friend class QtxWorkstackArea;
88   friend class QtxWorkstackDrag;
89 };
90
91 class QtxWorkstackArea : public QWidget
92 {
93   Q_OBJECT
94
95 public:
96   QtxWorkstackArea( QWidget* );
97   virtual ~QtxWorkstackArea();
98
99   bool                isEmpty() const;
100
101   void                insertWidget( QWidget*, const int = -1 );
102   void                removeWidget( QWidget* );
103
104   QWidget*            activeWidget() const;
105   void                setActiveWidget( QWidget* );
106
107   bool                contains( QWidget* ) const;
108
109   QWidgetList         widgetList() const;
110
111   bool                isActive() const;
112   void                updateActiveState();
113
114   QtxWorkstack*       workstack() const;
115
116   virtual bool        eventFilter( QObject*, QEvent* );
117
118   QRect               floatRect() const;
119   QRect               floatTab( const int ) const;
120
121   int                 tabAt( const QPoint& ) const;
122
123 signals:
124   void                activated( QWidget* );
125   void                contextMenuRequested( QPoint );
126   void                deactivated( QtxWorkstackArea* );
127
128 public slots:
129   virtual void        show();
130   virtual void        hide();
131
132 private slots:
133   void                onClose();
134   void                onSelected( int );
135
136   void                onDragActiveTab();
137   void                onChildDestroyed( QObject* );
138   void                onChildShown( QtxWorkstackChild* );
139   void                onChildHided( QtxWorkstackChild* );
140   void                onChildActivated( QtxWorkstackChild* );
141   void                onChildCaptionChanged( QtxWorkstackChild* );
142
143 protected:
144   virtual void        customEvent( QCustomEvent* );
145   virtual void        focusInEvent( QFocusEvent* );
146   virtual void        mousePressEvent( QMouseEvent* );
147
148 private:
149   enum { ActivateEvent = QEvent::User, FocusEvent, RemoveEvent };
150
151 private:
152   void                updateState();
153   void                updateCurrent();
154   void                updateTab( QWidget* );
155
156   QWidget*            widget( const int ) const;
157   int                 widgetId( QWidget* ) const;
158   bool                widgetVisibility( QWidget* ) const;
159
160   void                setWidgetActive( QWidget* );
161   void                setWidgetShown( QWidget*, const bool );
162
163   int                 generateId() const;
164
165   bool                isBlocked( QWidget* ) const;
166   void                setBlocked( QWidget*, const bool );
167
168   QtxWorkstackChild*  child( QWidget* ) const;
169
170 private:
171   typedef QMap<QWidget*, bool>               BlockMap;
172   typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
173   typedef struct { int id; bool vis; }       WidgetInfo;
174   typedef QMap<QWidget*, WidgetInfo>         WidgetInfoMap;
175
176 private:
177   QtxWorkstackTabBar* myBar;
178   QPushButton*        myClose;
179   QWidgetStack*       myStack;
180
181   QWidgetList         myList;
182   WidgetInfoMap       myInfo;
183   ChildMap            myChild;
184   BlockMap            myBlock;
185 };
186
187 class QtxWorkstackChild : public QHBox
188 {
189   Q_OBJECT
190
191 public:
192   QtxWorkstackChild( QWidget*, QWidget* = 0 );
193   virtual ~QtxWorkstackChild();
194
195   QWidget*            widget() const;
196
197   virtual bool        eventFilter( QObject*, QEvent* );
198
199 signals:
200   void                shown( QtxWorkstackChild* );
201   void                hided( QtxWorkstackChild* );
202   void                activated( QtxWorkstackChild* );
203   void                captionChanged( QtxWorkstackChild* );
204
205 private slots:
206   void                onDestroyed( QObject* );
207
208 protected:
209   virtual void        childEvent( QChildEvent* );
210
211 private:
212   QWidget*            myWidget;
213 };
214
215 class QtxWorkstackTabBar : public QTabBar
216 {
217   Q_OBJECT
218
219 public:
220   QtxWorkstackTabBar( QWidget* = 0 );
221   virtual ~QtxWorkstackTabBar();
222
223   QRect               tabRect( const int ) const;
224
225   void                setActive( const bool );
226
227 signals:
228   void                dragActiveTab();
229   void                contextMenuRequested( QPoint );
230
231 protected:
232   virtual void        mouseMoveEvent( QMouseEvent* );
233   virtual void        mousePressEvent( QMouseEvent* );
234   virtual void        mouseReleaseEvent( QMouseEvent* );
235   virtual void        contextMenuEvent( QContextMenuEvent* );
236
237   virtual void        paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
238
239 private:
240   int                 myId;
241 };
242
243 class QtxWorkstackDrag : public QObject
244 {
245   Q_OBJECT
246
247 public:
248   QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
249   virtual ~QtxWorkstackDrag();
250
251   virtual bool        eventFilter( QObject*, QEvent* );
252
253 private:
254   void                dropWidget();
255
256   void                updateTarget( const QPoint& );
257   QtxWorkstackArea*   detectTarget( const QPoint&, int& ) const;
258   void                setTarget( QtxWorkstackArea*, const int );
259
260   void                drawRect();
261   void                endDrawRect();
262   void                startDrawRect();
263
264 private:
265   QtxWorkstack*       myWS;
266   QtxWorkstackChild*  myChild;
267
268   int                 myTab;
269   QtxWorkstackArea*   myArea;
270   QPainter*           myPainter;
271 };
272
273 #endif