From: stv Date: Wed, 21 Feb 2007 09:09:14 +0000 (+0000) Subject: no message X-Git-Tag: For_HDF~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=65d2c636f731014ebb0a26a2eb36dcc124ec0994;p=modules%2Fgui.git no message --- diff --git a/src/Qtx/QtxAction.cxx b/src/Qtx/QtxAction.cxx index 23bd566af..9a04b8d07 100755 --- a/src/Qtx/QtxAction.cxx +++ b/src/Qtx/QtxAction.cxx @@ -22,7 +22,9 @@ #include "QtxAction.h" #include +#include #include +#include /*! Name: QtxAction [public] @@ -34,6 +36,8 @@ QtxAction::QtxAction( QObject* parent, const char* name, bool toggle ) : QAction( parent ) { setCheckable( toggle ); + + QApplication::instance()->installEventFilter( this ); } /*! @@ -53,6 +57,8 @@ QtxAction::QtxAction( const QString& text, const QIcon& icon, setToolTip( text ); setShortcut( accel ); setCheckable( toggle ); + + QApplication::instance()->installEventFilter( this ); } /*! @@ -70,6 +76,8 @@ QtxAction::QtxAction( const QString& text, const QString& menuText, int accel, setToolTip( text ); setShortcut( accel ); setCheckable( toggle ); + + QApplication::instance()->installEventFilter( this ); } /*! @@ -81,6 +89,18 @@ QtxAction::~QtxAction() { } +bool QtxAction::eventFilter( QObject* o, QEvent* e ) +{ + if ( o && o->isWidgetType() ) + { + if ( e->type() == QEvent::ActionAdded && ((QActionEvent*)e)->action() == this ) + addedTo( (QWidget*)o ); + if ( e->type() == QEvent::ActionRemoved && ((QActionEvent*)e)->action() == this ) + removedFrom( (QWidget*)o ); + } + return QAction::eventFilter( o, e ); +} + /*! Name: addTo [virtual public] Desc: Adds this action to widget. Returns true if the action was added @@ -132,80 +152,10 @@ bool QtxAction::removeFrom( QWidget* w ) return true; } -/*! - Name: setPopup [virtual public] - Desc: Set or unset the sub popup menu for item with specified id in the given popup. -*/ - -void QtxAction::setPopup( QWidget* w, const int id, QMenu* subPopup ) const +void QtxAction::addedTo( QWidget* ) { -/* - if ( !w ) - return; - - QMenuData* pmd = 0; - - if ( w->inherits( "QPopupMenu" ) ) - pmd = ::qt_cast( w ); - else if ( w->inherits( "QMenuBar" ) ) - pmd = ::qt_cast( w ); - - if ( !pmd ) - return; // bad widget - - QMenuData* md = 0; - QMenuItem* item = pmd->findItem( id, &md ); - if ( !item || md != pmd ) - return; // item is not found - - QPopupMenu* oldPopup = item->popup(); - if ( oldPopup == subPopup ) - return; // popup is not changed - - // get properties - int accel = pmd->accel( id ); - bool isOn = pmd->isItemEnabled( id ); - bool isVisible = pmd->isItemVisible( id ); - int pos = pmd->indexOf( id ); - QString text = pmd->text( id ); - QIconSet icon; - if ( pmd->iconSet( id ) ) - icon = *pmd->iconSet( id ); - - // remove previous item - pmd->removeItem( id ); - - // add new item - if ( w->inherits( "QPopupMenu" ) ) - { - // --- QPopupMenu --- - QPopupMenu* popup = (QPopupMenu*)w; - if ( icon.isNull() ) - pos = popup->indexOf( subPopup ? popup->insertItem( text, subPopup, id, pos ) : - popup->insertItem( text, id, pos ) ); - else - pos = popup->indexOf( subPopup ? popup->insertItem( icon, text, subPopup, id, pos ) : - popup->insertItem( icon, text, id, pos ) ); - } - else - { - // --- QMenuBar --- - QMenuBar* mb = (QMenuBar*)w; - if ( icon.isNull() ) - pos = mb->indexOf( subPopup ? mb->insertItem( text, subPopup, id, pos ) : - mb->insertItem( text, id, pos ) ); - else - pos = mb->indexOf( subPopup ? mb->insertItem( icon, text, subPopup, id, pos ) : - mb->insertItem( icon, text, id, pos ) ); - } - - // restore properties - pmd->setId( pos, id ); // for sure (if id < 0) - pmd->setAccel( accel, id ); - pmd->setItemEnabled( id, isOn ); - pmd->setItemVisible( id, isVisible ); +} - // delete old popup - delete oldPopup; -*/ +void QtxAction::removedFrom( QWidget* ) +{ } diff --git a/src/Qtx/QtxAction.h b/src/Qtx/QtxAction.h index 33932ec70..fa184e2c3 100755 --- a/src/Qtx/QtxAction.h +++ b/src/Qtx/QtxAction.h @@ -36,24 +36,23 @@ class QMenu; class QTX_EXPORT QtxAction : public QAction { - Q_OBJECT + Q_OBJECT public: - QtxAction( QObject* = 0, const char* = 0, bool = false ); - QtxAction( const QString&, const QString&, int, QObject*, const char* = 0, bool = false ); - QtxAction( const QString&, const QIcon&, const QString&, int, QObject*, const char* = 0, bool = false ); - virtual ~QtxAction(); + QtxAction( QObject* = 0, const char* = 0, bool = false ); + QtxAction( const QString&, const QString&, int, QObject*, const char* = 0, bool = false ); + QtxAction( const QString&, const QIcon&, const QString&, int, QObject*, const char* = 0, bool = false ); + virtual ~QtxAction(); - virtual bool addTo( QWidget* ); - virtual bool addTo( QWidget*, const int ); + virtual bool eventFilter( QObject*, QEvent* ); - virtual bool removeFrom( QWidget* ); + virtual bool addTo( QWidget* ); + virtual bool addTo( QWidget*, const int ); + virtual bool removeFrom( QWidget* ); protected: - void setPopup( QWidget*, const int, QMenu* ) const; - -private: - QMap myMenuIds; + virtual void addedTo( QWidget* ); + virtual void removedFrom( QWidget* ); }; #ifdef WIN32 diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index 869dd0026..c6b700dcf 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -973,11 +973,15 @@ void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bo if ( !isVisible( node->id, par ? par->id : -1 ) ) continue; + bool isMenu = false; QAction* a = itemAction( node->id ); if ( !a ) + { + isMenu = true; a = menuAction( node->id ); + } - if ( !a->menu() || !a->menu()->isEmpty() ) + if ( !isMenu || !a->menu()->isEmpty() ) mw->addAction( a ); } } diff --git a/src/Qtx/QtxDockAction.cxx b/src/Qtx/QtxDockAction.cxx new file mode 100755 index 000000000..49b22b89c --- /dev/null +++ b/src/Qtx/QtxDockAction.cxx @@ -0,0 +1,233 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxDockAction.cxx +// Author: Sergey TELKOV + +#include "QtxDockAction.h" + +#include +#include +#include +#include + +/*! + Name: QtxDockAction [public] + Desc: Constructs an Dock action with given main window and name. +*/ + +QtxDockAction::QtxDockAction( QMainWindow* mw ) +: QtxAction( "Windows and Toolbars", "Windows and Toolbars", 0, mw ), +myMain( mw ), +myType( Both ) +{ + initialize(); +} + +/*! + Name: QtxDockAction [public] + Desc: This constructor creates an action with the following properties: the + description text, the menu text and. It is a child of given main window + and named specified name. +*/ + +QtxDockAction::QtxDockAction( const QString& text, const QString& menuText, QMainWindow* mw ) +: QtxAction( text, menuText, 0, mw ), +myMain( mw ), +myType( Both ) +{ + initialize(); +} + +/*! + Name: QtxDockAction [public] + Desc: This constructor creates an action with the following properties: the + description text, the menu text, the icon or iconset icon and keyboard + accelerator. It is a child of given main window and named specified name. +*/ + +QtxDockAction::QtxDockAction( const QString& text, const QIcon& icon, const QString& menuText, QMainWindow* mw ) +: QtxAction( text, icon, menuText, 0, mw ), +myMain( mw ), +myType( Both ) +{ + initialize(); +} + +/*! + Name: ~QtxDockAction [public] + Desc: Removes all added popup items. +*/ + +QtxDockAction::~QtxDockAction() +{ +} + +/*! + Name: mainWindow [public] + Desc: Returns the main window which contains managed dock windows. +*/ + +QMainWindow* QtxDockAction::mainWindow() const +{ + return myMain; +} + +int QtxDockAction::dockType() const +{ + return myType; +} + +void QtxDockAction::setDockType( const int type ) +{ + myType = type; +} + +/*! + Name: onAboutToShow [private slots] + Desc: Prepare sub popup with dock windows list when parent popup is shown. +*/ + +void QtxDockAction::onAboutToShow() +{ + updateMenu(); + setVisible( menu() && !menu()->isEmpty() ); +} + +/*! + Name: toolBars [private] + Desc: Returns all toolbars of the main window. +*/ + +void QtxDockAction::toolBars( QList& lst ) const +{ + lst.clear(); + + QMainWindow* mw = mainWindow(); + if ( !mw ) + return; + + QList toolbars = qFindChildren( mw ); + for ( QList::iterator it = toolbars.begin(); it != toolbars.end(); ++it ) + { + QToolBar* tb = *it; + if ( tb->parentWidget() == mw ) + lst.append( tb ); + } +} + +/*! + Name: dockWidgets [private] + Desc: Returns all dock widgets of the main window. +*/ + +void QtxDockAction::dockWidgets( QList& lst ) const +{ + lst.clear(); + + QMainWindow* mw = mainWindow(); + if ( !mw ) + return; + + QList dockwidgets = qFindChildren( mw ); + for ( QList::iterator it = dockwidgets.begin(); it != dockwidgets.end(); ++it ) + { + QDockWidget* dw = *it; + if ( dw->parentWidget() == mw ) + lst.append( dw ); + } +} + +/*! + Name: updateInfo [private] + Desc: Updates icon and caption info of dock window in the corresponded action. +*/ +/* +void QtxDockAction::updateInfo( QDockWindow* dw ) +{ + QAction* a = action( dw ); + if ( !a ) + return; + + a->setText( dw->caption() ); + a->setMenuText( dw->caption() ); + + if ( isToolBar( dw ) ) + a->setStatusTip( tr( "Toggles toolbar \"%1\" on/off" ).arg( dw->caption() ) ); + else + a->setStatusTip( tr( "Toggles window \"%1\" on/off" ).arg( dw->caption() ) ); + + const QPixmap* icon = dw->icon(); + if ( icon ) + a->setIconSet( *icon ); +} +*/ + +void QtxDockAction::addedTo( QWidget* w ) +{ + if ( w->inherits( "QMenu" ) ) + connect( w, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); +} + +void QtxDockAction::removedFrom( QWidget* w ) +{ + if ( w->inherits( "QMenu" ) ) + disconnect( w, SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); +} + +/*! + Name: initialize [private] + Desc: Initialisation of the object. +*/ + +void QtxDockAction::initialize() +{ + setMenu( new QMenu( 0 ) ); +} + +/*! + Updates menu of action +*/ +void QtxDockAction::updateMenu() +{ + QMenu* pm = menu(); + if ( !pm ) + return; + + pm->clear(); + + if ( dockType() == DockWidget || dockType() == Both ) + { + QList dwList; + dockWidgets( dwList ); + for ( QList::iterator it = dwList.begin(); it != dwList.end(); ++it ) + pm->addAction( (*it)->toggleViewAction() ); + } + + pm->addSeparator(); + + if ( dockType() == ToolBar || dockType() == Both ) + { + QList tbList; + toolBars( tbList ); + for ( QList::iterator it = tbList.begin(); it != tbList.end(); ++it ) + pm->addAction( (*it)->toggleViewAction() ); + } + + Qtx::simplifySeparators( pm ); +} diff --git a/src/Qtx/QtxDockAction.h b/src/Qtx/QtxDockAction.h new file mode 100755 index 000000000..8fd83e6fb --- /dev/null +++ b/src/Qtx/QtxDockAction.h @@ -0,0 +1,80 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File: QtxDockAction.h +// Author: Sergey TELKOV + +#ifndef QTX_DOCKACTION_H +#define QTX_DOCKACTION_H + +#include "QtxAction.h" + +#include + +class QIcon; +class QString; +class QToolBar; +class QDockWidget; +class QMainWindow; + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +class QTX_EXPORT QtxDockAction : public QtxAction +{ + Q_OBJECT + +public: + enum { ToolBar, DockWidget, Both }; + +public: + QtxDockAction( QMainWindow* ); + QtxDockAction( const QString&, const QString&, QMainWindow* ); + QtxDockAction( const QString&, const QIcon&, const QString&, QMainWindow* ); + virtual ~QtxDockAction(); + + int dockType() const; + void setDockType( const int ); + + QMainWindow* mainWindow() const; + +private Q_SLOTS: + void onAboutToShow(); + +protected: + virtual void addedTo( QWidget* ); + virtual void removedFrom( QWidget* ); + +private: + void initialize(); + void updateMenu(); + + void toolBars( QList& ) const; + void dockWidgets( QList& ) const; + +private: + int myType; + QMainWindow* myMain; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 4047e221a..0739226ef 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -30,7 +30,7 @@ #include #include -//#include +#include #include #include @@ -185,11 +185,15 @@ void STD_Application::createActions() tr( "MEN_DESK_HELP_ABOUT" ), tr( "PRP_DESK_HELP_ABOUT" ), Qt::SHIFT+Qt::Key_A, desk, false, this, SLOT( onHelpAbout() ) ); -/* - QtxDockAction* da = new QtxDockAction( tr( "TOT_DOCK_WINDOWS" ), tr( "MEN_DOCK_WINDOWS" ), desk ); - registerAction( ViewWindowsId, da ); - da->setAutoPlace( false ); -*/ + + QtxDockAction* dwa = new QtxDockAction( tr( "TOT_DOCKWINDOWS" ), tr( "MEN_DOCKWINDOWS" ), desk ); + dwa->setDockType( QtxDockAction::DockWidget ); + registerAction( ViewWindowsId, dwa ); + + QtxDockAction* tba = new QtxDockAction( tr( "TOT_TOOLBARS" ), tr( "MEN_TOOLBARS" ), desk ); + tba->setDockType( QtxDockAction::ToolBar ); + registerAction( ViewToolBarsId, tba ); + // Create menus int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1, MenuFileId, 0 ); @@ -214,6 +218,7 @@ void STD_Application::createActions() createMenu( EditPasteId, editMenu ); createMenu( separator(), editMenu ); + createMenu( ViewToolBarsId, viewMenu, 0 ); createMenu( ViewWindowsId, viewMenu, 0 ); createMenu( separator(), viewMenu, -1, 10 ); createMenu( ViewStatusBarId, viewMenu, 10 ); diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index b28adcb1a..3de1db384 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -46,6 +46,11 @@ class STD_EXPORT STD_Application : public SUIT_Application { Q_OBJECT +public: + enum { FileNewId, FileOpenId, FileCloseId, FileSaveId, FileSaveAsId, FileExitId, + ViewWindowsId, ViewToolBarsId, ViewStatusBarId, NewWindowId, + EditCutId, EditCopyId, EditPasteId, HelpAboutId, UserID }; + public: STD_Application(); virtual ~STD_Application(); @@ -125,14 +130,6 @@ protected: MenuHelpId = 7 }; - enum { FileNewId, FileOpenId, FileCloseId, - FileSaveId, FileSaveAsId, FileExitId, - ViewStatusBarId, ViewWindowsId, NewWindowId, - EditCutId, EditCopyId, EditPasteId, - HelpAboutId, - UserID - }; - protected: virtual void createActions(); virtual void updateDesktopTitle(); diff --git a/src/STD/resources/STD_msg_en.ts b/src/STD/resources/STD_msg_en.ts index 0f0c794ab..245c4c391 100644 --- a/src/STD/resources/STD_msg_en.ts +++ b/src/STD/resources/STD_msg_en.ts @@ -454,12 +454,20 @@ Do you want to save changes? Study %1 saved - TOT_DOCK_WINDOWS - Show / hide dockable windows and toolbars + TOT_DOCKWINDOWS + Show / hide dockable windows - MEN_DOCK_WINDOWS - Windows and Toolbars + MEN_DOCKWINDOWS + Windows + + + TOT_TOOLBARS + Show / hide toolbars + + + MEN_TOOLBARS + Toolbars ABOUT_INFO