From 3e51c4c259f167b30aaf3c3d3e0bc6eb9cd93107 Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 2 Jun 2005 07:55:39 +0000 Subject: [PATCH] no message --- src/Qtx/QtxDockAction.cxx | 211 ++++++++++++++++++++++++++++++++++++-- src/Qtx/QtxDockAction.h | 13 ++- 2 files changed, 211 insertions(+), 13 deletions(-) diff --git a/src/Qtx/QtxDockAction.cxx b/src/Qtx/QtxDockAction.cxx index bcf788a1a..7e0187d85 100755 --- a/src/Qtx/QtxDockAction.cxx +++ b/src/Qtx/QtxDockAction.cxx @@ -22,7 +22,7 @@ QtxDockAction::QtxDockAction( QMainWindow* mw, const char* name ) myMain( mw ), myAutoAdd( true ), mySeparate( true ), -myAutoPlace( true ) +myAutoPlace( false ) { initialize( mw ); } @@ -39,7 +39,7 @@ QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMai myMain( mw ), myAutoAdd( true ), mySeparate( true ), -myAutoPlace( true ) +myAutoPlace( false ) { initialize( mw ); } @@ -56,7 +56,7 @@ QtxDockAction::QtxDockAction( const QString& text, const QIconSet& icon, const Q myMain( mw ), myAutoAdd( true ), mySeparate( true ), -myAutoPlace( true ) +myAutoPlace( false ) { initialize( mw ); } @@ -331,15 +331,10 @@ bool QtxDockAction::eventFilter( QObject* o, QEvent* e ) void QtxDockAction::restoreGeometry( QDockWindow* dw ) const { - QPtrList dwList; - - if ( dw ) - dwList.append( dw ); + if ( !dw ) + loadPlaceInfo(); else - dockWindows( dwList ); - - for ( QPtrListIterator it( dwList ); it.current(); ++it ) - loadPlaceInfo( it.current() ); + loadPlaceInfo( dw ); } /*! @@ -372,6 +367,8 @@ void QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& section if ( !resMgr || sec.isEmpty() ) return; + myNames = QStringList::split( "|", resMgr->stringValue( sec, "windows_list", QString::null ) ); + QMap map; QStringList params = resMgr->parameters( sec ); for ( QStringList::const_iterator it = params.begin(); it != params.end(); ++it ) @@ -409,9 +406,19 @@ void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section if ( !resMgr || sec.isEmpty() ) return; + QtxDockAction* that = (QtxDockAction*)this; + that->storeGeometry(); + + that->myNames.clear(); + collectNames( Minimized, that->myNames ); + for ( int i = DockTornOff; i < Minimized; i++ ) + collectNames( i, that->myNames ); + if ( clear ) resMgr->removeSection( sec ); + resMgr->setValue( sec, "windows_list", myNames.join( "|" ) ); + for ( GeomMap::ConstIterator it = myGeom.begin(); it != myGeom.end(); ++it ) saveGeometry( resMgr, sec, it.key(), it.data() ); } @@ -750,6 +757,121 @@ void QtxDockAction::loadPlaceInfo( QDockWindow* dw ) const that->myGeom.insert( myInfo[dw].name, inf ); } +/*! + Name: loadPlaceInfo [private] + Desc: Retrieve the stored place and geometry information to all dock windows. +*/ + +void QtxDockAction::loadPlaceInfo() const +{ + QMainWindow* mw = mainWindow(); + if ( !mw ) + return; + + typedef QPtrList DockWinList; + + DockWinList lst; + dockWindows( lst, mw ); + + QMap nameMap; + for ( QPtrListIterator itr( lst ); itr.current(); ++itr ) + { + QString name; + if ( myInfo.contains( itr.current() ) ) + name = myInfo[itr.current()].name; + + if ( !myGeom.contains( name ) ) + continue; + + nameMap.insert( name, itr.current() ); + } + + DockWinList winList; + for ( QStringList::const_iterator iter = myNames.begin(); iter != myNames.end(); ++iter ) + { + if ( nameMap.contains( *iter ) ) + winList.append( nameMap[*iter] ); + nameMap.remove( *iter ); + } + + for ( QMap::ConstIterator mIt = nameMap.begin(); mIt != nameMap.end(); ++mIt ) + winList.append( mIt.data() ); + + QMap winMap; + QMap geomMap; + + for ( QPtrListIterator it( winList ); it.current(); ++it ) + { + QString name; + if ( myInfo.contains( it.current() ) ) + name = myInfo[it.current()].name; + + if ( !myGeom.contains( name ) ) + continue; + + GeomInfo inf( myGeom[name] ); + geomMap.insert( it.current(), inf ); + if ( !winMap.contains( inf.place ) ) + winMap.insert( inf.place, DockWinList() ); + winMap[inf.place].append( it.current() ); + } + + loadPlaceArea( DockMinimized, mw, 0, + winMap.contains( DockMinimized ) ? winMap[DockMinimized] : DockWinList(), geomMap ); + for ( int i = DockTornOff; i < DockMinimized; i++ ) + { + loadPlaceArea( i, mw, dockArea( i ), winMap.contains( i ) ? winMap[i] : DockWinList(), geomMap ); + } +} + +/*! + Name: loadPlaceArea [private] + Desc: Set the place and geometry information to all dock windows in the area. +*/ + +void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area, + const QPtrList& dockList, + const QMap& geomMap ) const +{ + for ( QPtrListIterator it( dockList ); it.current(); ++it ) + { + if ( !geomMap.contains( it.current() ) ) + continue; + + const GeomInfo& inf = geomMap[it.current()]; + mw->moveDockWindow( it.current(), (Qt::Dock)place, inf.newLine, inf.index, inf.offset ); + } + + if ( !area ) + return; + + for ( QPtrListIterator itr( dockList ); itr.current(); ++itr ) + { + QDockWindow* dw = itr.current(); + if ( !geomMap.contains( dw ) ) + continue; + + const GeomInfo& inf = geomMap[dw]; + if ( place != DockTornOff ) + { + dw->setNewLine( inf.newLine ); + dw->setOffset( inf.offset ); + dw->setFixedExtentWidth( inf.fixW ); + dw->setFixedExtentHeight( inf.fixH ); + } + dw->setGeometry( inf.x, inf.y, inf.w, inf.h ); + + inf.vis ? dw->show() : dw->hide(); + } + + QWidget* wid = area; + if ( wid->layout() ) + { + wid->layout()->invalidate(); + wid->layout()->activate(); + } +} + /*! Name: action [private] Desc: Returns action for the given dock window. @@ -917,6 +1039,40 @@ int QtxDockAction::dockPlace( const QString& dockName ) const return res; } +/*! + Name: dockArea [private] + Desc: +*/ + +QDockArea* QtxDockAction::dockArea( const int place ) const +{ + if ( !mainWindow() ) + return 0; + + QDockArea* area = 0; + switch ( place ) + { + case DockTop: + area = mainWindow()->topDock(); + break; + case DockBottom: + area = mainWindow()->bottomDock(); + break; + case DockLeft: + area = mainWindow()->leftDock(); + break; + case DockRight: + area = mainWindow()->rightDock(); + break; + } + return area; +} + +/*! + Name: loadGeometry [private] + Desc: +*/ + bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec, const QString& name, GeomInfo& inf ) const { @@ -953,6 +1109,11 @@ bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec, return true; } +/*! + Name: saveGeometry [private] + Desc: +*/ + bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec, const QString& name, const GeomInfo& inf ) const { @@ -975,3 +1136,31 @@ bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec, return true; } + +/*! + Name: collectNames [private] + Desc: +*/ + +void QtxDockAction::collectNames( const int place, QStringList& lst ) const +{ + QPtrList winList; + QDockArea* area = dockArea( place ); + if ( area ) + winList = area->dockWindowList(); + else + winList = mainWindow()->dockWindows( (Qt::Dock)place ); + + for ( QPtrListIterator it( winList ); it.current(); ++it ) + { + QString name; + if ( myInfo.contains( it.current() ) ) + name = myInfo[it.current()].name; + if ( name.isEmpty() ) + name = windowName( it.current() ); + if ( name.isEmpty() ) + continue; + + lst.append( name ); + } +} diff --git a/src/Qtx/QtxDockAction.h b/src/Qtx/QtxDockAction.h index 4f1eeeec7..48b79233e 100755 --- a/src/Qtx/QtxDockAction.h +++ b/src/Qtx/QtxDockAction.h @@ -11,8 +11,9 @@ #include class QAction; -class QMainWindow; +class QDockArea; class QDockWindow; +class QMainWindow; class QtxResourceMgr; #ifdef WIN32 @@ -86,6 +87,7 @@ private: QString windowName( QDockWindow* ) const; void savePlaceInfo( QDockWindow* ); void loadPlaceInfo( QDockWindow* ) const; + void loadPlaceInfo() const; bool autoAddDockWindow( QDockWindow* ); void autoLoadPlaceInfo( QDockWindow* ); @@ -93,10 +95,13 @@ private: void splitMenuText( QString&, QString& ) const; QStringList splitText( const QString&, const QString& ) const; + QDockArea* dockArea( const int ) const; int dockPlace( const QString& ) const; + void collectNames( const int, QStringList& ) const; + private: - enum { AutoAdd = QEvent::User }; + enum { AutoAdd = QEvent::User, LoadArea }; typedef struct { bool vis, newLine; int place, index, offset; @@ -113,12 +118,16 @@ private: const QString&, GeomInfo& ) const; bool saveGeometry( QtxResourceMgr*, const QString&, const QString&, const GeomInfo& ) const; + void loadPlaceArea( const int, QMainWindow*, QDockArea*, + const QPtrList&, + const QMap& ) const; private: InfoMap myInfo; MenuMap myMenu; GeomMap myGeom; QMainWindow* myMain; + QStringList myNames; bool myAutoAdd; bool mySeparate; -- 2.39.2