Salome HOME
Support both 5.5 and 5.6 version of ParaView
[modules/gui.git] / src / GraphicsView / GraphicsView_Viewer.cxx
index 5fb5eb0825e37e0fc6e9effec082b8115bac35d8..cc55ba5d7361d6457e0bc8f6f97680ee21e72fc0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -37,6 +37,8 @@
 #include <QKeyEvent>
 #include <QMenu>
 
+#include <math.h>
+
 // testing ImageViewer
 /*
 #include "GraphicsView_PrsImage.h"
@@ -66,13 +68,18 @@ GraphicsView_Viewer::~GraphicsView_Viewer()
   delete mySelector;
 }
 
+GraphicsView_ViewFrame* GraphicsView_Viewer::createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget )
+{
+  return new GraphicsView_ViewFrame( theDesktop, this, theWidget );
+}
+
 //================================================================
 // Function : createView
 // Purpose  : 
 //================================================================
 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
 {
-  GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this, myWidget );
+  GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget );
 
   connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
            this, SLOT( onKeyEvent( QKeyEvent* ) ) );
@@ -399,7 +406,9 @@ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
       }
       else if( e->button() == Qt::LeftButton &&
                !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
-               !aViewPort->getHighlightedObject() )
+               !aViewPort->getHighlightedObject() &&
+               ( !aViewPort->isDraggingSelectedByLeftButton() ||
+                 aViewPort->isDraggingSelectedByLeftButton() && aViewPort->nbSelected() == 0 ) )
       {
         // Start rectangular selection if pulling was not started
         QPoint p = aViewPort->mapFromScene( e->scenePos() );
@@ -521,6 +530,16 @@ void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
 {
   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
   {
+    if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling ) )
+    {
+      const double d = 1.05;
+      double q = pow( d, e->delta()/120 );
+      QGraphicsView::ViewportAnchor old_anchor = aViewPort->transformationAnchor();
+      aViewPort->setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
+      aViewPort->scale( q, q );
+      aViewPort->setTransformationAnchor( old_anchor );
+    }
+
     if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
     {
       bool anIsScaleUp = e->delta() > 0;