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 );
85 void windowActivated( QWidget* );
89 void splitHorizontal();
94 void onDestroyed( QObject* );
95 void onWindowActivated( QWidget* );
96 void onContextMenuRequested( QWidget*, QPoint );
97 void onDeactivated( QtxWorkstackArea* );
100 virtual void childEvent( QChildEvent* );
101 virtual void customEvent( QCustomEvent* );
104 QSplitter* splitter( QtxWorkstackArea* ) const;
105 void splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
106 void areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
108 QSplitter* wrapSplitter( QtxWorkstackArea* );
109 void insertWidget( QWidget*, QWidget*, QWidget* );
111 QtxWorkstackArea* areaAt( const QPoint& ) const;
113 QtxWorkstackArea* targetArea();
114 QtxWorkstackArea* activeArea() const;
115 QtxWorkstackArea* currentArea() const;
117 void setActiveArea( QtxWorkstackArea* );
118 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
120 QtxWorkstackArea* createArea( QWidget* ) const;
123 void updateState( QSplitter* );
125 void distributeSpace( QSplitter* ) const;
126 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
127 const int need_pos, const int splitter_pos );
131 QtxWorkstackArea* myArea;
135 QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
137 friend class QtxWorkstackArea;
138 friend class QtxWorkstackDrag;
141 class QtxWorkstackArea : public QWidget
146 QtxWorkstackArea( QWidget* );
147 virtual ~QtxWorkstackArea();
149 bool isEmpty() const;
151 void insertWidget( QWidget*, const int = -1 );
152 void removeWidget( QWidget*, const bool = true );
154 QWidget* activeWidget() const;
155 void setActiveWidget( QWidget* );
157 bool contains( QWidget* ) const;
159 QWidgetList widgetList() const;
161 bool isActive() const;
162 void updateActiveState();
164 QtxWorkstack* workstack() const;
166 virtual bool eventFilter( QObject*, QEvent* );
168 QRect floatRect() const;
169 QRect floatTab( const int ) const;
171 int tabAt( const QPoint& ) const;
174 void activated( QWidget* );
175 void contextMenuRequested( QWidget*, QPoint );
176 void deactivated( QtxWorkstackArea* );
184 void onSelected( int );
186 void onWidgetDestroyed();
188 void onChildDestroyed( QObject* );
189 void onChildShown( QtxWorkstackChild* );
190 void onChildHided( QtxWorkstackChild* );
191 void onChildActivated( QtxWorkstackChild* );
192 void onChildCaptionChanged( QtxWorkstackChild* );
194 void onDragActiveTab();
195 void onContextMenuRequested( QPoint );
198 virtual void customEvent( QCustomEvent* );
199 virtual void focusInEvent( QFocusEvent* );
200 virtual void mousePressEvent( QMouseEvent* );
203 enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
207 void updateCurrent();
208 void updateTab( QWidget* );
210 QWidget* widget( const int ) const;
211 int widgetId( QWidget* ) const;
212 bool widgetVisibility( QWidget* ) const;
214 void setWidgetActive( QWidget* );
215 void setWidgetShown( QWidget*, const bool );
217 int generateId() const;
219 bool isBlocked( QWidget* ) const;
220 void setBlocked( QWidget*, const bool );
222 QtxWorkstackChild* child( QWidget* ) const;
227 WidgetInfo() : id( 0 ), vis( false ) {}
231 typedef QMap<QWidget*, bool> BlockMap;
232 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
233 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
236 QtxWorkstackTabBar* myBar;
237 QPushButton* myClose;
238 QWidgetStack* myStack;
241 WidgetInfoMap myInfo;
246 class QtxWorkstackChild : public QHBox
251 QtxWorkstackChild( QWidget*, QWidget* = 0 );
252 virtual ~QtxWorkstackChild();
254 QWidget* widget() const;
256 virtual bool eventFilter( QObject*, QEvent* );
259 void shown( QtxWorkstackChild* );
260 void hided( QtxWorkstackChild* );
261 void activated( QtxWorkstackChild* );
262 void captionChanged( QtxWorkstackChild* );
265 void onDestroyed( QObject* );
268 virtual void childEvent( QChildEvent* );
274 class QtxWorkstackTabBar : public QTabBar
279 QtxWorkstackTabBar( QWidget* = 0 );
280 virtual ~QtxWorkstackTabBar();
282 QRect tabRect( const int ) const;
284 void setActive( const bool );
287 void dragActiveTab();
288 void contextMenuRequested( QPoint );
291 virtual void mouseMoveEvent( QMouseEvent* );
292 virtual void mousePressEvent( QMouseEvent* );
293 virtual void mouseReleaseEvent( QMouseEvent* );
294 virtual void contextMenuEvent( QContextMenuEvent* );
296 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
302 class QtxWorkstackDrag : public QObject
307 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
308 virtual ~QtxWorkstackDrag();
310 virtual bool eventFilter( QObject*, QEvent* );
315 void updateTarget( const QPoint& );
316 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
317 void setTarget( QtxWorkstackArea*, const int );
321 void startDrawRect();
325 QtxWorkstackChild* myChild;
328 QtxWorkstackArea* myArea;
334 #pragma warning( default:4251 )