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 inf->vis ? dw->show() : dw->hide();
886 wid->layout()->invalidate();
887 wid->layout()->activate();
892 Name: action [private]
893 Desc: Returns action for the given dock window.
896 QAction* QtxDockAction::action( QDockWindow* dw ) const
899 if ( myInfo.contains( dw ) )
905 Name: dockWindow [private]
906 Desc: Returns dock window for the given action.
909 QDockWindow* QtxDockAction::dockWindow( const QAction* a ) const
912 for ( InfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !dw; ++it )
914 if ( it.data().a == a )
921 Name: initialize [private]
922 Desc: Initialisation of the object. Sets the event filters and add existing dock windows.
925 void QtxDockAction::initialize( QMainWindow* mw )
930 QPtrList<QDockWindow> lst;
931 dockWindows( lst, mw );
933 for ( QPtrListIterator<QDockWindow> it( lst ); it.current(); ++it )
934 autoAddDockWindow( it.current() );
937 mw->topDock()->installEventFilter( this );
938 if ( mw->leftDock() )
939 mw->leftDock()->installEventFilter( this );
940 if ( mw->rightDock() )
941 mw->rightDock()->installEventFilter( this );
942 if ( mw->bottomDock() )
943 mw->bottomDock()->installEventFilter( this );
945 connect( mw, SIGNAL( dockWindowPositionChanged( QDockWindow* ) ),
946 this, SLOT( onDockWindowPositionChanged( QDockWindow* ) ) );
950 Name: windowName [private]
951 Desc: Generate the dock window name.
954 QString QtxDockAction::windowName( QDockWindow* dw ) const
960 name = dw->name( "" );
961 if ( name.isEmpty() )
962 name = dw->caption();
969 Name: autoAddDockWindow [private]
970 Desc: Add the dock window if auto add property is setted.
973 bool QtxDockAction::autoAddDockWindow( QDockWindow* dw )
978 return addDockWindow( dw );
982 Name: autoLoadPlaceInfo [private]
983 Desc: Retieve the dock window place geometry if auto place property is setted.
986 void QtxDockAction::autoLoadPlaceInfo( QDockWindow* dw )
993 Name: splitMenuText [private]
997 void QtxDockAction::splitMenuText( QString& dock, QString& tool ) const
999 dock = tool = menuText();
1000 if ( !isSeparate() )
1003 QStringList lst = splitText( menuText(), "|" );
1004 if ( lst.count() < 2 )
1005 lst = splitText( menuText(), "and" );
1012 Name: splitText [private]
1016 QStringList QtxDockAction::splitText( const QString& str, const QString& sep ) const
1020 int idx = str.lower().find( sep.lower() );
1023 res.append( str.mid( 0, idx ).stripWhiteSpace() );
1024 res.append( str.mid( idx + sep.length() ).stripWhiteSpace() );
1031 Name: dockPlace [private]
1035 int QtxDockAction::dockPlace( const QString& dockName ) const
1037 static QMap<QString, int> dockNameMap;
1038 if ( dockNameMap.isEmpty() )
1040 dockNameMap["top"] = DockTop;
1041 dockNameMap["bottom"] = DockBottom;
1042 dockNameMap["left"] = DockLeft;
1043 dockNameMap["right"] = DockRight;
1044 dockNameMap["tornoff"] = DockTornOff;
1045 dockNameMap["torn_off"] = DockTornOff;
1046 dockNameMap["outside"] = DockTornOff;
1047 dockNameMap["undock"] = DockTornOff;
1048 dockNameMap["minimized"] = DockMinimized;
1049 dockNameMap["unmanaged"] = DockUnmanaged;
1053 if ( dockNameMap.contains( dockName.lower() ) )
1054 res = dockNameMap[dockName.lower()];
1059 Name: dockArea [private]
1063 QDockArea* QtxDockAction::dockArea( const int place ) const
1065 if ( !mainWindow() )
1068 QDockArea* area = 0;
1072 area = mainWindow()->topDock();
1075 area = mainWindow()->bottomDock();
1078 area = mainWindow()->leftDock();
1081 area = mainWindow()->rightDock();
1088 Name: loadGeometry [private]
1092 bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec,
1093 const QString& name, GeomInfo& inf ) const
1095 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1098 QString tmpl = QString( "%1.%2" ).arg( name );
1100 inf.vis = resMgr->booleanValue( sec, tmpl.arg( "visible" ), inf.vis );
1101 inf.newLine = resMgr->booleanValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1103 inf.index = resMgr->integerValue( sec, tmpl.arg( "index" ), inf.index );
1104 inf.offset = resMgr->integerValue( sec, tmpl.arg( "offset" ), inf.offset );
1106 inf.x = resMgr->integerValue( sec, tmpl.arg( "x" ), inf.x );
1107 inf.y = resMgr->integerValue( sec, tmpl.arg( "y" ), inf.y );
1108 inf.w = resMgr->integerValue( sec, tmpl.arg( "width" ), inf.w );
1109 inf.h = resMgr->integerValue( sec, tmpl.arg( "height" ), inf.h );
1111 inf.fixW = resMgr->integerValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1112 inf.fixH = resMgr->integerValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1115 if ( !resMgr->value( sec, tmpl.arg( "place" ), place ) )
1118 if ( resMgr->value( sec, tmpl.arg( "place" ), placeStr ) )
1119 place = dockPlace( placeStr );
1122 if ( place >= DockUnmanaged && place <= DockMinimized )
1129 Name: saveGeometry [private]
1133 bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec,
1134 const QString& name, const GeomInfo& inf ) const
1136 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1139 QString tmpl = QString( "%1.%2" ).arg( name );
1141 resMgr->setValue( sec, tmpl.arg( "visible" ), inf.vis );
1142 resMgr->setValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1143 resMgr->setValue( sec, tmpl.arg( "index" ), inf.index );
1144 resMgr->setValue( sec, tmpl.arg( "offset" ), inf.offset );
1145 resMgr->setValue( sec, tmpl.arg( "x" ), inf.x );
1146 resMgr->setValue( sec, tmpl.arg( "y" ), inf.y );
1147 resMgr->setValue( sec, tmpl.arg( "width" ), inf.w );
1148 resMgr->setValue( sec, tmpl.arg( "height" ), inf.h );
1149 resMgr->setValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1150 resMgr->setValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1151 resMgr->setValue( sec, tmpl.arg( "place" ), inf.place );
1157 Name: collectNames [private]
1161 void QtxDockAction::collectNames( const int place, QStringList& lst ) const
1163 QPtrList<QDockWindow> winList;
1164 QDockArea* area = dockArea( place );
1166 winList = area->dockWindowList();
1168 winList = mainWindow()->dockWindows( (Qt::Dock)place );
1170 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
1173 if ( myInfo.contains( it.current() ) )
1174 name = myInfo[it.current()].name;
1175 if ( name.isEmpty() )
1176 name = windowName( it.current() );
1177 if ( name.isEmpty() )
1184 void QtxDockAction::updateMenus()
1186 for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it )
1188 QPopupMenu* pm = it.key();
1189 MenuInfo& inf = it.data();
1191 int toolId = findId( pm, inf.tool );
1192 int dockId = findId( pm, inf.dock );
1194 int index = pm->indexOf( dockId );
1196 if ( isSeparate() && !inf.tool )
1197 inf.tool = new QPopupMenu( pm );
1199 pm->removeItem( dockId );
1200 pm->removeItem( toolId );
1202 if ( !isSeparate() && inf.tool )
1209 splitMenuText( dock, tool );
1212 iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) :
1213 pm->insertItem ( iconSet(), dock, inf.dock, -1, index );
1219 iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) :
1220 pm->insertItem ( iconSet(), tool, inf.tool, -1, index );