Salome HOME
The slot "onTextChanged" is disconnect, but value is updated in method value().
[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   void                distributeSpace( QSplitter* ) const;
83
84 private:
85   QWidget*            myWin;
86   QtxWorkstackArea*   myArea;
87   QSplitter*          mySplit;
88
89   friend class QtxWorkstackArea;
90   friend class QtxWorkstackDrag;
91 };
92
93 class QtxWorkstackArea : public QWidget
94 {
95   Q_OBJECT
96
97 public:
98   QtxWorkstackArea( QWidget* );
99   virtual ~QtxWorkstackArea();
100
101   bool                isEmpty() const;
102
103   void                insertWidget( QWidget*, const int = -1 );
104   void                removeWidget( QWidget* );
105
106   QWidget*            activeWidget() const;
107   void                setActiveWidget( QWidget* );
108
109   bool                contains( QWidget* ) const;
110
111   QWidgetList         widgetList() const;
112
113   bool                isActive() const;
114   void                updateActiveState();
115
116   QtxWorkstack*       workstack() const;
117
118   virtual bool        eventFilter( QObject*, QEvent* );
119
120   QRect               floatRect() const;
121   QRect               floatTab( const int ) const;
122
123   int                 tabAt( const QPoint& ) const;
124
125 signals:
126   void                activated( QWidget* );
127   void                contextMenuRequested( QPoint );
128   void                deactivated( QtxWorkstackArea* );
129
130 public slots:
131   virtual void        show();
132   virtual void        hide();
133
134 private slots:
135   void                onClose();
136   void                onSelected( int );
137
138   void                onDragActiveTab();
139   void                onChildDestroyed( QObject* );
140   void                onChildShown( QtxWorkstackChild* );
141   void                onChildHided( QtxWorkstackChild* );
142   void                onChildActivated( QtxWorkstackChild* );
143   void                onChildCaptionChanged( QtxWorkstackChild* );
144
145 protected:
146   virtual void        customEvent( QCustomEvent* );
147   virtual void        focusInEvent( QFocusEvent* );
148   virtual void        mousePressEvent( QMouseEvent* );
149
150 private:
151   enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
152
153 private:
154   void                updateState();
155   void                updateCurrent();
156   void                updateTab( QWidget* );
157
158   QWidget*            widget( const int ) const;
159   int                 widgetId( QWidget* ) const;
160   bool                widgetVisibility( QWidget* ) const;
161
162   void                setWidgetActive( QWidget* );
163   void                setWidgetShown( QWidget*, const bool );
164
165   int                 generateId() const;
166
167   bool                isBlocked( QWidget* ) const;
168   void                setBlocked( QWidget*, const bool );
169
170   QtxWorkstackChild*  child( QWidget* ) const;
171
172 private:
173   typedef QMap<QWidget*, bool>               BlockMap;
174   typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
175   typedef struct { int id; bool vis; }       WidgetInfo;
176   typedef QMap<QWidget*, WidgetInfo>         WidgetInfoMap;
177
178 private:
179   QtxWorkstackTabBar* myBar;
180   QPushButton*        myClose;
181   QWidgetStack*       myStack;
182
183   QWidgetList         myList;
184   WidgetInfoMap       myInfo;
185   ChildMap            myChild;
186   BlockMap            myBlock;
187 };
188
189 class QtxWorkstackChild : public QHBox
190 {
191   Q_OBJECT
192
193 public:
194   QtxWorkstackChild( QWidget*, QWidget* = 0 );
195   virtual ~QtxWorkstackChild();
196
197   QWidget*            widget() const;
198
199   virtual bool        eventFilter( QObject*, QEvent* );
200
201 signals:
202   void                shown( QtxWorkstackChild* );
203   void                hided( QtxWorkstackChild* );
204   void                activated( QtxWorkstackChild* );
205   void                captionChanged( QtxWorkstackChild* );
206
207 private slots:
208   void                onDestroyed( QObject* );
209
210 protected:
211   virtual void        childEvent( QChildEvent* );
212
213 private:
214   QWidget*            myWidget;
215 };
216
217 class QtxWorkstackTabBar : public QTabBar
218 {
219   Q_OBJECT
220
221 public:
222   QtxWorkstackTabBar( QWidget* = 0 );
223   virtual ~QtxWorkstackTabBar();
224
225   QRect               tabRect( const int ) const;
226
227   void                setActive( const bool );
228
229 signals:
230   void                dragActiveTab();
231   void                contextMenuRequested( QPoint );
232
233 protected:
234   virtual void        mouseMoveEvent( QMouseEvent* );
235   virtual void        mousePressEvent( QMouseEvent* );
236   virtual void        mouseReleaseEvent( QMouseEvent* );
237   virtual void        contextMenuEvent( QContextMenuEvent* );
238
239   virtual void        paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
240
241 private:
242   int                 myId;
243 };
244
245 class QtxWorkstackDrag : public QObject
246 {
247   Q_OBJECT
248
249 public:
250   QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
251   virtual ~QtxWorkstackDrag();
252
253   virtual bool        eventFilter( QObject*, QEvent* );
254
255 private:
256   void                dropWidget();
257
258   void                updateTarget( const QPoint& );
259   QtxWorkstackArea*   detectTarget( const QPoint&, int& ) const;
260   void                setTarget( QtxWorkstackArea*, const int );
261
262   void                drawRect();
263   void                endDrawRect();
264   void                startDrawRect();
265
266 private:
267   QtxWorkstack*       myWS;
268   QtxWorkstackChild*  myChild;
269
270   int                 myTab;
271   QtxWorkstackArea*   myArea;
272   QPainter*           myPainter;
273 };
274
275 #endif