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 );
259 Sets menu text of action
260 \param txt - new menu text
262 void QtxDockAction::setMenuText( const QString& txt )
264 if ( menuText() == txt )
267 QtxAction::setMenuText( txt );
272 Name: addDockWindow [public]
273 Desc: Add dock window to internal data structures. Action will be include all added
274 dock windows in to menu and manage their place configuration.
277 bool QtxDockAction::addDockWindow( QDockWindow* dw )
279 if ( !dw || !mainWindow() )
282 if ( myInfo.contains( dw ) )
285 myInfo.insert( dw, DockInfo() );
287 DockInfo& inf = myInfo[dw];
288 inf.name = windowName( dw );
289 QAction* a = inf.a = new QAction( mainWindow(), 0, true );
291 autoLoadPlaceInfo( dw );
293 bool block = a->signalsBlocked();
294 a->blockSignals( true );
295 a->setOn( dw->isVisibleTo( mainWindow() ) );
296 a->blockSignals( block );
301 dw->installEventFilter( this );
303 connect( a, SIGNAL( toggled( bool ) ), this, SLOT( onToggled( bool ) ) );
304 connect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
305 connect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
311 Name: removeDockWindow [public]
312 Desc: Remove dock window from internal data structures. Action will not manage this window.
315 bool QtxDockAction::removeDockWindow( QDockWindow* dw )
317 if ( !myInfo.contains( dw ) )
320 myGeom.remove( myInfo[dw].name );
325 dw->removeEventFilter( this );
327 disconnect( dw, SIGNAL( destroyed( QObject* ) ), this, SLOT( onWindowDestroyed( QObject* ) ) );
328 disconnect( dw, SIGNAL( visibilityChanged( bool ) ), this, SLOT( onVisibilityChanged( bool ) ) );
334 Name: eventFilter [public]
335 Desc: Event filter process caption and icon changing of managed dock windows
336 and try to add newly appeared dock windows.
339 bool QtxDockAction::eventFilter( QObject* o, QEvent* e )
341 if ( o->inherits( "QDockWindow" ) && ( e->type() == QEvent::CaptionChange ||
342 e->type() == QEvent::IconChange ) )
343 updateInfo( (QDockWindow*)o );
345 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildRemoved )
347 QChildEvent* ce = (QChildEvent*)e;
348 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
349 savePlaceInfo( (QDockWindow*)ce->child() );
352 if ( o->inherits( "QDockArea" ) && e->type() == QEvent::ChildInserted )
354 QChildEvent* ce = (QChildEvent*)e;
355 if ( ce->child() && ce->child()->inherits( "QDockWindow" ) )
356 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, ce->child() ) );
363 Name: restoreGeometry [public]
364 Desc: Retrieve the dock window geometry. If dock window specified as 0
365 then all windows geometry will be restored.
368 void QtxDockAction::restoreGeometry( QDockWindow* dw ) const
377 Name: storeGeometry [public]
378 Desc: Store the dock window geometry. If dock window specified as 0
379 then all windows geometry will be stored.
382 void QtxDockAction::storeGeometry( QDockWindow* dw )
384 QPtrList<QDockWindow> dwList;
389 dockWindows( dwList );
391 for ( QPtrListIterator<QDockWindow> it( dwList ); it.current(); ++it )
392 savePlaceInfo( it.current() );
396 Name: loadGeometry [public]
397 Desc: Retrieve the dock windows geometry information from the specified resource manager section.
400 void QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear )
402 QString sec = section.stripWhiteSpace();
403 if ( !resMgr || sec.isEmpty() )
406 myNames = QStringList::split( "|", resMgr->stringValue( sec, "windows_list", QString::null ) );
408 QMap<QString, int> map;
409 QStringList params = resMgr->parameters( sec );
410 for ( QStringList::const_iterator it = params.begin(); it != params.end(); ++it )
412 QString p = QStringList::split( ".", *it, true ).first().stripWhiteSpace();
417 for ( QMap<QString, int>::ConstIterator itr = map.begin(); itr != map.end(); ++itr )
420 if ( !clear && myGeom.contains( itr.key() ) )
421 inf = myGeom[itr.key()];
424 inf.vis = true; inf.newLine = false; inf.place = DockTop;
425 inf.index = 0; inf.offset = 0;
426 inf.x = 0; inf.y = 0; inf.w = 0; inf.h = 0;
427 inf.fixW = -1; inf.fixH = -1;
429 if ( loadGeometry( resMgr, sec, itr.key(), inf ) )
430 myGeom.insert( itr.key(), inf );
435 Name: saveGeometry [public]
436 Desc: Store the dock windows geometry information into the specified resource manager section.
439 void QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& section, const bool clear ) const
441 QString sec = section.stripWhiteSpace();
442 if ( !resMgr || sec.isEmpty() )
445 QtxDockAction* that = (QtxDockAction*)this;
446 that->storeGeometry();
448 that->myNames.clear();
449 collectNames( Minimized, that->myNames );
450 for ( int i = DockTornOff; i < Minimized; i++ )
451 collectNames( i, that->myNames );
454 resMgr->remove( sec );
456 resMgr->setValue( sec, "windows_list", myNames.join( "|" ) );
458 for ( GeomMap::ConstIterator it = myGeom.begin(); it != myGeom.end(); ++it )
459 saveGeometry( resMgr, sec, it.key(), it.data() );
463 Name: onAboutToShow [private slots]
464 Desc: Prepare sub popup with dock windows list when parent popup is shown.
467 void QtxDockAction::onAboutToShow()
469 const QObject* obj = sender();
470 if ( obj && obj->inherits( "QPopupMenu" ) )
472 QPopupMenu* pm = (QPopupMenu*)obj;
474 pm->setItemEnabled( findId( pm, myMenu[pm].dock ), isEnabled() && myMenu[pm].dock && myMenu[pm].dock->count() );
475 pm->setItemEnabled( findId( pm, myMenu[pm].tool ), isEnabled() && myMenu[pm].tool && myMenu[pm].tool->count() );
480 Name: onToggled [private slots]
481 Desc: Show or hide dock window when user toggled window item in popup.
484 void QtxDockAction::onToggled( bool on )
486 QDockWindow* dw = dockWindow( (QAction*)sender() );
488 on ? dw->show() : dw->hide();
492 Name: onPopupDestroyed [private slots]
493 Desc: Remove destroyed popup from data structures.
496 void QtxDockAction::onPopupDestroyed( QObject* obj )
498 myMenu.remove( (QPopupMenu*)obj );
502 Name: onWindowDestroyed [private slots]
503 Desc: Remove information about destroyed dock window.
506 void QtxDockAction::onWindowDestroyed( QObject* obj )
508 QDockWindow* dw = (QDockWindow*)obj;
509 if ( !myInfo.contains( dw ) )
517 Name: onVisibilityChanged [private slots]
518 Desc: Toggle corresponded action when visibility state of dock window changed.
521 void QtxDockAction::onVisibilityChanged( bool on )
523 const QObject* obj = sender();
524 if ( !obj || !obj->inherits( "QDockWindow" ) )
527 QDockWindow* dw = (QDockWindow*)obj;
529 QAction* a = action( dw );
530 if ( a && a->isOn() != on )
532 bool block = a->signalsBlocked();
533 a->blockSignals( true );
535 a->blockSignals( block );
542 Name: onDockWindowPositionChanged [private slots]
543 Desc: Update dock window place information
546 void QtxDockAction::onDockWindowPositionChanged( QDockWindow* dw )
552 Name: event [protected]
553 Desc: Check consistency the popup content and internal datas.
554 Synchronize internal data structures with popup content.
557 bool QtxDockAction::event( QEvent* e )
559 if ( e->type() == (int)AutoAdd )
561 QCustomEvent* ce = (QCustomEvent*)e;
562 QDockWindow* dw = (QDockWindow*)ce->data();
563 if ( !myInfo.contains( dw ) )
565 autoAddDockWindow( dw );
566 autoLoadPlaceInfo( dw );
570 return QtxAction::event( e );
574 Name: checkPopup [private]
575 Desc: Check consistency the popup content and internal datas.
576 Synchronize internal data structures with popup content.
579 void QtxDockAction::checkPopup( QPopupMenu* pm )
581 if ( !myMenu.contains( pm ) )
584 int id = findId( pm, myMenu[pm].dock );
587 delete myMenu[pm].dock;
590 id = findId( pm, myMenu[pm].tool );
593 delete myMenu[pm].tool;
597 if ( !myMenu[pm].dock )
599 delete myMenu[pm].tool;
601 disconnect( pm, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
606 Name: fillPopup [private]
607 Desc: Clear the popup and the add to it required actions.
610 void QtxDockAction::fillPopup( QPopupMenu* pm ) const
612 if ( !pm || !mainWindow() )
615 if ( !myMenu.contains( pm ) )
618 QPopupMenu* dockMenu = myMenu[pm].dock;
619 QPopupMenu* toolMenu = myMenu[pm].tool;
621 for ( InfoMap::ConstIterator mit = myInfo.begin(); mit != myInfo.end(); ++mit )
623 mit.data().a->removeFrom( dockMenu );
624 mit.data().a->removeFrom( toolMenu );
633 QPtrList<QDockWindow> dockList;
634 dockWindows( dockList, mainWindow() );
636 if ( dockList.isEmpty() )
639 QPtrList<QAction> toolBars, windows;
640 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
642 if ( !myInfo.contains( it.current() ) )
644 QtxDockAction* that = (QtxDockAction*)this;
645 that->autoAddDockWindow( it.current() );
648 if ( !mainWindow()->appropriate( it.current() ) ||
649 it.current()->caption().isEmpty() || !action( it.current() ) )
652 if ( isToolBar( it.current() ) )
653 toolBars.append( action( it.current() ) );
655 windows.append( action( it.current() ) );
658 for ( QPtrListIterator<QAction> wit( windows ); wit.current(); ++wit )
659 wit.current()->addTo( dockMenu );
661 dockMenu->insertSeparator();
663 for ( QPtrListIterator<QAction> tit( toolBars ); tit.current(); ++tit )
664 tit.current()->addTo( toolMenu ? toolMenu : dockMenu );
666 Qtx::simplifySeparators( dockMenu );
667 Qtx::simplifySeparators( toolMenu );
671 Name: isToolBar [private]
672 Desc: Returns 'true' if dock window is a toolbar.
675 bool QtxDockAction::isToolBar( QDockWindow* dw ) const
677 return dw && dw->inherits( "QToolBar" );
681 Name: findId [private]
682 Desc: Returns identificator of popup item which contains sub popup 'pm' in the popup 'cont'.
685 int QtxDockAction::findId( QPopupMenu* cont, QPopupMenu* pm ) const
692 for ( int i = 0; i < (int)cont->count() && id == -1; i++ )
695 QMenuItem* item = cont->findItem( cont->idAt( i ), &md );
696 if ( item && md == cont && item->popup() == pm )
703 Name: dockWindows [private]
704 Desc: Returns all dock windows of the main window.
707 void QtxDockAction::dockWindows( QPtrList<QDockWindow>& lst, QMainWindow* main ) const
711 QMainWindow* mw = main ? main : mainWindow();
715 QObjectList* objs = mw->queryList( "QDockWindow" );
718 for ( QObjectListIt it( *objs ); it.current(); ++it )
720 QDockWindow* dockWin = ::qt_cast<QDockWindow*>( it.current() );
721 if ( dockWin && dockMainWindow( mw, dockWin ) )
722 lst.append( dockWin );
729 \return true if main window is parent of object
730 \param mw - main window
733 bool QtxDockAction::dockMainWindow( QMainWindow* mw, QObject* win ) const
740 if ( win->parent() && win->parent() == mw )
743 if ( ::qt_cast<QMainWindow*>( win->parent() ) )
753 Name: updateInfo [private]
754 Desc: Updates icon and caption info of dock window in the corresponded action.
757 void QtxDockAction::updateInfo( QDockWindow* dw )
759 QAction* a = action( dw );
763 a->setText( dw->caption() );
764 a->setMenuText( dw->caption() );
766 if ( isToolBar( dw ) )
767 a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) );
769 a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) );
771 const QPixmap* icon = dw->icon();
773 a->setIconSet( *icon );
777 Name: savePlaceInfo [private]
778 Desc: Store the place and geometry information from specified dock window.
781 void QtxDockAction::savePlaceInfo( QDockWindow* dw )
783 if ( !myInfo.contains( dw ) )
786 if ( !myGeom.contains( myInfo[dw].name ) )
787 myGeom.insert( myInfo[dw].name, GeomInfo() );
789 GeomInfo& inf = myGeom[myInfo[dw].name];
792 inf.vis = dw->isVisibleTo( mainWindow() );
793 mainWindow()->getLocation( dw, dock, inf.index, inf.newLine, inf.offset );
799 inf.h = dw->height();
800 inf.fixW = dw->fixedExtent().width();
801 inf.fixH = dw->fixedExtent().height();
805 Name: loadPlaceInfo [private]
806 Desc: Retrieve the stored place and geometry information to specified dock window.
809 void QtxDockAction::loadPlaceInfo( QDockWindow* dw ) const
811 if ( !myInfo.contains( dw ) )
814 QMainWindow* mw = mainWindow();
818 QObject* p = dw->parent();
819 if ( !( !p || p == mw || ( p->parent() && p->parent() == mw ) ) )
822 QString winName = myInfo[dw].name;
823 if ( winName.isEmpty() || !myGeom.contains( winName ) )
826 GeomInfo inf = myGeom[myInfo[dw].name];
828 mainWindow()->moveDockWindow( dw, (Qt::Dock)inf.place, inf.newLine, inf.index, inf.offset );
829 dw->setGeometry( inf.x, inf.y, inf.w, inf.h );
831 dw->setFixedExtentWidth( inf.fixW );
832 dw->setFixedExtentHeight( inf.fixH );
834 QtxDockAction* that = (QtxDockAction*)this;
835 that->myGeom.insert( myInfo[dw].name, inf );
839 Name: loadPlaceInfo [private]
840 Desc: Retrieve the stored place and geometry information to all dock windows.
843 void QtxDockAction::loadPlaceInfo() const
845 QMainWindow* mw = mainWindow();
849 typedef QPtrList<QDockWindow> DockWinList;
852 dockWindows( lst, mw );
854 QMap<QString, QDockWindow*> nameMap;
855 for ( QPtrListIterator<QDockWindow> itr( lst ); itr.current(); ++itr )
857 QObject* p = itr.current()->parent();
858 if ( !( !p || p == mw || ( p->parent() && p->parent() == mw ) ) )
862 if ( myInfo.contains( itr.current() ) )
863 name = myInfo[itr.current()].name;
865 if ( !myGeom.contains( name ) )
868 nameMap.insert( name, itr.current() );
872 for ( QStringList::const_iterator iter = myNames.begin(); iter != myNames.end(); ++iter )
874 if ( nameMap.contains( *iter ) )
875 winList.append( nameMap[*iter] );
876 nameMap.remove( *iter );
879 for ( QMap<QString, QDockWindow*>::ConstIterator mIt = nameMap.begin(); mIt != nameMap.end(); ++mIt )
880 winList.append( mIt.data() );
882 QMap<int, DockWinList> winMap;
883 QMap<QDockWindow*, GeomInfo*> geomMap;
885 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
888 if ( myInfo.contains( it.current() ) )
889 name = myInfo[it.current()].name;
891 if ( !myGeom.contains( name ) )
894 //! collect pointer of info to have fresh info data after processEvents();
895 GeomInfo* inf = (GeomInfo*)&( myGeom[name] );
896 geomMap.insert( it.current(), inf );
897 if ( !winMap.contains( inf->place ) )
898 winMap.insert( inf->place, DockWinList() );
899 winMap[inf->place].append( it.current() );
902 loadPlaceArea( DockMinimized, mw, 0,
903 winMap.contains( DockMinimized ) ? winMap[DockMinimized] : DockWinList(), geomMap );
904 for ( int i = DockTornOff; i < DockMinimized; i++ )
906 loadPlaceArea( i, mw, dockArea( i ), winMap.contains( i ) ? winMap[i] : DockWinList(), geomMap );
911 Name: loadPlaceArea [private]
912 Desc: Set the place and geometry information to all dock windows in the area.
915 void QtxDockAction::loadPlaceArea( const int place, QMainWindow* mw, QDockArea* area,
916 const QPtrList<QDockWindow>& dockList,
917 const QMap<QDockWindow*, GeomInfo*>& geomMap ) const
919 for ( QPtrListIterator<QDockWindow> it( dockList ); it.current(); ++it )
921 if ( !geomMap.contains( it.current() ) )
924 GeomInfo* inf = geomMap[it.current()];
925 mw->moveDockWindow( it.current(), (Qt::Dock)place, inf->newLine, inf->index, inf->offset );
931 qApp->processEvents();
933 for ( QPtrListIterator<QDockWindow> itr( dockList ); itr.current(); ++itr )
935 QDockWindow* dw = itr.current();
936 if ( !geomMap.contains( dw ) )
939 GeomInfo* inf = geomMap[dw];
940 if ( place != DockTornOff )
942 dw->setNewLine( inf->newLine );
943 dw->setOffset( inf->offset );
944 dw->setFixedExtentWidth( inf->fixW );
945 dw->setFixedExtentHeight( inf->fixH );
947 dw->setGeometry( inf->x, inf->y, inf->w, inf->h );
949 QAction* a = action( dw );
952 bool block = a->signalsBlocked();
953 a->blockSignals( true );
954 a->setOn( inf->vis );
955 a->blockSignals( block );
958 if ( mainWindow() && mainWindow()->appropriate( dw ) )
959 inf->vis ? dw->show() : dw->hide();
965 wid->layout()->invalidate();
966 wid->layout()->activate();
971 Name: action [private]
972 Desc: Returns action for the given dock window.
975 QAction* QtxDockAction::action( QDockWindow* dw ) const
978 if ( myInfo.contains( dw ) )
984 Name: dockWindow [private]
985 Desc: Returns dock window for the given action.
988 QDockWindow* QtxDockAction::dockWindow( const QAction* a ) const
991 for ( InfoMap::ConstIterator it = myInfo.begin(); it != myInfo.end() && !dw; ++it )
993 if ( it.data().a == a )
1000 Name: initialize [private]
1001 Desc: Initialisation of the object. Sets the event filters and add existing dock windows.
1004 void QtxDockAction::initialize( QMainWindow* mw )
1009 QPtrList<QDockWindow> lst;
1010 dockWindows( lst, mw );
1012 for ( QPtrListIterator<QDockWindow> it( lst ); it.current(); ++it )
1013 QApplication::postEvent( this, new QCustomEvent( (QEvent::Type)AutoAdd, it.current() ) );
1015 if ( mw->topDock() )
1016 mw->topDock()->installEventFilter( this );
1017 if ( mw->leftDock() )
1018 mw->leftDock()->installEventFilter( this );
1019 if ( mw->rightDock() )
1020 mw->rightDock()->installEventFilter( this );
1021 if ( mw->bottomDock() )
1022 mw->bottomDock()->installEventFilter( this );
1024 connect( mw, SIGNAL( dockWindowPositionChanged( QDockWindow* ) ),
1025 this, SLOT( onDockWindowPositionChanged( QDockWindow* ) ) );
1029 Name: windowName [private]
1030 Desc: Generate the dock window name.
1033 QString QtxDockAction::windowName( QDockWindow* dw ) const
1039 name = dw->name( "" );
1040 if ( name.isEmpty() )
1041 name = dw->caption();
1048 Name: autoAddDockWindow [private]
1049 Desc: Add the dock window if auto add property is setted.
1052 bool QtxDockAction::autoAddDockWindow( QDockWindow* dw )
1057 return addDockWindow( dw );
1061 Name: autoLoadPlaceInfo [private]
1062 Desc: Retieve the dock window place geometry if auto place property is setted.
1065 void QtxDockAction::autoLoadPlaceInfo( QDockWindow* dw )
1067 if ( isAutoPlace() )
1068 loadPlaceInfo( dw );
1072 Name: splitMenuText [private]
1076 void QtxDockAction::splitMenuText( QString& dock, QString& tool ) const
1078 dock = tool = menuText();
1079 if ( !isSeparate() )
1082 QStringList lst = splitText( menuText(), "|" );
1083 if ( lst.count() < 2 )
1084 lst = splitText( menuText(), "and" );
1091 Name: splitText [private]
1095 QStringList QtxDockAction::splitText( const QString& str, const QString& sep ) const
1099 int idx = str.lower().find( sep.lower() );
1102 res.append( str.mid( 0, idx ).stripWhiteSpace() );
1103 res.append( str.mid( idx + sep.length() ).stripWhiteSpace() );
1110 Name: dockPlace [private]
1114 int QtxDockAction::dockPlace( const QString& dockName ) const
1116 static QMap<QString, int> dockNameMap;
1117 if ( dockNameMap.isEmpty() )
1119 dockNameMap["top"] = DockTop;
1120 dockNameMap["bottom"] = DockBottom;
1121 dockNameMap["left"] = DockLeft;
1122 dockNameMap["right"] = DockRight;
1123 dockNameMap["tornoff"] = DockTornOff;
1124 dockNameMap["torn_off"] = DockTornOff;
1125 dockNameMap["outside"] = DockTornOff;
1126 dockNameMap["undock"] = DockTornOff;
1127 dockNameMap["minimized"] = DockMinimized;
1128 dockNameMap["unmanaged"] = DockUnmanaged;
1132 if ( dockNameMap.contains( dockName.lower() ) )
1133 res = dockNameMap[dockName.lower()];
1138 Name: dockArea [private]
1142 QDockArea* QtxDockAction::dockArea( const int place ) const
1144 if ( !mainWindow() )
1147 QDockArea* area = 0;
1151 area = mainWindow()->topDock();
1154 area = mainWindow()->bottomDock();
1157 area = mainWindow()->leftDock();
1160 area = mainWindow()->rightDock();
1167 Name: loadGeometry [private]
1171 bool QtxDockAction::loadGeometry( QtxResourceMgr* resMgr, const QString& sec,
1172 const QString& name, GeomInfo& inf ) const
1174 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1177 QString tmpl = QString( "%1.%2" ).arg( name );
1179 inf.vis = resMgr->booleanValue( sec, tmpl.arg( "visible" ), inf.vis );
1180 inf.newLine = resMgr->booleanValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1182 inf.index = resMgr->integerValue( sec, tmpl.arg( "index" ), inf.index );
1183 inf.offset = resMgr->integerValue( sec, tmpl.arg( "offset" ), inf.offset );
1185 inf.x = resMgr->integerValue( sec, tmpl.arg( "x" ), inf.x );
1186 inf.y = resMgr->integerValue( sec, tmpl.arg( "y" ), inf.y );
1187 inf.w = resMgr->integerValue( sec, tmpl.arg( "width" ), inf.w );
1188 inf.h = resMgr->integerValue( sec, tmpl.arg( "height" ), inf.h );
1190 inf.fixW = resMgr->integerValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1191 inf.fixH = resMgr->integerValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1194 if ( !resMgr->value( sec, tmpl.arg( "place" ), place ) )
1197 if ( resMgr->value( sec, tmpl.arg( "place" ), placeStr ) )
1198 place = dockPlace( placeStr );
1201 if ( place >= DockUnmanaged && place <= DockMinimized )
1208 Name: saveGeometry [private]
1212 bool QtxDockAction::saveGeometry( QtxResourceMgr* resMgr, const QString& sec,
1213 const QString& name, const GeomInfo& inf ) const
1215 if ( !resMgr || sec.isEmpty() || name.isEmpty() )
1218 QString tmpl = QString( "%1.%2" ).arg( name );
1220 resMgr->setValue( sec, tmpl.arg( "visible" ), inf.vis );
1221 resMgr->setValue( sec, tmpl.arg( "new_line" ), inf.newLine );
1222 resMgr->setValue( sec, tmpl.arg( "index" ), inf.index );
1223 resMgr->setValue( sec, tmpl.arg( "offset" ), inf.offset );
1224 resMgr->setValue( sec, tmpl.arg( "x" ), inf.x );
1225 resMgr->setValue( sec, tmpl.arg( "y" ), inf.y );
1226 resMgr->setValue( sec, tmpl.arg( "width" ), inf.w );
1227 resMgr->setValue( sec, tmpl.arg( "height" ), inf.h );
1228 resMgr->setValue( sec, tmpl.arg( "fixed_width" ), inf.fixW );
1229 resMgr->setValue( sec, tmpl.arg( "fixed_height" ), inf.fixH );
1230 resMgr->setValue( sec, tmpl.arg( "place" ), inf.place );
1236 Name: collectNames [private]
1240 void QtxDockAction::collectNames( const int place, QStringList& lst ) const
1242 QPtrList<QDockWindow> winList;
1243 QDockArea* area = dockArea( place );
1245 winList = area->dockWindowList();
1247 winList = mainWindow()->dockWindows( (Qt::Dock)place );
1249 for ( QPtrListIterator<QDockWindow> it( winList ); it.current(); ++it )
1252 if ( myInfo.contains( it.current() ) )
1253 name = myInfo[it.current()].name;
1254 if ( name.isEmpty() )
1255 name = windowName( it.current() );
1256 if ( name.isEmpty() )
1264 Updates menu of action
1266 void QtxDockAction::updateMenus()
1268 for ( MenuMap::Iterator it = myMenu.begin(); it != myMenu.end(); ++it )
1270 QPopupMenu* pm = it.key();
1271 MenuInfo& inf = it.data();
1273 int toolId = findId( pm, inf.tool );
1274 int dockId = findId( pm, inf.dock );
1276 int index = pm->indexOf( dockId );
1278 if ( isSeparate() && !inf.tool )
1279 inf.tool = new QPopupMenu( pm );
1281 pm->removeItem( dockId );
1282 pm->removeItem( toolId );
1284 if ( !isSeparate() && inf.tool )
1291 splitMenuText( dock, tool );
1294 iconSet().isNull() ? pm->insertItem ( dock, inf.dock, -1, index ) :
1295 pm->insertItem ( iconSet(), dock, inf.dock, -1, index );
1301 iconSet().isNull() ? pm->insertItem ( tool, inf.tool, -1, index ) :
1302 pm->insertItem ( iconSet(), tool, inf.tool, -1, index );