2015-09-17 20:16:40 +00:00
|
|
|
#include "preferencesdialog.h"
|
|
|
|
|
|
|
|
#include "abstractpreferenceswidget.h"
|
|
|
|
#include "preferences_language.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
PreferencesDialogV2::PreferencesDialogV2()
|
|
|
|
{
|
|
|
|
pagesList = new QListWidget();
|
|
|
|
pagesStack = new QStackedWidget();
|
2015-09-17 20:53:39 +00:00
|
|
|
buttonBox = new QDialogButtonBox(
|
|
|
|
QDialogButtonBox::Save |
|
|
|
|
QDialogButtonBox::RestoreDefaults |
|
|
|
|
QDialogButtonBox::Cancel);
|
2015-09-17 20:16:40 +00:00
|
|
|
|
|
|
|
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);
|
2015-09-17 20:53:39 +00:00
|
|
|
|
2015-09-17 20:16:40 +00:00
|
|
|
addPreferencePage(new PreferencesLanguage());
|
|
|
|
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,
|
|
|
|
this, &PreferencesDialogV2::buttonClicked);
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PreferencesDialogV2::~PreferencesDialogV2()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-17 20:53:39 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 20:16:40 +00:00
|
|
|
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);
|
2015-09-17 21:10:32 +00:00
|
|
|
page->refreshSettings();
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialogV2::applyRequested()
|
|
|
|
{
|
2015-09-17 20:57:41 +00:00
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
|
|
|
page->syncSettings();
|
|
|
|
}
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialogV2::cancelRequested()
|
|
|
|
{
|
2015-09-17 20:57:41 +00:00
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
|
|
|
page->refreshSettings();
|
|
|
|
}
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreferencesDialogV2::defaultsRequested()
|
|
|
|
{
|
2015-09-17 20:57:41 +00:00
|
|
|
prefs = default_prefs;
|
|
|
|
Q_FOREACH(AbstractPreferencesWidget *page, pages) {
|
|
|
|
page->refreshSettings();
|
|
|
|
}
|
2015-09-17 20:16:40 +00:00
|
|
|
}
|