1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxWorkstack.h
20 // Author: Sergey TELKOV
22 #ifndef QTXWORKSTACK_H
23 #define QTXWORKSTACK_H
30 #include <qwidgetlist.h>
39 class QtxWorkstackArea;
40 class QtxWorkstackDrag;
41 class QtxWorkstackChild;
42 class QtxWorkstackTabBar;
45 #pragma warning( disable:4251 )
48 class QTX_EXPORT QtxWorkstack : public QWidget
53 enum { SplitVertical, SplitHorizontal, Close, Rename };
57 SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one
58 SPLIT_AT, //!< widgets before a given widget stays in they workarea, others are moved into a new one
59 SPLIT_MOVE //!< given widget is moved into a new workarea, others stay in an old one
63 QtxWorkstack( QWidget* = 0 );
64 virtual ~QtxWorkstack();
66 QWidgetList windowList() const;
67 QWidgetList splitWindowList() const;
69 QWidget* activeWindow() const;
71 int accel( const int ) const;
72 void setAccel( const int, const int );
74 void split( const int );
76 // STV: Useless function. wid->setFocus() should be used instead.
77 // void OnTop( QWidget* wid);
79 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
80 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
81 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
82 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
84 // asv: Store/Restore visual parameters - geometry of inner windows
85 QtxWorkstack& operator<<( const QString& );
86 QtxWorkstack& operator>>( QString& );
89 void windowActivated( QWidget* );
93 void splitHorizontal();
98 void onDestroyed( QObject* );
99 void onWindowActivated( QWidget* );
100 void onContextMenuRequested( QWidget*, QPoint );
101 void onDeactivated( QtxWorkstackArea* );
104 virtual void childEvent( QChildEvent* );
105 virtual void customEvent( QCustomEvent* );
108 QSplitter* splitter( QtxWorkstackArea* ) const;
109 void splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
110 void areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
112 QSplitter* wrapSplitter( QtxWorkstackArea* );
113 void insertWidget( QWidget*, QWidget*, QWidget* );
115 QtxWorkstackArea* areaAt( const QPoint& ) const;
117 QtxWorkstackArea* targetArea();
118 QtxWorkstackArea* activeArea() const;
119 QtxWorkstackArea* currentArea() const;
121 void setActiveArea( QtxWorkstackArea* );
122 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
124 QtxWorkstackArea* createArea( QWidget* ) const;
127 void updateState( QSplitter* );
129 void distributeSpace( QSplitter* ) const;
130 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
131 const int need_pos, const int splitter_pos );
133 void splitterInfo( QSplitter*, QString& ) const;
134 void setSplitter( QSplitter*, const QString&, QMap< QSplitter*,QValueList<int> >& );
138 QtxWorkstackArea* myArea;
141 QtxWorkstackArea* myWorkArea;
143 QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
145 friend class QtxWorkstackArea;
146 friend class QtxWorkstackDrag;
149 class QtxWorkstackArea : public QWidget
154 QtxWorkstackArea( QWidget* );
155 virtual ~QtxWorkstackArea();
157 bool isEmpty() const;
159 void insertWidget( QWidget*, const int = -1 );
160 void removeWidget( QWidget*, const bool = true );
162 QWidget* activeWidget() const;
163 void setActiveWidget( QWidget* );
165 bool contains( QWidget* ) const;
167 QWidgetList widgetList() const;
169 bool isActive() const;
170 void updateActiveState();
172 QtxWorkstack* workstack() const;
174 virtual bool eventFilter( QObject*, QEvent* );
176 QRect floatRect() const;
177 QRect floatTab( const int ) const;
179 int tabAt( const QPoint& ) const;
182 void activated( QWidget* );
183 void contextMenuRequested( QWidget*, QPoint );
184 void deactivated( QtxWorkstackArea* );
192 void onSelected( int );
194 void onWidgetDestroyed();
196 void onChildDestroyed( QObject* );
197 void onChildShown( QtxWorkstackChild* );
198 void onChildHided( QtxWorkstackChild* );
199 void onChildActivated( QtxWorkstackChild* );
200 void onChildCaptionChanged( QtxWorkstackChild* );
202 void onDragActiveTab();
203 void onContextMenuRequested( QPoint );
206 virtual void customEvent( QCustomEvent* );
207 virtual void focusInEvent( QFocusEvent* );
208 virtual void mousePressEvent( QMouseEvent* );
211 enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
215 void updateCurrent();
216 void updateTab( QWidget* );
218 QWidget* widget( const int ) const;
219 int widgetId( QWidget* ) const;
220 bool widgetVisibility( QWidget* ) const;
222 void setWidgetActive( QWidget* );
223 void setWidgetShown( QWidget*, const bool );
225 int generateId() const;
227 bool isBlocked( QWidget* ) const;
228 void setBlocked( QWidget*, const bool );
230 QtxWorkstackChild* child( QWidget* ) const;
235 WidgetInfo() : id( 0 ), vis( false ) {}
239 typedef QMap<QWidget*, bool> BlockMap;
240 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
241 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
244 QtxWorkstackTabBar* myBar;
245 QPushButton* myClose;
246 QWidgetStack* myStack;
249 WidgetInfoMap myInfo;
254 class QtxWorkstackChild : public QHBox
259 QtxWorkstackChild( QWidget*, QWidget* = 0 );
260 virtual ~QtxWorkstackChild();
262 QWidget* widget() const;
264 virtual bool eventFilter( QObject*, QEvent* );
267 void shown( QtxWorkstackChild* );
268 void hided( QtxWorkstackChild* );
269 void activated( QtxWorkstackChild* );
270 void captionChanged( QtxWorkstackChild* );
273 void onDestroyed( QObject* );
276 virtual void childEvent( QChildEvent* );
282 class QtxWorkstackTabBar : public QTabBar
287 QtxWorkstackTabBar( QWidget* = 0 );
288 virtual ~QtxWorkstackTabBar();
290 QRect tabRect( const int ) const;
292 void setActive( const bool );
295 void dragActiveTab();
296 void contextMenuRequested( QPoint );
299 virtual void mouseMoveEvent( QMouseEvent* );
300 virtual void mousePressEvent( QMouseEvent* );
301 virtual void mouseReleaseEvent( QMouseEvent* );
302 virtual void contextMenuEvent( QContextMenuEvent* );
304 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
310 class QtxWorkstackDrag : public QObject
315 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
316 virtual ~QtxWorkstackDrag();
318 virtual bool eventFilter( QObject*, QEvent* );
323 void updateTarget( const QPoint& );
324 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
325 void setTarget( QtxWorkstackArea*, const int );
329 void startDrawRect();
333 QtxWorkstackChild* myChild;
336 QtxWorkstackArea* myArea;
342 #pragma warning( default:4251 )