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;
200 typedef QMap<QWidget*, bool> BlockMap;
201 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
202 typedef struct { int id; bool vis; } WidgetInfo;
203 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
206 QtxWorkstackTabBar* myBar;
207 QPushButton* myClose;
208 QWidgetStack* myStack;
211 WidgetInfoMap myInfo;
216 class QtxWorkstackChild : public QHBox
221 QtxWorkstackChild( QWidget*, QWidget* = 0 );
222 virtual ~QtxWorkstackChild();
224 QWidget* widget() const;
226 virtual bool eventFilter( QObject*, QEvent* );
229 void shown( QtxWorkstackChild* );
230 void hided( QtxWorkstackChild* );
231 void activated( QtxWorkstackChild* );
232 void captionChanged( QtxWorkstackChild* );
235 void onDestroyed( QObject* );
238 virtual void childEvent( QChildEvent* );
244 class QtxWorkstackTabBar : public QTabBar
249 QtxWorkstackTabBar( QWidget* = 0 );
250 virtual ~QtxWorkstackTabBar();
252 QRect tabRect( const int ) const;
254 void setActive( const bool );
257 void dragActiveTab();
258 void contextMenuRequested( QPoint );
261 virtual void mouseMoveEvent( QMouseEvent* );
262 virtual void mousePressEvent( QMouseEvent* );
263 virtual void mouseReleaseEvent( QMouseEvent* );
264 virtual void contextMenuEvent( QContextMenuEvent* );
266 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
272 class QtxWorkstackDrag : public QObject
277 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
278 virtual ~QtxWorkstackDrag();
280 virtual bool eventFilter( QObject*, QEvent* );
285 void updateTarget( const QPoint& );
286 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
287 void setTarget( QtxWorkstackArea*, const int );
291 void startDrawRect();
295 QtxWorkstackChild* myChild;
298 QtxWorkstackArea* myArea;
304 #pragma warning( default:4251 )