]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
New class - SUIT_Accel - is introduced. It is used for handling keyboard accelerator...
authorasv <asv@opencascade.com>
Tue, 23 Aug 2005 12:20:26 +0000 (12:20 +0000)
committerasv <asv@opencascade.com>
Tue, 23 Aug 2005 12:20:26 +0000 (12:20 +0000)
12 files changed:
src/SOCC/Makefile.in
src/SOCC/SOCC_ViewModel.cxx
src/SOCC/SOCC_ViewModel.h
src/SOCC/SOCC_ViewWindow.cxx [new file with mode: 0644]
src/SOCC/SOCC_ViewWindow.h [new file with mode: 0644]
src/SUIT/Makefile.in
src/SUIT/SUIT_Accel.cxx [new file with mode: 0644]
src/SUIT/SUIT_Accel.h [new file with mode: 0644]
src/SUIT/SUIT_ViewWindow.cxx
src/SUIT/SUIT_ViewWindow.h
src/SVTK/SVTK_ViewWindow.cxx
src/SVTK/SVTK_ViewWindow.h

index 26f3ef6f3d576dbf6a0dd79a759f1c1c7245f6e2..9ae919a0afefcd594a746ebe315f27eff0e443fe 100755 (executable)
@@ -14,15 +14,18 @@ VPATH=.:@srcdir@
 # header files
 EXPORT_HEADERS= SOCC.h \
                SOCC_ViewModel.h \
-               SOCC_Prs.h
+               SOCC_Prs.h \
+               SOCC_ViewWindow.h
 
 # Libraries targets
 LIB = libSOCC.la
 
 LIB_SRC= SOCC_ViewModel.cxx \
-        SOCC_Prs.cxx
+        SOCC_Prs.cxx \
+        SOCC_ViewWindow.cxx
 
-LIB_MOC = SOCC_ViewModel.h
+LIB_MOC = SOCC_ViewModel.h \
+         SOCC_ViewWindow.h
 
 LIB_CLIENT_IDL = SALOMEDS.idl \
                 SALOME_Exception.idl \
index 44eaf80afe7dbc5953065d62bdfb8450a2479d58..b78328d7f40c2ea687c5966f5bbe4aab3376f84c 100755 (executable)
@@ -1,6 +1,7 @@
 #include "SOCC_ViewModel.h"
 
 #include "SOCC_Prs.h"
+#include "SOCC_ViewWindow.h"
 
 #include "SUIT_Session.h"
 #include "SUIT_Application.h"
@@ -597,3 +598,14 @@ void SOCC_Viewer::Repaint()
 //  onAdjustTrihedron();
   getViewer3d()->Update();
 }
+
+//=======================================================================
+// name    : createView
+// Purpose : create SOCC_ViewWindow
+//=======================================================================
+SUIT_ViewWindow* SOCC_Viewer::createView( SUIT_Desktop* theDesktop )
+{
+  SOCC_ViewWindow* view = new SOCC_ViewWindow(theDesktop, this);
+  initView( view );
+  return view;
+}
index 6551f47b88aab5bd70fcc7c5a04678884adb9961..327578f6a8e575401cde409a4afce2057a375b46 100755 (executable)
@@ -28,6 +28,8 @@ public:
 
   void      rename( const Handle(SALOME_InteractiveObject)&, const QString& );
 
+  virtual   SUIT_ViewWindow* createView(SUIT_Desktop* theDesktop);
+
   /* Reimplemented from SALOME_View */
   virtual void                Display( const SALOME_OCCPrs* );
   virtual void                Erase( const SALOME_OCCPrs*, const bool = false );
