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