Show temperature units in the label when editing dive

Currently when user wants to add a new dive information,
the ways to know what unit system is being used are

 - Through preferences panel.
 - Save the dive information, which displays units in
   the text field.

This patch provides an option to the user to show current
unit system by displaying the unit on the side of the label
when the user is editing the fields.

This feature can be enabled or disabled by using the new
checkbox option i.e. `Show units in text labels` included
in `preferences->units` section.

Signed-off-by: Lakshman Anumolu <acrlakshman@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lakshman 2014-03-10 22:49:08 -05:00 committed by Dirk Hohndel
parent eb47b2a8d8
commit 6e4466aa0a
6 changed files with 35 additions and 2 deletions

1
pref.h
View file

@ -40,6 +40,7 @@ struct preferences {
short show_sac; short show_sac;
bool display_unused_tanks; bool display_unused_tanks;
bool zoomed_plot; bool zoomed_plot;
bool text_label_with_units;
}; };
enum unit_system_values { enum unit_system_values {
METRIC, METRIC,

View file

@ -201,6 +201,7 @@ void MainTab::hideMessage()
ui.diveEquipmentMessage->animatedHide(); ui.diveEquipmentMessage->animatedHide();
ui.diveInfoMessage->animatedHide(); ui.diveInfoMessage->animatedHide();
ui.diveStatisticsMessage->animatedHide(); ui.diveStatisticsMessage->animatedHide();
updateTextLabels();
} }
void MainTab::closeMessage() void MainTab::closeMessage()
@ -222,6 +223,18 @@ void MainTab::displayMessage(QString str)
ui.diveInfoMessage->animatedShow(); ui.diveInfoMessage->animatedShow();
ui.diveStatisticsMessage->setText(str); ui.diveStatisticsMessage->setText(str);
ui.diveStatisticsMessage->animatedShow(); ui.diveStatisticsMessage->animatedShow();
updateTextLabels(true);
}
void MainTab::updateTextLabels(bool showUnits)
{
if (showUnits && prefs.text_label_with_units) {
ui.airTempLabel->setText(QApplication::translate("MainTab", "Air temp [%1]").arg(get_temp_unit()));
ui.waterTempLabel->setText(QApplication::translate("MainTab", "Water temp [%1]").arg(get_temp_unit()));
} else {
ui.airTempLabel->setText(QApplication::translate("MainTab", "Air temp", 0, QApplication::UnicodeUTF8));
ui.waterTempLabel->setText(QApplication::translate("MainTab", "Water temp", 0, QApplication::UnicodeUTF8));
}
} }
void MainTab::enableEdition(EditMode newEditMode) void MainTab::enableEdition(EditMode newEditMode)

View file

@ -94,6 +94,7 @@ slots:
void displayMessage(QString str); void displayMessage(QString str);
void enableEdition(EditMode newEditMode = NONE); void enableEdition(EditMode newEditMode = NONE);
void toggleTriggeredColumn(); void toggleTriggeredColumn();
void updateTextLabels(bool showUnits = false);
private: private:
Ui::MainTab ui; Ui::MainTab ui;

View file

@ -75,6 +75,7 @@ void PreferencesDialog::setUiFromPrefs()
ui.cuft->setChecked(prefs.units.volume == units::CUFT); ui.cuft->setChecked(prefs.units.volume == units::CUFT);
ui.kg->setChecked(prefs.units.weight == units::KG); ui.kg->setChecked(prefs.units.weight == units::KG);
ui.lbs->setChecked(prefs.units.weight == units::LBS); ui.lbs->setChecked(prefs.units.weight == units::LBS);
ui.text_label_with_units->setChecked(prefs.text_label_with_units);
ui.font->setCurrentFont(QString(prefs.divelist_font)); ui.font->setCurrentFont(QString(prefs.divelist_font));
ui.fontsize->setValue(prefs.font_size); ui.fontsize->setValue(prefs.font_size);
@ -190,6 +191,7 @@ void PreferencesDialog::syncSettings()
s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER); s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER);
s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG); s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG);
s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
SB("text_label_with_units", ui.text_label_with_units);
s.endGroup(); s.endGroup();
// Defaults // Defaults
s.beginGroup("GeneralSettings"); s.beginGroup("GeneralSettings");
@ -244,6 +246,7 @@ void PreferencesDialog::loadSettings()
GET_UNIT("weight", weight, units::LBS, units::KG); GET_UNIT("weight", weight, units::LBS, units::KG);
} }
GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS); GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS);
GET_BOOL("text_label_with_units", text_label_with_units);
s.endGroup(); s.endGroup();
s.beginGroup("TecDetails"); s.beginGroup("TecDetails");
GET_BOOL("po2graph", pp_graphs.po2); GET_BOOL("po2graph", pp_graphs.po2);

View file

@ -478,7 +478,21 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="text_label_with_units_hbox">
<item>
<widget class="QCheckBox" name="text_label_with_units">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Show units in text labels</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View file

@ -29,7 +29,8 @@ struct preferences default_prefs = {
.font_size = -1, .font_size = -1,
.display_invalid_dives = false, .display_invalid_dives = false,
.show_sac = false, .show_sac = false,
.display_unused_tanks = false .display_unused_tanks = false,
.text_label_with_units = false
}; };
struct units *get_units() struct units *get_units()