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