Version: 9.12.0
QtxWorkstack.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // File: QtxWorkstack.h
24 // Author: Sergey TELKOV
25 //
26 #ifndef QTXWORKSTACK_H
27 #define QTXWORKSTACK_H
28 
29 #include "Qtx.h"
30 
31 #include <QMap>
32 #include <QFrame>
33 #include <QEvent>
34 #include <QWidget>
35 #include <QTabBar>
36 #include <QPointer>
37 #include <QSplitter>
38 #include <QByteArray>
39 
40 class QAction;
41 class QDataStream;
42 class QRubberBand;
43 class QStackedWidget;
44 class QAbstractButton;
45 
46 class QtxWorkstackArea;
47 class QtxWorkstackDrag;
48 class QtxWorkstackChild;
49 class QtxWorkstackTabBar;
51 
52 #ifdef WIN32
53 #pragma warning( disable:4251 )
54 #endif
55 
57 {
58  Q_OBJECT
59 
60 public:
62  enum { SplitVertical = 0x01,
63  SplitHorizontal = 0x02,
64  Close = 0x04,
65  Rename = 0x08,
66  All = SplitVertical | SplitHorizontal |
67  Close | Rename
68  };
69 
70  enum { VersionMarker = 0x01,
71  SplitMarker = 0x02,
72  AreaMarker = 0x04,
73  WidgetMarker = 0x08
74  };
75 
76  enum { Horizontal = 0x01,
77  Visible = 0x02
78  };
79 
81  enum SplitType
82  {
85  SplitMove
86  };
87 
88 public:
89  QtxWorkstack( QWidget* = 0 );
90  virtual ~QtxWorkstack();
91 
92  QWidgetList windowList( QWidget* = 0 ) const;
93  QWidgetList splitWindowList() const;
94 
95  QWidget* activeWindow() const;
96  void setActiveWindow( QWidget* );
97 
98  int accel( const int ) const;
99  void setAccel( const int, const int );
100 
101  QIcon icon( const int ) const;
102  void setIcon( const int, const QIcon& );
103 
104  void setMenuActions( const int );
105  int menuActions() const;
106 
107  void stack();
108  void split( const int );
109  bool move( QWidget* wid, QWidget* wid_to, const bool before );
110 
111  QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 );
112 
113  QByteArray saveState( int ) const;
114  bool restoreState( const QByteArray&, int );
115 
116  void setOpaqueResize( bool = true );
117  bool opaqueResize() const;
118 
119  void splittersVisible( QWidget*, bool = true );
120 
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 );
125 
126  void updateState();
127 
128 signals:
130 
131 public slots:
132  void splitVertical();
133  void splitHorizontal();
134 
135 private slots:
136  void onRename();
137  void onCloseWindow();
138  void onDestroyed( QObject* );
139  void onWindowActivated( QWidget* );
140  void onContextMenuRequested( QWidget*, QPoint );
141  void onDeactivated( QtxWorkstackArea* );
142 
143 protected:
144  virtual void customEvent( QEvent* );
145 
146  QAction* action( const int ) const;
147 
148  void saveState( QDataStream& ) const;
149  bool restoreState( QDataStream& );
150 
151 private:
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;
155 
156  QSplitter* wrapSplitter( QtxWorkstackArea* );
157  void insertWidget( QWidget*, QWidget*, QWidget* );
158 
159  QtxWorkstackArea* areaAt( const QPoint& ) const;
160  QtxWorkstackArea* wgArea( QWidget* ) const;
161 
162  QtxWorkstackArea* targetArea();
163  QtxWorkstackArea* activeArea() const;
164  QtxWorkstackArea* currentArea() const;
165 
166  void setActiveArea( QtxWorkstackArea* );
167  QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
168 
169  QtxWorkstackArea* createArea( QWidget* ) const;
170 
171  void updateState( QSplitter* );
172 
173  void splitterVisible(QWidget*, QList<QSplitter*>&, QSplitter*, bool );
174 
175  void distributeSpace( QSplitter* ) const;
176 
177  int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
178  const int need_pos, const int splitter_pos );
179 
180 private:
181  QPointer<QWidget> myWin;
182  QPointer<QtxWorkstackArea> myArea;
184  QPointer<QWidget> myWorkWin;
185  QPointer<QtxWorkstackArea> myWorkArea;
186 
187  QMap<int, QAction*> myActionsMap;
188 
189  friend class QtxWorkstackArea;
190  friend class QtxWorkstackDrag;
191  friend class QtxWorkstackAction;
192  friend class QtxWorkstackSplitter;
193 };
194 
196 {
197  Q_OBJECT
198 
199 public:
201  virtual ~QtxWorkstackSplitter();
202 
203  QtxWorkstack* workstack() const;
204 
205  void saveState( QDataStream& ) const;
206  bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
207 };
208 
210 {
211  Q_OBJECT
212 
213  class WidgetEvent;
214  class RestoreEvent;
215 
216 public:
218  virtual ~QtxWorkstackArea();
219 
220  bool isNull() const;
221  bool isEmpty() const;
222 
223  QtxWorkstackChild* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 );
224  void removeWidget( QWidget*, const bool = true );
225 
226  void insertChild( QtxWorkstackChild*, const int = -1 );
227  void removeChild( QtxWorkstackChild*, const bool = true );
228 
229  QWidget* activeWidget() const;
230  void setActiveWidget( QWidget* );
231 
232  bool contains( QWidget* ) const;
233 
234  QWidgetList widgetList() const;
235  QList<QtxWorkstackChild*> childList() const;
236 
237  bool isActive() const;
238  void updateActiveState();
239 
240  QtxWorkstack* workstack() const;
241 
242  virtual bool eventFilter( QObject*, QEvent* );
243 
244  QRect floatRect() const;
245  QRect floatTab( const int ) const;
246 
247  int tabAt( const QPoint& ) const;
248 
249  void saveState( QDataStream& ) const;
250  bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
251 
252  void showTabBar( bool = true);
253 
254 signals:
255  void activated( QWidget* );
256  void contextMenuRequested( QWidget*, QPoint );
258 
259 private slots:
260  void onClose();
261  void onCurrentChanged( int );
262 
263  void onChildDestroyed( QObject* );
264  void onChildShown( QtxWorkstackChild* );
265  void onChildHidden( QtxWorkstackChild* );
266  void onChildActivated( QtxWorkstackChild* );
267  void onChildCaptionChanged( QtxWorkstackChild* );
268 
269  void onDragActiveTab();
270  void onContextMenuRequested( QPoint );
271 
272 protected:
273  virtual void customEvent( QEvent* );
274  virtual void focusInEvent( QFocusEvent* );
275  virtual void mousePressEvent( QMouseEvent* );
276 
277 private:
279  enum { ActivateWidget = QEvent::User,
282  RestoreWidget
283  };
284 
285 private:
286  void updateState();
287  void updateCurrent();
288  void updateTab( QWidget* );
289 
290  QWidget* widget( const int ) const;
291  int widgetId( QWidget* ) const;
292 
293  QtxWorkstackChild* child( QWidget* ) const;
294  QtxWorkstackChild* child( const int ) const;
295 
296  void setWidgetActive( QWidget* );
297 
298  int generateId() const;
299 
300 private:
302 
303 private:
308  QStackedWidget* myStack;
309 };
310 
312 {
313  Q_OBJECT
314 
315 public:
316  QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 );
317  virtual ~QtxWorkstackChild();
318 
319  QWidget* widget() const
320 ;
321 
322  int id() const;
323  void setId( const int );
324 
325  bool visibility();
326 
327  QtxWorkstackArea* area() const;
328 
329  virtual bool eventFilter( QObject*, QEvent* );
330 
331 signals:
336 
337 private slots:
338  void onDestroyed( QObject* );
339 
340 protected:
341  virtual void childEvent( QChildEvent* );
342 
343 private:
344  int myId;
345  QPointer<QWidget> myWidget;
346 };
347 
349 {
350  Q_OBJECT
351 
352 public:
353  QtxWorkstackTabBar( QWidget* = 0 );
354  virtual ~QtxWorkstackTabBar();
355 
356  bool isActive() const;
357  void setActive( const bool );
358 
359  int tabId( const int ) const;
360  int indexOf( const int ) const;
361  void setTabId( const int, const int );
362 
363  void updateActiveState();
364 
365 signals:
367  void contextMenuRequested( QPoint );
368 
369 private slots:
370  void onCurrentChanged( int );
371 
372 protected:
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* );
378 
379 private:
380  int myId;
381  bool myActive;
382 };
383 
384 class QtxWorkstackDrag : public QObject
385 {
386  Q_OBJECT
387 
388 public:
390  virtual ~QtxWorkstackDrag();
391 
392  virtual bool eventFilter( QObject*, QEvent* );
393 
394 private:
395  void dropWidget();
396 
397  void updateTarget( const QPoint& );
398  QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
399  void setTarget( QtxWorkstackArea*, const int );
400 
401  void drawRect();
402  void endDrawRect();
403  void startDrawRect();
404 
405 private:
408 
409  int myTab;
411  QRubberBand* myTabRect;
412  QRubberBand* myAreaRect;
413 };
414 
415 #ifdef WIN32
416 #pragma warning( default:4251 )
417 #endif
418 
419 #endif // QTXWORKSTACK_H
#define QTX_EXPORT
Definition: Qtx.h:36
Orientation
Orientation.
Definition: SalomePyQt.h:138
@ Horizontal
Horizontal orientation.
Definition: SalomePyQt.h:139
For more information see QT documentation.
Definition: SUIT_Application.h:42
Implements actions group for menu Windows with standard operations, like "Split vertical",...
Definition: QtxWorkstackAction.h:45
Internal class used to forward restore info events to the workarea.
Definition: QtxWorkstack.cxx:69
Internal class used to forward child widgets events to the workarea.
Definition: QtxWorkstack.cxx:52
Workstack widget workarea.
Definition: QtxWorkstack.h:210
void contextMenuRequested(QWidget *, QPoint)
Emitted when context popup menu is requested.
QList< QtxWorkstackChild * > ChildList
Definition: QtxWorkstack.h:301
QStackedWidget * myStack
widget stack
Definition: QtxWorkstack.h:308
void activated(QWidget *)
Emitted when child widget is activated.
void deactivated(QtxWorkstackArea *)
Emitted when workarea is deactivated.
@ FocusWidget
focus receiving widget event
Definition: QtxWorkstack.h:280
@ MakeCurrent
Definition: QtxWorkstack.h:281
ChildList myList
child widgets list
Definition: QtxWorkstack.h:306
QAbstractButton * myClose
close button
Definition: QtxWorkstack.h:307
QtxWorkstackTabBar * myBar
workarea tab bar header
Definition: QtxWorkstack.h:305
QWidget * myTop
workarea top widget
Definition: QtxWorkstack.h:304
Workarea child widget container.
Definition: QtxWorkstack.h:312
void hidden(QtxWorkstackChild *)
Emitted when child widget is hidden.
QPointer< QWidget > myWidget
child widget
Definition: QtxWorkstack.h:345
virtual ~QtxWorkstackChild()
Destructor.
Definition: QtxWorkstack.cxx:1377
void setId(const int)
Sets the id.
Definition: QtxWorkstack.cxx:1414
bool visibility()
Returns true if this child window should be visible.
Definition: QtxWorkstack.cxx:1422
void shown(QtxWorkstackChild *)
Emitted when child widget is shown.
QtxWorkstackChild(QWidget *, QWidget *=0, Qt::WindowFlags=0)
Constructor.
Definition: QtxWorkstack.cxx:1353
void captionChanged(QtxWorkstackChild *)
Emitted when child widget's title is changed.
void onDestroyed(QObject *)
Called when child widget is destroyed.
Definition: QtxWorkstack.cxx:1472
int id() const
Returns the id.
Definition: QtxWorkstack.cxx:1406
QtxWorkstackArea * area() const
Definition: QtxWorkstack.cxx:1427
void activated(QtxWorkstackChild *)
Emitted when child widget is activated.
virtual void childEvent(QChildEvent *)
Customize child event handler.
Definition: QtxWorkstack.cxx:1481
int myId
id
Definition: QtxWorkstack.h:344
virtual bool eventFilter(QObject *, QEvent *)
Custom event filter.
Definition: QtxWorkstack.cxx:1449
QWidget * widget() const
Get child widget.
Definition: QtxWorkstack.cxx:1398
Workstack drag object.
Definition: QtxWorkstack.h:385
QRubberBand * myTabRect
tab bar rubber band
Definition: QtxWorkstack.h:411
QtxWorkstackChild * myChild
workstack child widget container
Definition: QtxWorkstack.h:407
int myTab
workarea tab page index
Definition: QtxWorkstack.h:409
QtxWorkstack * myWS
parent workstack
Definition: QtxWorkstack.h:406
void dropWidget()
Called when drop operation is finished.
Definition: QtxWorkstack.cxx:195
void startDrawRect()
Create rubber band to be drawn on the dragging operation.
Definition: QtxWorkstack.cxx:252
QRubberBand * myAreaRect
workarea rubber band
Definition: QtxWorkstack.h:412
void endDrawRect()
Delete rubber band on the end on the dragging operation.
Definition: QtxWorkstack.cxx:240
void drawRect()
Draw floating rectangle.
Definition: QtxWorkstack.cxx:204
virtual ~QtxWorkstackDrag()
Destructor.
Definition: QtxWorkstack.cxx:108
void setTarget(QtxWorkstackArea *, const int)
Set dropping target.
Definition: QtxWorkstack.cxx:173
QtxWorkstackArea * detectTarget(const QPoint &, int &) const
Detect dropping target.
Definition: QtxWorkstack.cxx:157
QtxWorkstackArea * myArea
workarea
Definition: QtxWorkstack.h:410
void updateTarget(const QPoint &)
Detect and set dropping target widget.
Definition: QtxWorkstack.cxx:144
QtxWorkstackDrag(QtxWorkstack *, QtxWorkstackChild *)
Constructor.
Definition: QtxWorkstack.cxx:93
virtual bool eventFilter(QObject *, QEvent *)
Custom event filter.
Definition: QtxWorkstack.cxx:121
Workstack splitter.
Definition: QtxWorkstack.h:196
QtxWorkstack * workstack() const
Get parent workstack.
Definition: QtxWorkstack.cxx:409
bool restoreState(QDataStream &, QMap< QString, QtxWorkstackChild * > &)
Restore the widget area configuration from data stream info.
Definition: QtxWorkstack.cxx:458
virtual ~QtxWorkstackSplitter()
Destructor.
Definition: QtxWorkstack.cxx:401
void saveState(QDataStream &) const
Save the widget area configuration into data stream.
Definition: QtxWorkstack.cxx:424
QtxWorkstackSplitter(QWidget *=0)
Constructor.
Definition: QtxWorkstack.cxx:392
Workstack tab bar widget.
Definition: QtxWorkstack.h:349
int indexOf(const int) const
Get tab page index by specified identifier.
Definition: QtxWorkstack.cxx:1570
virtual void mouseReleaseEvent(QMouseEvent *)
Customize mouse release event handler.
Definition: QtxWorkstack.cxx:1654
virtual void contextMenuEvent(QContextMenuEvent *)
Customize context menu event handler.
Definition: QtxWorkstack.cxx:1668
bool myActive
"active" status
Definition: QtxWorkstack.h:381
virtual void changeEvent(QEvent *)
Process widget change state events (style, palette, enable state changing, etc).
Definition: QtxWorkstack.cxx:1678
int tabId(const int) const
Get tab page identifier.
Definition: QtxWorkstack.cxx:1547
virtual void mouseMoveEvent(QMouseEvent *)
Customize mouse move event handler.
Definition: QtxWorkstack.cxx:1627
void setActive(const bool)
Set tab bar active/inactive.
Definition: QtxWorkstack.cxx:1594
void updateActiveState()
Update tab bar according to the 'active' state.
Definition: QtxWorkstack.cxx:1606
void dragActiveTab()
Emitted when dragging operation is started.
virtual void mousePressEvent(QMouseEvent *)
Customize mouse press event handler.
Definition: QtxWorkstack.cxx:1642
void onCurrentChanged(int)
Called when current tab page is changed.
Definition: QtxWorkstack.cxx:1618
virtual ~QtxWorkstackTabBar()
Destructor.
Definition: QtxWorkstack.cxx:1538
bool isActive() const
Check if the tab bar is active.
Definition: QtxWorkstack.cxx:1585
void setTabId(const int, const int)
Set tab page identifier.
Definition: QtxWorkstack.cxx:1560
int myId
current tab page index
Definition: QtxWorkstack.h:380
void contextMenuRequested(QPoint)
Emitted when context popup menu is requested.
QtxWorkstackTabBar(QWidget *=0)
Constructor.
Definition: QtxWorkstack.cxx:1525
Workstack widget.
Definition: QtxWorkstack.h:57
QPointer< QWidget > myWin
active widget
Definition: QtxWorkstack.h:181
QMap< int, QAction * > myActionsMap
actions map
Definition: QtxWorkstack.h:187
QPointer< QtxWorkstackArea > myArea
active workarea
Definition: QtxWorkstack.h:182
SplitType
Workstack splitting type.
Definition: QtxWorkstack.h:82
@ SplitStay
selected widget stays in current workarea, others widgets are moved into a new workarea
Definition: QtxWorkstack.h:83
@ SplitAt
all widgets before selected widget stay in current workarea, other widgess are moved into a new worka...
Definition: QtxWorkstack.h:84
QPointer< QtxWorkstackArea > myWorkArea
workarea where popup menu is invoked (used internally)
Definition: QtxWorkstack.h:185
QPointer< QWidget > myWorkWin
widget where popup menu is invoked (used internally)
Definition: QtxWorkstack.h:184
QtxWorkstackSplitter * mySplit
tol-level splitter
Definition: QtxWorkstack.h:183
void windowActivated(QWidget *)
Emitted when the workstack's child widget \w is activated.