From 56dbb7c2ff697a393f5051e2b5363bd4c0f2bb6e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 17 May 2013 16:12:55 -0300 Subject: Added the possibility to change the coordinates of a dive. Added the possibility to change the coordinates of a dive. it's too intrusive in the moment, but it was a proof of concept. so I'll commit as is and try to find a better way to warn the user what's going on in the future, using something less terrible than a popup exploding in his face. Signed-off-by: Tomaz Canabrava --- qt-ui/globe.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'qt-ui/globe.cpp') diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index a8fb886d8..93d1ab7c4 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -9,7 +9,8 @@ #include #include -using namespace Marble; +#include +#include GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0) { @@ -31,7 +32,6 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0) floatItem->setContentSize( QSize( 50, 50 ) ); } } - } void GlobeGPS::reload() @@ -40,7 +40,9 @@ void GlobeGPS::reload() model()->treeModel()->removeDocument(loadedDives); delete loadedDives; } - + if (editingDiveCoords){ + editingDiveCoords = 0; + } loadedDives = new GeoDataDocument; @@ -62,5 +64,50 @@ void GlobeGPS::reload() void GlobeGPS::centerOn(dive* dive) { - centerOn(dive->longitude.udeg / 1000000.0,dive->latitude.udeg / 1000000.0, true); + qreal longitude = dive->longitude.udeg / 1000000.0; + qreal latitude = dive->latitude.udeg / 1000000.0; + + if (!longitude || !latitude){ + prepareForGetDiveCoordinates(dive); + return; + } + + centerOn(longitude,latitude, true); +} + +void GlobeGPS::prepareForGetDiveCoordinates(dive* dive) +{ + QMessageBox::warning(parentWidget(), + tr("This dive has no location!"), + tr("Move the planet to the desired position, then \n double-click to set the new location of this dive.")); + + editingDiveCoords = dive; +} + +void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) +{ + // convert to degrees if in radian. + if (unit == GeoDataCoordinates::Radian){ + lon = lon * 180 / M_PI; + lat = lat * 180 / M_PI; + } + + if (!editingDiveCoords){ + return; + } + + editingDiveCoords->latitude.udeg = (int) lat * 1000000.0; + editingDiveCoords->longitude.udeg = (int) lon * 1000000.0; + centerOn(lon, lat, true); + reload(); + editingDiveCoords = 0; } + +void GlobeGPS::mousePressEvent(QMouseEvent* event) +{ + qreal lat, lon; + if (editingDiveCoords && geoCoordinates(event->pos().x(), event->pos().y(), lon,lat, GeoDataCoordinates::Radian)){ + changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Radian); + } +} + -- cgit v1.2.3-70-g09d2