From 3a3731d5cc477ccf4ea1c8dd50e61373fbaa75b0 Mon Sep 17 00:00:00 2001 From: sln Date: Tue, 20 May 2008 09:04:05 +0000 Subject: [PATCH] NPAL19051: 1) Parameter 'wid' is added in windowList() method. It specifies area which windows have to be returned; if it is equal to null when widgets of all areas are retuned 2)New method move() is added for moving the first widget to the same area which the second widget belongs to. 3)New method stack() is added for grouping all windows in one area. 4)New auxiliary private method wgArea is added for detecting area containing given widget --- src/Qtx/QtxWorkstack.cxx | 111 +++++++++++++++++++++++++++++++++++++-- src/Qtx/QtxWorkstack.h | 5 +- 2 files changed, 112 insertions(+), 4 deletions(-) diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 3cf22f413..177dcca4b 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -74,12 +74,23 @@ QtxWorkstack::~QtxWorkstack() } /*! - \return list of all widgets in all areas + \brief Gets list of all widgets in all areas or in specified area which given + widget belong to + \param wid widget specifying area if it is equal to null when widgets of all + areas are retuned + \return list of widgets */ -QWidgetList QtxWorkstack::windowList() const +QWidgetList QtxWorkstack::windowList( QWidget* wid ) const { QPtrList lst; - areas( mySplit, lst, true ); + if ( !wid ) + areas( mySplit, lst, true ); + else + { + QtxWorkstackArea* area = wgArea( wid ); + if ( area ) + lst.append( area ); + } QWidgetList widList; for ( QPtrListIterator it( lst ); it.current(); ++it ) @@ -1522,6 +1533,100 @@ QtxWorkstack& QtxWorkstack::operator>>( QString& outParameters ) return (*this); } +/*! + \brief Gets area containing given widget + \param wid widget + \return pointer to QtxWorkstackArea* object +*/ +QtxWorkstackArea* QtxWorkstack::wgArea( QWidget* wid ) const +{ + QtxWorkstackArea* resArea = 0; + + QPtrList areaList; + areas( mySplit, areaList, true ); + + QtxWorkstackArea* area; + for ( area = areaList.first(); area; area = areaList.next() ) + { + if ( area->contains( wid ) ) + { + resArea = area; + break; + } + } + + return resArea; +} + +/*! + \brief Moves the first widget to the same area which the second widget belongs to + \param wid widget to be moved + \param wid_to widget specified the destination area + \param before specifies whether the first widget has to be moved before or after + the second widget + \return TRUE if operation is completed successfully, FALSE otherwise +*/ +bool QtxWorkstack::move( QWidget* wid, QWidget* wid_to, const bool before ) +{ + if ( wid && wid_to ) + { + QtxWorkstackArea* area_src = wgArea( wid ); + QtxWorkstackArea* area_to = wgArea( wid_to ); + if ( area_src && area_to ) + { + // find index of the second widget + QWidgetList wgList = area_to->widgetList(); + QWidget* it; + int idx = 0; + for ( it = wgList.first(); it; it = wgList.next(), idx++ ) + { + if ( it == wid_to ) + break; + } + + if ( idx < (int)wgList.count() ) // paranoidal check + { + if ( !before ) + idx++; + area_src->removeWidget( wid, true ); + area_to->insertWidget( wid, idx ); + return true; + } + } + } + return false; +} + +/*! + \brief Group all windows in one area + \return TRUE if operation is completed successfully, FALSE otherwise +*/ +void QtxWorkstack::stack() +{ + QWidgetList wgList = windowList(); + if ( !wgList.count() ) + return; // nothing to do + + QWidget* it; + QtxWorkstackArea* area_to = 0; + for ( it = wgList.first(); it; it = wgList.next() ) + { + QtxWorkstackArea* area_src = 0; + if ( !area_to ) + { + area_to = wgArea( it ); + area_src = area_to; + } + else + area_src = wgArea( it ); + + if ( area_src != area_to ) + { + area_src->removeWidget( it, true ); + area_to->insertWidget( it, -1 ); + } + } +} /*! Constructor diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index c31479cc6..1d3b2a4fc 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -63,7 +63,7 @@ public: QtxWorkstack( QWidget* = 0 ); virtual ~QtxWorkstack(); - QWidgetList windowList() const; + QWidgetList windowList( QWidget* = 0 ) const; QWidgetList splitWindowList() const; QWidget* activeWindow() const; @@ -72,6 +72,8 @@ public: void setAccel( const int, const int ); void split( const int ); + bool move( QWidget* wid, QWidget* wid_to, const bool before ); + void stack(); // STV: Useless function. wid->setFocus() should be used instead. // void OnTop( QWidget* wid); @@ -113,6 +115,7 @@ private: void insertWidget( QWidget*, QWidget*, QWidget* ); QtxWorkstackArea* areaAt( const QPoint& ) const; + QtxWorkstackArea* wgArea( QWidget* ) const; QtxWorkstackArea* targetArea(); QtxWorkstackArea* activeArea() const; -- 2.39.2