1 // File: QtxWorkstack.h
2 // Author: Sergey TELKOV
12 #include <qwidgetlist.h>
21 class QtxWorkstackArea;
22 class QtxWorkstackDrag;
23 class QtxWorkstackChild;
24 class QtxWorkstackTabBar;
26 class QTX_EXPORT QtxWorkstack : public QWidget
32 QtxWorkstack( QWidget* = 0 );
33 virtual ~QtxWorkstack();
35 QWidgetList windowList() const;
36 QWidgetList splitWindowList() const;
38 QWidget* activeWindow() const;
40 void split( const int );
42 enum { SplitVertical, SplitHorizontal, Close };
44 // begin: jfa 06.07.2005
46 SPLIT_STAY, //!< given widget stays in its workarea, others are moved into a new one
47 SPLIT_AT, //!< widgets before a given widget stays in they workarea, others are moved into a new one
48 SPLIT_MOVE //!< given widget is moved into a new workarea, others stay in an old one
52 * \brief Split workarea of the given widget on two parts.
53 * \param wid - widget, belonging to this workstack
54 * \param o - orientation of splitting (Qt::Horizontal or Qt::Vertical)
55 * \param type - type of splitting, see <VAR>SplitType</VAR> enumeration
57 void Split( QWidget* wid, const Qt::Orientation o, const SplitType type);
60 * \brief Put given widget on top of its workarea
61 * \param wid - widget, belonging to this workstack
63 void OnTop( QWidget* wid);
66 * \brief Move widget(s) from source workarea into target workarea
67 * or just reorder widgets inside one workarea.
68 * \param wid1 - widget from target workarea
69 * \param wid2 - widget from source workarea
70 * \param all - if this parameter is TRUE, all widgets from source workarea will
71 * be moved into the target one, else only the \a wid2 will be moved
73 * Move \a wid2 in target workarea. Put it right after \a wid1.
74 * If value of boolean argument is TRUE, all widgets from source workarea
75 * will be moved together with \a wid2, source workarea will be deleted.
76 * If \a wid1 and \a wid2 belongs to one workarea, simple reordering will take place.
78 void Attract( QWidget* wid1, QWidget* wid2, const bool all );
81 * \brief Set position of the widget relatively its splitter.
82 * \param wid - widget to set position of
83 * \param pos - position relatively splitter. Value in range [0..1].
85 * Orientation of positioning will correspond to the splitter orientation.
87 void SetRelativePositionInSplitter( QWidget* wid, const double pos );
90 * \brief Set position of the widget relatively the entire workstack.
91 * \param wid - widget to set position of
92 * \param o - orientation of positioning (Qt::Horizontal or Qt::Vertical).
93 * If o = Qt::Horizontal, horizontal position of \a wid will be changed.
94 * If o = Qt::Vertical, vertical position of \a wid will be changed.
95 * \param pos - position relatively workstack. Value in range [0..1].
97 void SetRelativePosition( QWidget* wid, const Qt::Orientation o, const double pos );
98 // end: jfa 06.07.2005
101 * \brief Sets the action's accelerator key to accel.
102 * \param id - the key of the action in the actions map.
103 * \param accel - action's accelerator key.
105 void setAccel( const int id, const int accel );
108 * \brief Returns the action's accelerator key.
109 * \param id - the key of the action in the actions map.
110 * \retval int - action's accelerator key.
112 int accel (const int id) const;
115 void windowActivated( QWidget* );
118 void splitVertical();
119 void splitHorizontal();
122 void onDestroyed( QObject* );
123 void onWindowActivated( QWidget* );
124 void onContextMenuRequested( QPoint );
125 void onDeactivated( QtxWorkstackArea* );
127 * \brief Closes the active window.
129 void onCloseWindow();
132 virtual void childEvent( QChildEvent* );
133 virtual void customEvent( QCustomEvent* );
136 QSplitter* splitter( QtxWorkstackArea* ) const;
137 void splitters( QSplitter*, QPtrList<QSplitter>&, const bool = false ) const;
138 void areas( QSplitter*, QPtrList<QtxWorkstackArea>&, const bool = false ) const;
140 QSplitter* wrapSplitter( QtxWorkstackArea* );
141 void insertWidget( QWidget*, QWidget*, QWidget* );
143 QtxWorkstackArea* areaAt( const QPoint& ) const;
145 QtxWorkstackArea* targetArea();
146 QtxWorkstackArea* activeArea() const;
147 QtxWorkstackArea* currentArea() const;
149 void setActiveArea( QtxWorkstackArea* );
150 QtxWorkstackArea* neighbourArea( QtxWorkstackArea* ) const;
152 QtxWorkstackArea* createArea( QWidget* ) const;
155 void updateState( QSplitter* );
157 void distributeSpace( QSplitter* ) const;
159 // begin: jfa 06.07.2005
161 * \brief Set position of given widget.
162 * \param wid - widget to be moved
163 * \param split - currently processed splitter (goes from more common
164 * to more particular splitter in recursion calls)
165 * \param o - orientation of positioning
166 * \param need_pos - required position of the given widget in pixels
167 * (from top/left side of workstack area)
168 * \param splitter_pos - position of the splitter \a split
169 * (from top/left side of workstack area)
170 * \retval int - returns difference between a required and a distinguished position.
172 * Internal method. Recursively calls itself.
173 * Is called from <VAR>SetRelativePosition</VAR> public method.
175 int setPosition( QWidget* wid, QSplitter* split, const Qt::Orientation o,
176 const int need_pos, const int splitter_pos);
177 // end: jfa 06.07.2005
181 QtxWorkstackArea* myArea;
184 QMap<int, QAction*> myActionsMap; //!< The map of the actions. Allows to get the QAction object by the key.
186 friend class QtxWorkstackArea;
187 friend class QtxWorkstackDrag;
190 class QtxWorkstackArea : public QWidget
195 QtxWorkstackArea( QWidget* );
196 virtual ~QtxWorkstackArea();
198 bool isEmpty() const;
200 void insertWidget( QWidget*, const int = -1 );
201 void removeWidget( QWidget* );
203 QWidget* activeWidget() const;
204 void setActiveWidget( QWidget* );
206 bool contains( QWidget* ) const;
208 QWidgetList widgetList() const;
210 bool isActive() const;
211 void updateActiveState();
213 QtxWorkstack* workstack() const;
215 virtual bool eventFilter( QObject*, QEvent* );
217 QRect floatRect() const;
218 QRect floatTab( const int ) const;
220 int tabAt( const QPoint& ) const;
223 void activated( QWidget* );
224 void contextMenuRequested( QPoint );
225 void deactivated( QtxWorkstackArea* );
233 void onSelected( int );
235 void onDragActiveTab();
236 void onChildDestroyed( QObject* );
237 void onChildShown( QtxWorkstackChild* );
238 void onChildHided( QtxWorkstackChild* );
239 void onChildActivated( QtxWorkstackChild* );
240 void onChildCaptionChanged( QtxWorkstackChild* );
243 virtual void customEvent( QCustomEvent* );
244 virtual void focusInEvent( QFocusEvent* );
245 virtual void mousePressEvent( QMouseEvent* );
248 enum { ActivateWidget = QEvent::User, FocusWidget, RemoveWidget };
252 void updateCurrent();
253 void updateTab( QWidget* );
255 QWidget* widget( const int ) const;
256 int widgetId( QWidget* ) const;
257 bool widgetVisibility( QWidget* ) const;
259 void setWidgetActive( QWidget* );
260 void setWidgetShown( QWidget*, const bool );
262 int generateId() const;
264 bool isBlocked( QWidget* ) const;
265 void setBlocked( QWidget*, const bool );
267 QtxWorkstackChild* child( QWidget* ) const;
270 typedef QMap<QWidget*, bool> BlockMap;
271 typedef QMap<QWidget*, QtxWorkstackChild*> ChildMap;
272 typedef struct { int id; bool vis; } WidgetInfo;
273 typedef QMap<QWidget*, WidgetInfo> WidgetInfoMap;
276 QtxWorkstackTabBar* myBar;
277 QPushButton* myClose;
278 QWidgetStack* myStack;
281 WidgetInfoMap myInfo;
286 class QtxWorkstackChild : public QHBox
291 QtxWorkstackChild( QWidget*, QWidget* = 0 );
292 virtual ~QtxWorkstackChild();
294 QWidget* widget() const;
296 virtual bool eventFilter( QObject*, QEvent* );
299 void shown( QtxWorkstackChild* );
300 void hided( QtxWorkstackChild* );
301 void activated( QtxWorkstackChild* );
302 void captionChanged( QtxWorkstackChild* );
305 void onDestroyed( QObject* );
308 virtual void childEvent( QChildEvent* );
314 class QtxWorkstackTabBar : public QTabBar
319 QtxWorkstackTabBar( QWidget* = 0 );
320 virtual ~QtxWorkstackTabBar();
322 QRect tabRect( const int ) const;
324 void setActive( const bool );
327 void dragActiveTab();
328 void contextMenuRequested( QPoint );
331 virtual void mouseMoveEvent( QMouseEvent* );
332 virtual void mousePressEvent( QMouseEvent* );
333 virtual void mouseReleaseEvent( QMouseEvent* );
334 virtual void contextMenuEvent( QContextMenuEvent* );
336 virtual void paintLabel( QPainter*, const QRect&, QTab*, bool ) const;
342 class QtxWorkstackDrag : public QObject
347 QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* );
348 virtual ~QtxWorkstackDrag();
350 virtual bool eventFilter( QObject*, QEvent* );
355 void updateTarget( const QPoint& );
356 QtxWorkstackArea* detectTarget( const QPoint&, int& ) const;
357 void setTarget( QtxWorkstackArea*, const int );
361 void startDrawRect();
365 QtxWorkstackChild* myChild;
368 QtxWorkstackArea* myArea;