From 7a4abd7477dc2a4f8e52f7bb00c19890c6ec2ca2 Mon Sep 17 00:00:00 2001 From: Willem Ferguson Date: Sun, 10 Nov 2019 13:09:19 -0800 Subject: Reorganise the Information tab of the Info panel 1) Reorganise the existing widgets in the Information tab 2) Move divemode widget and visibility widget from Notes tab to Information tab 3) Translate water density to a word indicating water type 4) Reorganise the Notes tab to compensate for the moving the divemode and visibility widgets to the Information tab 5) Remove the problems in showing a QGroupBox in Qt Windows. I do this by removing the CSS specifying border characteristics Signed-off-by: willemferguson Signed-off-by: Dirk Hohndel --- desktop-widgets/tab-widgets/TabDiveInformation.cpp | 93 ++++- desktop-widgets/tab-widgets/TabDiveInformation.h | 5 + desktop-widgets/tab-widgets/TabDiveInformation.ui | 409 ++++++++++++++++----- desktop-widgets/tab-widgets/maintab.cpp | 43 --- desktop-widgets/tab-widgets/maintab.h | 3 - desktop-widgets/tab-widgets/maintab.ui | 138 ++----- 6 files changed, 445 insertions(+), 246 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 928627311..641e762f2 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -1,6 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 #include "TabDiveInformation.h" #include "ui_TabDiveInformation.h" +#include "desktop-widgets/mainwindow.h" // TODO: Only used temporarilly for edit mode changes +#include "profile-widget/profilewidget2.h" #include "../tagwidget.h" #include "core/units.h" #include "core/dive.h" @@ -12,6 +14,7 @@ #define COMBO_CHANGED 0 #define TEXT_EDITED 1 +#define CSS_SET_HEADING_BLUE "QLabel { color: mediumblue;} " TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) { @@ -20,6 +23,28 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne QStringList atmPressTypes { "mbar", get_depth_unit() ,"use dc"}; ui->atmPressType->insertItems(0, atmPressTypes); pressTypeIndex = 0; + // This needs to be the same order as enum dive_comp_type in dive.h! + QStringList types; + for (int i = 0; i < NUM_DIVEMODE; i++) + types.append(gettextFromC::tr(divemode_text_ui[i])); + ui->diveType->insertItems(0, types); + connect(ui->diveType, SIGNAL(currentIndexChanged(int)), this, SLOT(diveModeChanged(int))); + QString CSSSetSmallLabel = "QLabel { color: mediumblue; font-size: " + /* // Using label height ... */ + QString::number((int)(0.5 + ui->diveHeadingLabel->geometry().height() * 0.66)) + "px;}"; // .. set CSS font size of star widget subscripts + ui->scrollAreaWidgetContents_3->setStyleSheet("QGroupBox::title { color: mediumblue;} "); + ui->diveModeBox->setStyleSheet("QGroupBox{ padding: 0;} "); + ui->diveHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); + ui->gasHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); + ui->environmentHeadingLabel->setStyleSheet(CSS_SET_HEADING_BLUE); + ui->groupBox_visibility->setStyleSheet(CSSSetSmallLabel); + QAction *action = new QAction(tr("OK"), this); + connect(action, &QAction::triggered, this, &TabDiveInformation::closeWarning); + ui->multiDiveWarningMessage->addAction(action); + action = new QAction(tr("Undo"), this); + connect(action, &QAction::triggered, Command::undoAction(this), &QAction::trigger); + connect(action, &QAction::triggered, this, &TabDiveInformation::closeWarning); + ui->multiDiveWarningMessage->addAction(action); + ui->multiDiveWarningMessage->hide(); } TabDiveInformation::~TabDiveInformation() @@ -34,7 +59,6 @@ void TabDiveInformation::clear() ui->maxcnsText->clear(); ui->oxygenHeliumText->clear(); ui->gasUsedText->clear(); - ui->dateText->clear(); ui->diveTimeText->clear(); ui->surfaceIntervalText->clear(); ui->maximumDepthText->clear(); @@ -43,6 +67,22 @@ void TabDiveInformation::clear() ui->airTemperatureText->clear(); ui->atmPressVal->clear(); ui->salinityText->clear(); + ui->waterTypeText->clear(); +} + +void TabDiveInformation::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)); + ui->multiDiveWarningMessage->show(); +} + +void TabDiveInformation::closeWarning() +{ + ui->multiDiveWarningMessage->hide(); } // Update fields that depend on the dive profile @@ -87,7 +127,6 @@ void TabDiveInformation::updateProfile() if (current_dive->surface_pressure.mbar == 0) { ui->atmPressVal->clear(); // If no atm pressure for dive then clear text box } else { - ui->atmPressVal->setEnabled(true); QString pressStr; pressStr.sprintf("%d",current_dive->surface_pressure.mbar); @@ -98,7 +137,6 @@ void TabDiveInformation::updateProfile() // Update fields that depend on start of dive void TabDiveInformation::updateWhen() { - ui->dateText->setText(get_short_dive_date_string(current_dive->when)); timestamp_t surface_interval = get_surface_interval(current_dive->when); if (surface_interval >= 0) ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min"))); @@ -108,10 +146,19 @@ void TabDiveInformation::updateWhen() void TabDiveInformation::updateSalinity() { - if (current_dive->salinity) + if (current_dive->salinity) { // Set up the salinity string: ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0)); - else + if (current_dive->salinity < 10050) // Set water type indicator: + ui->waterTypeText->setText(tr("Fresh")); + else if (current_dive->salinity < 10190) + ui->waterTypeText->setText(tr("Salty")); + else if (current_dive->salinity < 10210) // (EN13319 = 1.019 - 1.021 g/l) + ui->waterTypeText->setText(tr("EN13319")); + else ui->waterTypeText->setText(tr("Salt")); + } else { ui->salinityText->clear(); + ui->waterTypeText->clear(); + } } void TabDiveInformation::updateData() @@ -125,12 +172,11 @@ void TabDiveInformation::updateData() updateWhen(); ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true)); ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true)); - updateSalinity(); - - ui->atmPressType->setEditable(true); ui->atmPressType->setItemText(1, get_depth_unit()); // Check for changes in depth unit (imperial/metric) - ui->atmPressType->setEditable(false); - ui->atmPressType->setCurrentIndex(0); // Set the atmospheric pressure combo box to mbar + ui->atmPressType->setCurrentIndex(0); // Set the atmospheric pressure combo box to mbar + updateMode(current_dive); + updateSalinity(); + ui->visibility->setCurrentStars(current_dive->visibility); } // This function gets called if a field gets updated by an undo command. @@ -141,6 +187,10 @@ void TabDiveInformation::divesChanged(const QVector &dives, DiveField fi if (!current_dive || !dives.contains(current_dive)) return; + if (field.visibility) + ui->visibility->setCurrentStars(current_dive->visibility); + if (field.mode) + updateMode(current_dive); if (field.duration || field.depth || field.mode) updateProfile(); if (field.air_temp) @@ -149,12 +199,29 @@ void TabDiveInformation::divesChanged(const QVector &dives, DiveField fi ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true)); if (field.atm_press) ui->atmPressVal->setText(ui->atmPressVal->text().sprintf("%d",current_dive->surface_pressure.mbar)); - if (field.datetime) - updateWhen(); if (field.salinity) updateSalinity(); } + +void TabDiveInformation::on_visibility_valueChanged(int value) +{ + if (current_dive) + divesEdited(Command::editVisibility(value, false)); +} + +void TabDiveInformation::updateMode(struct dive *d) +{ + ui->diveType->setCurrentIndex(get_dive_dc(d, dc_number)->divemode); + MainWindow::instance()->graphics->replot(); +} + +void TabDiveInformation::diveModeChanged(int index) +{ + if (current_dive) + divesEdited(Command::editMode(dc_number, (enum divemode_t)index, false)); +} + void TabDiveInformation::on_atmPressType_currentIndexChanged(int index) { updateTextBox(COMBO_CHANGED); } void TabDiveInformation::on_atmPressVal_editingFinished() { updateTextBox(TEXT_EDITED); } @@ -193,7 +260,7 @@ void TabDiveInformation::updateTextBox(int event) // Either the text box has bee break; } if (atmpress.mbar) - Command::editAtmPress(atmpress.mbar, false); // and save the pressure for undo + divesEdited(Command::editAtmPress(atmpress.mbar, false)); // and save the pressure for undo } } diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.h b/desktop-widgets/tab-widgets/TabDiveInformation.h index 5305f4146..8b38797c3 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.h +++ b/desktop-widgets/tab-widgets/TabDiveInformation.h @@ -18,8 +18,10 @@ public: void clear() override; private slots: void divesChanged(const QVector &dives, DiveField field); + void diveModeChanged(int index); void on_atmPressVal_editingFinished(); void on_atmPressType_currentIndexChanged(int index); + void on_visibility_valueChanged(int value); private: Ui::TabDiveInformation *ui; void updateProfile(); @@ -27,6 +29,9 @@ private: void updateWhen(); int pressTypeIndex; void updateTextBox(int event); + void updateMode(struct dive *d); + void divesEdited(int); + void closeWarning(); }; #endif diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.ui b/desktop-widgets/tab-widgets/TabDiveInformation.ui index b35ddf01d..41be1bd8a 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.ui +++ b/desktop-widgets/tab-widgets/TabDiveInformation.ui @@ -14,6 +14,9 @@ Information + + + @@ -48,35 +51,65 @@ 0 - 6 + 4 0 + + + + + DIVE + + + + - + + + DIVE + + + + + - Date + Dive mode + + + Qt::AlignHCenter + + + + + + + + Qt::AlignBottom - - - - - - - Qt::AlignCenter - + - + + Interval + + Qt::AlignHCenter + + + + 1 + 0 + + @@ -84,78 +117,124 @@ - Qt::AlignCenter + Qt::AlignHCenter - - + + - Gases used + Duration - + + Qt::AlignHCenter + + + + 1 + 0 + + + - + - Qt::AlignCenter + Qt::AlignHCenter - - + + - Gas consumed + Max. depth - + + Qt::AlignHCenter + + + + 1 + 0 + + + - + - Qt::AlignCenter + Qt::AlignHCenter - - + + + - SAC + Avg. depth - + + Qt::AlignHCenter + + + + 1 + 0 + + + - + - Qt::AlignCenter + Qt::AlignHCenter + - + + + GAS + + + + + + - CNS + Gas name - + + Qt::AlignHCenter + + + + 1 + 0 + + + - + @@ -167,14 +246,23 @@ - - + + - OTU + Gas consumed - + + Qt::AlignHCenter + + + + 0 + 0 + + + - + @@ -186,14 +274,23 @@ - - + + - Max. depth + SAC - + + Qt::AlignHCenter + + + + 0 + 0 + + + - + @@ -205,14 +302,23 @@ - - + + - Avg. depth + CNS - + + Qt::AlignHCenter + + + + 0 + 1 + + + - + @@ -224,42 +330,63 @@ - - - + + - Atm. pressure + OTU Qt::AlignHCenter - - - 0 - 0 - - - + + + 0 + 0 + + + - - - false + + + + + + + 0 + 0 + + + + Qt::AlignCenter - - - - - + + + + ENVIRONMENT + + + + + Air temp. + + Qt::AlignHCenter + + + + 0 + 0 + + @@ -267,18 +394,28 @@ - Qt::AlignCenter + Qt::AlignHCenter - + + Water temp. + + Qt::AlignHCenter + + + + 0 + 0 + + @@ -286,49 +423,139 @@ - Qt::AlignCenter + Qt::AlignHCenter - - + + + + + 4 + + + + - Dive time + Water type/Density - + + Qt::AlignHCenter + + + + 1 + 0 + + + + - - - - + + + EN13319 + + + + + + Qt::AlignCenter + - - + + + - Water type + Atm. pressure/Altitude + + + Qt::AlignHCenter - + + + 1 + 0 + + + - - - Qt::AlignCenter + + + false + + + + - + + + + + + + + Visibility + + + Qt::AlignHCenter + + + + 0 + 0 + + + + + 0 + + + + + + 0 + 0 + + + + Qt::StrongFocus + + + + + + + Bad + + + + + + + Good + + + + + + + + Qt::Vertical @@ -336,6 +563,12 @@ QSizePolicy::Expanding + + + 0 + 0 + + 20 diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index e10575942..7e82ca5f1 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -116,13 +116,6 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), // filled from a dive, they are made writeable setEnabled(false); - // This needs to be the same order as enum dive_comp_type in dive.h! - QStringList types = QStringList(); - for (int i = 0; i < NUM_DIVEMODE; i++) - types.append(gettextFromC::tr(divemode_text_ui[i])); - ui.DiveType->insertItems(0, types); - connect(ui.DiveType, SIGNAL(currentIndexChanged(int)), this, SLOT(divetype_Changed(int))); - Completers completers; completers.buddy = new QCompleter(&buddyModel, ui.buddy); completers.divemaster = new QCompleter(&diveMasterModel, ui.divemaster); @@ -282,12 +275,8 @@ void MainTab::divesChanged(const QVector &dives, DiveField field) ui.watertemp->setText(get_temperature_string(current_dive->watertemp, true)); if (field.rating) ui.rating->setCurrentStars(current_dive->rating); - if (field.visibility) - ui.visibility->setCurrentStars(current_dive->visibility); if (field.notes) updateNotes(current_dive); - if (field.mode) - updateMode(current_dive); if (field.datetime) { updateDateTime(current_dive); MainWindow::instance()->graphics->dateTimeChanged(); @@ -352,12 +341,6 @@ void MainTab::updateNotes(const struct dive *d) } } -void MainTab::updateMode(struct dive *d) -{ - ui.DiveType->setCurrentIndex(get_dive_dc(d, dc_number)->divemode); - MainWindow::instance()->graphics->replot(); -} - static QDateTime timestampToDateTime(timestamp_t when) { // Subsurface always uses "local time" as in "whatever was the local time at the location" @@ -442,14 +425,10 @@ void MainTab::updateDiveInfo() ui.BuddyLabel->setVisible(false); ui.rating->setVisible(false); ui.RatingLabel->setVisible(false); - ui.visibility->setVisible(false); - ui.visibilityLabel->setVisible(false); ui.tagWidget->setVisible(false); ui.TagLabel->setVisible(false); ui.airTempLabel->setVisible(false); ui.airtemp->setVisible(false); - ui.DiveType->setVisible(false); - ui.TypeLabel->setVisible(false); ui.waterTempLabel->setVisible(false); ui.watertemp->setVisible(false); ui.dateEdit->setReadOnly(true); @@ -496,16 +475,12 @@ void MainTab::updateDiveInfo() ui.buddy->setVisible(true); ui.rating->setVisible(true); ui.RatingLabel->setVisible(true); - ui.visibility->setVisible(true); - ui.visibilityLabel->setVisible(true); ui.BuddyLabel->setVisible(true); ui.DivemasterLabel->setVisible(true); ui.TagLabel->setVisible(true); ui.tagWidget->setVisible(true); ui.airTempLabel->setVisible(true); ui.airtemp->setVisible(true); - ui.TypeLabel->setVisible(true); - ui.DiveType->setVisible(true); ui.waterTempLabel->setVisible(true); ui.watertemp->setVisible(true); ui.dateEdit->setReadOnly(false); @@ -513,7 +488,6 @@ void MainTab::updateDiveInfo() ui.timeEdit->setVisible(true); /* and fill them from the dive */ ui.rating->setCurrentStars(current_dive->rating); - ui.visibility->setCurrentStars(current_dive->visibility); // reset labels in case we last displayed trip notes ui.LocationLabel->setText(tr("Location")); ui.NotesLabel->setText(tr("Notes")); @@ -525,7 +499,6 @@ void MainTab::updateDiveInfo() ui.durationLabel->setVisible(isManual); updateNotes(current_dive); - updateMode(current_dive); updateDiveSite(current_dive); updateDateTime(current_dive); ui.divemaster->setText(current_dive->divemaster); @@ -548,7 +521,6 @@ void MainTab::updateDiveInfo() /* clear the fields */ clearTabs(); ui.rating->setCurrentStars(0); - ui.visibility->setCurrentStars(0); ui.location->clear(); ui.divemaster->clear(); ui.buddy->clear(); @@ -771,13 +743,6 @@ void MainTab::on_airtemp_editingFinished() divesEdited(Command::editAirTemp(parseTemperatureToMkelvin(ui.airtemp->text()), false)); } -void MainTab::divetype_Changed(int index) -{ - if (editMode == IGNORE_MODE || !current_dive) - return; - divesEdited(Command::editMode(dc_number, (enum divemode_t)index, false)); -} - void MainTab::on_watertemp_editingFinished() { // If the field wasn't modified by the user, don't post a new undo command. @@ -881,14 +846,6 @@ void MainTab::on_rating_valueChanged(int value) divesEdited(Command::editRating(value, false)); } -void MainTab::on_visibility_valueChanged(int value) -{ - if (editMode == IGNORE_MODE || !current_dive) - return; - - divesEdited(Command::editVisibility(value, false)); -} - // 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() diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 55227c993..e4994a231 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -51,7 +51,6 @@ slots: void tripChanged(dive_trip *trip, TripField field); void updateDiveInfo(); void updateNotes(const struct dive *d); - void updateMode(struct dive *d); void updateDateTime(const struct dive *d); void updateTripDate(const struct dive_trip *t); void updateDiveSite(struct dive *d); @@ -66,12 +65,10 @@ slots: void on_airtemp_editingFinished(); void on_duration_editingFinished(); void on_depth_editingFinished(); - void divetype_Changed(int); void on_watertemp_editingFinished(); void on_dateEdit_dateChanged(const QDate &date); void on_timeEdit_timeChanged(const QTime & time); void on_rating_valueChanged(int value); - void on_visibility_valueChanged(int value); void on_tagWidget_editingFinished(); void hideMessage(); void closeMessage(); diff --git a/desktop-widgets/tab-widgets/maintab.ui b/desktop-widgets/tab-widgets/maintab.ui index 606f1dd54..8e172f91a 100644 --- a/desktop-widgets/tab-widgets/maintab.ui +++ b/desktop-widgets/tab-widgets/maintab.ui @@ -298,100 +298,15 @@ - - - 5 - - - 5 - - + + 5 - - 0 - - - - - - 0 - 0 - - - - Rating - - - - - - - - 0 - 0 - - - - Visibility - - - - - - - - 0 - 0 - - - - Qt::StrongFocus - - - - - - - - 0 - 0 - - - - Qt::StrongFocus - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - - - - - + + 5 - - 0 - - - - @@ -402,16 +317,6 @@ - - - - Dive mode - - - Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft - - - @@ -439,6 +344,41 @@ + + + + 5 + + + + + + 0 + 0 + + + + Rating + + + + + + + + 0 + 0 + + + + Qt::StrongFocus + + + + + + + -- cgit v1.2.3-70-g09d2