1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "OCCViewer_ViewportInputFilter.h"
24 #include "OCCViewer_ViewManager.h"
25 #include "OCCViewer_ViewModel.h"
26 #include "OCCViewer_ViewWindow.h"
27 #include "OCCViewer_ViewPort3d.h"
29 #include <QMouseEvent>
34 \param theVM [in] the view manager to embed the filter into.
35 \param theParent [in] the parent object.
37 OCCViewer_ViewportInputFilter::OCCViewer_ViewportInputFilter( OCCViewer_ViewManager* theVM,
39 : QObject( theParent ),
47 OCCViewer_ViewportInputFilter::~OCCViewer_ViewportInputFilter()
53 \brief Enables or disables event processing within the viewer.
55 void OCCViewer_ViewportInputFilter::setEnabled(const bool theIsEnabled)
57 if ( theIsEnabled == myIsEnabled )
64 // install event filtering on viewer windows
65 myViewer = (OCCViewer_Viewer*) myVM->getViewModel();
66 if ( !myVM || !myViewer )
71 connect( myVM, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
72 connect( myVM, SIGNAL( deleteView ( SUIT_ViewWindow* ) ), SLOT( onViewRemoved( SUIT_ViewWindow* ) ) );
74 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
75 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
76 for ( ; aViewIt != aViews.end(); ++aViewIt )
78 connectView( *aViewIt );
83 // remove event filtering from viewer windows
84 QVector<SUIT_ViewWindow*> aViews = myVM->getViews();
85 QVector<SUIT_ViewWindow*>::iterator aViewIt = aViews.begin();
86 for ( ; aViewIt != aViews.end(); ++aViewIt )
88 disconnectView( *aViewIt );
92 myIsEnabled = theIsEnabled;
96 \brief Base-level implementation of event filtering.
97 Routes user input events to associated implementation methods.
98 \param theObject [in] the filtered object.
99 \param theEvent [in] the incoming event.
101 bool OCCViewer_ViewportInputFilter::eventFilter( QObject* theObject, QEvent* theEvent )
103 OCCViewer_ViewPort3d* aViewPort = (OCCViewer_ViewPort3d*) theObject;
110 switch ( theEvent->type() )
112 case QEvent::MouseMove : return mouseMove( (QMouseEvent*)theEvent, aViewPort );
113 case QEvent::MouseButtonPress : return mousePress( (QMouseEvent*)theEvent, aViewPort );
114 case QEvent::MouseButtonRelease : return mouseRelease( (QMouseEvent*)theEvent, aViewPort );
115 case QEvent::MouseButtonDblClick : return mouseDoubleClick( (QMouseEvent*)theEvent, aViewPort );
116 case QEvent::KeyPress : return keyPress( (QKeyEvent*)theEvent, aViewPort );
117 case QEvent::KeyRelease : return keyRelease( (QKeyEvent*)theEvent, aViewPort );
124 \brief Connects view to event processing.
125 \param theView [in] the view to connect.
127 void OCCViewer_ViewportInputFilter::connectView( SUIT_ViewWindow* theView )
129 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->installEventFilter( this );
133 \brief Disconnects view to event processing.
134 \param theView [in] the view to disconnect.
136 void OCCViewer_ViewportInputFilter::disconnectView( SUIT_ViewWindow* theView )
138 ( (OCCViewer_ViewWindow*) theView )->getViewPort()->removeEventFilter( this );
142 \brief Connects newly created within viewer to event processing.
143 \param theView [in] the view to connect.
145 void OCCViewer_ViewportInputFilter::onViewCreated( SUIT_ViewWindow* theView )
147 connectView( theView );
151 \brief Disconnects view being removed from viewer.
152 \param theView [in] the view to disconnect.
154 void OCCViewer_ViewportInputFilter::onViewRemoved( SUIT_ViewWindow* theView )
156 disconnectView( theView );