1 // Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2011 Dzmitry KAMIAHIN (dnk-88) <dnk-88@tut.by>
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 // Copyright (C) 2014-2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "../core/settings_dialog.h"
23 #include "ioptions_page.h"
26 #include <QtGui/QHeaderView>
27 #include <QtGui/QPushButton>
36 Q_DECLARE_METATYPE(PageData
);
40 SettingsDialog::SettingsDialog(ExtensionSystem::IPluginManager
*pluginManager
,
41 const QString
&categoryId
,
42 const QString
&pageId
,
49 m_plugMan
= pluginManager
;
51 QString initialCategory
= categoryId
;
52 QString initialPage
= pageId
;
54 m_ui
.buttonBox
->button(QDialogButtonBox::Ok
)->setDefault(true);
56 connect(m_ui
.buttonBox
->button(QDialogButtonBox::Apply
), SIGNAL(clicked()), this, SLOT(apply()));
58 m_ui
.splitter
->setCollapsible(1, false);
59 m_ui
.pageTree
->header()->setVisible(false);
61 connect(m_ui
.pageTree
, SIGNAL(currentItemChanged(QTreeWidgetItem
*, QTreeWidgetItem
*)),
62 this, SLOT(pageSelected()));
64 QMap
<QString
, QTreeWidgetItem
*> categories
;
66 QList
<IOptionsPage
*> pages
= m_plugMan
->getObjects
<IOptionsPage
>();
69 Q_FOREACH(IOptionsPage
*page
, pages
)
72 pageData
.index
= index
;
73 pageData
.category
= page
->category();
74 pageData
.id
= page
->id();
76 QTreeWidgetItem
*item
= new QTreeWidgetItem
;
77 item
->setText(0, page
->trName());
78 item
->setData(0, Qt::UserRole
, qVariantFromValue(pageData
));
80 QStringList categoriesId
= page
->category().split(QLatin1Char('|'));
81 QStringList trCategories
= page
->trCategory().split(QLatin1Char('|'));
82 QString currentCategory
= categoriesId
.at(0);
84 QTreeWidgetItem
*treeitem
;
85 if (!categories
.contains(currentCategory
))
87 treeitem
= new QTreeWidgetItem(m_ui
.pageTree
);
88 treeitem
->setText(0, trCategories
.at(0));
89 treeitem
->setData(0, Qt::UserRole
, qVariantFromValue(pageData
));
90 categories
.insert(currentCategory
, treeitem
);
94 while (catCount
< categoriesId
.count())
96 if (!categories
.contains(currentCategory
+ QLatin1Char('|') + categoriesId
.at(catCount
)))
98 treeitem
= new QTreeWidgetItem(categories
.value(currentCategory
));
99 currentCategory
+= QLatin1Char('|') + categoriesId
.at(catCount
);
100 treeitem
->setText(0, trCategories
.at(catCount
));
101 treeitem
->setData(0, Qt::UserRole
, qVariantFromValue(pageData
));
102 categories
.insert(currentCategory
, treeitem
);
106 currentCategory
+= QLatin1Char('|') + categoriesId
.at(catCount
);
111 categories
.value(currentCategory
)->addChild(item
);
113 m_pages
.append(page
);
114 m_ui
.stackedPages
->addWidget(page
->createPage(m_ui
.stackedPages
));
116 if (page
->id() == initialPage
&& currentCategory
== initialCategory
)
118 m_ui
.stackedPages
->setCurrentIndex(m_ui
.stackedPages
->count());
119 m_ui
.pageTree
->setCurrentItem(item
);
127 m_ui
.splitter
->setSizes(sizes
);
129 m_ui
.splitter
->setStretchFactor(m_ui
.splitter
->indexOf(m_ui
.pageTree
), 0);
130 m_ui
.splitter
->setStretchFactor(m_ui
.splitter
->indexOf(m_ui
.layoutWidget
), 1);
133 SettingsDialog::~SettingsDialog()
137 void SettingsDialog::pageSelected()
139 QTreeWidgetItem
*item
= m_ui
.pageTree
->currentItem();
140 PageData data
= item
->data(0, Qt::UserRole
).value
<PageData
>();
141 int index
= data
.index
;
142 m_currentCategory
= data
.category
;
143 m_currentPage
= data
.id
;
144 m_ui
.stackedPages
->setCurrentIndex(index
);
147 void SettingsDialog::accept()
151 setCursor( Qt::WaitCursor
);
153 Q_FOREACH(IOptionsPage
*page
, m_pages
)
159 setCursor( Qt::ArrowCursor
);
161 done(QDialog::Accepted
);
164 void SettingsDialog::reject()
166 Q_FOREACH(IOptionsPage
*page
, m_pages
)
168 done(QDialog::Rejected
);
171 void SettingsDialog::apply()
173 setCursor( Qt::WaitCursor
);
175 Q_FOREACH(IOptionsPage
*page
, m_pages
)
178 setCursor( Qt::ArrowCursor
);
183 bool SettingsDialog::execDialog()
190 void SettingsDialog::done(int val
)
195 } /* namespace Core */