Merge branch 'master' of https://github.com/SokoloffA/liblxqt into qt5
[lxde/liblxqt.git] / configdialog / lxqtconfigdialog.cpp
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXDE-Qt - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright (C) 2012 Alec Moskvin <alecm@gmx.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * END_COMMON_COPYRIGHT_HEADER */
24
25 #include "lxqtconfigdialog.h"
26 #include "ui_lxqtconfigdialog.h"
27
28 #include <qtxdg/XdgIcon>
29 #include <QtGui/QPushButton>
30
31 using namespace LxQt;
32
33 ConfigDialog::ConfigDialog(const QString& title, Settings* settings, QWidget* parent) :
34 QDialog(parent),
35 mSettings(settings),
36 mCache(new SettingsCache(settings)),
37 ui(new Ui::ConfigDialog)
38 {
39 ui->setupUi(this);
40 setWindowTitle(title);
41 connect(ui->buttons, SIGNAL(clicked(QAbstractButton*)), SLOT(dialogButtonsAction(QAbstractButton*)));
42 ui->moduleList->setVisible(false);
43 connect(Settings::globalSettings(), SIGNAL(settingsChanged()), this, SLOT(updateIcons()));
44 foreach(QPushButton* button, ui->buttons->findChildren<QPushButton*>())
45 button->setAutoDefault(false);
46 }
47
48 void ConfigDialog::addPage(QWidget* page, const QString& name, const QString& iconName)
49 {
50 addPage(page, name, QStringList() << iconName);
51 }
52
53 void ConfigDialog::addPage(QWidget* page, const QString& name, const QStringList& iconNames)
54 {
55 QStringList icons = QStringList(iconNames) << "application-x-executable";
56 new QListWidgetItem(XdgIcon::fromTheme(icons), name, ui->moduleList);
57 mIcons.append(icons);
58 ui->stackedWidget->addWidget(page);
59 if(ui->stackedWidget->count() > 1)
60 {
61 ui->moduleList->setVisible(true);
62 ui->moduleList->setCurrentRow(0);
63 mMaxSize = QSize(qMax(page->geometry().width() + ui->moduleList->geometry().width(), mMaxSize.width()),
64 qMax(page->geometry().height() + ui->buttons->geometry().height(), mMaxSize.height()));
65 }
66 else
67 {
68 mMaxSize = page->geometry().size();
69 }
70 resize(mMaxSize);
71 }
72
73 void ConfigDialog::closeEvent(QCloseEvent* event)
74 {
75 emit save();
76 mSettings->sync();
77 }
78
79 void ConfigDialog::dialogButtonsAction(QAbstractButton* button)
80 {
81 QDialogButtonBox::ButtonRole role = ui->buttons->buttonRole(button);
82 if (role == QDialogButtonBox::ResetRole)
83 {
84 mCache->loadToSettings();
85 emit reset();
86 }
87 else
88 {
89 close();
90 }
91 }
92
93 void ConfigDialog::updateIcons()
94 {
95 for (int ix = 0; ix < mIcons.size(); ix++)
96 ui->moduleList->item(ix)->setIcon(XdgIcon::fromTheme(mIcons.at(ix)));
97 update();
98 }
99
100 ConfigDialog::~ConfigDialog()
101 {
102 delete ui;
103 delete mCache;
104 }