mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fixes Setting the dive-location via the map.
This patch adds a context menu to set the dive location via the globe, being the dive with a coordinate or not. It also fixes setting the dive location on edit mode. Fixes: #315 Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
bbc022ba18
commit
d26f109fba
3 changed files with 31 additions and 36 deletions
|
@ -24,7 +24,7 @@
|
|||
#include <QMouseEvent>
|
||||
#include <QMessageBox>
|
||||
|
||||
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
||||
GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0), editingDiveLocation(false)
|
||||
{
|
||||
// check if Google Sat Maps are installed
|
||||
// if not, check if they are in a known location
|
||||
|
@ -72,7 +72,6 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
|||
|
||||
setMinimumHeight(0);
|
||||
setMinimumWidth(0);
|
||||
editingDiveCoords = 0;
|
||||
fixZoomTimer = new QTimer();
|
||||
connect(fixZoomTimer, SIGNAL(timeout()), this, SLOT(fixZoom()));
|
||||
fixZoomTimer->setSingleShot(true);
|
||||
|
@ -82,19 +81,29 @@ GlobeGPS::GlobeGPS(QWidget* parent) : MarbleWidget(parent), loadedDives(0)
|
|||
bool GlobeGPS::eventFilter(QObject *obj, QEvent *ev)
|
||||
{
|
||||
// This disables Zooming when a double click occours on the scene.
|
||||
if (ev->type() == QEvent::MouseButtonDblClick && !editingDiveCoords)
|
||||
if (ev->type() == QEvent::MouseButtonDblClick && !editingDiveLocation)
|
||||
return true;
|
||||
// This disables the Marble's Context Menu
|
||||
// we need to move this to our 'contextMenuEvent'
|
||||
// if we plan to do a different one in the future.
|
||||
if (ev->type() == QEvent::ContextMenu)
|
||||
if (ev->type() == QEvent::ContextMenu){
|
||||
contextMenuEvent(static_cast<QContextMenuEvent*>(ev));
|
||||
return true;
|
||||
}
|
||||
if (ev->type() == QEvent::MouseButtonPress){
|
||||
QMouseEvent *e = static_cast<QMouseEvent*>(ev);
|
||||
if(e->button() == Qt::RightButton)
|
||||
return true;
|
||||
}
|
||||
return QObject::eventFilter(obj,ev );
|
||||
return QObject::eventFilter(obj,ev );
|
||||
}
|
||||
|
||||
void GlobeGPS::contextMenuEvent(QContextMenuEvent* ev)
|
||||
{
|
||||
QMenu m;
|
||||
QAction *a = m.addAction(tr("Edit Selected Dive Locations"), this, SLOT(prepareForGetDiveCoordinates()));
|
||||
a->setData(QVariant::fromValue<void*>(&m));
|
||||
m.exec(ev->globalPos());
|
||||
}
|
||||
|
||||
void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
||||
|
@ -185,11 +194,9 @@ void GlobeGPS::repopulateLabels()
|
|||
|
||||
void GlobeGPS::reload()
|
||||
{
|
||||
editingDiveCoords = 0;
|
||||
|
||||
editingDiveLocation = false;
|
||||
if (messageWidget->isVisible())
|
||||
messageWidget->animatedHide();
|
||||
|
||||
repopulateLabels();
|
||||
}
|
||||
|
||||
|
@ -202,13 +209,11 @@ void GlobeGPS::centerOn(dive* dive)
|
|||
if (!dive)
|
||||
return;
|
||||
|
||||
editingDiveCoords = 0;
|
||||
|
||||
qreal longitude = dive->longitude.udeg / 1000000.0;
|
||||
qreal latitude = dive->latitude.udeg / 1000000.0;
|
||||
|
||||
if (!longitude || !latitude) {
|
||||
prepareForGetDiveCoordinates(dive);
|
||||
prepareForGetDiveCoordinates();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -231,37 +236,27 @@ void GlobeGPS::fixZoom()
|
|||
zoomView(currentZoomLevel, Marble::Linear);
|
||||
}
|
||||
|
||||
|
||||
void GlobeGPS::prepareForGetDiveCoordinates(dive* dive)
|
||||
void GlobeGPS::prepareForGetDiveCoordinates()
|
||||
{
|
||||
if (!messageWidget->isVisible()) {
|
||||
messageWidget->setMessageType(KMessageWidget::Warning);
|
||||
messageWidget->setText(QObject::tr("No location data - move the map and double-click to set the dive location"));
|
||||
messageWidget->setWordWrap(true);
|
||||
messageWidget->animatedShow();
|
||||
editingDiveLocation = true;
|
||||
}
|
||||
editingDiveCoords = dive;
|
||||
}
|
||||
|
||||
void GlobeGPS::diveEditMode()
|
||||
{
|
||||
if (messageWidget->isVisible())
|
||||
messageWidget->animatedHide();
|
||||
messageWidget->setMessageType(KMessageWidget::Warning);
|
||||
messageWidget->setText(QObject::tr("Editing dive - move the map and double-click to set the dive location"));
|
||||
messageWidget->setWordWrap(true);
|
||||
messageWidget->animatedShow();
|
||||
}
|
||||
|
||||
void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
||||
{
|
||||
if (mainWindow()->dive_list()->selectionModel()->selection().isEmpty())
|
||||
return;
|
||||
|
||||
// convert to degrees if in radian.
|
||||
if (unit == GeoDataCoordinates::Radian) {
|
||||
lon = lon * 180 / M_PI;
|
||||
lat = lat * 180 / M_PI;
|
||||
}
|
||||
if (!editingDiveCoords)
|
||||
return;
|
||||
|
||||
/* change everything on the selection. */
|
||||
int i;
|
||||
|
@ -273,7 +268,7 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
|
|||
dive->longitude.udeg = lrint(lon * 1000000.0);
|
||||
}
|
||||
centerOn(lon, lat, true);
|
||||
editingDiveCoords = 0;
|
||||
editingDiveLocation = false;
|
||||
mark_divelist_changed(TRUE);
|
||||
messageWidget->animatedHide();
|
||||
mainWindow()->refreshDisplay();
|
||||
|
@ -282,13 +277,13 @@ void GlobeGPS::changeDiveGeoPosition(qreal lon, qreal lat, GeoDataCoordinates::U
|
|||
void GlobeGPS::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
qreal lat, lon;
|
||||
bool clickOnGlobe = geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree);
|
||||
|
||||
// there could be two scenarios that got us here; let's check if we are editing a dive
|
||||
if (mainWindow()->information()->isEditing() &&
|
||||
geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) {
|
||||
if (mainWindow()->information()->isEditing() && clickOnGlobe) {
|
||||
mainWindow()->information()->updateCoordinatesText(lat, lon);
|
||||
repopulateLabels();
|
||||
} else if (editingDiveCoords &&
|
||||
geoCoordinates(event->pos().x(), event->pos().y(), lon, lat, GeoDataCoordinates::Degree)) {
|
||||
} else if (clickOnGlobe) {
|
||||
changeDiveGeoPosition(lon, lat, GeoDataCoordinates::Degree);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,23 +19,24 @@ public:
|
|||
void reload();
|
||||
void repopulateLabels();
|
||||
void centerOn(struct dive* dive);
|
||||
void diveEditMode();
|
||||
bool eventFilter(QObject*, QEvent*);
|
||||
protected:
|
||||
/* reimp */ void resizeEvent(QResizeEvent *event);
|
||||
/* reimp */ void mousePressEvent(QMouseEvent* event);
|
||||
/* reimp */ void contextMenuEvent(QContextMenuEvent*);
|
||||
private:
|
||||
void prepareForGetDiveCoordinates(struct dive* dive);
|
||||
GeoDataDocument *loadedDives;
|
||||
struct dive* editingDiveCoords;
|
||||
KMessageWidget* messageWidget;
|
||||
QTimer *fixZoomTimer;
|
||||
int currentZoomLevel;
|
||||
bool editingDiveLocation;
|
||||
|
||||
public slots:
|
||||
void changeDiveGeoPosition(qreal lon,qreal lat,GeoDataCoordinates::Unit);
|
||||
void mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit);
|
||||
void fixZoom();
|
||||
void prepareForGetDiveCoordinates();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -166,12 +166,11 @@ void MainTab::enableEdition(EditMode newEditMode)
|
|||
return;
|
||||
|
||||
mainWindow()->dive_list()->setEnabled(false);
|
||||
mainWindow()->globe()->diveEditMode();
|
||||
mainWindow()->globe()->prepareForGetDiveCoordinates();
|
||||
// We may be editing one or more dives here. backup everything.
|
||||
notesBackup.clear();
|
||||
ui.notesButtonBox->show();
|
||||
ui.equipmentButtonBox->show();
|
||||
|
||||
if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
|
||||
// we are editing trip location and notes
|
||||
ui.diveNotesMessage->setText(tr("This trip is being edited. Select Save or Cancel when done."));
|
||||
|
|
Loading…
Add table
Reference in a new issue