From 7f3b487c77c71cc7e3f62bfd2ebde4559a0a6e56 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 1 May 2014 14:48:14 -0700 Subject: Restore the previous globe zoom level after showing dive without GPS Thanks to commit 83c5ab58718e ("Zoom out when dive has no coords.") we show more of the globe when displaying dives without GPS data - but that caused us to forget the zoom level we used before and so the experience when switching back to a dive with GPS data was disappointing. This makes sure we track the last valid zoom level and restore it when needed. I also replaced the deprecated zoomView() calls with setZoom() calls. Signed-off-by: Dirk Hohndel --- qt-ui/globe.cpp | 35 +++++++++++++++++++++++++---------- qt-ui/globe.h | 1 + 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index 9f4ac62b9..03dccfe14 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -30,6 +30,7 @@ GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent), messageWidget(new KMessageWidget(this)), fixZoomTimer(new QTimer(this)), currentZoomLevel(0), + needResetZoom(false), editingDiveLocation(false) { // check if Google Sat Maps are installed @@ -214,12 +215,17 @@ void GlobeGPS::centerOn(dive *dive) return; } - // set the zoom as seen from n kilometer above. 3km / 10,000ft seems pleasant - // do not change it it was already modified by user - if (!zoom()) - zoomView(zoomFromDistance(3)); - - if (!fixZoomTimer->isActive()) + // if no zoom is set up, set the zoom as seen from 3km above + // if we come back from a dive without GPS data, reset to the last zoom value + // otherwise check to make sure we aren't still running an animation and then remember + // the current zoom level + if (!zoom()) { + currentZoomLevel = zoomFromDistance(3); + fixZoom(); + } else if (needResetZoom) { + needResetZoom = false; + fixZoom(); + } else if (!fixZoomTimer->isActive()) currentZoomLevel = zoom(); // From the marble source code, the maximum time of // 'spin and fit' is 2 seconds, so wait a bit them zoom again. @@ -230,7 +236,7 @@ void GlobeGPS::centerOn(dive *dive) void GlobeGPS::fixZoom() { - zoomView(currentZoomLevel, Marble::Linear); + setZoom(currentZoomLevel, Marble::Linear); } void GlobeGPS::prepareForGetDiveCoordinates() @@ -241,9 +247,18 @@ void GlobeGPS::prepareForGetDiveCoordinates() messageWidget->setWordWrap(true); messageWidget->animatedShow(); editingDiveLocation = true; - if(fixZoomTimer->isActive()) - fixZoomTimer->stop(); - setZoom(1200, Marble::Automatic); + // if the dive has no GPS location, zoom out quite a bit to show the globe + // and remember that the next time we show a dive with GPS location we need + // to zoom in again + if (!dive_has_gps_location(current_dive)) { + if(fixZoomTimer->isActive()) + fixZoomTimer->stop(); + setZoom(1200, Marble::Automatic); + if (!needResetZoom) { + needResetZoom = true; + currentZoomLevel = zoom(); + } + } } } diff --git a/qt-ui/globe.h b/qt-ui/globe.h index f5a1e4053..51bda4878 100644 --- a/qt-ui/globe.h +++ b/qt-ui/globe.h @@ -32,6 +32,7 @@ private: KMessageWidget *messageWidget; QTimer *fixZoomTimer; int currentZoomLevel; + bool needResetZoom; bool editingDiveLocation; public -- cgit v1.2.3-70-g09d2