Globe: another attempt to fix the globe zoom

The fact that Marble doesn't tell us when it's done flying to the next
point is making this excessively complicated to get right.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-08 13:45:24 -07:00
parent 33a7e5cd73
commit 83e5e4933f
2 changed files with 28 additions and 16 deletions

View file

@ -47,7 +47,7 @@ GlobeGPS::GlobeGPS(QWidget *parent) : MarbleWidget(parent),
// been processed but before we initialize the rest of Marble // been processed but before we initialize the rest of Marble
Marble::MarbleDebug::setEnabled(verbose); Marble::MarbleDebug::setEnabled(verbose);
#endif #endif
currentZoomLevel = zoomFromDistance(3.0); currentZoomLevel = -1;
// check if Google Sat Maps are installed // check if Google Sat Maps are installed
// if not, check if they are in a known location // if not, check if they are in a known location
MapThemeManager mtm; MapThemeManager mtm;
@ -241,7 +241,7 @@ void GlobeGPS::repopulateLabels()
struct dive_site *center = displayed_dive_site.uuid != 0 ? struct dive_site *center = displayed_dive_site.uuid != 0 ?
&displayed_dive_site : current_dive ? &displayed_dive_site : current_dive ?
get_dive_site_by_uuid(current_dive->dive_site_uuid) : NULL; get_dive_site_by_uuid(current_dive->dive_site_uuid) : NULL;
if(center) if(dive_site_has_gps_location(&displayed_dive_site) && center)
centerOn(displayed_dive_site.longitude.udeg / 1000000.0, displayed_dive_site.latitude.udeg / 1000000.0, true); centerOn(displayed_dive_site.longitude.udeg / 1000000.0, displayed_dive_site.latitude.udeg / 1000000.0, true);
} }
@ -260,7 +260,6 @@ void GlobeGPS::centerOnDiveSite(uint32_t uuid)
zoomOutForNoGPS(); zoomOutForNoGPS();
return; return;
} }
qreal longitude = ds->longitude.udeg / 1000000.0; qreal longitude = ds->longitude.udeg / 1000000.0;
qreal latitude = ds->latitude.udeg / 1000000.0; qreal latitude = ds->latitude.udeg / 1000000.0;
@ -268,24 +267,36 @@ void GlobeGPS::centerOnDiveSite(uint32_t uuid)
// if we come back from a dive without GPS data, reset to the last zoom value // 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 // otherwise check to make sure we aren't still running an animation and then remember
// the current zoom level // the current zoom level
if (fixZoomTimer->isActive()) { if (currentZoomLevel == -1) {
fixZoomTimer->stop(); currentZoomLevel = zoomFromDistance(3.0);
} else if (needResetZoom) { centerOn(longitude, latitude);
fixZoom(true);
return;
}
if (!fixZoomTimer->isActive()) {
if (needResetZoom) {
needResetZoom = false; needResetZoom = false;
fixZoom(); fixZoom();
} else if (zoom() > 1000) { } else if (zoom() >= 1200) {
currentZoomLevel = zoom(); currentZoomLevel = zoom();
} }
}
// From the marble source code, the maximum time of // From the marble source code, the maximum time of
// 'spin and fit' is 2000 miliseconds so wait a bit them zoom again. // 'spin and fit' is 2000 miliseconds so wait a bit them zoom again.
fixZoomTimer->stop();
if (zoom() < 1200 && IS_FP_SAME(centerLatitude(), latitude) && IS_FP_SAME(centerLongitude(), longitude)) {
// create a tiny movement
centerOn(longitude + 0.00001, latitude + 0.00001);
fixZoomTimer->start(300);
} else {
fixZoomTimer->start(2100); fixZoomTimer->start(2100);
}
centerOn(longitude, latitude, true); centerOn(longitude, latitude, true);
} }
void GlobeGPS::fixZoom() void GlobeGPS::fixZoom(bool now)
{ {
setZoom(currentZoomLevel, Marble::Linear); setZoom(currentZoomLevel, now ? Marble::Instant : Marble::Linear);
} }
void GlobeGPS::zoomOutForNoGPS() void GlobeGPS::zoomOutForNoGPS()
@ -295,9 +306,10 @@ void GlobeGPS::zoomOutForNoGPS()
// we show a dive with GPS location we need to zoom in again // we show a dive with GPS location we need to zoom in again
if (!needResetZoom) { if (!needResetZoom) {
needResetZoom = true; needResetZoom = true;
if (!fixZoomTimer->isActive()) if (!fixZoomTimer->isActive() && zoom() >= 1500) {
currentZoomLevel = zoom(); currentZoomLevel = zoom();
} }
}
if (fixZoomTimer->isActive()) if (fixZoomTimer->isActive())
fixZoomTimer->stop(); fixZoomTimer->stop();
// 1000 is supposed to make sure you see the whole globe // 1000 is supposed to make sure you see the whole globe

View file

@ -47,7 +47,7 @@ slots:
void repopulateLabels(); void repopulateLabels();
void changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit); void changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit);
void mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit); void mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit);
void fixZoom(); void fixZoom(bool now = false);
void zoomOutForNoGPS(); void zoomOutForNoGPS();
void prepareForGetDiveCoordinates(); void prepareForGetDiveCoordinates();
void endGetDiveCoordinates(); void endGetDiveCoordinates();