From 4e9a2ea0d9a4b6c9a74deac8b84173fa7221b046 Mon Sep 17 00:00:00 2001 From: asv Date: Tue, 23 Aug 2005 12:20:26 +0000 Subject: [PATCH] New class - SUIT_Accel - is introduced. It is used for handling keyboard accelerators. ViewWindow is responsible for receiving the event from Accelerator manager. --- src/SOCC/Makefile.in | 9 +++-- src/SOCC/SOCC_ViewModel.cxx | 12 ++++++ src/SOCC/SOCC_ViewModel.h | 2 + src/SOCC/SOCC_ViewWindow.cxx | 77 ++++++++++++++++++++++++++++++++++++ src/SOCC/SOCC_ViewWindow.h | 28 +++++++++++++ src/SUIT/Makefile.in | 9 +++-- src/SUIT/SUIT_Accel.cxx | 63 +++++++++++++++++++++++++++++ src/SUIT/SUIT_Accel.h | 41 +++++++++++++++++++ src/SUIT/SUIT_ViewWindow.cxx | 14 +++++++ src/SUIT/SUIT_ViewWindow.h | 3 ++ src/SVTK/SVTK_ViewWindow.cxx | 21 ++++++++++ src/SVTK/SVTK_ViewWindow.h | 1 + 12 files changed, 274 insertions(+), 6 deletions(-) create mode 100644 src/SOCC/SOCC_ViewWindow.cxx create mode 100644 src/SOCC/SOCC_ViewWindow.h create mode 100644 src/SUIT/SUIT_Accel.cxx create mode 100644 src/SUIT/SUIT_Accel.h diff --git a/src/SOCC/Makefile.in b/src/SOCC/Makefile.in index 26f3ef6f3..9ae919a0a 100755 --- a/src/SOCC/Makefile.in +++ b/src/SOCC/Makefile.in @@ -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 \ diff --git a/src/SOCC/SOCC_ViewModel.cxx b/src/SOCC/SOCC_ViewModel.cxx index 44eaf80af..b78328d7f 100755 --- a/src/SOCC/SOCC_ViewModel.cxx +++ b/src/SOCC/SOCC_ViewModel.cxx @@ -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; +} diff --git a/src/SOCC/SOCC_ViewModel.h b/src/SOCC/SOCC_ViewModel.h index 6551f47b8..327578f6a 100755 --- a/src/SOCC/SOCC_ViewModel.h +++ b/src/SOCC/SOCC_ViewModel.h @@ -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 index 000000000..826e0e5a0 --- /dev/null +++ b/src/SOCC/SOCC_ViewWindow.cxx @@ -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 index 000000000..ee043cd80 --- /dev/null +++ b/src/SOCC/SOCC_ViewWindow.h @@ -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 diff --git a/src/SUIT/Makefile.in b/src/SUIT/Makefile.in index a7ab82dac..f08c897d0 100755 --- a/src/SUIT/Makefile.in +++ b/src/SUIT/Makefile.in @@ -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 index 000000000..0b8534404 --- /dev/null +++ b/src/SUIT/SUIT_Accel.cxx @@ -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 + +/*!\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 index 000000000..0c72053da --- /dev/null +++ b/src/SUIT/SUIT_Accel.h @@ -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 +#include +#include + +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 KeyActionMap; // key-to-action map + typedef QMap ActionViewerTypesMap; // key=action id + KeyActionMap myKeyActionMap; + ActionViewerTypesMap myActionViewerTypesMap; +}; + +#endif diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index 73e310d02..e05fad7a5 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -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 ) +{ +} diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index 5cfcb4e1d..0aec5183e 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -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; }; diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 5260b9732..14e36c30d 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -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; + } +} diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index 2edda288e..549518dc4 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -131,6 +131,7 @@ public slots: protected: QImage dumpView(); + virtual void action( const int ); protected slots: void onKeyPressed(QKeyEvent* event); -- 2.39.2