X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUIT%2FSUIT_Accel.cxx;h=dd82975a6e685bade1675775db4c8e5755c4a2e9;hb=e6caa123c65e3c4a3017364ec5bb4225fd898465;hp=887b98bca581da81dc33aa02b618d1938107a5fb;hpb=101fd10f1e736daa5d7f0f0ee5499b951460832a;p=modules%2Fgui.git diff --git a/src/SUIT/SUIT_Accel.cxx b/src/SUIT/SUIT_Accel.cxx index 887b98bca..dd82975a6 100644 --- a/src/SUIT/SUIT_Accel.cxx +++ b/src/SUIT/SUIT_Accel.cxx @@ -1,45 +1,49 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SUIT_Accel.cxx: implementation of the SUIT_Accel class. // -////////////////////////////////////////////////////////////////////// - #include "SUIT_Accel.h" + #include "SUIT_ViewWindow.h" #include "SUIT_ViewManager.h" #include "SUIT_ViewModel.h" -#include -#include -#include +#include +#include +#include +/*! + \class SUIT_Accel + \brief Manager of keyboard accelerator bindings. +*/ -/*!\class SUIT_Accel - * Class handles keyboard accelerator bindings. - */ SUIT_Accel* SUIT_Accel::myself = 0; /*! Constructor [private].*/ SUIT_Accel::SUIT_Accel() - : QObject( qApp, "SUIT_Accel" ) +: QObject( QCoreApplication::instance() ) { - qApp->installEventFilter( this ); + QCoreApplication::instance()->installEventFilter( this ); } /*! getAccel() : public interface for SUIT_Accel object. Only one instance is created and returned. */ @@ -66,10 +70,12 @@ void SUIT_Accel::setActionKey( const int action, const int key, const QString& t /*! unsetActionKey() : unregister a certain key accelerator */ void SUIT_Accel::unsetActionKey( const int key, const QString& type ) { - if ( myMap.contains( type ) ) { + if ( myMap.contains( type ) ) + { IdActionMap idActionMap = myMap[type]; - if ( idActionMap.contains( key ) ) { - idActionMap.erase( key ); + if ( idActionMap.contains( key ) ) + { + idActionMap.remove( key ); myMap[type] = idActionMap; } } @@ -78,7 +84,8 @@ void SUIT_Accel::unsetActionKey( const int key, const QString& type ) /*! getParentViewWindow() : returns given object or any of its parents-grandparents-.. if it is a SUIT_ViewWindow */ SUIT_ViewWindow* getParentViewWindow( const QObject* obj ) { - if ( obj ) { + if ( obj ) + { if ( obj->inherits( "SUIT_ViewWindow" ) ) return (SUIT_ViewWindow*)obj; else @@ -88,22 +95,25 @@ SUIT_ViewWindow* getParentViewWindow( const QObject* obj ) } /*! getKey() : returns integer key code (with modifiers) made of key pressed 'inside' given event */ -int getKey( QKeyEvent *keyEvent ) +int getKey( QKeyEvent* keyEvent ) { - int key = keyEvent->key(), - state = keyEvent->state(); - if ( state & Qt::ShiftButton ) + int key = keyEvent->key(), state = keyEvent->modifiers(); + if ( state & Qt::ShiftModifier ) key += Qt::SHIFT; - if ( state & Qt::ControlButton ) + if ( state & Qt::ControlModifier ) key += Qt::CTRL; - if ( state & Qt::AltButton ) + if ( state & Qt::AltModifier ) key += Qt::ALT; - if ( state & Qt::MetaButton ) + if ( state & Qt::MetaModifier ) key += Qt::META; return key; } -/*! getAccelKey() : returns key pressed if 1) event was KeyPress 2) pressed key is a registered accelerator */ +/*! + Returns key pressed if + -# event was KeyPress + -# pressed key is a registered accelerator +*/ int SUIT_Accel::getAccelKey( QEvent *event ) { if ( event && event->type() == QEvent::KeyPress ) { @@ -121,13 +131,15 @@ bool SUIT_Accel::eventFilter( QObject *obj, QEvent *event ) if ( key ) { SUIT_ViewWindow* vw = ::getParentViewWindow( obj ); if ( vw ) { - QString type = vw->getViewManager()->getViewModel()->getType(); - if ( myMap.contains( type ) ) { - IdActionMap idActionMap = myMap[type]; - if ( idActionMap.contains( key ) ) { - vw->onAccelAction( idActionMap[key] ); - return true; - } + if ( vw->getViewManager() && vw->getViewManager()->getViewModel() ) + { + QString type = vw->getViewManager()->getViewModel()->getType(); + if ( myMap.contains( type ) ) { + IdActionMap idActionMap = myMap[type]; + if ( idActionMap.contains( key ) ) { + return vw->onAccelAction( idActionMap[key] ); + } + } } } }