// 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
+// 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
+//
+// 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
+// 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
#include "QtxAction.h"
-#include <qwidget.h>
-#include <qmenubar.h>
-#include <qpopupmenu.h>
-#include <qwidgetlist.h>
-#include <qobjectlist.h>
-#include <qmainwindow.h>
-#include <qfile.h>
-#include <qdom.h>
-#include <qvaluelist.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qfile.h>
+
+#include <QtGui/qmenu.h>
+#include <QtGui/qwidget.h>
+#include <QtGui/qmenubar.h>
+#include <QtGui/qmainwindow.h>
+
+#include <QtXml/qdom.h>
// VSR: Uncomment this #define in order to allow dynamic menus support
// (emit signals when popup menu is pre-activated)
// Currently this support is disabled.
//#define ENABLE_DYNAMIC_MENU
-
-/*!
- Service functions
- Level: Internal
-*/
-namespace {
- QValueList<int> prepareIds( const QWidget* w )
- {
- QValueList<int> l;
- const QMenuData* md = 0;
- if ( w->inherits( "QMenuBar" ) )
- md = ::qt_cast<QMenuBar*>( w );
- else if ( w->inherits( "QPopupMenu" ) )
- md = ::qt_cast<QPopupMenu*>( w );
- if ( md ) {
- for ( uint i = 0; i < md->count(); i++ )
- l.append( md->idAt( i ) );
- }
- return l;
- }
- int getNewId( const QWidget* w, const QValueList<int>& l, bool retId = true )
- {
- const QMenuData* md = 0;
- if ( w->inherits( "QMenuBar" ) )
- md = ::qt_cast<QMenuBar*>( w );
- else if ( w->inherits( "QPopupMenu" ) )
- md = ::qt_cast<QPopupMenu*>( w );
- if ( md )
- {
- for ( uint i = 0, j = 0; i < md->count() && j < l.count(); i++, j++ )
- if ( md->idAt( i ) != l[ j ] )
- return retId ? md->idAt( i ) : i;
- if ( md->count() > l.count() )
- return retId ? md->idAt( md->count()-1 ) : md->count() - 1;
- }
- return -1;
- }
-
- void dumpMenu( QWidget* w, bool before )
- {
- if ( !w )
- return;
-
- QMenuData* md = 0;
- if ( w->inherits( "QMenuBar" ) )
- md = ::qt_cast<QMenuBar*>( w );
- else if ( w->inherits( "QPopupMenu" ) )
- md = ::qt_cast<QPopupMenu*>( w );
-
- if ( !md )
- return;
-
- printf( ">>> start dump menu (%s) >>>\n", before ? "before" : "after" );
- for ( uint i = 0; i < md->count(); i++ )
- printf( "%d: %d: %s\n", i, md->idAt( i ), md->text( md->idAt( i ) ).latin1() );
- printf( "<<< end dump menu (%s) <<<\n", before ? "before" : "after" );
- }
-};
/*!
- Class: QtxActionMenuMgr::MenuAction
- Level: Internal
+ \class QtxActionMenuMgr::MenuNode
+ \internal
+ \brief Represents a menu item inside main menu structure.
*/
-class QtxActionMenuMgr::MenuAction : public QtxAction
-{
+class QtxActionMenuMgr::MenuNode {
public:
- MenuAction( const QString&, const QString&, QObject*, const int = -1, const bool = false );
- virtual ~MenuAction();
-
- virtual bool addTo( QWidget* );
-
- virtual bool removeFrom( QWidget* );
-
- QPopupMenu* popup() const;
-
-private:
- int myId;
- QPopupMenu* myPopup;
- bool myEmptyEnabled;
- QMap<QWidget*,int> myIds;
+ MenuNode();
+ MenuNode( MenuNode*, const int, const int, const int );
+ ~MenuNode();
+
+ MenuNode* parent; //!< parent menu node
+ int id; //!< menu nodeID
+ int idx; //!< menu node index
+ int group; //!< menu group ID
+ bool visible; //!< visibility status
+ NodeList children; //!< children menu nodes list
};
-
/*!
- Constructor for menu action
- \param text - description text
- \param menutext - menu text
- \param parent - parent object
- \param id - integer identificator of action
- \param allowEmpty - if it is true, it makes possible to add this action with empty popup to menu
+ \brief Default constructor.
*/
-
-QtxActionMenuMgr::MenuAction::MenuAction( const QString& text,
- const QString& menuText,
- QObject* parent,
- const int id,
- const bool allowEmpty )
-: QtxAction( text, menuText, 0, parent ),
- myId( id ),
- myPopup( 0 ),
- myEmptyEnabled( allowEmpty )
+QtxActionMenuMgr::MenuNode::MenuNode()
+: parent( 0 ), id( -1 ), idx( -1 ), group( -1 ), visible( true )
{
- myPopup = new QPopupMenu();
}
/*!
- Destructor: deletes internal popup
+ \brief Constructor.
+ \param p parent menu node
+ \param _id menu node ID
+ \param _idx menu node index
+ \param _group menu node group ID
*/
-QtxActionMenuMgr::MenuAction::~MenuAction()
+QtxActionMenuMgr::MenuNode::MenuNode( MenuNode* p,
+ const int _id,
+ const int _idx,
+ const int _group )
+: parent( p ), id( _id ), idx( _idx ), group( _group ), visible( true )
{
- delete myPopup;
+ if ( p )
+ p->children.append( this );
}
/*!
- Adds action to widget, for example, to popup menu or menu bar
+ \brief Destructor.
*/
-bool QtxActionMenuMgr::MenuAction::addTo( QWidget* w )
+QtxActionMenuMgr::MenuNode::~MenuNode()
{
- if ( !w )
- return false; // bad widget
-
- if ( !w->inherits( "QPopupMenu" ) && !w->inherits( "QMenuBar" ) )
- return false; // not allowed widget type
-
- if ( myIds.find( w ) != myIds.end() )
- return false; // already added
-
- if ( !myPopup )
- return false; // bad own popup menu
-
- if ( !myEmptyEnabled && !myPopup->count() )
- return false; // not allowed empty menu
-
- if ( w->inherits( "QPopupMenu" ) ) {
- QValueList<int> l = prepareIds( w );
- int idx;
- if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) {
- QPopupMenu* pm = (QPopupMenu*)w;
- myIds[ w ] = pm->idAt( idx );
- if ( myId != -1 )
- pm->setId( idx, myId );
- setPopup( pm, myId != -1 ? myId : myIds[ w ], myPopup );
- }
- }
- else if ( w->inherits( "QMenuBar" ) ) {
- QValueList<int> l = prepareIds( w );
- int idx;
- if ( QtxAction::addTo( w ) && ( idx = getNewId( w, l, false ) ) != -1 ) {
- QMenuBar* mb = (QMenuBar*)w;
- myIds[ w ] = mb->idAt( idx );
- if ( myId != -1 )
- mb->setId( idx, myId );
- setPopup( mb, myId != -1 ? myId : myIds[ w ], myPopup );
- }
- }
- else
- return false;
-
- return true;
+ for ( NodeList::iterator it = children.begin(); it != children.end(); ++it )
+ delete *it;
}
/*!
- Removes action from widget, for example, from popup menu or menu bar
-*/
-bool QtxActionMenuMgr::MenuAction::removeFrom( QWidget* w )
-{
- if ( !w )
- return false; // bad widget
+ \class QtxActionMenuMgr
+ \brief Main menu actions manager.
- if ( !w->inherits( "QPopupMenu" ) && !w->inherits( "QMenuBar" ) )
- return false; // not allowed widget type
+ Menu manager allows using of set of action for automatic generating of
+ application main menu and dynamic update of its contents.
- if ( myIds.find( w ) == myIds.end() )
- return false; // not yet added
+ Use insert(), append() and remove() methods to create main menu.
+ Methods show(), hide() allow displaying/erasing of specified menu items.
- if ( w->inherits( "QPopupMenu" ) ) {
- if ( myId != -1 ) {
- QPopupMenu* pm = (QPopupMenu*)w;
- int idx = pm->indexOf( myId );
- if ( idx != -1 ) pm->setId( idx, myIds[ w ] );
- }
- myIds.remove( w );
- return QtxAction::removeFrom( w );;
- }
- else if ( w->inherits( "QMenuBar" ) )
- {
- if ( myId != -1 ) {
- QMenuBar* mb = (QMenuBar*)w;
- int idx = mb->indexOf( myId );
- if ( idx != -1 ) mb->setId( idx, myIds[ w ] );
- }
- myIds.remove( w );
- return QtxAction::removeFrom( w );
- }
- return false;
-}
+ Actions can be grouped with help of group identificator. Inside the popup
+ or main menu bar menu items are ordered by the group ID (ascending).
-/*!
- \return internal popup of action
+ Menu manager automatically optimizes the menu by removing extra separators,
+ hiding empty popup menus etc.
*/
-QPopupMenu* QtxActionMenuMgr::MenuAction::popup() const
-{
- return myPopup;
-}
/*!
- Class: QtxActionMenuMgr
- Level: Public
+ \brief Constructor.
+ \param p parent main window
*/
QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p )
-: QtxActionMgr( p ),
+: QtxActionMgr( p ),
+ myRoot( new MenuNode() ),
myMenu( p ? p->menuBar() : 0 )
{
- myRoot.id = -1;
- myRoot.group = -1;
-
if ( myMenu ) {
connect( myMenu, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
#ifdef ENABLE_DYNAMIC_MENU
}
/*!
- Constructor
+ \brief Constructor.
+ \param mw menu widget
+ \param p parent object
*/
QtxActionMenuMgr::QtxActionMenuMgr( QWidget* mw, QObject* p )
-: QtxActionMgr( p ),
+: QtxActionMgr( p ),
+ myRoot( new MenuNode() ),
myMenu( mw )
{
- myRoot.id = -1;
- myRoot.group = -1;
-
- if ( myMenu )
+ if ( myMenu ) {
connect( myMenu, SIGNAL( destroyed( QObject* ) ), this, SLOT( onDestroyed( QObject* ) ) );
+#ifdef ENABLE_DYNAMIC_MENU
+ if ( myMenu->inherits( "QMenuBar" ) )
+ connect( myMenu, SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) );
+#endif
+ }
}
/*!
- Destructor
+ \brief Destructor.
*/
QtxActionMenuMgr::~QtxActionMenuMgr()
{
- for ( NodeListIterator it( myRoot.children ); it.current() && myMenu; ++it )
+ for ( NodeList::iterator it = myRoot->children.begin(); it != myRoot->children.end() && myMenu; ++it )
{
- QAction* a = itemAction( it.current()->id );
+ QAction* a = itemAction( (*it)->id );
if ( !a )
- a = menuAction( it.current()->id );
+ a = menuAction( (*it)->id );
- if ( a )
- a->removeFrom( myMenu );
+// if ( a )
+// a->removeFrom( myMenu );
}
for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr )
- delete itr.data();
+ delete itr.value();
+
+ delete myRoot;
}
/*!
- \return whether menu item corresponding to action is visible
- \param actId - identificator of action
- \param place - identificator of some parent action
+ \brief Check if an action with given ID \a actId is visible to
+ the parent action with given ID \a place.
+ \param actId action ID
+ \param place some parent action ID
+ \return \c true if an action is visible
*/
bool QtxActionMenuMgr::isVisible( const int actId, const int place ) const
{
}
/*!
- Sets visible state of action
- \param actId - identificator of action
- \param place - identificator of some parent action
- \param v - visibility state
+ \brief Set action visibility flag.
+ \param actId action ID
+ \param place some parent action ID
+ \param on visibility state
*/
void QtxActionMenuMgr::setVisible( const int actId, const int place, const bool v )
{
}
/*!
- Insert action as children menu item
- \param id - identificator of action
- \param menus - few names of parent menu items, separated by '|'. It means sequence of menu items,
- for example "File|Edit" means File->Edit submenu. If submenu doesn't exist, it will be created.
- \param group - group identificator
- \param idx - index inside Qt menu
+ \brief Insert action to the menu.
+
+ Insert an action to the named menu. The \a menus parameter represents
+ the menu name: it is a sequence of strings, separated by '|' symbol.
+ For example, "File|Edit" means File->Edit submenu.
+ If submenu doesn't exist, it will be created.
+
+ \param id action ID
+ \param menus menu name
+ \param group group ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
int QtxActionMenuMgr::insert( const int id, const QString& menus, const int group, const int idx )
{
- return insert( id, QStringList::split( "|", menus ), group, idx );
+ return insert( id, menus.split( "|", QString::SkipEmptyParts ), group, idx );
}
/*!
- Insert action as children menu item
- \param a - action
- \param menus - few names of parent menu items, separated by '|'. It means sequence of menu items,
- for example "File|Edit" means File->Edit submenu. If submenu doesn't exist, it will be created.
- \param group - group identificator
- \param idx - index inside Qt menu
+ \brief Insert action to the menu.
+
+ Insert an action to the named menu. The \a menus parameter represents
+ the menu name: it is a sequence of strings, separated by '|' symbol.
+ For example, "File|Edit" means File->Edit submenu.
+ If submenu doesn't exist, it will be created.
+
+ \param a action
+ \param menus menu name
+ \param group group ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
int QtxActionMenuMgr::insert( QAction* a, const QString& menus, const int group, const int idx )
{
- return insert( a, QStringList::split( "|", menus ), group, idx );
+ return insert( a, menus.split( "|", QString::SkipEmptyParts ), group, idx );
}
/*!
- Insert action as children menu item
- \param id - identificator of action
- \param menus - list of names of parent menu items, separated by |. It means sequence of menu items,
- for example "File|Edit" means File->Edit submenu. If submenu doesn't exist, it will be created.
- \param group - group identificator
- \param idx - index inside Qt menu
+ \brief Insert action to the menu.
+
+ Insert an action to the named menu. The \a menus parameter represents
+ the menu names list.
+ For example, string list consisting from two items "File" and "Edit"
+ means File->Edit submenu.
+ If submenu doesn't exist, it will be created.
+
+ \param id action ID
+ \param menus menu names list
+ \param group group ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
int QtxActionMenuMgr::insert( const int id, const QStringList& menus, const int group, const int idx )
{
}
/*!
- Insert action as children menu item
- \param a - action
- \param menus - list of names of parent menu items. It means sequence of menu items,
- for example "File|Edit" means File->Edit submenu. If submenu doesn't exist, it will be created.
- \param group - group identificator
- \param idx - index inside Qt menu
+ \brief Insert action to the menu.
+
+ Insert an action to the named menu. The \a menus parameter represents
+ the menu names list.
+ For example, string list consisting from two items "File" and "Edit"
+ means File->Edit submenu.
+ If submenu doesn't exist, it will be created.
+
+ \param a action
+ \param menus menu names list
+ \param group group ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
int QtxActionMenuMgr::insert( QAction* a, const QStringList& menus, const int group, const int idx )
{
}
/*!
- Insert action as children menu item
- \param id - identificator of action
- \param pId - identificator of action corresponding to parent menu item
- \param group - group identificator
- \param idx - index inside Qt menu
+ \brief Insert action to the menu.
+ \param id action ID
+ \param pId parent menu action ID
+ \param group group ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
int QtxActionMenuMgr::insert( const int id, const int pId, const int group, const int idx )
{
if ( id == -1 )
return -1;
- MenuNode* pNode = pId == -1 ? &myRoot : find( pId );
+ MenuNode* pNode = pId == -1 ? myRoot : find( pId );
if ( !pNode )
return -1;
- MenuNode* node = new MenuNode( pNode );
- node->id = id;
- node->idx = idx;
- node->group = group;
-
- pNode->children.append( node );
+ MenuNode* node = new MenuNode( pNode, id, idx, group );
- updateMenu( pNode, false );
+ triggerUpdate( pNode->id, false );
return node->id;
}
/*!
- Insert action as children menu item
- \param a - action
- \param pId - identificator of action corresponding to parent menu item
- \param group - group identificator
- \param idx - index inside Qt menu
+ \brief Insert action to the menu.
+ \param a action
+ \param pId parent menu action ID
+ \param group group ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
int QtxActionMenuMgr::insert( QAction* a, const int pId, const int group, const int idx )
{
}
/*!
- Create and insert action as children menu item
- \return identificator of inserted action
- \param title - menu text of action
- \param pId - identificator of action corresponding to parent menu item
- \param group - group identificator
- \param id - identificator of new action
- \param idx - index inside Qt menu
- \param allowEmpty - indicates, that it is possible to add this action with empty popup menu to other menu
+ \brief Create and insert menu item action to the menu.
+ \param title menu text
+ \param pId parent menu action ID
+ \param group group ID
+ \param id action ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
-int QtxActionMenuMgr::insert( const QString& title, const int pId, const int group, const int id, const int idx, const bool allowEmpty )
+int QtxActionMenuMgr::insert( const QString& title, const int pId, const int group, const int id, const int idx )
{
- MenuNode* pNode = pId == -1 ? &myRoot : find( pId );
+ MenuNode* pNode = pId == -1 ? myRoot : find( pId );
if ( !pNode )
return -1;
MenuNode* eNode = id == -1 ? 0 : find( id );
int fid = -1;
- for ( NodeListIterator it( pNode->children ); it.current() && fid == -1; ++it )
+ for ( NodeList::iterator it = pNode->children.begin(); it != pNode->children.end() && fid == -1; ++it )
{
- if ( myMenus.contains( it.current()->id ) &&
- clearTitle( myMenus[it.current()->id]->menuText() ) == clearTitle( title ) )
- fid = it.current()->id;
+ if ( myMenus.contains( (*it)->id ) &&
+ clearTitle( myMenus[(*it)->id]->text() ) == clearTitle( title ) )
+ fid = (*it)->id;
}
if ( fid != -1 )
int gid = (id == -1 || eNode ) ? generateId() : id;
- MenuAction* ma = new MenuAction( clearTitle( title ), title, this, gid, allowEmpty );
+ QAction* ma = new QAction( title, this );
+ ma->setMenu( new QMenu( myMenu ) );
+
+ connect( ma->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) );
+ connect( ma->menu(), SIGNAL( aboutToHide() ), this, SLOT( onAboutToHide() ) );
#ifdef ENABLE_DYNAMIC_MENU
- connect( ma->popup(), SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) );
+ connect( ma->menu(), SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) );
#endif
- MenuNode* node = new MenuNode( pNode );
- node->group = group;
- node->idx = idx;
- node->id = myMenus.insert( gid, ma ).key();
-
- pNode->children.append( node );
+ MenuNode* node = new MenuNode( pNode, myMenus.insert( gid, ma ).key(), idx, group );
- updateMenu( pNode, false );
+ triggerUpdate( pNode->id, false );
return node->id;
}
/*!
- Create and insert action as children menu item
- \return identificator of inserted action
- \param title - menu text of action
- \param menus - string list of parents' menu texts, separated by |
- \param group - group identificator
- \param id - identificator of new action
- \param idx - index inside Qt menu
- \param allowEmpty - indicates, that it is possible to add this action with empty popup menu to other menu
+ \brief Create and insert menu item action to the menu.
+
+ Insert an action to the named menu. The \a menus parameter represents
+ the menu name: it is a sequence of strings, separated by '|' symbol.
+ For example, "File|Edit" means File->Edit submenu.
+ If submenu doesn't exist, it will be created.
+
+ \param title menu text
+ \param menus menu name
+ \param group group ID
+ \param id action ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
-int QtxActionMenuMgr::insert( const QString& title, const QString& menus, const int group, const int id, const int idx, const bool allowEmpty )
+int QtxActionMenuMgr::insert( const QString& title, const QString& menus, const int group, const int id, const int idx )
{
- return insert( title, QStringList::split( "|", menus ), group, id, idx, allowEmpty );
+ return insert( title, menus.split( "|", QString::SkipEmptyParts ), group, id, idx );
}
/*!
- Create and insert action as children menu item
- \return identificator of inserted action
- \param title - menu text of action
- \param menus - list of parents menu items
- \param group - group identificator
- \param id - identificator of new action
- \param idx - index inside Qt menu
- \param allowEmpty - indicates, that it is possible to add this action with empty popup menu to other menu
+ \brief Create and insert menu item action to the menu.
+
+ Insert an action to the named menu. The \a menus parameter represents
+ the menu names list.
+ For example, string list consisting from two items "File" and "Edit"
+ means File->Edit submenu.
+ If submenu doesn't exist, it will be created.
+
+ \param title menu text
+ \param menus menu names list
+ \param group group ID
+ \param id action ID
+ \param idx menu index inside the menu group
+ \return action ID
*/
-int QtxActionMenuMgr::insert( const QString& title, const QStringList& menus, const int group, const int id, const int idx, const bool allowEmpty )
+int QtxActionMenuMgr::insert( const QString& title, const QStringList& menus, const int group, const int id, const int idx )
{
int pId = createMenu( menus, -1 );
- return insert( title, pId, group, id, idx, allowEmpty );
+ return insert( title, pId, group, id, idx );
}
/*!
- Create and append action as last children
- \return identificator of inserted action
- \param title - menu text of action
- \param pId - id of action corresponding to parent menu item
- \param group - group identificator
- \param id - identificator of new action
- \param allowEmpty - indicates, that it is possible to add this action with empty popup menu to other menu
+ \brief Create and add menu item action to the end of menu.
+ \param title menu text
+ \param pId parent menu action ID
+ \param group group ID
+ \param id action ID
+ \return action ID
*/
-int QtxActionMenuMgr::append( const QString& title, const int pId, const int group, const int id, const bool allowEmpty )
+int QtxActionMenuMgr::append( const QString& title, const int pId, const int group, const int id )
{
- return insert( title, pId, group, id, allowEmpty );
+ return insert( title, pId, group, id );
}
/*!
- Create and append action as last children
- \return identificator of inserted action
- \param id - identificator of existing action
- \param pId - id of action corresponding to parent menu item
- \param group - group identificator
+ \brief Create and add menu item action to the end of menu.
+ \param id action ID
+ \param pId parent menu action ID
+ \param group group ID
+ \return action ID
*/
int QtxActionMenuMgr::append( const int id, const int pId, const int group )
{
}
/*!
- Create and append action as last children
- \return identificator of inserted action
- \param a - action
- \param pId - id of action corresponding to parent menu item
- \param group - group identificator
+ \brief Create and add menu item action to the end of menu.
+ \param a action
+ \param pId parent menu action ID
+ \param group group ID
+ \return action ID
*/
int QtxActionMenuMgr::append( QAction* a, const int pId, const int group )
{
}
/*!
- Create and insert action as first children
- \return identificator of inserted action
- \param title - menu text of action
- \param pId - id of action corresponding to parent menu item
- \param group - group identificator
- \param id - identificator of new action
- \param allowEmpty - indicates, that it is possible to add this action with empty popup menu to other menu
+ \brief Create and add menu item action to the beginning of menu.
+ \param title menu text
+ \param pId parent menu action ID
+ \param group group ID
+ \param id action ID
+ \return action ID
*/
-int QtxActionMenuMgr::prepend( const QString& title, const int pId, const int group, const int id, const bool allowEmpty )
+int QtxActionMenuMgr::prepend( const QString& title, const int pId, const int group, const int id )
{
- return insert( title, pId, group, id, 0, allowEmpty );
+ return insert( title, pId, group, id, 0 );
}
/*!
- Create and insert action as last children
- \return identificator of inserted action
- \param id - identificator of existing action
- \param pId - id of action corresponding to parent menu item
- \param group - group identificator
+ \brief Create and add menu item action to the beginning of menu.
+ \param id action ID
+ \param pId parent menu action ID
+ \param group group ID
+ \return action ID
*/
int QtxActionMenuMgr::prepend( const int id, const int pId, const int group )
{
}
/*!
- Create and insert action as last children
- \return identificator of inserted action
- \param a - action
- \param pId - id of action corresponding to parent menu item
- \param group - group identificator
+ \brief Create and add menu item action to the beginning of menu.
+ \param a action
+ \param pId parent menu action ID
+ \param group group ID
+ \return action ID
*/
int QtxActionMenuMgr::prepend( QAction* a, const int pId, const int group )
{
}
/*!
- Removes menu item corresponding to action
- \param id - identificator of action
+ \brief Remove menu item with given \a id.
+ \param id menu action ID
*/
void QtxActionMenuMgr::remove( const int id )
{
}
/*!
- Removes menu item
- \param id - identificator of action
- \param pId - identificator of action corresponding to parent menu item
- \param group - group identificator
+ \brief Remove menu item with given \a id.
+ \param id menu action ID
+ \param pId parent menu action ID
+ \param group group ID
*/
void QtxActionMenuMgr::remove( const int id, const int pId, const int group )
{
- MenuNode* pNode = pId == -1 ? &myRoot : find( pId );
+ MenuNode* pNode = pId == -1 ? myRoot : find( pId );
if ( !pNode )
return;
NodeList delNodes;
- for ( NodeListIterator it( pNode->children ); it.current(); ++it )
+ for ( NodeList::iterator it = pNode->children.begin(); it != pNode->children.end(); ++it )
{
- if ( it.current()->id == id && ( it.current()->group == group || group == -1 ) )
- delNodes.append( it.current() );
+ if ( (*it)->id == id && ( (*it)->group == group || group == -1 ) )
+ delNodes.append( *it );
}
- for ( NodeListIterator itr( delNodes ); itr.current(); ++itr )
- pNode->children.remove( itr.current() );
+ for ( NodeList::iterator itr = delNodes.begin(); itr != delNodes.end(); ++itr )
+ pNode->children.removeAll( *itr );
- updateMenu( pNode, false );
+ triggerUpdate( pNode->id, false );
}
/*!
- Shows menu item corresponding to action
- \param id - identificator of action
+ \brief Show menu item with given \a id.
+ \param id menu action ID
*/
void QtxActionMenuMgr::show( const int id )
{
}
/*!
- Hides menu item corresponding to action
- \param id - identificator of action
+ \brief Hide menu item with given \a id.
+ \param id menu action ID
*/
void QtxActionMenuMgr::hide( const int id )
{
}
/*!
- \return shown status of menu item corresponding to action
- \param id - identificator of action
+ \brief Get visibility status for menu item with given \a id.
+ \param id menu action ID
+ \return \c true if an item is shown
*/
bool QtxActionMenuMgr::isShown( const int id ) const
{
}
/*!
- Sets shown status of menu item corresponding to action
- \param id - identificator of action
- \param on - new shown status
+ \brief Set visibility status for menu item with given \a id.
+ \param id menu action ID
+ \param on new visibility status
*/
void QtxActionMenuMgr::setShown( const int id, const bool on )
{
NodeList aNodes;
find( id, aNodes );
- QMap<MenuNode*, int> updMap;
- for ( NodeListIterator it( aNodes ); it.current(); ++it )
+ for ( NodeList::iterator it = aNodes.begin(); it != aNodes.end(); ++it )
{
- if ( it.current()->visible != on )
+ if ( (*it)->visible != on )
{
- it.current()->visible = on;
- updMap.insert( it.current()->parent, 0 );
+ (*it)->visible = on;
+ triggerUpdate( (*it)->parent ? (*it)->parent->id : myRoot->id, false );
}
}
+}
+
+/*!
+ \brief Change menu title fot the action with given \a id.
+ \param id menu action ID
+ \param title new menu title
+*/
+void QtxActionMenuMgr::change( const int id, const QString& title )
+{
+ QAction* a = menuAction( id );
+ if ( a )
+ a->setText( title );
+}
- for ( QMap<MenuNode*, int>::ConstIterator itr = updMap.begin(); itr != updMap.end(); ++itr )
- updateMenu( itr.key(), false );
+/*!
+ \brief Called when the submenu is about to show.
+
+ Emits the signal menuAboutToShow(QMenu*).
+*/
+void QtxActionMenuMgr::onAboutToShow()
+{
+ QMenu* m = ::qobject_cast<QMenu*>( sender() );
+ if ( m )
+ emit menuAboutToShow( m );
}
/*!
- SLOT: called when corresponding menu is destroyed, clears internal pointer to menu
+ \brief Called when the submenu is about to hide.
+
+ Emits the signal menuAboutToHide(QMenu*).
+*/
+void QtxActionMenuMgr::onAboutToHide()
+{
+ QMenu* m = ::qobject_cast<QMenu*>( sender() );
+ if ( m )
+ emit menuAboutToHide( m );
+}
+
+/*!
+ \brief Called when the corresponding menu object is destroyed.
+
+ Clears internal pointer to menu to disable crashes.
+
+ \param obj (menu) object being destroyed
*/
void QtxActionMenuMgr::onDestroyed( QObject* obj )
{
}
/*!
- SLOT: called when menu item is highlighted
+ \brief Called when menu item is highlighted.
+ \param id menu item being highlighted ID
*/
void QtxActionMenuMgr::onHighlighted( int id )
{
int pid = 0, realId;
if ( myMenu && snd == myMenu )
pid = -1;
- else {
- for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr ) {
- if ( itr.data()->popup() && itr.data()->popup() == snd )
- pid = itr.key();
+ else
+ {
+ for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr )
+ {
+ if ( itr.value()->menu() && itr.value()->menu() == snd )
+ pid = itr.key();
}
}
- if ( pid ) {
+ if ( pid )
+ {
realId = findId( id, pid );
- if ( realId != -1 ) {
- bool updatesEnabled = isUpdatesEnabled();
- setUpdatesEnabled( false );
+ if ( realId != -1 )
+ {
emit menuHighlighted( pid, realId );
- setUpdatesEnabled( updatesEnabled );
- updateMenu( find( realId ) );
+ triggerUpdate( realId );
}
}
}
/*!
- Assignes new menu with manager
- \param mw - new menu
+ \brief Assign new menu widget to the menu manager.
+ \param mw new menu widget
*/
void QtxActionMenuMgr::setWidget( QWidget* mw )
{
}
/*!
- \return menu node by it's place description
- \param actId - identificator of action
- \param pId - identificator of action corresponding to start menu item
- \param rec - recursive search
+ \brief Search menu node.
+ \param id menu action ID
+ \param pId parent menu item ID
+ \param rec if \c true perform recursive search
+ \return menu node or 0 if not found
*/
-QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int actId, const int pId, const bool rec ) const
+QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int id, const int pId, const bool rec ) const
{
- return find( actId, find( pId ), rec );
+ return find( id, find( pId ), rec );
}
/*!
- \return menu node by it's place description
- \param actId - identificator of action
- \param startNode - start menu item
- \param rec - recursive search
+ \brief Search menu node.
+ \param id menu action ID
+ \param startNode start menu node (if 0, search from root node)
+ \param rec if \c true perform recursive search
+ \return menu node or 0 if not found
*/
QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const int id, MenuNode* startNode, const bool rec ) const
{
MenuNode* node = 0;
- MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
- for ( NodeListIterator it( start->children ); it.current() && !node; ++it )
+ MenuNode* start = startNode ? startNode : myRoot;
+ for ( NodeList::iterator it = start->children.begin(); it != start->children.end() && !node; ++it )
{
- if ( it.current()->id == id )
- node = it.current();
+ if ( (*it)->id == id )
+ node = *it;
else if ( rec )
- node = find( id, it.current(), rec );
+ node = find( id, *it, rec );
}
return node;
}
/*!
- Finds menu node
- \return true if at least one node is found
- \param id - identificator of action
- \param lst - list to be filled with found nodes
- \param startNode - start menu item
+ \brief Search recursively all menu nodes with given \a id.
+ \param id menu action ID
+ \param NodeList resulting list of menu nodes
+ \param startNode start menu node (if 0, search from root node)
+ \return \c true if at least one node is found
*/
bool QtxActionMenuMgr::find( const int id, NodeList& lst, MenuNode* startNode ) const
{
- MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
- for ( NodeListIterator it( start->children ); it.current(); ++it )
+ MenuNode* start = startNode ? startNode : myRoot;
+ for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it )
{
- if ( it.current()->id == id )
- lst.prepend( it.current() );
+ MenuNode* node = *it;
+ if ( node->id == id )
+ lst.prepend( node );
- find( id, lst, it.current() );
+ find( id, lst, node );
}
return !lst.isEmpty();
}
/*!
- Finds menu node
- \return menu node
- \param title - menu text of searched node
- \param pId - id of action corresponding to start menu item
- \param rec - recursive searching
+ \brief Search menu node.
+ \param title menu item title
+ \param pId parent menu item ID
+ \param rec if \c true perform recursive search
+ \return menu node or 0 if not found
*/
QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, const int pId, const bool rec ) const
{
}
/*!
- Finds menu node
- \return true if at least one node is found
- \param title - menu text of node
- \param lst - list to be filled with found nodes
- \param startNode - start menu item
+ \brief Search recursively all menu nodes with given \a title.
+ \param title menu item title
+ \param NodeList resulting list of menu nodes
+ \param startNode start menu node (if 0, search from root node)
+ \return \c true if at least one node is found
*/
bool QtxActionMenuMgr::find( const QString& title, NodeList& lst, MenuNode* startNode ) const
{
- MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
- for ( NodeListIterator it( start->children ); it.current(); ++it )
+ MenuNode* start = startNode ? startNode : myRoot;
+ for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it )
{
- QAction* a = itemAction( it.current()->id );
+ QAction* a = itemAction( (*it)->id );
if ( !a )
- a = menuAction( it.current()->id );
- if ( a && clearTitle( a->menuText() ) == clearTitle( title ) )
- lst.prepend( it.current() );
+ a = menuAction( (*it)->id );
+ if ( a && clearTitle( a->text() ) == clearTitle( title ) )
+ lst.prepend( *it );
- find( title, lst, it.current() );
+ find( title, lst, *it );
}
return !lst.isEmpty();
}
/*!
- Finds menu node
- \return menu node
- \param title - menu text of searched node
- \param startNode - start menu item
- \param rec - recursive searching
+ \brief Search menu node.
+ \param title menu item title
+ \param startNode start menu node (if 0, search from root node)
+ \param rec if \c true perform recursive search
+ \return menu node or 0 if not found
*/
QtxActionMenuMgr::MenuNode* QtxActionMenuMgr::find( const QString& title, MenuNode* startNode, const bool rec ) const
{
MenuNode* node = 0;
- MenuNode* start = startNode ? startNode : (MenuNode*)&myRoot;
- for ( NodeListIterator it( start->children ); it.current() && !node; ++it )
+ MenuNode* start = startNode ? startNode : myRoot;
+ for ( NodeList::iterator it = start->children.begin(); it != start->children.end() && !node; ++it )
{
- QAction* a = itemAction( it.current()->id );
+ QAction* a = itemAction( (*it)->id );
if ( !a )
- a = menuAction( it.current()->id );
- if ( a && clearTitle( a->menuText() ) == clearTitle( title ) )
- node = it.current();
+ a = menuAction( (*it)->id );
+ if ( a && clearTitle( a->text() ) == clearTitle( title ) )
+ node = *it;
if ( !node && rec )
- node = find( title, it.current(), rec );
+ node = find( title, *it, rec );
}
return node;
}
/*!
- Find id among children
- \return id (>0) if on success or -1 on fail
- \param id - id to be searched
- \param pid - id of parent, among children of that 'id' must be searched
+ \brief Find menu item by given ID (one-level only).
+ \param id menu action ID
+ \param pid parent meun item ID
+ \return id (>0) on success or -1 if menu item is not found
*/
int QtxActionMenuMgr::findId( const int id, const int pid ) const
{
- MenuNode* start = pid != -1 ? find( pid ) : (MenuNode*)&myRoot;
- if ( start ) {
- for ( NodeListIterator it( start->children ); it.current(); ++it ) {
- if ( it.current()->id == id ) return id;
+ MenuNode* start = pid != -1 ? find( pid ) : myRoot;
+ if ( start )
+ {
+ for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it )
+ {
+ if ( (*it)->id == id )
+ return id;
}
}
return -1;
}
/*!
- Removes child
- \param id - id of child to be removed
- \param startNode - parent menu item
+ \brief Removes menu node (with all its children).
+ \param id menu action ID
+ \param startNode parent menu node which search starts from (if 0, search starts from root)
*/
void QtxActionMenuMgr::removeMenu( const int id, MenuNode* startNode )
{
- MenuNode* start = startNode ? startNode : &myRoot;
- for ( NodeListIterator it( start->children ); it.current(); ++it )
+ MenuNode* start = startNode ? startNode : myRoot;
+ for ( NodeList::iterator it = start->children.begin(); it != start->children.end(); ++it )
{
- if ( it.current()->id == id )
- start->children.remove( it.current() );
+ if ( (*it)->id == id )
+ start->children.removeAll( *it );
else
- removeMenu( id, it.current() );
+ removeMenu( id, *it );
}
}
/*!
- \return menu item action by id
- \param id - id of action
+ \brief Get action by \a id.
+ \param id action ID
+ \return action or 0 if not found
*/
QAction* QtxActionMenuMgr::itemAction( const int id ) const
{
}
/*!
- \return menu action by id
- \param id - id of action
+ \brief Get submenu action by \a id.
+ \param id submenu ID
+ \return submenu action or 0 if not found
*/
-QtxActionMenuMgr::MenuAction* QtxActionMenuMgr::menuAction( const int id ) const
+QAction* QtxActionMenuMgr::menuAction( const int id ) const
{
- MenuAction* a = 0;
+ QAction* a = 0;
if ( myMenus.contains( id ) )
a = myMenus[id];
}
/*!
- Updates menu ( isUpdatesEnabled() must return true )
- \param startNode - first menu item to be updated
- \param rec - recursive update
- \param updParent - update also parent item (without recursion)
- \sa isUpdatesEnabled()
+ \brief Update menu.
+
+ Does nothing if update is disabled.
+
+ \param startNode start menu item to be updated
+ \param rec if \c true, perform recursive update
+ \param updParent if \c true update also parent item (without recursion)
+
+ \sa isUpdatesEnabled() and setUpdatesEnabled()
*/
void QtxActionMenuMgr::updateMenu( MenuNode* startNode, const bool rec, const bool updParent )
{
if ( !isUpdatesEnabled() )
return;
- MenuNode* node = startNode ? startNode : &myRoot;
+ MenuNode* node = startNode ? startNode : myRoot;
QWidget* mw = menuWidget( node );
if ( !mw )
bool filled = checkWidget( mw );
- for ( NodeListIterator it1( node->children ); it1.current(); ++it1 )
+ for ( NodeList::iterator it1 = node->children.begin(); it1 != node->children.end(); ++it1 )
{
- QAction* a = itemAction( it1.current()->id );
+ QAction* a = itemAction( (*it1)->id );
if ( !a )
- a = menuAction( it1.current()->id );
+ a = menuAction( (*it1)->id );
- if ( a )
- a->removeFrom( mw );
+ mw->removeAction( a );
+// if ( a )
+// a->removeFrom( mw );
}
- /* VSR: commented to allow direct creating of menus by calling insertItem() methods
- if ( mw->inherits( "QMenuBar" ) )
- ((QMenuBar*)mw)->clear();
- else if ( mw->inherits( "QPopupMenu" ) )
- ((QPopupMenu*)mw)->clear();
- */
+
QMap<int, NodeList> idMap;
- for ( NodeListIterator it2( node->children ); it2.current(); ++it2 )
+ for ( NodeList::iterator it2 = node->children.begin(); it2 != node->children.end(); ++it2 )
{
- NodeList& lst = idMap[it2.current()->group];
- int idx = it2.current()->idx;
+ NodeList& lst = idMap[(*it2)->group];
+ int idx = (*it2)->idx;
if ( idx < 0 || idx >= (int)lst.count() )
- lst.append( it2.current() );
+ lst.append( *it2 );
else
- lst.insert( idx, it2.current() );
+ lst.insert( idx, *it2 );
}
QIntList groups = idMap.keys();
- qHeapSort( groups );
+ qSort( groups );
- groups.remove( -1 );
+ groups.removeAll( -1 );
groups.append( -1 );
for ( QIntList::const_iterator gIt = groups.begin(); gIt != groups.end(); ++gIt )
continue;
const NodeList& lst = idMap[*gIt];
- for ( NodeListIterator iter( lst ); iter.current(); ++iter )
+ for ( NodeList::const_iterator iter = lst.begin(); iter != lst.end(); ++iter )
{
- MenuNode* par = iter.current()->parent;
- if ( !isVisible( iter.current()->id, par ? par->id : -1 ) )
- continue;
+ MenuNode* node = *iter;
if ( rec )
- updateMenu( iter.current(), rec, false );
+ updateMenu( node, rec, false );
+
+ MenuNode* par = node->parent;
+ if ( !isVisible( node->id, par ? par->id : -1 ) )
+ continue;
- QAction* a = itemAction( iter.current()->id );
+ bool isMenu = false;
+ QAction* a = itemAction( node->id );
if ( !a )
- a = menuAction( iter.current()->id );
- if ( a )
- a->addTo( mw );
+ {
+ isMenu = true;
+ a = menuAction( node->id );
+ }
+
+ if ( !isMenu || !a->menu()->isEmpty() )
+ mw->addAction( a );
}
}
}
/*!
- Updates menu (virtual variant). To be redefined for custom activity on menu updating
+ \brief Internal update.
+
+ Customizes the menu update processing.
*/
void QtxActionMenuMgr::internalUpdate()
{
- if ( isUpdatesEnabled() )
- updateMenu();
+ if ( !isUpdatesEnabled() )
+ return;
+
+ updateMenu();
+ myUpdateIds.clear();
}
/*!
- \return true if widget is non-empty menu
- \param wid - widget to be checked
+ \brief Check if menu widget has any actions.
+ \param wid widget to be checked
+ \return \c true if widget contains action(s)
*/
bool QtxActionMenuMgr::checkWidget( QWidget* wid ) const
{
if ( !wid )
return false;
- QMenuData* md = 0;
- if ( wid->inherits( "QPopupMenu" ) )
- md = (QPopupMenu*)wid;
- else if ( wid->inherits( "QMenuBar" ) )
- md = (QMenuBar*)wid;
-
- return md ? md->count() : false;
+ return !wid->actions().isEmpty();
}
/*!
- \return popup of menu item
- \param node - menu item
+ \brief Get menu widget for the given \a node.
+ \param node menu node
+ \return popup menu or main menu corresponding to the menu node (or 0 if not found)
*/
QWidget* QtxActionMenuMgr::menuWidget( MenuNode* node) const
{
- if ( !node || node == &myRoot )
+ if ( !node || node == myRoot )
return myMenu;
if ( !myMenus.contains( node->id ) || !myMenus[node->id] )
return 0;
- return myMenus[node->id]->popup();
+ return myMenus[node->id]->menu();
}
/*!
- Removes excess separators of menu
- \param wid - menu to be processed
+ \brief Remove extra separators from menu widget.
+ \param wid menu widget to be processed
*/
void QtxActionMenuMgr::simplifySeparators( QWidget* wid )
{
- if ( wid && wid->inherits( "QPopupMenu" ) )
- Qtx::simplifySeparators( (QPopupMenu*)wid, false );
+ Qtx::simplifySeparators( wid, false );
}
/*!
- Removes special symbols (&) from string
- \param txt - string to be processed
- \return clear variant of string
+ \brief Remove special symbols (&) from string to get clear menu title.
+ \param txt string to be processed
+ \return clear title
*/
QString QtxActionMenuMgr::clearTitle( const QString& txt ) const
{
}
/*!
- Creates and inserts many menu items
- \param lst - list of menu texts
- \param pId - id of action corresponding to parent menu item
+ \brief Create and inserts menu item recursively.
+ \param lst list of menu names
+ \param pId parent menu item ID
+ \return created menu item ID (last in the chain)
*/
int QtxActionMenuMgr::createMenu( const QStringList& lst, const int pId )
{
QStringList sl( lst );
- QString title = sl.last().stripWhiteSpace();
- sl.remove( sl.fromLast() );
+ QString title = sl.last().trimmed();
+ sl.removeLast();
int parentId = sl.isEmpty() ? pId : createMenu( sl, pId );
}
/*!
- Loads actions description from file
- \param fname - name of file
- \param r - reader of file
- \return true on success
+ \brief Load actions description from the file.
+ \param fname file name
+ \param r action reader
+ \return \c true on success and \c false on error
*/
bool QtxActionMenuMgr::load( const QString& fname, QtxActionMgr::Reader& r )
{
}
/*!
- \return true if item has such child
- \param title - menu text of child
- \param pid - id of action corresponding to item
+ \brief Check if the parent menu contains menu item with given \a title.
+ \param title menu title
+ \param pid parent menu item ID
+ \return \c true if parent menu item contains such child item
*/
bool QtxActionMenuMgr::containsMenu( const QString& title, const int pid ) const
{
}
/*!
- \return true if item has such child
- \param id - id of action corresponding to child
- \param pid - id of action corresponding to item
+ \brief Check if the parent menu contains menu item with given \a id.
+ \param id menu item ID
+ \param pid parent menu item ID
+ \return \c true if parent menu item contains such child item
*/
bool QtxActionMenuMgr::containsMenu( const int id, const int pid ) const
{
return (bool)find( id, pid, false );
}
+/*!
+ \brief Perform delayed menu update.
+ \param id menu item ID
+ \param rec if \c true, perform recursive update
+*/
+void QtxActionMenuMgr::triggerUpdate( const int id, const bool rec )
+{
+ bool isRec = rec;
+ if ( myUpdateIds.contains( id ) )
+ isRec = isRec || myUpdateIds[ id ];
+ myUpdateIds.insert( id, isRec );
+
+ QtxActionMgr::triggerUpdate();
+}
+
+/*!
+ \brief Called when delayed content update is performed.
+
+ Customizes the content update operation.
+*/
+void QtxActionMenuMgr::updateContent()
+{
+ // Warning: For correct updating it is necessary to update the most enclosed submenu in first turn
+ // because not updated empty submenu will be skipped. Now the submenus are iterated in
+ // ascending order according to their identifiers. For a submenus with automatically generated
+ // identifiers this will work correctly since the uppermost submenus have the biggest number
+ // (identifiers are generated by decrementing 1 starting from -1). In general, if any submenu
+ // have positive identifiers this method might not work correctly. In this case it would be
+ // necessary to improve this method and to add preliminary sorting a submenus by depth of an
+ // enclosure.
+ for ( QMap<int, bool>::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it )
+ {
+ MenuNode* node = it.key() == -1 ? myRoot : find( it.key() );
+ if ( node )
+ updateMenu( node, it.value() );
+ }
+ myUpdateIds.clear();
+}
/*!
- Constructor
- \param r - menu reader
- \param mgr - menu manager
+ \class QtxActionMenuMgr::MenuCreator
+ \brief Menu actions creator.
+
+ Used by Reader to create actions by reading descriptions from the file
+ and fill in the action manager with the actions.
+*/
+
+/*!
+ \brief Constructor.
+ \param r menu actions reader
+ \param mgr menu manager
*/
-QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r,
- QtxActionMenuMgr* mgr )
+QtxActionMenuMgr::MenuCreator::MenuCreator( QtxActionMgr::Reader* r, QtxActionMenuMgr* mgr )
: QtxActionMgr::Creator( r ),
- myMgr( mgr )
+myMgr( mgr )
{
}
/*!
- Destructor
+ \brief Creator destructor.
+
+ Does nothing for the moment.
*/
QtxActionMenuMgr::MenuCreator::~MenuCreator()
{
}
/*!
- Appends new menu items
- \param tag - tag of item
- \param subMenu - it has submenu
- \param attr - list of attributes
- \param pId - id of action corresponding to parent item
+ \brief Create and append to the action manager a new action.
+ \param tag item tag name
+ \param subMenu \c true if this item is submenu
+ \param attr attributes map
+ \param pId parent action ID
+ \return menu action ID
*/
int QtxActionMenuMgr::MenuCreator::append( const QString& tag, const bool subMenu,
const ItemAttributes& attr, const int pId )
res = myMgr->insert( separator(), pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) );
else
{
- QPixmap pix; QIconSet set;
+ QIcon set;
+ QPixmap pix;
QString name = strValue( attr, icon );
if( !name.isEmpty() && loadPixmap( name, pix ) )
- set = QIconSet( pix );
+ set = QIcon( pix );
QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set,
- strValue( attr, label ),
+ strValue( attr, label ),
QKeySequence( strValue( attr, accel ) ),
myMgr );
newAct->setToolTip( strValue( attr, tooltip ) );
QString toggleact = strValue( attr, toggle );
- newAct->setToggleAction( !toggleact.isEmpty() );
- newAct->setOn( toggleact.lower()=="true" );
-
+ newAct->setCheckable( !toggleact.isEmpty() );
+ newAct->setChecked( toggleact.toLower() == "true" );
+
connect( newAct );
int aid = myMgr->registerAction( newAct, actId );
res = myMgr->insert( aid, pId, intValue( attr, group, 0 ), intValue( attr, pos, -1 ) );
#include "QtxAction.h"
#include "QtxToolBar.h"
-#include <qmainwindow.h>
-#include <qobjectlist.h>
+#include <QtGui/qmainwindow.h>
/*!
- Constructor
+ \class ToolNode
+ \internal
+ \brief Represents a toolbutton inside toolbar structure.
+*/
+
+/*!
+ \fn QtxActionToolMgr::ToolNode::ToolNode()
+ \brief Default constructor.
+*/
+
+/*!
+ \fn QtxActionToolMgr::ToolNode::ToolNode( const int _id )
+ \brief Constructor.
+ \param _id toolbar node ID
+*/
+
+
+/*!
+ \class QtxActionToolMgr
+ \brief Toolbar actions manager.
+
+ Toolbar manager allows using of set of action for automatic generating of
+ application toolbars and dynamic update of toolbars contents.
+
+ Use insert(), append() and remove() methods to create toolbar and add actions to it.
+ Methods show(), hide() allow displaying/erasing of specified toolbar items.
+
+ Toolbar manager automatically optimizes toolbars by removing extra separators, etc.
+*/
+
+/*!
+ \brief Constructor.
+ \param p parent main window
*/
QtxActionToolMgr::QtxActionToolMgr( QMainWindow* p )
: QtxActionMgr( p ),
-myMainWindow( p )
+ myMainWindow( p )
{
}
/*!
- Destructor
+ \brief Destructor.
*/
QtxActionToolMgr::~QtxActionToolMgr()
{
}
/*!
- \return desktop
+ \brief Get parent main window.
+ \return main window pointer
*/
QMainWindow* QtxActionToolMgr::mainWindow() const
{
}
/*!
- Creates toolbar
- \return id of just created toolbar
- \param name - name of toolbar
- \param tid - proposed id (if such id is used already, then it will be returned without creation)
+ \brief Create toolbar and assign \a id to it.
+
+ If \a tid is less than 0, the ID is generated automatically.
+ If toolbar with given \a tid is already registered, the toolbar will not be created.
+
+ \param title toolbar title
+ \param tid requested toolbar ID
+ \return id of created/found toolbar
*/
-int QtxActionToolMgr::createToolBar( const QString& name, const int tid )
+int QtxActionToolMgr::createToolBar( const QString& title, const int tid )
{
static int _toolBarId = -1;
int tbId = -1;
for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && tbId == -1; ++it )
{
- if ( it.data().toolBar->label().lower() == name.lower() )
+ if ( it.value().toolBar->windowTitle().toLower() == title.toLower() )
tbId = it.key();
}
if ( tbId != -1 )
return tbId;
- QToolBar* tb = find( name, mainWindow() );
+ QToolBar* tb = find( title, mainWindow() );
tbId = tid < 0 ? --_toolBarId : tid;
if ( !tb )
{
tb = new QtxToolBar( true, mainWindow() );
- tb->setLabel( name );
+ mainWindow()->addToolBar( tb );
+ tb->setWindowTitle( title );
}
tInfo.toolBar = tb;
}
/*!
- \return toolbar by title
- \param label - toolbar title
- \param mw - desktop
+ \brief Search toolbar with given \a title owned by main window \mw.
+ \param title toolbar title
+ \param mw main window
+ \return toolbar or 0 if not found
*/
-QToolBar* QtxActionToolMgr::find( const QString& label, QMainWindow* mw ) const
+QToolBar* QtxActionToolMgr::find( const QString& title, QMainWindow* mw ) const
{
if ( !mw )
return 0;
- QString pattern = label.lower();
+ QString pattern = title.toLower();
QToolBar* res = 0;
- QPtrList<QDockWindow> lst = mw->dockWindows();
- for ( QPtrListIterator<QDockWindow> it( lst ); it.current() && !res; ++it )
+ QList<QToolBar*> toolbars = qFindChildren<QToolBar*>( mw );
+ for ( QList<QToolBar*>::iterator it = toolbars.begin(); it != toolbars.end() && !res; ++it )
{
- if ( !it.current()->inherits( "QToolBar" ) )
- continue;
-
- QToolBar* cur = (QToolBar*)it.current();
- if ( cur->label().lower() == pattern )
- res = cur;
+ if ( (*it)->windowTitle().toLower() == pattern )
+ res = *it;
}
return res;
}
/*!
- Removes toolbar
- \param tid - toolbar id
+ \brief Remove toolbar.
+ \param tid toolbar ID
*/
void QtxActionToolMgr::removeToolBar( const int tid )
{
}
/*!
- Removes toolbar
- \param tname - toolbar name
+ \brief Remove toolbar.
+ \param title toolbar title
*/
-void QtxActionToolMgr::removeToolBar( const QString& tname )
+void QtxActionToolMgr::removeToolBar( const QString& title )
{
- removeToolBar( find( tname ) );
+ removeToolBar( find( title ) );
}
/*!
- Insert action into toolbar
- \param id - identificator of action
- \param tId - identificator of toolbar
- \param idx - position inside toolbar
+ \brief Insert action into toolbar.
+ \param id action ID
+ \param tid toolbar ID
+ \param idx action index in the toolbar (if < 0, action is appended to the end)
+ \return action ID
*/
int QtxActionToolMgr::insert( const int id, const int tid, const int idx )
{
if ( !contains( id ) || !hasToolBar( tid ) )
return -1;
-
+/*
if ( containsAction( id, tid ) )
remove( id, tid );
-
- ToolNode node;
- node.id = id;
+*/
+ ToolNode node( id );
NodeList& list = myToolBars[tid].nodes;
- int index = idx < 0 ? list.count() : QMIN( idx, (int)list.count() );
- list.insert( list.at( index ), node );
- updateToolBar( tid );
+ int index = idx < 0 ? list.count() : qMin( idx, (int)list.count() );
+ list.insert( index, node );
+ triggerUpdate( tid );
return id;
}
/*!
- Insert action into toolbar
- \param act - action
- \param tId - identificator of toolbar
- \param pos - position inside toolbar
+ \brief Insert action into toolbar.
+ \param a action
+ \param tid toolbar ID
+ \param idx action index in the toolbar (if < 0, action is appended to the end)
+ \return action ID
*/
-int QtxActionToolMgr::insert( QAction* act, const int tid, const int pos )
+int QtxActionToolMgr::insert( QAction* a, const int tid, const int idx )
{
- return insert( registerAction( act ), tid, pos );
+ return insert( registerAction( a ), tid, idx );
}
/*!
- Insert action into toolbar
- \param id - identificator of action
- \param tname - name of toolbar
- \param pos - position inside toolbar
+ \brief Insert action into toolbar.
+ \param id action ID
+ \param title toolbar title
+ \param idx action index in the toolbar (if < 0, action is appended to the end)
+ \return action ID
*/
-int QtxActionToolMgr::insert( const int id, const QString& tname, const int pos )
+int QtxActionToolMgr::insert( const int id, const QString& title, const int idx )
{
- return insert( id, createToolBar( tname ), pos );
+ return insert( id, createToolBar( title ), idx );
}
/*!
- Insert action into toolbar
- \param act - action
- \param tname - name of toolbar
- \param pos - position inside toolbar
+ \brief Insert action into toolbar.
+ \param a action
+ \param title toolbar title
+ \param idx action index in the toolbar (if < 0, action is appended to the end)
+ \return action ID
*/
-int QtxActionToolMgr::insert( QAction* act, const QString& tname, const int pos )
+int QtxActionToolMgr::insert( QAction* a, const QString& title, const int idx )
{
- return insert( registerAction( act ), createToolBar( tname ), pos );
+ return insert( registerAction( a ), createToolBar( title ), idx );
}
/*!
- Append action into toolbar as last toolbutton
- \param id - identificator of action
- \param tId - identificator of toolbar
+ \brief Append action to the end of toolbar.
+ \param id action ID
+ \param tid toolbar ID
+ \return action ID
*/
int QtxActionToolMgr::append( const int id, const int tid )
{
}
/*!
- Append action into toolbar as last toolbutton
- \param act - action
- \param tId - identificator of toolbar
+ \brief Append action to the end of toolbar.
+ \param a action
+ \param tid toolbar ID
+ \return action ID
*/
-int QtxActionToolMgr::append( QAction* act, const int tid )
+int QtxActionToolMgr::append( QAction* a, const int tid )
{
- return insert( act, tid );
+ return insert( a, tid );
}
/*!
- Append action into toolbar as last toolbutton
- \param id - identificator of action
- \param tname - toolbar name
+ \brief Append action to the end of toolbar.
+ \param id action ID
+ \param title toolbar title
+ \return action ID
*/
-int QtxActionToolMgr::append( const int id, const QString& tname )
+int QtxActionToolMgr::append( const int id, const QString& title )
{
- return insert( id, tname );
+ return insert( id, title );
}
/*!
- Append action into toolbar as last toolbutton
- \param act - action
- \param tname - toolbar name
+ \brief Append action to the end of toolbar.
+ \param a action
+ \param title toolbar title
+ \return action ID
*/
-int QtxActionToolMgr::append( QAction* act, const QString& tname )
+int QtxActionToolMgr::append( QAction* a, const QString& title )
{
- return insert( act, tname );
+ return insert( a, title );
}
/*!
- Append action into toolbar as first toolbutton
- \param id - identificator of action
- \param tId - identificator of toolbar
+ \brief Insert action to the beginning of toolbar.
+ \param id action ID
+ \param tid toolbar ID
+ \return action ID
*/
int QtxActionToolMgr::prepend( const int id, const int tid )
{
}
/*!
- Append action into toolbar as first toolbutton
- \param act - action
- \param tId - identificator of toolbar
+ \brief Insert action to the beginning of toolbar.
+ \param a action
+ \param tid toolbar ID
+ \return action ID
*/
-int QtxActionToolMgr::prepend( QAction* act, const int tid )
+int QtxActionToolMgr::prepend( QAction* a, const int tid )
{
- return insert( act, tid, 0 );
+ return insert( a, tid, 0 );
}
/*!
- Append action into toolbar as first toolbutton
- \param id - identificator of action
- \param tname - toolbar name
+ \brief Insert action to the beginning of toolbar.
+ \param id action ID
+ \param title toolbar title
+ \return action ID
*/
-int QtxActionToolMgr::prepend( const int id, const QString& tname )
+int QtxActionToolMgr::prepend( const int id, const QString& title )
{
- return insert( id, tname, 0 );
+ return insert( id, title, 0 );
}
/*!
- Append action into toolbar as first toolbutton
- \param act - action
- \param tname - toolbar name
+ \brief Insert action to the beginning of toolbar.
+ \param a action ID
+ \param title toolbar title
+ \return action ID
*/
-int QtxActionToolMgr::prepend( QAction* act, const QString& tname )
+int QtxActionToolMgr::prepend( QAction* a, const QString& tname )
{
- return insert( act, tname, 0 );
+ return insert( a, tname, 0 );
}
/*!
- Remove action from toolbar
- \param id - identificator of action
- \param tId - identificator of toolbar
+ \brief Remove action from toolbar.
+ \param id action ID
+ \param tid toolbar ID
*/
void QtxActionToolMgr::remove( const int id, const int tid )
{
myToolBars[tid].nodes = newList;
- updateToolBar( tid );
+ triggerUpdate( tid );
}
/*!
- Remove action from toolbar
- \param id - identificator of action
- \param tname - name of toolbar
+ \brief Remove action from toolbar.
+ \param id action ID
+ \param title toolbar title
*/
-void QtxActionToolMgr::remove( const int id, const QString& tname )
+void QtxActionToolMgr::remove( const int id, const QString& title )
{
- remove( id, find( tname ) );
+ remove( id, find( title ) );
}
/*!
- \return toolbar by it's id
- \param tId - identificator of toolbar
+ \brief Get toolbar by given \a tid.
+ \param tid toolbar ID
+ \return toolbar or 0 if not found
*/
QToolBar* QtxActionToolMgr::toolBar( const int tid ) const
{
}
/*!
- \return toolbar by it's name
- \param tname - name of toolbar
+ \brief Get toolbar by given \a title.
+ \param title toolbar title
+ \return toolbar or 0 if not found
*/
-QToolBar* QtxActionToolMgr::toolBar( const QString& tname ) const
+QToolBar* QtxActionToolMgr::toolBar( const QString& title ) const
{
- return toolBar( find( tname ) );
+ return toolBar( find( title ) );
}
/*!
- \return true if manager contains toolbar with such id
- \param tId - identificator of toolbar
+ \brief Check if toolbar with given \a id already registered.
+ \param tid toolbar ID
+ \return \c true if toolbar is registered in the toolbar manager
*/
bool QtxActionToolMgr::hasToolBar( const int tid ) const
{
}
/*!
- \return true if manager contains toolbar with such name
- \param tname - name of toolbar
+ \brief Check if toolbar with given \a id already registered.
+ \param title toolbar title
+ \return \c true if toolbar is registered in the toolbar manager
*/
-bool QtxActionToolMgr::hasToolBar( const QString& tname ) const
+bool QtxActionToolMgr::hasToolBar( const QString& title ) const
{
- return find( tname ) != -1;
+ return find( title ) != -1;
}
/*!
- \return true if toolbar contains action
- \param id - identificator of action
- \param tId - identificator of toolbar
+ \brief Check if toolbar contains given action.
+ \param id action ID
+ \param tid toolbar ID
+ \return \c true if toolbar contains action
*/
bool QtxActionToolMgr::containsAction( const int id, const int tid ) const
{
for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
{
- if ( tid == -1 || it.key() == tid ) {
- const NodeList& list = it.data().nodes;
+ if ( tid == -1 || it.key() == tid )
+ {
+ const NodeList& list = it.value().nodes;
for ( NodeList::const_iterator nit = list.begin(); nit != list.end(); ++nit )
if ( (*nit).id == id )
return true;
}
/*!
- SLOT: called when toolbar is destroyed, removes just destroyed toolbar from map
+ \brief Called when toolbar is destroyed.
+
+ Clears internal pointer to the toolbar to disable crashes.
*/
void QtxActionToolMgr::onToolBarDestroyed()
{
}
/*!
- \return id of toolbar by it's name
- \param tname - name of toolbar
+ \brief Search toolbar by given \a name.
+ \param title toolbar title
+ \return toolbar ID or -1 if not found
*/
-int QtxActionToolMgr::find( const QString& tname ) const
+int QtxActionToolMgr::find( const QString& title ) const
{
int id = -1;
for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
{
- if ( it.data().toolBar->label() == tname )
+ if ( it.value().toolBar->windowTitle() == title )
id = it.key();
}
return id;
}
/*!
- \return id of toolbar
- \param t - toolbar
+ \brief Get toolbar ID.
+ \param tb toolbar
+ \return toolbar ID or -1 if toolbar is not registered
*/
-int QtxActionToolMgr::find( QToolBar* t ) const
+int QtxActionToolMgr::find( QToolBar* tb ) const
{
int id = -1;
for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end() && id == -1; ++it )
{
- if ( it.data().toolBar == t )
+ if ( it.value().toolBar == tb )
id = it.key();
}
return id;
}
/*!
- Updates toolbar
- \param tId - toolbar id
+ \brief Update toolbar.
+ \param tid toolbar ID
*/
-void QtxActionToolMgr::updateToolBar( const int tId )
+void QtxActionToolMgr::updateToolBar( const int tid )
{
if ( !isUpdatesEnabled() )
return;
- if ( !myToolBars.contains( tId ) )
+ if ( !myToolBars.contains( tid ) )
return;
- QToolBar* tb = myToolBars[tId].toolBar;
- const NodeList& list = myToolBars[tId].nodes;
+ QToolBar* tb = myToolBars[tid].toolBar;
+ const NodeList& list = myToolBars[tid].nodes;
for ( NodeList::const_iterator it = list.begin(); it != list.end(); ++it )
{
QAction* a = action( (*it).id );
- if ( a )
- a->removeFrom( tb );
+ tb->removeAction( a );
+// if ( a )
+// a->removeFrom( tb );
}
tb->clear();
for ( NodeList::const_iterator itr = list.begin(); itr != list.end(); ++itr )
{
- if ( !isVisible( (*itr).id, tId ) )
+ if ( !isVisible( (*itr).id, tid ) )
continue;
QAction* a = action( (*itr).id );
- if ( a )
- a->addTo( tb );
+ tb->addAction( a );
+// if ( a )
+// a->addTo( tb );
}
simplifySeparators( tb );
}
/*!
- Updates all toolbars
+ \brief Update all registered toolbars.
*/
void QtxActionToolMgr::internalUpdate()
{
+ if ( !isUpdatesEnabled() )
+ return;
+
for ( ToolBarMap::ConstIterator it1 = myToolBars.begin(); it1 != myToolBars.end(); ++it1 )
updateToolBar( it1.key() );
+
+ myUpdateIds.clear();
}
/*!
- Removes excess separators from toolbar
+ \brief Remove extra separators from toolbar.
+ \param tb toolbar
*/
-void QtxActionToolMgr::simplifySeparators( QToolBar* t )
+void QtxActionToolMgr::simplifySeparators( QToolBar* tb )
{
- if ( t )
- Qtx::simplifySeparators( t );
+ Qtx::simplifySeparators( tb );
}
/*!
- Shows action in all toolbars
- \param actId - action id
+ \brief Show action (in all toolbars)
+ \param id action ID
*/
-void QtxActionToolMgr::show( const int actId )
+void QtxActionToolMgr::show( const int id )
{
- setShown( actId, true );
+ setShown( id, true );
}
/*!
- Hides action in all toolbars
- \param actId - action id
+ \brief Hide action (in all toolbars)
+ \param id action ID
*/
-void QtxActionToolMgr::hide( const int actId )
+void QtxActionToolMgr::hide( const int id )
{
- setShown( actId, false );
+ setShown( id, false );
}
/*!
- Changes shown status of action in all toolbars
- \param id - action id
- \param on - new shown status
+ \brief Set visibility status for toolbar action with given \a id.
+ \param id action ID
+ \param on new visibility status
*/
void QtxActionToolMgr::setShown( const int id, const bool on )
{
}
/*!
- \return true if action is shown in all toolbars
- \param id - action id
+ \brief Get visibility status for toolbar action with given \a id.
+ \param id action ID
+ \return \c true if action is shown in all toolbars
*/
bool QtxActionToolMgr::isShown( const int id ) const
{
- QPtrList<ToolNode> nodes;
+ QList<const ToolNode*> nodes;
for ( ToolBarMap::ConstIterator it = myToolBars.begin(); it != myToolBars.end(); ++it )
{
- const NodeList& nl = it.data().nodes;
+ const NodeList& nl = it.value().nodes;
for ( NodeList::const_iterator itr = nl.begin(); itr != nl.end(); ++itr )
{
const ToolNode& node = *itr;
return false;
bool vis = true;
- for ( QPtrListIterator<ToolNode> itr( nodes ); itr.current() && vis; ++itr )
- vis = itr.current()->visible;
+ for ( QList<const ToolNode*>::iterator itr = nodes.begin(); itr != nodes.end() && vis; ++itr )
+ vis = (*itr)->visible;
return vis;
}
/*!
- \return shown status of action in toolbar
- \param id - action id
- \param tId - toolbar id
+ \brief Check if an action with given \a id is visible in the toolbar \a tid.
+ \param id action ID
+ \param tid toolbar ID
+ \return \c true if action is shown in the toolbar
*/
-bool QtxActionToolMgr::isVisible( const int id, const int tId ) const
+bool QtxActionToolMgr::isVisible( const int id, const int tid ) const
{
- if ( !myToolBars.contains( tId ) )
+ if ( !myToolBars.contains( tid ) )
return false;
bool vis = false;
- const NodeList& lst = myToolBars[tId].nodes;
+ const NodeList& lst = myToolBars[tid].nodes;
for ( NodeList::const_iterator it = lst.begin(); it != lst.end() && !vis; ++it )
{
const ToolNode& node = *it;
if ( node.id == id )
+
vis = node.visible;
}
return vis;
}
/*!
- Changes action shown status in certain toolbar
- \param id - action id
- \param tId - toolbar id
- \param on - new shown status
+ \brief Show/hide action with given \a id in the toolbar \a tid.
+ \param id action ID
+ \param tid toolbar ID
+ \param on new visibility status
*/
-void QtxActionToolMgr::setVisible( const int id, const int tId, const bool on )
+void QtxActionToolMgr::setVisible( const int id, const int tid, const bool on )
{
- if ( !myToolBars.contains( tId ) )
+ if ( !myToolBars.contains( tid ) )
return;
bool changed = false;
- NodeList& lst = myToolBars[tId].nodes;
+ NodeList& lst = myToolBars[tid].nodes;
for ( NodeList::iterator it = lst.begin(); it != lst.end(); ++it )
{
ToolNode& node = *it;
}
if ( changed )
- updateToolBar( tId );
+ triggerUpdate( tid );
}
/*!
- Loads toolbar content from file
- \param fname - file name
- \param r - reader
+ \brief Load toolbar contents from the file.
+ \param fname file name
+ \param r actions reader
+ \return \c true on success and \c false on error
*/
bool QtxActionToolMgr::load( const QString& fname, QtxActionMgr::Reader& r )
{
return r.read( fname, cr );
}
+/*!
+ \brief Called when delayed content update is performed.
+
+ Customizes the content update operation.
+*/
+void QtxActionToolMgr::updateContent()
+{
+ if ( !isUpdatesEnabled() )
+ return;
+
+ for ( QMap<int,int>::const_iterator it = myUpdateIds.constBegin(); it != myUpdateIds.constEnd(); ++it )
+ updateToolBar( it.key() );
+ myUpdateIds.clear();
+}
+
+/*!
+ \brief Perform delayed toolbar update.
+ \param tid toolbar ID
+*/
+void QtxActionToolMgr::triggerUpdate( const int tid )
+{
+ myUpdateIds.insert( tid, 0 );
+ QtxActionMgr::triggerUpdate();
+}
+
/*!
- Constructor
+ \class QtxActionMenuMgr::ToolCreator
+ \brief Toolbars creator.
+
+ Used by Reader to create actions by reading descriptions from the file,
+ create toolbars and fill in the toolbara with the actions.
+*/
+
+/*!
+ \brief Constructor.
+ \param r actions reader
+ \param mgr toolbar manager
*/
QtxActionToolMgr::ToolCreator::ToolCreator( QtxActionMgr::Reader* r,
QtxActionToolMgr* mgr )
}
/*!
- Destructor
+ \brief Creator destructor.
+
+ Does nothing for the moment.
*/
QtxActionToolMgr::ToolCreator::~ToolCreator()
{
}
/*!
- Appends new tool buttons
- \param tag - tag of toolmenu
- \param subMenu - it has submenu (not used here)
- \param attr - list of attributes
- \param pId - id of action corresponding to parent item
+ \brief Create and append to the action manager a new toolbar or toolbar action.
+ \param tag item tag name
+ \param subMenu \c true if this item is submenu (not used)
+ \param attr attributes map
+ \param tid toolbar ID
+ \return toolbar or toolbar action ID
*/
-int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool subMenu,
- const ItemAttributes& attr, const int tId )
+int QtxActionToolMgr::ToolCreator::append( const QString& tag, const bool /*subMenu*/,
+ const ItemAttributes& attr, const int tid )
{
if( !myMgr || !reader() )
return -1;
toggle = reader()->option( "toggle", "toggle" );
int res = -1, actId = intValue( attr, id, -1 );
- if( tId==-1 )
+ if( tid==-1 )
res = myMgr->createToolBar( strValue( attr, label ), intValue( attr, id, -1 ) );
else if( tag==sep )
- res = myMgr->insert( separator(), tId, intValue( attr, pos, -1 ) );
+ res = myMgr->insert( separator(), tid, intValue( attr, pos, -1 ) );
else
{
- QPixmap pix; QIconSet set;
+ QIcon set;
+ QPixmap pix;
QString name = strValue( attr, icon );
if( !name.isEmpty() && loadPixmap( name, pix ) )
- set = QIconSet( pix );
+ set = QIcon( pix );
- QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set,
- strValue( attr, label ),
- QKeySequence( strValue( attr, accel ) ),
- myMgr );
+ QtxAction* newAct = new QtxAction( strValue( attr, tooltip ), set, strValue( attr, label ),
+ QKeySequence( strValue( attr, accel ) ), myMgr );
QString toggleact = strValue( attr, toggle );
- newAct->setToggleAction( !toggleact.isEmpty() );
- newAct->setOn( toggleact.lower()=="true" );
+ newAct->setCheckable( !toggleact.isEmpty() );
+ newAct->setChecked( toggleact.toLower() == "true" );
connect( newAct );
int aid = myMgr->registerAction( newAct, actId );
- res = myMgr->insert( aid, tId, intValue( attr, pos, -1 ) );
+ res = myMgr->insert( aid, tid, intValue( attr, pos, -1 ) );
}
return res;
}
-
-