1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: QtxDockAction.cxx
24 // Author: Sergey TELKOV
26 #include "QtxDockAction.h"
30 #include <QDockWidget>
31 #include <QMainWindow>
35 \brief Dockable windows & toolbars list action.
37 Implements the action which provides the popup menu with the list
38 of toolbars and/or dockable windows list owned by the main window.
39 This action can be used, for example, in the menu "Windows".
44 \param mw parent main window
46 QtxDockAction::QtxDockAction( QMainWindow* mw )
47 : QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw ),
56 \param text description (tooltip) text
57 \param menuText menu text
58 \param mw parent main window
60 QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw )
61 : QtxAction( text, menuText, 0, mw ),
70 \param text description (tooltip) text
71 \param icon action icon
72 \param menuText menu text
73 \param mw parent main window
75 QtxDockAction::QtxDockAction( const QString& text, const QIcon& icon, const QString& menuText, QMainWindow* mw )
76 : QtxAction( text, icon, menuText, 0, mw ),
86 Does nothing currently.
88 QtxDockAction::~QtxDockAction()
90 // to avoid memory leak
91 if( QMenu* aMenu = menu() )
99 \brief Update associated menu
101 void QtxDockAction::update()
107 \brief Get parent main window.
108 \return main window pointer.
110 QMainWindow* QtxDockAction::mainWindow() const
116 \brief Get dock action type.
117 \return dock type (QtxDockAction::DockType)
119 int QtxDockAction::dockType() const
125 \brief Set dock action type.
126 \param type dock type (QtxDockAction::DockType)
128 void QtxDockAction::setDockType( const int type )
134 \brief Prepare popup menu with dock windows list when
135 parent popup menu is shown.
137 void QtxDockAction::onAboutToShow()
140 setVisible( menu() && !menu()->isEmpty() );
144 \brief Get all toolbars owned by parent main window.
145 \param lst returned list of all toolbars owned by main window
147 void QtxDockAction::toolBars( QList<QToolBar*>& lst ) const
151 QMainWindow* mw = mainWindow();
155 QList<QToolBar*> toolbars = qFindChildren<QToolBar*>( mw );
156 for ( QList<QToolBar*>::iterator it = toolbars.begin(); it != toolbars.end(); ++it )
159 if ( tb->parentWidget() == mw )
165 \brief Get all dockable windows owned by parent main window.
166 \param lst returned list of all dockable windows owned by main window
168 void QtxDockAction::dockWidgets( QList<QDockWidget*>& lst ) const
172 QMainWindow* mw = mainWindow();
176 QList<QDockWidget*> dockwidgets = qFindChildren<QDockWidget*>( mw );
177 for ( QList<QDockWidget*>::iterator it = dockwidgets.begin(); it != dockwidgets.end(); ++it )
179 QDockWidget* dw = *it;
180 if ( dw->parentWidget() == mw )
186 void QtxDockAction::updateInfo( QDockWindow* dw )
188 QAction* a = action( dw );
192 a->setText( dw->caption() );
193 a->setMenuText( dw->caption() );
195 if ( isToolBar( dw ) )
196 a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) );
198 a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) );
200 const QPixmap* icon = dw->icon();
202 a->setIconSet( *icon );
207 \brief Customize action adding to the widget operation.
209 Called when the action is added to the widget.
210 Reimplemented from QtxAction class.
212 \param w widget this action is added to (menu or toolbar)
214 void QtxDockAction::addedTo( QWidget* w )
216 if ( w->inherits( "QMenu" ) )
217 connect( w, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
221 \brief Customize action removing from the widget operation.
223 Called when the action is removed from the widget.
224 Reimplemented from QtxAction class.
226 \param w widget this action is removed from to (menu or toolbar)
228 void QtxDockAction::removedFrom( QWidget* w )
230 if ( w->inherits( "QMenu" ) )
231 disconnect( w, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
235 \brief Initialize the action.
237 void QtxDockAction::initialize()
239 setMenu( new QMenu( 0 ) );
243 \brief Update action child popup menu.
245 void QtxDockAction::updateMenu()
253 if ( dockType() == DockWidget || dockType() == Both )
255 QList<QDockWidget*> dwList;
256 dockWidgets( dwList );
257 for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
258 pm->addAction( (*it)->toggleViewAction() );
263 if ( dockType() == ToolBar || dockType() == Both )
265 QList<QToolBar*> tbList;
267 for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
268 pm->addAction( (*it)->toggleViewAction() );
271 Qtx::simplifySeparators( pm );