From 41cec17cfffb2dfc6d8b10ec9619f81a3bc9416d Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 10 Mar 2014 17:59:02 +0200 Subject: Profile2: reset the zoom level when a new profile is drawn If the user has zoomed in but then changes to a new dive, we may want to reset the scale back to the original value (1.0) based on the current zoomLevel, so that the profile is not stuck in zoomed mode. This patch adds a snippet that resets the QGraphicsView scale, zoomLevel variable and also the toolTip position. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- qt-ui/profile/profilewidget2.cpp | 15 ++++++++++++--- qt-ui/profile/profilewidget2.h | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index d7a2228f4..822f1bc7f 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #ifndef QT_NO_DEBUG #include @@ -59,6 +60,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), dataModel(new DivePlotDataModel(this)), currentState(INVALID), zoomLevel(0), + zoomFactor(1.15), background(new DivePixmapItem()), toolTipItem(new ToolTipItem()), isPlotZoomed(prefs.zoomed_plot), @@ -320,6 +322,14 @@ void ProfileWidget2::plotDives(QList dives) if (!d) return; + // restore default zoom level and tooltip position + if (zoomLevel) { + const qreal defScale = 1.0 / qPow(zoomFactor, (qreal)zoomLevel); + scale(defScale, defScale); + zoomLevel = 0; + } + toolTipItem->setPos(0, 0); + // No need to do this again if we are already showing the same dive // computer of the same dive, so we check the unique id of the dive // and the selected dive computer number against the ones we are @@ -478,13 +488,12 @@ void ProfileWidget2::wheelEvent(QWheelEvent *event) if (currentState == EMPTY) return; QPoint toolTipPos = mapFromScene(toolTipItem->pos()); - double scaleFactor = 1.15; if (event->delta() > 0 && zoomLevel < 20) { - scale(scaleFactor, scaleFactor); + scale(zoomFactor, zoomFactor); zoomLevel++; } else if (event->delta() < 0 && zoomLevel > 0) { // Zooming out - scale(1.0 / scaleFactor, 1.0 / scaleFactor); + scale(1.0 / zoomFactor, 1.0 / zoomFactor); zoomLevel--; } scrollViewTo(event->pos()); diff --git a/qt-ui/profile/profilewidget2.h b/qt-ui/profile/profilewidget2.h index c6c9adf93..b5339edef 100644 --- a/qt-ui/profile/profilewidget2.h +++ b/qt-ui/profile/profilewidget2.h @@ -93,6 +93,7 @@ private: DivePlotDataModel *dataModel; State currentState; int zoomLevel; + qreal zoomFactor; DivePixmapItem *background; QString backgroundFile; ToolTipItem *toolTipItem; -- cgit v1.2.3-70-g09d2