mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
@@ -21,6 +21,7 @@ ${CEE_CURRENT_LIST_DIR}RiuProjectPropertyView.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuPropertyViewTabWidget.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtScalePicker.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtCurvePointTracker.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtPlotWheelZoomer.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuRecentFileActionProvider.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuResultInfoPanel.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuResultQwtPlot.h
|
||||
@@ -62,6 +63,7 @@ ${CEE_CURRENT_LIST_DIR}RiuProjectPropertyView.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuPropertyViewTabWidget.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtScalePicker.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtCurvePointTracker.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtPlotWheelZoomer.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuRecentFileActionProvider.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuResultInfoPanel.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RiuResultQwtPlot.cpp
|
||||
@@ -109,6 +111,7 @@ ${CEE_CURRENT_LIST_DIR}RiuWellLogTrack.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuRecentFileActionProvider.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuSummaryQwtPlot.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtScalePicker.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuQwtPlotWheelZoomer.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuExportMultipleSnapshotsWidget.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuWellAllocationPlot.h
|
||||
${CEE_CURRENT_LIST_DIR}RiuFlowCharacteristicsPlot.h
|
||||
|
||||
75
ApplicationCode/UserInterface/RiuQwtPlotWheelZoomer.cpp
Normal file
75
ApplicationCode/UserInterface/RiuQwtPlotWheelZoomer.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiuQwtPlotWheelZoomer.h"
|
||||
#include "qwt_plot.h"
|
||||
#include <QEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#define RIU_SCROLLWHEEL_ZOOMFACTOR 1.1
|
||||
#define RIU_SCROLLWHEEL_PANFACTOR 0.1
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuQwtPlotWheelZoomer::RiuQwtPlotWheelZoomer(QwtPlot* plot): QObject(plot), m_plot(plot)
|
||||
{
|
||||
plot->canvas()->installEventFilter(this);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void zoomOnAxis(QwtPlot* plot, QwtPlot::Axis axis, double zoomFactor, int eventPos)
|
||||
{
|
||||
QwtScaleMap scaleMap = plot->canvasMap(axis);
|
||||
double zoomCenter = scaleMap.invTransform(eventPos);
|
||||
double newMin = zoomCenter - zoomFactor * (zoomCenter - scaleMap.s1());
|
||||
double newMax = zoomCenter + zoomFactor * (-zoomCenter + scaleMap.s2());
|
||||
plot->setAxisScale(axis, newMin, newMax);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuQwtPlotWheelZoomer::eventFilter(QObject * watched, QEvent * event)
|
||||
{
|
||||
QWheelEvent* wheelEvent = dynamic_cast<QWheelEvent*>(event);
|
||||
if ( wheelEvent )
|
||||
{
|
||||
if ( wheelEvent->modifiers() )
|
||||
{
|
||||
double zoomFactor = 1.0/RIU_SCROLLWHEEL_ZOOMFACTOR;
|
||||
if ( wheelEvent->delta() > 0 )
|
||||
{
|
||||
zoomFactor = RIU_SCROLLWHEEL_ZOOMFACTOR;
|
||||
}
|
||||
|
||||
zoomOnAxis(m_plot, QwtPlot::xBottom, zoomFactor, wheelEvent->pos().x());
|
||||
zoomOnAxis(m_plot, QwtPlot::xTop, zoomFactor, wheelEvent->pos().x());
|
||||
zoomOnAxis(m_plot, QwtPlot::yLeft, zoomFactor, wheelEvent->pos().y());
|
||||
zoomOnAxis(m_plot, QwtPlot::yRight, zoomFactor, wheelEvent->pos().y());
|
||||
|
||||
m_plot->replot();
|
||||
emit zoomUpdated();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
40
ApplicationCode/UserInterface/RiuQwtPlotWheelZoomer.h
Normal file
40
ApplicationCode/UserInterface/RiuQwtPlotWheelZoomer.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017- Statoil ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QwtPlot;
|
||||
class QEvent;
|
||||
|
||||
class RiuQwtPlotWheelZoomer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RiuQwtPlotWheelZoomer(QwtPlot* plot);
|
||||
|
||||
virtual bool eventFilter(QObject * watched, QEvent * event) override;
|
||||
|
||||
signals:
|
||||
void zoomUpdated();
|
||||
|
||||
private:
|
||||
QwtPlot* m_plot;
|
||||
};
|
||||
|
||||
|
||||
@@ -66,19 +66,21 @@ RiuSummaryQwtPlot::RiuSummaryQwtPlot(RimSummaryPlot* plotDefinition, QWidget* pa
|
||||
m_zoomerLeft->setTrackerPen(QColor(Qt::black));
|
||||
m_zoomerLeft->initMousePattern(1);
|
||||
|
||||
// MidButton for the panning
|
||||
QwtPlotPanner* panner = new QwtPlotPanner(canvas());
|
||||
panner->setMouseButton(Qt::MidButton);
|
||||
|
||||
connect(m_zoomerLeft, SIGNAL(zoomed( const QRectF & )), SLOT(onZoomedSlot()));
|
||||
connect(panner, SIGNAL(panned( int , int )), SLOT(onZoomedSlot()));
|
||||
|
||||
// Attach a zoomer for the right axis
|
||||
m_zoomerRight = new QwtPlotZoomer(canvas());
|
||||
m_zoomerRight->setAxis(xTop, yRight);
|
||||
m_zoomerRight->setTrackerMode(QwtPicker::AlwaysOff);
|
||||
m_zoomerRight->initMousePattern(1);
|
||||
|
||||
// MidButton for the panning
|
||||
QwtPlotPanner* panner = new QwtPlotPanner(canvas());
|
||||
panner->setMouseButton(Qt::MidButton);
|
||||
|
||||
auto wheelZoomer = new RiuQwtPlotWheelZoomer(this);
|
||||
|
||||
connect(wheelZoomer, SIGNAL(zoomUpdated()), SLOT(onZoomedSlot()));
|
||||
connect(m_zoomerLeft, SIGNAL(zoomed( const QRectF & )), SLOT(onZoomedSlot()));
|
||||
connect(panner, SIGNAL(panned( int , int )), SLOT(onZoomedSlot()));
|
||||
|
||||
RiuQwtScalePicker* scalePicker = new RiuQwtScalePicker(this);
|
||||
connect(scalePicker, SIGNAL(clicked(int, double)), this, SLOT(onAxisClicked(int, double)));
|
||||
|
||||
Reference in New Issue
Block a user