Version: 9.16.0
QtxWorkstack.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 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
40class QAction;
41class QDataStream;
42class QRubberBand;
43class QStackedWidget;
44class QAbstractButton;
45
51
52#ifdef WIN32
53#pragma warning( disable:4251 )
54#endif
55
57{
58 Q_OBJECT
59
60public:
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
82 {
85 SplitMove
86 };
87
88public:
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
100 QIcon icon( const int ) const;
101 void setIcon( const int, const QIcon& );
102
103 void setMenuActions( const int );
104 int menuActions() const;
105
106 void stack();
107 void split( const int );
108 bool move( QWidget* wid, QWidget* wid_to, const bool before );
109
110 QWidget* addWindow( QWidget*, Qt::WindowFlags = 0 );
111
112 QByteArray saveState( int ) const;
113 bool restoreState( const QByteArray&, int );
114
115 void setOpaqueResize( bool = true );
116 bool opaqueResize() const;
117
118 void splittersVisible( QWidget*, bool = true );
119
120 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
121 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
122 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
123 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
124
125 void updateState();
126
127signals:
129
130public slots:
131 void splitVertical();
132 void splitHorizontal();
133
134private slots:
135 void onRename();
136 void onCloseWindow();
137 void onDestroyed( QObject* );
138 void onWindowActivated( QWidget* );
139 void onContextMenuRequested( QWidget*, QPoint );
140 void onDeactivated( QtxWorkstackArea* );
141
142protected:
143 virtual void customEvent( QEvent* );
144
145 QAction* action( const int ) const;
146
147 void saveState( QDataStream& ) const;
148 bool restoreState( QDataStream& );
149
150private:
151 QSplitter* splitter( QtxWorkstackArea* ) const;
152 void splitters( QSplitter*, QList<QSplitter*>&, const bool = false ) const;
153 void areas( QSplitter*, QList<QtxWorkstackArea*>&, const bool = false ) const;
154
155 QSplitter* wrapSplitter( QtxWorkstackArea* );
156 void insertWidget( QWidget*, QWidget*, QWidget* );
157
158 QtxWorkstackArea* areaAt( const QPoint& ) const;
159 QtxWorkstackArea* wgArea( QWidget* ) const;
160
161 QtxWorkstackArea* targetArea();
162 QtxWorkstackArea* activeArea() const;
163 QtxWorkstackArea* currentArea() const;
164
165 void setActiveArea( QtxWorkstackArea* );
166 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
167
168 QtxWorkstackArea* createArea( QWidget* ) const;
169
170 void updateState( QSplitter* );
171
172 void splitterVisible(QWidget*, QList<QSplitter*>&, QSplitter*, bool );
173
174 void distributeSpace( QSplitter* ) const;
175
176 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
177 const int need_pos, const int splitter_pos );
178
179private:
180 QPointer<QWidget> myWin;
181 QPointer<QtxWorkstackArea> myArea;
183 QPointer<QWidget> myWorkWin;
184 QPointer<QtxWorkstackArea> myWorkArea;
185
186 QMap<int, QAction*> myActionsMap;
187
188 friend class QtxWorkstackArea;
189 friend class QtxWorkstackDrag;
190 friend class QtxWorkstackAction;
192};
193
195{
196 Q_OBJECT
197
198public:
200 virtual ~QtxWorkstackSplitter();
201
202 QtxWorkstack* workstack() const;
203
204 void saveState( QDataStream& ) const;
205 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
206};
207
209{
210 Q_OBJECT
211
212 class WidgetEvent;
213 class RestoreEvent;
214
215public:
217 virtual ~QtxWorkstackArea();
218
219 bool isNull() const;
220 bool isEmpty() const;
221
222 QtxWorkstackChild* insertWidget( QWidget*, const int = -1, Qt::WindowFlags = 0 );
223 void removeWidget( QWidget*, const bool = true );
224
225 void insertChild( QtxWorkstackChild*, const int = -1 );
226 void removeChild( QtxWorkstackChild*, const bool = true );
227
228 QWidget* activeWidget() const;
229 void setActiveWidget( QWidget* );
230
231 bool contains( QWidget* ) const;
232
233 QWidgetList widgetList() const;
234 QList<QtxWorkstackChild*> childList() const;
235
236 bool isActive() const;
237 void updateActiveState();
238
239 QtxWorkstack* workstack() const;
240
241 virtual bool eventFilter( QObject*, QEvent* );
242
243 QRect floatRect() const;
244 QRect floatTab( const int ) const;
245
246 int tabAt( const QPoint& ) const;
247
248 void saveState( QDataStream& ) const;
249 bool restoreState( QDataStream&, QMap<QString, QtxWorkstackChild*>& );
250
251 void showTabBar( bool = true);
252
253signals:
257
258private slots:
259 void onClose();
260 void onCurrentChanged( int );
261
262 void onChildDestroyed( QObject* );
263 void onChildShown( QtxWorkstackChild* );
264 void onChildHidden( QtxWorkstackChild* );
265 void onChildActivated( QtxWorkstackChild* );
266 void onChildCaptionChanged( QtxWorkstackChild* );
267
268 void onDragActiveTab();
269 void onContextMenuRequested( QPoint );
270
271protected:
272 virtual void customEvent( QEvent* );
273 virtual void focusInEvent( QFocusEvent* );
274 virtual void mousePressEvent( QMouseEvent* );
275
276private:
278 enum { ActivateWidget = QEvent::User,
281 RestoreWidget
282 };
283
284private:
285 void updateState();
286 void updateCurrent();
287 void updateTab( QWidget* );
288
289 QWidget* widget( const int ) const;
290 int widgetId( QWidget* ) const;
291
292 QtxWorkstackChild* child( QWidget* ) const;
293 QtxWorkstackChild* child( const int ) const;
294
295 void setWidgetActive( QWidget* );
296
297 int generateId() const;
298
299private:
301
302private:
307 QStackedWidget* myStack;
308};
309
311{
312 Q_OBJECT
313
314public:
315 QtxWorkstackChild( QWidget*, QWidget* = 0, Qt::WindowFlags = 0 );
316 virtual ~QtxWorkstackChild();
317
318 QWidget* widget() const
319;
320
321 int id() const;
322 void setId( const int );
323
324 bool visibility();
325
326 QtxWorkstackArea* area() const;
327
328 virtual bool eventFilter( QObject*, QEvent* );
329
330signals:
335
336private slots:
337 void onDestroyed( QObject* );
338
339protected:
340 virtual void childEvent( QChildEvent* );
341
342private:
343 int myId;
344 QPointer<QWidget> myWidget;
345};
346
348{
349 Q_OBJECT
350
351public:
353 virtual ~QtxWorkstackTabBar();
354
355 bool isActive() const;
356 void setActive( const bool );
357
358 int tabId( const int ) const;
359 int indexOf( const int ) const;
360 void setTabId( const int, const int );
361
362 void updateActiveState();
363
364signals:
366 void contextMenuRequested( QPoint );
367
368private slots:
369 void onCurrentChanged( int );
370
371protected:
372 virtual void changeEvent( QEvent* );
373 virtual void mouseMoveEvent( QMouseEvent* );
374 virtual void mousePressEvent( QMouseEvent* );
375 virtual void mouseReleaseEvent( QMouseEvent* );
376 virtual void contextMenuEvent( QContextMenuEvent* );
377
378private:
379 int myId;
380 bool myActive;
381};
382
384{
385 Q_OBJECT
386
387public:
389 virtual ~QtxWorkstackDrag();
390
391 virtual bool eventFilter( QObject*, QEvent* );
392
393private:
394 void dropWidget();
395
396 void updateTarget( const QPoint& );
397 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
398 void setTarget( QtxWorkstackArea*, const int );
399
400 void drawRect();
401 void endDrawRect();
402 void startDrawRect();
403
404private:
407
408 int myTab;
410 QRubberBand* myTabRect;
411 QRubberBand* myAreaRect;
412};
413
414#ifdef WIN32
415#pragma warning( default:4251 )
416#endif
417
418#endif // QTXWORKSTACK_H
#define QTX_EXPORT
Definition: Qtx.h:36
Orientation
Orientation.
Definition: SalomePyQt.h:147
@ Horizontal
Horizontal orientation.
Definition: SalomePyQt.h:148
For more information see QT documentation.
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:209
void contextMenuRequested(QWidget *, QPoint)
Emitted when context popup menu is requested.
QList< QtxWorkstackChild * > ChildList
Definition: QtxWorkstack.h:300
QStackedWidget * myStack
widget stack
Definition: QtxWorkstack.h:307
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:279
@ MakeCurrent
Definition: QtxWorkstack.h:280
ChildList myList
child widgets list
Definition: QtxWorkstack.h:305
QAbstractButton * myClose
close button
Definition: QtxWorkstack.h:306
QtxWorkstackTabBar * myBar
workarea tab bar header
Definition: QtxWorkstack.h:304
QWidget * myTop
workarea top widget
Definition: QtxWorkstack.h:303
Workarea child widget container.
Definition: QtxWorkstack.h:311
void hidden(QtxWorkstackChild *)
Emitted when child widget is hidden.
QPointer< QWidget > myWidget
child widget
Definition: QtxWorkstack.h:344
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:343
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:384
QRubberBand * myTabRect
tab bar rubber band
Definition: QtxWorkstack.h:410
QtxWorkstackChild * myChild
workstack child widget container
Definition: QtxWorkstack.h:406
int myTab
workarea tab page index
Definition: QtxWorkstack.h:408
QtxWorkstack * myWS
parent workstack
Definition: QtxWorkstack.h:405
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:411
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:409
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:195
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:348
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:380
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:379
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:180
QMap< int, QAction * > myActionsMap
actions map
Definition: QtxWorkstack.h:186
QPointer< QtxWorkstackArea > myArea
active workarea
Definition: QtxWorkstack.h:181
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:184
QPointer< QWidget > myWorkWin
widget where popup menu is invoked (used internally)
Definition: QtxWorkstack.h:183
QtxWorkstackSplitter * mySplit
tol-level splitter
Definition: QtxWorkstack.h:182
void windowActivated(QWidget *)
Emitted when the workstack's child widget \w is activated.