2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
|
** contact the sales department at qt-sales@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QHeaderView>
|
|
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent, const QString &initialCategory,
|
|
|
|
|
const QString &initialPage)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
{
|
|
|
|
|
setupUi(this);
|
|
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
|
|
2009-01-05 13:45:30 +01:00
|
|
|
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
|
|
|
|
|
2008-12-10 12:33:14 +01:00
|
|
|
splitter->setCollapsible(1, false);
|
2008-12-02 12:01:29 +01:00
|
|
|
pageTree->header()->setVisible(false);
|
|
|
|
|
|
|
|
|
|
connect(pageTree, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)),
|
|
|
|
|
this, SLOT(pageSelected(QTreeWidgetItem *)));
|
|
|
|
|
|
|
|
|
|
QMap<QString, QTreeWidgetItem *> categories;
|
|
|
|
|
|
|
|
|
|
QList<IOptionsPage*> pages =
|
2009-01-20 15:31:33 +01:00
|
|
|
ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int index = 0;
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (IOptionsPage *page, pages) {
|
2008-12-10 12:33:14 +01:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem;
|
2008-12-02 12:01:29 +01:00
|
|
|
item->setText(0, page->name());
|
|
|
|
|
item->setData(0, Qt::UserRole, index);
|
|
|
|
|
|
|
|
|
|
QStringList categoriesId = page->category().split(QLatin1Char('|'));
|
|
|
|
|
QStringList trCategories = page->trCategory().split(QLatin1Char('|'));
|
|
|
|
|
QString currentCategory = categoriesId.at(0);
|
|
|
|
|
|
|
|
|
|
QTreeWidgetItem *treeitem;
|
|
|
|
|
if (!categories.contains(currentCategory)) {
|
|
|
|
|
treeitem = new QTreeWidgetItem(pageTree);
|
|
|
|
|
treeitem->setText(0, trCategories.at(0));
|
|
|
|
|
treeitem->setData(0, Qt::UserRole, index);
|
|
|
|
|
categories.insert(currentCategory, treeitem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int catCount = 1;
|
|
|
|
|
while (catCount < categoriesId.count()) {
|
2008-12-09 11:07:24 +01:00
|
|
|
if (!categories.contains(currentCategory + QLatin1Char('|') + categoriesId.at(catCount))) {
|
2008-12-02 12:01:29 +01:00
|
|
|
treeitem = new QTreeWidgetItem(categories.value(currentCategory));
|
|
|
|
|
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
|
|
|
|
treeitem->setText(0, trCategories.at(catCount));
|
|
|
|
|
treeitem->setData(0, Qt::UserRole, index);
|
|
|
|
|
categories.insert(currentCategory, treeitem);
|
|
|
|
|
} else {
|
|
|
|
|
currentCategory += QLatin1Char('|') + categoriesId.at(catCount);
|
|
|
|
|
}
|
|
|
|
|
++catCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categories.value(currentCategory)->addChild(item);
|
|
|
|
|
|
|
|
|
|
m_pages.append(page);
|
|
|
|
|
stackedPages->addWidget(page->createPage(stackedPages));
|
|
|
|
|
|
|
|
|
|
if (page->name() == initialPage && currentCategory == initialCategory) {
|
|
|
|
|
stackedPages->setCurrentIndex(stackedPages->count());
|
|
|
|
|
pageTree->setCurrentItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> sizes;
|
|
|
|
|
sizes << 150 << 300;
|
|
|
|
|
splitter->setSizes(sizes);
|
|
|
|
|
|
|
|
|
|
splitter->setStretchFactor(splitter->indexOf(pageTree), 0);
|
|
|
|
|
splitter->setStretchFactor(splitter->indexOf(layoutWidget), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::pageSelected(QTreeWidgetItem *)
|
|
|
|
|
{
|
|
|
|
|
QTreeWidgetItem *item = pageTree->currentItem();
|
|
|
|
|
int index = item->data(0, Qt::UserRole).toInt();
|
|
|
|
|
stackedPages->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::accept()
|
|
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
foreach (IOptionsPage *page, m_pages) {
|
|
|
|
|
page->apply();
|
|
|
|
|
page->finish();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
done(QDialog::Accepted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::reject()
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (IOptionsPage *page, m_pages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->finish();
|
2008-12-02 12:01:29 +01:00
|
|
|
done(QDialog::Rejected);
|
|
|
|
|
}
|
2009-01-05 13:45:30 +01:00
|
|
|
|
|
|
|
|
void SettingsDialog::apply()
|
|
|
|
|
{
|
|
|
|
|
foreach (IOptionsPage *page, m_pages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->apply();
|
2009-01-05 13:45:30 +01:00
|
|
|
}
|