2013-05-24 18:19:48 +00:00
|
|
|
#include "preferences.h"
|
|
|
|
#include <QSettings>
|
2013-06-02 10:52:18 +00:00
|
|
|
#include <QDebug>
|
2013-10-14 04:19:13 +00:00
|
|
|
#include <QFileDialog>
|
2013-05-24 18:19:48 +00:00
|
|
|
|
|
|
|
PreferencesDialog* PreferencesDialog::instance()
|
|
|
|
{
|
|
|
|
static PreferencesDialog *dialog = new PreferencesDialog();
|
2013-06-28 12:20:42 +00:00
|
|
|
dialog->setAttribute(Qt::WA_QuitOnClose, false);
|
2013-05-24 18:19:48 +00:00
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
2013-05-24 18:19:48 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.setupUi(this);
|
|
|
|
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonClicked(QAbstractButton*)));
|
2013-06-03 12:08:49 +00:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-02 20:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
2013-06-03 12:08:49 +00:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-02 20:58:50 +00:00
|
|
|
QDialog::showEvent(event);
|
|
|
|
}
|
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::setUiFromPrefs()
|
2013-06-02 20:58:50 +00:00
|
|
|
{
|
2013-06-03 12:08:49 +00:00
|
|
|
// graphs
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.phe->setChecked(prefs.pp_graphs.phe);
|
|
|
|
ui.pheThreshold->setEnabled(ui.phe->isChecked());
|
|
|
|
ui.po2->setChecked(prefs.pp_graphs.po2);
|
|
|
|
ui.po2Threshold->setEnabled(ui.po2->isChecked());
|
|
|
|
ui.pn2->setChecked(prefs.pp_graphs.pn2);
|
|
|
|
ui.pn2Threshold->setEnabled(ui.pn2->isChecked());
|
|
|
|
ui.pheThreshold->setValue(prefs.pp_graphs.phe_threshold);
|
|
|
|
ui.po2Threshold->setValue(prefs.pp_graphs.po2_threshold);
|
|
|
|
ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold);
|
|
|
|
ui.ead_end_eadd->setChecked(prefs.ead);
|
|
|
|
ui.dc_reported_ceiling->setChecked(prefs.profile_dc_ceiling);
|
|
|
|
ui.red_ceiling->setEnabled(ui.dc_reported_ceiling->isChecked());
|
|
|
|
ui.red_ceiling->setChecked(prefs.profile_red_ceiling);
|
|
|
|
ui.calculated_ceiling->setChecked(prefs.profile_calc_ceiling);
|
|
|
|
ui.increment_3m->setEnabled(ui.calculated_ceiling->isChecked());
|
|
|
|
ui.increment_3m->setChecked(prefs.calc_ceiling_3m_incr);
|
|
|
|
ui.all_tissues->setEnabled(ui.calculated_ceiling->isChecked());
|
|
|
|
ui.all_tissues->setChecked(prefs.calc_all_tissues);
|
|
|
|
ui.groupBox->setEnabled(ui.personalize->isChecked());
|
|
|
|
|
|
|
|
ui.gflow->setValue(prefs.gflow);
|
|
|
|
ui.gfhigh->setValue(prefs.gfhigh);
|
2013-06-03 12:08:49 +00:00
|
|
|
|
|
|
|
// units
|
|
|
|
if (prefs.unit_system == METRIC)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.metric->setChecked(true);
|
2013-06-03 12:08:49 +00:00
|
|
|
else if (prefs.unit_system == IMPERIAL)
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.imperial->setChecked(true);
|
2013-06-03 12:08:49 +00:00
|
|
|
else
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.personalize->setChecked(true);
|
|
|
|
|
|
|
|
ui.celsius->setChecked(prefs.units.temperature == units::CELSIUS);
|
|
|
|
ui.fahrenheit->setChecked(prefs.units.temperature == units::FAHRENHEIT);
|
|
|
|
ui.meter->setChecked(prefs.units.length == units::METERS);
|
|
|
|
ui.feet->setChecked(prefs.units.length == units::FEET);
|
|
|
|
ui.bar->setChecked(prefs.units.pressure == units::BAR);
|
|
|
|
ui.psi->setChecked(prefs.units.pressure == units::PSI);
|
|
|
|
ui.liter->setChecked(prefs.units.volume == units::LITER);
|
|
|
|
ui.cuft->setChecked(prefs.units.volume == units::CUFT);
|
|
|
|
ui.kgs->setChecked(prefs.units.weight == units::KG);
|
|
|
|
ui.lbs->setChecked(prefs.units.weight == units::LBS);
|
|
|
|
ui.font->setFont(QString(prefs.divelist_font));
|
|
|
|
ui.fontsize->setValue(prefs.font_size);
|
|
|
|
ui.defaultfilename->setText(prefs.default_filename);
|
|
|
|
ui.displayinvalid->setChecked(prefs.show_invalid);
|
|
|
|
ui.show_time->setChecked(prefs.show_time);
|
2013-10-04 05:57:48 +00:00
|
|
|
ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES);
|
|
|
|
ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS);
|
2013-06-03 12:08:49 +00:00
|
|
|
}
|
2013-05-24 18:19:48 +00:00
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::restorePrefs()
|
|
|
|
{
|
|
|
|
prefs = oldPrefs;
|
|
|
|
}
|
2013-05-24 18:19:48 +00:00
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::rememberPrefs()
|
|
|
|
{
|
|
|
|
oldPrefs = prefs;
|
2013-05-28 18:21:27 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
#define SP(V, B) prefs.V = (int)(B->isChecked() ? 1 : 0)
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2013-06-03 12:08:49 +00:00
|
|
|
void PreferencesDialog::setPrefsFromUi()
|
2013-05-28 18:21:27 +00:00
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
SP(pp_graphs.phe, ui.phe);
|
|
|
|
SP(pp_graphs.po2, ui.po2);
|
|
|
|
SP(pp_graphs.pn2, ui.pn2);
|
|
|
|
prefs.pp_graphs.phe_threshold = ui.pheThreshold->value();
|
|
|
|
prefs.pp_graphs.po2_threshold = ui.po2Threshold->value();
|
|
|
|
prefs.pp_graphs.pn2_threshold = ui.pn2Threshold->value();
|
|
|
|
SP(ead, ui.ead_end_eadd);
|
|
|
|
SP(profile_dc_ceiling, ui.dc_reported_ceiling);
|
|
|
|
SP(profile_red_ceiling, ui.red_ceiling);
|
|
|
|
SP(profile_calc_ceiling, ui.calculated_ceiling);
|
|
|
|
SP(calc_ceiling_3m_incr, ui.increment_3m);
|
|
|
|
SP(calc_all_tissues, ui.all_tissues);
|
|
|
|
prefs.gflow = ui.gflow->value();
|
|
|
|
prefs.gfhigh = ui.gfhigh->value();
|
|
|
|
prefs.unit_system = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE);
|
|
|
|
prefs.units.temperature = ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS;
|
|
|
|
prefs.units.length = ui.feet->isChecked() ? units::FEET : units::METERS;
|
|
|
|
prefs.units.pressure = ui.psi->isChecked() ? units::PSI : units::BAR;
|
|
|
|
prefs.units.volume = ui.cuft->isChecked() ? units::CUFT : units::LITER;
|
|
|
|
prefs.units.weight = ui.lbs->isChecked() ? units::LBS : units::KG;
|
2013-10-04 05:57:48 +00:00
|
|
|
prefs.units.vertical_speed_time = ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS;
|
2013-10-03 18:54:25 +00:00
|
|
|
prefs.divelist_font = strdup(ui.font->font().family().toUtf8().data());
|
|
|
|
prefs.font_size = ui.fontsize->value();
|
|
|
|
prefs.default_filename = strdup(ui.defaultfilename->text().toUtf8().data());
|
|
|
|
prefs.display_invalid_dives = ui.displayinvalid->isChecked();
|
|
|
|
SP(show_time, ui.show_time);
|
2013-05-24 18:19:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-28 18:21:27 +00:00
|
|
|
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
|
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
void PreferencesDialog::syncSettings()
|
|
|
|
{
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
// Graph
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("TecDetails");
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2013-10-03 18:54:25 +00:00
|
|
|
SB("phegraph", ui.phe);
|
|
|
|
SB("po2graph", ui.po2);
|
|
|
|
SB("pn2graph", ui.pn2);
|
|
|
|
s.setValue("phethreshold", ui.pheThreshold->value());
|
|
|
|
s.setValue("po2threshold", ui.po2Threshold->value());
|
|
|
|
s.setValue("pn2threshold", ui.pn2Threshold->value());
|
|
|
|
SB("ead", ui.ead_end_eadd);
|
|
|
|
SB("dcceiling", ui.dc_reported_ceiling);
|
|
|
|
SB("redceiling", ui.red_ceiling);
|
|
|
|
SB("calcceiling", ui.calculated_ceiling);
|
|
|
|
SB("calcceiling3m", ui.increment_3m);
|
|
|
|
SB("calcalltissues", ui.all_tissues);
|
|
|
|
s.setValue("gflow", ui.gflow->value());
|
|
|
|
s.setValue("gfhigh", ui.gfhigh->value());
|
|
|
|
SB("show_time", ui.show_time);
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2013-05-24 18:19:48 +00:00
|
|
|
// Units
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("Units");
|
2013-10-03 18:54:25 +00:00
|
|
|
QString unitSystem = ui.metric->isChecked() ? "metric" : (ui.imperial->isChecked() ? "imperial" : "personal");
|
2013-06-02 10:52:18 +00:00
|
|
|
s.setValue("unit_system", unitSystem);
|
2013-10-03 18:54:25 +00:00
|
|
|
s.setValue("temperature", ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS);
|
|
|
|
s.setValue("length", ui.feet->isChecked() ? units::FEET : units::METERS);
|
|
|
|
s.setValue("pressure", ui.psi->isChecked() ? units::PSI : units::BAR);
|
|
|
|
s.setValue("volume", ui.cuft->isChecked() ? units::CUFT : units::LITER);
|
|
|
|
s.setValue("weight", ui.lbs->isChecked() ? units::LBS : units::KG);
|
2013-10-04 05:57:48 +00:00
|
|
|
s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2013-05-24 18:19:48 +00:00
|
|
|
// Defaults
|
2013-05-26 17:49:05 +00:00
|
|
|
s.beginGroup("GeneralSettings");
|
2013-10-03 18:54:25 +00:00
|
|
|
s.value("table_fonts", ui.font->font().family());
|
|
|
|
s.value("font_size", ui.fontsize->value());
|
|
|
|
s.value("default_filename", ui.defaultfilename->text());
|
|
|
|
s.value("displayinvalid", ui.displayinvalid->isChecked());
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2013-05-24 18:19:48 +00:00
|
|
|
s.sync();
|
|
|
|
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2013-06-02 20:58:50 +00:00
|
|
|
void PreferencesDialog::buttonClicked(QAbstractButton* button)
|
|
|
|
{
|
2013-10-03 18:54:25 +00:00
|
|
|
switch(ui.buttonBox->standardButton(button)){
|
2013-06-02 20:58:50 +00:00
|
|
|
case QDialogButtonBox::Discard:
|
2013-06-03 12:08:49 +00:00
|
|
|
restorePrefs();
|
|
|
|
setUiFromPrefs();
|
|
|
|
syncSettings();
|
2013-06-02 20:58:50 +00:00
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Apply:
|
2013-06-03 21:29:33 +00:00
|
|
|
setPrefsFromUi();
|
2013-06-02 20:58:50 +00:00
|
|
|
syncSettings();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::FirstButton:
|
2013-06-03 21:29:33 +00:00
|
|
|
setPrefsFromUi();
|
2013-06-02 20:58:50 +00:00
|
|
|
syncSettings();
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break; // ignore warnings.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-28 18:21:27 +00:00
|
|
|
#undef SB
|
2013-10-14 04:19:13 +00:00
|
|
|
|
|
|
|
void PreferencesDialog::on_chooseFile_clicked()
|
|
|
|
{
|
|
|
|
QFileInfo fi(system_default_filename());
|
|
|
|
ui.defaultfilename->setText(QFileDialog::getOpenFileName(this, tr("Open Default Log File"), fi.absolutePath(), tr("XML Files (*.xml)")));
|
|
|
|
}
|