2013-05-24 18:19:48 +00:00
|
|
|
#include "preferences.h"
|
2013-11-30 17:18:04 +00:00
|
|
|
#include "mainwindow.h"
|
2013-05-24 18:19:48 +00:00
|
|
|
#include <QSettings>
|
2013-06-02 10:52:18 +00:00
|
|
|
#include <QDebug>
|
2013-10-14 04:19:13 +00:00
|
|
|
#include <QFileDialog>
|
2013-12-06 16:29:38 +00:00
|
|
|
#include <QMessageBox>
|
2013-12-06 19:14:50 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2013-05-24 18:19:48 +00:00
|
|
|
|
|
|
|
PreferencesDialog* PreferencesDialog::instance()
|
|
|
|
{
|
2014-02-12 14:22:54 +00:00
|
|
|
static PreferencesDialog *dialog = new PreferencesDialog(MainWindow::instance());
|
2013-06-28 12:20:42 +00:00
|
|
|
dialog->setAttribute(Qt::WA_QuitOnClose, false);
|
2013-12-06 16:29:38 +00:00
|
|
|
LanguageModel::instance();
|
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-12-04 23:48:37 +00:00
|
|
|
connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int)));
|
|
|
|
connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int)));
|
2014-02-08 17:07:06 +00:00
|
|
|
loadSettings();
|
2013-06-03 12:08:49 +00:00
|
|
|
setUiFromPrefs();
|
|
|
|
rememberPrefs();
|
2013-06-02 20:58:50 +00:00
|
|
|
}
|
|
|
|
|
2013-12-06 16:35:23 +00:00
|
|
|
#define DANGER_GF ( gf > 100 ) ? "* { color: red; }" : ""
|
2013-12-04 23:48:37 +00:00
|
|
|
void PreferencesDialog::gflowChanged(int gf)
|
|
|
|
{
|
2013-12-06 16:35:23 +00:00
|
|
|
ui.gflow->setStyleSheet(DANGER_GF);
|
2013-12-04 23:48:37 +00:00
|
|
|
}
|
|
|
|
void PreferencesDialog::gfhighChanged(int gf)
|
|
|
|
{
|
2013-12-06 16:35:23 +00:00
|
|
|
ui.gfhigh->setStyleSheet(DANGER_GF);
|
2013-12-04 23:48:37 +00:00
|
|
|
}
|
2013-12-06 16:35:23 +00:00
|
|
|
#undef DANGER_GF
|
2013-12-04 23:48:37 +00:00
|
|
|
|
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.pheThreshold->setValue(prefs.pp_graphs.phe_threshold);
|
|
|
|
ui.po2Threshold->setValue(prefs.pp_graphs.po2_threshold);
|
|
|
|
ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold);
|
2013-11-19 13:32:24 +00:00
|
|
|
ui.maxppo2->setValue(prefs.mod_ppO2);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.red_ceiling->setChecked(prefs.profile_red_ceiling);
|
2013-12-08 13:18:26 +00:00
|
|
|
ui.units_group->setEnabled(ui.personalize->isChecked());
|
2013-10-03 18:54:25 +00:00
|
|
|
|
|
|
|
ui.gflow->setValue(prefs.gflow);
|
|
|
|
ui.gfhigh->setValue(prefs.gfhigh);
|
2013-11-20 15:11:22 +00:00
|
|
|
ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth);
|
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);
|
2013-12-08 13:18:27 +00:00
|
|
|
ui.kg->setChecked(prefs.units.weight == units::KG);
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.lbs->setChecked(prefs.units.weight == units::LBS);
|
2013-12-08 13:18:26 +00:00
|
|
|
|
2013-12-18 21:06:51 +00:00
|
|
|
ui.font->setCurrentFont(QString(prefs.divelist_font));
|
2013-10-03 18:54:25 +00:00
|
|
|
ui.fontsize->setValue(prefs.font_size);
|
|
|
|
ui.defaultfilename->setText(prefs.default_filename);
|
2013-11-24 22:21:29 +00:00
|
|
|
ui.default_cylinder->clear();
|
|
|
|
for(int i=0; tank_info[i].name != NULL; i++) {
|
|
|
|
ui.default_cylinder->addItem(tank_info[i].name);
|
|
|
|
if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0)
|
|
|
|
ui.default_cylinder->setCurrentIndex(i);
|
|
|
|
}
|
2013-11-20 12:40:14 +00:00
|
|
|
ui.displayinvalid->setChecked(prefs.display_invalid_dives);
|
2014-01-11 14:57:06 +00:00
|
|
|
ui.display_unused_tanks->setChecked(prefs.display_unused_tanks);
|
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-12-06 16:29:38 +00:00
|
|
|
|
2013-12-06 19:14:50 +00:00
|
|
|
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel();
|
|
|
|
filterModel->setSourceModel(LanguageModel::instance());
|
|
|
|
filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
ui.languageView->setModel(filterModel);
|
2013-12-07 15:32:17 +00:00
|
|
|
filterModel->sort(0);
|
2013-12-06 19:14:50 +00:00
|
|
|
connect(ui.languageFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString)));
|
2013-12-06 16:29:38 +00:00
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup("Language");
|
2013-12-12 05:44:09 +00:00
|
|
|
ui.languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool());
|
2013-12-18 20:18:33 +00:00
|
|
|
QAbstractItemModel *m = ui.languageView->model();
|
|
|
|
QModelIndexList languages = m->match( m->index(0,0), Qt::UserRole, s.value("UiLanguage").toString());
|
|
|
|
if (languages.count())
|
|
|
|
ui.languageView->setCurrentIndex(languages.first());
|
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-11-20 12:40:14 +00:00
|
|
|
setUiFromPrefs();
|
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::rememberPrefs()
|
|
|
|
{
|
|
|
|
oldPrefs = prefs;
|
2013-05-28 18:21:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
|
|
|
|
|
2014-02-06 16:18:00 +00:00
|
|
|
|
|
|
|
#define GET_UNIT(name, field, f, t) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.units.field = (v.toInt() == (t)) ? (t) : (f); \
|
|
|
|
else \
|
|
|
|
prefs.units.field = default_prefs.units.field
|
|
|
|
|
|
|
|
#define GET_BOOL(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = v.toInt() ? true : false; \
|
|
|
|
else \
|
|
|
|
prefs.field = default_prefs.field
|
|
|
|
|
|
|
|
#define GET_DOUBLE(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = v.toDouble(); \
|
|
|
|
else \
|
|
|
|
prefs.field = default_prefs.field
|
|
|
|
|
|
|
|
#define GET_INT(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = v.toInt(); \
|
|
|
|
else \
|
|
|
|
prefs.field = default_prefs.field
|
|
|
|
|
|
|
|
#define GET_TXT(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
|
|
|
else \
|
|
|
|
prefs.field = default_prefs.field
|
|
|
|
|
|
|
|
#define GET_TXT(name, field) \
|
|
|
|
v = s.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
|
|
|
else \
|
|
|
|
prefs.field = default_prefs.field
|
|
|
|
|
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
|
|
|
s.setValue("phethreshold", ui.pheThreshold->value());
|
|
|
|
s.setValue("po2threshold", ui.po2Threshold->value());
|
|
|
|
s.setValue("pn2threshold", ui.pn2Threshold->value());
|
2013-11-20 15:11:22 +00:00
|
|
|
s.setValue("modppO2", ui.maxppo2->value());
|
2013-10-03 18:54:25 +00:00
|
|
|
SB("redceiling", ui.red_ceiling);
|
|
|
|
s.setValue("gflow", ui.gflow->value());
|
|
|
|
s.setValue("gfhigh", ui.gfhigh->value());
|
2013-11-20 15:11:22 +00:00
|
|
|
SB("gf_low_at_maxdepth", ui.gf_low_at_maxdepth);
|
2014-01-11 14:57:06 +00:00
|
|
|
SB("display_unused_tanks", ui.display_unused_tanks);
|
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-11-24 05:54:51 +00:00
|
|
|
s.setValue("default_filename", ui.defaultfilename->text());
|
2013-11-24 22:21:29 +00:00
|
|
|
s.setValue("default_cylinder", ui.default_cylinder->currentText());
|
2013-11-20 12:40:14 +00:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("Display");
|
2013-12-18 21:06:51 +00:00
|
|
|
s.setValue("divelist_font", ui.font->currentFont());
|
2013-12-06 16:30:59 +00:00
|
|
|
s.setValue("font_size", ui.fontsize->value());
|
|
|
|
s.setValue("displayinvalid", ui.displayinvalid->isChecked());
|
2013-05-26 17:49:05 +00:00
|
|
|
s.endGroup();
|
2013-05-24 18:19:48 +00:00
|
|
|
s.sync();
|
|
|
|
|
2013-12-06 16:29:38 +00:00
|
|
|
QLocale loc;
|
|
|
|
s.beginGroup("Language");
|
2013-12-12 05:44:09 +00:00
|
|
|
bool useSystemLang = s.value("UseSystemLanguage", true).toBool();
|
|
|
|
if (useSystemLang != ui.languageSystemDefault->isChecked() ||
|
|
|
|
(!useSystemLang && s.value("UiLanguage").toString() != ui.languageView->currentIndex().data(Qt::UserRole))) {
|
2014-02-12 14:22:54 +00:00
|
|
|
QMessageBox::warning(MainWindow::instance(), tr("Restart required"),
|
2013-12-06 16:29:38 +00:00
|
|
|
tr("To correctly load a new language you must restart Subsurface."));
|
|
|
|
}
|
2013-12-06 19:48:38 +00:00
|
|
|
s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked());
|
2013-12-06 16:29:38 +00:00
|
|
|
s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole));
|
2014-02-06 16:18:00 +00:00
|
|
|
s.endGroup();
|
2014-02-08 17:07:06 +00:00
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialog::loadSettings()
|
|
|
|
{
|
2014-02-06 16:18:00 +00:00
|
|
|
// This code was on the mainwindow, it should belong nowhere, but since we dind't
|
|
|
|
// correctly fixed this code yet ( too much stuff on the code calling preferences )
|
|
|
|
// force this here.
|
2013-12-06 16:29:38 +00:00
|
|
|
|
2014-02-08 17:07:06 +00:00
|
|
|
QSettings s;
|
2014-02-06 16:18:00 +00:00
|
|
|
QVariant v;
|
|
|
|
s.beginGroup("Units");
|
|
|
|
if (s.value("unit_system").toString() == "metric") {
|
|
|
|
prefs.unit_system = METRIC;
|
|
|
|
prefs.units = SI_units;
|
|
|
|
} else if (s.value("unit_system").toString() == "imperial") {
|
|
|
|
prefs.unit_system = IMPERIAL;
|
|
|
|
prefs.units = IMPERIAL_units;
|
|
|
|
} else {
|
|
|
|
prefs.unit_system = PERSONALIZE;
|
|
|
|
GET_UNIT("length", length, units::FEET, units::METERS);
|
|
|
|
GET_UNIT("pressure", pressure, units::PSI, units::BAR);
|
|
|
|
GET_UNIT("volume", volume, units::CUFT, units::LITER);
|
|
|
|
GET_UNIT("temperature", temperature, units::FAHRENHEIT, units::CELSIUS);
|
|
|
|
GET_UNIT("weight", weight, units::LBS, units::KG);
|
|
|
|
}
|
|
|
|
GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS);
|
|
|
|
s.endGroup();
|
|
|
|
s.beginGroup("TecDetails");
|
|
|
|
GET_BOOL("po2graph", pp_graphs.po2);
|
|
|
|
GET_BOOL("pn2graph", pp_graphs.pn2);
|
|
|
|
GET_BOOL("phegraph", pp_graphs.phe);
|
|
|
|
GET_DOUBLE("po2threshold", pp_graphs.po2_threshold);
|
|
|
|
GET_DOUBLE("pn2threshold", pp_graphs.pn2_threshold);
|
|
|
|
GET_DOUBLE("phethreshold", pp_graphs.phe_threshold);
|
|
|
|
GET_BOOL("mod", mod);
|
|
|
|
GET_DOUBLE("modppO2", mod_ppO2);
|
|
|
|
GET_BOOL("ead", ead);
|
|
|
|
GET_BOOL("redceiling", profile_red_ceiling);
|
|
|
|
GET_BOOL("dcceiling", profile_dc_ceiling);
|
|
|
|
GET_BOOL("calcceiling", profile_calc_ceiling);
|
|
|
|
GET_BOOL("calcceiling3m", calc_ceiling_3m_incr);
|
|
|
|
GET_BOOL("calcndltts", calc_ndl_tts);
|
|
|
|
GET_BOOL("calcalltissues", calc_all_tissues);
|
|
|
|
GET_INT("gflow", gflow);
|
|
|
|
GET_INT("gfhigh", gfhigh);
|
|
|
|
GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth);
|
|
|
|
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
|
|
|
|
GET_BOOL("show_sac", show_sac);
|
|
|
|
GET_BOOL("display_unused_tanks", display_unused_tanks);
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("GeneralSettings");
|
|
|
|
GET_TXT("default_filename", default_filename);
|
|
|
|
GET_TXT("default_cylinder", default_cylinder);
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
s.beginGroup("Display");
|
|
|
|
QFont defaultFont = s.value("divelist_font", qApp->font()).value<QFont>();
|
|
|
|
defaultFont.setPointSizeF(s.value("font_size", qApp->font().pointSizeF()).toFloat());
|
|
|
|
qApp->setFont(defaultFont);
|
|
|
|
GET_TXT("divelist_font", divelist_font);
|
|
|
|
GET_INT("font_size", font_size);
|
|
|
|
GET_INT("displayinvalid", display_invalid_dives);
|
|
|
|
s.endGroup();
|
2013-05-24 18:19:48 +00:00
|
|
|
}
|
2013-05-28 18:21:27 +00:00
|
|
|
|
2013-06-02 20:58:50 +00:00
|
|
|
void PreferencesDialog::buttonClicked(QAbstractButton* button)
|
|
|
|
{
|
2014-01-16 04:50:56 +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();
|
2013-06-02 20:58:50 +00:00
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::Apply:
|
|
|
|
syncSettings();
|
|
|
|
break;
|
|
|
|
case QDialogButtonBox::FirstButton:
|
|
|
|
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()
|
|
|
|
{
|
2013-11-20 07:08:20 +00:00
|
|
|
QFileInfo fi(system_default_filename());
|
2014-02-11 18:49:56 +00:00
|
|
|
QString choosenFileName = QFileDialog::getOpenFileName(this, tr("Open Default Log File"), fi.absolutePath(), tr("Subsurface XML files (*.ssrf *.xml *.XML)"));
|
|
|
|
|
|
|
|
if(!choosenFileName.isEmpty())
|
|
|
|
ui.defaultfilename->setText(choosenFileName);
|
2013-10-14 04:19:13 +00:00
|
|
|
}
|
2014-02-06 13:38:28 +00:00
|
|
|
|
|
|
|
void PreferencesDialog::emitSettingsChanged()
|
|
|
|
{
|
|
|
|
emit settingsChanged();
|
|
|
|
}
|