From f00b43207e8d245e0b26a0e962b890844efdcc65 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 29 Jun 2007 14:44:11 +0000 Subject: [PATCH] Porting to Qt 4 --- src/Qtx/QtxActionMenuMgr.cxx | 30 +++++++++++++++++++++++------- src/Qtx/QtxActionMenuMgr.h | 3 ++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Qtx/QtxActionMenuMgr.cxx b/src/Qtx/QtxActionMenuMgr.cxx index 6a6a5fe12..dce08b4ac 100644 --- a/src/Qtx/QtxActionMenuMgr.cxx +++ b/src/Qtx/QtxActionMenuMgr.cxx @@ -117,7 +117,7 @@ QtxActionMenuMgr::QtxActionMenuMgr( QMainWindow* p ) 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 ) ) ); + connect( myMenu, SIGNAL( hovered( QAction* ) ), this, SLOT( onHighlighted( QAction* ) ) ); #endif } } @@ -136,7 +136,7 @@ QtxActionMenuMgr::QtxActionMenuMgr( QWidget* mw, QObject* p ) 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 ) ) ); + connect( myMenu, SIGNAL( hovered( QAction* ) ), this, SLOT( onHighlighted( QAction* ) ) ); #endif } } @@ -340,7 +340,7 @@ int QtxActionMenuMgr::insert( const QString& title, const int pId, const int gro connect( ma->menu(), SIGNAL( aboutToShow() ), this, SLOT( onAboutToShow() ) ); connect( ma->menu(), SIGNAL( aboutToHide() ), this, SLOT( onAboutToHide() ) ); #ifdef ENABLE_DYNAMIC_MENU - connect( ma->menu(), SIGNAL( highlighted( int ) ), this, SLOT( onHighlighted( int ) ) ); + connect( ma->menu(), SIGNAL( hovered( QAction* ) ), this, SLOT( onHighlighted( QAction* ) ) ); #endif MenuNode* node = new MenuNode( pNode, myMenus.insert( gid, ma ).key(), idx, group ); @@ -606,10 +606,10 @@ void QtxActionMenuMgr::onDestroyed( QObject* obj ) \brief Called when menu item is highlighted. \param id menu item being highlighted ID */ -void QtxActionMenuMgr::onHighlighted( int id ) +void QtxActionMenuMgr::onHighlighted( QAction* a ) { const QObject* snd = sender(); - int pid = 0, realId; + int pid = 0; if ( myMenu && snd == myMenu ) pid = -1; else @@ -617,12 +617,12 @@ void QtxActionMenuMgr::onHighlighted( int id ) for ( MenuMap::Iterator itr = myMenus.begin(); itr != myMenus.end(); ++itr ) { if ( itr.value()->menu() && itr.value()->menu() == snd ) - pid = itr.key(); + pid = itr.key(); } } if ( pid ) { - realId = findId( id, pid ); + int realId = menuActionId( a ); if ( realId != -1 ) { emit menuHighlighted( pid, realId ); @@ -834,6 +834,22 @@ QAction* QtxActionMenuMgr::menuAction( const int id ) const return a; } +/*! + \brief Get submenu action by \a id. + \param id submenu ID + \return submenu action or 0 if not found +*/ +int QtxActionMenuMgr::menuActionId( QAction* a ) const +{ + int id = -1; + for ( MenuMap::ConstIterator itr = myMenus.begin(); itr != myMenus.end() && id == -1; ++itr ) + { + if ( itr.value() == a ) + id = itr.key(); + } + return id; +} + /*! \brief Update menu. diff --git a/src/Qtx/QtxActionMenuMgr.h b/src/Qtx/QtxActionMenuMgr.h index c475de410..bff1fbaf7 100644 --- a/src/Qtx/QtxActionMenuMgr.h +++ b/src/Qtx/QtxActionMenuMgr.h @@ -96,7 +96,7 @@ public: private slots: void onAboutToShow(); void onAboutToHide(); - void onHighlighted( int ); + void onHighlighted( QAction* ); void onDestroyed( QObject* ); signals: @@ -120,6 +120,7 @@ protected: QAction* itemAction( const int ) const; QAction* menuAction( const int ) const; + int menuActionId( QAction* ) const; void updateMenu( MenuNode* = 0, const bool = true, const bool = true ); virtual void internalUpdate(); -- 2.39.2