diff options
Diffstat (limited to 'qt-ui/simplewidgets.cpp')
-rw-r--r-- | qt-ui/simplewidgets.cpp | 102 |
1 files changed, 82 insertions, 20 deletions
diff --git a/qt-ui/simplewidgets.cpp b/qt-ui/simplewidgets.cpp index f8f4c2493..430609c7b 100644 --- a/qt-ui/simplewidgets.cpp +++ b/qt-ui/simplewidgets.cpp @@ -5,12 +5,17 @@ #include <QFileDialog> #include <QShortcut> #include <QCalendarWidget> +#include <QKeyEvent> +#include <QAction> #include "file.h" #include "mainwindow.h" #include "helpers.h" #include "libdivecomputer/parser.h" - +#include "divelistview.h" +#include "display.h" +#include "profile/profilewidget2.h" +#include "undocommands.h" class MinMaxAvgWidgetPrivate { public: @@ -137,8 +142,17 @@ void RenumberDialog::renumberOnlySelected(bool selected) void RenumberDialog::buttonClicked(QAbstractButton *button) { - if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) - renumber_dives(ui.spinBox->value(), selectedOnly); + if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { + QMap<int,int> renumberedDives; + int i; + struct dive *dive = NULL; + for_each_dive (i, dive) { + if (!selectedOnly || dive->selected) + renumberedDives.insert(dive->id, dive->number); + } + UndoRenumberDives *undoCommand = new UndoRenumberDives(renumberedDives, ui.spinBox->value()); + MainWindow::instance()->undoStack->push(undoCommand); + } } RenumberDialog::RenumberDialog(QWidget *parent) : QDialog(parent), selectedOnly(false) @@ -169,7 +183,6 @@ void SetpointDialog::buttonClicked(QAbstractButton *button) add_event(dc, time, SAMPLE_EVENT_PO2, 0, (int)(1000.0 * ui.spinbox->value()), "SP change"); mark_divelist_changed(true); MainWindow::instance()->graphics()->replot(); - } SetpointDialog::SetpointDialog(QWidget *parent) : QDialog(parent) @@ -198,7 +211,16 @@ void ShiftTimesDialog::buttonClicked(QAbstractButton *button) amount *= -1; if (amount != 0) { // DANGER, DANGER - this could get our dive_table unsorted... - shift_times(amount); + int i; + struct dive *dive; + QList<int> affectedDives; + for_each_dive (i, dive) { + if (!dive->selected) + continue; + + affectedDives.append(dive->id); + } + MainWindow::instance()->undoStack->push(new UndoShiftTime(affectedDives, amount)); sort_table(&dive_table); mark_divelist_changed(true); MainWindow::instance()->dive_list()->rememberSelection(); @@ -250,9 +272,6 @@ void ShiftImageTimesDialog::buttonClicked(QAbstractButton *button) void ShiftImageTimesDialog::syncCameraClicked() { - struct memblock mem; - EXIFInfo exiv; - int retval; QPixmap picture; QDateTime dcDateTime = QDateTime(); QStringList fileNames = QFileDialog::getOpenFileNames(this, @@ -268,13 +287,8 @@ void ShiftImageTimesDialog::syncCameraClicked() scene->addPixmap(picture.scaled(ui.DCImage->size())); ui.DCImage->setScene(scene); - if (readfile(fileNames.at(0).toUtf8().data(), &mem) <= 0) - return; - retval = exiv.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size); - free(mem.buffer); - if (retval != PARSE_EXIF_SUCCESS) - return; - dcImageEpoch = exiv.epoch(); + + dcImageEpoch = picture_get_timestamp(fileNames.at(0).toUtf8().data()); dcDateTime.setTime_t(dcImageEpoch); ui.dcTime->setDateTime(dcDateTime); connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &))); @@ -287,11 +301,12 @@ void ShiftImageTimesDialog::dcDateTimeChanged(const QDateTime &newDateTime) setOffset(newDateTime.toTime_t() - dcImageEpoch); } -ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent) : QDialog(parent), m_amount(0) +ShiftImageTimesDialog::ShiftImageTimesDialog(QWidget *parent, QStringList fileNames) : QDialog(parent), fileNames(fileNames), m_amount(0) { ui.setupUi(this); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.syncCamera, SIGNAL(clicked()), this, SLOT(syncCameraClicked())); + connect(ui.timeEdit, SIGNAL(timeChanged(const QTime &)), this, SLOT(timeEditChanged(const QTime &))); dcImageEpoch = (time_t)0; } @@ -311,6 +326,55 @@ void ShiftImageTimesDialog::setOffset(time_t offset) ui.timeEdit->setTime(QTime(offset / 3600, (offset % 3600) / 60, offset % 60)); } +void ShiftImageTimesDialog::updateInvalid() +{ + timestamp_t timestamp; + QDateTime time; + bool allValid = true; + ui.warningLabel->hide(); + ui.invalidLabel->hide(); + ui.invalidLabel->clear(); + + Q_FOREACH (const QString &fileName, fileNames) { + if (picture_check_valid(fileName.toUtf8().data(), m_amount)) + continue; + + // We've found invalid image + timestamp = picture_get_timestamp(fileName.toUtf8().data()); + dcImageEpoch = timestamp; + time.setTime_t(timestamp + m_amount); + ui.invalidLabel->setText(ui.invalidLabel->text() + fileName + " " + time.toString() + "\n"); + allValid = false; + } + + if (!allValid){ + ui.warningLabel->show(); + ui.invalidLabel->show(); + } +} + +void ShiftImageTimesDialog::timeEditChanged(const QTime &time) +{ + m_amount = time.hour() * 3600 + time.minute() * 60; + if (ui.backwards->isChecked()) + m_amount *= -1; + updateInvalid(); +} + +URLDialog::URLDialog(QWidget *parent) : QDialog(parent) +{ + ui.setupUi(this); + QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); + connect(close, SIGNAL(activated()), this, SLOT(close())); + QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this); + connect(quit, SIGNAL(activated()), parent, SLOT(close())); +} + +QString URLDialog::url() const +{ + return ui.urlField->toPlainText(); +} + bool isGnome3Session() { #if defined(QT_OS_WIW) || defined(QT_OS_MAC) @@ -454,8 +518,7 @@ DiveComponentSelection::DiveComponentSelection(QWidget *parent, struct dive *tar { ui.setupUi(this); what = _what; - UI_FROM_COMPONENT(location); - UI_FROM_COMPONENT(gps); + UI_FROM_COMPONENT(divesite); UI_FROM_COMPONENT(divemaster); UI_FROM_COMPONENT(buddy); UI_FROM_COMPONENT(rating); @@ -475,8 +538,7 @@ DiveComponentSelection::DiveComponentSelection(QWidget *parent, struct dive *tar void DiveComponentSelection::buttonClicked(QAbstractButton *button) { if (ui.buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) { - COMPONENT_FROM_UI(location); - COMPONENT_FROM_UI(gps); + COMPONENT_FROM_UI(divesite); COMPONENT_FROM_UI(divemaster); COMPONENT_FROM_UI(buddy); COMPONENT_FROM_UI(rating); |