Salome HOME
INT PAL 0052660: Plot2D Viewer: Plot2d_Curve can't be selected
[modules/gui.git] / src / SUIT / SUIT_Accel.cxx
index 600ab2ebd2324bd9322ce818b5a7785d2c4baf5b..dd82975a6e685bade1675775db4c8e5755c4a2e9 100644 (file)
@@ -1,40 +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.
 
+// 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 <qobjectlist.h>
-#include <qapplication.h>
-#include <qnamespace.h>
+#include <QCoreApplication>
+#include <QEvent>
+#include <QKeyEvent>
 
+/*!
+  \class SUIT_Accel
+  \brief Manager of 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. */
@@ -61,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;
     }
   }
@@ -73,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
@@ -83,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( QKeyEventkeyEvent )
 {
-  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 ) {
@@ -116,12 +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 ) ) {
-         return vw->onAccelAction( idActionMap[key] );
-       }
+      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] );
+          }
+        }
       }
     }
   }