1 // File: QtxDockAction.cxx
2 // Author: Sergey TELKOV
4 #include "QtxDockAction.h"
6 #include "QtxResourceMgr.h"
10 #include <qdockarea.h>
11 #include <qdockwindow.h>
12 #include <qmainwindow.h>
13 #include <qapplication.h>
16 Name: QtxDockAction [public]
17 Desc: Constructs an Dock action with given main window and name.
20 QtxDockAction::QtxDockAction( QMainWindow* mw, const char* name )
21 : QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw, name ),
31 Name: QtxDockAction [public]
32 Desc: This constructor creates an action with the following properties: the
33 description text, the menu text and. It is a child of given main window
34 and named specified name.
37 QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw, const char* name )
38 : QtxAction( text, menuText, 0, mw, name ),
48 Name: QtxDockAction [public]
49 Desc: This constructor creates an action with the following properties: the
50 description text, the menu text, the icon or iconset icon and keyboard
51 accelerator. It is a child of given main window and named specified name.
54 QtxDockAction::QtxDockAction( const QString& text, const QIconSet& icon, const QString& menuText, QMainWindow* mw, const char* name )
55 : QtxAction( text, icon, menuText, 0, mw, name ),
65 Name: ~QtxDockAction [public]
66 Desc: Removes all added popup items.
69 QtxDockAction::~QtxDockAction()
71 for ( MenuMap::ConstIterator mIt = myMenu.begin(); mIt != myMenu.end(); ++mIt )
72 removeFrom( mIt.key() );
74 for ( InfoMap::ConstIterator iIt = myInfo.begin(); iIt != myInfo.end(); ++iIt )
79 Name: mainWindow [public]
80 Desc: Returns the main window which contains managed dock windows.
83 QMainWindow* QtxDockAction::mainWindow() const
89 Name: isAutoAdd [public]
90 Desc: Returns the auto add property. If this property is setted then all newly
91 appeared dock windows will be automatically added.
94 bool QtxDockAction::isAutoAdd() const
100 Name: setAutoAdd [public]
101 Desc: Sets the auto add property. If this property is setted then all newly
102 appeared dock windows will be automatically added.
105 void QtxDockAction::setAutoAdd( const bool on )
111 Name: isAutoPlace [public]
112 Desc: Returns the auto place property. If this property is setted then all newly
113 added dock windows will be automatically placed according stored place information.
116 bool QtxDockAction::isAutoPlace() const
122 Name: setAutoPlace [public]
123 Desc: Sets the auto place property. If this property is setted then all newly
124 added dock windows will be automatically placed according stored place
128 void QtxDockAction::setAutoPlace( const bool on )
134 Name: isSeparate [public]
135 Desc: Returns the 'separate' property.
138 bool QtxDockAction::isSeparate() const
144 Name: setSeparate [public]
145 Desc: Sets the 'separate' property. If this property is 'true' then toolbars and
146 dock windows menu items will be placed in different popup menus otherwise
147 their will be placed in one common popup menu. This property will be
148 affected in next method 'addTo'.
151 void QtxDockAction::setSeparate( const bool on )
153 if ( mySeparate == on )
162 Desc: Add the dock windows sub menu item to the end of specified popup.
165 bool QtxDockAction::addTo( QWidget* wid )
167 return addTo( wid, -1 );
172 Desc: Add the dock windows sub menu item to specified popup at the given index.
175 bool QtxDockAction::addTo( QWidget* wid, const int idx )
177 if ( !wid || !wid->inherits( "QPopupMenu" ) )
180 QPopupMenu* pm = (QPopupMenu*)wid;
183 if ( myMenu.contains( pm ) )
187 mInfo.dock = new QPopupMenu( pm );
188 mInfo.tool = isSeparate() ? new QPopupMenu( pm ) : 0;
191 splitMenuText( dock, tool );
193 myMenu.insert( pm, mInfo );
198 iconSet().isNull() ? pm->insertItem ( dock, mInfo.dock, -1, index ) :
199 pm->insertItem ( iconSet(), dock, mInfo.dock, -1, index );
205 iconSet().isNull() ? pm->insertItem ( tool, mInfo.tool, -1, index ) :
206 pm->insertItem ( iconSet(), tool, mInfo.tool, -1, index );
208 connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
209 connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
215 Name: removeFrom [public]
216 Desc: Removes dock window sub menu from specified popup.
219 bool QtxDockAction::removeFrom( QWidget* wid )
221 QPopupMenu* pm = (QPopupMenu*)wid;
223 if ( myMenu.contains( pm ) )
225 pm->removeItem( findId( pm, myMenu[pm].dock ) );
226 pm->removeItem( findId( pm, myMenu[pm].tool ) );
228 delete myMenu[pm].dock;
229 delete myMenu[pm].tool;
232 disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
233 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
236 return QtxAction::removeFrom( wid );
239 void QtxDockAction::setMenuText( const QString& txt )
241 if ( menuText() == txt )
244 QtxAction::setMenuText( txt );
249 Name: addDockWindow [public]
250 Desc: Add dock window to internal data structures. Action will be include all added
251 dock windows in to menu and manage their place configuration.
254 bool QtxDockAction::addDockWindow( QDockWindow* dw )
256 if ( !dw || !mainWindow() )
259 if ( myInfo.contains( dw ) )
262 myInfo.insert( dw, DockInfo() );
264 DockInfo& inf = myInfo[dw];
265 inf.name = windowName( dw );
266 QAction* a = inf.a = new QAction( mainWindow(), 0, true );
268 autoLoadPlaceInfo( dw );
270 bool block = a->signalsBlocked();
271 a->blockSignals( true );
272 a->setOn( dw->isVisibleTo( mainWindow() ) );
273 a->blockSignals( block );
278 dw->installEventFilter( this );
280 connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
281 connect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
282 connect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
288 Name: removeDockWindow [public]
289 Desc: Remove dock window from internal data structures. Action will not manage this window.
292 bool QtxDockAction::removeDockWindow( QDockWindow* dw )
294 if ( !myInfo.contains( dw ) )
297 myGeom.remove( myInfo[dw].name );
302 dw->removeEventFilter( this );
304 disconnect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
305 disconnect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
311 Name: eventFilter [public]
312 Desc: Event filter process caption and icon changing of managed dock windows
313 and try to add newly appeared dock windows.
316 bool QtxDockAction::eventFilter( QObject* o, QEvent* e )
318 if ( o->inherits( "QDockWindow" ) && ( e->type() == QEvent::CaptionChange ||
319 e->type() == QEvent::IconChange ) )
320 updateInfo( (QDockWindow*)o );
322 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildRemoved )
324 QChildEvent* ce = (QChildEvent*)e;
325 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
326 savePlaceInfo( (QDockWindow*)ce->child() );
329 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildInserted )
331 QChildEvent* ce = (QChildEvent*)e;
332 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
333 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, ce->child() ) );
340 Name: restoreGeometry [public]
341 Desc: Retrieve the dock window geometry. If dock window specified as 0
342 then all windows geometry will be restored.
345 void QtxDockAction::restoreGeometry( QDockWindow* dw ) const
354 Name: storeGeometry [public]
355 Desc: Store the dock window geometry. If dock window specified as 0
356 then all windows geometry will be stored.
359 void QtxDockAction::storeGeometry( QDockWindow* dw )
361 QPtrList<QDockWindow> dwList;
366 dockWindows( dwList );
368 for ( QPtrListIterator<QDockWindow> it( dwList ); it.current(); ++it )
369 savePlaceInfo( it.current() );
373 Name: loadGeometry [public]
374 Desc: Retrieve the dock windows geometry information from the specified resource manager section.
377 void QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear )
379 QString sec = section.stripWhiteSpace();
380 if ( !resMgr || sec.isEmpty() )
383 myNames = QStringList::split( "|", resMgr->stringValue( sec, "windows_list", QString::null ) );
385 QMap<QString, int> map;
386 QStringList params = resMgr->parameters( sec );
387 for ( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
389 QString p = QStringList::split( ".", *it, true ).first().stripWhiteSpace();
394 for ( QMap<QString, int>::ConstIterator itr = map.begin(); itr != map.end(); ++itr )
397 if ( !clear && myGeom.contains( itr.key() ) )
398 inf = myGeom[itr.key()];
401 inf.vis = true; inf.newLine = false; inf.place = DockTop;
402 inf.index = 0; inf.offset = 0;
403 inf.x = 0; inf.y = 0; inf.w = 0; inf.h = 0;
404 inf.fixW = -1; inf.fixH = -1;
406 if ( loadGeometry( resMgr, sec, itr.key(), inf ) )
407 myGeom.insert( itr.key(), inf );
412 Name: saveGeometry [public]
413 Desc: Store the dock windows geometry information into the specified resource manager section.
416 void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const
418 QString sec = section.stripWhiteSpace();
419 if ( !resMgr || sec.isEmpty() )
422 QtxDockAction* that = (QtxDockAction*)this;
423 that->storeGeometry();
425 that->myNames.clear();
426 collectNames( Minimized, that->myNames );
427 for ( int i = DockTornOff; i < Minimized; i++ )
428 collectNames( i, that->myNames );
431 resMgr->remove( sec );
433 resMgr->setValue( sec, "windows_list", myNames.join( "|" ) );
435 for ( GeomMap::ConstIterator it = myGeom.begin(); it != myGeom.end(); ++it )
436 saveGeometry( resMgr, sec, it.key(), it.data() );
440 Name: onAboutToShow [private slots]
441 Desc: Prepare sub popup with dock windows list when parent popup is shown.
444 void QtxDockAction::onAboutToShow()
446 const QObject* obj = sender();
447 if ( obj && obj->inherits( "QPopupMenu" ) )
449 QPopupMenu* pm = (QPopupMenu*)obj;
451 pm->setItemEnabled( findId( pm, myMenu[pm].dock ), isEnabled() && myMenu[pm].dock && myMenu[pm].dock->count() );
452 pm->setItemEnabled( findId( pm, myMenu[pm].tool ), isEnabled() && myMenu[pm].tool && myMenu[pm].tool->count() );
457 Name: onToggled [private slots]
458 Desc: Show or hide dock window when user toggled window item in popup.
461 void QtxDockAction::onToggled( bool on )
463 QDockWindow* dw = dockWindow( (QAction*)sender() );
465 on ? dw->show() : dw->hide();
469 Name: onPopupDestroyed [private slots]
470 Desc: Remove destroyed popup from data structures.
473 void QtxDockAction::onPopupDestroyed( QObject* obj )
475 myMenu.remove( (QPopupMenu*)obj );
479 Name: onWindowDestroyed [private slots]
480 Desc: Remove information about destroyed dock window.
483 void QtxDockAction::onWindowDestroyed( QObject* obj )
485 QDockWindow* dw = (QDockWindow*)obj;
486 if ( !myInfo.contains( dw ) )
494 Name: onVisibilityChanged [private slots]
495 Desc: Toggle corresponded action when visibility state of dock window changed.
498 void QtxDockAction::onVisibilityChanged( bool on )
500 const QObject* obj = sender();
501 if ( !obj || !obj->inherits( "QDockWindow" ) )
504 QDockWindow* dw = (QDockWindow*)obj;
506 QAction* a = action( dw );
507 if ( a && a->isOn() != on )
509 bool block = a->signalsBlocked();
510 a->blockSignals( true );
512 a->blockSignals( block );
519 Name: onDockWindowPositionChanged [private slots]
520 Desc: Update dock window place information
523 void QtxDockAction::onDockWindowPositionChanged( QDockWindow* dw )
529 Name: event [protected]
530 Desc: Check consistency the popup content and internal datas.
531 Synchronize internal data structures with popup content.
534 bool QtxDockAction::event( QEvent* e )
536 if ( e->type() == (int)AutoAdd )
538 QCustomEvent* ce = (QCustomEvent*)e;
539 QDockWindow* dw = (QDockWindow*)ce->data();
540 if ( !myInfo.contains( dw ) )
542 autoAddDockWindow( dw );
543 autoLoadPlaceInfo( dw );
547 return QtxAction::event( e );
551 Name: checkPopup [private]
552 Desc: Check consistency the popup content and internal datas.
553 Synchronize internal data structures with popup content.
556 void QtxDockAction::checkPopup( QPopupMenu* pm )
558 if ( !myMenu.contains( pm ) )
561 int id = findId( pm, myMenu[pm].dock );
564 delete myMenu[pm].dock;
567 id = findId( pm, myMenu[pm].tool );
570 delete myMenu[pm].tool;
574 if ( !myMenu[pm].dock )
576 delete myMenu[pm].tool;
578 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
583 Name: fillPopup [private]
584 Desc: Clear the popup and the add to it required actions.
587 void QtxDockAction::fillPopup( QPopupMenu* pm ) const
589 if ( !pm || !mainWindow() )
592 if ( !myMenu.contains( pm ) )
595 QPopupMenu* dockMenu = myMenu[pm].dock;
596 QPopupMenu* toolMenu = myMenu[pm].tool;
598 for ( InfoMap::ConstIterator mit = myInfo.begin(); mit != myInfo.end(); ++mit )
600 mit.data().a->removeFrom( dockMenu );
601 mit.data().a->removeFrom( toolMenu );
610 QPtrList<QDockWindow> dockList;
611 dockWindows( dockList, mainWindow() );
613 if ( dockList.isEmpty() )
616 QPtrList<QAction> toolBars, windows;
617 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
619 if ( !myInfo.contains( it.current() ) )
621 QtxDockAction* that = (QtxDockAction*)this;
622 that->autoAddDockWindow( it.current() );
625 if ( !mainWindow()->appropriate( it.current() ) ||
626 it.current()->caption().isEmpty() || !action( it.current() ) )
629 if ( isToolBar( it.current() ) )
630 toolBars.append( action( it.current() ) );
632 windows.append( action( it.current() ) );
635 for ( QPtrListIterator<QAction> wit( windows ); wit.current(); ++wit )
636 wit.current()->addTo( dockMenu );
638 dockMenu->insertSeparator();
640 for ( QPtrListIterator<QAction> tit( toolBars ); tit.current(); ++tit )
641 tit.current()->addTo( toolMenu ? toolMenu : dockMenu );
643 Qtx::simplifySeparators( dockMenu );
644 Qtx::simplifySeparators( toolMenu );
648 Name: isToolBar [private]
649 Desc: Returns 'true' if dock window is a toolbar.
652 bool QtxDockAction::isToolBar( QDockWindow* dw ) const
654 return dw && dw->inherits( "QToolBar" );
658 Name: findId [private]
659 Desc: Returns identificator of popup item which contains sub popup 'pm' in the popup 'cont'.
662 int QtxDockAction::findId( QPopupMenu* cont, QPopupMenu* pm ) const
669 for ( int i = 0; i < (int)cont->count() && id == -1; i++ )
672 QMenuItem* item = cont->findItem( cont->idAt( i ), &md );
673 if ( item && md == cont && item->popup() == pm )
680 Name: dockWindows [private]
681 Desc: Returns all dock windows of the main window.
684 void QtxDockAction::dockWindows( QPtrList<QDockWindow>& lst, QMainWindow* main ) const
688 QMainWindow* mw = main ? main : mainWindow();
692 lst = mw->dockWindows();
696 Name: updateInfo [private]
697 Desc: Updates icon and caption info of dock window in the corresponded action.
700 void QtxDockAction::updateInfo( QDockWindow* dw )
702 QAction* a = action( dw );
706 a->setText( dw->caption() );
707 a->setMenuText( dw->caption() );
709 if ( isToolBar( dw ) )
710 a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) );
712 a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) );
714 const QPixmap* icon = dw->icon();
716 a->setIconSet( *icon );
720 Name: savePlaceInfo [private]
721 Desc: Store the place and geometry information from specified dock window.
724 void QtxDockAction::savePlaceInfo( QDockWindow* dw )
726 if ( !myInfo.contains( dw ) )
729 if ( !myGeom.contains( myInfo[dw].name ) )
730 myGeom.insert( myInfo[dw].name, GeomInfo() );
732 GeomInfo& inf = myGeom[myInfo[dw].name];
735 inf.vis = dw->isVisibleTo( mainWindow() );
736 mainWindow()->getLocation( dw, dock, inf.index, inf.newLine, inf.offset );
742 inf.h = dw->height();
743 inf.fixW = dw->fixedExtent().width();
744 inf.fixH = dw->fixedExtent().height();
748 Name: loadPlaceInfo [private]
749 Desc: Retrieve the stored place and geometry information to specified dock window.
752 void QtxDockAction::loadPlaceInfo( QDockWindow* dw ) const
754 if ( !myInfo.contains( dw ) )
757 QString winName = myInfo[dw].name;
758 if ( winName.isEmpty() || !myGeom.contains( winName ) )
761 GeomInfo inf = myGeom[myInfo[dw].name];
763 mainWindow()->moveDockWindow( dw, (Qt::Dock)inf.place, inf.newLine, inf.index, inf.offset );
764 dw->setGeometry( inf.x, inf.y, inf.w, inf.h );
766 dw->setFixedExtentWidth( inf.fixW );
767 dw->setFixedExtentHeight( inf.fixH );
769 QtxDockAction* that = (QtxDockAction*)this;
770 that->myGeom.insert( myInfo[dw].name, inf );
774 Name: loadPlaceInfo [private]
775 Desc: Retrieve the stored place and geometry information to all dock windows.
778 void QtxDockAction::loadPlaceInfo() const
780 QMainWindow* mw = mainWindow();
784 typedef QPtrList<QDockWindow> DockWinList;
787 dockWindows( lst, mw );
789 QMap<QString, QDockWindow*> nameMap;
790 for ( QPtrListIterator<QDockWindow> itr( lst ); itr.current(); ++itr )
793 if ( myInfo.contains( itr.current() ) )
794 name = myInfo[itr.current()].name;
796 if ( !myGeom.contains( name ) )
799 nameMap.insert( name, itr.current() );
803 for ( QStringList::const_iterator iter = myNames.begin(); iter != myNames.end(); ++iter )
805 if ( nameMap.contains( *iter ) )
806 winList.append( nameMap[*iter] );
807 nameMap.remove( *iter );
810 for ( QMap<QString, QDockWindow*>::ConstIterator mIt = nameMap.begin(); mIt != nameMap.end(); ++mIt )
811 winList.append( mIt.data() );
813 QMap<int, DockWinList> winMap;
814 QMap<QDockWindow*, GeomInfo*> geomMap;
816 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
819 if ( myInfo.contains( it.current() ) )
820 name = myInfo[it.current()].name;
822 if ( !myGeom.contains( name ) )
825 //! collect pointer of info to have fresh info data after processEvents();
826 GeomInfo* inf = (GeomInfo*)&( myGeom[name] );
827 geomMap.insert( it.current(), inf );
828 if ( !winMap.contains( inf->place ) )
829 winMap.insert( inf->place, DockWinList() );
830 winMap[inf->place].append( it.current() );
833 loadPlaceArea( DockMinimized, mw, 0,
834 winMap.contains( DockMinimized ) ? winMap[DockMinimized] : DockWinList(), geomMap );
835 for ( int i = DockTornOff; i < DockMinimized; i++ )
837 loadPlaceArea( i, mw, dockArea( i ), winMap.contains( i ) ? winMap[i] : DockWinList(), geomMap );
842 Name: loadPlaceArea [private]
843 Desc: Set the place and geometry information to all dock windows in the area.
846 void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area,
847 const QPtrList<QDockWindow>& dockList,
848 const QMap<QDockWindow*, GeomInfo*>& geomMap ) const
850 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
852 if ( !geomMap.contains( it.current() ) )
855 GeomInfo* inf = geomMap[it.current()];
856 mw->moveDockWindow( it.current(), (Qt::Dock)place, inf->newLine, inf->index, inf->offset );
862 qApp->processEvents();
864 for ( QPtrListIterator<QDockWindow> itr( dockList ); itr.current(); ++itr )
866 QDockWindow* dw = itr.current();
867 if ( !geomMap.contains( dw ) )
870 GeomInfo* inf = geomMap[dw];
871 if ( place != DockTornOff )
873 dw->setNewLine( inf->newLine );
874 dw->setOffset( inf->offset );
875 dw->setFixedExtentWidth( inf->fixW );
876 dw->setFixedExtentHeight( inf->fixH );
878 dw->setGeometry( inf->x, inf->y, inf->w, inf->h );
880 QAction* a = action( dw );
883 bool block = a->signalsBlocked();
884 a->blockSignals( true );
885 a->setOn( inf->vis );
886 a->blockSignals( block );
889 if ( mainWindow() && mainWindow()->appropriate( dw ) )
890 inf->vis ? dw->show() : dw->hide();
896 wid->layout()->invalidate();
897 wid->layout()->activate();
902 Name: action [private]
903 Desc: Returns action for the given dock window.
906 QAction* QtxDockAction::action( QDockWindow* dw ) const
909 if ( myInfo.contains( dw ) )
915 Name: dockWindow [private]
916 Desc: Returns dock window for the given action.
919 QDockWindow* QtxDockAction::dockWindow( const QAction* a ) const
922 for ( InfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !dw; ++it )
924 if ( it.data().a == a )
931 Name: initialize [private]
932 Desc: Initialisation of the object. Sets the event filters and add existing dock windows.
935 void QtxDockAction::initialize( QMainWindow* mw )
940 QPtrList<QDockWindow> lst;
941 dockWindows( lst, mw );
943 for ( QPtrListIterator<QDockWindow> it( lst ); it.current(); ++it )
944 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, it.current() ) );
947 mw->topDock()->installEventFilter( this );
948 if ( mw->leftDock() )
949 mw->leftDock()->installEventFilter( this );
950 if ( mw->rightDock() )
951 mw->rightDock()->installEventFilter( this );
952 if ( mw->bottomDock() )
953 mw->bottomDock()->installEventFilter( this );
955 connect( mw, SIGNAL( dockWindowPositionChanged( QDockWindow* ) ),
956 this, SLOT( onDockWindowPositionChanged( QDockWindow* ) ) );
960 Name: windowName [private]
961 Desc: Generate the dock window name.
964 QString QtxDockAction::windowName( QDockWindow* dw ) const
970 name = dw->name( "" );
971 if ( name.isEmpty() )
972 name = dw->caption();
979 Name: autoAddDockWindow [private]
980 Desc: Add the dock window if auto add property is setted.
983 bool QtxDockAction::autoAddDockWindow( QDockWindow* dw )
988 return addDockWindow( dw );
992 Name: autoLoadPlaceInfo [private]
993 Desc: Retieve the dock window place geometry if auto place property is setted.
996 void QtxDockAction::autoLoadPlaceInfo( QDockWindow* dw )
1003 Name: splitMenuText [private]
1007 void QtxDockAction::splitMenuText( QString& dock, QString& tool ) const
1009 dock = tool = menuText();
1010 if ( !isSeparate() )
1013 QStringList lst = splitText( menuText(), "|" );
1014 if ( lst.count() < 2 )
1015 lst = splitText( menuText(), "and" );
1022 Name: splitText [private]
1026 QStringList QtxDockAction::splitText( const QString& str, const QString& sep ) const
1030 int idx = str.lower().find( sep.lower() );
1033 res.append( str.mid( 0, idx ).stripWhiteSpace() );
1034 res.append( str.mid( idx + sep.length() ).stripWhiteSpace() );
1041 Name: dockPlace [private]
1045 int QtxDockAction::dockPlace( const QString& dockName ) const
1047 static QMap<QString, int> dockNameMap;
1048 if ( dockNameMap.isEmpty() )
1050 dockNameMap["top"] = DockTop;
1051 dockNameMap["bottom"] = DockBottom;
1052 dockNameMap["left"] = DockLeft;
1053 dockNameMap["right"] = DockRight;
1054 dockNameMap["tornoff"] = DockTornOff;
1055 dockNameMap["torn_off"] = DockTornOff;
1056 dockNameMap["outside"] = DockTornOff;
1057 dockNameMap["undock"] = DockTornOff;
1058 dockNameMap["minimized"] = DockMinimized;
1059 dockNameMap["unmanaged"] = DockUnmanaged;
1063 if ( dockNameMap.contains( dockName.lower() ) )
1064 res = dockNameMap[dockName.lower()];
1069 Name: dockArea [private]
1073 QDockArea* QtxDockAction::dockArea( const int place ) const
1075 if ( !mainWindow() )
1078 QDockArea* area = 0;
1082 area = mainWindow()->topDock();
1085 area = mainWindow()->bottomDock();
1088 area = mainWindow()->leftDock();
1091 area = mainWindow()->rightDock();
1098 Name: loadGeometry [private]
1102 bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec,
1103 const QString& name, GeomInfo& inf ) const
1105 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1108 QString tmpl = QString( "%1.%2" ).arg( name );
1110 inf.vis = resMgr->booleanValue( sec, tmpl.arg( "visible" ), inf.vis );
1111 inf.newLine = resMgr->booleanValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1113 inf.index = resMgr->integerValue( sec, tmpl.arg( "index" ), inf.index );
1114 inf.offset = resMgr->integerValue( sec, tmpl.arg( "offset" ), inf.offset );
1116 inf.x = resMgr->integerValue( sec, tmpl.arg( "x" ), inf.x );
1117 inf.y = resMgr->integerValue( sec, tmpl.arg( "y" ), inf.y );
1118 inf.w = resMgr->integerValue( sec, tmpl.arg( "width" ), inf.w );
1119 inf.h = resMgr->integerValue( sec, tmpl.arg( "height" ), inf.h );
1121 inf.fixW = resMgr->integerValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1122 inf.fixH = resMgr->integerValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1125 if ( !resMgr->value( sec, tmpl.arg( "place" ), place ) )
1128 if ( resMgr->value( sec, tmpl.arg( "place" ), placeStr ) )
1129 place = dockPlace( placeStr );
1132 if ( place >= DockUnmanaged && place <= DockMinimized )
1139 Name: saveGeometry [private]
1143 bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec,
1144 const QString& name, const GeomInfo& inf ) const
1146 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1149 QString tmpl = QString( "%1.%2" ).arg( name );
1151 resMgr->setValue( sec, tmpl.arg( "visible" ), inf.vis );
1152 resMgr->setValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1153 resMgr->setValue( sec, tmpl.arg( "index" ), inf.index );
1154 resMgr->setValue( sec, tmpl.arg( "offset" ), inf.offset );
1155 resMgr->setValue( sec, tmpl.arg( "x" ), inf.x );
1156 resMgr->setValue( sec, tmpl.arg( "y" ), inf.y );
1157 resMgr->setValue( sec, tmpl.arg( "width" ), inf.w );
1158 resMgr->setValue( sec, tmpl.arg( "height" ), inf.h );
1159 resMgr->setValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1160 resMgr->setValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1161 resMgr->setValue( sec, tmpl.arg( "place" ), inf.place );
1167 Name: collectNames [private]
1171 void QtxDockAction::collectNames( const int place, QStringList& lst ) const
1173 QPtrList<QDockWindow> winList;
1174 QDockArea* area = dockArea( place );
1176 winList = area->dockWindowList();
1178 winList = mainWindow()->dockWindows( (Qt::Dock)place );
1180 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
1183 if ( myInfo.contains( it.current() ) )
1184 name = myInfo[it.current()].name;
1185 if ( name.isEmpty() )
1186 name = windowName( it.current() );
1187 if ( name.isEmpty() )
1194 void QtxDockAction::updateMenus()
1196 for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it )
1198 QPopupMenu* pm = it.key();
1199 MenuInfo& inf = it.data();
1201 int toolId = findId( pm, inf.tool );
1202 int dockId = findId( pm, inf.dock );
1204 int index = pm->indexOf( dockId );
1206 if ( isSeparate() && !inf.tool )
1207 inf.tool = new QPopupMenu( pm );
1209 pm->removeItem( dockId );
1210 pm->removeItem( toolId );
1212 if ( !isSeparate() && inf.tool )
1219 splitMenuText( dock, tool );
1222 iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) :
1223 pm->insertItem ( iconSet(), dock, inf.dock, -1, index );
1229 iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) :
1230 pm->insertItem ( iconSet(), tool, inf.tool, -1, index );