desktop: allow update of tab widget colors at run time

Adding a new virtual function to all of these classes may seem like overkill,
but of course the idea is that likely we'd allow similar changes to all of
them.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-11-02 12:10:33 -08:00
parent 00dd98163f
commit 7d18a525f1
7 changed files with 42 additions and 23 deletions

View file

@ -4,3 +4,7 @@
TabBase::TabBase(QWidget *parent) : QWidget(parent)
{
}
void TabBase::updateUi()
{
}

View file

@ -13,6 +13,7 @@ public:
TabBase(QWidget *parent = 0);
virtual void updateData() = 0;
virtual void clear() = 0;
virtual void updateUi();
};
#endif

View file

@ -24,17 +24,7 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne
connect(&diveListNotifier, &DiveListNotifier::cylinderRemoved, this, &TabDiveInformation::cylinderChanged);
connect(&diveListNotifier, &DiveListNotifier::cylinderEdited, this, &TabDiveInformation::cylinderChanged);
// Put together appropriate CSS stylesheets: NB: Colors below in same order as the enum in prefs.h
QStringList colors = { "mediumblue", "lightblue", "black" }; // If using dark theme, set color appropriately
QString colorText = colors[prefs.headerstyle_color];
QString lastpart = colorText + " ;}";
QString CSSLabelColor = "QLabel { color: " + lastpart;
QString CSSTitleColor = "QGroupBox::title { color: " + lastpart ;
QStringList atmPressTypes { "mbar", get_depth_unit() ,tr("Use DC")};
QString CSSSetSmallLabel = "QLabel { color: ";
CSSSetSmallLabel.append(colorText + "; font-size: ");
CSSSetSmallLabel.append(QString::number((int)(0.5 + ui->diveHeadingLabel->geometry().height() * 0.66)) + "px;}");
ui->atmPressType->insertItems(0, atmPressTypes);
pressTypeIndex = 0;
ui->waterTypeCombo->insertItems(0, getWaterTypesAsString());
@ -45,15 +35,6 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne
types.append(gettextFromC::tr(divemode_text_ui[i]));
ui->diveType->insertItems(0, types);
connect(ui->diveType, SIGNAL(currentIndexChanged(int)), this, SLOT(diveModeChanged(int)));
ui->scrollAreaWidgetContents_3->setStyleSheet(CSSTitleColor);
ui->diveHeadingLabel->setStyleSheet(CSSLabelColor);
ui->gasHeadingLabel->setStyleSheet(CSSLabelColor);
ui->environmentHeadingLabel->setStyleSheet(CSSLabelColor);
ui->groupBox_visibility->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_current->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_wavesize->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_surge->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_chill->setStyleSheet(CSSSetSmallLabel);
if (!prefs.extraEnvironmentalDefault) // if extraEnvironmental preference is turned off
showCurrentWidget(false, 0); // Show current star widget at lefthand side
QAction *action = new QAction(tr("OK"), this);
@ -68,7 +49,6 @@ TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(ne
updateWaterTypeWidget();
QPixmap warning (":salinity-warning-icon");
ui->salinityOverWrittenIcon->setPixmap(warning);
ui->salinityOverWrittenIcon->setToolTip(CSSSetSmallLabel);
ui->salinityOverWrittenIcon->setToolTipDuration(2500);
ui->salinityOverWrittenIcon->setVisible(false);
}
@ -241,7 +221,7 @@ void TabDiveInformation::updateData()
if (prefs.salinityEditDefault) { //If edit-salinity is enabled then set correct water type in combobox:
ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value));
} else { // If water salinity is not editable: show water type as a text label
ui->waterTypeText->setText(get_water_type_string(salinity_value));
ui->waterTypeText->setText(get_water_type_string(salinity_value));
}
ui->salinityText->setText(get_salinity_string(salinity_value));
} else {
@ -263,6 +243,31 @@ void TabDiveInformation::updateData()
showCurrentWidget(false, 0); // Show current star widget at lefthand side
}
void TabDiveInformation::updateUi()
{
// Put together appropriate CSS stylesheets: NB: colors below in same order as the enum in prefs.h
QStringList colors = { "mediumblue", "lightblue", "black" }; // If using dark theme, set color appropriately
QString colorText = colors[prefs.headerstyle_color];
QString lastpart = colorText + " ;}";
QString CSSLabelcolor = "QLabel { color: " + lastpart;
QString CSSTitlecolor = "QGroupBox::title { color: " + lastpart ;
QString CSSSetSmallLabel = "QLabel { color: ";
CSSSetSmallLabel.append(colorText + "; font-size: ");
CSSSetSmallLabel.append(QString::number((int)(0.5 + ui->diveHeadingLabel->geometry().height() * 0.66)) + "px;}");
ui->scrollAreaWidgetContents_3->setStyleSheet(CSSTitlecolor);
ui->diveHeadingLabel->setStyleSheet(CSSLabelcolor);
ui->gasHeadingLabel->setStyleSheet(CSSLabelcolor);
ui->environmentHeadingLabel->setStyleSheet(CSSLabelcolor);
ui->groupBox_visibility->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_current->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_wavesize->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_surge->setStyleSheet(CSSSetSmallLabel);
ui->groupBox_chill->setStyleSheet(CSSSetSmallLabel);
ui->salinityOverWrittenIcon->setToolTip(CSSSetSmallLabel);
}
// From the index of the water type combo box, set the dive->salinity to an appropriate value
void TabDiveInformation::on_waterTypeCombo_activated(int index)
{

View file

@ -16,6 +16,7 @@ public:
~TabDiveInformation();
void updateData() override;
void clear() override;
void updateUi() override;
private slots:
void divesChanged(const QVector<dive *> &dives, DiveField field);
void cylinderChanged(dive *d);

View file

@ -112,7 +112,7 @@ void TabDiveStatistics::updateData()
bool is_freedive = current_dive && current_dive->dc.divemode == FREEDIVE;
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ", is_freedive));
int seconds = stats_selection.total_time.seconds;
if (stats_selection.selection_size)
seconds /= stats_selection.selection_size;

View file

@ -34,6 +34,7 @@
#include "TabDiveStatistics.h"
#include "TabDiveSite.h"
#include "TabDiveComputer.h"
#include "core/settings/qPrefDisplay.h"
#include <QCompleter>
#include <QScrollBar>
@ -89,7 +90,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
// 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.
connect(PreferencesDialog::instance(), &PreferencesDialog::settingsChanged, this, &MainTab::updateDateTimeFields);
connect(qPrefDisplay::instance(), &qPrefDisplay::headerstyle_colorChanged, this, &MainTab::colorsChanged);
QAction *action = new QAction(tr("Apply changes"), this);
connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges()));
ui.diveNotesMessage->addAction(action);
@ -699,3 +700,9 @@ void MainTab::clearTabs()
for (auto widget: extraWidgets)
widget->clear();
}
void MainTab::colorsChanged()
{
for (TabBase *widget: extraWidgets)
widget->updateUi();
}

View file

@ -64,6 +64,7 @@ slots:
void enableEdition();
void escDetected(void);
void updateDateTimeFields();
void colorsChanged();
private:
Ui::MainTab ui;
bool editMode;