1 // Copyright (C) 2007-2008 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.
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
22 // File: QtxDockAction.cxx
23 // Author: Sergey TELKOV
25 #include "QtxDockAction.h"
29 #include <QDockWidget>
30 #include <QMainWindow>
34 \brief Dockable windows & toolbars list action.
36 Implements the action which provides the popup menu with the list
37 of toolbars and/or dockable windows list owned by the main window.
38 This action can be used, for example, in the menu "Windows".
43 \param mw parent main window
45 QtxDockAction::QtxDockAction( QMainWindow* mw )
46 : QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw ),
55 \param text description (tooltip) text
56 \param menuText menu text
57 \param mw parent main window
59 QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw )
60 : QtxAction( text, menuText, 0, mw ),
69 \param text description (tooltip) text
70 \param icon action icon
71 \param menuText menu text
72 \param mw parent main window
74 QtxDockAction::QtxDockAction( const QString& text, const QIcon& icon, const QString& menuText, QMainWindow* mw )
75 : QtxAction( text, icon, menuText, 0, mw ),
85 Does nothing currently.
87 QtxDockAction::~QtxDockAction()
92 \brief Get parent main window.
93 \return main window pointer.
95 QMainWindow* QtxDockAction::mainWindow() const
101 \brief Get dock action type.
102 \return dock type (QtxDockAction::DockType)
104 int QtxDockAction::dockType() const
110 \brief Set dock action type.
111 \param type dock type (QtxDockAction::DockType)
113 void QtxDockAction::setDockType( const int type )
119 \brief Prepare popup menu with dock windows list when
120 parent popup menu is shown.
122 void QtxDockAction::onAboutToShow()
125 setVisible( menu() && !menu()->isEmpty() );
129 \brief Get all toolbars owned by parent main window.
130 \param lst returned list of all toolbars owned by main window
132 void QtxDockAction::toolBars( QList<QToolBar*>& lst ) const
136 QMainWindow* mw = mainWindow();
140 QList<QToolBar*> toolbars = qFindChildren<QToolBar*>( mw );
141 for ( QList<QToolBar*>::iterator it = toolbars.begin(); it != toolbars.end(); ++it )
144 if ( tb->parentWidget() == mw )
150 \brief Get all dockable windows owned by parent main window.
151 \param lst returned list of all dockable windows owned by main window
153 void QtxDockAction::dockWidgets( QList<QDockWidget*>& lst ) const
157 QMainWindow* mw = mainWindow();
161 QList<QDockWidget*> dockwidgets = qFindChildren<QDockWidget*>( mw );
162 for ( QList<QDockWidget*>::iterator it = dockwidgets.begin(); it != dockwidgets.end(); ++it )
164 QDockWidget* dw = *it;
165 if ( dw->parentWidget() == mw )
171 void QtxDockAction::updateInfo( QDockWindow* dw )
173 QAction* a = action( dw );
177 a->setText( dw->caption() );
178 a->setMenuText( dw->caption() );
180 if ( isToolBar( dw ) )
181 a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) );
183 a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) );
185 const QPixmap* icon = dw->icon();
187 a->setIconSet( *icon );
192 \brief Customize action adding to the widget operation.
194 Called when the action is added to the widget.
195 Reimplemented from QtxAction class.
197 \param w widget this action is added to (menu or toolbar)
199 void QtxDockAction::addedTo( QWidget* w )
201 if ( w->inherits( "QMenu" ) )
202 connect( w, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
206 \brief Customize action removing from the widget operation.
208 Called when the action is removed from the widget.
209 Reimplemented from QtxAction class.
211 \param w widget this action is removed from to (menu or toolbar)
213 void QtxDockAction::removedFrom( QWidget* w )
215 if ( w->inherits( "QMenu" ) )
216 disconnect( w, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
220 \brief Initialize the action.
222 void QtxDockAction::initialize()
224 setMenu( new QMenu( 0 ) );
228 \brief Update action child popup menu.
230 void QtxDockAction::updateMenu()
238 if ( dockType() == DockWidget || dockType() == Both )
240 QList<QDockWidget*> dwList;
241 dockWidgets( dwList );
242 for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
243 pm->addAction( (*it)->toggleViewAction() );
248 if ( dockType() == ToolBar || dockType() == Both )
250 QList<QToolBar*> tbList;
252 for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
253 pm->addAction( (*it)->toggleViewAction() );
256 Qtx::simplifySeparators( pm );