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 splittersVisible( QWidget*, 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 );
129 void windowActivated( QWidget* );
132 void splitVertical();
133 void splitHorizontal();
137 void onCloseWindow();
138 void onDestroyed( QObject* );
139 void onWindowActivated( QWidget* );
140 void onContextMenuRequested( QWidget*, QPoint );
141 void onDeactivated( QtxWorkstackArea* );
144 virtual void customEvent( QEvent* );
146 QAction* action( const int ) const;
148 void saveState( QDataStream& ) const;
149 bool restoreState( QDataStream& );
152 QSplitter* splitter( QtxWorkstackArea* ) const;
153 void splitters( QSplitter*, QList<QSplitter*>&, const bool = false ) const;
154 void areas( QSplitter*, QList<QtxWorkstackArea*>&, const bool = false ) const;
156 QSplitter* wrapSplitter( QtxWorkstackArea* );
157 void insertWidget( QWidget*, QWidget*, QWidget* );
159 QtxWorkstackArea* areaAt( const QPoint& ) const;
160 QtxWorkstackArea* wgArea( QWidget* ) const;
162 QtxWorkstackArea* targetArea();
163 QtxWorkstackArea* activeArea() const;
164 QtxWorkstackArea* currentArea() const;
166 void setActiveArea( QtxWorkstackArea* );
167 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
169 QtxWorkstackArea* createArea( QWidget* ) const;
171 void updateState( QSplitter* );
173 void splitterVisible(QWidget*, QList<QSplitter*>&, QSplitter*, bool );
175 void distributeSpace( QSplitter* ) const;
177 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
178 const int need_pos, const int splitter_pos );
181 QPointer<QWidget> myWin; //!< active widget
182 QPointer<QtxWorkstackArea> myArea; //!< active workarea
183 QtxWorkstackSplitter* mySplit; //!< tol-level splitter
184 QPointer<QWidget> myWorkWin; //!< widget where popup menu is invoked (used internally)
185 QPointer<QtxWorkstackArea> myWorkArea; //!< workarea where popup menu is invoked (used internally)
187 QMap<int, QAction*> myActionsMap; //!< actions map
189 friend class QtxWorkstackArea;
190 friend class QtxWorkstackDrag;
191 friend class QtxWorkstackAction;
192 friend class QtxWorkstackSplitter;
195 class QtxWorkstackSplitter : public QSplitter
200 QtxWorkstackSplitter( QWidget* = 0 );
201 virtual ~QtxWorkstackSplitter();
203 QtxWorkstack* workstack() const;
205 void saveState( QDataStream& ) const;
206 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
209 class QTX_EXPORT QtxWorkstackArea : public QFrame
217 QtxWorkstackArea( QWidget* );
218 virtual ~QtxWorkstackArea();
221 bool isEmpty() const;
223 QtxWorkstackChild* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 );
224 void removeWidget( QWidget*, const bool = true );
226 void insertChild( QtxWorkstackChild*, const int = -1 );
227 void removeChild( QtxWorkstackChild*, const bool = true );
229 QWidget* activeWidget() const;
230 void setActiveWidget( QWidget* );
232 bool contains( QWidget* ) const;
234 QWidgetList widgetList() const;
235 QList<QtxWorkstackChild*> childList() const;
237 bool isActive() const;
238 void updateActiveState();
240 QtxWorkstack* workstack() const;
242 virtual bool eventFilter( QObject*, QEvent* );
244 QRect floatRect() const;
245 QRect floatTab( const int ) const;
247 int tabAt( const QPoint& ) const;
249 void saveState( QDataStream& ) const;
250 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
252 void showTabBar( bool = true);
255 void activated( QWidget* );
256 void contextMenuRequested( QWidget*, QPoint );
257 void deactivated( QtxWorkstackArea* );
261 void onCurrentChanged( int );
263 void onChildDestroyed( QObject* );
264 void onChildShown( QtxWorkstackChild* );
265 void onChildHidden( QtxWorkstackChild* );
266 void onChildActivated( QtxWorkstackChild* );
267 void onChildCaptionChanged( QtxWorkstackChild* );
269 void onDragActiveTab();
270 void onContextMenuRequested( QPoint );
273 virtual void customEvent( QEvent* );
274 virtual void focusInEvent( QFocusEvent* );
275 virtual void mousePressEvent( QMouseEvent* );
279 enum { ActivateWidget = QEvent::User, //!< activate widget event
280 FocusWidget, //!< focus receiving widget event
287 void updateCurrent();
288 void updateTab( QWidget* );
290 QWidget* widget( const int ) const;
291 int widgetId( QWidget* ) const;
293 QtxWorkstackChild* child( QWidget* ) const;
294 QtxWorkstackChild* child( const int ) const;
296 void setWidgetActive( QWidget* );
298 int generateId() const;
301 typedef QList<QtxWorkstackChild*> ChildList;
304 QWidget* myTop; //!< workarea top widget
305 QtxWorkstackTabBar* myBar; //!< workarea tab bar header
306 ChildList myList; //!< child widgets list
307 QAbstractButton* myClose; //!< close button
308 QStackedWidget* myStack; //!< widget stack
311 class QtxWorkstackChild : public QWidget
316 QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 );
317 virtual ~QtxWorkstackChild();
319 QWidget* widget() const
323 void setId( const int );
327 QtxWorkstackArea* area() const;
329 virtual bool eventFilter( QObject*, QEvent* );
332 void shown( QtxWorkstackChild* );
333 void hidden( QtxWorkstackChild* );
334 void activated( QtxWorkstackChild* );
335 void captionChanged( QtxWorkstackChild* );
338 void onDestroyed( QObject* );
341 virtual void childEvent( QChildEvent* );
345 QPointer<QWidget> myWidget; //!< child widget
348 class QtxWorkstackTabBar : public QTabBar
353 QtxWorkstackTabBar( QWidget* = 0 );
354 virtual ~QtxWorkstackTabBar();
356 bool isActive() const;
357 void setActive( const bool );
359 int tabId( const int ) const;
360 int indexOf( const int ) const;
361 void setTabId( const int, const int );
363 void updateActiveState();
366 void dragActiveTab();
367 void contextMenuRequested( QPoint );
370 void onCurrentChanged( int );
373 virtual void changeEvent( QEvent* );
374 virtual void mouseMoveEvent( QMouseEvent* );
375 virtual void mousePressEvent( QMouseEvent* );
376 virtual void mouseReleaseEvent( QMouseEvent* );
377 virtual void contextMenuEvent( QContextMenuEvent* );
380 int myId; //!< current tab page index
381 bool myActive; //!< "active" status
384 class QtxWorkstackDrag : public QObject
389 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
390 virtual ~QtxWorkstackDrag();
392 virtual bool eventFilter( QObject*, QEvent* );
397 void updateTarget( const QPoint& );
398 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
399 void setTarget( QtxWorkstackArea*, const int );
403 void startDrawRect();
406 QtxWorkstack* myWS; //!< parent workstack
407 QtxWorkstackChild* myChild; //!< workstack child widget container
409 int myTab; //!< workarea tab page index
410 QtxWorkstackArea* myArea; //!< workarea
411 QRubberBand* myTabRect; //!< tab bar rubber band
412 QRubberBand* myAreaRect; //!< workarea rubber band
416 #pragma warning( default:4251 )
419 #endif // QTXWORKSTACK_H