From 1e69f443a7d1c43dec88876f08bae0d21a25c915 Mon Sep 17 00:00:00 2001 From: asv Date: Wed, 24 Aug 2005 07:52:12 +0000 Subject: [PATCH] Improved implementaion of internal data structure of Accelerator manager. Now it allows to register different actions for the same key press (in different types of viewers, naturally). --- src/SUIT/SUIT_Accel.cxx | 33 ++++++++++++++++----------------- src/SUIT/SUIT_Accel.h | 26 ++++++++++++++++++++------ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/SUIT/SUIT_Accel.cxx b/src/SUIT/SUIT_Accel.cxx index 0b8534404..5e94b5497 100644 --- a/src/SUIT/SUIT_Accel.cxx +++ b/src/SUIT/SUIT_Accel.cxx @@ -31,30 +31,29 @@ SUIT_Accel::~SUIT_Accel() /*! setActionKey assign a ceratain action for a key accelerator */ void SUIT_Accel::setActionKey( const int action, const int key, const QString& type ) { - if ( myKeyActionMap.contains( key ) ) - myAccel->removeItem( action ); - - myKeyActionMap[key] = action; - QStringList vTypes; - if ( myActionViewerTypesMap.contains( action ) ) - vTypes = myActionViewerTypesMap[action]; - if ( !vTypes.contains( type ) ) - vTypes.append( type ); - myActionViewerTypesMap[action] = vTypes; - - myAccel->insertItem( key, action ); + // 1. get or generate interal "id" of action + int id = myAccel->findKey( key ); + if ( id == -1 ) + id = myAccel->insertItem( key ); + + IdActionMap idActionMap; + if ( myMap.contains( type ) ) + idActionMap = myMap[type]; + + idActionMap[id] = action; + myMap[type] = idActionMap; } /*! onActivated slot called when a registered key accelerator was activated */ -void SUIT_Accel::onActivated( int action ) +void SUIT_Accel::onActivated( int id ) { if ( myDesktop ) { if ( SUIT_ViewWindow* vw = myDesktop->activeWindow() ) { QString type = vw->getViewManager()->getViewModel()->getType(); - if ( myActionViewerTypesMap.contains( action ) ) { - QStringList vTypes = myActionViewerTypesMap[action]; - if ( vTypes.contains( type ) ) { - vw->onAccelAction( action ); + if ( myMap.contains( type ) ) { + IdActionMap idActionMap = myMap[type]; + if ( idActionMap.contains( id ) ) { + vw->onAccelAction( idActionMap[id] ); } } } diff --git a/src/SUIT/SUIT_Accel.h b/src/SUIT/SUIT_Accel.h index 0c72053da..1821ce224 100644 --- a/src/SUIT/SUIT_Accel.h +++ b/src/SUIT/SUIT_Accel.h @@ -8,7 +8,7 @@ #include "SUIT.h" #include -#include +#include #include class QAccel; @@ -18,11 +18,26 @@ class SUIT_EXPORT SUIT_Accel: public QObject { Q_OBJECT +public: + enum Actions { + PanLeft = 1, + PanRight, + PanUp, + PanDown, + ZoomIn, + ZoomOut, + ZoomFit, + RotateLeft, + RotateRight, + RotateUp, + RotateDown, + LastAction + }; + public: SUIT_Accel( SUIT_Desktop* theDesktop ); virtual ~SUIT_Accel(); - enum Actions { PanLeft = 1, PanRight, PanUp, PanDown, ZoomIn, ZoomOut, ZoomFit, RotateLeft, RotateRight, RotateUp, RotateDown, UserAction }; void setActionKey( const int action, const int key, const QString& type ); protected slots: @@ -32,10 +47,9 @@ private: QAccel* myAccel; SUIT_Desktop* myDesktop; - typedef QMap KeyActionMap; // key-to-action map - typedef QMap ActionViewerTypesMap; // key=action id - KeyActionMap myKeyActionMap; - ActionViewerTypesMap myActionViewerTypesMap; + typedef QMap IdActionMap; // internal_id - to - action map + typedef QMap ViewerTypeIdActionMap; // viewer_type - to - IdActionMap + ViewerTypeIdActionMap myMap; }; #endif -- 2.39.2