1 // SUIT_Accel.cxx: implementation of the SUIT_Accel class.
3 //////////////////////////////////////////////////////////////////////
5 #include "SUIT_Accel.h"
6 #include "SUIT_Desktop.h"
7 #include "SUIT_ViewManager.h"
8 #include "SUIT_ViewWindow.h"
9 #include "SUIT_ViewModel.h"
14 * Class handles keyboard accelerator bindings.
18 SUIT_Accel::SUIT_Accel(SUIT_Desktop* theDesktop)
19 : QObject( theDesktop, "SUIT_Accel" ),
20 myDesktop( theDesktop )
22 myAccel = new QAccel( theDesktop, "SUIT_Accel_interal_qaccel" );
23 connect( myAccel, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
27 SUIT_Accel::~SUIT_Accel()
31 /*! setActionKey assign a ceratain action for a key accelerator */
32 void SUIT_Accel::setActionKey( const int action, const int key, const QString& type )
34 if ( myKeyActionMap.contains( key ) )
35 myAccel->removeItem( action );
37 myKeyActionMap[key] = action;
39 if ( myActionViewerTypesMap.contains( action ) )
40 vTypes = myActionViewerTypesMap[action];
41 if ( !vTypes.contains( type ) )
42 vTypes.append( type );
43 myActionViewerTypesMap[action] = vTypes;
45 myAccel->insertItem( key, action );
48 /*! onActivated slot called when a registered key accelerator was activated */
49 void SUIT_Accel::onActivated( int action )
52 if ( SUIT_ViewWindow* vw = myDesktop->activeWindow() ) {
53 QString type = vw->getViewManager()->getViewModel()->getType();
54 if ( myActionViewerTypesMap.contains( action ) ) {
55 QStringList vTypes = myActionViewerTypesMap[action];
56 if ( vTypes.contains( type ) ) {
57 vw->onAccelAction( action );