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 };
38 SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one
39 SPLIT_AT, //!< widgets before a given widget stays in they workarea, others are moved into a new one
40 SPLIT_MOVE //!< given widget is moved into a new workarea, others stay in an old one
44 QtxWorkstack( QWidget* = 0 );
45 virtual ~QtxWorkstack();
47 QWidgetList windowList() const;
48 QWidgetList splitWindowList() const;
50 QWidget* activeWindow() const;
52 int accel( const int ) const;
53 void setAccel( const int, const int );
55 void split( const int );
57 // STV: Useless function. wid->setFocus() should be used instead.
58 // void OnTop( QWidget* wid);
60 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type );
61 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
62 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
63 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
66 void windowActivated( QWidget* );
70 void splitHorizontal();
74 void onDestroyed( QObject* );
75 void onWindowActivated( QWidget* );
76 void onContextMenuRequested( QPoint );
77 void onDeactivated( QtxWorkstackArea* );
80 virtual void childEvent( QChildEvent* );
81 virtual void customEvent( QCustomEvent* );
84 QSplitter* splitter( QtxWorkstackArea* ) const;
85 void splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
86 void areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
88 QSplitter* wrapSplitter( QtxWorkstackArea* );
89 void insertWidget( QWidget*, QWidget*, QWidget* );
91 QtxWorkstackArea* areaAt( const QPoint& ) const;
93 QtxWorkstackArea* targetArea();
94 QtxWorkstackArea* activeArea() const;
95 QtxWorkstackArea* currentArea() const;
97 void setActiveArea( QtxWorkstackArea* );
98 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
100 QtxWorkstackArea* createArea( QWidget* ) const;
103 void updateState( QSplitter* );
105 void distributeSpace( QSplitter* ) const;
106 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
107 const int need_pos, const int splitter_pos );
111 QtxWorkstackArea* myArea;
114 QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
116 friend class QtxWorkstackArea;
117 friend class QtxWorkstackDrag;
120 class QtxWorkstackArea : public QWidget
125 QtxWorkstackArea( QWidget* );
126 virtual ~QtxWorkstackArea();
128 bool isEmpty() const;
130 void insertWidget( QWidget*, const int = -1 );
131 void removeWidget( QWidget* );
133 QWidget* activeWidget() const;
134 void setActiveWidget( QWidget* );
136 bool contains( QWidget* ) const;
138 QWidgetList widgetList() const;
140 bool isActive() const;
141 void updateActiveState();
143 QtxWorkstack* workstack() const;
145 virtual bool eventFilter( QObject*, QEvent* );
147 QRect floatRect() const;
148 QRect floatTab( const int ) const;
150 int tabAt( const QPoint& ) const;
153 void activated( QWidget* );
154 void contextMenuRequested( QPoint );
155 void deactivated( QtxWorkstackArea* );
163 void onSelected( int );
165 void onDragActiveTab();
166 void onChildDestroyed( QObject* );
167 void onChildShown( QtxWorkstackChild* );
168 void onChildHided( QtxWorkstackChild* );
169 void onChildActivated( QtxWorkstackChild* );
170 void onChildCaptionChanged( QtxWorkstackChild* );
173 virtual void customEvent( QCustomEvent* );
174 virtual void focusInEvent( QFocusEvent* );
175 virtual void mousePressEvent( QMouseEvent* );
178 enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
182 void updateCurrent();
183 void updateTab( QWidget* );
185 QWidget* widget( const int ) const;
186 int widgetId( QWidget* ) const;
187 bool widgetVisibility( QWidget* ) const;
189 void setWidgetActive( QWidget* );
190 void setWidgetShown( QWidget*, const bool );
192 int generateId() const;
194 bool isBlocked( QWidget* ) const;
195 void setBlocked( QWidget*, const bool );
197 QtxWorkstackChild* child( QWidget* ) const;
202 WidgetInfo() : id( 0 ), vis( false ) {}
206 typedef QMap<QWidget*, bool> BlockMap;
207 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
208 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
211 QtxWorkstackTabBar* myBar;
212 QPushButton* myClose;
213 QWidgetStack* myStack;
216 WidgetInfoMap myInfo;
221 class QtxWorkstackChild : public QHBox
226 QtxWorkstackChild( QWidget*, QWidget* = 0 );
227 virtual ~QtxWorkstackChild();
229 QWidget* widget() const;
231 virtual bool eventFilter( QObject*, QEvent* );
234 void shown( QtxWorkstackChild* );
235 void hided( QtxWorkstackChild* );
236 void activated( QtxWorkstackChild* );
237 void captionChanged( QtxWorkstackChild* );
240 void onDestroyed( QObject* );
243 virtual void childEvent( QChildEvent* );
249 class QtxWorkstackTabBar : public QTabBar
254 QtxWorkstackTabBar( QWidget* = 0 );
255 virtual ~QtxWorkstackTabBar();
257 QRect tabRect( const int ) const;
259 void setActive( const bool );
262 void dragActiveTab();
263 void contextMenuRequested( QPoint );
266 virtual void mouseMoveEvent( QMouseEvent* );
267 virtual void mousePressEvent( QMouseEvent* );
268 virtual void mouseReleaseEvent( QMouseEvent* );
269 virtual void contextMenuEvent( QContextMenuEvent* );
271 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
277 class QtxWorkstackDrag : public QObject
282 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
283 virtual ~QtxWorkstackDrag();
285 virtual bool eventFilter( QObject*, QEvent* );
290 void updateTarget( const QPoint& );
291 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
292 void setTarget( QtxWorkstackArea*, const int );
296 void startDrawRect();
300 QtxWorkstackChild* myChild;
303 QtxWorkstackArea* myArea;
309 #pragma warning( default:4251 )