From efb7f109e89c3d8c093c238fb7671c7ab2475f25 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 24 May 2013 15:19:48 -0300 Subject: Added support for a preliminary Preferences Dialog Dirk asked me to try to make it more modern, so I used as a base, the Firefox preferences. currently it saves / loads the preferences, and also smits a signal 'preferencesChanged' that should be connected to anything that uses preferenes, via the PreferencesDialog::intance() object. In the future, I plan to make it have a signal / slot for each member that changes. I also moved the icons to a new folder this time, because the amount of icons is now more than just two, and it was becoming messy. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 3 +- qt-ui/preferences.cpp | 109 +++++++ qt-ui/preferences.h | 26 ++ qt-ui/preferences.ui | 890 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1027 insertions(+), 1 deletion(-) create mode 100644 qt-ui/preferences.cpp create mode 100644 qt-ui/preferences.h create mode 100644 qt-ui/preferences.ui (limited to 'qt-ui') diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 53138f5a1..b343140b0 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -26,6 +26,7 @@ #include "modeldelegates.h" #include "models.h" #include "downloadfromdivecomputer.h" +#include "preferences.h" static MainWindow* instance = 0; @@ -148,7 +149,7 @@ void MainWindow::on_actionPrint_triggered() void MainWindow::on_actionPreferences_triggered() { - qDebug("actionPreferences"); + PreferencesDialog::instance()->show(); } void MainWindow::on_actionQuit_triggered() diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp new file mode 100644 index 000000000..f9165c750 --- /dev/null +++ b/qt-ui/preferences.cpp @@ -0,0 +1,109 @@ +#include "preferences.h" +#include "ui_preferences.h" +#include + +PreferencesDialog* PreferencesDialog::instance() +{ + static PreferencesDialog *dialog = new PreferencesDialog(); + return dialog; +} + +PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) +, ui(new Ui::PreferencesDialog()) +{ + ui->setupUi(this); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(syncSettings())); + + #define B(X) s.value(#X, false).toBool() + #define D(X) s.value(#X, 0.0).toDouble() + + QSettings s; + + // Graph + ui->calculated_ceiling->setChecked(B(show_calculated_ceiling)); + ui->phe->setChecked(B(show_phe)); + ui->po2->setChecked(B(show_po2)); + ui->pn2->setChecked(B(show_pn2)); + ui->pheThreshould->setValue(D(phe_threshould)); + ui->po2Threashould->setValue(D(po2_threshould)); + ui->pn2Threshould->setValue(D(pn2_threshould)); + ui->ead_end_eadd->setChecked(B(show_ead_end_eadd)); + ui->dc_reported_ceiling->setChecked(B(show_dc_reported_ceiling)); + ui->calculated_ceiling->setChecked(B(show_calculated_ceiling)); + ui->increment_3m->setChecked(B(show_3m_increments)); + ui->gflow->setValue(D(gflow)); + ui->gfhigh->setValue(D(gfhigh)); + + // Units + bool value = s.value("units_metric").toBool(); + ui->metric->setChecked(value); + ui->imperial->setChecked(!value); + + value = s.value("units_celcius").toBool(); + ui->celsius->setChecked( value); + ui->fahrenheit->setChecked( !value); + + value = s.value("units_meters").toBool(); + ui->meter->setChecked(value); + ui->feet->setChecked(!value); + + value = s.value("units_bar").toBool(); + ui->bar->setChecked(value); + ui->psi->setChecked(!value); + + value = s.value("units_liter").toBool(); + ui->liter->setChecked(value); + ui->cuft->setChecked(!value); + + value = s.value("units_kgs").toBool(); + ui->kgs->setChecked(value); + ui->lbs->setChecked(!value); + + // Defaults + ui->font->setFont( QFont(s.value("table_fonts").toString())); + ui->fontsize->setValue(D(font_size)); + + ui->defaultfilename->setText(s.value("default_file").toString()); + ui->displayinvalid->setChecked(B(show_invalid)); + +#undef B +#undef D +} + +void PreferencesDialog::syncSettings() +{ + QSettings s; + + // Graph + s.setValue("show_calculated_ceiling", ui->calculated_ceiling->isChecked()); + s.setValue("show_phe", ui->phe->isChecked()); + s.setValue("show_po2", ui->po2->isChecked()); + s.setValue("show_pn2", ui->pn2->isChecked()); + s.setValue("phe_threshould", ui->pheThreshould->value()); + s.setValue("po2_threshould", ui->po2Threashould->value()); + s.setValue("pn2_threshould", ui->pn2Threshould->value()); + s.setValue("show_ead_end_eadd", ui->ead_end_eadd->isChecked()); + s.setValue("show_dc_reported_ceiling", ui->dc_reported_ceiling->isChecked()); + s.setValue("show_calculated_ceiling", ui->calculated_ceiling->isChecked()); + + s.setValue("show_3m_increments", ui->increment_3m->isChecked()); + s.setValue("gflow", ui->gflow->value()); + s.setValue("gfhigh", ui->gfhigh->value()); + + // Units + s.setValue("units_metric", ui->metric->isChecked()); + s.setValue("units_celcius", ui->celsius->isChecked()); + s.setValue("units_meter", ui->meter->isChecked()); + s.setValue("units_bar", ui->bar->isChecked()); + s.setValue("units_liter", ui->liter->isChecked()); + s.setValue("units_kgs", ui->liter->isChecked()); + + // Defaults + s.value("table_fonts", ui->font->font().family()); + s.value("font_size", ui->fontsize->value()); + s.value("default_file", ui->defaultfilename->text()); + s.value("displayinvalid", ui->displayinvalid->isChecked()); + s.sync(); + + emit settingsChanged(); +} diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h new file mode 100644 index 000000000..ab5a214ed --- /dev/null +++ b/qt-ui/preferences.h @@ -0,0 +1,26 @@ +#ifndef PREFERENCES_DIALOG_H +#define PREFERENCES_DIALOG_H + +#include + +namespace Ui{ + class PreferencesDialog; +} + +class PreferencesDialog :public QDialog{ +Q_OBJECT +public: + static PreferencesDialog* instance(); + +signals: + void settingsChanged(); + +public slots: + void syncSettings(); + +private: + explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); + Ui::PreferencesDialog* ui; +}; + +#endif \ No newline at end of file diff --git a/qt-ui/preferences.ui b/qt-ui/preferences.ui new file mode 100644 index 000000000..e36aef5b3 --- /dev/null +++ b/qt-ui/preferences.ui @@ -0,0 +1,890 @@ + + + PreferencesDialog + + + + 0 + 0 + 444 + 386 + + + + Dialog + + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 80 + 16777215 + + + + + 40 + 40 + + + + Qt::ElideNone + + + QListView::Static + + + true + + + QListView::Batched + + + 0 + + + + 70 + 60 + + + + QListView::IconMode + + + false + + + true + + + -1 + + + + Defaults + + + + :/subsurface-icon + + + + + + Units + + + + :/units + + + + + + Graph + + + + :/graph + + + + + + + + + + 0 + 0 + + + + 1 + + + + + + + Lists and Tables + + + + + + Font + + + + + + + + + + Font size + + + + + + + + + + + + + Dives + + + + + + Default Dive file + + + + + + + + + + + + ... + + + + + + + + + Display Invalid + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + System + + + + + + + Metric + + + + + + + Imperial + + + + + + + + + Personalize + + + true + + + false + + + + + + Depth + + + + + + + Meter + + + buttonGroup + + + + + + + Feet + + + buttonGroup + + + + + + + Pressure + + + + + + + Bar + + + buttonGroup_2 + + + + + + + Psi + + + buttonGroup_2 + + + + + + + Volume + + + + + + + Liter + + + buttonGroup_3 + + + + + + + CuFt + + + buttonGroup_3 + + + + + + + Temperature + + + + + + + Celsius + + + buttonGroup_4 + + + + + + + Fahrenheit + + + buttonGroup_4 + + + + + + + Weigth + + + + + + + Kg + + + buttonGroup_5 + + + + + + + lbs + + + buttonGroup_5 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Show + + + + + + + + pO2 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + threshould + + + + + + + false + + + + + + + + + + + pN2 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + threshould + + + + + + + false + + + + + + + + + + + pHe + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + threshould + + + + + + + false + + + + + + + + + + + MOD + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + max PP02 + + + + + + + false + + + + + + + + + EAD END EADD + + + + + + + Dive computer reported ceiling + + + + + + + + + Calculated ceiling + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + 3m increments + + + + + + + + + + + + Misc + + + + + + GFLow + + + + + + + + + + GFHigh + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Discard|QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + PreferencesDialog + accept() + + + 226 + 522 + + + 157 + 274 + + + + + buttonBox + rejected() + PreferencesDialog + reject() + + + 294 + 522 + + + 286 + 274 + + + + + listWidget + currentRowChanged(int) + stackedWidget + setCurrentIndex(int) + + + 37 + 97 + + + 186 + 8 + + + + + po2 + clicked(bool) + label_12 + setEnabled(bool) + + + 288 + 179 + + + 681 + 194 + + + + + po2 + clicked(bool) + po2Threashould + setEnabled(bool) + + + 301 + 179 + + + 742 + 184 + + + + + pn2 + clicked(bool) + label_13 + setEnabled(bool) + + + 295 + 208 + + + 673 + 216 + + + + + pn2 + clicked(bool) + pn2Threshould + setEnabled(bool) + + + 301 + 206 + + + 740 + 216 + + + + + phe + clicked(bool) + label_17 + setEnabled(bool) + + + 296 + 240 + + + 683 + 242 + + + + + phe + clicked(bool) + pheThreshould + setEnabled(bool) + + + 304 + 232 + + + 760 + 236 + + + + + mod + clicked(bool) + label_18 + setEnabled(bool) + + + 294 + 267 + + + 692 + 271 + + + + + mod + clicked(bool) + maxppo2 + setEnabled(bool) + + + 286 + 261 + + + 760 + 269 + + + + + calculated_ceiling + clicked(bool) + increment_3m + setEnabled(bool) + + + 288 + 344 + + + 555 + 351 + + + + + + + + + + + + -- cgit v1.2.3-70-g09d2