#include "QtxAction.h"
#include <QtGui/qmenu.h>
+#include <QtGui/qevent.h>
#include <QtGui/qmenubar.h>
+#include <QtGui/qapplication.h>
/*!
Name: QtxAction [public]
: QAction( parent )
{
setCheckable( toggle );
+
+ QApplication::instance()->installEventFilter( this );
}
/*!
setToolTip( text );
setShortcut( accel );
setCheckable( toggle );
+
+ QApplication::instance()->installEventFilter( this );
}
/*!
setToolTip( text );
setShortcut( accel );
setCheckable( toggle );
+
+ QApplication::instance()->installEventFilter( this );
}
/*!
{
}
+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
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<QPopupMenu*>( w );
- else if ( w->inherits( "QMenuBar" ) )
- pmd = ::qt_cast<QMenuBar*>( 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* )
+{
}
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<QWidget*,int> myMenuIds;
+ virtual void addedTo( QWidget* );
+ virtual void removedFrom( QWidget* );
};
#ifdef WIN32
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 );
}
}
--- /dev/null
+// 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 <QtGui/qmenu.h>
+#include <QtGui/qtoolbar.h>
+#include <QtGui/qdockwidget.h>
+#include <QtGui/qmainwindow.h>
+
+/*!
+ 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<QToolBar*>& lst ) const
+{
+ lst.clear();
+
+ QMainWindow* mw = mainWindow();
+ if ( !mw )
+ return;
+
+ QList<QToolBar*> toolbars = qFindChildren<QToolBar*>( mw );
+ for ( QList<QToolBar*>::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<QDockWidget*>& lst ) const
+{
+ lst.clear();
+
+ QMainWindow* mw = mainWindow();
+ if ( !mw )
+ return;
+
+ QList<QDockWidget*> dockwidgets = qFindChildren<QDockWidget*>( mw );
+ for ( QList<QDockWidget*>::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<QDockWidget*> dwList;
+ dockWidgets( dwList );
+ for ( QList<QDockWidget*>::iterator it = dwList.begin(); it != dwList.end(); ++it )
+ pm->addAction( (*it)->toggleViewAction() );
+ }
+
+ pm->addSeparator();
+
+ if ( dockType() == ToolBar || dockType() == Both )
+ {
+ QList<QToolBar*> tbList;
+ toolBars( tbList );
+ for ( QList<QToolBar*>::iterator it = tbList.begin(); it != tbList.end(); ++it )
+ pm->addAction( (*it)->toggleViewAction() );
+ }
+
+ Qtx::simplifySeparators( pm );
+}
--- /dev/null
+// 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 <QtCore/qlist.h>
+
+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<QToolBar*>& ) const;
+ void dockWidgets( QList<QDockWidget*>& ) const;
+
+private:
+ int myType;
+ QMainWindow* myMain;
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif
#include <SUIT_MessageBox.h>
#include <SUIT_ResourceMgr.h>
-//#include <QtxDockAction.h>
+#include <QtxDockAction.h>
#include <QtxActionMenuMgr.h>
#include <QtxActionToolMgr.h>
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 );
createMenu( EditPasteId, editMenu );
createMenu( separator(), editMenu );
+ createMenu( ViewToolBarsId, viewMenu, 0 );
createMenu( ViewWindowsId, viewMenu, 0 );
createMenu( separator(), viewMenu, -1, 10 );
createMenu( ViewStatusBarId, viewMenu, 10 );
{
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();
MenuHelpId = 7
};
- enum { FileNewId, FileOpenId, FileCloseId,
- FileSaveId, FileSaveAsId, FileExitId,
- ViewStatusBarId, ViewWindowsId, NewWindowId,
- EditCutId, EditCopyId, EditPasteId,
- HelpAboutId,
- UserID
- };
-
protected:
virtual void createActions();
virtual void updateDesktopTitle();
<translation>Study %1 saved</translation>
</message>
<message>
- <source>TOT_DOCK_WINDOWS</source>
- <translation>Show / hide dockable windows and toolbars</translation>
+ <source>TOT_DOCKWINDOWS</source>
+ <translation>Show / hide dockable windows</translation>
</message>
<message>
- <source>MEN_DOCK_WINDOWS</source>
- <translation>Windows and Toolbars</translation>
+ <source>MEN_DOCKWINDOWS</source>
+ <translation>Windows</translation>
+ </message>
+ <message>
+ <source>TOT_TOOLBARS</source>
+ <translation>Show / hide toolbars</translation>
+ </message>
+ <message>
+ <source>MEN_TOOLBARS</source>
+ <translation>Toolbars</translation>
</message>
<message>
<source>ABOUT_INFO</source>