Update DBus Notify method annotation name
[lxde/liblxqt.git] / configdialog / lxqtconfigdialog.cpp
CommitLineData
a36cb19b
AM
1/* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
b9223fe7 4 * LXQt - a lightweight, Qt based, desktop toolset
a36cb19b
AM
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
b6483430
AS
25#include "lxqtconfigdialog.h"
26#include "ui_lxqtconfigdialog.h"
a36cb19b 27
e6389bfc
HJYP
28#include <XdgIcon>
29#include <QPushButton>
a36cb19b 30
f05ba5af 31using namespace LXQt;
ad7ee7e8 32
82830dc2 33ConfigDialog::ConfigDialog(const QString& title, Settings* settings, QWidget* parent) :
a36cb19b 34 QDialog(parent),
a36cb19b 35 mSettings(settings),
82830dc2 36 mCache(new SettingsCache(settings)),
552e1c4a 37 ui(new Ui::ConfigDialog)
a36cb19b
AM
38{
39 ui->setupUi(this);
40 setWindowTitle(title);
41 connect(ui->buttons, SIGNAL(clicked(QAbstractButton*)), SLOT(dialogButtonsAction(QAbstractButton*)));
42 ui->moduleList->setVisible(false);
6841f67c
AM
43 foreach(QPushButton* button, ui->buttons->findChildren<QPushButton*>())
44 button->setAutoDefault(false);
a36cb19b
AM
45}
46
552e1c4a 47void ConfigDialog::setButtons(QDialogButtonBox::StandardButtons buttons)
ae45471f
L
48{
49 ui->buttons->setStandardButtons(buttons);
50 foreach(QPushButton* button, ui->buttons->findChildren<QPushButton*>())
51 button->setAutoDefault(false);
52}
53
ad7ee7e8 54void ConfigDialog::addPage(QWidget* page, const QString& name, const QString& iconName)
a36cb19b 55{
edcb7d1a
AM
56 addPage(page, name, QStringList() << iconName);
57}
58
ad7ee7e8 59void ConfigDialog::addPage(QWidget* page, const QString& name, const QStringList& iconNames)
edcb7d1a 60{
c30ce71e
LP
61 Q_ASSERT(page);
62 if (!page)
63 {
64 return;
65 }
66
fb57b43b
LP
67 /* We set the layout margin to 0. In the default configuration, one page
68 * only, it aligns buttons with the page. In multi-page it saves a little
69 * bit of space, without clutter.
70 */
71 if (page->layout())
72 {
73 page->layout()->setMargin(0);
74 }
75
edcb7d1a
AM
76 QStringList icons = QStringList(iconNames) << "application-x-executable";
77 new QListWidgetItem(XdgIcon::fromTheme(icons), name, ui->moduleList);
ad0420f9 78 mIcons.append(icons);
a36cb19b 79 ui->stackedWidget->addWidget(page);
ca9b082d
AM
80 if(ui->stackedWidget->count() > 1)
81 {
82 ui->moduleList->setVisible(true);
83 ui->moduleList->setCurrentRow(0);
98dd8833
PL
84 mMaxSize = QSize(qMax(page->geometry().width() + ui->moduleList->geometry().width(),
85 mMaxSize.width()),
86 qMax(page->geometry().height() + ui->buttons->geometry().height(),
87 mMaxSize.height()));
ca9b082d
AM
88 }
89 else
90 {
91 mMaxSize = page->geometry().size();
92 }
93 resize(mMaxSize);
a36cb19b
AM
94}
95
98dd8833
PL
96void ConfigDialog::showPage(QWidget* page)
97{
98 int index = ui->stackedWidget->indexOf(page);
99 if (index < 0)
100 return;
101
102 ui->stackedWidget->setCurrentIndex(index);
103 ui->moduleList->setCurrentRow(index);
104}
105
38964268
PK
106bool ConfigDialog::event(QEvent * event)
107{
108 if (QEvent::ThemeChange == event->type())
109 updateIcons();
110 return QDialog::event(event);
111}
112
ad7ee7e8 113void ConfigDialog::closeEvent(QCloseEvent* event)
a36cb19b 114{
a36cb19b 115 emit save();
4cf2dc5e 116 mSettings->sync();
a36cb19b
AM
117}
118
ad7ee7e8 119void ConfigDialog::dialogButtonsAction(QAbstractButton* button)
a36cb19b 120{
ae45471f
L
121 QDialogButtonBox::StandardButton standardButton = ui->buttons->standardButton(button);
122 emit clicked(standardButton);
123 if (standardButton == QDialogButtonBox::Reset)
a36cb19b
AM
124 {
125 mCache->loadToSettings();
126 emit reset();
127 }
ae45471f 128 else if(standardButton == QDialogButtonBox::Close)
a36cb19b
AM
129 {
130 close();
131 }
132}
133
ad7ee7e8 134void ConfigDialog::updateIcons()
ad0420f9
AM
135{
136 for (int ix = 0; ix < mIcons.size(); ix++)
137 ui->moduleList->item(ix)->setIcon(XdgIcon::fromTheme(mIcons.at(ix)));
138 update();
139}
140
ad7ee7e8 141ConfigDialog::~ConfigDialog()
a36cb19b
AM
142{
143 delete ui;
144 delete mCache;
145}