1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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;
96 void setActiveWindow( QWidget* );
98 int accel( const int ) const;
99 void setAccel( const int, const int );
101 QIcon icon( const int ) const;
102 void setIcon( const int, const QIcon& );
104 void setMenuActions( const int );
105 int menuActions() const;
108 void split( const int );
109 bool move( QWidget* wid, QWidget* wid_to, const bool before );
111 QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 );
113 QByteArray saveState( int ) const;
114 bool restoreState( const QByteArray&, int );
116 void setOpaqueResize( bool = true );
117 bool opaqueResize() const;
119 void showActiveTabBar( bool = true );
121 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
122 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
123 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
124 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
127 void windowActivated( QWidget* );
130 void splitVertical();
131 void splitHorizontal();
135 void onCloseWindow();
136 void onDestroyed( QObject* );
137 void onWindowActivated( QWidget* );
138 void onContextMenuRequested( QWidget*, QPoint );
139 void onDeactivated( QtxWorkstackArea* );
142 virtual void customEvent( QEvent* );
144 QAction* action( const int ) const;
146 void saveState( QDataStream& ) const;
147 bool restoreState( QDataStream& );
150 QSplitter* splitter( QtxWorkstackArea* ) const;
151 void splitters( QSplitter*, QList<QSplitter*>&, const bool = false ) const;
152 void areas( QSplitter*, QList<QtxWorkstackArea*>&, const bool = false ) const;
154 QSplitter* wrapSplitter( QtxWorkstackArea* );
155 void insertWidget( QWidget*, QWidget*, QWidget* );
157 QtxWorkstackArea* areaAt( const QPoint& ) const;
158 QtxWorkstackArea* wgArea( QWidget* ) const;
160 QtxWorkstackArea* targetArea();
161 QtxWorkstackArea* activeArea() const;
162 QtxWorkstackArea* currentArea() const;
164 void setActiveArea( QtxWorkstackArea* );
165 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
167 QtxWorkstackArea* createArea( QWidget* ) const;
170 void updateState( QSplitter* );
172 void distributeSpace( QSplitter* ) const;
174 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
175 const int need_pos, const int splitter_pos );
178 QPointer<QWidget> myWin; //!< active widget
179 QPointer<QtxWorkstackArea> myArea; //!< active workarea
180 QtxWorkstackSplitter* mySplit; //!< tol-level splitter
181 QPointer<QWidget> myWorkWin; //!< widget where popup menu is invoked (used internally)
182 QPointer<QtxWorkstackArea> myWorkArea; //!< workarea where popup menu is invoked (used internally)
184 QMap<int, QAction*> myActionsMap; //!< actions map
186 friend class QtxWorkstackArea;
187 friend class QtxWorkstackDrag;
188 friend class QtxWorkstackAction;
189 friend class QtxWorkstackSplitter;
192 class QtxWorkstackSplitter : public QSplitter
197 QtxWorkstackSplitter( QWidget* = 0 );
198 virtual ~QtxWorkstackSplitter();
200 QtxWorkstack* workstack() const;
202 void saveState( QDataStream& ) const;
203 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
206 class QTX_EXPORT QtxWorkstackArea : public QFrame
214 QtxWorkstackArea( QWidget* );
215 virtual ~QtxWorkstackArea();
218 bool isEmpty() const;
220 QtxWorkstackChild* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 );
221 void removeWidget( QWidget*, const bool = true );
223 void insertChild( QtxWorkstackChild*, const int = -1 );
224 void removeChild( QtxWorkstackChild*, const bool = true );
226 QWidget* activeWidget() const;
227 void setActiveWidget( QWidget* );
229 bool contains( QWidget* ) const;
231 QWidgetList widgetList() const;
232 QList<QtxWorkstackChild*> childList() const;
234 bool isActive() const;
235 void updateActiveState();
237 QtxWorkstack* workstack() const;
239 virtual bool eventFilter( QObject*, QEvent* );
241 QRect floatRect() const;
242 QRect floatTab( const int ) const;
244 int tabAt( const QPoint& ) const;
246 void saveState( QDataStream& ) const;
247 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
249 void showTabBar( bool = true);
252 void activated( QWidget* );
253 void contextMenuRequested( QWidget*, QPoint );
254 void deactivated( QtxWorkstackArea* );
258 void onCurrentChanged( int );
260 void onChildDestroyed( QObject* );
261 void onChildShown( QtxWorkstackChild* );
262 void onChildHidden( QtxWorkstackChild* );
263 void onChildActivated( QtxWorkstackChild* );
264 void onChildCaptionChanged( QtxWorkstackChild* );
266 void onDragActiveTab();
267 void onContextMenuRequested( QPoint );
270 virtual void customEvent( QEvent* );
271 virtual void focusInEvent( QFocusEvent* );
272 virtual void mousePressEvent( QMouseEvent* );
276 enum { ActivateWidget = QEvent::User, //!< activate widget event
277 FocusWidget, //!< focus receiving widget event
284 void updateCurrent();
285 void updateTab( QWidget* );
287 QWidget* widget( const int ) const;
288 int widgetId( QWidget* ) const;
290 QtxWorkstackChild* child( QWidget* ) const;
291 QtxWorkstackChild* child( const int ) const;
293 void setWidgetActive( QWidget* );
295 int generateId() const;
298 typedef QList<QtxWorkstackChild*> ChildList;
301 QWidget* myTop; //!< workarea top widget
302 QtxWorkstackTabBar* myBar; //!< workarea tab bar header
303 ChildList myList; //!< child widgets list
304 QAbstractButton* myClose; //!< close button
305 QStackedWidget* myStack; //!< widget stack
308 class QtxWorkstackChild : public QWidget
313 QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 );
314 virtual ~QtxWorkstackChild();
316 QWidget* widget() const
320 void setId( const int );
324 QtxWorkstackArea* area() const;
326 virtual bool eventFilter( QObject*, QEvent* );
329 void shown( QtxWorkstackChild* );
330 void hidden( QtxWorkstackChild* );
331 void activated( QtxWorkstackChild* );
332 void captionChanged( QtxWorkstackChild* );
335 void onDestroyed( QObject* );
338 virtual void childEvent( QChildEvent* );
342 QPointer<QWidget> myWidget; //!< child widget
345 class QtxWorkstackTabBar : public QTabBar
350 QtxWorkstackTabBar( QWidget* = 0 );
351 virtual ~QtxWorkstackTabBar();
353 bool isActive() const;
354 void setActive( const bool );
356 int tabId( const int ) const;
357 int indexOf( const int ) const;
358 void setTabId( const int, const int );
360 void updateActiveState();
363 void dragActiveTab();
364 void contextMenuRequested( QPoint );
367 void onCurrentChanged( int );
370 virtual void changeEvent( QEvent* );
371 virtual void mouseMoveEvent( QMouseEvent* );
372 virtual void mousePressEvent( QMouseEvent* );
373 virtual void mouseReleaseEvent( QMouseEvent* );
374 virtual void contextMenuEvent( QContextMenuEvent* );
377 int myId; //!< current tab page index
378 bool myActive; //!< "active" status
381 class QtxWorkstackDrag : public QObject
386 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
387 virtual ~QtxWorkstackDrag();
389 virtual bool eventFilter( QObject*, QEvent* );
394 void updateTarget( const QPoint& );
395 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
396 void setTarget( QtxWorkstackArea*, const int );
400 void startDrawRect();
403 QtxWorkstack* myWS; //!< parent workstack
404 QtxWorkstackChild* myChild; //!< workstack child widget container
406 int myTab; //!< workarea tab page index
407 QtxWorkstackArea* myArea; //!< workarea
408 QRubberBand* myTabRect; //!< tab bar rubber band
409 QRubberBand* myAreaRect; //!< workarea rubber band
413 #pragma warning( default:4251 )
416 #endif // QTXWORKSTACK_H