]> SALOME platform Git repositories - modules/gui.git/blob - src/Qtx/QtxWorkstack.h
Salome HOME
Copyrights update
[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 signals:
85   void                windowActivated( QWidget* );
86
87 public slots:
88   void                splitVertical();
89   void                splitHorizontal();
90   
91 private slots:
92   void                onRename();
93   void                onCloseWindow();
94   void                onDestroyed( QObject* );
95   void                onWindowActivated( QWidget* );
96   void                onContextMenuRequested( QWidget*, QPoint );
97   void                onDeactivated( QtxWorkstackArea* );
98
99 protected:
100   virtual void        childEvent( QChildEvent* );
101   virtual void        customEvent( QCustomEvent* );
102
103 private:
104   QSplitter*          splitter( QtxWorkstackArea* ) const;
105   void                splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
106   void                areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
107
108   QSplitter*          wrapSplitter( QtxWorkstackArea* );
109   void                insertWidget( QWidget*, QWidget*, QWidget* );
110
111   QtxWorkstackArea*   areaAt( const QPoint& ) const;
112
113   QtxWorkstackArea*   targetArea();
114   QtxWorkstackArea*   activeArea() const;
115   QtxWorkstackArea*   currentArea() const;
116
117   void                setActiveArea( QtxWorkstackArea* );
118   QtxWorkstackArea*   neighbourArea( QtxWorkstackArea* ) const;
119
120   QtxWorkstackArea*   createArea( QWidget* ) const;
121
122   void                updateState();
123   void                updateState( QSplitter* );
124
125   void                distributeSpace( QSplitter* ) const;
126   int                 setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
127                                                            const int need_pos, const int splitter_pos );
128
129 private:
130   QWidget*            myWin;
131   QtxWorkstackArea*   myArea;
132   QSplitter*          mySplit;
133   QWidget*            myWorkWin;
134
135   QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
136
137   friend class QtxWorkstackArea;
138   friend class QtxWorkstackDrag;
139 };
140
141 class QtxWorkstackArea : public QWidget
142 {
143   Q_OBJECT
144
145 public:
146   QtxWorkstackArea( QWidget* );
147   virtual ~QtxWorkstackArea();
148
149   bool                isEmpty() const;
150
151   void                insertWidget( QWidget*, const int = -1 );
152   void                removeWidget( QWidget*, const bool = true );
153
154   QWidget*            activeWidget() const;
155   void                setActiveWidget( QWidget* );
156
157   bool                contains( QWidget* ) const;
158
159   QWidgetList         widgetList() const;
160
161   bool                isActive() const;
162   void                updateActiveState();
163
164   QtxWorkstack*       workstack() const;
165
166   virtual bool        eventFilter( QObject*, QEvent* );
167
168   QRect               floatRect() const;
169   QRect               floatTab( const int ) const;
170
171   int                 tabAt( const QPoint& ) const;
172
173 signals:
174   void                activated( QWidget* );
175   void                contextMenuRequested( QWidget*, QPoint );
176   void                deactivated( QtxWorkstackArea* );
177
178 public slots:
179   virtual void        show();
180   virtual void        hide();
181
182 private slots:
183   void                onClose();
184   void                onSelected( int );
185
186   void                onWidgetDestroyed();
187
188   void                onChildDestroyed( QObject* );
189   void                onChildShown( QtxWorkstackChild* );
190   void                onChildHided( QtxWorkstackChild* );
191   void                onChildActivated( QtxWorkstackChild* );
192   void                onChildCaptionChanged( QtxWorkstackChild* );
193
194   void                onDragActiveTab();
195   void                onContextMenuRequested( QPoint );
196
197 protected:
198   virtual void        customEvent( QCustomEvent* );
199   virtual void        focusInEvent( QFocusEvent* );
200   virtual void        mousePressEvent( QMouseEvent* );
201
202 private:
203   enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
204
205 private:
206   void                updateState();
207   void                updateCurrent();
208   void                updateTab( QWidget* );
209
210   QWidget*            widget( const int ) const;
211   int                 widgetId( QWidget* ) const;
212   bool                widgetVisibility( QWidget* ) const;
213
214   void                setWidgetActive( QWidget* );
215   void                setWidgetShown( QWidget*, const bool );
216
217   int                 generateId() const;
218
219   bool                isBlocked( QWidget* ) const;
220   void                setBlocked( QWidget*, const bool );
221
222   QtxWorkstackChild*  child( QWidget* ) const;
223
224 private:
225   struct WidgetInfo
226   {
227     WidgetInfo() : id( 0 ), vis( false ) {}
228     int id; bool vis;
229   };
230
231   typedef QMap<QWidget*, bool>               BlockMap;
232   typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
233   typedef QMap<QWidget*, WidgetInfo>         WidgetInfoMap;
234
235 private:
236   QtxWorkstackTabBar* myBar;
237   QPushButton*        myClose;
238   QWidgetStack*       myStack;
239
240   QWidgetList         myList;
241   WidgetInfoMap       myInfo;
242   ChildMap            myChild;
243   BlockMap            myBlock;
244 };
245
246 class QtxWorkstackChild : public QHBox
247 {
248   Q_OBJECT
249
250 public:
251   QtxWorkstackChild( QWidget*, QWidget* = 0 );
252   virtual ~QtxWorkstackChild();
253
254   QWidget*            widget() const;
255
256   virtual bool        eventFilter( QObject*, QEvent* );
257
258 signals:
259   void                shown( QtxWorkstackChild* );
260   void                hided( QtxWorkstackChild* );
261   void                activated( QtxWorkstackChild* );
262   void                captionChanged( QtxWorkstackChild* );
263
264 private slots:
265   void                onDestroyed( QObject* );
266
267 protected:
268   virtual void        childEvent( QChildEvent* );
269
270 private:
271   QWidget*            myWidget;
272 };
273
274 class QtxWorkstackTabBar : public QTabBar
275 {
276   Q_OBJECT
277
278 public:
279   QtxWorkstackTabBar( QWidget* = 0 );
280   virtual ~QtxWorkstackTabBar();
281
282   QRect               tabRect( const int ) const;
283
284   void                setActive( const bool );
285
286 signals:
287   void                dragActiveTab();
288   void                contextMenuRequested( QPoint );
289
290 protected:
291   virtual void        mouseMoveEvent( QMouseEvent* );
292   virtual void        mousePressEvent( QMouseEvent* );
293   virtual void        mouseReleaseEvent( QMouseEvent* );
294   virtual void        contextMenuEvent( QContextMenuEvent* );
295
296   virtual void        paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
297
298 private:
299   int                 myId;
300 };
301
302 class QtxWorkstackDrag : public QObject
303 {
304   Q_OBJECT
305
306 public:
307   QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
308   virtual ~QtxWorkstackDrag();
309
310   virtual bool        eventFilter( QObject*, QEvent* );
311
312 private:
313   void                dropWidget();
314
315   void                updateTarget( const QPoint& );
316   QtxWorkstackArea*   detectTarget( const QPoint&, int& ) const;
317   void                setTarget( QtxWorkstackArea*, const int );
318
319   void                drawRect();
320   void                endDrawRect();
321   void                startDrawRect();
322
323 private:
324   QtxWorkstack*       myWS;
325   QtxWorkstackChild*  myChild;
326
327   int                 myTab;
328   QtxWorkstackArea*   myArea;
329   QPainter*           myPainter;
330   
331 };
332
333 #ifdef WIN32
334 #pragma warning( default:4251 )
335 #endif
336
337 #endif