From b35ccc3a3533a3fcf9c7434584470537b6d0001e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 14:04:27 -0300 Subject: Preferences: start to port preferences to a more sane design Our preferences dialog right now is a rather huge dialog with more than 9 subpages, and all of those pages are programmed inside of the same class, same methods and all that - which means that if I change something on the dialog I can break any other thing quite easily. The idea of this patch series is to make it harder to break user settings and the settings dialog. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/CMakeLists.txt | 9 ++++++++ .../preferences/abstractpreferenceswidget.cpp | 21 +++++++++++++++++ .../preferences/abstractpreferenceswidget.h | 27 ++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 desktop-widgets/preferences/CMakeLists.txt create mode 100644 desktop-widgets/preferences/abstractpreferenceswidget.cpp create mode 100644 desktop-widgets/preferences/abstractpreferenceswidget.h (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt new file mode 100644 index 000000000..953c587b1 --- /dev/null +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -0,0 +1,9 @@ +# the profile widget +set(SUBSURFACE_PREFERENCES_LIB_SRCS + abstractpreferenceswidget.cpp +) + +source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) + +add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS}) +target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES}) \ No newline at end of file diff --git a/desktop-widgets/preferences/abstractpreferenceswidget.cpp b/desktop-widgets/preferences/abstractpreferenceswidget.cpp new file mode 100644 index 000000000..9334c74ed --- /dev/null +++ b/desktop-widgets/preferences/abstractpreferenceswidget.cpp @@ -0,0 +1,21 @@ +#include "abstractpreferenceswidget.h" + +AbstractPreferencesWidget::AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight) +: QWidget(), _name(name), _icon(icon), _positionHeight(positionHeight) +{ +} + +QIcon AbstractPreferencesWidget::icon() const +{ + return _icon; +} + +QString AbstractPreferencesWidget::name() const +{ + return _name; +} + +float AbstractPreferencesWidget::positionHeight() const +{ + return _positionHeight; +} diff --git a/desktop-widgets/preferences/abstractpreferenceswidget.h b/desktop-widgets/preferences/abstractpreferenceswidget.h new file mode 100644 index 000000000..2f607c4c9 --- /dev/null +++ b/desktop-widgets/preferences/abstractpreferenceswidget.h @@ -0,0 +1,27 @@ +#ifndef ABSTRACTPREFERENCESWIDGET_H +#define ABSTRACTPREFERENCESWIDGET_H + +#include +#include + +class AbstractPreferencesWidget : public QWidget { + Q_OBJECT +public: + AbstractPreferencesWidget(const QString& name, const QIcon& icon, float positionHeight); + QIcon icon() const; + QString name() const; + float positionHeight() const; + + /* gets the values from the preferences and should set the correct values in + * the interface */ + virtual void refreshSettings() = 0; + + /* gets the values from the interface and set in the preferences object. */ + virtual void syncSettings() = 0; + +private: + QIcon _icon; + QString _name; + float _positionHeight; +}; +#endif \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 255325e219f7d1922ac7740649fdbc89228a36c1 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 15:58:26 -0300 Subject: Preferences: add a new page for language This is not hooked into anything - It's the bare minimum that I need to continue creating the new preferences dialog. But take a look at it... very simple. :) Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/CMakeLists.txt | 16 ++++- .../preferences/preferences_language.cpp | 47 +++++++++++++ desktop-widgets/preferences/preferences_language.h | 21 ++++++ desktop-widgets/preferences/prefs_language.ui | 76 ++++++++++++++++++++++ 4 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_language.cpp create mode 100644 desktop-widgets/preferences/preferences_language.h create mode 100644 desktop-widgets/preferences/prefs_language.ui (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 953c587b1..6af8b4a73 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -1,9 +1,21 @@ # the profile widget +include_directories(. + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} +) + +file(GLOB SUBSURFACE_PREFERENCES_UI *.ui) +qt5_wrap_ui(SUBSURFACE_PREFERENCES_UI_HDRS ${SUBSURFACE_PREFERENCES_UI}) + +source_group("Subsurface Interface Files" FILES ${SUBSURFACE_PREFERENCES_UI}) + set(SUBSURFACE_PREFERENCES_LIB_SRCS abstractpreferenceswidget.cpp + preferences_language.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) -add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS}) -target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES}) \ No newline at end of file +add_library(subsurface_desktop_preferences STATIC ${SUBSURFACE_PREFERENCES_LIB_SRCS} ${SUBSURFACE_PREFERENCES_UI_HDRS}) +target_link_libraries(subsurface_desktop_preferences ${QT_LIBRARIES}) + diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp new file mode 100644 index 000000000..7254482e2 --- /dev/null +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -0,0 +1,47 @@ +#include "preferences_language.h" +#include "ui_prefs_language.h" + +#include +#include +#include + + +PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Language"), QIcon(":/language"), 4) +{ + ui = new Ui::PreferencesLanguage(); + ui->setupUi(this); +} + +PreferencesLanguage::~PreferencesLanguage() +{ + delete ui; +} + +void PreferencesLanguage::refreshSettings() +{ + QSettings s; + s.beginGroup("Language"); + ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); + 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()); + s.endGroup(); +} + +void PreferencesLanguage::syncSettings() +{ + // Locale + QLocale loc; + QSettings s; + s.beginGroup("Language"); + bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); + if (useSystemLang != ui->languageSystemDefault->isChecked() || + (!useSystemLang && s.value("UiLanguage").toString() != ui->languageView->currentIndex().data(Qt::UserRole))) { + QMessageBox::warning(this, tr("Restart required"), + tr("To correctly load a new language you must restart Subsurface.")); + } + s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked()); + s.setValue("UiLanguage", ui->languageView->currentIndex().data(Qt::UserRole)); + s.endGroup(); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_language.h b/desktop-widgets/preferences/preferences_language.h new file mode 100644 index 000000000..43014c0fd --- /dev/null +++ b/desktop-widgets/preferences/preferences_language.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_LANGUAGE_H +#define PREFERENCES_LANGUAGE_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesLanguage; +} + +class PreferencesLanguage : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesLanguage(); + virtual ~PreferencesLanguage(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesLanguage *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/prefs_language.ui b/desktop-widgets/preferences/prefs_language.ui new file mode 100644 index 000000000..80671fca8 --- /dev/null +++ b/desktop-widgets/preferences/prefs_language.ui @@ -0,0 +1,76 @@ + + + PreferencesLanguage + + + + 0 + 0 + 576 + 523 + + + + Form + + + + + + + 0 + 0 + + + + UI language + + + + + + System default + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + Filter + + + + + + + + + + + + + + 0 + 0 + + + + + + + + + -- cgit v1.2.3-70-g09d2 From b7a476169d50dbf4d40b134faac5b88cabd4fa17 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 17:16:40 -0300 Subject: Preferecnes: add the initial skeleton This Preferences dialog should be visually similar to the old one - the main difference is how it acts on the preferences. It's also not based on .ui files since it's a very simple widget I prefered to mount it by hand - no more than 6 lines of c++ code. Right now we have only one preference page on this, and nothing is hoocked up. I've also changed mainwindow a bit to only show this dialog for testing purposes. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/CMakeLists.txt | 2 +- desktop-widgets/mainwindow.cpp | 3 + desktop-widgets/preferences/CMakeLists.txt | 1 + desktop-widgets/preferences/preferencesdialog.cpp | 83 +++++++++++++++++++++++ desktop-widgets/preferences/preferencesdialog.h | 30 ++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 desktop-widgets/preferences/preferencesdialog.cpp create mode 100644 desktop-widgets/preferences/preferencesdialog.h (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt index 6d9051b10..7b3e60f3b 100644 --- a/desktop-widgets/CMakeLists.txt +++ b/desktop-widgets/CMakeLists.txt @@ -91,4 +91,4 @@ target_link_libraries(subsurface_statistics ${QT_LIBRARIES}) add_library(subsurface_generated_ui STATIC ${SUBSURFACE_UI_HDRS}) target_link_libraries(subsurface_generated_ui ${QT_LIBRARIES}) add_library(subsurface_interface STATIC ${SUBSURFACE_INTERFACE}) -target_link_libraries(subsurface_interface ${QT_LIBRARIES} ${MARBLE_LIBRARIES}) +target_link_libraries(subsurface_interface ${QT_LIBRARIES} ${MARBLE_LIBRARIES} subsurface_desktop_preferences) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 43b433d62..156034598 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -40,6 +40,7 @@ #include "divesitehelpers.h" #include "windowtitleupdate.h" #include "locationinformation.h" +#include "preferences/preferencesdialog.h" #ifndef NO_USERMANUAL #include "usermanual.h" @@ -254,6 +255,8 @@ MainWindow::MainWindow() : QMainWindow(), ui.menubar->show(); set_git_update_cb(&updateProgress); + PreferencesDialogV2 *d = new PreferencesDialogV2(); + d->show(); } MainWindow::~MainWindow() diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 6af8b4a73..468501e7d 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -11,6 +11,7 @@ source_group("Subsurface Interface Files" FILES ${SUBSURFACE_PREFERENCES_UI}) set(SUBSURFACE_PREFERENCES_LIB_SRCS abstractpreferenceswidget.cpp + preferencesdialog.cpp preferences_language.cpp ) diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp new file mode 100644 index 000000000..b2eb77975 --- /dev/null +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -0,0 +1,83 @@ +#include "preferencesdialog.h" + +#include "abstractpreferenceswidget.h" +#include "preferences_language.h" + +#include +#include +#include +#include +#include + +PreferencesDialogV2::PreferencesDialogV2() +{ + pagesList = new QListWidget(); + pagesStack = new QStackedWidget(); + buttonBox = new QDialogButtonBox(QDialogButtonBox::Apply|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Cancel); + + pagesList->setMinimumWidth(120); + pagesList->setMaximumWidth(120); + + QHBoxLayout *h = new QHBoxLayout(); + h->addWidget(pagesList); + h->addWidget(pagesStack); + + QVBoxLayout *v = new QVBoxLayout(); + v->addLayout(h); + v->addWidget(buttonBox); + + setLayout(v); + + addPreferencePage(new PreferencesLanguage()); + refreshPages(); + connect(pagesList, &QListWidget::currentRowChanged, + pagesStack, &QStackedWidget::setCurrentIndex); +} + +PreferencesDialogV2::~PreferencesDialogV2() +{ +} + +bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractPreferencesWidget *p2) +{ + return p1->positionHeight() <= p2->positionHeight(); +} + +void PreferencesDialogV2::addPreferencePage(AbstractPreferencesWidget *page) +{ + pages.push_back(page); + qSort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan); +} + +void PreferencesDialogV2::refreshPages() +{ + // Remove things + pagesList->clear(); + while(pagesStack->count()) { + QWidget *curr = pagesStack->widget(0); + pagesStack->removeWidget(curr); + curr->setParent(0); + } + + // Readd things. + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name()); + pagesList->addItem(item); + pagesStack->addWidget(page); + } +} + +void PreferencesDialogV2::applyRequested() +{ + //TODO +} + +void PreferencesDialogV2::cancelRequested() +{ + //TODO +} + +void PreferencesDialogV2::defaultsRequested() +{ + //TODO +} diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h new file mode 100644 index 000000000..a1db94b43 --- /dev/null +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -0,0 +1,30 @@ +#ifndef PREFERENCES_WIDGET_H +#define PREFERENCES_WIDGET_H + +#include +#include "pref.h" + +class AbstractPreferencesWidget; +class QListWidget; +class QStackedWidget; +class QDialogButtonBox; + +class PreferencesDialogV2 : public QDialog { + Q_OBJECT +public: + PreferencesDialogV2(); + virtual ~PreferencesDialogV2(); + void addPreferencePage(AbstractPreferencesWidget *page); + void refreshPages(); +private: + void cancelRequested(); + void applyRequested(); + void defaultsRequested(); + + QList pages; + QListWidget *pagesList; + QStackedWidget *pagesStack; + QDialogButtonBox *buttonBox; +}; + +#endif \ No newline at end of file -- cgit v1.2.3-70-g09d2 From b7daffbf084c44b099c9d1f84fb3935ce5735b39 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 17:53:39 -0300 Subject: Preferences: Hook up the dialog buttons and make it work Since I'm using a dialog created by hand, I also need to hook things by hand. the code is very simple - debug output kept in just to make sure things are indeed working. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferencesdialog.cpp | 29 ++++++++++++++++++----- desktop-widgets/preferences/preferencesdialog.h | 3 ++- 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index b2eb77975..e21207761 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -8,12 +8,17 @@ #include #include #include +#include +#include PreferencesDialogV2::PreferencesDialogV2() { pagesList = new QListWidget(); pagesStack = new QStackedWidget(); - buttonBox = new QDialogButtonBox(QDialogButtonBox::Apply|QDialogButtonBox::RestoreDefaults|QDialogButtonBox::Cancel); + buttonBox = new QDialogButtonBox( + QDialogButtonBox::Save | + QDialogButtonBox::RestoreDefaults | + QDialogButtonBox::Cancel); pagesList->setMinimumWidth(120); pagesList->setMaximumWidth(120); @@ -21,23 +26,35 @@ PreferencesDialogV2::PreferencesDialogV2() QHBoxLayout *h = new QHBoxLayout(); h->addWidget(pagesList); h->addWidget(pagesStack); - QVBoxLayout *v = new QVBoxLayout(); v->addLayout(h); v->addWidget(buttonBox); setLayout(v); - + addPreferencePage(new PreferencesLanguage()); refreshPages(); + connect(pagesList, &QListWidget::currentRowChanged, pagesStack, &QStackedWidget::setCurrentIndex); + connect(buttonBox, &QDialogButtonBox::clicked, + this, &PreferencesDialogV2::buttonClicked); } PreferencesDialogV2::~PreferencesDialogV2() { } +void PreferencesDialogV2::buttonClicked(QAbstractButton* btn) +{ + QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn); + switch(role) { + case QDialogButtonBox::AcceptRole : applyRequested(); return; + case QDialogButtonBox::RejectRole : cancelRequested(); return; + case QDialogButtonBox::ResetRole : defaultsRequested(); return; + } +} + bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractPreferencesWidget *p2) { return p1->positionHeight() <= p2->positionHeight(); @@ -69,15 +86,15 @@ void PreferencesDialogV2::refreshPages() void PreferencesDialogV2::applyRequested() { - //TODO + qDebug() << "Apply Clicked"; } void PreferencesDialogV2::cancelRequested() { - //TODO + qDebug() << "Cancel Clicked"; } void PreferencesDialogV2::defaultsRequested() { - //TODO + qDebug() << "Defaults Clicked"; } diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h index a1db94b43..dcc97bf94 100644 --- a/desktop-widgets/preferences/preferencesdialog.h +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -8,6 +8,7 @@ class AbstractPreferencesWidget; class QListWidget; class QStackedWidget; class QDialogButtonBox; +class QAbstractButton; class PreferencesDialogV2 : public QDialog { Q_OBJECT @@ -20,7 +21,7 @@ private: void cancelRequested(); void applyRequested(); void defaultsRequested(); - + void buttonClicked(QAbstractButton *btn); QList pages; QListWidget *pagesList; QStackedWidget *pagesStack; -- cgit v1.2.3-70-g09d2 From c0d16267afd66e03591a449d9fa4bff78903b203 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 17:57:41 -0300 Subject: Preferences: Apply / Cancel / Defaults All functions that should control the preferences are created. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferencesdialog.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index e21207761..a50e6c406 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -86,15 +86,22 @@ void PreferencesDialogV2::refreshPages() void PreferencesDialogV2::applyRequested() { - qDebug() << "Apply Clicked"; + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + page->syncSettings(); + } } void PreferencesDialogV2::cancelRequested() { - qDebug() << "Cancel Clicked"; + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + page->refreshSettings(); + } } void PreferencesDialogV2::defaultsRequested() { - qDebug() << "Defaults Clicked"; + prefs = default_prefs; + Q_FOREACH(AbstractPreferencesWidget *page, pages) { + page->refreshSettings(); + } } -- cgit v1.2.3-70-g09d2 From c06813317f1030f4c16968fc523746c064d24aab Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 18:08:24 -0300 Subject: Preferences: hook up the missing parts for the language prefs ui And this actually made me find one memory leak on the old version: We are constantly creating / leaking a new QSortFilterProxyModel everytime a sync() is done on the settings. That's not a lot, maybe once per time a user changes its settings... but it's still a leak. And the code is more sanely separated this time. yey. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferences_language.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp index 7254482e2..f9cd1da93 100644 --- a/desktop-widgets/preferences/preferences_language.cpp +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -4,12 +4,23 @@ #include #include #include +#include +#include "qt-models/models.h" PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Language"), QIcon(":/language"), 4) { ui = new Ui::PreferencesLanguage(); ui->setupUi(this); + + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); + filterModel->setSourceModel(LanguageModel::instance()); + filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + ui->languageView->setModel(filterModel); + filterModel->sort(0); + connect(ui->languageFilter, &QLineEdit::textChanged, + filterModel, &QSortFilterProxyModel::setFilterFixedString); + } PreferencesLanguage::~PreferencesLanguage() -- cgit v1.2.3-70-g09d2 From 5461eadd1bd88844194073c56a2f8397c98dda04 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 18:10:32 -0300 Subject: Preferences: start with all settings set Load all settings as soon as we start the preferences. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferencesdialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index a50e6c406..5bdc75dbb 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -81,6 +81,7 @@ void PreferencesDialogV2::refreshPages() QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name()); pagesList->addItem(item); pagesStack->addWidget(page); + page->refreshSettings(); } } -- cgit v1.2.3-70-g09d2 From 315641b0b497a06dd508d8dee08b792623e091c7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 19:22:19 -0300 Subject: Preferences: add GeoReference Straigth port from the old version. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/CMakeLists.txt | 1 + .../preferences/preferences_georeference.cpp | 45 ++++++++ .../preferences/preferences_georeference.h | 21 ++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + desktop-widgets/preferences/prefs_georeference.ui | 123 +++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 desktop-widgets/preferences/preferences_georeference.cpp create mode 100644 desktop-widgets/preferences/preferences_georeference.h create mode 100644 desktop-widgets/preferences/prefs_georeference.ui (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 468501e7d..4eb2f7d23 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -13,6 +13,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS abstractpreferenceswidget.cpp preferencesdialog.cpp preferences_language.cpp + preferences_georeference.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_georeference.cpp b/desktop-widgets/preferences/preferences_georeference.cpp new file mode 100644 index 000000000..7e8ccec9d --- /dev/null +++ b/desktop-widgets/preferences/preferences_georeference.cpp @@ -0,0 +1,45 @@ +#include "preferences_georeference.h" +#include "ui_prefs_georeference.h" +#include "prefs-macros.h" +#include "qthelper.h" +#include "qt-models/divelocationmodel.h" + +#include +#include + +PreferencesGeoreference::PreferencesGeoreference() : AbstractPreferencesWidget(tr("Georeference"), QIcon(":/georeference"), 9) +{ + ui = new Ui::PreferencesGeoreference(); + ui->setupUi(this); + ui->first_item->setModel(GeoReferencingOptionsModel::instance()); + ui->second_item->setModel(GeoReferencingOptionsModel::instance()); + ui->third_item->setModel(GeoReferencingOptionsModel::instance()); +} + +PreferencesGeoreference::~PreferencesGeoreference() +{ + delete ui; +} + +void PreferencesGeoreference::refreshSettings() +{ + ui->enable_geocoding->setChecked(prefs.geocoding.enable_geocoding); + ui->parse_without_gps->setChecked(prefs.geocoding.parse_dive_without_gps); + ui->tag_existing_dives->setChecked(prefs.geocoding.tag_existing_dives); + ui->first_item->setCurrentIndex(prefs.geocoding.category[0]); + ui->second_item->setCurrentIndex(prefs.geocoding.category[1]); + ui->third_item->setCurrentIndex(prefs.geocoding.category[2]); +} + +void PreferencesGeoreference::syncSettings() +{ + QSettings s; + s.beginGroup("geocoding"); + s.setValue("enable_geocoding", ui->enable_geocoding->isChecked()); + s.setValue("parse_dives_without_gps", ui->parse_without_gps->isChecked()); + s.setValue("tag_existing_dives", ui->tag_existing_dives->isChecked()); + s.setValue("cat0", ui->first_item->currentIndex()); + s.setValue("cat1", ui->second_item->currentIndex()); + s.setValue("cat2", ui->third_item->currentIndex()); + s.endGroup(); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_georeference.h b/desktop-widgets/preferences/preferences_georeference.h new file mode 100644 index 000000000..5dd4bc445 --- /dev/null +++ b/desktop-widgets/preferences/preferences_georeference.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_GEOREFERENCE_H +#define PREFERENCES_GEOREFERENCE_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesGeoreference; +} + +class PreferencesGeoreference : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesGeoreference(); + virtual ~PreferencesGeoreference(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesGeoreference *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 5bdc75dbb..3975994a9 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -2,6 +2,7 @@ #include "abstractpreferenceswidget.h" #include "preferences_language.h" +#include "preferences_georeference.h" #include #include @@ -33,6 +34,7 @@ PreferencesDialogV2::PreferencesDialogV2() setLayout(v); addPreferencePage(new PreferencesLanguage()); + addPreferencePage(new PreferencesGeoreference()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, diff --git a/desktop-widgets/preferences/prefs_georeference.ui b/desktop-widgets/preferences/prefs_georeference.ui new file mode 100644 index 000000000..7d4f0907e --- /dev/null +++ b/desktop-widgets/preferences/prefs_georeference.ui @@ -0,0 +1,123 @@ + + + PreferencesGeoreference + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Dive site geo lookup + + + + + + Enable geocoding for dive site management + + + + + + + Parse site without GPS data + + + + + + + Same format for existing dives + + + + + + + + + + Dive Site Layout + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + / + + + + + + + + 0 + 0 + + + + + + + + / + + + + + + + + 0 + 0 + + + + + + + + + + + Qt::Vertical + + + + 20 + 109 + + + + + + + + + -- cgit v1.2.3-70-g09d2 From 8cdae5ce24fbb2795ef4ee2cd5d35805e4d5646d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 17 Sep 2015 19:22:44 -0300 Subject: Code cleanup Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferences_language.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp index f9cd1da93..07b60c3a3 100644 --- a/desktop-widgets/preferences/preferences_language.cpp +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -20,7 +20,6 @@ PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Langu filterModel->sort(0); connect(ui->languageFilter, &QLineEdit::textChanged, filterModel, &QSortFilterProxyModel::setFilterFixedString); - } PreferencesLanguage::~PreferencesLanguage() @@ -42,8 +41,6 @@ void PreferencesLanguage::refreshSettings() void PreferencesLanguage::syncSettings() { - // Locale - QLocale loc; QSettings s; s.beginGroup("Language"); bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); -- cgit v1.2.3-70-g09d2 From 1d2d046c0f80d8884d783aad57340c9b6867985a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 25 Sep 2015 16:15:37 -0300 Subject: Preferences: Port the default preferences to the new system Simple port of the default preferences to the new preferences structure. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 83 +------ desktop-widgets/preferences.h | 5 - desktop-widgets/preferences.ui | 276 +-------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + .../preferences/preferences_defaults.cpp | 115 +++++++++ desktop-widgets/preferences/preferences_defaults.h | 30 +++ .../preferences/preferences_defaults.ui | 251 +++++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 8 files changed, 402 insertions(+), 361 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_defaults.cpp create mode 100644 desktop-widgets/preferences/preferences_defaults.h create mode 100644 desktop-widgets/preferences/preferences_defaults.ui (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 6450c41cb..cb19ce759 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -118,12 +118,8 @@ void PreferencesDialog::cloudPinNeeded() ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); if (prefs.cloud_verification_status == CS_VERIFIED) { ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); - ui.cloudDefaultFile->setEnabled(true); } else { ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); - if (ui.cloudDefaultFile->isChecked()) - ui.noDefaultFile->setChecked(true); - ui.cloudDefaultFile->setEnabled(false); } MainWindow::instance()->enableDisableCloudActions(); } @@ -186,24 +182,11 @@ void PreferencesDialog::setUiFromPrefs() ui.kg->setChecked(prefs.units.weight == units::KG); ui.lbs->setChecked(prefs.units.weight == units::LBS); - ui.font->setCurrentFont(QString(prefs.divelist_font)); - ui.fontsize->setValue(prefs.font_size); - ui.defaultfilename->setText(prefs.default_filename); - ui.noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); - ui.cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); - ui.localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - 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); - } - ui.displayinvalid->setChecked(prefs.display_invalid_dives); ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); ui.show_average_depth->setChecked(prefs.show_average_depth); ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); - ui.velocitySlider->setValue(prefs.animation_speed); + QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); filterModel->setSourceModel(LanguageModel::instance()); @@ -232,7 +215,7 @@ void PreferencesDialog::setUiFromPrefs() ui.proxyUsername->setText(prefs.proxy_user); ui.proxyPassword->setText(prefs.proxy_pass); ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); - ui.btnUseDefaultFile->setChecked(prefs.use_default_file); + ui.cloud_storage_email->setText(prefs.cloud_storage_email); ui.cloud_storage_password->setText(prefs.cloud_storage_password); @@ -302,27 +285,11 @@ void PreferencesDialog::syncSettings() // Defaults s.beginGroup("GeneralSettings"); - s.setValue("default_filename", ui.defaultfilename->text()); - s.setValue("default_cylinder", ui.default_cylinder->currentText()); - s.setValue("use_default_file", ui.btnUseDefaultFile->isChecked()); - if (ui.noDefaultFile->isChecked()) - s.setValue("default_file_behavior", NO_DEFAULT_FILE); - else if (ui.localDefaultFile->isChecked()) - s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); - else if (ui.cloudDefaultFile->isChecked()) - s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0)); s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); s.endGroup(); - s.beginGroup("Display"); - SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui.font->currentFont().toString(), ui.font->currentFont()); - SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui.fontsize->value()); - s.setValue("displayinvalid", ui.displayinvalid->isChecked()); - s.endGroup(); - s.sync(); - // Locale QLocale loc; s.beginGroup("Language"); @@ -336,11 +303,6 @@ void PreferencesDialog::syncSettings() s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole)); s.endGroup(); - // Animation - s.beginGroup("Animations"); - s.setValue("animation_speed", ui.velocitySlider->value()); - s.endGroup(); - s.beginGroup("Network"); s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); s.setValue("proxy_host", ui.proxyHost->text()); @@ -445,10 +407,6 @@ void PreferencesDialog::loadSettings() ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - - ui.defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); - ui.chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); } void PreferencesDialog::buttonClicked(QAbstractButton *button) @@ -472,15 +430,6 @@ void PreferencesDialog::buttonClicked(QAbstractButton *button) } #undef SB -void PreferencesDialog::on_chooseFile_clicked() -{ - QFileInfo fi(system_default_filename()); - 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); -} - void PreferencesDialog::on_resetSettings_clicked() { QSettings s; @@ -529,31 +478,3 @@ void PreferencesDialog::proxyType_changed(int idx) ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked()); } - -void PreferencesDialog::on_btnUseDefaultFile_toggled(bool toggle) -{ - if (toggle) { - ui.defaultfilename->setText(system_default_filename()); - ui.defaultfilename->setEnabled(false); - } else { - ui.defaultfilename->setEnabled(true); - } -} - -void PreferencesDialog::on_noDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = NO_DEFAULT_FILE; -} - -void PreferencesDialog::on_localDefaultFile_toggled(bool toggle) -{ - ui.defaultfilename->setEnabled(toggle); - ui.btnUseDefaultFile->setEnabled(toggle); - ui.chooseFile->setEnabled(toggle); - prefs.default_file_behavior = LOCAL_DEFAULT_FILE; -} - -void PreferencesDialog::on_cloudDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = CLOUD_DEFAULT_FILE; -} diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h index 326b1f964..c05145611 100644 --- a/desktop-widgets/preferences.h +++ b/desktop-widgets/preferences.h @@ -24,7 +24,6 @@ signals: public slots: void buttonClicked(QAbstractButton *button); - void on_chooseFile_clicked(); void on_resetSettings_clicked(); void syncSettings(); void loadSettings(); @@ -33,10 +32,6 @@ slots: void gflowChanged(int gf); void gfhighChanged(int gf); void proxyType_changed(int idx); - void on_btnUseDefaultFile_toggled(bool toggle); - void on_noDefaultFile_toggled(bool toggle); - void on_localDefaultFile_toggled(bool toggle); - void on_cloudDefaultFile_toggled(bool toggle); void facebookLoggedIn(); void facebookDisconnect(); void cloudPinNeeded(); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index de2d79b91..aa5dc4cb5 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -164,7 +164,7 @@ - 4 + 0 @@ -180,232 +180,6 @@ 5 - - - - Lists and tables - - - - 5 - - - - - Font - - - - - - - - - - Font size - - - - - - - - - - - - - Dives - - - - 5 - - - 5 - - - 5 - - - - - Default dive log file - - - - - - - - - No default file - - - defaultFileGroup - - - - - - - &Local default file - - - defaultFileGroup - - - - - - - Clo&ud storage default file - - - defaultFileGroup - - - - - - - - - Local dive log file - - - - - - - - - - - - Use default - - - true - - - - - - - ... - - - - - - - - - Display invalid - - - - - - - - - - - - - - - - - Default cylinder - - - - 5 - - - 5 - - - 5 - - - - - Use default cylinder - - - - - - - - - - - - - - - - - Animations - - - - 5 - - - - - Speed - - - - - - - 500 - - - Qt::Horizontal - - - - - - - 500 - - - - - - - - - - Clear all settings - - - - 5 - - - 5 - - - - - Reset all settings to their default value - - - - - - @@ -1788,38 +1562,6 @@ - - velocitySlider - valueChanged(int) - velocitySpinBox - setValue(int) - - - 236 - 52 - - - 236 - 52 - - - - - velocitySpinBox - valueChanged(int) - velocitySlider - setValue(int) - - - 236 - 52 - - - 236 - 52 - - - proxyAuthRequired toggled(bool) @@ -1852,22 +1594,6 @@ - - btnUseDefaultFile - toggled(bool) - chooseFile - setHidden(bool) - - - 236 - 44 - - - 236 - 44 - - - diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 4eb2f7d23..c55d7b881 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -14,6 +14,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferencesdialog.cpp preferences_language.cpp preferences_georeference.cpp + preferences_defaults.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp new file mode 100644 index 000000000..637117105 --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -0,0 +1,115 @@ +#include "preferences_defaults.h" +#include "ui_preferences_defaults.h" +#include "dive.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +PreferencesDefaults::PreferencesDefaults(): AbstractPreferencesWidget(tr("Defaults"), QIcon(":defaults"), 0 ), ui(new Ui::PreferencesDefaults()) +{ + ui->setupUi(this); +} + +PreferencesDefaults::~PreferencesDefaults() +{ + delete ui; +} + +void PreferencesDefaults::on_chooseFile_clicked() +{ + QFileInfo fi(system_default_filename()); + 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); +} + + +void PreferencesDefaults::on_btnUseDefaultFile_toggled(bool toggle) +{ + if (toggle) { + ui->defaultfilename->setText(system_default_filename()); + ui->defaultfilename->setEnabled(false); + } else { + ui->defaultfilename->setEnabled(true); + } +} + +void PreferencesDefaults::on_noDefaultFile_toggled(bool toggle) +{ + prefs.default_file_behavior = NO_DEFAULT_FILE; +} + +void PreferencesDefaults::on_localDefaultFile_toggled(bool toggle) +{ + ui->defaultfilename->setEnabled(toggle); + ui->btnUseDefaultFile->setEnabled(toggle); + ui->chooseFile->setEnabled(toggle); + prefs.default_file_behavior = LOCAL_DEFAULT_FILE; +} + +void PreferencesDefaults::on_cloudDefaultFile_toggled(bool toggle) +{ + prefs.default_file_behavior = CLOUD_DEFAULT_FILE; +} + +void PreferencesDefaults::refreshSettings() +{ + ui->font->setCurrentFont(QString(prefs.divelist_font)); + ui->fontsize->setValue(prefs.font_size); + ui->defaultfilename->setText(prefs.default_filename); + ui->noDefaultFile->setChecked(prefs.default_file_behavior == NO_DEFAULT_FILE); + ui->cloudDefaultFile->setChecked(prefs.default_file_behavior == CLOUD_DEFAULT_FILE); + ui->localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + + 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); + } + ui->displayinvalid->setChecked(prefs.display_invalid_dives); + ui->velocitySlider->setValue(prefs.animation_speed); + ui->btnUseDefaultFile->setChecked(prefs.use_default_file); + + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui->cloudDefaultFile->setEnabled(true); + } else { + if (ui->cloudDefaultFile->isChecked()) + ui->noDefaultFile->setChecked(true); + ui->cloudDefaultFile->setEnabled(false); + } + + ui->defaultfilename->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui->btnUseDefaultFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); + ui->chooseFile->setEnabled(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); +} + +void PreferencesDefaults::syncSettings() +{ + QSettings s; + s.beginGroup("GeneralSettings"); + s.setValue("default_filename", ui->defaultfilename->text()); + s.setValue("default_cylinder", ui->default_cylinder->currentText()); + s.setValue("use_default_file", ui->btnUseDefaultFile->isChecked()); + if (ui->noDefaultFile->isChecked()) + s.setValue("default_file_behavior", NO_DEFAULT_FILE); + else if (ui->localDefaultFile->isChecked()) + s.setValue("default_file_behavior", LOCAL_DEFAULT_FILE); + else if (ui->cloudDefaultFile->isChecked()) + s.setValue("default_file_behavior", CLOUD_DEFAULT_FILE); + s.endGroup(); + + s.beginGroup("Display"); + SAVE_OR_REMOVE_SPECIAL("divelist_font", system_divelist_default_font, ui->font->currentFont().toString(), ui->font->currentFont()); + SAVE_OR_REMOVE("font_size", system_divelist_default_font_size, ui->fontsize->value()); + s.setValue("displayinvalid", ui->displayinvalid->isChecked()); + s.endGroup(); + s.sync(); + + // Animation + s.beginGroup("Animations"); + s.setValue("animation_speed", ui->velocitySlider->value()); + s.endGroup(); +} diff --git a/desktop-widgets/preferences/preferences_defaults.h b/desktop-widgets/preferences/preferences_defaults.h new file mode 100644 index 000000000..94de8b28a --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.h @@ -0,0 +1,30 @@ +#ifndef PREFERENCES_DEFAULTS_H +#define PREFERENCES_DEFAULTS_H + +#include "abstractpreferenceswidget.h" +#include "subsurface-core/pref.h" + +namespace Ui { + class PreferencesDefaults; +} + +class PreferencesDefaults : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesDefaults(); + virtual ~PreferencesDefaults(); + virtual void refreshSettings(); + virtual void syncSettings(); +public slots: + void on_chooseFile_clicked(); + void on_btnUseDefaultFile_toggled(bool toggled); + void on_noDefaultFile_toggled(bool toggled); + void on_localDefaultFile_toggled(bool toggled); + void on_cloudDefaultFile_toggled(bool toggled); + +private: + Ui::PreferencesDefaults *ui; +}; + + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui new file mode 100644 index 000000000..632e82763 --- /dev/null +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -0,0 +1,251 @@ + + + PreferencesDefaults + + + + 0 + 0 + 555 + 558 + + + + Form + + + + + + Lists and tables + + + + 5 + + + + + Font + + + + + + + + + + Font size + + + + + + + + + + + + + Dives + + + + 5 + + + 5 + + + 5 + + + + + Default dive log file + + + + + + + + + No default file + + + + + + + &Local default file + + + + + + + Clo&ud storage default file + + + + + + + + + Local dive log file + + + + + + + + + + + + Use default + + + true + + + + + + + ... + + + + + + + + + Display invalid + + + + + + + + + + + + + + + + + Default cylinder + + + + 5 + + + 5 + + + 5 + + + + + Use default cylinder + + + + + + + + + + + + + + + + + Animations + + + + 5 + + + + + Speed + + + + + + + 500 + + + Qt::Horizontal + + + + + + + 500 + + + + + + + + + + Clear all settings + + + + 5 + + + 5 + + + + + Reset all settings to their default value + + + + + + + + + + Qt::Vertical + + + + 0 + 195 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 3975994a9..6f66d856d 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -3,6 +3,7 @@ #include "abstractpreferenceswidget.h" #include "preferences_language.h" #include "preferences_georeference.h" +#include "preferences_defaults.h" #include #include @@ -35,6 +36,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesLanguage()); addPreferencePage(new PreferencesGeoreference()); + addPreferencePage(new PreferencesDefaults()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From 57d7b59bdc62a5b01fa420bc420dbdcf1414a23a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 25 Sep 2015 17:07:04 -0300 Subject: Preferences: move units to the new dialog Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 39 -- desktop-widgets/preferences.ui | 489 +--------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + desktop-widgets/preferences/preferences_units.cpp | 60 +++ desktop-widgets/preferences/preferences_units.h | 21 + desktop-widgets/preferences/preferences_units.ui | 251 +++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 7 files changed, 336 insertions(+), 527 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_units.cpp create mode 100644 desktop-widgets/preferences/preferences_units.h create mode 100644 desktop-widgets/preferences/preferences_units.ui (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 2ce96bd77..672d75906 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -146,7 +146,6 @@ void PreferencesDialog::setUiFromPrefs() ui.pn2Threshold->setValue(prefs.pp_graphs.pn2_threshold); ui.maxpo2->setValue(prefs.modpO2); ui.red_ceiling->setChecked(prefs.redceiling); - ui.units_group->setEnabled(ui.personalize->isChecked()); ui.gflow->setValue(prefs.gflow); ui.gfhigh->setValue(prefs.gfhigh); @@ -157,31 +156,8 @@ void PreferencesDialog::setUiFromPrefs() ui.psro2rate->setValue(prefs.o2consumption / 1000.0); ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); - // units - if (prefs.unit_system == METRIC) - ui.metric->setChecked(true); - else if (prefs.unit_system == IMPERIAL) - ui.imperial->setChecked(true); - else - ui.personalize->setChecked(true); - ui.gpsTraditional->setChecked(prefs.coordinates_traditional); - ui.gpsDecimal->setChecked(!prefs.coordinates_traditional); - - 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.kg->setChecked(prefs.units.weight == units::KG); - ui.lbs->setChecked(prefs.units.weight == units::LBS); - ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); ui.show_average_depth->setChecked(prefs.show_average_depth); - ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); - ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); QSettings s; @@ -237,20 +213,6 @@ void PreferencesDialog::syncSettings() SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked()); s.endGroup(); - // Units - s.beginGroup("Units"); - QString unitSystem[] = {"metric", "imperial", "personal"}; - short unitValue = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE); - SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); - 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); - s.setValue("vertical_speed_time", ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); - s.setValue("coordinates", ui.gpsTraditional->isChecked()); - s.endGroup(); - // Defaults s.beginGroup("GeneralSettings"); s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); @@ -391,7 +353,6 @@ void PreferencesDialog::buttonClicked(QAbstractButton *button) void PreferencesDialog::on_resetSettings_clicked() { QSettings s; - QMessageBox response(this); response.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); response.setDefaultButton(QMessageBox::Cancel); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index a799d966c..12ba10d4b 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -83,16 +83,6 @@ -1 - - - Units - - - - :/units - - - Graph @@ -134,309 +124,8 @@ - 3 + 0 - - - - 0 - 0 - - - - - 5 - - - 5 - - - - - Unit system - - - - - - System - - - - - - - &Metric - - - buttonGroup_6 - - - - - - - Imperial - - - buttonGroup_6 - - - - - - - Personali&ze - - - buttonGroup_6 - - - - - - - - - - Individual settings - - - false - - - false - - - - - - Depth - - - - - - - meter - - - buttonGroup - - - - - - - feet - - - buttonGroup - - - - - - - Pressure - - - - - - - bar - - - buttonGroup_2 - - - - - - - psi - - - buttonGroup_2 - - - - - - - Volume - - - - - - - &liter - - - buttonGroup_3 - - - - - - - cu ft - - - buttonGroup_3 - - - - - - - Temperature - - - - - - - celsius - - - buttonGroup_4 - - - - - - - fahrenheit - - - buttonGroup_4 - - - - - - - Weight - - - - - - - kg - - - buttonGroup_5 - - - - - - - lbs - - - buttonGroup_5 - - - - - - - - - - - - Time units - - - - - - Ascent/descent speed denominator - - - - - - - Minutes - - - verticalSpeed - - - - - - - Seconds - - - verticalSpeed - - - - - - - - - - - - GPS coordinates - - - - - - Location Display - - - - - - - traditional (dms) - - - buttonGroup_7 - - - - - - - decimal - - - buttonGroup_7 - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - @@ -1120,182 +809,6 @@ - - personalize - toggled(bool) - units_group - setEnabled(bool) - - - 185 - 19 - - - 186 - 23 - - - - - imperial - toggled(bool) - feet - setChecked(bool) - - - 164 - 19 - - - 175 - 34 - - - - - metric - toggled(bool) - meter - setChecked(bool) - - - 142 - 19 - - - 153 - 34 - - - - - imperial - toggled(bool) - psi - setChecked(bool) - - - 164 - 19 - - - 175 - 33 - - - - - metric - toggled(bool) - bar - setChecked(bool) - - - 142 - 19 - - - 153 - 33 - - - - - imperial - toggled(bool) - cuft - setChecked(bool) - - - 164 - 19 - - - 175 - 31 - - - - - metric - toggled(bool) - liter - setChecked(bool) - - - 142 - 19 - - - 153 - 31 - - - - - imperial - toggled(bool) - fahrenheit - setChecked(bool) - - - 164 - 19 - - - 175 - 29 - - - - - metric - toggled(bool) - celsius - setChecked(bool) - - - 142 - 19 - - - 153 - 29 - - - - - imperial - toggled(bool) - lbs - setChecked(bool) - - - 164 - 19 - - - 175 - 28 - - - - - metric - toggled(bool) - kg - setChecked(bool) - - - 142 - 19 - - - 153 - 28 - - - proxyAuthRequired toggled(bool) diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index c55d7b881..8ea4bd79c 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -15,6 +15,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_language.cpp preferences_georeference.cpp preferences_defaults.cpp + preferences_units.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_units.cpp b/desktop-widgets/preferences/preferences_units.cpp new file mode 100644 index 000000000..76f2078d7 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.cpp @@ -0,0 +1,60 @@ +#include "preferences_units.h" +#include "ui_preferences_units.h" +#include "prefs-macros.h" +#include "qthelper.h" + +#include + +PreferencesUnits::PreferencesUnits(): AbstractPreferencesWidget(tr("Units"),QIcon(":units"),1), ui(new Ui::PreferencesUnits()) +{ + ui->setupUi(this); +} + +PreferencesUnits::~PreferencesUnits() +{ + +} + +void PreferencesUnits::refreshSettings() +{ + QSettings s; + s.beginGroup("Units"); + QString unitSystem[] = {"metric", "imperial", "personal"}; + short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE); + SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); + 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); + s.setValue("vertical_speed_time", ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); + s.setValue("coordinates", ui->gpsTraditional->isChecked()); + s.endGroup(); +} + +void PreferencesUnits::syncSettings() +{ + switch(prefs.unit_system) { + case METRIC: ui->metric->setChecked(true); break; + case IMPERIAL: ui->imperial->setChecked(true); break; + default: ui->personalize->setChecked(true); break; + } + + ui->gpsTraditional->setChecked(prefs.coordinates_traditional); + ui->gpsDecimal->setChecked(!prefs.coordinates_traditional); + + 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->kg->setChecked(prefs.units.weight == units::KG); + ui->lbs->setChecked(prefs.units.weight == units::LBS); + ui->units_group->setEnabled(ui->personalize->isChecked()); + + ui->vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); + ui->vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); +} diff --git a/desktop-widgets/preferences/preferences_units.h b/desktop-widgets/preferences/preferences_units.h new file mode 100644 index 000000000..21a7f4404 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.h @@ -0,0 +1,21 @@ +#ifndef PREFERENCES_UNITS_H +#define PREFERENCES_UNITS_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesUnits; +} + +class PreferencesUnits : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesUnits(); + virtual ~PreferencesUnits(); + virtual void refreshSettings(); + virtual void syncSettings(); +private: + Ui::PreferencesUnits *ui; +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_units.ui b/desktop-widgets/preferences/preferences_units.ui new file mode 100644 index 000000000..bb1ffba66 --- /dev/null +++ b/desktop-widgets/preferences/preferences_units.ui @@ -0,0 +1,251 @@ + + + PreferencesUnits + + + + 0 + 0 + 400 + 374 + + + + Form + + + + + + Unit system + + + + + + System + + + + + + + &Metric + + + + + + + Imperial + + + + + + + Personali&ze + + + + + + + + + + Individual settings + + + false + + + false + + + + + + Depth + + + + + + + meter + + + + + + + feet + + + + + + + Pressure + + + + + + + bar + + + + + + + psi + + + + + + + Volume + + + + + + + &liter + + + + + + + cu ft + + + + + + + Temperature + + + + + + + celsius + + + + + + + fahrenheit + + + + + + + Weight + + + + + + + kg + + + + + + + lbs + + + + + + + + + + Time units + + + + + + Ascent/descent speed denominator + + + + + + + Minutes + + + + + + + Seconds + + + + + + + + + + GPS coordinates + + + + + + Location Display + + + + + + + traditional (dms) + + + + + + + decimal + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 6f66d856d..7d9e17d7e 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -4,6 +4,7 @@ #include "preferences_language.h" #include "preferences_georeference.h" #include "preferences_defaults.h" +#include "preferences_units.h" #include #include @@ -37,6 +38,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesLanguage()); addPreferencePage(new PreferencesGeoreference()); addPreferencePage(new PreferencesDefaults()); + addPreferencePage(new PreferencesUnits()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From cfecd1a9ab6f1ac870622427af56fa43a87bf14b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 1 Oct 2015 18:59:53 -0300 Subject: Preferences: move graph preferences to the new dialog Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 56 +--- desktop-widgets/preferences.h | 2 - desktop-widgets/preferences.ui | 356 +++------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + desktop-widgets/preferences/preferences_graph.cpp | 78 +++++ desktop-widgets/preferences/preferences_graph.h | 27 ++ desktop-widgets/preferences/preferences_graph.ui | 268 ++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 8 files changed, 417 insertions(+), 373 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_graph.cpp create mode 100644 desktop-widgets/preferences/preferences_graph.h create mode 100644 desktop-widgets/preferences/preferences_graph.ui (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 672d75906..9ef93fafc 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -64,8 +64,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial #endif connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); - connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int))); - connect(ui.gfhigh, SIGNAL(valueChanged(int)), this, SLOT(gfhighChanged(int))); + // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); connect(close, SIGNAL(activated()), this, SLOT(close())); @@ -120,17 +119,6 @@ void PreferencesDialog::cloudPinNeeded() MainWindow::instance()->enableDisableCloudActions(); } -#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" -void PreferencesDialog::gflowChanged(int gf) -{ - ui.gflow->setStyleSheet(DANGER_GF); -} -void PreferencesDialog::gfhighChanged(int gf) -{ - ui.gfhigh->setStyleSheet(DANGER_GF); -} -#undef DANGER_GF - void PreferencesDialog::showEvent(QShowEvent *event) { setUiFromPrefs(); @@ -140,25 +128,6 @@ void PreferencesDialog::showEvent(QShowEvent *event) void PreferencesDialog::setUiFromPrefs() { - // graphs - 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.maxpo2->setValue(prefs.modpO2); - ui.red_ceiling->setChecked(prefs.redceiling); - - ui.gflow->setValue(prefs.gflow); - ui.gfhigh->setValue(prefs.gfhigh); - ui.gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); - ui.show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); - ui.show_ccr_sensors->setChecked(prefs.show_ccr_sensors); - ui.defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); - ui.psro2rate->setValue(prefs.o2consumption / 1000.0); - ui.pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); - - ui.display_unused_tanks->setChecked(prefs.display_unused_tanks); - ui.show_average_depth->setChecked(prefs.show_average_depth); - QSettings s; ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); @@ -197,29 +166,6 @@ void PreferencesDialog::syncSettings() s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper()); set_save_userid_local(ui.save_uid_local->checkState()); - // Graph - s.beginGroup("TecDetails"); - SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui.pheThreshold->value()); - SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui.po2Threshold->value()); - SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui.pn2Threshold->value()); - SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui.maxpo2->value()); - SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui.red_ceiling->isChecked()); - SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui.gflow->value()); - SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui.gfhigh->value()); - SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui.gf_low_at_maxdepth->isChecked()); - SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui.show_ccr_setpoint->isChecked()); - SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui.show_ccr_sensors->isChecked()); - SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui.display_unused_tanks->isChecked()); - SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui.show_average_depth->isChecked()); - s.endGroup(); - - // Defaults - s.beginGroup("GeneralSettings"); - s.setValue("defaultsetpoint", rint(ui.defaultSetpoint->value() * 1000.0)); - s.setValue("o2consumption", rint(ui.psro2rate->value() *1000.0)); - s.setValue("pscr_ratio", rint(1000.0 / ui.pscrfactor->value())); - s.endGroup(); - s.beginGroup("Network"); s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); s.setValue("proxy_host", ui.proxyHost->text()); diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h index c05145611..4d2c33e76 100644 --- a/desktop-widgets/preferences.h +++ b/desktop-widgets/preferences.h @@ -29,8 +29,6 @@ slots: void loadSettings(); void restorePrefs(); void rememberPrefs(); - void gflowChanged(int gf); - void gfhighChanged(int gf); void proxyType_changed(int idx); void facebookLoggedIn(); void facebookDisconnect(); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index 12ba10d4b..97e281433 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -6,8 +6,8 @@ 0 0 - 711 - 662 + 835 + 698 @@ -19,7 +19,16 @@ - + + 5 + + + 5 + + + 5 + + 5 @@ -83,16 +92,6 @@ -1 - - - Graph - - - - :/graph - - - Network @@ -126,309 +125,27 @@ 0 - + 0 0 - + 5 - + 5 - - - - Show - - - - - - - - true - - - Threshold when showing pOâ‚‚ - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Threshold when showing pNâ‚‚ - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Threshold when showing pHe - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Max pOâ‚‚ when showing MOD - - - - - - - true - - - 0.100000000000000 - - - - - - - - - - - true - - - Draw dive computer reported ceiling red - - - - - - - - - - - Show unused cylinders in Equipment tab - - - - - - - - - - - Show average depth - - - - - - - - - - - - Misc - - - - - - GFLow - - - - - - - 1 - - - 150 - - - - - - - GFHigh - - - - - - - 1 - - - 150 - - - - - - - GFLow at max depth - - - - - - - CCR: show setpoints when viewing pOâ‚‚ - - - - - - - CCR: show individual Oâ‚‚ sensor values when viewing pOâ‚‚ - - - - - - - Default CCR set-point for dive planning - - - - - - - bar - - - 2 - - - 10.000000000000000 - - - 0.100000000000000 - - - - - - - pSCR Oâ‚‚ metabolism rate - - - - - - - pSCR ratio - - - - - - - â„“/min - - - 3 - - - - - - - - - - 1: - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - 0 - - - - + + 5 + + 5 - + 5 @@ -658,7 +375,16 @@ 5 - + + 5 + + + 5 + + + 5 + + 5 @@ -707,7 +433,16 @@ 5 - + + 5 + + + 5 + + + 5 + + 5 @@ -842,15 +577,4 @@ - - - - - - - - - - - diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 8ea4bd79c..b3ef4e3d5 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -16,6 +16,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_georeference.cpp preferences_defaults.cpp preferences_units.cpp + preferences_graph.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_graph.cpp b/desktop-widgets/preferences/preferences_graph.cpp new file mode 100644 index 000000000..f671076f4 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.cpp @@ -0,0 +1,78 @@ +#include "preferences_graph.h" +#include "ui_preferences_graph.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +#include "qt-models/models.h" + +PreferencesGraph::PreferencesGraph() : AbstractPreferencesWidget(tr("Graph"), QIcon(":graph"), 5) +{ + ui = new Ui::PreferencesGraph(); + ui->setupUi(this); +} + +PreferencesGraph::~PreferencesGraph() +{ + delete ui; +} + +void PreferencesGraph::refreshSettings() +{ + 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->maxpo2->setValue(prefs.modpO2); + ui->red_ceiling->setChecked(prefs.redceiling); + + ui->gflow->setValue(prefs.gflow); + ui->gfhigh->setValue(prefs.gfhigh); + ui->gf_low_at_maxdepth->setChecked(prefs.gf_low_at_maxdepth); + ui->show_ccr_setpoint->setChecked(prefs.show_ccr_setpoint); + ui->show_ccr_sensors->setChecked(prefs.show_ccr_sensors); + ui->defaultSetpoint->setValue((double)prefs.defaultsetpoint / 1000.0); + ui->psro2rate->setValue(prefs.o2consumption / 1000.0); + ui->pscrfactor->setValue(rint(1000.0 / prefs.pscr_ratio)); + + ui->display_unused_tanks->setChecked(prefs.display_unused_tanks); + ui->show_average_depth->setChecked(prefs.show_average_depth); +} + +void PreferencesGraph::syncSettings() +{ + QSettings s; + + s.beginGroup("GeneralSettings"); + s.setValue("defaultsetpoint", rint(ui->defaultSetpoint->value() * 1000.0)); + s.setValue("o2consumption", rint(ui->psro2rate->value() *1000.0)); + s.setValue("pscr_ratio", rint(1000.0 / ui->pscrfactor->value())); + s.endGroup(); + + // Graph + s.beginGroup("TecDetails"); + SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui->pheThreshold->value()); + SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui->po2Threshold->value()); + SAVE_OR_REMOVE("pn2threshold", default_prefs.pp_graphs.pn2_threshold, ui->pn2Threshold->value()); + SAVE_OR_REMOVE("modpO2", default_prefs.modpO2, ui->maxpo2->value()); + SAVE_OR_REMOVE("redceiling", default_prefs.redceiling, ui->red_ceiling->isChecked()); + SAVE_OR_REMOVE("gflow", default_prefs.gflow, ui->gflow->value()); + SAVE_OR_REMOVE("gfhigh", default_prefs.gfhigh, ui->gfhigh->value()); + SAVE_OR_REMOVE("gf_low_at_maxdepth", default_prefs.gf_low_at_maxdepth, ui->gf_low_at_maxdepth->isChecked()); + SAVE_OR_REMOVE("show_ccr_setpoint", default_prefs.show_ccr_setpoint, ui->show_ccr_setpoint->isChecked()); + SAVE_OR_REMOVE("show_ccr_sensors", default_prefs.show_ccr_sensors, ui->show_ccr_sensors->isChecked()); + SAVE_OR_REMOVE("display_unused_tanks", default_prefs.display_unused_tanks, ui->display_unused_tanks->isChecked()); + SAVE_OR_REMOVE("show_average_depth", default_prefs.show_average_depth, ui->show_average_depth->isChecked()); + s.endGroup(); +} + +#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" +void PreferencesGraph::on_gflow_valueChanged(int gf) +{ + ui->gflow->setStyleSheet(DANGER_GF); +} +void PreferencesGraph::on_gfhigh_valueChanged(int gf) +{ + ui->gfhigh->setStyleSheet(DANGER_GF); +} +#undef DANGER_GF \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.h b/desktop-widgets/preferences/preferences_graph.h new file mode 100644 index 000000000..ca40c0a92 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.h @@ -0,0 +1,27 @@ +#ifndef PREFERENCES_GRAPH_H +#define PREFERENCES_GRAPH_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesGraph; +} + +class PreferencesGraph : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesGraph(); + virtual ~PreferencesGraph(); + virtual void refreshSettings(); + virtual void syncSettings(); + +private slots: + void on_gflow_valueChanged(int gf); + void on_gfhigh_valueChanged(int gf); + +private: + Ui::PreferencesGraph *ui; + +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_graph.ui b/desktop-widgets/preferences/preferences_graph.ui new file mode 100644 index 000000000..bdbbc75d3 --- /dev/null +++ b/desktop-widgets/preferences/preferences_graph.ui @@ -0,0 +1,268 @@ + + + PreferencesGraph + + + + 0 + 0 + 505 + 623 + + + + Form + + + + + + Show + + + + + + true + + + Threshold when showing pOâ‚‚ + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Threshold when showing pNâ‚‚ + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Threshold when showing pHe + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Max pOâ‚‚ when showing MOD + + + + + + + true + + + 0.100000000000000 + + + + + + + true + + + Draw dive computer reported ceiling red + + + + + + + Show unused cylinders in Equipment tab + + + + + + + Show average depth + + + + + + + + + + Misc + + + + + + 1 + + + 150 + + + + + + + bar + + + 2 + + + 10.000000000000000 + + + 0.100000000000000 + + + + + + + Default CCR set-point for dive planning + + + + + + + pSCR Oâ‚‚ metabolism rate + + + + + + + GFLow + + + + + + + GFHigh + + + + + + + 1 + + + 150 + + + + + + + â„“/min + + + 3 + + + + + + + pSCR ratio + + + + + + + + + + 1: + + + + + + + CCR: show individual Oâ‚‚ sensor values when viewing pOâ‚‚ + + + + + + + CCR: show setpoints when viewing pOâ‚‚ + + + + + + + GFLow at max depth + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 7d9e17d7e..db1d30113 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -5,6 +5,7 @@ #include "preferences_georeference.h" #include "preferences_defaults.h" #include "preferences_units.h" +#include "preferences_graph.h" #include #include @@ -39,6 +40,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesGeoreference()); addPreferencePage(new PreferencesDefaults()); addPreferencePage(new PreferencesUnits()); + addPreferencePage(new PreferencesGraph()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From d9595ad266021575522f73bb87dfc51517461d59 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 1 Oct 2015 19:48:57 -0300 Subject: Preferences: move network preferences to the new dialog Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences.cpp | 177 +---------- desktop-widgets/preferences.h | 3 - desktop-widgets/preferences.ui | 339 --------------------- desktop-widgets/preferences/CMakeLists.txt | 1 + .../preferences/preferences_network.cpp | 173 +++++++++++ desktop-widgets/preferences/preferences_network.h | 26 ++ desktop-widgets/preferences/preferences_network.ui | 293 ++++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 2 + 8 files changed, 496 insertions(+), 518 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_network.cpp create mode 100644 desktop-widgets/preferences/preferences_network.h create mode 100644 desktop-widgets/preferences/preferences_network.ui (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 9ef93fafc..2ec9ee96d 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -31,23 +31,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial ui.setupUi(this); setAttribute(Qt::WA_QuitOnClose, false); -#if defined(Q_OS_ANDROID) || !defined(FBSUPPORT) - for (int i = 0; i < ui.listWidget->count(); i++) { - if (ui.listWidget->item(i)->text() == "Facebook") { - delete ui.listWidget->item(i); - QWidget *fbpage = ui.stackedWidget->widget(i); - ui.stackedWidget->removeWidget(fbpage); - } - } -#endif - - ui.proxyType->clear(); - ui.proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); - ui.proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); - ui.proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); - ui.proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); - ui.proxyType->setCurrentIndex(-1); - #if !defined(Q_OS_ANDROID) && defined(FBSUPPORT) FacebookManager *fb = FacebookManager::instance(); facebookWebView = new QWebView(this); @@ -62,7 +45,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial connect(ui.fbDisconnect, &QPushButton::clicked, fb, &FacebookManager::logout); connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); #endif - connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); + connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); // connect(ui.defaultSetpoint, SIGNAL(valueChanged(double)), this, SLOT(defaultSetpointChanged(double))); @@ -101,24 +84,6 @@ void PreferencesDialog::facebookDisconnect() #endif } -void PreferencesDialog::cloudPinNeeded() -{ - ui.cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); - ui.cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); - ui.cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); - if (prefs.cloud_verification_status == CS_VERIFIED) { - ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); - } else { - ui.cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); - } - MainWindow::instance()->enableDisableCloudActions(); -} - void PreferencesDialog::showEvent(QShowEvent *event) { setUiFromPrefs(); @@ -128,24 +93,7 @@ void PreferencesDialog::showEvent(QShowEvent *event) void PreferencesDialog::setUiFromPrefs() { - QSettings s; - - ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); - ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); - - ui.proxyHost->setText(prefs.proxy_host); - ui.proxyPort->setValue(prefs.proxy_port); - ui.proxyAuthRequired->setChecked(prefs.proxy_auth); - ui.proxyUsername->setText(prefs.proxy_user); - ui.proxyPassword->setText(prefs.proxy_pass); - ui.proxyType->setCurrentIndex(ui.proxyType->findData(prefs.proxy_type)); - - ui.cloud_storage_email->setText(prefs.cloud_storage_email); - ui.cloud_storage_password->setText(prefs.cloud_storage_password); - ui.save_password_local->setChecked(prefs.save_password_local); - cloudPinNeeded(); - ui.cloud_background_sync->setChecked(prefs.cloud_background_sync); } void PreferencesDialog::restorePrefs() @@ -161,105 +109,6 @@ void PreferencesDialog::rememberPrefs() void PreferencesDialog::syncSettings() { - QSettings s; - - s.setValue("subsurface_webservice_uid", ui.default_uid->text().toUpper()); - set_save_userid_local(ui.save_uid_local->checkState()); - - s.beginGroup("Network"); - s.setValue("proxy_type", ui.proxyType->itemData(ui.proxyType->currentIndex()).toInt()); - s.setValue("proxy_host", ui.proxyHost->text()); - s.setValue("proxy_port", ui.proxyPort->value()); - SB("proxy_auth", ui.proxyAuthRequired); - s.setValue("proxy_user", ui.proxyUsername->text()); - s.setValue("proxy_pass", ui.proxyPassword->text()); - s.endGroup(); - - s.beginGroup("CloudStorage"); - QString email = ui.cloud_storage_email->text(); - QString password = ui.cloud_storage_password->text(); - QString newpassword = ui.cloud_storage_new_passwd->text(); - if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { - // deal with password change - if (!email.isEmpty() && !password.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } else { - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); - QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); - ui.cloud_storage_new_passwd->setText(""); - free(prefs.cloud_storage_newpassword); - prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); - } - } - } else if (prefs.cloud_verification_status == CS_UNKNOWN || - prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || - email != prefs.cloud_storage_email || - password != prefs.cloud_storage_password) { - - // different credentials - reset verification status - prefs.cloud_verification_status = CS_UNKNOWN; - if (!email.isEmpty() && !password.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } else { - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->backend(email, password); - } - } - } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { - QString pin = ui.cloud_storage_pin->text(); - if (!pin.isEmpty()) { - // connect to backend server to check / create credentials - QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); - if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { - report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); - } - CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); - connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->backend(email, password, pin); - } - } - SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); - SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui.save_password_local->isChecked()); - if (ui.save_password_local->isChecked()) { - SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); - } else { - s.remove("password"); - free(prefs.cloud_storage_password); - prefs.cloud_storage_password = strdup(qPrintable(password)); - } - SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); - SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui.cloud_background_sync->isChecked()); - - // at this point we intentionally do not have a UI for changing this - // it could go into some sort of "advanced setup" or something - SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); - s.endGroup(); - -<<<<<<< HEAD - s.beginGroup("geocoding"); -#ifdef DISABLED - s.setValue("enable_geocoding", ui.enable_geocoding->isChecked()); - s.setValue("parse_dive_without_gps", ui.parse_without_gps->isChecked()); - s.setValue("tag_existing_dives", ui.tag_existing_dives->isChecked()); -#endif - s.setValue("cat0", ui.first_item->currentIndex()); - s.setValue("cat1", ui.second_item->currentIndex()); - s.setValue("cat2", ui.third_item->currentIndex()); - s.endGroup(); - -======= ->>>>>>> Code Cleanup - loadSettings(); - emit settingsChanged(); } void PreferencesDialog::loadSettings() @@ -270,9 +119,6 @@ void PreferencesDialog::loadSettings() loadPreferences(); QSettings s; QVariant v; - - ui.save_uid_local->setChecked(s.value("save_uid_local").toBool()); - ui.default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); } void PreferencesDialog::buttonClicked(QAbstractButton *button) @@ -318,28 +164,7 @@ void PreferencesDialog::on_resetSettings_clicked() } } -void PreferencesDialog::passwordUpdateSuccessfull() -{ - ui.cloud_storage_password->setText(prefs.cloud_storage_password); -} - void PreferencesDialog::emitSettingsChanged() { emit settingsChanged(); } - -void PreferencesDialog::proxyType_changed(int idx) -{ - if (idx == -1) { - return; - } - - int proxyType = ui.proxyType->itemData(idx).toInt(); - bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); - ui.proxyHost->setEnabled(hpEnabled); - ui.proxyPort->setEnabled(hpEnabled); - ui.proxyAuthRequired->setEnabled(hpEnabled); - ui.proxyUsername->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); - ui.proxyPassword->setEnabled(hpEnabled & ui.proxyAuthRequired->isChecked()); - ui.proxyAuthRequired->setChecked(ui.proxyAuthRequired->isChecked()); -} diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h index 4d2c33e76..0fda4d390 100644 --- a/desktop-widgets/preferences.h +++ b/desktop-widgets/preferences.h @@ -29,11 +29,8 @@ slots: void loadSettings(); void restorePrefs(); void rememberPrefs(); - void proxyType_changed(int idx); void facebookLoggedIn(); void facebookDisconnect(); - void cloudPinNeeded(); - void passwordUpdateSuccessfull(); private: explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); void setUiFromPrefs(); diff --git a/desktop-widgets/preferences.ui b/desktop-widgets/preferences.ui index 97e281433..8d0b18900 100644 --- a/desktop-widgets/preferences.ui +++ b/desktop-widgets/preferences.ui @@ -92,16 +92,6 @@ -1 - - - Network - - - - :/network - - - Facebook @@ -125,303 +115,6 @@ 0 - - - - 0 - 0 - - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Proxy - - - - - - - 0 - 0 - - - - Port - - - - - - - - - - Host - - - - - - - Qt::LeftToRight - - - Requires authentication - - - - - - - Proxy type - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Username - - - - - - - - 1 - 0 - - - - 65535 - - - 80 - - - - - - - - 0 - 0 - - - - 32 - - - - - - - - 2 - 0 - - - - 64 - - - - - - - Password - - - - - - - - 0 - 0 - - - - 32 - - - QLineEdit::Password - - - - - - - - - - - 0 - 0 - - - - - 0 - 129 - - - - Subsurface cloud storage - - - - - - - - - Email address - - - - - - - Password - - - - - - - Verification PIN - - - - - - - New password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - - - - - - - - QLineEdit::Password - - - - - - - Sync to cloud in the background? - - - - - - - Save Password locally? - - - - - - - - - - Subsurface web service - - - - 5 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - Default user ID - - - - - - - - - - Save user ID locally? - - - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - @@ -544,37 +237,5 @@ - - proxyAuthRequired - toggled(bool) - proxyUsername - setEnabled(bool) - - - 409 - 123 - - - 409 - 153 - - - - - proxyAuthRequired - toggled(bool) - proxyPassword - setEnabled(bool) - - - 409 - 123 - - - 409 - 183 - - - diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index b3ef4e3d5..4e506ed73 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -17,6 +17,7 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_defaults.cpp preferences_units.cpp preferences_graph.cpp + preferences_network.cpp ) source_group("Subsurface Preferences" FILES ${SUBSURFACE_PREFERENCES_LIB_SRCS}) diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp new file mode 100644 index 000000000..000df1e7f --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.cpp @@ -0,0 +1,173 @@ +#include "preferences_network.h" +#include "ui_preferences_network.h" +#include "preferences.h" +#include "dive.h" +#include "subsurfacewebservices.h" +#include "subsurface-core/prefs-macros.h" + +#include +#include + +PreferencesNetwork::PreferencesNetwork() : AbstractPreferencesWidget(tr("Network"),QIcon(":network"), 9), ui(new Ui::PreferencesNetwork()) +{ + ui->setupUi(this); + + ui->proxyType->clear(); + ui->proxyType->addItem(tr("No proxy"), QNetworkProxy::NoProxy); + ui->proxyType->addItem(tr("System proxy"), QNetworkProxy::DefaultProxy); + ui->proxyType->addItem(tr("HTTP proxy"), QNetworkProxy::HttpProxy); + ui->proxyType->addItem(tr("SOCKS proxy"), QNetworkProxy::Socks5Proxy); + ui->proxyType->setCurrentIndex(-1); + + connect(ui->proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); +} + +PreferencesNetwork::~PreferencesNetwork() +{ + delete ui; +} + +void PreferencesNetwork::refreshSettings() +{ + QSettings s; + + ui->proxyHost->setText(prefs.proxy_host); + ui->proxyPort->setValue(prefs.proxy_port); + ui->proxyAuthRequired->setChecked(prefs.proxy_auth); + ui->proxyUsername->setText(prefs.proxy_user); + ui->proxyPassword->setText(prefs.proxy_pass); + ui->proxyType->setCurrentIndex(ui->proxyType->findData(prefs.proxy_type)); + ui->cloud_storage_email->setText(prefs.cloud_storage_email); + ui->cloud_storage_password->setText(prefs.cloud_storage_password); + ui->save_password_local->setChecked(prefs.save_password_local); + ui->cloud_background_sync->setChecked(prefs.cloud_background_sync); + ui->save_uid_local->setChecked(prefs.save_userid_local); + ui->default_uid->setText(s.value("subsurface_webservice_uid").toString().toUpper()); + + cloudPinNeeded(); +} + +void PreferencesNetwork::syncSettings() +{ + QSettings s; + s.setValue("subsurface_webservice_uid", ui->default_uid->text().toUpper()); + set_save_userid_local(ui->save_uid_local->checkState()); + + s.beginGroup("Network"); + s.setValue("proxy_type", ui->proxyType->itemData(ui->proxyType->currentIndex()).toInt()); + s.setValue("proxy_host", ui->proxyHost->text()); + s.setValue("proxy_port", ui->proxyPort->value()); + SB("proxy_auth", ui->proxyAuthRequired); + s.setValue("proxy_user", ui->proxyUsername->text()); + s.setValue("proxy_pass", ui->proxyPassword->text()); + s.endGroup(); + + s.beginGroup("CloudStorage"); + QString email = ui->cloud_storage_email->text(); + QString password = ui->cloud_storage_password->text(); + QString newpassword = ui->cloud_storage_new_passwd->text(); + if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { + // deal with password change + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + connect(cloudAuth, SIGNAL(passwordChangeSuccessful()), this, SLOT(passwordUpdateSuccessfull())); + QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); + ui->cloud_storage_new_passwd->setText(""); + free(prefs.cloud_storage_newpassword); + prefs.cloud_storage_newpassword = strdup(qPrintable(newpassword)); + } + } + } else if (prefs.cloud_verification_status == CS_UNKNOWN || + prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || + email != prefs.cloud_storage_email || + password != prefs.cloud_storage_password) { + + // different credentials - reset verification status + prefs.cloud_verification_status = CS_UNKNOWN; + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password); + } + } + } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { + QString pin = ui->cloud_storage_pin->text(); + if (!pin.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password, pin); + } + } + SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); + SAVE_OR_REMOVE("save_password_local", default_prefs.save_password_local, ui->save_password_local->isChecked()); + if (ui->save_password_local->isChecked()) { + SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); + } else { + s.remove("password"); + free(prefs.cloud_storage_password); + prefs.cloud_storage_password = strdup(qPrintable(password)); + } + SAVE_OR_REMOVE("cloud_verification_status", default_prefs.cloud_verification_status, prefs.cloud_verification_status); + SAVE_OR_REMOVE("cloud_background_sync", default_prefs.cloud_background_sync, ui->cloud_background_sync->isChecked()); + + // at this point we intentionally do not have a UI for changing this + // it could go into some sort of "advanced setup" or something + SAVE_OR_REMOVE("cloud_base_url", default_prefs.cloud_base_url, prefs.cloud_base_url); + s.endGroup(); +} + +void PreferencesNetwork::cloudPinNeeded() +{ + ui->cloud_storage_pin->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin_label->setEnabled(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_pin_label->setVisible(prefs.cloud_verification_status == CS_NEED_TO_VERIFY); + ui->cloud_storage_new_passwd->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd_label->setEnabled(prefs.cloud_verification_status == CS_VERIFIED); + ui->cloud_storage_new_passwd_label->setVisible(prefs.cloud_verification_status == CS_VERIFIED); + if (prefs.cloud_verification_status == CS_VERIFIED) { + ui->cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage (credentials verified)")); + } else { + ui->cloudStorageGroupBox->setTitle(tr("Subsurface cloud storage")); + } + //TODO: Do not call mainWindow here. Verify things on SettingsChanged. + //MainWindow::instance()->enableDisableCloudActions(); +} + +void PreferencesNetwork::proxyType_changed(int idx) +{ + if (idx == -1) { + return; + } + + int proxyType = ui->proxyType->itemData(idx).toInt(); + bool hpEnabled = (proxyType == QNetworkProxy::Socks5Proxy || proxyType == QNetworkProxy::HttpProxy); + ui->proxyHost->setEnabled(hpEnabled); + ui->proxyPort->setEnabled(hpEnabled); + ui->proxyAuthRequired->setEnabled(hpEnabled); + ui->proxyUsername->setEnabled(hpEnabled & ui->proxyAuthRequired->isChecked()); + ui->proxyPassword->setEnabled(hpEnabled & ui->proxyAuthRequired->isChecked()); + ui->proxyAuthRequired->setChecked(ui->proxyAuthRequired->isChecked()); +} + +void PreferencesNetwork::passwordUpdateSuccessfull() +{ + ui->cloud_storage_password->setText(prefs.cloud_storage_password); +} \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.h b/desktop-widgets/preferences/preferences_network.h new file mode 100644 index 000000000..8f35adeb0 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.h @@ -0,0 +1,26 @@ +#ifndef PREFERENCES_NETWORK_H +#define PREFERENCES_NETWORK_H + +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesNetwork; +} + +class PreferencesNetwork : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesNetwork(); + virtual ~PreferencesNetwork(); + virtual void refreshSettings(); + virtual void syncSettings(); + +private: + Ui::PreferencesNetwork *ui; + + void cloudPinNeeded(); + void proxyType_changed(int i); + void passwordUpdateSuccessfull(); +}; + +#endif \ No newline at end of file diff --git a/desktop-widgets/preferences/preferences_network.ui b/desktop-widgets/preferences/preferences_network.ui new file mode 100644 index 000000000..8bb9bf9a0 --- /dev/null +++ b/desktop-widgets/preferences/preferences_network.ui @@ -0,0 +1,293 @@ + + + PreferencesNetwork + + + + 0 + 0 + 713 + 558 + + + + Form + + + + + + Proxy + + + + + + + 0 + 0 + + + + Port + + + + + + + Host + + + + + + + Proxy type + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Username + + + + + + + + 1 + 0 + + + + 65535 + + + 80 + + + + + + + + 2 + 0 + + + + 64 + + + + + + + + + + Qt::LeftToRight + + + Requires authentication + + + + + + + + 0 + 0 + + + + 32 + + + + + + + Password + + + + + + + + 0 + 0 + + + + 32 + + + QLineEdit::Password + + + + + + + + + + + 0 + 0 + + + + + 0 + 129 + + + + Subsurface cloud storage + + + + + + + + + Email address + + + + + + + Password + + + + + + + Verification PIN + + + + + + + New password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + + + + + + + + QLineEdit::Password + + + + + + + Sync to cloud in the background? + + + + + + + Save Password locally? + + + + + + + + + + Subsurface web service + + + + 5 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Default user ID + + + + + + + + + + Save user ID locally? + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index db1d30113..bf751bff7 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -6,6 +6,7 @@ #include "preferences_defaults.h" #include "preferences_units.h" #include "preferences_graph.h" +#include "preferences_network.h" #include #include @@ -41,6 +42,7 @@ PreferencesDialogV2::PreferencesDialogV2() addPreferencePage(new PreferencesDefaults()); addPreferencePage(new PreferencesUnits()); addPreferencePage(new PreferencesGraph()); + addPreferencePage(new PreferencesNetwork()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2 From 8a54a46779bac174cb9216d1c8aa76a3bfc1bc84 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 2 Oct 2015 11:09:13 -0300 Subject: Preferences: random fixes Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- .../preferences/preferences_defaults.cpp | 12 -------- desktop-widgets/preferences/preferences_defaults.h | 2 -- desktop-widgets/preferences/preferences_graph.cpp | 1 - desktop-widgets/preferences/preferences_units.cpp | 34 +++++++++++----------- desktop-widgets/preferences/preferencesdialog.cpp | 5 ++++ desktop-widgets/preferences/preferencesdialog.h | 2 ++ 6 files changed, 24 insertions(+), 32 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index 637117105..45888ebec 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -25,7 +25,6 @@ void PreferencesDefaults::on_chooseFile_clicked() ui->defaultfilename->setText(choosenFileName); } - void PreferencesDefaults::on_btnUseDefaultFile_toggled(bool toggle) { if (toggle) { @@ -36,22 +35,11 @@ void PreferencesDefaults::on_btnUseDefaultFile_toggled(bool toggle) } } -void PreferencesDefaults::on_noDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = NO_DEFAULT_FILE; -} - void PreferencesDefaults::on_localDefaultFile_toggled(bool toggle) { ui->defaultfilename->setEnabled(toggle); ui->btnUseDefaultFile->setEnabled(toggle); ui->chooseFile->setEnabled(toggle); - prefs.default_file_behavior = LOCAL_DEFAULT_FILE; -} - -void PreferencesDefaults::on_cloudDefaultFile_toggled(bool toggle) -{ - prefs.default_file_behavior = CLOUD_DEFAULT_FILE; } void PreferencesDefaults::refreshSettings() diff --git a/desktop-widgets/preferences/preferences_defaults.h b/desktop-widgets/preferences/preferences_defaults.h index 94de8b28a..c72be31a6 100644 --- a/desktop-widgets/preferences/preferences_defaults.h +++ b/desktop-widgets/preferences/preferences_defaults.h @@ -18,9 +18,7 @@ public: public slots: void on_chooseFile_clicked(); void on_btnUseDefaultFile_toggled(bool toggled); - void on_noDefaultFile_toggled(bool toggled); void on_localDefaultFile_toggled(bool toggled); - void on_cloudDefaultFile_toggled(bool toggled); private: Ui::PreferencesDefaults *ui; diff --git a/desktop-widgets/preferences/preferences_graph.cpp b/desktop-widgets/preferences/preferences_graph.cpp index f671076f4..327557692 100644 --- a/desktop-widgets/preferences/preferences_graph.cpp +++ b/desktop-widgets/preferences/preferences_graph.cpp @@ -49,7 +49,6 @@ void PreferencesGraph::syncSettings() s.setValue("pscr_ratio", rint(1000.0 / ui->pscrfactor->value())); s.endGroup(); - // Graph s.beginGroup("TecDetails"); SAVE_OR_REMOVE("phethreshold", default_prefs.pp_graphs.phe_threshold, ui->pheThreshold->value()); SAVE_OR_REMOVE("po2threshold", default_prefs.pp_graphs.po2_threshold, ui->po2Threshold->value()); diff --git a/desktop-widgets/preferences/preferences_units.cpp b/desktop-widgets/preferences/preferences_units.cpp index 76f2078d7..cc77e51bb 100644 --- a/desktop-widgets/preferences/preferences_units.cpp +++ b/desktop-widgets/preferences/preferences_units.cpp @@ -16,23 +16,6 @@ PreferencesUnits::~PreferencesUnits() } void PreferencesUnits::refreshSettings() -{ - QSettings s; - s.beginGroup("Units"); - QString unitSystem[] = {"metric", "imperial", "personal"}; - short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE); - SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); - 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); - s.setValue("vertical_speed_time", ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); - s.setValue("coordinates", ui->gpsTraditional->isChecked()); - s.endGroup(); -} - -void PreferencesUnits::syncSettings() { switch(prefs.unit_system) { case METRIC: ui->metric->setChecked(true); break; @@ -58,3 +41,20 @@ void PreferencesUnits::syncSettings() ui->vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui->vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); } + +void PreferencesUnits::syncSettings() +{ + QSettings s; + s.beginGroup("Units"); + QString unitSystem[] = {"metric", "imperial", "personal"}; + short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE); + SAVE_OR_REMOVE_SPECIAL("unit_system", default_prefs.unit_system, unitValue, unitSystem[unitValue]); + 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); + s.setValue("vertical_speed_time", ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); + s.setValue("coordinates", ui->gpsTraditional->isChecked()); + s.endGroup(); +} diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index bf751bff7..5b4cc560e 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -100,6 +100,8 @@ void PreferencesDialogV2::applyRequested() Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->syncSettings(); } + emit settingsChanged(); + accept(); } void PreferencesDialogV2::cancelRequested() @@ -107,6 +109,7 @@ void PreferencesDialogV2::cancelRequested() Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->refreshSettings(); } + reject(); } void PreferencesDialogV2::defaultsRequested() @@ -115,4 +118,6 @@ void PreferencesDialogV2::defaultsRequested() Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->refreshSettings(); } + emit settingsChanged(); + accept(); } diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h index dcc97bf94..720b94c25 100644 --- a/desktop-widgets/preferences/preferencesdialog.h +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -17,6 +17,8 @@ public: virtual ~PreferencesDialogV2(); void addPreferencePage(AbstractPreferencesWidget *page); void refreshPages(); +signals: + void settingsChanged(); private: void cancelRequested(); void applyRequested(); -- cgit v1.2.3-70-g09d2 From c1b2907071432f6a313605950fa95c8eff000a55 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 9 Oct 2015 18:11:18 -0300 Subject: Fix warnings Also, disable Facebook temporarely since I'm removing the preferences widget in a few commits. Facebook will have to change to use a new way of connection that I'm still creating. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/mainwindow.ui | 1 - desktop-widgets/preferences.cpp | 3 +++ desktop-widgets/preferences/preferences_network.h | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/mainwindow.ui b/desktop-widgets/mainwindow.ui index 5e3200cfc..c62e1df7f 100644 --- a/desktop-widgets/mainwindow.ui +++ b/desktop-widgets/mainwindow.ui @@ -142,7 +142,6 @@ Share on - diff --git a/desktop-widgets/preferences.cpp b/desktop-widgets/preferences.cpp index 2ec9ee96d..29e9d2458 100644 --- a/desktop-widgets/preferences.cpp +++ b/desktop-widgets/preferences.cpp @@ -142,6 +142,8 @@ void PreferencesDialog::buttonClicked(QAbstractButton *button) } #undef SB +#if 0 +// TODO: Copy this later. void PreferencesDialog::on_resetSettings_clicked() { QSettings s; @@ -163,6 +165,7 @@ void PreferencesDialog::on_resetSettings_clicked() close(); } } +#endif void PreferencesDialog::emitSettingsChanged() { diff --git a/desktop-widgets/preferences/preferences_network.h b/desktop-widgets/preferences/preferences_network.h index 8f35adeb0..3e17d51b0 100644 --- a/desktop-widgets/preferences/preferences_network.h +++ b/desktop-widgets/preferences/preferences_network.h @@ -9,17 +9,19 @@ namespace Ui { class PreferencesNetwork : public AbstractPreferencesWidget { Q_OBJECT + public: PreferencesNetwork(); virtual ~PreferencesNetwork(); virtual void refreshSettings(); virtual void syncSettings(); +public slots: + void proxyType_changed(int i); + private: Ui::PreferencesNetwork *ui; - void cloudPinNeeded(); - void proxyType_changed(int i); void passwordUpdateSuccessfull(); }; -- cgit v1.2.3-70-g09d2 From 9eed778c68f72862b27695bee8b4dd1ba553bdc2 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 30 Oct 2015 13:14:06 -0700 Subject: Preferences: switch language preference to be a dropdown The list widget takes too much space and isn't really any better. The dropdown plus fliter is actually rather neat. Also added back the connections so the dropdown and filter get disabled when system default is selected (just as it was in the old preferences dialog). Signed-off-by: Dirk Hohndel --- .../preferences/preferences_language.cpp | 14 +++-- desktop-widgets/preferences/prefs_language.ui | 65 +++++++++++++++++----- 2 files changed, 60 insertions(+), 19 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp index 07b60c3a3..ec4eed471 100644 --- a/desktop-widgets/preferences/preferences_language.cpp +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -16,7 +16,7 @@ PreferencesLanguage::PreferencesLanguage() : AbstractPreferencesWidget(tr("Langu QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(); filterModel->setSourceModel(LanguageModel::instance()); filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - ui->languageView->setModel(filterModel); + ui->languageDropdown->setModel(filterModel); filterModel->sort(0); connect(ui->languageFilter, &QLineEdit::textChanged, filterModel, &QSortFilterProxyModel::setFilterFixedString); @@ -32,10 +32,10 @@ void PreferencesLanguage::refreshSettings() QSettings s; s.beginGroup("Language"); ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); - QAbstractItemModel *m = ui->languageView->model(); + QAbstractItemModel *m = ui->languageDropdown->model(); QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); if (languages.count()) - ui->languageView->setCurrentIndex(languages.first()); + ui->languageDropdown->setCurrentIndex(languages.first().row()); s.endGroup(); } @@ -44,12 +44,14 @@ void PreferencesLanguage::syncSettings() QSettings s; s.beginGroup("Language"); bool useSystemLang = s.value("UseSystemLanguage", true).toBool(); + QAbstractItemModel *m = ui->languageDropdown->model(); + QString currentText = m->data(m->index(ui->languageDropdown->currentIndex(),0), Qt::UserRole).toString(); if (useSystemLang != ui->languageSystemDefault->isChecked() || - (!useSystemLang && s.value("UiLanguage").toString() != ui->languageView->currentIndex().data(Qt::UserRole))) { + (!useSystemLang && s.value("UiLanguage").toString() != currentText)) { QMessageBox::warning(this, tr("Restart required"), tr("To correctly load a new language you must restart Subsurface.")); } s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked()); - s.setValue("UiLanguage", ui->languageView->currentIndex().data(Qt::UserRole)); + s.setValue("UiLanguage", currentText); s.endGroup(); -} \ No newline at end of file +} diff --git a/desktop-widgets/preferences/prefs_language.ui b/desktop-widgets/preferences/prefs_language.ui index 80671fca8..650d543f6 100644 --- a/desktop-widgets/preferences/prefs_language.ui +++ b/desktop-widgets/preferences/prefs_language.ui @@ -6,7 +6,7 @@ 0 0 - 576 + 621 523 @@ -17,7 +17,7 @@ - + 0 0 @@ -33,6 +33,9 @@ + + + @@ -59,18 +62,54 @@ - - - - - 0 - 0 - - - - + + + + Qt::Vertical + + + + 20 + 20 + + + + - + + + languageSystemDefault + toggled(bool) + languageDropdown + setDisabled(bool) + + + 73 + 273 + + + 179 + 273 + + + + + languageSystemDefault + toggled(bool) + languageFilter + setDisabled(bool) + + + 73 + 273 + + + 539 + 273 + + + + -- cgit v1.2.3-70-g09d2 From 222ce62bceac4c7f95e7a0564f11b5789dc18d29 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 30 Oct 2015 13:26:05 -0700 Subject: Preferences: add date and time format to language page Not hooked up, yet. Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/prefs_language.ui | 153 +++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 4 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/prefs_language.ui b/desktop-widgets/preferences/prefs_language.ui index 650d543f6..af3a0ad87 100644 --- a/desktop-widgets/preferences/prefs_language.ui +++ b/desktop-widgets/preferences/prefs_language.ui @@ -29,7 +29,7 @@ - System default + Use system default @@ -62,19 +62,116 @@ + + + + + 0 + 0 + + + + Date format + + + + + + <html><head/><body><p>Preferred date format. Commonly used fields are</p><p>d (day of month)</p><p>ddd (abbr. day name)</p><p>M (month number)</p><p>MMM (abbr. month name)</p><p>yy/yyyy (2/4 digit year)</p></body></html> + + + + + + + Use UI language default + + + + + + + + + + This is used in places where there is less space to show the full date + + + Short format + + + + + + + Qt::Horizontal + + + + 203 + 20 + + + + + + + + + + + + 0 + 0 + + + + Time format + + - + + + Use UI language default + + + + + + + <html><head/><body><p>Preferred time format</p><p>Commonly used format specifiers are</p><p>h (hours in 12h format)</p><p>H (hours in 24h format)</p><p>mm (2 digit minutes)</p><p>ss (2 digit seconds)</p><p>t/tt (a/p or am/pm)</p></body></html> + + + + + - Qt::Vertical + Qt::Horizontal - 20 + 203 20 + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + @@ -111,5 +208,53 @@ + + dateFormatSystemDefault + toggled(bool) + dateFormatEntry + setDisabled(bool) + + + 79 + 132 + + + 264 + 132 + + + + + timeFormatSystemDefault + toggled(bool) + timeFormatEntry + setDisabled(bool) + + + 79 + 210 + + + 264 + 210 + + + + + dateFormatSystemDefault + toggled(bool) + shortDateFormatEntry + setDisabled(bool) + + + 99 + 132 + + + 293 + 169 + + + -- cgit v1.2.3-70-g09d2 From 8a3fb854c2b835271cc03ea02e1046f2ec0fd5d5 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 2 Nov 2015 11:32:46 -0800 Subject: Preferences: hook up the UI page with the preferences structure With this the new date and time formats mostly work Signed-off-by: Dirk Hohndel --- .../preferences/preferences_language.cpp | 15 +++++- subsurface-core/qthelper.cpp | 53 ++++++++++++++-------- 2 files changed, 48 insertions(+), 20 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp index ec4eed471..1b5ee19a8 100644 --- a/desktop-widgets/preferences/preferences_language.cpp +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -32,6 +32,11 @@ void PreferencesLanguage::refreshSettings() QSettings s; s.beginGroup("Language"); ui->languageSystemDefault->setChecked(s.value("UseSystemLanguage", true).toBool()); + ui->timeFormatSystemDefault->setChecked(!s.value("time_format_override", false).toBool()); + ui->dateFormatSystemDefault->setChecked(!s.value("date_format_override", false).toBool()); + ui->timeFormatEntry->setText(s.value("time_format").toString()); + ui->dateFormatEntry->setText(s.value("date_format").toString()); + ui->shortDateFormatEntry->setText(s.value("date_format_short").toString()); QAbstractItemModel *m = ui->languageDropdown->model(); QModelIndexList languages = m->match(m->index(0, 0), Qt::UserRole, s.value("UiLanguage").toString()); if (languages.count()) @@ -51,7 +56,15 @@ void PreferencesLanguage::syncSettings() QMessageBox::warning(this, tr("Restart required"), tr("To correctly load a new language you must restart Subsurface.")); } - s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked()); s.setValue("UiLanguage", currentText); + s.setValue("UseSystemLanguage", ui->languageSystemDefault->isChecked()); + s.setValue("time_format_override", !ui->timeFormatSystemDefault->isChecked()); + s.setValue("date_format_override", !ui->dateFormatSystemDefault->isChecked()); + if (!ui->timeFormatSystemDefault->isChecked()) + s.setValue("time_format", ui->timeFormatEntry->text()); + if (!ui->dateFormatSystemDefault->isChecked()) { + s.setValue("date_format", ui->dateFormatEntry->text()); + s.setValue("date_format_short", ui->shortDateFormatEntry->text()); + } s.endGroup(); } diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index a91e1aae2..40c507a7e 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -722,6 +722,7 @@ QString uiLanguage(QLocale *callerLoc) QString dateFormat; QString timeFormat; QSettings s; + QVariant v; s.beginGroup("Language"); if (!s.value("UseSystemLanguage", true).toBool()) { @@ -731,6 +732,11 @@ QString uiLanguage(QLocale *callerLoc) } QString uiLang = loc.uiLanguages().first(); + GET_BOOL("time_format_override", time_format_override); + GET_BOOL("date_format_override", date_format_override); + GET_TXT("time_format", time_format); + GET_TXT("date_format", date_format); + GET_TXT("date_format_short", date_format_short); s.endGroup(); // there's a stupid Qt bug on MacOS where uiLanguages doesn't give us the country info @@ -742,24 +748,33 @@ QString uiLanguage(QLocale *callerLoc) if (callerLoc) *callerLoc = loc; - // the short format is fine - // the long format uses long weekday and month names, so replace those with the short ones - // for time we don't want the time zone designator and don't want leading zeroes on the hours - shortDateFormat = loc.dateFormat(QLocale::ShortFormat); - dateFormat = loc.dateFormat(QLocale::LongFormat); - dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM"); - // special hack for Swedish as our switching from long weekday names to short weekday names - // messes things up there - dateFormat.replace("'en' 'den' d:'e'", " d"); - timeFormat = loc.timeFormat(); - timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); - timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); - free((void*)prefs.time_format); - prefs.time_format = strdup(qPrintable(timeFormat)); - free((void*)prefs.date_format); - prefs.date_format = strdup(qPrintable(dateFormat)); - free((void*)prefs.date_format_short); - prefs.date_format_short = strdup(qPrintable(shortDateFormat)); + if (!prefs.date_format_override || same_string(prefs.date_format_short, "") || same_string(prefs.date_format, "")) { + // derive our standard date format from what the locale gives us + // the short format is fine + // the long format uses long weekday and month names, so replace those with the short ones + // for time we don't want the time zone designator and don't want leading zeroes on the hours + shortDateFormat = loc.dateFormat(QLocale::ShortFormat); + dateFormat = loc.dateFormat(QLocale::LongFormat); + dateFormat.replace("dddd,", "ddd").replace("dddd", "ddd").replace("MMMM", "MMM"); + // special hack for Swedish as our switching from long weekday names to short weekday names + // messes things up there + dateFormat.replace("'en' 'den' d:'e'", " d"); + if (!prefs.date_format_override || same_string(prefs.date_format, "")) { + free((void*)prefs.date_format); + prefs.date_format = strdup(qPrintable(dateFormat)); + } + if (!prefs.date_format_override || same_string(prefs.date_format_short, "")) { + free((void*)prefs.date_format_short); + prefs.date_format_short = strdup(qPrintable(shortDateFormat)); + } + } + if (!prefs.time_format_override || same_string(prefs.time_format, "")) { + timeFormat = loc.timeFormat(); + timeFormat.replace("(t)", "").replace(" t", "").replace("t", "").replace("hh", "h").replace("HH", "H").replace("'kl'.", ""); + timeFormat.replace(".ss", "").replace(":ss", "").replace("ss", ""); + free((void*)prefs.time_format); + prefs.time_format = strdup(qPrintable(timeFormat)); + } return uiLang; } @@ -1078,7 +1093,7 @@ QString get_trip_date_string(timestamp_t when, int nr, bool getday) QString suffix = " " + QObject::tr("(%n dive(s))", "", nr); if (getday) { - ret = localTime.date().toString(dateFormat) + suffix; + ret = localTime.date().toString(prefs.date_format) + suffix; } else { ret = localTime.date().toString("MMM yy") + suffix; } -- cgit v1.2.3-70-g09d2 From ff57881265a305fe06691b065bc3f0efae88e6b3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 31 Oct 2015 21:02:16 -0200 Subject: Preferences: Remove the old dialog and use the new one The new preferences dialog still needs a bit of fine tuning but should already work. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/CMakeLists.txt | 1 - desktop-widgets/mainwindow.cpp | 4 +- desktop-widgets/preferences.h | 43 ---------------------- .../preferences/preferences_network.cpp | 1 - desktop-widgets/preferences/preferencesdialog.cpp | 29 ++++++++++----- desktop-widgets/preferences/preferencesdialog.h | 8 ++-- profile-widget/divecartesianaxis.cpp | 2 +- profile-widget/divepixmapitem.cpp | 2 +- profile-widget/diveprofileitem.cpp | 2 +- profile-widget/profilewidget2.cpp | 2 +- profile-widget/ruleritem.cpp | 2 +- 11 files changed, 31 insertions(+), 65 deletions(-) delete mode 100644 desktop-widgets/preferences.h (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt index 62be916cc..0a0059ee3 100644 --- a/desktop-widgets/CMakeLists.txt +++ b/desktop-widgets/CMakeLists.txt @@ -30,7 +30,6 @@ set(SUBSURFACE_INTERFACE mainwindow.cpp modeldelegates.cpp notificationwidget.cpp - preferences.cpp simplewidgets.cpp starwidget.cpp subsurfacewebservices.cpp diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 23b4fb9b0..dc45d1d8d 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -15,7 +15,6 @@ #include "version.h" #include "divelistview.h" #include "downloadfromdivecomputer.h" -#include "preferences.h" #include "subsurfacewebservices.h" #include "divecomputermanagementdialog.h" #include "about.h" @@ -278,8 +277,6 @@ MainWindow::MainWindow() : QMainWindow(), ui.menubar->show(); set_git_update_cb(&updateProgress); - PreferencesDialogV2 *d = new PreferencesDialogV2(); - d->show(); } MainWindow::~MainWindow() @@ -1785,6 +1782,7 @@ void MainWindow::editCurrentDive() } } +// TODO: Remove the dependency to the PreferencesDialog here. #define PREF_PROFILE(QT_PREFS) \ QSettings s; \ s.beginGroup("TecDetails"); \ diff --git a/desktop-widgets/preferences.h b/desktop-widgets/preferences.h deleted file mode 100644 index 4b619dde4..000000000 --- a/desktop-widgets/preferences.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef PREFERENCES_H -#define PREFERENCES_H - -#include -#include "pref.h" - -#include "ui_preferences.h" - -#ifndef Q_OS_ANDROID - class QWebView; -#endif - -class QAbstractButton; - -class PreferencesDialog : public QDialog { - Q_OBJECT -public: - static PreferencesDialog *instance(); - void showEvent(QShowEvent *); - void emitSettingsChanged(); - -signals: - void settingsChanged(); -public -slots: - void buttonClicked(QAbstractButton *button); - void syncSettings(); - void loadSettings(); - void restorePrefs(); - void rememberPrefs(); - void facebookLoggedIn(); - void facebookDisconnect(); -private: - explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - void setUiFromPrefs(); - Ui::PreferencesDialog ui; - struct preferences oldPrefs; - #ifndef Q_OS_ANDROID - QWebView *facebookWebView; - #endif -}; - -#endif // PREFERENCES_H diff --git a/desktop-widgets/preferences/preferences_network.cpp b/desktop-widgets/preferences/preferences_network.cpp index 000df1e7f..3780a6c91 100644 --- a/desktop-widgets/preferences/preferences_network.cpp +++ b/desktop-widgets/preferences/preferences_network.cpp @@ -1,6 +1,5 @@ #include "preferences_network.h" #include "ui_preferences_network.h" -#include "preferences.h" #include "dive.h" #include "subsurfacewebservices.h" #include "subsurface-core/prefs-macros.h" diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 5b4cc560e..d59296519 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -16,7 +16,18 @@ #include #include -PreferencesDialogV2::PreferencesDialogV2() +PreferencesDialog* PreferencesDialog::instance() +{ + PreferencesDialog *self = new PreferencesDialog(); + return self; +} + +void PreferencesDialog::emitSettingsChanged() +{ + emit settingsChanged(); +} + +PreferencesDialog::PreferencesDialog() { pagesList = new QListWidget(); pagesStack = new QStackedWidget(); @@ -48,14 +59,14 @@ PreferencesDialogV2::PreferencesDialogV2() connect(pagesList, &QListWidget::currentRowChanged, pagesStack, &QStackedWidget::setCurrentIndex); connect(buttonBox, &QDialogButtonBox::clicked, - this, &PreferencesDialogV2::buttonClicked); + this, &PreferencesDialog::buttonClicked); } -PreferencesDialogV2::~PreferencesDialogV2() +PreferencesDialog::~PreferencesDialog() { } -void PreferencesDialogV2::buttonClicked(QAbstractButton* btn) +void PreferencesDialog::buttonClicked(QAbstractButton* btn) { QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn); switch(role) { @@ -70,13 +81,13 @@ bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractP return p1->positionHeight() <= p2->positionHeight(); } -void PreferencesDialogV2::addPreferencePage(AbstractPreferencesWidget *page) +void PreferencesDialog::addPreferencePage(AbstractPreferencesWidget *page) { pages.push_back(page); qSort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan); } -void PreferencesDialogV2::refreshPages() +void PreferencesDialog::refreshPages() { // Remove things pagesList->clear(); @@ -95,7 +106,7 @@ void PreferencesDialogV2::refreshPages() } } -void PreferencesDialogV2::applyRequested() +void PreferencesDialog::applyRequested() { Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->syncSettings(); @@ -104,7 +115,7 @@ void PreferencesDialogV2::applyRequested() accept(); } -void PreferencesDialogV2::cancelRequested() +void PreferencesDialog::cancelRequested() { Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->refreshSettings(); @@ -112,7 +123,7 @@ void PreferencesDialogV2::cancelRequested() reject(); } -void PreferencesDialogV2::defaultsRequested() +void PreferencesDialog::defaultsRequested() { prefs = default_prefs; Q_FOREACH(AbstractPreferencesWidget *page, pages) { diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h index 720b94c25..611bd5fac 100644 --- a/desktop-widgets/preferences/preferencesdialog.h +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -10,16 +10,18 @@ class QStackedWidget; class QDialogButtonBox; class QAbstractButton; -class PreferencesDialogV2 : public QDialog { +class PreferencesDialog : public QDialog { Q_OBJECT public: - PreferencesDialogV2(); - virtual ~PreferencesDialogV2(); + static PreferencesDialog* instance(); + virtual ~PreferencesDialog(); void addPreferencePage(AbstractPreferencesWidget *page); void refreshPages(); + void emitSettingsChanged(); signals: void settingsChanged(); private: + PreferencesDialog(); void cancelRequested(); void applyRequested(); void defaultsRequested(); diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index bf5a5380c..f40e1c3e5 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -1,7 +1,7 @@ #include "divecartesianaxis.h" #include "divetextitem.h" #include "helpers.h" -#include "preferences.h" +#include "preferences/preferencesdialog.h" #include "diveplotdatamodel.h" #include "animationfunctions.h" #include "mainwindow.h" diff --git a/profile-widget/divepixmapitem.cpp b/profile-widget/divepixmapitem.cpp index 581f6f9b4..627473c2f 100644 --- a/profile-widget/divepixmapitem.cpp +++ b/profile-widget/divepixmapitem.cpp @@ -1,7 +1,7 @@ #include "divepixmapitem.h" #include "animationfunctions.h" #include "divepicturemodel.h" -#include +#include "preferences/preferencesdialog.h" #include #include diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 7cdccee32..14efa9123 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -5,7 +5,7 @@ #include "animationfunctions.h" #include "dive.h" #include "profile.h" -#include "preferences.h" +#include "preferences/preferencesdialog.h" #include "diveplannermodel.h" #include "helpers.h" #include "libdivecomputer/parser.h" diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 3ccd1bb6d..8ff8e8669 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -29,7 +29,7 @@ #include #endif #include "mainwindow.h" -#include +#include "preferences/preferencesdialog.h" /* This is the global 'Item position' variable. * it should tell you where to position things up diff --git a/profile-widget/ruleritem.cpp b/profile-widget/ruleritem.cpp index 830985552..a5a61c0fe 100644 --- a/profile-widget/ruleritem.cpp +++ b/profile-widget/ruleritem.cpp @@ -1,5 +1,5 @@ #include "ruleritem.h" -#include "preferences.h" +#include "preferences/preferencesdialog.h" #include "mainwindow.h" #include "profilewidget2.h" #include "display.h" -- cgit v1.2.3-70-g09d2 From bf12c3533c73054066c4a1223bdb0a533778d44c Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 31 Oct 2015 21:26:52 -0200 Subject: Preferences: Use apply instead of reset to defaults Change the Reset to Defaults button to Apply in the preferences dialog. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferencesdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index d59296519..0af7a78bd 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -33,7 +33,7 @@ PreferencesDialog::PreferencesDialog() pagesStack = new QStackedWidget(); buttonBox = new QDialogButtonBox( QDialogButtonBox::Save | - QDialogButtonBox::RestoreDefaults | + QDialogButtonBox::Apply | QDialogButtonBox::Cancel); pagesList->setMinimumWidth(120); -- cgit v1.2.3-70-g09d2 From a48e6241dc86c722032f7cd15bcffb565d5dbb4f Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 31 Oct 2015 21:54:59 -0200 Subject: Forgot to set the static variable static Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferencesdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 0af7a78bd..9041668f8 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -18,7 +18,7 @@ PreferencesDialog* PreferencesDialog::instance() { - PreferencesDialog *self = new PreferencesDialog(); + static PreferencesDialog *self = new PreferencesDialog(); return self; } -- cgit v1.2.3-70-g09d2 From 9f93b9a934e23be05322ff47a0c6a8fa3b8b3adb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 1 Nov 2015 12:14:40 -0200 Subject: Preferences: Call LoadPreferences from whitin the new dialog When I removed the old preferences dialog, I forgot to load them again. The code is in the wrong place: it should be on every and each preferences dialog (or on the main preferences) Beware if you used this wip code before, I may have destroyed your preferences. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferencesdialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 9041668f8..a7934a96d 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -8,6 +8,8 @@ #include "preferences_graph.h" #include "preferences_network.h" +#include "subsurface-core/qthelper.h" + #include #include #include @@ -29,6 +31,8 @@ void PreferencesDialog::emitSettingsChanged() PreferencesDialog::PreferencesDialog() { + loadPreferences(); //TODO: Move this code out of the qthelper.cpp + pagesList = new QListWidget(); pagesStack = new QStackedWidget(); buttonBox = new QDialogButtonBox( -- cgit v1.2.3-70-g09d2 From df7818a9b8495285b4d9812e5d6d50d6f9c08813 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 2 Nov 2015 12:50:17 -0800 Subject: Preferences: make apply work We didn't respond at all to that button. Also, the language settings didn't propagate without this explicit call. Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferences_language.cpp | 2 ++ desktop-widgets/preferences/preferencesdialog.cpp | 12 +++++++----- desktop-widgets/preferences/preferencesdialog.h | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_language.cpp b/desktop-widgets/preferences/preferences_language.cpp index 1b5ee19a8..31bbd1c20 100644 --- a/desktop-widgets/preferences/preferences_language.cpp +++ b/desktop-widgets/preferences/preferences_language.cpp @@ -1,5 +1,6 @@ #include "preferences_language.h" #include "ui_prefs_language.h" +#include "subsurface-core/helpers.h" #include #include @@ -67,4 +68,5 @@ void PreferencesLanguage::syncSettings() s.setValue("date_format_short", ui->shortDateFormatEntry->text()); } s.endGroup(); + uiLanguage(NULL); } diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index a7934a96d..d8798879a 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -74,9 +74,10 @@ void PreferencesDialog::buttonClicked(QAbstractButton* btn) { QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn); switch(role) { - case QDialogButtonBox::AcceptRole : applyRequested(); return; - case QDialogButtonBox::RejectRole : cancelRequested(); return; - case QDialogButtonBox::ResetRole : defaultsRequested(); return; + case QDialogButtonBox::ApplyRole : applyRequested(false); return; + case QDialogButtonBox::AcceptRole : applyRequested(true); return; + case QDialogButtonBox::RejectRole : cancelRequested(); return; + case QDialogButtonBox::ResetRole : defaultsRequested(); return; } } @@ -110,13 +111,14 @@ void PreferencesDialog::refreshPages() } } -void PreferencesDialog::applyRequested() +void PreferencesDialog::applyRequested(bool closeIt) { Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->syncSettings(); } emit settingsChanged(); - accept(); + if (closeIt) + accept(); } void PreferencesDialog::cancelRequested() diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h index 611bd5fac..5f7f5f979 100644 --- a/desktop-widgets/preferences/preferencesdialog.h +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -23,7 +23,7 @@ signals: private: PreferencesDialog(); void cancelRequested(); - void applyRequested(); + void applyRequested(bool closeIt); void defaultsRequested(); void buttonClicked(QAbstractButton *btn); QList pages; @@ -32,4 +32,4 @@ private: QDialogButtonBox *buttonBox; }; -#endif \ No newline at end of file +#endif -- cgit v1.2.3-70-g09d2