1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // SUIT_Accel.cxx: implementation of the SUIT_Accel class.
21 //////////////////////////////////////////////////////////////////////
23 #include "SUIT_Accel.h"
24 #include "SUIT_Desktop.h"
25 #include "SUIT_ViewManager.h"
26 #include "SUIT_ViewWindow.h"
27 #include "SUIT_ViewModel.h"
32 * Class handles keyboard accelerator bindings.
36 SUIT_Accel::SUIT_Accel(SUIT_Desktop* theDesktop)
37 : QObject( theDesktop, "SUIT_Accel" ),
38 myDesktop( theDesktop )
40 myAccel = new QAccel( theDesktop, "SUIT_Accel_interal_qaccel" );
41 connect( myAccel, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
45 SUIT_Accel::~SUIT_Accel()
49 /*! setActionKey assign a ceratain action for a key accelerator */
50 void SUIT_Accel::setActionKey( const int action, const int key, const QString& type )
52 // 1. get or generate interal "id" of action
53 int id = myAccel->findKey( key );
55 id = myAccel->insertItem( key );
57 IdActionMap idActionMap;
58 if ( myMap.contains( type ) )
59 idActionMap = myMap[type];
61 idActionMap[id] = action;
62 myMap[type] = idActionMap;
65 /*! onActivated slot called when a registered key accelerator was activated */
66 void SUIT_Accel::onActivated( int id )
69 if ( SUIT_ViewWindow* vw = myDesktop->activeWindow() ) {
70 QString type = vw->getViewManager()->getViewModel()->getType();
71 if ( myMap.contains( type ) ) {
72 IdActionMap idActionMap = myMap[type];
73 if ( idActionMap.contains( id ) ) {
74 vw->onAccelAction( idActionMap[id] );