1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: QtxWorkstack.h
24 // Author: Sergey TELKOV
26 #ifndef QTXWORKSTACK_H
27 #define QTXWORKSTACK_H
44 class QAbstractButton;
46 class QtxWorkstackArea;
47 class QtxWorkstackDrag;
48 class QtxWorkstackChild;
49 class QtxWorkstackTabBar;
50 class QtxWorkstackSplitter;
53 #pragma warning( disable:4251 )
56 class QTX_EXPORT QtxWorkstack : public QWidget
61 //! Workstack actions (context menu items)
62 enum { SplitVertical = 0x01, //!< "Split vertically" menu item
63 SplitHorizontal = 0x02, //!< "Split horizontally" menu item
64 Close = 0x04, //!< "Close" menu item
65 Rename = 0x08, //!< "Rename" menu item
66 All = SplitVertical | SplitHorizontal |
67 Close | Rename //!< all menu items
70 enum { VersionMarker = 0x01,
76 enum { Horizontal = 0x01,
80 //! Workstack splitting type
83 SplitStay, //!< selected widget stays in current workarea, others widgets are moved into a new workarea
84 SplitAt, //!< all widgets before selected widget stay in current workarea, other widgess are moved into a new workarea
85 SplitMove //!< selected widget is moved into a new workarea, all other widgets stay in an old workarea
89 QtxWorkstack( QWidget* = 0 );
90 virtual ~QtxWorkstack();
92 QWidgetList windowList( QWidget* = 0 ) const;
93 QWidgetList splitWindowList() const;
95 QWidget* activeWindow() const;
97 int accel( const int ) const;
98 void setAccel( const int, const int );
100 QIcon icon( const int ) const;
101 void setIcon( const int, const QIcon& );
103 void setMenuActions( const int );
104 int menuActions() const;
107 void split( const int );
108 bool move( QWidget* wid, QWidget* wid_to, const bool before );
110 QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 );
112 QByteArray saveState( int ) const;
113 bool restoreState( const QByteArray&, int );
115 void setOpaqueResize( bool = true );
116 bool opaqueResize() const;
118 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
119 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
120 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
121 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
124 void windowActivated( QWidget* );
127 void splitVertical();
128 void splitHorizontal();
132 void onCloseWindow();
133 void onDestroyed( QObject* );
134 void onWindowActivated( QWidget* );
135 void onContextMenuRequested( QWidget*, QPoint );
136 void onDeactivated( QtxWorkstackArea* );
139 virtual void customEvent( QEvent* );
141 QAction* action( const int ) const;
143 void saveState( QDataStream& ) const;
144 bool restoreState( QDataStream& );
147 QSplitter* splitter( QtxWorkstackArea* ) const;
148 void splitters( QSplitter*, QList<QSplitter*>&, const bool = false ) const;
149 void areas( QSplitter*, QList<QtxWorkstackArea*>&, const bool = false ) const;
151 QSplitter* wrapSplitter( QtxWorkstackArea* );
152 void insertWidget( QWidget*, QWidget*, QWidget* );
154 QtxWorkstackArea* areaAt( const QPoint& ) const;
155 QtxWorkstackArea* wgArea( QWidget* ) const;
157 QtxWorkstackArea* targetArea();
158 QtxWorkstackArea* activeArea() const;
159 QtxWorkstackArea* currentArea() const;
161 void setActiveArea( QtxWorkstackArea* );
162 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
164 QtxWorkstackArea* createArea( QWidget* ) const;
167 void updateState( QSplitter* );
169 void distributeSpace( QSplitter* ) const;
171 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
172 const int need_pos, const int splitter_pos );
175 QPointer<QWidget> myWin; //!< active widget
176 QPointer<QtxWorkstackArea> myArea; //!< active workarea
177 QtxWorkstackSplitter* mySplit; //!< tol-level splitter
178 QPointer<QWidget> myWorkWin; //!< widget where popup menu is invoked (used internally)
179 QPointer<QtxWorkstackArea> myWorkArea; //!< workarea where popup menu is invoked (used internally)
181 QMap<int, QAction*> myActionsMap; //!< actions map
183 friend class QtxWorkstackArea;
184 friend class QtxWorkstackDrag;
185 friend class QtxWorkstackAction;
186 friend class QtxWorkstackSplitter;
189 class QtxWorkstackSplitter : public QSplitter
194 QtxWorkstackSplitter( QWidget* = 0 );
195 virtual ~QtxWorkstackSplitter();
197 QtxWorkstack* workstack() const;
199 void saveState( QDataStream& ) const;
200 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
203 class QTX_EXPORT QtxWorkstackArea : public QFrame
211 QtxWorkstackArea( QWidget* );
212 virtual ~QtxWorkstackArea();
215 bool isEmpty() const;
217 QtxWorkstackChild* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 );
218 void removeWidget( QWidget*, const bool = true );
220 void insertChild( QtxWorkstackChild*, const int = -1 );
221 void removeChild( QtxWorkstackChild*, const bool = true );
223 QWidget* activeWidget() const;
224 void setActiveWidget( QWidget* );
226 bool contains( QWidget* ) const;
228 QWidgetList widgetList() const;
229 QList<QtxWorkstackChild*> childList() const;
231 bool isActive() const;
232 void updateActiveState();
234 QtxWorkstack* workstack() const;
236 virtual bool eventFilter( QObject*, QEvent* );
238 QRect floatRect() const;
239 QRect floatTab( const int ) const;
241 int tabAt( const QPoint& ) const;
243 void saveState( QDataStream& ) const;
244 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
247 void activated( QWidget* );
248 void contextMenuRequested( QWidget*, QPoint );
249 void deactivated( QtxWorkstackArea* );
253 void onCurrentChanged( int );
255 void onChildDestroyed( QObject* );
256 void onChildShown( QtxWorkstackChild* );
257 void onChildHidden( QtxWorkstackChild* );
258 void onChildActivated( QtxWorkstackChild* );
259 void onChildCaptionChanged( QtxWorkstackChild* );
261 void onDragActiveTab();
262 void onContextMenuRequested( QPoint );
265 virtual void customEvent( QEvent* );
266 virtual void focusInEvent( QFocusEvent* );
267 virtual void mousePressEvent( QMouseEvent* );
271 enum { ActivateWidget = QEvent::User, //!< activate widget event
272 FocusWidget, //!< focus receiving widget event
279 void updateCurrent();
280 void updateTab( QWidget* );
282 QWidget* widget( const int ) const;
283 int widgetId( QWidget* ) const;
285 QtxWorkstackChild* child( QWidget* ) const;
286 QtxWorkstackChild* child( const int ) const;
288 void setWidgetActive( QWidget* );
290 int generateId() const;
293 typedef QList<QtxWorkstackChild*> ChildList;
296 QtxWorkstackTabBar* myBar; //!< workarea tab bar header
297 ChildList myList; //!< child widgets list
298 QAbstractButton* myClose; //!< close button
299 QStackedWidget* myStack; //!< widget stack
302 class QtxWorkstackChild : public QWidget
307 QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 );
308 virtual ~QtxWorkstackChild();
310 QWidget* widget() const
314 void setId( const int );
318 QtxWorkstackArea* area() const;
320 virtual bool eventFilter( QObject*, QEvent* );
323 void shown( QtxWorkstackChild* );
324 void hidden( QtxWorkstackChild* );
325 void activated( QtxWorkstackChild* );
326 void captionChanged( QtxWorkstackChild* );
329 void onDestroyed( QObject* );
332 virtual void childEvent( QChildEvent* );
336 QPointer<QWidget> myWidget; //!< child widget
339 class QtxWorkstackTabBar : public QTabBar
344 QtxWorkstackTabBar( QWidget* = 0 );
345 virtual ~QtxWorkstackTabBar();
347 bool isActive() const;
348 void setActive( const bool );
350 int tabId( const int ) const;
351 int indexOf( const int ) const;
352 void setTabId( const int, const int );
354 void updateActiveState();
357 void dragActiveTab();
358 void contextMenuRequested( QPoint );
361 void onCurrentChanged( int );
364 virtual void changeEvent( QEvent* );
365 virtual void mouseMoveEvent( QMouseEvent* );
366 virtual void mousePressEvent( QMouseEvent* );
367 virtual void mouseReleaseEvent( QMouseEvent* );
368 virtual void contextMenuEvent( QContextMenuEvent* );
371 int myId; //!< current tab page index
372 bool myActive; //!< "active" status
375 class QtxWorkstackDrag : public QObject
380 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
381 virtual ~QtxWorkstackDrag();
383 virtual bool eventFilter( QObject*, QEvent* );
388 void updateTarget( const QPoint& );
389 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
390 void setTarget( QtxWorkstackArea*, const int );
394 void startDrawRect();
397 QtxWorkstack* myWS; //!< parent workstack
398 QtxWorkstackChild* myChild; //!< workstack child widget container
400 int myTab; //!< workarea tab page index
401 QtxWorkstackArea* myArea; //!< workarea
402 QRubberBand* myTabRect; //!< tab bar rubber band
403 QRubberBand* myAreaRect; //!< workarea rubber band
407 #pragma warning( default:4251 )
410 #endif // QTXWORKSTACK_H