1 // File: QtxWorkstack.h
2 // Author: Sergey TELKOV
12 #include <qwidgetlist.h>
21 class QtxWorkstackArea;
22 class QtxWorkstackDrag;
23 class QtxWorkstackChild;
24 class QtxWorkstackTabBar;
27 #pragma warning( disable:4251 )
30 class QTX_EXPORT QtxWorkstack : public QWidget
35 enum { SplitVertical, SplitHorizontal, Close, Rename };
39 SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one
40 SPLIT_AT, //!< widgets before a given widget stays in they workarea, others are moved into a new one
41 SPLIT_MOVE //!< given widget is moved into a new workarea, others stay in an old one
45 QtxWorkstack( QWidget* = 0 );
46 virtual ~QtxWorkstack();
48 QWidgetList windowList() const;
49 QWidgetList splitWindowList() const;
51 QWidget* activeWindow() const;
53 int accel( const int ) const;
54 void setAccel( const int, const int );
56 void split( const int );
58 // STV: Useless function. wid->setFocus() should be used instead.
59 // void OnTop( QWidget* wid);
61 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
62 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
63 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
64 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
67 void windowActivated( QWidget* );
71 void splitHorizontal();
72 void onRenameActive();
77 void onDestroyed( QObject* );
78 void onWindowActivated( QWidget* );
79 void onContextMenuRequested( QWidget*, QPoint );
80 void onDeactivated( QtxWorkstackArea* );
83 virtual void childEvent( QChildEvent* );
84 virtual void customEvent( QCustomEvent* );
87 QSplitter* splitter( QtxWorkstackArea* ) const;
88 void splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
89 void areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
91 QSplitter* wrapSplitter( QtxWorkstackArea* );
92 void insertWidget( QWidget*, QWidget*, QWidget* );
93 void renameWindow( QWidget* );
95 QtxWorkstackArea* areaAt( const QPoint& ) const;
97 QtxWorkstackArea* targetArea();
98 QtxWorkstackArea* activeArea() const;
99 QtxWorkstackArea* currentArea() const;
101 void setActiveArea( QtxWorkstackArea* );
102 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
104 QtxWorkstackArea* createArea( QWidget* ) const;
107 void updateState( QSplitter* );
109 void distributeSpace( QSplitter* ) const;
110 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
111 const int need_pos, const int splitter_pos );
115 QtxWorkstackArea* myArea;
119 QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
121 friend class QtxWorkstackArea;
122 friend class QtxWorkstackDrag;
125 class QtxWorkstackArea : public QWidget
130 QtxWorkstackArea( QWidget* );
131 virtual ~QtxWorkstackArea();
133 bool isEmpty() const;
135 void insertWidget( QWidget*, const int = -1 );
136 void removeWidget( QWidget*, const bool = true );
138 QWidget* activeWidget() const;
139 void setActiveWidget( QWidget* );
141 bool contains( QWidget* ) const;
143 QWidgetList widgetList() const;
145 bool isActive() const;
146 void updateActiveState();
148 QtxWorkstack* workstack() const;
150 virtual bool eventFilter( QObject*, QEvent* );
152 QRect floatRect() const;
153 QRect floatTab( const int ) const;
155 int tabAt( const QPoint& ) const;
158 void activated( QWidget* );
159 void contextMenuRequested( QWidget*, QPoint );
160 void deactivated( QtxWorkstackArea* );
168 void onSelected( int );
170 void onWidgetDestroyed();
172 void onChildDestroyed( QObject* );
173 void onChildShown( QtxWorkstackChild* );
174 void onChildHided( QtxWorkstackChild* );
175 void onChildActivated( QtxWorkstackChild* );
176 void onChildCaptionChanged( QtxWorkstackChild* );
178 void onDragActiveTab();
179 void onContextMenuRequested( QPoint );
182 virtual void customEvent( QCustomEvent* );
183 virtual void focusInEvent( QFocusEvent* );
184 virtual void mousePressEvent( QMouseEvent* );
187 enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
191 void updateCurrent();
192 void updateTab( QWidget* );
194 QWidget* widget( const int ) const;
195 int widgetId( QWidget* ) const;
196 bool widgetVisibility( QWidget* ) const;
198 void setWidgetActive( QWidget* );
199 void setWidgetShown( QWidget*, const bool );
201 int generateId() const;
203 bool isBlocked( QWidget* ) const;
204 void setBlocked( QWidget*, const bool );
206 QtxWorkstackChild* child( QWidget* ) const;
211 WidgetInfo() : id( 0 ), vis( false ) {}
215 typedef QMap<QWidget*, bool> BlockMap;
216 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
217 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
220 QtxWorkstackTabBar* myBar;
221 QPushButton* myClose;
222 QWidgetStack* myStack;
225 WidgetInfoMap myInfo;
230 class QtxWorkstackChild : public QHBox
235 QtxWorkstackChild( QWidget*, QWidget* = 0 );
236 virtual ~QtxWorkstackChild();
238 QWidget* widget() const;
240 virtual bool eventFilter( QObject*, QEvent* );
243 void shown( QtxWorkstackChild* );
244 void hided( QtxWorkstackChild* );
245 void activated( QtxWorkstackChild* );
246 void captionChanged( QtxWorkstackChild* );
249 void onDestroyed( QObject* );
252 virtual void childEvent( QChildEvent* );
258 class QtxWorkstackTabBar : public QTabBar
263 QtxWorkstackTabBar( QWidget* = 0 );
264 virtual ~QtxWorkstackTabBar();
266 QRect tabRect( const int ) const;
268 void setActive( const bool );
271 void dragActiveTab();
272 void contextMenuRequested( QPoint );
275 virtual void mouseMoveEvent( QMouseEvent* );
276 virtual void mousePressEvent( QMouseEvent* );
277 virtual void mouseReleaseEvent( QMouseEvent* );
278 virtual void contextMenuEvent( QContextMenuEvent* );
280 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
286 class QtxWorkstackDrag : public QObject
291 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
292 virtual ~QtxWorkstackDrag();
294 virtual bool eventFilter( QObject*, QEvent* );
299 void updateTarget( const QPoint& );
300 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
301 void setTarget( QtxWorkstackArea*, const int );
305 void startDrawRect();
309 QtxWorkstackChild* myChild;
312 QtxWorkstackArea* myArea;
318 #pragma warning( default:4251 )