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 <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Willem Ferguson 2019-11-10 13:09:19 -08:00 committed by Dirk Hohndel
parent dc95b077d9
commit 7a4abd7477
6 changed files with 483 additions and 284 deletions

View file

@ -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<dive *> &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<dive *> &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
}
}