From 7532b52dd10c89d637688e96b315442a4f9e52b4 2016-06-29 22:22:17 From: jeandet Date: 2016-06-29 22:22:17 Subject: [PATCH] Added parametric zoom on QChart. Signed-off-by: jeandet --- diff --git a/src/charts/qchart.cpp b/src/charts/qchart.cpp index 67af761..1d4ff29 100644 --- a/src/charts/qchart.cpp +++ b/src/charts/qchart.cpp @@ -354,6 +354,11 @@ void QChart::zoomIn() d_ptr->zoomIn(2.0); } +void QChart::zoomIn2(double factor) +{ + d_ptr->zoomIn2(factor); +} + /*! Zooms in the view to a maximum level at which \a rect is still fully visible. \note This is not supported for polar charts. @@ -373,6 +378,11 @@ void QChart::zoomOut() d_ptr->zoomOut(2.0); } +void QChart::zoomOut2(double factor) +{ + d_ptr->zoomOut2(factor); +} + /*! Zooms in the view by a custom \a factor. @@ -834,6 +844,14 @@ void QChartPrivate::zoomIn(qreal factor) zoomIn(rect); } +void QChartPrivate::zoomIn2(qreal factor) +{ + QRectF rect = m_presenter->geometry(); + rect.setWidth(rect.width() / factor); + rect.moveCenter(m_presenter->geometry().center()); + zoomIn(rect); +} + void QChartPrivate::zoomIn(const QRectF &rect) { if (!rect.isValid()) @@ -879,6 +897,24 @@ void QChartPrivate::zoomOut(qreal factor) m_presenter->setState(ChartPresenter::ShowState,QPointF()); } +void QChartPrivate::zoomOut2(qreal factor) +{ + const QRectF geometry = m_presenter->geometry(); + + QRectF r; + QSizeF size = geometry.size(); + size.setWidth(size.width()/factor); + r.setSize(size); + r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); + if (!r.isValid()) + return; + + QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); + m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); + m_dataset->zoomOutDomain(r); + m_presenter->setState(ChartPresenter::ShowState,QPointF()); +} + void QChartPrivate::scroll(qreal dx, qreal dy) { if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); diff --git a/src/charts/qchart.h b/src/charts/qchart.h index 40b53a8..21ee8fd 100644 --- a/src/charts/qchart.h +++ b/src/charts/qchart.h @@ -147,7 +147,9 @@ public: QEasingCurve animationEasingCurve() const; void zoomIn(); + void zoomIn2(double factor); void zoomOut(); + void zoomOut2(double factor); void zoomIn(const QRectF &rect); void zoom(qreal factor); diff --git a/src/charts/qchart_p.h b/src/charts/qchart_p.h index 1f11b3c..05441c7 100644 --- a/src/charts/qchart_p.h +++ b/src/charts/qchart_p.h @@ -68,7 +68,9 @@ public: void init(); void zoomIn(qreal factor); + void zoomIn2(qreal factor); void zoomOut(qreal factor); + void zoomOut2(qreal factor); void zoomIn(const QRectF &rect); void zoomReset(); bool isZoomed();