2017-04-27 20:26:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-09-17 17:16:40 -03:00
|
|
|
#include "preferencesdialog.h"
|
|
|
|
|
|
|
|
#include "abstractpreferenceswidget.h"
|
|
|
|
#include "preferences_language.h"
|
2015-09-17 19:22:19 -03:00
|
|
|
#include "preferences_georeference.h"
|
2015-09-25 16:15:37 -03:00
|
|
|
#include "preferences_defaults.h"
|
2015-09-25 17:07:04 -03:00
|
|
|
#include "preferences_units.h"
|
2015-10-01 18:59:53 -03:00
|
|
|
#include "preferences_graph.h"
|
2015-10-01 19:48:57 -03:00
|
|
|
#include "preferences_network.h"
|
2019-12-06 15:53:14 +02:00
|
|
|
#include "preferences_cloud.h"
|
2019-12-07 20:27:25 +02:00
|
|
|
#include "preferences_equipment.h"
|
2019-12-08 11:30:16 +02:00
|
|
|
#include "preferences_media.h"
|
2019-12-08 15:44:14 +02:00
|
|
|
#include "preferences_dc.h"
|
2019-12-09 20:58:20 +02:00
|
|
|
#include "preferences_log.h"
|
2019-12-10 15:02:13 +02:00
|
|
|
#include "preferences_reset.h"
|
2015-09-17 17:16:40 -03:00
|
|
|
|
2016-04-04 22:02:03 -07:00
|
|
|
#include "core/qthelper.h"
|
2020-11-24 12:50:52 +01:00
|
|
|
#include "core/subsurface-qt/divelistnotifier.h"
|
2015-11-01 12:14:40 -02:00
|
|
|
|
2015-09-17 17:16:40 -03:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QListWidget>
|
|
|
|
#include <QStackedWidget>
|
|
|
|
#include <QDialogButtonBox>
|
2015-09-17 17:53:39 -03:00
|
|
|
#include <QAbstractButton>
|
2015-09-17 17:16:40 -03:00
|
|
|
|
2020-11-24 12:50:52 +01:00
|
|
|
PreferencesDialog *PreferencesDialog::instance()
|
2015-10-31 21:02:16 -02:00
|
|
|
{
|
2015-10-31 21:54:59 -02:00
|
|
|
static PreferencesDialog *self = new PreferencesDialog();
|
2015-10-31 21:02:16 -02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-11-24 12:55:59 +01:00
|
|
|
static bool abstractpreferenceswidget_lessthan(const AbstractPreferencesWidget *p1, const AbstractPreferencesWidget *p2)
|
|
|
|
{
|
|
|
|
return p1->positionHeight() < p2->positionHeight();
|
|
|
|
}
|
|
|
|
|
2015-10-31 21:02:16 -02:00
|
|
|
PreferencesDialog::PreferencesDialog()
|
2015-09-17 17:16:40 -03:00
|
|
|
{
|
2018-08-29 03:08:47 -07:00
|
|
|
//FIXME: This looks wrong.
|
|
|
|
//QSettings s;
|
|
|
|
//s.beginGroup("GeneralSettings");
|
|
|
|
//s.setValue("default_directory", system_default_directory());
|
|
|
|
//s.endGroup();
|
|
|
|
|
2017-10-09 00:28:14 +03:00
|
|
|
setWindowIcon(QIcon(":subsurface-icon"));
|
2018-12-31 09:53:21 -08:00
|
|
|
setWindowTitle(tr("Preferences"));
|
2015-09-17 17:16:40 -03:00
|
|
|
pagesList = new QListWidget();
|
|
|
|
pagesStack = new QStackedWidget();
|
2015-09-17 17:53:39 -03:00
|
|
|
buttonBox = new QDialogButtonBox(
|
|
|
|
QDialogButtonBox::Save |
|
2015-10-31 21:26:52 -02:00
|
|
|
QDialogButtonBox::Apply |
|
2015-09-17 17:53:39 -03:00
|
|
|
QDialogButtonBox::Cancel);
|
2015-09-17 17:16:40 -03:00
|
|
|
|
2019-12-10 15:02:13 +02:00
|
|
|
pagesList->setMinimumWidth(140);
|
|
|
|
pagesList->setMaximumWidth(140);
|
2015-09-17 17:16:40 -03:00
|
|
|
|
|
|
|
QHBoxLayout *h = new QHBoxLayout();
|
|
|
|
h->addWidget(pagesList);
|
|
|
|
h->addWidget(pagesStack);
|
|
|
|
QVBoxLayout *v = new QVBoxLayout();
|
|
|
|
v->addLayout(h);
|
|
|
|
v->addWidget(buttonBox);
|
|
|
|
|
|
|
|
setLayout(v);
|
2015-09-17 17:53:39 -03:00
|
|
|
|
2020-11-24 12:55:59 +01:00
|
|
|
pages.push_back(new PreferencesLanguage);
|
|
|
|
pages.push_back(new PreferencesGeoreference);
|
|
|
|
pages.push_back(new PreferencesDefaults);
|
|
|
|
pages.push_back(new PreferencesUnits);
|
|
|
|
pages.push_back(new PreferencesGraph);
|
|
|
|
pages.push_back(new PreferencesNetwork);
|
|
|
|
pages.push_back(new PreferencesCloud);
|
|
|
|
pages.push_back(new PreferencesEquipment);
|
|
|
|
pages.push_back(new PreferencesMedia);
|
|
|
|
pages.push_back(new PreferencesDc);
|
|
|
|
pages.push_back(new PreferencesLog);
|
|
|
|
pages.push_back(new PreferencesReset);
|
|
|
|
std::sort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan);
|
2019-12-08 11:30:16 +02:00
|
|
|
|
2020-11-24 13:54:21 +01:00
|
|
|
for (AbstractPreferencesWidget *page: pages) {
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name());
|
|
|
|
pagesList->addItem(item);
|
|
|
|
pagesStack->addWidget(page);
|
|
|
|
page->refreshSettings();
|
2020-11-24 14:10:53 +01:00
|
|
|
connect(page, &AbstractPreferencesWidget::settingsChanged, &diveListNotifier, &DiveListNotifier::settingsChanged);
|
2020-11-24 13:54:21 +01:00
|
|
|
}
|
2015-09-17 17:53:39 -03:00
|
|
|
|
2015-09-17 17:16:40 -03:00
|
|
|
connect(pagesList, &QListWidget::currentRowChanged,
|
|
|
|
pagesStack, &QStackedWidget::setCurrentIndex);
|
2015-09-17 17:53:39 -03:00
|
|
|
connect(buttonBox, &QDialogButtonBox::clicked,
|
2015-10-31 21:02:16 -02:00
|
|
|
this, &PreferencesDialog::buttonClicked);
|
2015-09-17 17:16:40 -03:00
|
|
|
}
|
|
|
|
|
2015-10-31 21:02:16 -02:00
|
|
|
PreferencesDialog::~PreferencesDialog()
|
2015-09-17 17:16:40 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-31 21:02:16 -02:00
|
|
|
void PreferencesDialog::buttonClicked(QAbstractButton* btn)
|
2015-09-17 17:53:39 -03:00
|
|
|
{
|
|
|
|
QDialogButtonBox::ButtonRole role = buttonBox->buttonRole(btn);
|
|
|
|
switch(role) {
|
2015-11-02 12:50:17 -08:00
|
|
|
case QDialogButtonBox::ApplyRole : applyRequested(false); return;
|
|
|
|
case QDialogButtonBox::AcceptRole : applyRequested(true); return;
|
|
|
|
case QDialogButtonBox::RejectRole : cancelRequested(); return;
|
|
|
|
case QDialogButtonBox::ResetRole : defaultsRequested(); return;
|
2015-11-07 23:17:24 +02:00
|
|
|
default: return;
|
2015-09-17 17:53:39 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-31 21:02:16 -02:00
|
|
|
void PreferencesDialog::refreshPages()
|
2015-09-17 17:16:40 -03:00
|
|
|
{
|
2020-11-24 13:54:21 +01:00
|
|
|
for (AbstractPreferencesWidget *page: pages)
|
2015-09-17 18:10:32 -03:00
|
|
|
page->refreshSettings();
|
2015-09-17 17:16:40 -03:00
|
|
|
}
|
|
|
|
|
2015-11-02 12:50:17 -08:00
|
|
|
void PreferencesDialog::applyRequested(bool closeIt)
|
2015-09-17 17:16:40 -03:00
|
|
|
{
|
2020-11-24 14:10:53 +01:00
|
|
|
for (AbstractPreferencesWidget *page: pages)
|
2015-09-17 17:57:41 -03:00
|
|
|
page->syncSettings();
|
2020-11-24 12:50:52 +01:00
|
|
|
emit diveListNotifier.settingsChanged();
|
2015-11-02 12:50:17 -08:00
|
|
|
if (closeIt)
|
|
|
|
accept();
|
2015-09-17 17:16:40 -03:00
|
|
|
}
|
|
|
|
|
2015-10-31 21:02:16 -02:00
|
|
|
void PreferencesDialog::cancelRequested()
|
2015-09-17 17:16:40 -03:00
|
|
|
{
|
2020-11-24 13:54:21 +01:00
|
|
|
refreshPages();
|
2015-10-02 11:09:13 -03:00
|
|
|
reject();
|
2015-09-17 17:16:40 -03:00
|
|
|
}
|
|
|
|
|
2015-10-31 21:02:16 -02:00
|
|
|
void PreferencesDialog::defaultsRequested()
|
2015-09-17 17:16:40 -03:00
|
|
|
{
|
2017-11-25 09:22:19 +01:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2020-11-24 13:54:21 +01:00
|
|
|
refreshPages();
|
2020-11-24 12:50:52 +01:00
|
|
|
emit diveListNotifier.settingsChanged();
|
2015-10-02 11:09:13 -03:00
|
|
|
accept();
|
2015-09-17 17:16:40 -03:00
|
|
|
}
|