diff --git a/src/SOCC/SOCC_ViewWindow.cxx b/src/SOCC/SOCC_ViewWindow.cxx
new file mode 100644 (file)
index 0000000..826e0e5
--- /dev/null
@@ -0,0 +1,77 @@
+#include "SOCC_ViewWindow.h"
+
+#include "OCCViewer_ViewPort3d.h"
+
+#include "SUIT_Accel.h"
+
+//----------------------------------------------------------------------------
+SOCC_ViewWindow
+::SOCC_ViewWindow( SUIT_Desktop* theDesktop, 
+                  OCCViewer_Viewer* theModel)
+  : OCCViewer_ViewWindow( theDesktop, theModel )
+{
+}
+
+//----------------------------------------------------------------------------
+SOCC_ViewWindow
+::~SOCC_ViewWindow()
+{
+}
+
+//----------------------------------------------------------------------------
+void 
+SOCC_ViewWindow
+::action( const int theAction  )
+{
+  const int inc = 10;
+  int cx, cy;
+  if ( theAction == SUIT_Accel::ZoomIn || theAction == SUIT_Accel::ZoomOut ||
+       theAction == SUIT_Accel::RotateLeft || theAction == SUIT_Accel::RotateRight ||
+       theAction == SUIT_Accel::RotateUp || theAction == SUIT_Accel::RotateDown ) {
+    cx = myViewPort->width() / 2;
+    cy = myViewPort->height() / 2;
+  }
+  switch ( theAction ) {
+  case SUIT_Accel::PanLeft     : 
+    myViewPort->pan( -inc, 0 );   
+    break;
+  case SUIT_Accel::PanRight    : 
+    myViewPort->pan(  inc, 0 );   
+    break;
+  case SUIT_Accel::PanUp       : 
+    myViewPort->pan( 0, inc );   
+    break;
+  case SUIT_Accel::PanDown     : 
+    myViewPort->pan( 0, -inc );   
+    break;
+  case SUIT_Accel::ZoomIn      : 
+    myViewPort->zoom( cx, cy, cx + inc, cy + inc );
+    break;
+  case SUIT_Accel::ZoomOut     : 
+    myViewPort->zoom( cx, cy, cx - inc, cy - inc );
+    break;
+  case SUIT_Accel::ZoomFit     :
+    myViewPort->fitAll();
+    break;
+  case SUIT_Accel::RotateLeft  : 
+    myViewPort->startRotation( cx, cy );
+    myViewPort->rotate( cx - inc, cy );
+    myViewPort->endRotation();
+    break;
+  case SUIT_Accel::RotateRight :  
+    myViewPort->startRotation( cx, cy );
+    myViewPort->rotate( cx + inc, cy );
+    myViewPort->endRotation();
+    break;
+  case SUIT_Accel::RotateUp    :  
+    myViewPort->startRotation( cx, cy );
+    myViewPort->rotate( cx, cy - inc );
+    myViewPort->endRotation();
+    break;
+  case SUIT_Accel::RotateDown  :  
+    myViewPort->startRotation( cx, cy );
+    myViewPort->rotate( cx, cy + inc );
+    myViewPort->endRotation();
+    break;
+  } 
+}
diff --git a/src/SOCC/SOCC_ViewWindow.h b/src/SOCC/SOCC_ViewWindow.h
new file mode 100644 (file)
index 0000000..ee043cd
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef SOCC_VIEWWINDOW_H
+#define SOCC_VIEWWINDOW_H
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+#include "SOCC.h"
+#include "OCCViewer_ViewWindow.h"
+
+class SOCC_EXPORT SOCC_ViewWindow : public OCCViewer_ViewWindow
+{
+  Q_OBJECT;
+
+public:
+  SOCC_ViewWindow( SUIT_Desktop*, OCCViewer_Viewer* );
+  virtual ~SOCC_ViewWindow();
+  
+protected:
+  virtual void      action( const int );
+
+};
+
+#ifdef WIN32
+#pragma warning( default:4251 )
+#endif
+
+#endif
index a7ab82dacf6826f7907c97dbf44ed5b9ab1c5a1d..f08c897d024f90093454f5ee64e9bca3b7baf721 100755 (executable)
@@ -40,7 +40,8 @@ EXPORT_HEADERS= SUIT.h \
         SUIT_ViewManager.h \
         SUIT_ViewModel.h \
         SUIT_ViewWindow.h \
-        SUIT_SelectionFilter.h
+        SUIT_SelectionFilter.h \
+        SUIT_Accel.h
 
 # .po files to transform in .qm
 PO_FILES = SUIT_images.po \
@@ -74,7 +75,8 @@ LIB_SRC= SUIT_ActionOperation.cxx \
         SUIT_ViewManager.cxx \
         SUIT_ViewModel.cxx \
         SUIT_ViewWindow.cxx \
-        SUIT_SelectionFilter.cxx
+        SUIT_SelectionFilter.cxx \
+        SUIT_Accel.cxx 
 
 LIB_MOC = SUIT_ActionOperation.h \
           SUIT_Application.h \
@@ -90,7 +92,8 @@ LIB_MOC = SUIT_ActionOperation.h \
          SUIT_ViewWindow.h \
          SUIT_ViewManager.h \
          SUIT_SelectionMgr.h \
-          SUIT_Selector.h
+          SUIT_Selector.h \
+         SUIT_Accel.h 
 
 RESOURCES_FILES = \
        cascade.png \
