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-08 13:44:14 +00:00
|
|
|
#include "preferences_dc.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"
|
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>
|
|
|
|
#include <QDebug>
|
2015-09-17 20:16:40 +00:00
|
|
|
|
2015-10-31 23:02:16 +00:00
|
|
|
PreferencesDialog* PreferencesDialog::instance()
|
|
|
|
{
|
2015-10-31 23:54:59 +00:00
|
|
|
static PreferencesDialog *self = new PreferencesDialog();
|
2015-10-31 23:02:16 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreferencesDialog::PreferencesDialog()
|
2015-09-17 20:16:40 +00:00
|
|
|
{
|
2018-08-29 10:08:47 +00:00
|
|
|
//FIXME: This looks wrong.
|
|
|
|
//QSettings s;
|
|
|
|
//s.beginGroup("GeneralSettings");
|
|
|
|
//s.setValue("default_directory", system_default_directory());
|
|
|
|
//s.endGroup();
|
|
|
|
|
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
|
|
|
|
2015-09-17 20:16:40 +00:00
|
|
|
addPreferencePage(new PreferencesLanguage());
|
2015-09-17 22:22:19 +00:00
|
|
|
addPreferencePage(new PreferencesGeoreference());
|
2015-09-25 19:15:37 +00:00
|
|
|
addPreferencePage(new PreferencesDefaults());
|
2015-09-25 20:07:04 +00:00
|
|
|
addPreferencePage(new PreferencesUnits());
|
2015-10-01 21:59:53 +00:00
|
|
|
addPreferencePage(new PreferencesGraph());
|
2015-10-01 22:48:57 +00:00
|
|
|
addPreferencePage(new PreferencesNetwork());
|
2019-12-06 13:53:14 +00:00
|
|
|
addPreferencePage(new PreferencesCloud());
|
2019-12-07 18:27:25 +00:00
|
|
|
addPreferencePage(new PreferencesEquipment());
|
2019-12-08 09:30:16 +00:00
|
|
|
addPreferencePage(new PreferencesMedia());
|
2019-12-08 13:44:14 +00:00
|
|
|
addPreferencePage(new PreferencesDc());
|
2019-12-09 18:58:20 +00:00
|
|
|
addPreferencePage(new PreferencesLog());
|
2019-12-10 13:02:13 +00:00
|
|
|
addPreferencePage(new PreferencesReset());
|
2019-12-08 09:30:16 +00:00
|
|
|
|
2015-09-17 20:16:40 +00:00
|
|
|
refreshPages();
|
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-09-17 20:16:40 +00:00
|
|
|
bool abstractpreferenceswidget_lessthan(AbstractPreferencesWidget *p1, AbstractPreferencesWidget *p2)
|
|
|
|
{
|
2017-12-29 18:29:23 +00:00
|
|
|
return p1->positionHeight() < p2->positionHeight();
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 23:02:16 +00:00
|
|
|
void PreferencesDialog::addPreferencePage(AbstractPreferencesWidget *page)
|
2015-09-17 20:16:40 +00:00
|
|
|
{
|
|
|
|
pages.push_back(page);
|
2019-04-03 18:21:53 +00:00
|
|
|
std::sort(pages.begin(), pages.end(), abstractpreferenceswidget_lessthan);
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 23:02:16 +00:00
|
|
|
void PreferencesDialog::refreshPages()
|
2015-09-17 20:16:40 +00:00
|
|
|
{
|
|
|
|
// Remove things
|
|
|
|
pagesList->clear();
|
|
|
|
while(pagesStack->count()) {
|
|
|
|
QWidget *curr = pagesStack->widget(0);
|
|
|
|
pagesStack->removeWidget(curr);
|
|
|
|
curr->setParent(0);
|
|
|
|
}
|
|
|
|
|
2017-11-25 08:22:19 +00:00
|
|
|
// Read things
|
2015-09-17 20:16:40 +00:00
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(page->icon(), page->name());
|
|
|
|
pagesList->addItem(item);
|
|
|
|
pagesStack->addWidget(page);
|
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
|
|
|
{
|
2015-09-17 20:57:41 +00:00
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
2015-11-10 21:45:13 +00:00
|
|
|
connect(page, &AbstractPreferencesWidget::settingsChanged, this, &PreferencesDialog::settingsChanged, Qt::UniqueConnection);
|
2015-09-17 20:57:41 +00:00
|
|
|
page->syncSettings();
|
|
|
|
}
|
2015-10-02 14:09:13 +00:00
|
|
|
emit 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
|
|
|
{
|
2015-09-17 20:57:41 +00:00
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
|
|
|
page->refreshSettings();
|
|
|
|
}
|
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
|
|
|
{
|
2017-11-25 08:22:19 +00:00
|
|
|
copy_prefs(&default_prefs, &prefs);
|
2015-09-17 20:57:41 +00:00
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
|
|
|
page->refreshSettings();
|
|
|
|
}
|
2015-10-02 14:09:13 +00:00
|
|
|
emit settingsChanged();
|
|
|
|
accept();
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|