2017-04-27 20:26:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-13 20:44:02 -07:00
|
|
|
/*
|
|
|
|
* maintab.cpp
|
|
|
|
*
|
|
|
|
* classes for the "notebook" area of the main window of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2017-04-04 19:21:30 +02:00
|
|
|
#include "desktop-widgets/tab-widgets/maintab.h"
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "desktop-widgets/mainwindow.h"
|
2017-07-15 23:37:02 +03:00
|
|
|
#include "desktop-widgets/mapwidget.h"
|
2018-06-03 22:15:19 +02:00
|
|
|
#include "core/qthelper.h"
|
2019-05-31 16:09:14 +02:00
|
|
|
#include "core/trip.h"
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "qt-models/diveplannermodel.h"
|
|
|
|
#include "desktop-widgets/divelistview.h"
|
2019-11-24 15:02:34 +01:00
|
|
|
#include "core/selection.h"
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "desktop-widgets/diveplanner.h"
|
|
|
|
#include "qt-models/divecomputerextradatamodel.h"
|
|
|
|
#include "qt-models/divelocationmodel.h"
|
2017-11-26 22:21:58 +01:00
|
|
|
#include "qt-models/filtermodels.h"
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "core/divesite.h"
|
2019-08-05 19:41:15 +02:00
|
|
|
#include "core/errorhelper.h"
|
2018-05-11 08:25:41 -07:00
|
|
|
#include "core/subsurface-string.h"
|
2018-06-17 08:48:54 +02:00
|
|
|
#include "core/gettextfromc.h"
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "desktop-widgets/locationinformation.h"
|
2018-10-21 18:00:02 +02:00
|
|
|
#include "desktop-widgets/simplewidgets.h"
|
2019-11-13 15:08:40 +01:00
|
|
|
#include "commands/command.h"
|
2015-06-01 16:58:23 -03:00
|
|
|
|
2019-04-13 17:43:45 +02:00
|
|
|
#include "TabDiveEquipment.h"
|
2017-04-04 19:21:30 +02:00
|
|
|
#include "TabDiveExtraInfo.h"
|
|
|
|
#include "TabDiveInformation.h"
|
|
|
|
#include "TabDivePhotos.h"
|
|
|
|
#include "TabDiveStatistics.h"
|
2019-03-09 22:32:16 +01:00
|
|
|
#include "TabDiveSite.h"
|
2017-04-04 19:21:30 +02:00
|
|
|
|
2013-08-13 10:49:59 -03:00
|
|
|
#include <QCompleter>
|
2013-12-11 23:08:56 -02:00
|
|
|
#include <QScrollBar>
|
2014-06-03 15:29:28 -07:00
|
|
|
#include <QShortcut>
|
2014-06-03 18:01:00 -07:00
|
|
|
#include <QMessageBox>
|
2013-04-07 15:20:43 -07:00
|
|
|
|
2019-04-13 18:14:50 +02:00
|
|
|
struct Completers {
|
|
|
|
QCompleter *divemaster;
|
|
|
|
QCompleter *buddy;
|
|
|
|
QCompleter *tags;
|
|
|
|
};
|
|
|
|
|
2020-11-04 13:09:44 -08:00
|
|
|
static bool paletteIsDark(const QPalette &p)
|
|
|
|
{
|
|
|
|
// we consider a palette dark if the text color is lighter than the windows background
|
|
|
|
return p.window().color().valueF() < p.windowText().color().valueF();
|
|
|
|
}
|
|
|
|
|
2013-04-07 15:20:43 -07:00
|
|
|
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
2020-03-18 22:42:47 +01:00
|
|
|
editMode(false),
|
2020-03-18 22:37:18 +01:00
|
|
|
ignoreInput(false),
|
2018-03-15 22:41:59 +01:00
|
|
|
lastSelectedDive(true),
|
2017-11-30 20:33:43 +01:00
|
|
|
lastTabSelectedDive(0),
|
2017-12-19 23:05:42 +01:00
|
|
|
lastTabSelectedDiveTrip(0),
|
2019-12-04 08:15:20 +01:00
|
|
|
currentTrip(0)
|
2013-04-07 15:20:43 -07:00
|
|
|
{
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.setupUi(this);
|
2017-04-04 19:21:30 +02:00
|
|
|
|
2020-04-13 19:26:29 +02:00
|
|
|
extraWidgets << new TabDiveEquipment(this);
|
2019-04-13 17:43:45 +02:00
|
|
|
ui.tabWidget->addTab(extraWidgets.last(), tr("Equipment"));
|
2020-04-13 19:26:29 +02:00
|
|
|
extraWidgets << new TabDiveInformation(this);
|
2017-04-13 20:23:07 +02:00
|
|
|
ui.tabWidget->addTab(extraWidgets.last(), tr("Information"));
|
2020-04-13 19:26:29 +02:00
|
|
|
extraWidgets << new TabDiveStatistics(this);
|
2021-01-03 13:53:52 -08:00
|
|
|
ui.tabWidget->addTab(extraWidgets.last(), tr("Summary"));
|
2020-04-13 19:26:29 +02:00
|
|
|
extraWidgets << new TabDivePhotos(this);
|
2018-07-13 20:46:45 +02:00
|
|
|
ui.tabWidget->addTab(extraWidgets.last(), tr("Media"));
|
2020-04-13 19:26:29 +02:00
|
|
|
extraWidgets << new TabDiveExtraInfo(this);
|
2017-04-21 18:33:38 +02:00
|
|
|
ui.tabWidget->addTab(extraWidgets.last(), tr("Extra Info"));
|
2020-04-13 19:26:29 +02:00
|
|
|
extraWidgets << new TabDiveSite(this);
|
2019-03-09 22:32:16 +01:00
|
|
|
ui.tabWidget->addTab(extraWidgets.last(), tr("Dive sites"));
|
2017-04-04 19:21:30 +02:00
|
|
|
|
2020-11-04 13:09:44 -08:00
|
|
|
// make sure we know if this is a light or dark mode
|
|
|
|
isDark = paletteIsDark(palette());
|
|
|
|
|
2020-11-02 12:36:29 -08:00
|
|
|
// call colorsChanged() for the initial setup now that the extraWidgets are loaded
|
|
|
|
colorsChanged();
|
|
|
|
|
2020-05-22 09:49:48 +02:00
|
|
|
updateDateTimeFields();
|
2014-02-09 19:49:15 +01:00
|
|
|
|
2013-12-03 21:44:48 +01:00
|
|
|
closeMessage();
|
2013-09-26 17:02:27 -03:00
|
|
|
|
2019-02-11 15:34:43 +01:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &MainTab::divesChanged);
|
2019-02-24 21:22:33 +01:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &MainTab::tripChanged);
|
2019-03-29 17:48:08 +01:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MainTab::diveSiteEdited);
|
2019-05-24 21:38:56 +02:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::commandExecuted, this, &MainTab::closeWarning);
|
2020-11-24 12:50:52 +01:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDiveInfo);
|
2019-02-24 21:22:33 +01:00
|
|
|
|
2019-03-16 11:51:42 +01:00
|
|
|
connect(ui.editDiveSiteButton, &QToolButton::clicked, MainWindow::instance(), &MainWindow::startDiveSiteEdit);
|
2017-07-15 23:37:02 +03:00
|
|
|
connect(ui.location, &DiveLocationLineEdit::entered, MapWidget::instance(), &MapWidget::centerOnIndex);
|
|
|
|
connect(ui.location, &DiveLocationLineEdit::currentChanged, MapWidget::instance(), &MapWidget::centerOnIndex);
|
2019-06-30 23:08:02 +02:00
|
|
|
connect(ui.location, &DiveLocationLineEdit::editingFinished, this, &MainTab::on_location_diveSiteSelected);
|
2015-02-11 13:32:29 -02:00
|
|
|
|
2020-05-22 09:49:48 +02:00
|
|
|
// One might think that we could listen to the precise property-changed signals of the preferences system.
|
|
|
|
// Alas, this is not the case. When the user switches to system-format, the preferences sends the according
|
|
|
|
// signal. However, the correct date and time format is set by the preferences dialog later. This should be fixed.
|
2020-11-24 12:50:52 +01:00
|
|
|
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDateTimeFields);
|
2020-11-04 14:29:48 -08:00
|
|
|
|
2014-11-23 07:41:25 -08:00
|
|
|
QAction *action = new QAction(tr("Apply changes"), this);
|
2013-12-02 15:33:00 -02:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
|
2019-05-24 20:50:25 +02:00
|
|
|
ui.diveNotesMessage->addAction(action);
|
2013-12-02 15:33:00 -02:00
|
|
|
|
2014-11-23 07:41:25 -08:00
|
|
|
action = new QAction(tr("Discard changes"), this);
|
2013-12-02 15:33:00 -02:00
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(rejectChanges()));
|
2019-05-24 20:50:25 +02:00
|
|
|
ui.diveNotesMessage->addAction(action);
|
2014-06-03 15:29:28 -07:00
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
action = new QAction(tr("OK"), this);
|
|
|
|
connect(action, &QAction::triggered, this, &MainTab::closeWarning);
|
|
|
|
ui.multiDiveWarningMessage->addAction(action);
|
|
|
|
|
2019-05-24 21:50:17 +02:00
|
|
|
action = new QAction(tr("Undo"), this);
|
|
|
|
connect(action, &QAction::triggered, Command::undoAction(this), &QAction::trigger);
|
|
|
|
connect(action, &QAction::triggered, this, &MainTab::closeWarning);
|
|
|
|
ui.multiDiveWarningMessage->addAction(action);
|
|
|
|
|
2014-06-03 15:29:28 -07:00
|
|
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
|
|
|
connect(closeKey, SIGNAL(activated()), this, SLOT(escDetected()));
|
|
|
|
|
2013-09-26 17:02:27 -03:00
|
|
|
if (qApp->style()->objectName() == "oxygen")
|
2013-09-26 16:51:11 -03:00
|
|
|
setDocumentMode(true);
|
2013-09-26 17:02:27 -03:00
|
|
|
else
|
|
|
|
setDocumentMode(false);
|
|
|
|
|
2013-05-19 17:38:20 -07:00
|
|
|
// we start out with the fields read-only; once things are
|
|
|
|
// filled from a dive, they are made writeable
|
2013-09-18 21:56:53 -03:00
|
|
|
setEnabled(false);
|
2013-05-19 11:45:01 -03:00
|
|
|
|
2019-04-13 18:14:50 +02:00
|
|
|
Completers completers;
|
2014-02-11 18:46:14 +01:00
|
|
|
completers.buddy = new QCompleter(&buddyModel, ui.buddy);
|
|
|
|
completers.divemaster = new QCompleter(&diveMasterModel, ui.divemaster);
|
|
|
|
completers.tags = new QCompleter(&tagModel, ui.tagWidget);
|
2014-01-06 20:00:10 -02:00
|
|
|
completers.buddy->setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
completers.divemaster->setCaseSensitivity(Qt::CaseInsensitive);
|
2013-11-15 01:39:02 +01:00
|
|
|
completers.tags->setCaseSensitivity(Qt::CaseInsensitive);
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.buddy->setCompleter(completers.buddy);
|
|
|
|
ui.divemaster->setCompleter(completers.divemaster);
|
2013-11-02 02:20:02 +01:00
|
|
|
ui.tagWidget->setCompleter(completers.tags);
|
2015-06-03 22:08:57 -03:00
|
|
|
ui.diveNotesMessage->hide();
|
2019-05-24 21:11:20 +02:00
|
|
|
ui.multiDiveWarningMessage->hide();
|
2017-02-04 13:12:50 -08:00
|
|
|
ui.depth->hide();
|
|
|
|
ui.depthLabel->hide();
|
|
|
|
ui.duration->hide();
|
|
|
|
ui.durationLabel->hide();
|
2013-09-26 18:14:09 -03:00
|
|
|
setMinimumHeight(0);
|
|
|
|
setMinimumWidth(0);
|
2013-09-27 12:52:01 -03:00
|
|
|
|
|
|
|
// Current display of things on Gnome3 looks like shit, so
|
2019-04-13 17:43:45 +02:00
|
|
|
// let's fix that.
|
2013-09-27 12:52:01 -03:00
|
|
|
if (isGnome3Session()) {
|
|
|
|
QPalette p;
|
|
|
|
p.setColor(QPalette::Window, QColor(Qt::white));
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.scrollArea->viewport()->setPalette(p);
|
2013-12-04 18:24:37 -02:00
|
|
|
|
|
|
|
// GroupBoxes in Gnome3 looks like I'v drawn them...
|
2019-04-01 23:15:23 +02:00
|
|
|
static const QString gnomeCss = QStringLiteral(
|
2013-12-04 18:24:37 -02:00
|
|
|
"QGroupBox {"
|
2019-04-01 23:15:23 +02:00
|
|
|
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
|
|
|
"stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
|
|
|
"border: 2px solid gray;"
|
|
|
|
"border-radius: 5px;"
|
|
|
|
"margin-top: 1ex;"
|
2013-12-04 18:24:37 -02:00
|
|
|
"}"
|
|
|
|
"QGroupBox::title {"
|
2019-04-01 23:15:23 +02:00
|
|
|
"subcontrol-origin: margin;"
|
|
|
|
"subcontrol-position: top center;"
|
|
|
|
"padding: 0 3px;"
|
|
|
|
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
|
|
|
|
"stop: 0 #E0E0E0, stop: 1 #FFFFFF);"
|
2013-12-04 18:24:37 -02:00
|
|
|
"}");
|
2014-05-22 11:40:22 -07:00
|
|
|
Q_FOREACH (QGroupBox *box, findChildren<QGroupBox *>()) {
|
2013-12-04 18:24:37 -02:00
|
|
|
box->setStyleSheet(gnomeCss);
|
|
|
|
}
|
2013-09-27 12:52:01 -03:00
|
|
|
}
|
2014-12-23 10:16:11 -08:00
|
|
|
// QLineEdit and QLabels should have minimal margin on the left and right but not waste vertical space
|
2015-01-02 12:42:02 -08:00
|
|
|
QMargins margins(3, 2, 1, 0);
|
2014-12-23 10:16:11 -08:00
|
|
|
Q_FOREACH (QLabel *label, findChildren<QLabel *>()) {
|
|
|
|
label->setContentsMargins(margins);
|
|
|
|
}
|
2014-08-06 18:05:54 -03:00
|
|
|
|
2015-09-23 16:03:28 -03:00
|
|
|
connect(ui.diveNotesMessage, &KMessageWidget::showAnimationFinished,
|
|
|
|
ui.location, &DiveLocationLineEdit::fixPopupPosition);
|
2019-05-24 21:11:20 +02:00
|
|
|
connect(ui.multiDiveWarningMessage, &KMessageWidget::showAnimationFinished,
|
|
|
|
ui.location, &DiveLocationLineEdit::fixPopupPosition);
|
2015-09-23 16:03:28 -03:00
|
|
|
|
2015-11-15 20:56:24 -08:00
|
|
|
// enable URL clickability in notes:
|
|
|
|
new TextHyperlinkEventFilter(ui.notes);//destroyed when ui.notes is destroyed
|
|
|
|
|
2015-10-01 17:54:13 -03:00
|
|
|
ui.diveTripLocation->hide();
|
2013-11-28 09:17:30 -02:00
|
|
|
}
|
|
|
|
|
2020-05-22 09:49:48 +02:00
|
|
|
void MainTab::updateDateTimeFields()
|
|
|
|
{
|
|
|
|
ui.dateEdit->setDisplayFormat(prefs.date_format);
|
|
|
|
ui.timeEdit->setDisplayFormat(prefs.time_format);
|
|
|
|
}
|
|
|
|
|
2013-12-03 21:44:48 +01:00
|
|
|
void MainTab::hideMessage()
|
|
|
|
{
|
|
|
|
ui.diveNotesMessage->animatedHide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::closeMessage()
|
|
|
|
{
|
|
|
|
hideMessage();
|
|
|
|
ui.diveNotesMessage->setCloseButtonVisible(false);
|
2019-01-27 22:08:13 +01:00
|
|
|
}
|
2013-12-03 21:44:48 +01:00
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
void MainTab::closeWarning()
|
|
|
|
{
|
2019-05-24 21:38:56 +02:00
|
|
|
ui.multiDiveWarningMessage->hide();
|
2019-05-24 21:11:20 +02:00
|
|
|
}
|
|
|
|
|
2013-12-03 21:44:48 +01:00
|
|
|
void MainTab::displayMessage(QString str)
|
|
|
|
{
|
2014-08-04 22:45:17 -07:00
|
|
|
ui.diveNotesMessage->setCloseButtonVisible(false);
|
2013-12-03 21:44:48 +01:00
|
|
|
ui.diveNotesMessage->setText(str);
|
|
|
|
ui.diveNotesMessage->animatedShow();
|
|
|
|
}
|
|
|
|
|
2020-03-02 16:03:32 +01:00
|
|
|
void MainTab::enableEdition()
|
2013-08-13 08:34:04 -03:00
|
|
|
{
|
2020-03-18 22:42:47 +01:00
|
|
|
if (current_dive == NULL || editMode)
|
2013-08-13 08:34:04 -03:00
|
|
|
return;
|
2015-09-23 17:11:43 -03:00
|
|
|
|
|
|
|
ui.editDiveSiteButton->setEnabled(false);
|
2018-10-12 16:13:42 +02:00
|
|
|
MainWindow::instance()->diveList->setEnabled(false);
|
2014-08-04 12:58:21 -03:00
|
|
|
MainWindow::instance()->setEnabledToolbar(false);
|
2014-07-03 14:45:01 -07:00
|
|
|
|
2019-02-24 21:22:33 +01:00
|
|
|
ui.dateEdit->setEnabled(true);
|
2020-02-27 22:10:43 +01:00
|
|
|
displayMessage(tr("This dive is being edited."));
|
|
|
|
|
2020-03-18 22:42:47 +01:00
|
|
|
editMode = true;
|
2013-08-13 08:34:04 -03:00
|
|
|
}
|
|
|
|
|
2019-01-27 22:08:13 +01:00
|
|
|
// This function gets called if a field gets updated by an undo command.
|
|
|
|
// Refresh the corresponding UI field.
|
2019-06-23 09:22:26 +02:00
|
|
|
void MainTab::divesChanged(const QVector<dive *> &dives, DiveField field)
|
2019-01-27 22:08:13 +01:00
|
|
|
{
|
2019-02-11 15:34:43 +01:00
|
|
|
// If the current dive is not in list of changed dives, do nothing
|
|
|
|
if (!current_dive || !dives.contains(current_dive))
|
2019-01-27 22:08:13 +01:00
|
|
|
return;
|
|
|
|
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.duration)
|
2019-02-10 17:37:06 +01:00
|
|
|
ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds));
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.depth)
|
2019-02-10 17:37:06 +01:00
|
|
|
ui.depth->setText(get_depth_string(current_dive->maxdepth, true));
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.rating)
|
2019-01-28 22:35:07 +01:00
|
|
|
ui.rating->setCurrentStars(current_dive->rating);
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.notes)
|
2019-01-27 22:08:13 +01:00
|
|
|
updateNotes(current_dive);
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.datetime) {
|
2019-03-19 22:05:52 +01:00
|
|
|
updateDateTime(current_dive);
|
|
|
|
DivePlannerPointsModel::instance()->getDiveplan().when = current_dive->when;
|
2019-10-13 12:44:39 +02:00
|
|
|
}
|
|
|
|
if (field.divesite)
|
2019-03-20 21:46:58 +01:00
|
|
|
updateDiveSite(current_dive);
|
2020-11-14 17:42:59 +01:00
|
|
|
if (field.tags)
|
2019-02-07 19:59:34 +01:00
|
|
|
ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
|
2020-11-14 17:42:59 +01:00
|
|
|
if (field.buddy)
|
2019-02-07 21:00:09 +01:00
|
|
|
ui.buddy->setText(current_dive->buddy);
|
2020-11-14 17:42:59 +01:00
|
|
|
if (field.divemaster)
|
2019-02-07 21:23:00 +01:00
|
|
|
ui.divemaster->setText(current_dive->divemaster);
|
2019-10-13 12:44:39 +02:00
|
|
|
|
|
|
|
// If duration or depth changed, the profile needs to be replotted
|
|
|
|
if (field.duration || field.depth)
|
2021-01-27 18:08:23 +01:00
|
|
|
MainWindow::instance()->refreshProfile();
|
2019-01-27 22:08:13 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 17:48:08 +01:00
|
|
|
void MainTab::diveSiteEdited(dive_site *ds, int)
|
|
|
|
{
|
|
|
|
if (current_dive && current_dive->dive_site == ds)
|
|
|
|
updateDiveSite(current_dive);
|
|
|
|
}
|
|
|
|
|
2019-02-24 21:22:33 +01:00
|
|
|
// This function gets called if a trip-field gets updated by an undo command.
|
|
|
|
// Refresh the corresponding UI field.
|
|
|
|
void MainTab::tripChanged(dive_trip *trip, TripField field)
|
|
|
|
{
|
|
|
|
// If the current dive is not in list of changed dives, do nothing
|
|
|
|
if (currentTrip != trip)
|
|
|
|
return;
|
|
|
|
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.notes)
|
2019-02-24 21:22:33 +01:00
|
|
|
ui.notes->setText(currentTrip->notes);
|
2019-10-13 12:44:39 +02:00
|
|
|
if (field.location)
|
2019-02-24 21:22:33 +01:00
|
|
|
ui.diveTripLocation->setText(currentTrip->location);
|
|
|
|
}
|
|
|
|
|
2014-05-16 15:12:46 +09:00
|
|
|
void MainTab::nextInputField(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-11-11 06:23:18 +09:00
|
|
|
bool MainTab::isEditing()
|
|
|
|
{
|
2020-03-18 22:42:47 +01:00
|
|
|
return editMode;
|
2013-11-11 06:23:18 +09:00
|
|
|
}
|
|
|
|
|
2019-08-29 23:16:38 +02:00
|
|
|
static bool isHtml(const QString &s)
|
|
|
|
{
|
|
|
|
return s.contains("<div", Qt::CaseInsensitive) || s.contains("<table", Qt::CaseInsensitive);
|
|
|
|
}
|
|
|
|
|
2019-01-27 22:08:13 +01:00
|
|
|
void MainTab::updateNotes(const struct dive *d)
|
|
|
|
{
|
|
|
|
QString tmp(d->notes);
|
2019-08-29 23:16:38 +02:00
|
|
|
if (isHtml(tmp)) {
|
2019-01-27 22:08:13 +01:00
|
|
|
ui.notes->setHtml(tmp);
|
|
|
|
} else {
|
|
|
|
ui.notes->setPlainText(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 21:53:50 +02:00
|
|
|
void MainTab::updateDateTime(const struct dive *d)
|
|
|
|
{
|
|
|
|
QDateTime localTime = timestampToDateTime(d->when);
|
2019-03-19 22:05:52 +01:00
|
|
|
ui.dateEdit->setDate(localTime.date());
|
|
|
|
ui.timeEdit->setTime(localTime.time());
|
|
|
|
}
|
|
|
|
|
2019-08-07 21:53:50 +02:00
|
|
|
void MainTab::updateTripDate(const struct dive_trip *t)
|
|
|
|
{
|
|
|
|
QDateTime localTime = timestampToDateTime(trip_date(t));
|
|
|
|
ui.dateEdit->setDate(localTime.date());
|
|
|
|
}
|
|
|
|
|
2019-03-20 21:46:58 +01:00
|
|
|
void MainTab::updateDiveSite(struct dive *d)
|
|
|
|
{
|
|
|
|
struct dive_site *ds = d->dive_site;
|
2019-04-25 00:26:48 +02:00
|
|
|
ui.location->setCurrentDiveSite(d);
|
2019-03-20 21:46:58 +01:00
|
|
|
if (ds) {
|
|
|
|
ui.locationTags->setText(constructLocationTags(&ds->taxonomy, true));
|
|
|
|
|
|
|
|
if (ui.locationTags->text().isEmpty() && has_location(&ds->location))
|
|
|
|
ui.locationTags->setText(printGPSCoords(&ds->location));
|
|
|
|
ui.editDiveSiteButton->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ui.locationTags->clear();
|
|
|
|
ui.editDiveSiteButton->setEnabled(false);
|
|
|
|
}
|
2020-05-08 11:43:22 +02:00
|
|
|
|
|
|
|
if (ui.locationTags->text().isEmpty())
|
|
|
|
ui.locationTags->hide();
|
|
|
|
else
|
|
|
|
ui.locationTags->show();
|
2019-03-20 21:46:58 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:29:08 +01:00
|
|
|
void MainTab::updateDiveInfo()
|
2013-05-06 13:23:14 -03:00
|
|
|
{
|
2015-09-21 14:01:58 -03:00
|
|
|
ui.location->refreshDiveSiteCache();
|
2014-05-26 15:17:34 -07:00
|
|
|
// don't execute this while adding / planning a dive
|
2021-02-21 19:10:14 +01:00
|
|
|
if (editMode || DivePlannerPointsModel::instance()->isPlanner())
|
2013-11-12 16:33:27 +09:00
|
|
|
return;
|
2019-04-12 20:33:43 +02:00
|
|
|
|
2020-09-12 23:31:46 +02:00
|
|
|
// If there is no current dive, disable all widgets except the last two,
|
|
|
|
// which are the dive site tab and the dive computer tabs.
|
|
|
|
// TODO: Conceptually, these two shouldn't even be a tabs here!
|
2019-04-12 20:33:43 +02:00
|
|
|
bool enabled = current_dive != nullptr;
|
|
|
|
ui.notesTab->setEnabled(enabled);
|
2020-09-12 23:31:46 +02:00
|
|
|
for (int i = 0; i < extraWidgets.size() - 2; ++i)
|
2019-04-12 20:33:43 +02:00
|
|
|
extraWidgets[i]->setEnabled(enabled);
|
|
|
|
|
2020-03-18 22:37:18 +01:00
|
|
|
ignoreInput = true; // don't trigger on changes to the widgets
|
2014-07-02 22:15:08 -07:00
|
|
|
|
2019-03-29 18:29:08 +01:00
|
|
|
if (current_dive) {
|
2020-04-13 19:01:36 +02:00
|
|
|
for (TabBase *widget: extraWidgets)
|
|
|
|
widget->updateData();
|
|
|
|
|
2019-05-04 14:23:46 +02:00
|
|
|
// If we're on the dive-site tab, we don't want to switch tab when entering / exiting
|
|
|
|
// trip mode. The reason is that
|
|
|
|
// 1) this disrupts the user-experience and
|
|
|
|
// 2) the filter is reset, potentially erasing the current trip under our feet.
|
|
|
|
// TODO: Don't hard code tab location!
|
|
|
|
bool onDiveSiteTab = ui.tabWidget->currentIndex() == 6;
|
2020-05-02 18:14:44 +02:00
|
|
|
currentTrip = single_selected_trip();
|
|
|
|
if (currentTrip) {
|
2019-05-04 14:23:46 +02:00
|
|
|
// Remember the tab selected for last dive but only if we're not on the dive site tab
|
|
|
|
if (lastSelectedDive && !onDiveSiteTab)
|
2017-11-30 20:33:43 +01:00
|
|
|
lastTabSelectedDive = ui.tabWidget->currentIndex();
|
2017-11-30 19:36:05 +01:00
|
|
|
ui.tabWidget->setTabText(0, tr("Trip notes"));
|
2019-05-04 14:23:46 +02:00
|
|
|
// Recover the tab selected for last dive trip but only if we're not on the dive site tab
|
|
|
|
if (lastSelectedDive && !onDiveSiteTab)
|
2017-11-30 20:33:43 +01:00
|
|
|
ui.tabWidget->setCurrentIndex(lastTabSelectedDiveTrip);
|
|
|
|
lastSelectedDive = false;
|
2013-06-14 09:17:46 -07:00
|
|
|
// only use trip relevant fields
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.divemaster->setVisible(false);
|
|
|
|
ui.DivemasterLabel->setVisible(false);
|
|
|
|
ui.buddy->setVisible(false);
|
|
|
|
ui.BuddyLabel->setVisible(false);
|
|
|
|
ui.rating->setVisible(false);
|
|
|
|
ui.RatingLabel->setVisible(false);
|
2013-11-04 20:28:03 +01:00
|
|
|
ui.tagWidget->setVisible(false);
|
|
|
|
ui.TagLabel->setVisible(false);
|
2016-01-17 12:53:50 +02:00
|
|
|
ui.dateEdit->setReadOnly(true);
|
2017-11-16 07:35:57 +01:00
|
|
|
ui.timeLabel->setVisible(false);
|
2016-01-17 12:53:51 +02:00
|
|
|
ui.timeEdit->setVisible(false);
|
2015-10-01 17:41:38 -03:00
|
|
|
ui.diveTripLocation->show();
|
|
|
|
ui.location->hide();
|
2019-06-03 22:44:37 +02:00
|
|
|
ui.locationPopupButton->hide();
|
2015-10-01 17:41:38 -03:00
|
|
|
ui.editDiveSiteButton->hide();
|
2013-06-14 09:17:46 -07:00
|
|
|
// rename the remaining fields and fill data from selected trip
|
2014-07-11 00:06:42 +01:00
|
|
|
ui.LocationLabel->setText(tr("Trip location"));
|
2015-10-01 18:11:03 -03:00
|
|
|
ui.diveTripLocation->setText(currentTrip->location);
|
2019-08-07 21:53:50 +02:00
|
|
|
updateTripDate(currentTrip);
|
2015-07-01 16:38:22 -07:00
|
|
|
ui.locationTags->clear();
|
2015-09-25 14:51:10 -03:00
|
|
|
//TODO: Fix this.
|
|
|
|
//ui.location->setText(currentTrip->location);
|
2014-07-11 00:06:42 +01:00
|
|
|
ui.NotesLabel->setText(tr("Trip notes"));
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.notes->setText(currentTrip->notes);
|
2017-02-04 13:44:10 -08:00
|
|
|
ui.depth->setVisible(false);
|
|
|
|
ui.depthLabel->setVisible(false);
|
|
|
|
ui.duration->setVisible(false);
|
|
|
|
ui.durationLabel->setVisible(false);
|
2013-06-14 09:17:46 -07:00
|
|
|
} else {
|
2019-05-04 14:23:46 +02:00
|
|
|
// Remember the tab selected for last dive trip but only if we're not on the dive site tab
|
|
|
|
if (!lastSelectedDive && !onDiveSiteTab)
|
2017-11-30 20:33:43 +01:00
|
|
|
lastTabSelectedDiveTrip = ui.tabWidget->currentIndex();
|
2017-11-30 19:36:05 +01:00
|
|
|
ui.tabWidget->setTabText(0, tr("Notes"));
|
2019-05-04 14:23:46 +02:00
|
|
|
// Recover the tab selected for last dive but only if we're not on the dive site tab
|
|
|
|
if (!lastSelectedDive && !onDiveSiteTab)
|
2017-11-30 20:33:43 +01:00
|
|
|
ui.tabWidget->setCurrentIndex(lastTabSelectedDive);
|
|
|
|
lastSelectedDive = true;
|
2013-06-14 09:17:46 -07:00
|
|
|
// make all the fields visible writeable
|
2015-10-01 17:41:38 -03:00
|
|
|
ui.diveTripLocation->hide();
|
|
|
|
ui.location->show();
|
2019-06-03 22:44:37 +02:00
|
|
|
ui.locationPopupButton->show();
|
2015-10-01 17:41:38 -03:00
|
|
|
ui.editDiveSiteButton->show();
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.divemaster->setVisible(true);
|
|
|
|
ui.buddy->setVisible(true);
|
|
|
|
ui.rating->setVisible(true);
|
|
|
|
ui.RatingLabel->setVisible(true);
|
|
|
|
ui.BuddyLabel->setVisible(true);
|
|
|
|
ui.DivemasterLabel->setVisible(true);
|
2013-11-04 20:28:03 +01:00
|
|
|
ui.TagLabel->setVisible(true);
|
|
|
|
ui.tagWidget->setVisible(true);
|
2016-01-17 12:53:50 +02:00
|
|
|
ui.dateEdit->setReadOnly(false);
|
2017-11-16 07:35:57 +01:00
|
|
|
ui.timeLabel->setVisible(true);
|
2016-01-17 12:53:51 +02:00
|
|
|
ui.timeEdit->setVisible(true);
|
2013-06-14 09:17:46 -07:00
|
|
|
/* and fill them from the dive */
|
2019-03-29 18:29:08 +01:00
|
|
|
ui.rating->setCurrentStars(current_dive->rating);
|
2013-06-14 09:17:46 -07:00
|
|
|
// reset labels in case we last displayed trip notes
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.LocationLabel->setText(tr("Location"));
|
|
|
|
ui.NotesLabel->setText(tr("Notes"));
|
2019-03-29 18:29:08 +01:00
|
|
|
ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
|
|
|
|
bool isManual = same_string(current_dive->dc.model, "manually added dive");
|
|
|
|
ui.depth->setVisible(isManual);
|
|
|
|
ui.depthLabel->setVisible(isManual);
|
|
|
|
ui.duration->setVisible(isManual);
|
|
|
|
ui.durationLabel->setVisible(isManual);
|
2019-04-26 09:39:33 +02:00
|
|
|
|
|
|
|
updateNotes(current_dive);
|
|
|
|
updateDiveSite(current_dive);
|
|
|
|
updateDateTime(current_dive);
|
|
|
|
ui.divemaster->setText(current_dive->divemaster);
|
|
|
|
ui.buddy->setText(current_dive->buddy);
|
2013-06-14 09:17:46 -07:00
|
|
|
}
|
2019-03-29 18:29:08 +01:00
|
|
|
ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds));
|
|
|
|
ui.depth->setText(get_depth_string(current_dive->maxdepth, true));
|
2015-06-25 15:42:28 -03:00
|
|
|
|
2017-10-06 07:51:02 -07:00
|
|
|
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
|
2015-10-08 07:38:26 +01:00
|
|
|
/* unset the special value text for date and time, just in case someone dove at midnight */
|
2019-04-03 19:34:52 +02:00
|
|
|
ui.dateEdit->setSpecialValueText(QString());
|
|
|
|
ui.timeEdit->setSpecialValueText(QString());
|
2013-05-08 12:08:00 -07:00
|
|
|
} else {
|
2013-05-19 17:38:20 -07:00
|
|
|
/* clear the fields */
|
2017-04-04 19:21:30 +02:00
|
|
|
clearTabs();
|
2013-10-03 11:54:25 -07:00
|
|
|
ui.rating->setCurrentStars(0);
|
2015-02-12 12:46:21 -08:00
|
|
|
ui.location->clear();
|
2019-04-26 09:39:33 +02:00
|
|
|
ui.divemaster->clear();
|
|
|
|
ui.buddy->clear();
|
2019-07-10 23:13:54 +02:00
|
|
|
ui.notes->clear();
|
2015-10-08 07:38:26 +01:00
|
|
|
/* set date and time to minimums which triggers showing the special value text */
|
|
|
|
ui.dateEdit->setSpecialValueText(QString("-"));
|
|
|
|
ui.dateEdit->setMinimumDate(QDate(1, 1, 1));
|
|
|
|
ui.dateEdit->setDate(QDate(1, 1, 1));
|
|
|
|
ui.timeEdit->setSpecialValueText(QString("-"));
|
|
|
|
ui.timeEdit->setMinimumTime(QTime(0, 0, 0, 0));
|
|
|
|
ui.timeEdit->setTime(QTime(0, 0, 0, 0));
|
2018-01-01 08:49:40 +01:00
|
|
|
ui.tagWidget->clear();
|
2013-05-08 12:08:00 -07:00
|
|
|
}
|
2020-03-18 22:37:18 +01:00
|
|
|
ignoreInput = false;
|
2015-06-03 22:44:16 -03:00
|
|
|
|
2019-03-29 18:29:08 +01:00
|
|
|
if (verbose && current_dive && current_dive->dive_site)
|
|
|
|
qDebug() << "Set the current dive site:" << current_dive->dive_site->uuid;
|
2013-05-06 13:23:14 -03:00
|
|
|
}
|
|
|
|
|
2015-08-30 01:00:22 +02:00
|
|
|
void MainTab::refreshDisplayedDiveSite()
|
|
|
|
{
|
2019-04-25 00:26:48 +02:00
|
|
|
ui.location->setCurrentDiveSite(current_dive);
|
2015-08-30 01:00:22 +02:00
|
|
|
}
|
|
|
|
|
2013-09-18 21:56:53 -03:00
|
|
|
void MainTab::acceptChanges()
|
2013-05-18 20:42:59 -03:00
|
|
|
{
|
2019-02-05 08:01:04 +01:00
|
|
|
if (ui.location->hasFocus())
|
2019-04-01 21:07:51 +02:00
|
|
|
stealFocus();
|
2015-07-13 15:38:46 -03:00
|
|
|
|
2020-03-18 22:37:18 +01:00
|
|
|
ignoreInput = true;
|
2014-08-23 11:49:28 -03:00
|
|
|
ui.dateEdit->setEnabled(true);
|
2013-12-03 21:44:48 +01:00
|
|
|
hideMessage();
|
2019-03-03 17:10:09 +01:00
|
|
|
|
2021-01-29 16:15:17 +01:00
|
|
|
MainWindow::instance()->showProfile();
|
|
|
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
|
|
|
Command::editProfile(&displayed_dive);
|
|
|
|
|
2018-10-12 16:13:42 +02:00
|
|
|
int scrolledBy = MainWindow::instance()->diveList->verticalScrollBar()->sliderPosition();
|
2021-01-29 16:15:17 +01:00
|
|
|
MainWindow::instance()->diveList->reload();
|
|
|
|
MainWindow::instance()->refreshDisplay();
|
|
|
|
MainWindow::instance()->refreshProfile();
|
|
|
|
|
2014-02-19 19:43:34 +02:00
|
|
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
2018-10-12 16:13:42 +02:00
|
|
|
MainWindow::instance()->diveList->verticalScrollBar()->setSliderPosition(scrolledBy);
|
|
|
|
MainWindow::instance()->diveList->setFocus();
|
2014-08-04 12:58:21 -03:00
|
|
|
MainWindow::instance()->setEnabledToolbar(true);
|
2017-10-06 07:51:02 -07:00
|
|
|
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
|
2020-03-18 22:37:18 +01:00
|
|
|
ignoreInput = false;
|
2020-03-18 22:42:47 +01:00
|
|
|
editMode = false;
|
2013-09-25 14:36:59 -03:00
|
|
|
}
|
|
|
|
|
2013-09-18 21:56:53 -03:00
|
|
|
void MainTab::rejectChanges()
|
2013-05-18 20:42:59 -03:00
|
|
|
{
|
2021-01-29 16:15:17 +01:00
|
|
|
if (QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(tr("Discard the changes?"),
|
|
|
|
tr("You are about to discard your changes.")),
|
|
|
|
QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Discard) != QMessageBox::Discard) {
|
|
|
|
return;
|
2014-06-03 18:01:00 -07:00
|
|
|
}
|
2021-01-29 16:15:17 +01:00
|
|
|
|
2014-08-23 11:49:28 -03:00
|
|
|
ui.dateEdit->setEnabled(true);
|
2020-03-18 22:42:47 +01:00
|
|
|
editMode = false;
|
2013-12-03 21:44:48 +01:00
|
|
|
hideMessage();
|
2019-03-28 17:23:35 +01:00
|
|
|
// no harm done to call cancelPlan even if we were not PLAN mode...
|
2014-07-06 12:36:25 -07:00
|
|
|
DivePlannerPointsModel::instance()->cancelPlan();
|
|
|
|
|
2019-03-29 18:29:08 +01:00
|
|
|
updateDiveInfo();
|
2017-04-04 19:21:30 +02:00
|
|
|
|
2014-07-06 12:36:25 -07:00
|
|
|
// show the profile and dive info
|
2021-01-29 16:15:17 +01:00
|
|
|
MainWindow::instance()->refreshDisplay();
|
2021-01-27 18:08:23 +01:00
|
|
|
MainWindow::instance()->refreshProfile();
|
2014-08-04 12:58:21 -03:00
|
|
|
MainWindow::instance()->setEnabledToolbar(true);
|
2017-10-06 07:51:02 -07:00
|
|
|
ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty());
|
2013-05-18 20:42:59 -03:00
|
|
|
}
|
2013-08-16 15:52:40 -03:00
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
void MainTab::divesEdited(int i)
|
|
|
|
{
|
|
|
|
// No warning if only one dive was edited
|
|
|
|
if (i <= 1)
|
|
|
|
return;
|
|
|
|
ui.multiDiveWarningMessage->setCloseButtonVisible(false);
|
|
|
|
ui.multiDiveWarningMessage->setText(tr("Warning: edited %1 dives").arg(i));
|
2019-05-24 21:38:56 +02:00
|
|
|
ui.multiDiveWarningMessage->show();
|
2019-05-24 21:11:20 +02:00
|
|
|
}
|
|
|
|
|
2019-02-07 21:00:09 +01:00
|
|
|
void MainTab::on_buddy_editingFinished()
|
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2015-02-01 21:25:27 +02:00
|
|
|
return;
|
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editBuddies(stringToList(ui.buddy->toPlainText()), false));
|
2013-05-18 20:42:59 -03:00
|
|
|
}
|
|
|
|
|
2019-02-07 21:23:00 +01:00
|
|
|
void MainTab::on_divemaster_editingFinished()
|
2013-05-18 20:42:59 -03:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2015-02-01 21:25:27 +02:00
|
|
|
return;
|
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editDiveMaster(stringToList(ui.divemaster->toPlainText()), false));
|
2013-05-18 20:42:59 -03:00
|
|
|
}
|
|
|
|
|
2019-02-10 17:37:06 +01:00
|
|
|
void MainTab::on_duration_editingFinished()
|
2017-02-04 13:59:20 -08:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2017-02-04 13:59:20 -08:00
|
|
|
return;
|
2017-02-25 21:00:09 -08:00
|
|
|
|
2019-02-10 17:37:06 +01:00
|
|
|
// Duration editing is special: we only edit the current dive.
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editDuration(parseDurationToSeconds(ui.duration->text()), true));
|
2017-02-04 13:59:20 -08:00
|
|
|
}
|
|
|
|
|
2019-02-10 17:37:06 +01:00
|
|
|
void MainTab::on_depth_editingFinished()
|
2017-02-04 13:59:20 -08:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2017-02-04 13:59:20 -08:00
|
|
|
return;
|
2019-02-10 17:37:06 +01:00
|
|
|
|
|
|
|
// Depth editing is special: we only edit the current dive.
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editDepth(parseLengthToMm(ui.depth->text()), true));
|
2017-02-04 13:59:20 -08:00
|
|
|
}
|
|
|
|
|
2019-03-19 22:05:52 +01:00
|
|
|
// Editing of the dive time is different. If multiple dives are edited,
|
|
|
|
// all dives are shifted by an offset.
|
|
|
|
static void shiftTime(QDateTime &dateTime)
|
|
|
|
{
|
2020-05-22 18:53:25 +02:00
|
|
|
timestamp_t when = dateTimeToTimestamp(dateTime);
|
2019-03-19 22:05:52 +01:00
|
|
|
if (current_dive && current_dive->when != when) {
|
2019-06-24 12:04:50 +08:00
|
|
|
timestamp_t offset = when - current_dive->when;
|
2020-01-03 16:04:54 +01:00
|
|
|
Command::shiftTime(getDiveSelection(), (int)offset);
|
2019-03-19 22:05:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 21:02:10 +02:00
|
|
|
void MainTab::on_dateEdit_editingFinished()
|
2013-09-20 16:41:42 -07:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2014-06-02 18:13:50 -07:00
|
|
|
return;
|
2020-05-22 18:02:15 +02:00
|
|
|
QDateTime dateTime = timestampToDateTime(current_dive->when);
|
2020-05-06 21:02:10 +02:00
|
|
|
dateTime.setDate(ui.dateEdit->date());
|
2019-03-19 22:05:52 +01:00
|
|
|
shiftTime(dateTime);
|
2013-09-20 16:41:42 -07:00
|
|
|
}
|
|
|
|
|
2020-05-06 21:02:10 +02:00
|
|
|
void MainTab::on_timeEdit_editingFinished()
|
2014-06-26 14:54:16 -03:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2014-06-26 14:54:16 -03:00
|
|
|
return;
|
2020-05-22 18:02:15 +02:00
|
|
|
QDateTime dateTime = timestampToDateTime(current_dive->when);
|
2020-05-06 21:02:10 +02:00
|
|
|
dateTime.setTime(ui.timeEdit->time());
|
2019-03-19 22:05:52 +01:00
|
|
|
shiftTime(dateTime);
|
2014-06-26 14:54:16 -03:00
|
|
|
}
|
|
|
|
|
2019-02-07 19:59:34 +01:00
|
|
|
void MainTab::on_tagWidget_editingFinished()
|
2013-11-02 02:20:02 +01:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2015-02-01 21:25:27 +02:00
|
|
|
return;
|
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editTags(ui.tagWidget->getBlockStringList(), false));
|
2013-11-02 02:20:02 +01:00
|
|
|
}
|
|
|
|
|
2015-09-23 14:46:29 -03:00
|
|
|
void MainTab::on_location_diveSiteSelected()
|
2013-05-18 20:42:59 -03:00
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2014-05-07 23:51:39 +02:00
|
|
|
return;
|
2015-06-03 22:32:13 -03:00
|
|
|
|
2019-03-20 21:46:58 +01:00
|
|
|
struct dive_site *newDs = ui.location->currDiveSite();
|
|
|
|
if (newDs == RECENTLY_ADDED_DIVESITE)
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editDiveSiteNew(ui.location->text(), false));
|
2019-03-20 21:46:58 +01:00
|
|
|
else
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editDiveSite(newDs, false));
|
2015-10-01 17:52:00 -03:00
|
|
|
}
|
|
|
|
|
2019-04-25 13:16:30 +02:00
|
|
|
void MainTab::on_locationPopupButton_clicked()
|
|
|
|
{
|
|
|
|
ui.location->showAllSites();
|
|
|
|
}
|
|
|
|
|
2019-02-24 21:22:33 +01:00
|
|
|
void MainTab::on_diveTripLocation_editingFinished()
|
2015-10-01 17:52:00 -03:00
|
|
|
{
|
2019-02-24 21:22:33 +01:00
|
|
|
if (!currentTrip)
|
|
|
|
return;
|
|
|
|
Command::editTripLocation(currentTrip, ui.diveTripLocation->text());
|
2013-05-18 20:42:59 -03:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:27:31 +01:00
|
|
|
void MainTab::on_notes_editingFinished()
|
|
|
|
{
|
2019-02-24 21:22:33 +01:00
|
|
|
if (!currentTrip && !current_dive)
|
|
|
|
return;
|
2019-01-25 18:27:31 +01:00
|
|
|
|
2019-08-29 23:16:38 +02:00
|
|
|
QString html = ui.notes->toHtml();
|
|
|
|
QString notes = isHtml(html) ? html : ui.notes->toPlainText();
|
2019-01-25 18:27:31 +01:00
|
|
|
|
2019-02-24 21:22:33 +01:00
|
|
|
if (currentTrip)
|
|
|
|
Command::editTripNotes(currentTrip, notes);
|
|
|
|
else
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editNotes(notes, false));
|
2013-05-18 20:42:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_rating_valueChanged(int value)
|
|
|
|
{
|
2020-03-18 22:37:18 +01:00
|
|
|
if (ignoreInput || !current_dive)
|
2015-01-04 20:06:33 +02:00
|
|
|
return;
|
2019-01-28 22:35:07 +01:00
|
|
|
|
2019-05-24 21:11:20 +02:00
|
|
|
divesEdited(Command::editRating(value, false));
|
2013-05-18 20:42:59 -03:00
|
|
|
}
|
2013-05-20 06:25:16 -07:00
|
|
|
|
2019-04-01 21:07:51 +02:00
|
|
|
// Remove focus from any active field to update the corresponding value in the dive.
|
|
|
|
// Do this by setting the focus to ourself
|
|
|
|
void MainTab::stealFocus()
|
|
|
|
{
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
2014-06-03 15:29:28 -07:00
|
|
|
void MainTab::escDetected()
|
|
|
|
{
|
2019-02-05 08:01:04 +01:00
|
|
|
// In edit mode, pressing escape cancels the current changes.
|
|
|
|
// In standard mode, remove focus of any active widget to
|
2020-03-18 22:42:47 +01:00
|
|
|
if (editMode)
|
2014-06-03 15:29:28 -07:00
|
|
|
rejectChanges();
|
2019-02-05 08:01:04 +01:00
|
|
|
else
|
2019-04-01 21:07:51 +02:00
|
|
|
stealFocus();
|
2014-06-03 15:29:28 -07:00
|
|
|
}
|
2014-06-27 16:17:33 +04:00
|
|
|
|
2019-02-23 18:31:02 +01:00
|
|
|
void MainTab::clearTabs()
|
|
|
|
{
|
|
|
|
for (auto widget: extraWidgets)
|
2017-04-04 19:21:30 +02:00
|
|
|
widget->clear();
|
2015-10-20 22:36:59 +02:00
|
|
|
}
|
2020-11-02 12:10:33 -08:00
|
|
|
|
2020-11-04 13:09:44 -08:00
|
|
|
void MainTab::changeEvent(QEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->type() == QEvent::PaletteChange) {
|
|
|
|
// check if this is a light or dark mode
|
|
|
|
bool dark = paletteIsDark(palette());
|
|
|
|
if (dark != isDark) {
|
|
|
|
// things have changed, so setup the colors correctly
|
|
|
|
isDark = dark;
|
|
|
|
colorsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QTabWidget::changeEvent(ev);
|
|
|
|
}
|
|
|
|
|
2020-11-02 12:36:29 -08:00
|
|
|
// setup the colors of 'header' elements in the tab widget
|
2020-11-02 12:10:33 -08:00
|
|
|
void MainTab::colorsChanged()
|
|
|
|
{
|
2020-11-04 13:09:44 -08:00
|
|
|
QString colorText = isDark ? QStringLiteral("lightblue") : QStringLiteral("mediumblue");
|
2020-11-02 12:36:29 -08:00
|
|
|
QString lastpart = colorText + " ;}";
|
|
|
|
|
|
|
|
// only set the color if the widget is enabled
|
|
|
|
QString CSSLabelcolor = "QLabel:enabled { color: " + lastpart;
|
|
|
|
QString CSSTitlecolor = "QGroupBox::title:enabled { color: " + lastpart ;
|
|
|
|
|
|
|
|
// apply to all the group boxes
|
|
|
|
QList<QGroupBox *>groupBoxes = this->findChildren<QGroupBox *>();
|
|
|
|
for (QGroupBox *gb: groupBoxes)
|
|
|
|
gb->setStyleSheet(QString(CSSTitlecolor));
|
|
|
|
|
|
|
|
// apply to all labels that are marked as headers in the .ui file
|
|
|
|
QList<QLabel *>labels = this->findChildren<QLabel *>();
|
|
|
|
for (QLabel *ql: labels) {
|
|
|
|
if (ql->property("isHeader").toBool())
|
|
|
|
ql->setStyleSheet(QString(CSSLabelcolor));
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally call the individual updateUi() functions so they can overwrite these style sheets
|
2020-11-02 12:10:33 -08:00
|
|
|
for (TabBase *widget: extraWidgets)
|
2020-11-04 13:09:44 -08:00
|
|
|
widget->updateUi(colorText);
|
2020-11-02 12:10:33 -08:00
|
|
|
}
|