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 <qobjectlist.h>
32 #include <qapplication.h>
35 Name: QtxDockAction [public]
36 Desc: Constructs an Dock action with given main window and name.
39 QtxDockAction::QtxDockAction( QMainWindow* mw, const char* name )
40 : QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw, name ),
50 Name: QtxDockAction [public]
51 Desc: This constructor creates an action with the following properties: the
52 description text, the menu text and. It is a child of given main window
53 and named specified name.
56 QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw, const char* name )
57 : QtxAction( text, menuText, 0, mw, name ),
67 Name: QtxDockAction [public]
68 Desc: This constructor creates an action with the following properties: the
69 description text, the menu text, the icon or iconset icon and keyboard
70 accelerator. It is a child of given main window and named specified name.
73 QtxDockAction::QtxDockAction( const QString& text, const QIconSet& icon, const QString& menuText, QMainWindow* mw, const char* name )
74 : QtxAction( text, icon, menuText, 0, mw, name ),
84 Name: ~QtxDockAction [public]
85 Desc: Removes all added popup items.
88 QtxDockAction::~QtxDockAction()
90 for ( MenuMap::ConstIterator mIt = myMenu.begin(); mIt != myMenu.end(); ++mIt )
91 removeFrom( mIt.key() );
93 for ( InfoMap::ConstIterator iIt = myInfo.begin(); iIt != myInfo.end(); ++iIt )
98 Name: mainWindow [public]
99 Desc: Returns the main window which contains managed dock windows.
102 QMainWindow* QtxDockAction::mainWindow() const
108 Name: isAutoAdd [public]
109 Desc: Returns the auto add property. If this property is setted then all newly
110 appeared dock windows will be automatically added.
113 bool QtxDockAction::isAutoAdd() const
119 Name: setAutoAdd [public]
120 Desc: Sets the auto add property. If this property is setted then all newly
121 appeared dock windows will be automatically added.
124 void QtxDockAction::setAutoAdd( const bool on )
130 Name: isAutoPlace [public]
131 Desc: Returns the auto place property. If this property is setted then all newly
132 added dock windows will be automatically placed according stored place information.
135 bool QtxDockAction::isAutoPlace() const
141 Name: setAutoPlace [public]
142 Desc: Sets the auto place property. If this property is setted then all newly
143 added dock windows will be automatically placed according stored place
147 void QtxDockAction::setAutoPlace( const bool on )
153 Name: isSeparate [public]
154 Desc: Returns the 'separate' property.
157 bool QtxDockAction::isSeparate() const
163 Name: setSeparate [public]
164 Desc: Sets the 'separate' property. If this property is 'true' then toolbars and
165 dock windows menu items will be placed in different popup menus otherwise
166 their will be placed in one common popup menu. This property will be
167 affected in next method 'addTo'.
170 void QtxDockAction::setSeparate( const bool on )
172 if ( mySeparate == on )
181 Desc: Add the dock windows sub menu item to the end of specified popup.
184 bool QtxDockAction::addTo( QWidget* wid )
186 return addTo( wid, -1 );
191 Desc: Add the dock windows sub menu item to specified popup at the given index.
194 bool QtxDockAction::addTo( QWidget* wid, const int idx )
196 if ( !wid || !wid->inherits( "QPopupMenu" ) )
199 QPopupMenu* pm = (QPopupMenu*)wid;
202 if ( myMenu.contains( pm ) )
206 mInfo.dock = new QPopupMenu( pm );
207 mInfo.tool = isSeparate() ? new QPopupMenu( pm ) : 0;
210 splitMenuText( dock, tool );
212 myMenu.insert( pm, mInfo );
217 iconSet().isNull() ? pm->insertItem ( dock, mInfo.dock, -1, index ) :
218 pm->insertItem ( iconSet(), dock, mInfo.dock, -1, index );
224 iconSet().isNull() ? pm->insertItem ( tool, mInfo.tool, -1, index ) :
225 pm->insertItem ( iconSet(), tool, mInfo.tool, -1, index );
227 connect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
228 connect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
234 Name: removeFrom [public]
235 Desc: Removes dock window sub menu from specified popup.
238 bool QtxDockAction::removeFrom( QWidget* wid )
240 QPopupMenu* pm = (QPopupMenu*)wid;
242 if ( myMenu.contains( pm ) )
244 pm->removeItem( findId( pm, myMenu[pm].dock ) );
245 pm->removeItem( findId( pm, myMenu[pm].tool ) );
247 delete myMenu[pm].dock;
248 delete myMenu[pm].tool;
251 disconnect( pm, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
252 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onPopupDestroyed( QObject* ) ) );
255 return QtxAction::removeFrom( wid );
258 void QtxDockAction::setMenuText( const QString& txt )
260 if ( menuText() == txt )
263 QtxAction::setMenuText( txt );
268 Name: addDockWindow [public]
269 Desc: Add dock window to internal data structures. Action will be include all added
270 dock windows in to menu and manage their place configuration.
273 bool QtxDockAction::addDockWindow( QDockWindow* dw )
275 if ( !dw || !mainWindow() )
278 if ( myInfo.contains( dw ) )
281 myInfo.insert( dw, DockInfo() );
283 DockInfo& inf = myInfo[dw];
284 inf.name = windowName( dw );
285 QAction* a = inf.a = new QAction( mainWindow(), 0, true );
287 autoLoadPlaceInfo( dw );
289 bool block = a->signalsBlocked();
290 a->blockSignals( true );
291 a->setOn( dw->isVisibleTo( mainWindow() ) );
292 a->blockSignals( block );
297 dw->installEventFilter( this );
299 connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
300 connect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
301 connect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
307 Name: removeDockWindow [public]
308 Desc: Remove dock window from internal data structures. Action will not manage this window.
311 bool QtxDockAction::removeDockWindow( QDockWindow* dw )
313 if ( !myInfo.contains( dw ) )
316 myGeom.remove( myInfo[dw].name );
321 dw->removeEventFilter( this );
323 disconnect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
324 disconnect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
330 Name: eventFilter [public]
331 Desc: Event filter process caption and icon changing of managed dock windows
332 and try to add newly appeared dock windows.
335 bool QtxDockAction::eventFilter( QObject* o, QEvent* e )
337 if ( o->inherits( "QDockWindow" ) && ( e->type() == QEvent::CaptionChange ||
338 e->type() == QEvent::IconChange ) )
339 updateInfo( (QDockWindow*)o );
341 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildRemoved )
343 QChildEvent* ce = (QChildEvent*)e;
344 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
345 savePlaceInfo( (QDockWindow*)ce->child() );
348 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildInserted )
350 QChildEvent* ce = (QChildEvent*)e;
351 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
352 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, ce->child() ) );
359 Name: restoreGeometry [public]
360 Desc: Retrieve the dock window geometry. If dock window specified as 0
361 then all windows geometry will be restored.
364 void QtxDockAction::restoreGeometry( QDockWindow* dw ) const
373 Name: storeGeometry [public]
374 Desc: Store the dock window geometry. If dock window specified as 0
375 then all windows geometry will be stored.
378 void QtxDockAction::storeGeometry( QDockWindow* dw )
380 QPtrList<QDockWindow> dwList;
385 dockWindows( dwList );
387 for ( QPtrListIterator<QDockWindow> it( dwList ); it.current(); ++it )
388 savePlaceInfo( it.current() );
392 Name: loadGeometry [public]
393 Desc: Retrieve the dock windows geometry information from the specified resource manager section.
396 void QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear )
398 QString sec = section.stripWhiteSpace();
399 if ( !resMgr || sec.isEmpty() )
402 myNames = QStringList::split( "|", resMgr->stringValue( sec, "windows_list", QString::null ) );
404 QMap<QString, int> map;
405 QStringList params = resMgr->parameters( sec );
406 for ( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
408 QString p = QStringList::split( ".", *it, true ).first().stripWhiteSpace();
413 for ( QMap<QString, int>::ConstIterator itr = map.begin(); itr != map.end(); ++itr )
416 if ( !clear && myGeom.contains( itr.key() ) )
417 inf = myGeom[itr.key()];
420 inf.vis = true; inf.newLine = false; inf.place = DockTop;
421 inf.index = 0; inf.offset = 0;
422 inf.x = 0; inf.y = 0; inf.w = 0; inf.h = 0;
423 inf.fixW = -1; inf.fixH = -1;
425 if ( loadGeometry( resMgr, sec, itr.key(), inf ) )
426 myGeom.insert( itr.key(), inf );
431 Name: saveGeometry [public]
432 Desc: Store the dock windows geometry information into the specified resource manager section.
435 void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const
437 QString sec = section.stripWhiteSpace();
438 if ( !resMgr || sec.isEmpty() )
441 QtxDockAction* that = (QtxDockAction*)this;
442 that->storeGeometry();
444 that->myNames.clear();
445 collectNames( Minimized, that->myNames );
446 for ( int i = DockTornOff; i < Minimized; i++ )
447 collectNames( i, that->myNames );
450 resMgr->remove( sec );
452 resMgr->setValue( sec, "windows_list", myNames.join( "|" ) );
454 for ( GeomMap::ConstIterator it = myGeom.begin(); it != myGeom.end(); ++it )
455 saveGeometry( resMgr, sec, it.key(), it.data() );
459 Name: onAboutToShow [private slots]
460 Desc: Prepare sub popup with dock windows list when parent popup is shown.
463 void QtxDockAction::onAboutToShow()
465 const QObject* obj = sender();
466 if ( obj && obj->inherits( "QPopupMenu" ) )
468 QPopupMenu* pm = (QPopupMenu*)obj;
470 pm->setItemEnabled( findId( pm, myMenu[pm].dock ), isEnabled() && myMenu[pm].dock && myMenu[pm].dock->count() );
471 pm->setItemEnabled( findId( pm, myMenu[pm].tool ), isEnabled() && myMenu[pm].tool && myMenu[pm].tool->count() );
476 Name: onToggled [private slots]
477 Desc: Show or hide dock window when user toggled window item in popup.
480 void QtxDockAction::onToggled( bool on )
482 QDockWindow* dw = dockWindow( (QAction*)sender() );
484 on ? dw->show() : dw->hide();
488 Name: onPopupDestroyed [private slots]
489 Desc: Remove destroyed popup from data structures.
492 void QtxDockAction::onPopupDestroyed( QObject* obj )
494 myMenu.remove( (QPopupMenu*)obj );
498 Name: onWindowDestroyed [private slots]
499 Desc: Remove information about destroyed dock window.
502 void QtxDockAction::onWindowDestroyed( QObject* obj )
504 QDockWindow* dw = (QDockWindow*)obj;
505 if ( !myInfo.contains( dw ) )
513 Name: onVisibilityChanged [private slots]
514 Desc: Toggle corresponded action when visibility state of dock window changed.
517 void QtxDockAction::onVisibilityChanged( bool on )
519 const QObject* obj = sender();
520 if ( !obj || !obj->inherits( "QDockWindow" ) )
523 QDockWindow* dw = (QDockWindow*)obj;
525 QAction* a = action( dw );
526 if ( a && a->isOn() != on )
528 bool block = a->signalsBlocked();
529 a->blockSignals( true );
531 a->blockSignals( block );
538 Name: onDockWindowPositionChanged [private slots]
539 Desc: Update dock window place information
542 void QtxDockAction::onDockWindowPositionChanged( QDockWindow* dw )
548 Name: event [protected]
549 Desc: Check consistency the popup content and internal datas.
550 Synchronize internal data structures with popup content.
553 bool QtxDockAction::event( QEvent* e )
555 if ( e->type() == (int)AutoAdd )
557 QCustomEvent* ce = (QCustomEvent*)e;
558 QDockWindow* dw = (QDockWindow*)ce->data();
559 if ( !myInfo.contains( dw ) )
561 autoAddDockWindow( dw );
562 autoLoadPlaceInfo( dw );
566 return QtxAction::event( e );
570 Name: checkPopup [private]
571 Desc: Check consistency the popup content and internal datas.
572 Synchronize internal data structures with popup content.
575 void QtxDockAction::checkPopup( QPopupMenu* pm )
577 if ( !myMenu.contains( pm ) )
580 int id = findId( pm, myMenu[pm].dock );
583 delete myMenu[pm].dock;
586 id = findId( pm, myMenu[pm].tool );
589 delete myMenu[pm].tool;
593 if ( !myMenu[pm].dock )
595 delete myMenu[pm].tool;
597 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
602 Name: fillPopup [private]
603 Desc: Clear the popup and the add to it required actions.
606 void QtxDockAction::fillPopup( QPopupMenu* pm ) const
608 if ( !pm || !mainWindow() )
611 if ( !myMenu.contains( pm ) )
614 QPopupMenu* dockMenu = myMenu[pm].dock;
615 QPopupMenu* toolMenu = myMenu[pm].tool;
617 for ( InfoMap::ConstIterator mit = myInfo.begin(); mit != myInfo.end(); ++mit )
619 mit.data().a->removeFrom( dockMenu );
620 mit.data().a->removeFrom( toolMenu );
629 QPtrList<QDockWindow> dockList;
630 dockWindows( dockList, mainWindow() );
632 if ( dockList.isEmpty() )
635 QPtrList<QAction> toolBars, windows;
636 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
638 if ( !myInfo.contains( it.current() ) )
640 QtxDockAction* that = (QtxDockAction*)this;
641 that->autoAddDockWindow( it.current() );
644 if ( !mainWindow()->appropriate( it.current() ) ||
645 it.current()->caption().isEmpty() || !action( it.current() ) )
648 if ( isToolBar( it.current() ) )
649 toolBars.append( action( it.current() ) );
651 windows.append( action( it.current() ) );
654 for ( QPtrListIterator<QAction> wit( windows ); wit.current(); ++wit )
655 wit.current()->addTo( dockMenu );
657 dockMenu->insertSeparator();
659 for ( QPtrListIterator<QAction> tit( toolBars ); tit.current(); ++tit )
660 tit.current()->addTo( toolMenu ? toolMenu : dockMenu );
662 Qtx::simplifySeparators( dockMenu );
663 Qtx::simplifySeparators( toolMenu );
667 Name: isToolBar [private]
668 Desc: Returns 'true' if dock window is a toolbar.
671 bool QtxDockAction::isToolBar( QDockWindow* dw ) const
673 return dw && dw->inherits( "QToolBar" );
677 Name: findId [private]
678 Desc: Returns identificator of popup item which contains sub popup 'pm' in the popup 'cont'.
681 int QtxDockAction::findId( QPopupMenu* cont, QPopupMenu* pm ) const
688 for ( int i = 0; i < (int)cont->count() && id == -1; i++ )
691 QMenuItem* item = cont->findItem( cont->idAt( i ), &md );
692 if ( item && md == cont && item->popup() == pm )
699 Name: dockWindows [private]
700 Desc: Returns all dock windows of the main window.
703 void QtxDockAction::dockWindows( QPtrList<QDockWindow>& lst, QMainWindow* main ) const
707 QMainWindow* mw = main ? main : mainWindow();
711 QObjectList* objs = mw->queryList( "QDockWindow" );
714 for ( QObjectListIt it( *objs ); it.current(); ++it )
716 QDockWindow* dockWin = ::qt_cast<QDockWindow*>( it.current() );
717 if ( dockWin && dockMainWindow( mw, dockWin ) )
718 lst.append( dockWin );
724 bool QtxDockAction::dockMainWindow( QMainWindow* mw, QObject* win ) const
731 if ( win->parent() && win->parent() == mw )
734 if ( ::qt_cast<QMainWindow*>( win->parent() ) )
744 Name: updateInfo [private]
745 Desc: Updates icon and caption info of dock window in the corresponded action.
748 void QtxDockAction::updateInfo( QDockWindow* dw )
750 QAction* a = action( dw );
754 a->setText( dw->caption() );
755 a->setMenuText( dw->caption() );
757 if ( isToolBar( dw ) )
758 a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) );
760 a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) );
762 const QPixmap* icon = dw->icon();
764 a->setIconSet( *icon );
768 Name: savePlaceInfo [private]
769 Desc: Store the place and geometry information from specified dock window.
772 void QtxDockAction::savePlaceInfo( QDockWindow* dw )
774 if ( !myInfo.contains( dw ) )
777 if ( !myGeom.contains( myInfo[dw].name ) )
778 myGeom.insert( myInfo[dw].name, GeomInfo() );
780 GeomInfo& inf = myGeom[myInfo[dw].name];
783 inf.vis = dw->isVisibleTo( mainWindow() );
784 mainWindow()->getLocation( dw, dock, inf.index, inf.newLine, inf.offset );
790 inf.h = dw->height();
791 inf.fixW = dw->fixedExtent().width();
792 inf.fixH = dw->fixedExtent().height();
796 Name: loadPlaceInfo [private]
797 Desc: Retrieve the stored place and geometry information to specified dock window.
800 void QtxDockAction::loadPlaceInfo( QDockWindow* dw ) const
802 if ( !myInfo.contains( dw ) )
805 QMainWindow* mw = mainWindow();
809 QObject* p = dw->parent();
810 if ( !( !p || p == mw || ( p->parent() && p->parent() == mw ) ) )
813 QString winName = myInfo[dw].name;
814 if ( winName.isEmpty() || !myGeom.contains( winName ) )
817 GeomInfo inf = myGeom[myInfo[dw].name];
819 mainWindow()->moveDockWindow( dw, (Qt::Dock)inf.place, inf.newLine, inf.index, inf.offset );
820 dw->setGeometry( inf.x, inf.y, inf.w, inf.h );
822 dw->setFixedExtentWidth( inf.fixW );
823 dw->setFixedExtentHeight( inf.fixH );
825 QtxDockAction* that = (QtxDockAction*)this;
826 that->myGeom.insert( myInfo[dw].name, inf );
830 Name: loadPlaceInfo [private]
831 Desc: Retrieve the stored place and geometry information to all dock windows.
834 void QtxDockAction::loadPlaceInfo() const
836 QMainWindow* mw = mainWindow();
840 typedef QPtrList<QDockWindow> DockWinList;
843 dockWindows( lst, mw );
845 QMap<QString, QDockWindow*> nameMap;
846 for ( QPtrListIterator<QDockWindow> itr( lst ); itr.current(); ++itr )
848 QObject* p = itr.current()->parent();
849 if ( !( !p || p == mw || ( p->parent() && p->parent() == mw ) ) )
853 if ( myInfo.contains( itr.current() ) )
854 name = myInfo[itr.current()].name;
856 if ( !myGeom.contains( name ) )
859 nameMap.insert( name, itr.current() );
863 for ( QStringList::const_iterator iter = myNames.begin(); iter != myNames.end(); ++iter )
865 if ( nameMap.contains( *iter ) )
866 winList.append( nameMap[*iter] );
867 nameMap.remove( *iter );
870 for ( QMap<QString, QDockWindow*>::ConstIterator mIt = nameMap.begin(); mIt != nameMap.end(); ++mIt )
871 winList.append( mIt.data() );
873 QMap<int, DockWinList> winMap;
874 QMap<QDockWindow*, GeomInfo*> geomMap;
876 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
879 if ( myInfo.contains( it.current() ) )
880 name = myInfo[it.current()].name;
882 if ( !myGeom.contains( name ) )
885 //! collect pointer of info to have fresh info data after processEvents();
886 GeomInfo* inf = (GeomInfo*)&( myGeom[name] );
887 geomMap.insert( it.current(), inf );
888 if ( !winMap.contains( inf->place ) )
889 winMap.insert( inf->place, DockWinList() );
890 winMap[inf->place].append( it.current() );
893 loadPlaceArea( DockMinimized, mw, 0,
894 winMap.contains( DockMinimized ) ? winMap[DockMinimized] : DockWinList(), geomMap );
895 for ( int i = DockTornOff; i < DockMinimized; i++ )
897 loadPlaceArea( i, mw, dockArea( i ), winMap.contains( i ) ? winMap[i] : DockWinList(), geomMap );
902 Name: loadPlaceArea [private]
903 Desc: Set the place and geometry information to all dock windows in the area.
906 void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area,
907 const QPtrList<QDockWindow>& dockList,
908 const QMap<QDockWindow*, GeomInfo*>& geomMap ) const
910 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
912 if ( !geomMap.contains( it.current() ) )
915 GeomInfo* inf = geomMap[it.current()];
916 mw->moveDockWindow( it.current(), (Qt::Dock)place, inf->newLine, inf->index, inf->offset );
922 qApp->processEvents();
924 for ( QPtrListIterator<QDockWindow> itr( dockList ); itr.current(); ++itr )
926 QDockWindow* dw = itr.current();
927 if ( !geomMap.contains( dw ) )
930 GeomInfo* inf = geomMap[dw];
931 if ( place != DockTornOff )
933 dw->setNewLine( inf->newLine );
934 dw->setOffset( inf->offset );
935 dw->setFixedExtentWidth( inf->fixW );
936 dw->setFixedExtentHeight( inf->fixH );
938 dw->setGeometry( inf->x, inf->y, inf->w, inf->h );
940 QAction* a = action( dw );
943 bool block = a->signalsBlocked();
944 a->blockSignals( true );
945 a->setOn( inf->vis );
946 a->blockSignals( block );
949 if ( mainWindow() && mainWindow()->appropriate( dw ) )
950 inf->vis ? dw->show() : dw->hide();
956 wid->layout()->invalidate();
957 wid->layout()->activate();
962 Name: action [private]
963 Desc: Returns action for the given dock window.
966 QAction* QtxDockAction::action( QDockWindow* dw ) const
969 if ( myInfo.contains( dw ) )
975 Name: dockWindow [private]
976 Desc: Returns dock window for the given action.
979 QDockWindow* QtxDockAction::dockWindow( const QAction* a ) const
982 for ( InfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !dw; ++it )
984 if ( it.data().a == a )
991 Name: initialize [private]
992 Desc: Initialisation of the object. Sets the event filters and add existing dock windows.
995 void QtxDockAction::initialize( QMainWindow* mw )
1000 QPtrList<QDockWindow> lst;
1001 dockWindows( lst, mw );
1003 for ( QPtrListIterator<QDockWindow> it( lst ); it.current(); ++it )
1004 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, it.current() ) );
1006 if ( mw->topDock() )
1007 mw->topDock()->installEventFilter( this );
1008 if ( mw->leftDock() )
1009 mw->leftDock()->installEventFilter( this );
1010 if ( mw->rightDock() )
1011 mw->rightDock()->installEventFilter( this );
1012 if ( mw->bottomDock() )
1013 mw->bottomDock()->installEventFilter( this );
1015 connect( mw, SIGNAL( dockWindowPositionChanged( QDockWindow* ) ),
1016 this, SLOT( onDockWindowPositionChanged( QDockWindow* ) ) );
1020 Name: windowName [private]
1021 Desc: Generate the dock window name.
1024 QString QtxDockAction::windowName( QDockWindow* dw ) const
1030 name = dw->name( "" );
1031 if ( name.isEmpty() )
1032 name = dw->caption();
1039 Name: autoAddDockWindow [private]
1040 Desc: Add the dock window if auto add property is setted.
1043 bool QtxDockAction::autoAddDockWindow( QDockWindow* dw )
1048 return addDockWindow( dw );
1052 Name: autoLoadPlaceInfo [private]
1053 Desc: Retieve the dock window place geometry if auto place property is setted.
1056 void QtxDockAction::autoLoadPlaceInfo( QDockWindow* dw )
1058 if ( isAutoPlace() )
1059 loadPlaceInfo( dw );
1063 Name: splitMenuText [private]
1067 void QtxDockAction::splitMenuText( QString& dock, QString& tool ) const
1069 dock = tool = menuText();
1070 if ( !isSeparate() )
1073 QStringList lst = splitText( menuText(), "|" );
1074 if ( lst.count() < 2 )
1075 lst = splitText( menuText(), "and" );
1082 Name: splitText [private]
1086 QStringList QtxDockAction::splitText( const QString& str, const QString& sep ) const
1090 int idx = str.lower().find( sep.lower() );
1093 res.append( str.mid( 0, idx ).stripWhiteSpace() );
1094 res.append( str.mid( idx + sep.length() ).stripWhiteSpace() );
1101 Name: dockPlace [private]
1105 int QtxDockAction::dockPlace( const QString& dockName ) const
1107 static QMap<QString, int> dockNameMap;
1108 if ( dockNameMap.isEmpty() )
1110 dockNameMap["top"] = DockTop;
1111 dockNameMap["bottom"] = DockBottom;
1112 dockNameMap["left"] = DockLeft;
1113 dockNameMap["right"] = DockRight;
1114 dockNameMap["tornoff"] = DockTornOff;
1115 dockNameMap["torn_off"] = DockTornOff;
1116 dockNameMap["outside"] = DockTornOff;
1117 dockNameMap["undock"] = DockTornOff;
1118 dockNameMap["minimized"] = DockMinimized;
1119 dockNameMap["unmanaged"] = DockUnmanaged;
1123 if ( dockNameMap.contains( dockName.lower() ) )
1124 res = dockNameMap[dockName.lower()];
1129 Name: dockArea [private]
1133 QDockArea* QtxDockAction::dockArea( const int place ) const
1135 if ( !mainWindow() )
1138 QDockArea* area = 0;
1142 area = mainWindow()->topDock();
1145 area = mainWindow()->bottomDock();
1148 area = mainWindow()->leftDock();
1151 area = mainWindow()->rightDock();
1158 Name: loadGeometry [private]
1162 bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec,
1163 const QString& name, GeomInfo& inf ) const
1165 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1168 QString tmpl = QString( "%1.%2" ).arg( name );
1170 inf.vis = resMgr->booleanValue( sec, tmpl.arg( "visible" ), inf.vis );
1171 inf.newLine = resMgr->booleanValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1173 inf.index = resMgr->integerValue( sec, tmpl.arg( "index" ), inf.index );
1174 inf.offset = resMgr->integerValue( sec, tmpl.arg( "offset" ), inf.offset );
1176 inf.x = resMgr->integerValue( sec, tmpl.arg( "x" ), inf.x );
1177 inf.y = resMgr->integerValue( sec, tmpl.arg( "y" ), inf.y );
1178 inf.w = resMgr->integerValue( sec, tmpl.arg( "width" ), inf.w );
1179 inf.h = resMgr->integerValue( sec, tmpl.arg( "height" ), inf.h );
1181 inf.fixW = resMgr->integerValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1182 inf.fixH = resMgr->integerValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1185 if ( !resMgr->value( sec, tmpl.arg( "place" ), place ) )
1188 if ( resMgr->value( sec, tmpl.arg( "place" ), placeStr ) )
1189 place = dockPlace( placeStr );
1192 if ( place >= DockUnmanaged && place <= DockMinimized )
1199 Name: saveGeometry [private]
1203 bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec,
1204 const QString& name, const GeomInfo& inf ) const
1206 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1209 QString tmpl = QString( "%1.%2" ).arg( name );
1211 resMgr->setValue( sec, tmpl.arg( "visible" ), inf.vis );
1212 resMgr->setValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1213 resMgr->setValue( sec, tmpl.arg( "index" ), inf.index );
1214 resMgr->setValue( sec, tmpl.arg( "offset" ), inf.offset );
1215 resMgr->setValue( sec, tmpl.arg( "x" ), inf.x );
1216 resMgr->setValue( sec, tmpl.arg( "y" ), inf.y );
1217 resMgr->setValue( sec, tmpl.arg( "width" ), inf.w );
1218 resMgr->setValue( sec, tmpl.arg( "height" ), inf.h );
1219 resMgr->setValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1220 resMgr->setValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1221 resMgr->setValue( sec, tmpl.arg( "place" ), inf.place );
1227 Name: collectNames [private]
1231 void QtxDockAction::collectNames( const int place, QStringList& lst ) const
1233 QPtrList<QDockWindow> winList;
1234 QDockArea* area = dockArea( place );
1236 winList = area->dockWindowList();
1238 winList = mainWindow()->dockWindows( (Qt::Dock)place );
1240 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
1243 if ( myInfo.contains( it.current() ) )
1244 name = myInfo[it.current()].name;
1245 if ( name.isEmpty() )
1246 name = windowName( it.current() );
1247 if ( name.isEmpty() )
1254 void QtxDockAction::updateMenus()
1256 for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it )
1258 QPopupMenu* pm = it.key();
1259 MenuInfo& inf = it.data();
1261 int toolId = findId( pm, inf.tool );
1262 int dockId = findId( pm, inf.dock );
1264 int index = pm->indexOf( dockId );
1266 if ( isSeparate() && !inf.tool )
1267 inf.tool = new QPopupMenu( pm );
1269 pm->removeItem( dockId );
1270 pm->removeItem( toolId );
1272 if ( !isSeparate() && inf.tool )
1279 splitMenuText( dock, tool );
1282 iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) :
1283 pm->insertItem ( iconSet(), dock, inf.dock, -1, index );
1289 iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) :
1290 pm->insertItem ( iconSet(), tool, inf.tool, -1, index );