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();
76 void onDestroyed( QObject* );
77 void onWindowActivated( QWidget* );
78 void onContextMenuRequested( QWidget*, QPoint );
79 void onDeactivated( QtxWorkstackArea* );
82 virtual void childEvent( QChildEvent* );
83 virtual void customEvent( QCustomEvent* );
86 QSplitter* splitter( QtxWorkstackArea* ) const;
87 void splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
88 void areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
90 QSplitter* wrapSplitter( QtxWorkstackArea* );
91 void insertWidget( QWidget*, QWidget*, QWidget* );
93 QtxWorkstackArea* areaAt( const QPoint& ) const;
95 QtxWorkstackArea* targetArea();
96 QtxWorkstackArea* activeArea() const;
97 QtxWorkstackArea* currentArea() const;
99 void setActiveArea( QtxWorkstackArea* );
100 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
102 QtxWorkstackArea* createArea( QWidget* ) const;
105 void updateState( QSplitter* );
107 void distributeSpace( QSplitter* ) const;
108 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
109 const int need_pos, const int splitter_pos );
113 QtxWorkstackArea* myArea;
117 QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
119 friend class QtxWorkstackArea;
120 friend class QtxWorkstackDrag;
123 class QtxWorkstackArea : public QWidget
128 QtxWorkstackArea( QWidget* );
129 virtual ~QtxWorkstackArea();
131 bool isEmpty() const;
133 void insertWidget( QWidget*, const int = -1 );
134 void removeWidget( QWidget*, const bool = true );
136 QWidget* activeWidget() const;
137 void setActiveWidget( QWidget* );
139 bool contains( QWidget* ) const;
141 QWidgetList widgetList() const;
143 bool isActive() const;
144 void updateActiveState();
146 QtxWorkstack* workstack() const;
148 virtual bool eventFilter( QObject*, QEvent* );
150 QRect floatRect() const;
151 QRect floatTab( const int ) const;
153 int tabAt( const QPoint& ) const;
156 void activated( QWidget* );
157 void contextMenuRequested( QWidget*, QPoint );
158 void deactivated( QtxWorkstackArea* );
166 void onSelected( int );
168 void onWidgetDestroyed();
170 void onChildDestroyed( QObject* );
171 void onChildShown( QtxWorkstackChild* );
172 void onChildHided( QtxWorkstackChild* );
173 void onChildActivated( QtxWorkstackChild* );
174 void onChildCaptionChanged( QtxWorkstackChild* );
176 void onDragActiveTab();
177 void onContextMenuRequested( QPoint );
180 virtual void customEvent( QCustomEvent* );
181 virtual void focusInEvent( QFocusEvent* );
182 virtual void mousePressEvent( QMouseEvent* );
185 enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
189 void updateCurrent();
190 void updateTab( QWidget* );
192 QWidget* widget( const int ) const;
193 int widgetId( QWidget* ) const;
194 bool widgetVisibility( QWidget* ) const;
196 void setWidgetActive( QWidget* );
197 void setWidgetShown( QWidget*, const bool );
199 int generateId() const;
201 bool isBlocked( QWidget* ) const;
202 void setBlocked( QWidget*, const bool );
204 QtxWorkstackChild* child( QWidget* ) const;
209 WidgetInfo() : id( 0 ), vis( false ) {}
213 typedef QMap<QWidget*, bool> BlockMap;
214 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
215 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
218 QtxWorkstackTabBar* myBar;
219 QPushButton* myClose;
220 QWidgetStack* myStack;
223 WidgetInfoMap myInfo;
228 class QtxWorkstackChild : public QHBox
233 QtxWorkstackChild( QWidget*, QWidget* = 0 );
234 virtual ~QtxWorkstackChild();
236 QWidget* widget() const;
238 virtual bool eventFilter( QObject*, QEvent* );
241 void shown( QtxWorkstackChild* );
242 void hided( QtxWorkstackChild* );
243 void activated( QtxWorkstackChild* );
244 void captionChanged( QtxWorkstackChild* );
247 void onDestroyed( QObject* );
250 virtual void childEvent( QChildEvent* );
256 class QtxWorkstackTabBar : public QTabBar
261 QtxWorkstackTabBar( QWidget* = 0 );
262 virtual ~QtxWorkstackTabBar();
264 QRect tabRect( const int ) const;
266 void setActive( const bool );
269 void dragActiveTab();
270 void contextMenuRequested( QPoint );
273 virtual void mouseMoveEvent( QMouseEvent* );
274 virtual void mousePressEvent( QMouseEvent* );
275 virtual void mouseReleaseEvent( QMouseEvent* );
276 virtual void contextMenuEvent( QContextMenuEvent* );
278 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
284 class QtxWorkstackDrag : public QObject
289 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
290 virtual ~QtxWorkstackDrag();
292 virtual bool eventFilter( QObject*, QEvent* );
297 void updateTarget( const QPoint& );
298 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
299 void setTarget( QtxWorkstackArea*, const int );
303 void startDrawRect();
307 QtxWorkstackChild* myChild;
310 QtxWorkstackArea* myArea;
316 #pragma warning( default:4251 )