diff --git a/src/SUIT/SUIT_Accel.cxx b/src/SUIT/SUIT_Accel.cxx
new file mode 100644 (file)
index 0000000..0b85344
--- /dev/null
@@ -0,0 +1,63 @@
+// SUIT_Accel.cxx: implementation of the SUIT_Accel class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "SUIT_Accel.h"
+#include "SUIT_Desktop.h"
+#include "SUIT_ViewManager.h"
+#include "SUIT_ViewWindow.h"
+#include "SUIT_ViewModel.h"
+
+#include <qaccel.h>
+
+/*!\class SUIT_Accel
+ * Class handles keyboard accelerator bindings.
+ */
+
+/*! Constructor.*/
+SUIT_Accel::SUIT_Accel(SUIT_Desktop* theDesktop)
+  : QObject( theDesktop, "SUIT_Accel" ),
+    myDesktop( theDesktop )
+{
+  myAccel = new QAccel( theDesktop, "SUIT_Accel_interal_qaccel" );
+  connect( myAccel, SIGNAL( activated( int ) ), this, SLOT( onActivated( int ) ) );
+}
+
+/*! Destructor.*/
+SUIT_Accel::~SUIT_Accel()
+{
+}
+
+/*! 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 );
+}
+
+/*! onActivated  slot called when a registered key accelerator was activated */
+void SUIT_Accel::onActivated( int action )
+{
+  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 );
+       }
+      }
+    }
+  }
+}
+
diff --git a/src/SUIT/SUIT_Accel.h b/src/SUIT/SUIT_Accel.h
new file mode 100644 (file)
index 0000000..0c72053
--- /dev/null
@@ -0,0 +1,41 @@
+// SUIT_Accel.h: interface for the SUIT_Accel class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#ifndef SUIT_Accel_h 
+#define SUIT_Accel_h
+
+#include "SUIT.h"
+
+#include <qobject.h>
+#include <qstringlist.h>
+#include <qmap.h>
+
+class QAccel;
+class SUIT_Desktop;
+
+class SUIT_EXPORT SUIT_Accel: public QObject
+{
+  Q_OBJECT
+
+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:
+  void onActivated( int );
+
+private:
+  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;
+};
+
+#endif
index 73e310d02d71574d038a762069f326ebc5e9087c..e05fad7a52f290028ba125cbb5fde3028b159e15 100755 (executable)
@@ -26,6 +26,7 @@ SUIT_ViewWindow::SUIT_ViewWindow(SUIT_Desktop* theDesktop)
 {
   myDesktop = theDesktop;
 }
+
 /*! Destructor.*/
 SUIT_ViewWindow::~SUIT_ViewWindow()
 {
@@ -87,3 +88,16 @@ bool SUIT_ViewWindow::event( QEvent* e )
   }
   return QMainWindow::event( e );
 }
+
+/*! Called by SUIT_Accel::onActivated() when a key accelerator was activated and this window was active
+*/
+void SUIT_ViewWindow::onAccelAction( int _action )
+{
+  action( _action );
+}
+
+/*! action  handle standard action (zoom, pan) or custom action.  to be redefined in successors.
+*/
+void SUIT_ViewWindow::action( const int  )
+{
+}
index 5cfcb4e1d5e9feb32b1e35b44cf6aaf4eeb70bed..0aec5183e85711017131a2750b53583a7e83b8e8 100755 (executable)
@@ -30,6 +30,7 @@ public:
   bool              event(QEvent*);
 
   virtual QImage    dumpView() { return QImage(); }
+  void              onAccelAction( int );
 
 public slots:
   virtual void      onDumpView();
@@ -49,6 +50,8 @@ protected:
   void              closeEvent(QCloseEvent* theEvent);
   virtual void      contextMenuEvent( QContextMenuEvent * e );
 
+  virtual void      action( const int );
+
   SUIT_Desktop*     myDesktop;
   SUIT_ViewManager* myManager;
 };
index 5260b9732e43ad1e00fbf062bc8fa5c00cfd9e32..14e36c30d2cbcf37ed06672a756975d7a0f6e3f5 100755 (executable)
@@ -13,6 +13,7 @@
 #include "SUIT_Session.h"
 #include "SUIT_ToolButton.h"
 #include "SUIT_MessageBox.h"
+#include "SUIT_Accel.h"
 
 #include "SUIT_Tools.h"
 #include "SUIT_ResourceMgr.h"
@@ -1030,3 +1031,23 @@ SVTK_ViewWindow
   QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
   return px.convertToImage();
 }
+
+//----------------------------------------------------------------------------
+void 
+SVTK_ViewWindow
+::action( const int theAction  )
+{
+  switch ( theAction ) {
+  case SUIT_Accel::PanLeft     : onPanLeft();     break;
+  case SUIT_Accel::PanRight    : onPanRight();    break;
+  case SUIT_Accel::PanUp       : onPanUp();       break;
+  case SUIT_Accel::PanDown     : onPanDown();     break;
+  case SUIT_Accel::ZoomIn      : onZoomIn();      break;
+  case SUIT_Accel::ZoomOut     : onZoomOut();     break;
+  case SUIT_Accel::ZoomFit     : onFitAll();      break;
+  case SUIT_Accel::RotateLeft  : onRotateLeft();  break;
+  case SUIT_Accel::RotateRight : onRotateRight(); break;
+  case SUIT_Accel::RotateUp    : onRotateUp();    break;
+  case SUIT_Accel::RotateDown  : onRotateDown();  break;
+  }   
+}
index 2edda288e5291ed7a71103d03c8654db38a1a694..549518dc447763af298aba1bd7d7767f0cad9e8f 100755 (executable)
@@ -131,6 +131,7 @@ public slots:
 
 protected:
   QImage dumpView();
+  virtual void      action( const int );
 
 protected slots:
   void onKeyPressed(QKeyEvent* event);