From c919fa1618856c4d963fc8f19bc6d3487e118eb4 Mon Sep 17 00:00:00 2001 From: apo Date: Fri, 19 Aug 2005 06:42:56 +0000 Subject: [PATCH] To provide a SUIT way of event dispatching --- src/SVTK/SVTK_RenderWindow.h | 2 - src/SVTK/SVTK_RenderWindowInteractor.cxx | 86 ++++++++++++++---------- src/SVTK/SVTK_RenderWindowInteractor.h | 15 ++++- src/SVTK/SVTK_View.h | 10 +-- src/SVTK/SVTK_ViewWindow.cxx | 14 +++- src/SVTK/SVTK_ViewWindow.h | 2 - 6 files changed, 78 insertions(+), 51 deletions(-) diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h index b974ccc22..b2cd961d9 100644 --- a/src/SVTK/SVTK_RenderWindow.h +++ b/src/SVTK/SVTK_RenderWindow.h @@ -75,8 +75,6 @@ class SVTK_EXPORT SVTK_RenderWindow : public QMainWindow //apply existing transformation on adding SALOME_Actor void SetScale( double theScale[3] ); void GetScale( double theScale[3] ); - //void AddActor( VTKViewer_Actor*, bool update = false ); - //void RemoveActor(VTKViewer_Actor*, bool update = false); public slots: virtual void activateZoom(); diff --git a/src/SVTK/SVTK_RenderWindowInteractor.cxx b/src/SVTK/SVTK_RenderWindowInteractor.cxx index 92bd03542..30df08353 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.cxx +++ b/src/SVTK/SVTK_RenderWindowInteractor.cxx @@ -247,6 +247,16 @@ SVTK_RenderWindowInteractor } +//---------------------------------------------------------------------------- +void +SVTK_RenderWindowInteractor +::contextMenuEvent( QContextMenuEvent* event ) +{ + if( !( event->state() & KeyButtonMask ) ) + emit contextMenuRequested( event ); +} + + //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor @@ -256,6 +266,8 @@ SVTK_RenderWindowInteractor ( event->state() & ControlButton ), ( event->state() & ShiftButton ) ); myInteractor->MouseMoveEvent(); + + emit MouseMove( event ); } @@ -273,6 +285,8 @@ SVTK_RenderWindowInteractor myInteractor->MiddleButtonPressEvent(); else if( event->button() & RightButton ) myInteractor->RightButtonPressEvent(); + + emit MouseButtonPressed( event ); } @@ -291,6 +305,8 @@ SVTK_RenderWindowInteractor myInteractor->MiddleButtonReleaseEvent(); else if( event->button() & RightButton ) myInteractor->RightButtonReleaseEvent(); + + emit MouseButtonReleased( event ); } @@ -298,14 +314,18 @@ SVTK_RenderWindowInteractor void SVTK_RenderWindowInteractor ::mouseDoubleClickEvent( QMouseEvent* event ) -{} +{ + emit MouseDoubleClicked( event ); +} //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor ::wheelEvent( QWheelEvent* event ) -{} +{ + emit WheelMoved( event ); +} //---------------------------------------------------------------------------- @@ -317,6 +337,8 @@ SVTK_RenderWindowInteractor ( event->state() & ShiftButton ), 0 ); myInteractor->KeyPressEvent(); + + emit KeyPressed( event ); } //---------------------------------------------------------------------------- @@ -328,36 +350,11 @@ SVTK_RenderWindowInteractor ( event->state() & ShiftButton ), 0 ); myInteractor->KeyReleaseEvent(); -} - -//---------------------------------------------------------------------------- -bool -SVTK_RenderWindowInteractor -::x11Event( XEvent *xEvent ) -{ - // handle 3d space mouse events - SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); - if ( sm->isSpaceMouseOn() && xEvent->type == ClientMessage ) { - SVTK_SpaceMouse::MoveEvent spaceMouseEvent; - int type = sm->translateEvent( x11Display(), xEvent, &spaceMouseEvent, 1.0, 1.0 ); - switch ( type ) - { - case SVTK_SpaceMouse::SpaceMouseMove : - myInteractor->InvokeEvent( SpaceMouseMoveEvent, spaceMouseEvent.data ); - break; - case SVTK_SpaceMouse::SpaceButtonPress : - myInteractor->InvokeEvent( SpaceMouseButtonEvent, &spaceMouseEvent.button ); - break; - case SVTK_SpaceMouse::SpaceButtonRelease : - break; - } - return true; // stop handling the event - } - - return SVTK_RenderWindow::x11Event( xEvent ); + emit KeyReleased( event ); } + //---------------------------------------------------------------------------- void SVTK_RenderWindowInteractor @@ -374,6 +371,8 @@ SVTK_RenderWindowInteractor } else SVTK_SpaceMouse::getInstance()->setWindow( x11Display(), winId() ); + + myInteractor->EnterEvent(); } //---------------------------------------------------------------------------- @@ -385,18 +384,37 @@ SVTK_RenderWindowInteractor // unregister set space mouse events receiver if ( SVTK_SpaceMouse::getInstance()->isSpaceMouseOn() ) SVTK_SpaceMouse::getInstance()->setWindow( x11Display(), 0 ); + + myInteractor->LeaveEvent(); } //---------------------------------------------------------------------------- -void +bool SVTK_RenderWindowInteractor -::contextMenuEvent( QContextMenuEvent* event ) +::x11Event( XEvent *xEvent ) { - if( !( event->state() & KeyButtonMask ) ) - emit contextMenuRequested( event ); -} + // handle 3d space mouse events + SVTK_SpaceMouse* sm = SVTK_SpaceMouse::getInstance(); + if ( sm->isSpaceMouseOn() && xEvent->type == ClientMessage ) { + SVTK_SpaceMouse::MoveEvent spaceMouseEvent; + int type = sm->translateEvent( x11Display(), xEvent, &spaceMouseEvent, 1.0, 1.0 ); + switch ( type ) + { + case SVTK_SpaceMouse::SpaceMouseMove : + myInteractor->InvokeEvent( SpaceMouseMoveEvent, spaceMouseEvent.data ); + break; + case SVTK_SpaceMouse::SpaceButtonPress : + myInteractor->InvokeEvent( SpaceMouseButtonEvent, &spaceMouseEvent.button ); + break; + case SVTK_SpaceMouse::SpaceButtonRelease : + break; + } + return true; // stop handling the event + } + return SVTK_RenderWindow::x11Event( xEvent ); +} //---------------------------------------------------------------------------- int diff --git a/src/SVTK/SVTK_RenderWindowInteractor.h b/src/SVTK/SVTK_RenderWindowInteractor.h index 5667ef038..c3d6e7241 100644 --- a/src/SVTK/SVTK_RenderWindowInteractor.h +++ b/src/SVTK/SVTK_RenderWindowInteractor.h @@ -111,6 +111,7 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow virtual void paintEvent( QPaintEvent* ); virtual void resizeEvent( QResizeEvent* ); + virtual void contextMenuEvent( QContextMenuEvent * e ); virtual void mouseMoveEvent( QMouseEvent* ); virtual void mousePressEvent( QMouseEvent* ); @@ -120,19 +121,27 @@ class SVTK_EXPORT SVTK_RenderWindowInteractor: public SVTK_RenderWindow virtual void keyPressEvent( QKeyEvent* ); virtual void keyReleaseEvent( QKeyEvent* ); - virtual bool x11Event( XEvent *e ); // reimplemented from QWidget in order to set window - receiver // of space mouse events. virtual void focusInEvent ( QFocusEvent* ); virtual void focusOutEvent( QFocusEvent* ); - virtual void contextMenuEvent( QContextMenuEvent * e ); + virtual bool x11Event( XEvent *e ); + public: signals: + void MouseMove( QMouseEvent* ); + void MouseButtonPressed( QMouseEvent* ); + void MouseButtonReleased( QMouseEvent* ); + void MouseDoubleClicked( QMouseEvent* ); + void WheelMoved( QWheelEvent* ); + void ButtonPressed(const QMouseEvent *event); + void ButtonReleased(const QMouseEvent *event); + void KeyPressed( QKeyEvent* ); + void KeyReleased( QKeyEvent* ); void contextMenuRequested( QContextMenuEvent *e ); public: - /* Selection Management */ bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject); bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); diff --git a/src/SVTK/SVTK_View.h b/src/SVTK/SVTK_View.h index 276793b62..9cff5031d 100644 --- a/src/SVTK/SVTK_View.h +++ b/src/SVTK/SVTK_View.h @@ -104,15 +104,7 @@ public slots: virtual void activatePanning(); virtual void activateGlobalPanning(); -protected slots: - void onKeyPressed(QKeyEvent* event); - void onKeyReleased(QKeyEvent* event); - void onMousePressed(QMouseEvent* event); - void onMouseDoubleClicked(QMouseEvent* event); - void onMouseReleased(QMouseEvent* event); - void onMouseMoving(QMouseEvent* event); - -private: +protected: void InitialSetup(); void InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors = false ); diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 907010801..8b5dc9bb4 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -75,8 +75,20 @@ SVTK_ViewWindow myView->setFocusPolicy( StrongFocus ); myView->setFocus(); + connect( myView, SIGNAL(KeyPressed( QKeyEvent* )), + this, SLOT(onKeyPressed( QKeyEvent* )) ); + connect( myView, SIGNAL(KeyReleased( QKeyEvent* )), + this, SLOT(onKeyReleased( QKeyEvent* )) ); + connect( myView, SIGNAL(MouseButtonPressed( QMouseEvent* )), + this, SLOT(onMousePressed( QMouseEvent* )) ); + connect( myView, SIGNAL(MouseButtonReleased( QMouseEvent* )), + this, SLOT(onMouseReleased( QMouseEvent* )) ); + connect( myView, SIGNAL(MouseDoubleClicked( QMouseEvent* )), + this, SLOT(onMouseDoubleClicked( QMouseEvent* )) ); + connect( myView, SIGNAL(MouseMove( QMouseEvent* )), + this, SLOT(onMouseMoving( QMouseEvent* )) ); connect( myView, SIGNAL(contextMenuRequested( QContextMenuEvent * )), - this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); + this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) ); onResetView(); diff --git a/src/SVTK/SVTK_ViewWindow.h b/src/SVTK/SVTK_ViewWindow.h index ff2ebada8..c985c2108 100755 --- a/src/SVTK/SVTK_ViewWindow.h +++ b/src/SVTK/SVTK_ViewWindow.h @@ -83,8 +83,6 @@ public: void RemoveActor(VTKViewer_Actor*, bool update = false); void AdjustTrihedrons( const bool forced ); - //merge with V2_2_0_VISU_improvements:bool ComputeTrihedronSize( double& theNewSize, - //merge with V2_2_0_VISU_improvements: double& theOldSize ); VTKViewer_Trihedron* GetTrihedron(); SVTK_CubeAxesActor2D* GetCubeAxes(); -- 2.39.2