]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Handling wheel events to control longitudial and lateral scale of the presentation...
authorouv <ouv@opencascade.com>
Mon, 20 Dec 2010 13:59:59 +0000 (13:59 +0000)
committerouv <ouv@opencascade.com>
Mon, 20 Dec 2010 13:59:59 +0000 (13:59 +0000)
src/GraphicsView/GraphicsView_Object.h
src/GraphicsView/GraphicsView_Scene.cxx
src/GraphicsView/GraphicsView_Scene.h
src/GraphicsView/GraphicsView_ViewFrame.cxx
src/GraphicsView/GraphicsView_Viewer.cxx
src/GraphicsView/GraphicsView_Viewer.h

index 7998b4d3ed01b9dbcbf23d90f630dc309c91ac32..7cb2a18c1865304ba53b4f5d13da524688088d61 100644 (file)
@@ -61,6 +61,8 @@ public:
   virtual bool               isMovingByXAllowed( double theDX ) { return true; }
   virtual bool               isMovingByYAllowed( double theDY ) { return true; }
 
+  virtual bool               updateScale( bool theIsScaleUp, bool theIsCtrl ) { return false; }
+
   virtual QRectF             getPullingRect() const { return getRect(); }
   virtual bool               portContains( const QPointF& ) { return false; }
   virtual bool               startPulling( const QPointF& ) { return false; }
index 2b66a218c02df73c25bebe2376d1db04628049ea..42d50ed4a5580223796f3e42f7afea5581dca7dc 100644 (file)
@@ -79,6 +79,21 @@ void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
   QGraphicsScene::mouseDoubleClickEvent( e );
 }
 
+//================================================================
+// Function : wheelEvent
+// Purpose  : 
+//================================================================
+void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e )
+{
+  emit gsWheelEvent( e );
+
+  // accept the event to prevent calling QAbstractScrollArea::wheelEvent()
+  // from QGraphicsView::wheelEvent(), which will change values of scroll-bars
+  e->accept();
+
+  //QGraphicsScene::wheelEvent( e ); // don't uncomment
+}
+
 //================================================================
 // Function : contextMenuEvent
 // Purpose  : 
index d949cdf60dc9e910c3bcc24a867ec8cd75a4b153..e67cd8bfcee12d8eec3a5c895de633d2998de2c7 100644 (file)
@@ -44,6 +44,7 @@ protected:
   virtual void               mouseMoveEvent( QGraphicsSceneMouseEvent* );
   virtual void               mouseReleaseEvent( QGraphicsSceneMouseEvent* );
   virtual void                      mouseDoubleClickEvent( QGraphicsSceneMouseEvent* );
+  virtual void               wheelEvent( QGraphicsSceneWheelEvent* );
   virtual void               contextMenuEvent( QGraphicsSceneContextMenuEvent* );
 
   virtual void               dragEnterEvent( QGraphicsSceneDragDropEvent* );
index c04eabbd81f4d37bfc68d2e854a895055ff944ad..77df4f75a727818a92c8aa60c5ac3b3aa7b4a866 100644 (file)
@@ -288,7 +288,7 @@ void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e )
 {
   switch ( e->type() )
   {
-    case QEvent::Wheel:
+    case QEvent::GraphicsSceneWheel:
       emit wheeling( e );
       break;
     default:
index d09ed715ab07fcd56bffc045ada96feda9ced84e..a7da60b45270921b599c786e45a81d723ae5d68c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "GraphicsView_Viewer.h"
 
+#include "GraphicsView_Object.h"
 #include "GraphicsView_Selector.h"
 #include "GraphicsView_Scene.h"
 #include "GraphicsView_ViewFrame.h"
@@ -258,7 +259,7 @@ void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
 {
   switch( e->type() )
   {
-    case QEvent::Wheel:
+    case QEvent::GraphicsSceneWheel:
       handleWheel( e );
       break;
     default: break;
@@ -308,13 +309,16 @@ void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
 {
   // selection
-  if( e->button() == Qt::LeftButton &&
-      !( getActiveViewPort()->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
+  if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
   {
-    if ( getSelector() )
+    if( e->button() == Qt::LeftButton &&
+        !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
     {
-      bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
-      getSelector()->select( QRectF(), append );
+      if ( getSelector() )
+      {
+        bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
+        getSelector()->select( QRectF(), append );
+      }
     }
   }
 
@@ -378,6 +382,8 @@ void GraphicsView_Viewer::onSelectionCancel()
 void GraphicsView_Viewer::startOperations( QGraphicsSceneMouseEvent* e )
 {
   GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+  if( !aViewPort )
+    return;
 
   // If the 'immediate selection' mode is enabled,
   // try to perform selection before invoking context menu
@@ -417,6 +423,8 @@ void GraphicsView_Viewer::startOperations( QGraphicsSceneMouseEvent* e )
 bool GraphicsView_Viewer::updateOperations( QGraphicsSceneMouseEvent* e )
 {
   GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+  if( !aViewPort )
+    return false;
 
   if( aViewPort->isPulling() )
   {
@@ -449,6 +457,8 @@ bool GraphicsView_Viewer::updateOperations( QGraphicsSceneMouseEvent* e )
 bool GraphicsView_Viewer::finishOperations( QGraphicsSceneMouseEvent* e )
 {
   GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+  if( !aViewPort )
+    return false;
 
   if( aViewPort->isPulling() )
   {
@@ -474,3 +484,25 @@ bool GraphicsView_Viewer::finishOperations( QGraphicsSceneMouseEvent* e )
 
   return false;
 }
+
+//================================================================
+// Function : startOperations
+// Purpose  : 
+//================================================================
+void GraphicsView_Viewer::startOperations( QGraphicsSceneWheelEvent* e )
+{
+  GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+  if( !aViewPort )
+    return;
+
+  bool anIsScaleUp = e->delta() > 0;
+  bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
+
+  bool anIsScaleChanged = false;
+  for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
+    if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
+      anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
+
+  if( anIsScaleChanged )
+    emit wheelScaleChanged();
+}
index f6d70147ef6a64e442b040bf9f3b744a3f56a69c..4fb7943cc67072fb50661afa025631eb30c2abdd 100644 (file)
@@ -80,6 +80,7 @@ public:
 
 signals:
   void                          selectionChanged( GV_SelectionChangeStatus );
+  void                          wheelScaleChanged();
 
 protected:
   virtual GraphicsView_ViewTransformer* createTransformer( int );
@@ -90,7 +91,7 @@ protected:
   virtual void                  startOperations( QGraphicsSceneMouseEvent* );
   virtual bool                  updateOperations( QGraphicsSceneMouseEvent* );
   virtual bool                  finishOperations( QGraphicsSceneMouseEvent* );
-  virtual void                  startOperations( QGraphicsSceneWheelEvent* ) {}
+  virtual void                  startOperations( QGraphicsSceneWheelEvent* );
 
 protected slots:
   virtual void                  onMouseEvent( QGraphicsSceneMouseEvent* );