1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxDockAction.cxx
20 // Author: Sergey TELKOV
22 #include "QtxDockAction.h"
24 #include "QtxResourceMgr.h"
28 #include <qdockarea.h>
29 #include <qdockwindow.h>
30 #include <qmainwindow.h>
31 #include <qapplication.h>
34 Name: QtxDockAction [public]
35 Desc: Constructs an Dock action with given main window and name.
38 QtxDockAction::QtxDockAction( QMainWindow* mw, const char* name )
39 : QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw, name ),
49 Name: QtxDockAction [public]
50 Desc: This constructor creates an action with the following properties: the
51 description text, the menu text and. It is a child of given main window
52 and named specified name.
55 QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw, const char* name )
56 : QtxAction( text, menuText, 0, mw, name ),
66 Name: QtxDockAction [public]
67 Desc: This constructor creates an action with the following properties: the
68 description text, the menu text, the icon or iconset icon and keyboard
69 accelerator. It is a child of given main window and named specified name.
72 QtxDockAction::QtxDockAction( const QString& text, const QIconSet& icon, const QString& menuText, QMainWindow* mw, const char* name )
73 : QtxAction( text, icon, menuText, 0, mw, name ),
83 Name: ~QtxDockAction [public]
84 Desc: Removes all added popup items.
87 QtxDockAction::~QtxDockAction()
89 for ( MenuMap::ConstIterator mIt = myMenu.begin(); mIt != myMenu.end(); ++mIt )
90 removeFrom( mIt.key() );
92 for ( InfoMap::ConstIterator iIt = myInfo.begin(); iIt != myInfo.end(); ++iIt )
97 Name: mainWindow [public]
98 Desc: Returns the main window which contains managed dock windows.
101 QMainWindow* QtxDockAction::mainWindow() const
107 Name: isAutoAdd [public]
108 Desc: Returns the auto add property. If this property is setted then all newly
109 appeared dock windows will be automatically added.
112 bool QtxDockAction::isAutoAdd() const
118 Name: setAutoAdd [public]
119 Desc: Sets the auto add property. If this property is setted then all newly
120 appeared dock windows will be automatically added.
123 void QtxDockAction::setAutoAdd( const bool on )
129 Name: isAutoPlace [public]
130 Desc: Returns the auto place property. If this property is setted then all newly
131 added dock windows will be automatically placed according stored place information.
134 bool QtxDockAction::isAutoPlace() const
140 Name: setAutoPlace [public]
141 Desc: Sets the auto place property. If this property is setted then all newly
142 added dock windows will be automatically placed according stored place
146 void QtxDockAction::setAutoPlace( const bool on )
152 Name: isSeparate [public]
153 Desc: Returns the 'separate' property.
156 bool QtxDockAction::isSeparate() const
162 Name: setSeparate [public]
163 Desc: Sets the 'separate' property. If this property is 'true' then toolbars and
164 dock windows menu items will be placed in different popup menus otherwise
165 their will be placed in one common popup menu. This property will be
166 affected in next method 'addTo'.
169 void QtxDockAction::setSeparate( const bool on )
171 if ( mySeparate == on )
180 Desc: Add the dock windows sub menu item to the end of specified popup.
183 bool QtxDockAction::addTo( QWidget* wid )
185 return addTo( wid, -1 );
190 Desc: Add the dock windows sub menu item to specified popup at the given index.
193 bool QtxDockAction::addTo( QWidget* wid, const int idx )
195 if ( !wid || !wid->inherits( "QPopupMenu" ) )
198 QPopupMenu* pm = (QPopupMenu*)wid;
201 if ( myMenu.contains( pm ) )
205 mInfo.dock = new QPopupMenu( pm );
206 mInfo.tool = isSeparate() ? new QPopupMenu( pm ) : 0;
209 splitMenuText( dock, tool );
211 myMenu.insert( pm, mInfo );
216 iconSet().isNull() ? pm->insertItem ( dock, mInfo.dock, -1, index ) :
217 pm->insertItem ( iconSet(), dock, mInfo.dock, -1, index );
223 iconSet().isNull() ? pm->insertItem ( tool, mInfo.tool, -1, index ) :
224 pm->insertItem ( iconSet(), tool, mInfo.tool, -1, index );
226 connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
227 connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
233 Name: removeFrom [public]
234 Desc: Removes dock window sub menu from specified popup.
237 bool QtxDockAction::removeFrom( QWidget* wid )
239 QPopupMenu* pm = (QPopupMenu*)wid;
241 if ( myMenu.contains( pm ) )
243 pm->removeItem( findId( pm, myMenu[pm].dock ) );
244 pm->removeItem( findId( pm, myMenu[pm].tool ) );
246 delete myMenu[pm].dock;
247 delete myMenu[pm].tool;
250 disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
251 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
254 return QtxAction::removeFrom( wid );
257 void QtxDockAction::setMenuText( const QString& txt )
259 if ( menuText() == txt )
262 QtxAction::setMenuText( txt );
267 Name: addDockWindow [public]
268 Desc: Add dock window to internal data structures. Action will be include all added
269 dock windows in to menu and manage their place configuration.
272 bool QtxDockAction::addDockWindow( QDockWindow* dw )
274 if ( !dw || !mainWindow() )
277 if ( myInfo.contains( dw ) )
280 myInfo.insert( dw, DockInfo() );
282 DockInfo& inf = myInfo[dw];
283 inf.name = windowName( dw );
284 QAction* a = inf.a = new QAction( mainWindow(), 0, true );
286 autoLoadPlaceInfo( dw );
288 bool block = a->signalsBlocked();
289 a->blockSignals( true );
290 a->setOn( dw->isVisibleTo( mainWindow() ) );
291 a->blockSignals( block );
296 dw->installEventFilter( this );
298 connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
299 connect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
300 connect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
306 Name: removeDockWindow [public]
307 Desc: Remove dock window from internal data structures. Action will not manage this window.
310 bool QtxDockAction::removeDockWindow( QDockWindow* dw )
312 if ( !myInfo.contains( dw ) )
315 myGeom.remove( myInfo[dw].name );
320 dw->removeEventFilter( this );
322 disconnect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
323 disconnect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
329 Name: eventFilter [public]
330 Desc: Event filter process caption and icon changing of managed dock windows
331 and try to add newly appeared dock windows.
334 bool QtxDockAction::eventFilter( QObject* o, QEvent* e )
336 if ( o->inherits( "QDockWindow" ) && ( e->type() == QEvent::CaptionChange ||
337 e->type() == QEvent::IconChange ) )
338 updateInfo( (QDockWindow*)o );
340 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildRemoved )
342 QChildEvent* ce = (QChildEvent*)e;
343 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
344 savePlaceInfo( (QDockWindow*)ce->child() );
347 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildInserted )
349 QChildEvent* ce = (QChildEvent*)e;
350 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
351 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, ce->child() ) );
358 Name: restoreGeometry [public]
359 Desc: Retrieve the dock window geometry. If dock window specified as 0
360 then all windows geometry will be restored.
363 void QtxDockAction::restoreGeometry( QDockWindow* dw ) const
372 Name: storeGeometry [public]
373 Desc: Store the dock window geometry. If dock window specified as 0
374 then all windows geometry will be stored.
377 void QtxDockAction::storeGeometry( QDockWindow* dw )
379 QPtrList<QDockWindow> dwList;
384 dockWindows( dwList );
386 for ( QPtrListIterator<QDockWindow> it( dwList ); it.current(); ++it )
387 savePlaceInfo( it.current() );
391 Name: loadGeometry [public]
392 Desc: Retrieve the dock windows geometry information from the specified resource manager section.
395 void QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear )
397 QString sec = section.stripWhiteSpace();
398 if ( !resMgr || sec.isEmpty() )
401 myNames = QStringList::split( "|", resMgr->stringValue( sec, "windows_list", QString::null ) );
403 QMap<QString, int> map;
404 QStringList params = resMgr->parameters( sec );
405 for ( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
407 QString p = QStringList::split( ".", *it, true ).first().stripWhiteSpace();
412 for ( QMap<QString, int>::ConstIterator itr = map.begin(); itr != map.end(); ++itr )
415 if ( !clear && myGeom.contains( itr.key() ) )
416 inf = myGeom[itr.key()];
419 inf.vis = true; inf.newLine = false; inf.place = DockTop;
420 inf.index = 0; inf.offset = 0;
421 inf.x = 0; inf.y = 0; inf.w = 0; inf.h = 0;
422 inf.fixW = -1; inf.fixH = -1;
424 if ( loadGeometry( resMgr, sec, itr.key(), inf ) )
425 myGeom.insert( itr.key(), inf );
430 Name: saveGeometry [public]
431 Desc: Store the dock windows geometry information into the specified resource manager section.
434 void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const
436 QString sec = section.stripWhiteSpace();
437 if ( !resMgr || sec.isEmpty() )
440 QtxDockAction* that = (QtxDockAction*)this;
441 that->storeGeometry();
443 that->myNames.clear();
444 collectNames( Minimized, that->myNames );
445 for ( int i = DockTornOff; i < Minimized; i++ )
446 collectNames( i, that->myNames );
449 resMgr->remove( sec );
451 resMgr->setValue( sec, "windows_list", myNames.join( "|" ) );
453 for ( GeomMap::ConstIterator it = myGeom.begin(); it != myGeom.end(); ++it )
454 saveGeometry( resMgr, sec, it.key(), it.data() );
458 Name: onAboutToShow [private slots]
459 Desc: Prepare sub popup with dock windows list when parent popup is shown.
462 void QtxDockAction::onAboutToShow()
464 const QObject* obj = sender();
465 if ( obj && obj->inherits( "QPopupMenu" ) )
467 QPopupMenu* pm = (QPopupMenu*)obj;
469 pm->setItemEnabled( findId( pm, myMenu[pm].dock ), isEnabled() && myMenu[pm].dock && myMenu[pm].dock->count() );
470 pm->setItemEnabled( findId( pm, myMenu[pm].tool ), isEnabled() && myMenu[pm].tool && myMenu[pm].tool->count() );
475 Name: onToggled [private slots]
476 Desc: Show or hide dock window when user toggled window item in popup.
479 void QtxDockAction::onToggled( bool on )
481 QDockWindow* dw = dockWindow( (QAction*)sender() );
483 on ? dw->show() : dw->hide();
487 Name: onPopupDestroyed [private slots]
488 Desc: Remove destroyed popup from data structures.
491 void QtxDockAction::onPopupDestroyed( QObject* obj )
493 myMenu.remove( (QPopupMenu*)obj );
497 Name: onWindowDestroyed [private slots]
498 Desc: Remove information about destroyed dock window.
501 void QtxDockAction::onWindowDestroyed( QObject* obj )
503 QDockWindow* dw = (QDockWindow*)obj;
504 if ( !myInfo.contains( dw ) )
512 Name: onVisibilityChanged [private slots]
513 Desc: Toggle corresponded action when visibility state of dock window changed.
516 void QtxDockAction::onVisibilityChanged( bool on )
518 const QObject* obj = sender();
519 if ( !obj || !obj->inherits( "QDockWindow" ) )
522 QDockWindow* dw = (QDockWindow*)obj;
524 QAction* a = action( dw );
525 if ( a && a->isOn() != on )
527 bool block = a->signalsBlocked();
528 a->blockSignals( true );
530 a->blockSignals( block );
537 Name: onDockWindowPositionChanged [private slots]
538 Desc: Update dock window place information
541 void QtxDockAction::onDockWindowPositionChanged( QDockWindow* dw )
547 Name: event [protected]
548 Desc: Check consistency the popup content and internal datas.
549 Synchronize internal data structures with popup content.
552 bool QtxDockAction::event( QEvent* e )
554 if ( e->type() == (int)AutoAdd )
556 QCustomEvent* ce = (QCustomEvent*)e;
557 QDockWindow* dw = (QDockWindow*)ce->data();
558 if ( !myInfo.contains( dw ) )
560 autoAddDockWindow( dw );
561 autoLoadPlaceInfo( dw );
565 return QtxAction::event( e );
569 Name: checkPopup [private]
570 Desc: Check consistency the popup content and internal datas.
571 Synchronize internal data structures with popup content.
574 void QtxDockAction::checkPopup( QPopupMenu* pm )
576 if ( !myMenu.contains( pm ) )
579 int id = findId( pm, myMenu[pm].dock );
582 delete myMenu[pm].dock;
585 id = findId( pm, myMenu[pm].tool );
588 delete myMenu[pm].tool;
592 if ( !myMenu[pm].dock )
594 delete myMenu[pm].tool;
596 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
601 Name: fillPopup [private]
602 Desc: Clear the popup and the add to it required actions.
605 void QtxDockAction::fillPopup( QPopupMenu* pm ) const
607 if ( !pm || !mainWindow() )
610 if ( !myMenu.contains( pm ) )
613 QPopupMenu* dockMenu = myMenu[pm].dock;
614 QPopupMenu* toolMenu = myMenu[pm].tool;
616 for ( InfoMap::ConstIterator mit = myInfo.begin(); mit != myInfo.end(); ++mit )
618 mit.data().a->removeFrom( dockMenu );
619 mit.data().a->removeFrom( toolMenu );
628 QPtrList<QDockWindow> dockList;
629 dockWindows( dockList, mainWindow() );
631 if ( dockList.isEmpty() )
634 QPtrList<QAction> toolBars, windows;
635 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
637 if ( !myInfo.contains( it.current() ) )
639 QtxDockAction* that = (QtxDockAction*)this;
640 that->autoAddDockWindow( it.current() );
643 if ( !mainWindow()->appropriate( it.current() ) ||
644 it.current()->caption().isEmpty() || !action( it.current() ) )
647 if ( isToolBar( it.current() ) )
648 toolBars.append( action( it.current() ) );
650 windows.append( action( it.current() ) );
653 for ( QPtrListIterator<QAction> wit( windows ); wit.current(); ++wit )
654 wit.current()->addTo( dockMenu );
656 dockMenu->insertSeparator();
658 for ( QPtrListIterator<QAction> tit( toolBars ); tit.current(); ++tit )
659 tit.current()->addTo( toolMenu ? toolMenu : dockMenu );
661 Qtx::simplifySeparators( dockMenu );
662 Qtx::simplifySeparators( toolMenu );
666 Name: isToolBar [private]
667 Desc: Returns 'true' if dock window is a toolbar.
670 bool QtxDockAction::isToolBar( QDockWindow* dw ) const
672 return dw && dw->inherits( "QToolBar" );
676 Name: findId [private]
677 Desc: Returns identificator of popup item which contains sub popup 'pm' in the popup 'cont'.
680 int QtxDockAction::findId( QPopupMenu* cont, QPopupMenu* pm ) const
687 for ( int i = 0; i < (int)cont->count() && id == -1; i++ )
690 QMenuItem* item = cont->findItem( cont->idAt( i ), &md );
691 if ( item && md == cont && item->popup() == pm )
698 Name: dockWindows [private]
699 Desc: Returns all dock windows of the main window.
702 void QtxDockAction::dockWindows( QPtrList<QDockWindow>& lst, QMainWindow* main ) const
706 QMainWindow* mw = main ? main : mainWindow();
710 lst = mw->dockWindows();
714 Name: updateInfo [private]
715 Desc: Updates icon and caption info of dock window in the corresponded action.
718 void QtxDockAction::updateInfo( QDockWindow* dw )
720 QAction* a = action( dw );
724 a->setText( dw->caption() );
725 a->setMenuText( dw->caption() );
727 if ( isToolBar( dw ) )
728 a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) );
730 a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) );
732 const QPixmap* icon = dw->icon();
734 a->setIconSet( *icon );
738 Name: savePlaceInfo [private]
739 Desc: Store the place and geometry information from specified dock window.
742 void QtxDockAction::savePlaceInfo( QDockWindow* dw )
744 if ( !myInfo.contains( dw ) )
747 if ( !myGeom.contains( myInfo[dw].name ) )
748 myGeom.insert( myInfo[dw].name, GeomInfo() );
750 GeomInfo& inf = myGeom[myInfo[dw].name];
753 inf.vis = dw->isVisibleTo( mainWindow() );
754 mainWindow()->getLocation( dw, dock, inf.index, inf.newLine, inf.offset );
760 inf.h = dw->height();
761 inf.fixW = dw->fixedExtent().width();
762 inf.fixH = dw->fixedExtent().height();
766 Name: loadPlaceInfo [private]
767 Desc: Retrieve the stored place and geometry information to specified dock window.
770 void QtxDockAction::loadPlaceInfo( QDockWindow* dw ) const
772 if ( !myInfo.contains( dw ) )
775 QString winName = myInfo[dw].name;
776 if ( winName.isEmpty() || !myGeom.contains( winName ) )
779 GeomInfo inf = myGeom[myInfo[dw].name];
781 mainWindow()->moveDockWindow( dw, (Qt::Dock)inf.place, inf.newLine, inf.index, inf.offset );
782 dw->setGeometry( inf.x, inf.y, inf.w, inf.h );
784 dw->setFixedExtentWidth( inf.fixW );
785 dw->setFixedExtentHeight( inf.fixH );
787 QtxDockAction* that = (QtxDockAction*)this;
788 that->myGeom.insert( myInfo[dw].name, inf );
792 Name: loadPlaceInfo [private]
793 Desc: Retrieve the stored place and geometry information to all dock windows.
796 void QtxDockAction::loadPlaceInfo() const
798 QMainWindow* mw = mainWindow();
802 typedef QPtrList<QDockWindow> DockWinList;
805 dockWindows( lst, mw );
807 QMap<QString, QDockWindow*> nameMap;
808 for ( QPtrListIterator<QDockWindow> itr( lst ); itr.current(); ++itr )
811 if ( myInfo.contains( itr.current() ) )
812 name = myInfo[itr.current()].name;
814 if ( !myGeom.contains( name ) )
817 nameMap.insert( name, itr.current() );
821 for ( QStringList::const_iterator iter = myNames.begin(); iter != myNames.end(); ++iter )
823 if ( nameMap.contains( *iter ) )
824 winList.append( nameMap[*iter] );
825 nameMap.remove( *iter );
828 for ( QMap<QString, QDockWindow*>::ConstIterator mIt = nameMap.begin(); mIt != nameMap.end(); ++mIt )
829 winList.append( mIt.data() );
831 QMap<int, DockWinList> winMap;
832 QMap<QDockWindow*, GeomInfo*> geomMap;
834 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
837 if ( myInfo.contains( it.current() ) )
838 name = myInfo[it.current()].name;
840 if ( !myGeom.contains( name ) )
843 //! collect pointer of info to have fresh info data after processEvents();
844 GeomInfo* inf = (GeomInfo*)&( myGeom[name] );
845 geomMap.insert( it.current(), inf );
846 if ( !winMap.contains( inf->place ) )
847 winMap.insert( inf->place, DockWinList() );
848 winMap[inf->place].append( it.current() );
851 loadPlaceArea( DockMinimized, mw, 0,
852 winMap.contains( DockMinimized ) ? winMap[DockMinimized] : DockWinList(), geomMap );
853 for ( int i = DockTornOff; i < DockMinimized; i++ )
855 loadPlaceArea( i, mw, dockArea( i ), winMap.contains( i ) ? winMap[i] : DockWinList(), geomMap );
860 Name: loadPlaceArea [private]
861 Desc: Set the place and geometry information to all dock windows in the area.
864 void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area,
865 const QPtrList<QDockWindow>& dockList,
866 const QMap<QDockWindow*, GeomInfo*>& geomMap ) const
868 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
870 if ( !geomMap.contains( it.current() ) )
873 GeomInfo* inf = geomMap[it.current()];
874 mw->moveDockWindow( it.current(), (Qt::Dock)place, inf->newLine, inf->index, inf->offset );
880 qApp->processEvents();
882 for ( QPtrListIterator<QDockWindow> itr( dockList ); itr.current(); ++itr )
884 QDockWindow* dw = itr.current();
885 if ( !geomMap.contains( dw ) )
888 GeomInfo* inf = geomMap[dw];
889 if ( place != DockTornOff )
891 dw->setNewLine( inf->newLine );
892 dw->setOffset( inf->offset );
893 dw->setFixedExtentWidth( inf->fixW );
894 dw->setFixedExtentHeight( inf->fixH );
896 dw->setGeometry( inf->x, inf->y, inf->w, inf->h );
898 QAction* a = action( dw );
901 bool block = a->signalsBlocked();
902 a->blockSignals( true );
903 a->setOn( inf->vis );
904 a->blockSignals( block );
907 if ( mainWindow() && mainWindow()->appropriate( dw ) )
908 inf->vis ? dw->show() : dw->hide();
914 wid->layout()->invalidate();
915 wid->layout()->activate();
920 Name: action [private]
921 Desc: Returns action for the given dock window.
924 QAction* QtxDockAction::action( QDockWindow* dw ) const
927 if ( myInfo.contains( dw ) )
933 Name: dockWindow [private]
934 Desc: Returns dock window for the given action.
937 QDockWindow* QtxDockAction::dockWindow( const QAction* a ) const
940 for ( InfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !dw; ++it )
942 if ( it.data().a == a )
949 Name: initialize [private]
950 Desc: Initialisation of the object. Sets the event filters and add existing dock windows.
953 void QtxDockAction::initialize( QMainWindow* mw )
958 QPtrList<QDockWindow> lst;
959 dockWindows( lst, mw );
961 for ( QPtrListIterator<QDockWindow> it( lst ); it.current(); ++it )
962 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, it.current() ) );
965 mw->topDock()->installEventFilter( this );
966 if ( mw->leftDock() )
967 mw->leftDock()->installEventFilter( this );
968 if ( mw->rightDock() )
969 mw->rightDock()->installEventFilter( this );
970 if ( mw->bottomDock() )
971 mw->bottomDock()->installEventFilter( this );
973 connect( mw, SIGNAL( dockWindowPositionChanged( QDockWindow* ) ),
974 this, SLOT( onDockWindowPositionChanged( QDockWindow* ) ) );
978 Name: windowName [private]
979 Desc: Generate the dock window name.
982 QString QtxDockAction::windowName( QDockWindow* dw ) const
988 name = dw->name( "" );
989 if ( name.isEmpty() )
990 name = dw->caption();
997 Name: autoAddDockWindow [private]
998 Desc: Add the dock window if auto add property is setted.
1001 bool QtxDockAction::autoAddDockWindow( QDockWindow* dw )
1006 return addDockWindow( dw );
1010 Name: autoLoadPlaceInfo [private]
1011 Desc: Retieve the dock window place geometry if auto place property is setted.
1014 void QtxDockAction::autoLoadPlaceInfo( QDockWindow* dw )
1016 if ( isAutoPlace() )
1017 loadPlaceInfo( dw );
1021 Name: splitMenuText [private]
1025 void QtxDockAction::splitMenuText( QString& dock, QString& tool ) const
1027 dock = tool = menuText();
1028 if ( !isSeparate() )
1031 QStringList lst = splitText( menuText(), "|" );
1032 if ( lst.count() < 2 )
1033 lst = splitText( menuText(), "and" );
1040 Name: splitText [private]
1044 QStringList QtxDockAction::splitText( const QString& str, const QString& sep ) const
1048 int idx = str.lower().find( sep.lower() );
1051 res.append( str.mid( 0, idx ).stripWhiteSpace() );
1052 res.append( str.mid( idx + sep.length() ).stripWhiteSpace() );
1059 Name: dockPlace [private]
1063 int QtxDockAction::dockPlace( const QString& dockName ) const
1065 static QMap<QString, int> dockNameMap;
1066 if ( dockNameMap.isEmpty() )
1068 dockNameMap["top"] = DockTop;
1069 dockNameMap["bottom"] = DockBottom;
1070 dockNameMap["left"] = DockLeft;
1071 dockNameMap["right"] = DockRight;
1072 dockNameMap["tornoff"] = DockTornOff;
1073 dockNameMap["torn_off"] = DockTornOff;
1074 dockNameMap["outside"] = DockTornOff;
1075 dockNameMap["undock"] = DockTornOff;
1076 dockNameMap["minimized"] = DockMinimized;
1077 dockNameMap["unmanaged"] = DockUnmanaged;
1081 if ( dockNameMap.contains( dockName.lower() ) )
1082 res = dockNameMap[dockName.lower()];
1087 Name: dockArea [private]
1091 QDockArea* QtxDockAction::dockArea( const int place ) const
1093 if ( !mainWindow() )
1096 QDockArea* area = 0;
1100 area = mainWindow()->topDock();
1103 area = mainWindow()->bottomDock();
1106 area = mainWindow()->leftDock();
1109 area = mainWindow()->rightDock();
1116 Name: loadGeometry [private]
1120 bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec,
1121 const QString& name, GeomInfo& inf ) const
1123 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1126 QString tmpl = QString( "%1.%2" ).arg( name );
1128 inf.vis = resMgr->booleanValue( sec, tmpl.arg( "visible" ), inf.vis );
1129 inf.newLine = resMgr->booleanValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1131 inf.index = resMgr->integerValue( sec, tmpl.arg( "index" ), inf.index );
1132 inf.offset = resMgr->integerValue( sec, tmpl.arg( "offset" ), inf.offset );
1134 inf.x = resMgr->integerValue( sec, tmpl.arg( "x" ), inf.x );
1135 inf.y = resMgr->integerValue( sec, tmpl.arg( "y" ), inf.y );
1136 inf.w = resMgr->integerValue( sec, tmpl.arg( "width" ), inf.w );
1137 inf.h = resMgr->integerValue( sec, tmpl.arg( "height" ), inf.h );
1139 inf.fixW = resMgr->integerValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1140 inf.fixH = resMgr->integerValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1143 if ( !resMgr->value( sec, tmpl.arg( "place" ), place ) )
1146 if ( resMgr->value( sec, tmpl.arg( "place" ), placeStr ) )
1147 place = dockPlace( placeStr );
1150 if ( place >= DockUnmanaged && place <= DockMinimized )
1157 Name: saveGeometry [private]
1161 bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec,
1162 const QString& name, const GeomInfo& inf ) const
1164 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1167 QString tmpl = QString( "%1.%2" ).arg( name );
1169 resMgr->setValue( sec, tmpl.arg( "visible" ), inf.vis );
1170 resMgr->setValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1171 resMgr->setValue( sec, tmpl.arg( "index" ), inf.index );
1172 resMgr->setValue( sec, tmpl.arg( "offset" ), inf.offset );
1173 resMgr->setValue( sec, tmpl.arg( "x" ), inf.x );
1174 resMgr->setValue( sec, tmpl.arg( "y" ), inf.y );
1175 resMgr->setValue( sec, tmpl.arg( "width" ), inf.w );
1176 resMgr->setValue( sec, tmpl.arg( "height" ), inf.h );
1177 resMgr->setValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1178 resMgr->setValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1179 resMgr->setValue( sec, tmpl.arg( "place" ), inf.place );
1185 Name: collectNames [private]
1189 void QtxDockAction::collectNames( const int place, QStringList& lst ) const
1191 QPtrList<QDockWindow> winList;
1192 QDockArea* area = dockArea( place );
1194 winList = area->dockWindowList();
1196 winList = mainWindow()->dockWindows( (Qt::Dock)place );
1198 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
1201 if ( myInfo.contains( it.current() ) )
1202 name = myInfo[it.current()].name;
1203 if ( name.isEmpty() )
1204 name = windowName( it.current() );
1205 if ( name.isEmpty() )
1212 void QtxDockAction::updateMenus()
1214 for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it )
1216 QPopupMenu* pm = it.key();
1217 MenuInfo& inf = it.data();
1219 int toolId = findId( pm, inf.tool );
1220 int dockId = findId( pm, inf.dock );
1222 int index = pm->indexOf( dockId );
1224 if ( isSeparate() && !inf.tool )
1225 inf.tool = new QPopupMenu( pm );
1227 pm->removeItem( dockId );
1228 pm->removeItem( toolId );
1230 if ( !isSeparate() && inf.tool )
1237 splitMenuText( dock, tool );
1240 iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) :
1241 pm->insertItem ( iconSet(), dock, inf.dock, -1, index );
1247 iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) :
1248 pm->insertItem ( iconSet(), tool, inf.tool, -1, index );