diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/diveplanner.cpp | 26 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 2 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 55 |
3 files changed, 59 insertions, 24 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index fe1342112..36cd7f144 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -428,7 +428,7 @@ void DivePlannerGraphics::drawProfile() dp = dp->next; } - if (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum()) { + if (!activeDraggedHandler && (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum())) { double newMax = fmax(dp->time / 60.0 + 5, minMinutes); timeLine->setMaximum(newMax); timeLine->updateTicks(); @@ -522,7 +522,7 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) depthString->setBrush( QColor(redDelta, greenDelta, blueDelta)); if (activeDraggedHandler) - moveActiveHandler(mappedPos); + moveActiveHandler(mappedPos, handles.indexOf(activeDraggedHandler)); if (!handles.count()) return; @@ -535,13 +535,27 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) } } -void DivePlannerGraphics::moveActiveHandler(const QPointF& pos) +void DivePlannerGraphics::moveActiveHandler(const QPointF& mappedPos, const int pos) { - double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos))); - double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos))); + + divedatapoint data = plannerModel->at(pos); + int minutes = rint(timeLine->valueAt(mappedPos)); + int meters = rint(depthLine->valueAt(mappedPos)); + double xpos = timeLine->posAtValue(minutes); + double ypos = depthLine->posAtValue(meters); + + data.depth = rint(depthLine->valueAt(mappedPos)) * 1000; + data.time = rint(timeLine->valueAt(mappedPos)) * 60; + + plannerModel->editStop(pos, data); + activeDraggedHandler->setPos(QPointF(xpos, ypos)); qDeleteAll(lines); lines.clear(); + + drawProfile(); + + } bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point) @@ -606,8 +620,8 @@ void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) activeDraggedHandler->setBrush(QBrush(Qt::white)); activeDraggedHandler->setPos(QPointF(xpos, ypos)); - drawProfile(); activeDraggedHandler = 0; + drawProfile(); } } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 016fda332..12b01cdeb 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -153,7 +153,7 @@ private slots: void pointInserted(const QModelIndex&, int start, int end); void pointsRemoved(const QModelIndex&, int start, int end); private: - void moveActiveHandler(const QPointF& pos); + void moveActiveHandler(const QPointF& MappedPos, const int pos); /* This are the lines of the plotted dive. */ QList<QGraphicsLineItem*> lines; diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a42ce68dd..d35fefcf9 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -141,7 +141,7 @@ void MainTab::enableEdition() notesBackup[mydive].visibility = mydive->visibility; notesBackup[mydive].latitude = mydive->latitude; notesBackup[mydive].longitude = mydive->longitude; - notesBackup[mydive].coordinates = ui->location->text(); + notesBackup[mydive].coordinates = ui->coordinates->text(); } editMode = DIVE; } @@ -374,6 +374,11 @@ void MainTab::acceptChanges() mark_divelist_changed(TRUE); } else { struct dive *curr = current_dive; + //Reset coordinates field, in case it contains garbage. + char buffer[256]; + print_gps_coordinates(buffer, sizeof buffer + , current_dive->latitude.udeg, current_dive->longitude.udeg); + ui->coordinates->setText(buffer); if (notesBackup[curr].buddy != ui->buddy->text() || notesBackup[curr].suit != ui->suit->text() || notesBackup[curr].notes != ui->notes->toPlainText() || @@ -403,6 +408,7 @@ void MainTab::acceptChanges() ui->buddy->setPalette(p); ui->notes->setPalette(p); ui->location->setPalette(p); + ui->coordinates->setPalette(p); ui->divemaster->setPalette(p); ui->suit->setPalette(p); } @@ -468,6 +474,7 @@ void MainTab::rejectChanges() ui->buddy->setPalette(p); ui->notes->setPalette(p); ui->location->setPalette(p); + ui->coordinates->setPalette(p); ui->divemaster->setPalette(p); ui->suit->setPalette(p); if (editMode == ADD) { @@ -482,7 +489,7 @@ void MainTab::rejectChanges() } #undef EDIT_TEXT2 -#define EDIT_SELECTED_DIVES( WHAT ) \ +#define EDIT_SELECTED_DIVES( WHAT ) do { \ if (editMode == NONE) \ return; \ \ @@ -494,7 +501,8 @@ void MainTab::rejectChanges() continue; \ \ WHAT; \ - } + } \ +} while(0) void markChangedWidget(QWidget *w){ QPalette p; @@ -523,21 +531,26 @@ void MainTab::on_location_textChanged(const QString& text) dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->location, text); } else if (editMode == DIVE || editMode == ADD){ - struct dive* dive; - int i = 0; - for_each_dive(i, dive){ - QString location(dive->location); - if (location == text && - (dive->latitude.udeg || dive->longitude.udeg)){ - EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude ) - EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude ) - char buffer[256]; - print_gps_coordinates(buffer, sizeof buffer, dive->latitude.udeg, dive->longitude.udeg); - ui->coordinates->setText(buffer); - break; + if (!ui->coordinates->isModified() || + ui->coordinates->text().trimmed().isEmpty()) { + struct dive* dive; + int i = 0; + for_each_dive(i, dive){ + QString location(dive->location); + if (location == text && + (dive->latitude.udeg || dive->longitude.udeg)) { + EDIT_SELECTED_DIVES( mydive->latitude = dive->latitude ); + EDIT_SELECTED_DIVES( mydive->longitude = dive->longitude ); + char buffer[256]; + print_gps_coordinates(buffer, sizeof buffer + , dive->latitude.udeg, dive->longitude.udeg); + ui->coordinates->setText(buffer); + markChangedWidget(ui->coordinates); + break; + } } } - EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ) + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ); } markChangedWidget(ui->location); @@ -568,7 +581,15 @@ void MainTab::on_notes_textChanged() void MainTab::on_coordinates_textChanged(const QString& text) { QByteArray textByteArray = text.toLocal8Bit(); - EDIT_SELECTED_DIVES(gps_changed(mydive, NULL, textByteArray.data())); + gboolean gpsChanged = FALSE; + EDIT_SELECTED_DIVES(gpsChanged |= gps_changed(mydive, NULL, textByteArray.data())); + if (gpsChanged) { + markChangedWidget(ui->coordinates); + } else { + QPalette p; + p.setBrush(QPalette::Base, QColor(Qt::red).lighter()); + ui->coordinates->setPalette(p); + } } void MainTab::on_rating_valueChanged(int value) |