From d26b30617c1378fd65c526f7d6cd4fe1c02ee5e3 Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 27 Aug 2012 08:00:04 +0000 Subject: [PATCH] 0021814: [CEA 643] wheel-zoom per axis in plot2D viewer Process wheel event properly: when mouse pointer is on some scale (x, y1 or y2) - zooming is only done for this scale. --- src/Plot2d/Plot2d_ViewFrame.cxx | 46 +++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index b9fd235cf..6995c9fa3 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -57,6 +57,7 @@ #include #include +#include #include #include #include @@ -191,6 +192,7 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) myLNormAlgo = new Plot2d_NormalizeAlgorithm(this); /* Plot 2d View */ QVBoxLayout* aLayout = new QVBoxLayout( this ); + aLayout->setMargin(0); myPlot = new Plot2d_Plot2d( this ); new Plot2d_ToolTip( this ); @@ -2616,25 +2618,47 @@ void Plot2d_ViewFrame::plotMouseReleased( const QMouseEvent& me ) */ void Plot2d_ViewFrame::wheelEvent(QWheelEvent* event) { + QwtPlotLayout* pl = myPlot->plotLayout(); + + // compute zooming factor double aDelta = event->delta(); double aScale = (aDelta < 0) ? 100./(-aDelta) : aDelta/100.; - QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); - QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); - - if ( ((yMap.s2() - yMap.s1()) < 10e-13 || (xMap.s2() - xMap.s1()) < 10e-13 ) && aScale < 1 ) - return; + bool scaleXBottom = pl->scaleRect(QwtPlot::xBottom).contains( event->pos() ) || + pl->canvasRect().contains( event->pos() ); + bool scaleYLeft = pl->scaleRect(QwtPlot::yLeft).contains( event->pos() ) || + pl->canvasRect().contains( event->pos() ); + bool scaleYRight = mySecondY && ( pl->scaleRect(QwtPlot::yRight).contains( event->pos() ) || + pl->canvasRect().contains( event->pos() ) ); + + // scale x bottom axis + if ( scaleXBottom ) { + QwtScaleMap xMap = myPlot->canvasMap( QwtPlot::xBottom ); + if ( xMap.s2() - xMap.s1() > 1.0e-12 || aScale > 1 ) + myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s1() + aScale*(xMap.s2() - xMap.s1()) ); + } + + // scale y left axis + if ( scaleYLeft ) { + QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yLeft ); + if ( yMap.s2() - yMap.s1() > 1.0e-12 || aScale > 1 ) + myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) ); + } - myPlot->setAxisScale( QwtPlot::yLeft, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) ); - myPlot->setAxisScale( QwtPlot::xBottom, xMap.s1(), xMap.s1() + aScale*(xMap.s2() - xMap.s1()) ); - if (mySecondY) { - QwtScaleMap y2Map = myPlot->canvasMap( QwtPlot::yRight ); - if ( ((y2Map.s2() - y2Map.s1()) < 10e-13 ) && aScale < 1 ) return; - myPlot->setAxisScale( QwtPlot::yRight, y2Map.s1(), y2Map.s1() + aScale*(y2Map.s2() - y2Map.s1()) ); + // scale y right axis (note: mySecondY value is checked above) + if ( scaleYRight ) { + QwtScaleMap yMap = myPlot->canvasMap( QwtPlot::yRight ); + if ( yMap.s2() - yMap.s1() > 10e-12 || aScale > 1 ) + myPlot->setAxisScale( QwtPlot::yRight, yMap.s1(), yMap.s1() + aScale*(yMap.s2() - yMap.s1()) ); } + + // redraw myPlot->replot(); + // update zoomer if ( myPlot->zoomer() ) myPlot->zoomer()->setZoomBase(); + // store current mouse position myPnt = event->pos(); + // update analytical curves updateAnalyticalCurves(); } -- 2.39.2