/*! 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] );
}
}
}
#include "SUIT.h"
#include <qobject.h>
-#include <qstringlist.h>
+#include <qstring.h>
#include <qmap.h>
class QAccel;
{
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:
QAccel* myAccel;
SUIT_Desktop* myDesktop;
- typedef QMap<int, int> KeyActionMap; // key-to-action map
- typedef QMap<int, QStringList> ActionViewerTypesMap; // key=action id
- KeyActionMap myKeyActionMap;
- ActionViewerTypesMap myActionViewerTypesMap;
+ typedef QMap<int, int> IdActionMap; // internal_id - to - action map
+ typedef QMap<QString, IdActionMap> ViewerTypeIdActionMap; // viewer_type - to - IdActionMap
+ ViewerTypeIdActionMap myMap;
};
#endif