2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
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
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
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>
|
2009-03-19 18:14:54 +01:00
|
|
|
#include "icore.h"
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <utils/filterlineedit.h>
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
#include <QtCore/QSettings>
|
2009-11-19 17:47:13 +01:00
|
|
|
#include <QtGui/QSortFilterProxyModel>
|
|
|
|
|
#include <QtGui/QItemSelectionModel>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QHBoxLayout>
|
2009-11-19 17:47:13 +01:00
|
|
|
#include <QtGui/QIcon>
|
2009-11-24 15:05:02 +01:00
|
|
|
#include <QtGui/QLabel>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QPushButton>
|
|
|
|
|
#include <QtGui/QToolButton>
|
|
|
|
|
#include <QtGui/QToolBar>
|
2010-03-26 17:34:10 +01:00
|
|
|
#include <QtGui/QScrollBar>
|
2009-11-24 15:05:02 +01:00
|
|
|
#include <QtGui/QSpacerItem>
|
|
|
|
|
#include <QtGui/QStyle>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QStackedLayout>
|
|
|
|
|
#include <QtGui/QGridLayout>
|
|
|
|
|
#include <QtGui/QLineEdit>
|
|
|
|
|
#include <QtGui/QFrame>
|
|
|
|
|
#include <QtGui/QDialogButtonBox>
|
2010-03-26 14:31:40 +01:00
|
|
|
#include <QtGui/QListView>
|
2009-11-27 13:54:27 +01:00
|
|
|
#include <QtGui/QApplication>
|
2010-03-26 17:34:10 +01:00
|
|
|
#include <QtGui/QGroupBox>
|
2009-11-19 17:47:13 +01:00
|
|
|
|
|
|
|
|
static const char categoryKeyC[] = "General/LastPreferenceCategory";
|
|
|
|
|
static const char pageKeyC[] = "General/LastPreferencePage";
|
2010-03-26 17:34:10 +01:00
|
|
|
const int categoryIconSize = 32;
|
2009-11-19 17:47:13 +01:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
// ----------- Category model
|
|
|
|
|
|
2010-03-30 13:48:33 +02:00
|
|
|
class Category {
|
|
|
|
|
public:
|
2010-03-26 14:31:40 +01:00
|
|
|
QString id;
|
|
|
|
|
QString displayName;
|
2010-03-26 17:34:10 +01:00
|
|
|
QIcon icon;
|
2010-03-26 14:31:40 +01:00
|
|
|
QList<IOptionsPage*> pages;
|
|
|
|
|
int index;
|
|
|
|
|
QTabWidget *tabWidget;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CategoryModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CategoryModel(QObject *parent = 0);
|
|
|
|
|
~CategoryModel();
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
|
|
|
|
|
|
void setPages(const QList<IOptionsPage*> &pages);
|
|
|
|
|
const QList<Category*> &categories() const { return m_categories; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Category *findCategoryById(const QString &id);
|
|
|
|
|
|
|
|
|
|
QList<Category*> m_categories;
|
2010-03-26 17:34:10 +01:00
|
|
|
QIcon m_emptyIcon;
|
2010-03-26 14:31:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CategoryModel::CategoryModel(QObject *parent)
|
|
|
|
|
: QAbstractListModel(parent)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 17:34:10 +01:00
|
|
|
QPixmap empty(categoryIconSize, categoryIconSize);
|
|
|
|
|
empty.fill(Qt::transparent);
|
|
|
|
|
m_emptyIcon = QIcon(empty);
|
2009-03-19 18:14:54 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
CategoryModel::~CategoryModel()
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
qDeleteAll(m_categories);
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
int CategoryModel::rowCount(const QModelIndex &parent) const
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
return parent.isValid() ? 0 : m_categories.size();
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
QVariant CategoryModel::data(const QModelIndex &index, int role) const
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
switch (role) {
|
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
|
return m_categories.at(index.row())->displayName;
|
2010-03-26 17:34:10 +01:00
|
|
|
case Qt::DecorationRole: {
|
|
|
|
|
QIcon icon = m_categories.at(index.row())->icon;
|
|
|
|
|
if (icon.isNull())
|
|
|
|
|
icon = m_emptyIcon;
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
2010-03-26 14:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
void CategoryModel::setPages(const QList<IOptionsPage*> &pages)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
// Clear any previous categories
|
|
|
|
|
qDeleteAll(m_categories);
|
|
|
|
|
m_categories.clear();
|
|
|
|
|
|
|
|
|
|
// Put the pages in categories
|
|
|
|
|
foreach (IOptionsPage *page, pages) {
|
|
|
|
|
const QString &categoryId = page->category();
|
|
|
|
|
Category *category = findCategoryById(categoryId);
|
|
|
|
|
if (!category) {
|
|
|
|
|
category = new Category;
|
|
|
|
|
category->id = categoryId;
|
|
|
|
|
category->displayName = page->displayCategory();
|
2010-03-26 17:34:10 +01:00
|
|
|
category->icon = page->categoryIcon();
|
2010-03-26 14:31:40 +01:00
|
|
|
category->pages.append(page);
|
|
|
|
|
m_categories.append(category);
|
|
|
|
|
} else {
|
|
|
|
|
category->pages.append(page);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reset();
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
Category *CategoryModel::findCategoryById(const QString &id)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
for (int i = 0; i < m_categories.size(); ++i) {
|
|
|
|
|
Category *category = m_categories.at(i);
|
|
|
|
|
if (category->id == id)
|
|
|
|
|
return category;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
2009-03-19 18:14:54 +01:00
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
// ----------- Category filter model
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A filter model that returns true for each category node that has pages that
|
|
|
|
|
* match the search string.
|
|
|
|
|
*/
|
|
|
|
|
class CategoryFilterModel : public QSortFilterProxyModel
|
|
|
|
|
{
|
2009-11-19 17:47:13 +01:00
|
|
|
public:
|
2010-03-26 14:31:40 +01:00
|
|
|
explicit CategoryFilterModel(QObject *parent = 0)
|
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
|
{}
|
|
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
protected:
|
2010-03-26 14:31:40 +01:00
|
|
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
|
2009-11-19 17:47:13 +01:00
|
|
|
};
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
bool CategoryFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
|
|
|
|
// Regular contents check, then check page-filter.
|
2010-03-26 14:31:40 +01:00
|
|
|
if (QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent))
|
2009-11-19 17:47:13 +01:00
|
|
|
return true;
|
2010-03-26 14:31:40 +01:00
|
|
|
|
|
|
|
|
const CategoryModel *cm = static_cast<CategoryModel*>(sourceModel());
|
|
|
|
|
foreach (const IOptionsPage *page, cm->categories().at(sourceRow)->pages) {
|
2009-11-20 12:56:49 +01:00
|
|
|
const QString pattern = filterRegExp().pattern();
|
2010-03-26 14:31:40 +01:00
|
|
|
if (page->displayCategory().contains(pattern, Qt::CaseInsensitive)
|
|
|
|
|
|| page->displayName().contains(pattern, Qt::CaseInsensitive)
|
|
|
|
|
|| page->matches(pattern))
|
|
|
|
|
return true;
|
2009-11-20 12:56:49 +01:00
|
|
|
}
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
return false;
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
// ----------- Category list view
|
2009-12-10 14:01:37 +01:00
|
|
|
|
|
|
|
|
/**
|
2010-03-26 14:31:40 +01:00
|
|
|
* Special version of a QListView that has the width of the first column as
|
2009-12-10 14:01:37 +01:00
|
|
|
* minimum size.
|
|
|
|
|
*/
|
2010-03-26 14:31:40 +01:00
|
|
|
class CategoryListView : public QListView
|
2009-12-10 14:01:37 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2010-03-26 14:31:40 +01:00
|
|
|
CategoryListView(QWidget *parent = 0) : QListView(parent)
|
2009-12-10 14:01:37 +01:00
|
|
|
{
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual QSize sizeHint() const
|
|
|
|
|
{
|
2010-03-26 17:34:10 +01:00
|
|
|
int width = sizeHintForColumn(0) + frameWidth() * 2 + 5;
|
|
|
|
|
if (verticalScrollBar()->isVisible())
|
|
|
|
|
width += verticalScrollBar()->width();
|
|
|
|
|
return QSize(width, 100);
|
2009-12-10 14:01:37 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-11-27 16:12:12 +01:00
|
|
|
// ----------- SettingsDialog
|
|
|
|
|
|
|
|
|
|
// Helpers to sort by category. id
|
|
|
|
|
bool optionsPageLessThan(const IOptionsPage *p1, const IOptionsPage *p2)
|
|
|
|
|
{
|
|
|
|
|
if (const int cc = p1->category().compare(p2->category()))
|
|
|
|
|
return cc < 0;
|
|
|
|
|
return p1->id().compare(p2->id()) < 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QList<Core::IOptionsPage*> sortedOptionsPages()
|
|
|
|
|
{
|
|
|
|
|
QList<Core::IOptionsPage*> rc = ExtensionSystem::PluginManager::instance()->getObjects<IOptionsPage>();
|
|
|
|
|
qStableSort(rc.begin(), rc.end(), optionsPageLessThan);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
|
2009-11-19 17:47:13 +01:00
|
|
|
const QString &pageId) :
|
|
|
|
|
QDialog(parent),
|
2009-11-27 16:12:12 +01:00
|
|
|
m_pages(sortedOptionsPages()),
|
2010-03-26 14:31:40 +01:00
|
|
|
m_proxyModel(new CategoryFilterModel(this)),
|
|
|
|
|
m_model(new CategoryModel(this)),
|
2009-11-27 13:54:27 +01:00
|
|
|
m_applied(false),
|
|
|
|
|
m_stackedLayout(new QStackedLayout),
|
|
|
|
|
m_filterLineEdit(new Utils::FilterLineEdit),
|
2010-03-26 14:31:40 +01:00
|
|
|
m_categoryList(new CategoryListView),
|
2009-11-27 13:54:27 +01:00
|
|
|
m_headerLabel(new QLabel)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-11-27 13:54:27 +01:00
|
|
|
createGui();
|
2009-11-20 16:55:23 +01:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2009-09-17 10:38:53 +02:00
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
setWindowTitle(tr("Preferences"));
|
|
|
|
|
#else
|
|
|
|
|
setWindowTitle(tr("Options"));
|
|
|
|
|
#endif
|
2010-03-26 14:31:40 +01:00
|
|
|
|
|
|
|
|
m_model->setPages(m_pages);
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
QString initialCategory = categoryId;
|
|
|
|
|
QString initialPage = pageId;
|
|
|
|
|
if (initialCategory.isEmpty() && initialPage.isEmpty()) {
|
|
|
|
|
QSettings *settings = ICore::instance()->settings();
|
2009-11-19 17:47:13 +01:00
|
|
|
initialCategory = settings->value(QLatin1String(categoryKeyC), QVariant(QString())).toString();
|
|
|
|
|
initialPage = settings->value(QLatin1String(pageKeyC), QVariant(QString())).toString();
|
2009-03-19 18:14:54 +01:00
|
|
|
}
|
2009-01-05 13:45:30 +01:00
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
int initialCategoryIndex = -1;
|
|
|
|
|
int initialPageIndex = -1;
|
|
|
|
|
|
|
|
|
|
// Create the tab widgets with the pages in each category
|
|
|
|
|
const QList<Category*> &categories = m_model->categories();
|
|
|
|
|
for (int i = 0; i < categories.size(); ++i) {
|
|
|
|
|
Category *category = categories.at(i);
|
|
|
|
|
if (category->id == initialCategory)
|
|
|
|
|
initialCategoryIndex = i;
|
|
|
|
|
|
|
|
|
|
QTabWidget *tabWidget = new QTabWidget;
|
|
|
|
|
for (int j = 0; j < category->pages.size(); ++j) {
|
|
|
|
|
IOptionsPage *page = category->pages.at(j);
|
2010-03-26 17:34:10 +01:00
|
|
|
QWidget *widget = page->createPage(0);
|
|
|
|
|
tabWidget->addTab(widget, page->displayName());
|
2010-03-26 14:31:40 +01:00
|
|
|
if (initialCategoryIndex == i && page->id() == initialPage)
|
|
|
|
|
initialPageIndex = j;
|
2010-03-26 17:34:10 +01:00
|
|
|
|
|
|
|
|
// A hack to remove the borders from all group boxes
|
|
|
|
|
foreach (QGroupBox *groupBox, qFindChildren<QGroupBox*>(widget))
|
|
|
|
|
groupBox->setFlat(true);
|
2010-03-26 14:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(tabWidget, SIGNAL(currentChanged(int)),
|
|
|
|
|
this, SLOT(currentTabChanged(int)));
|
|
|
|
|
|
|
|
|
|
category->tabWidget = tabWidget;
|
|
|
|
|
category->index = m_stackedLayout->addWidget(tabWidget);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
m_proxyModel->setSourceModel(m_model);
|
2010-03-26 14:31:40 +01:00
|
|
|
m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
2010-03-26 17:34:10 +01:00
|
|
|
m_categoryList->setIconSize(QSize(categoryIconSize, categoryIconSize));
|
2010-03-26 14:31:40 +01:00
|
|
|
m_categoryList->setModel(m_proxyModel);
|
|
|
|
|
m_categoryList->setSelectionMode(QAbstractItemView::SingleSelection);
|
2010-03-26 17:34:10 +01:00
|
|
|
m_categoryList->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
2010-03-26 14:31:40 +01:00
|
|
|
|
|
|
|
|
connect(m_categoryList->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
|
|
|
|
|
this, SLOT(currentChanged(QModelIndex)));
|
|
|
|
|
|
|
|
|
|
if (initialCategoryIndex != -1) {
|
|
|
|
|
const QModelIndex modelIndex = m_proxyModel->mapFromSource(m_model->index(initialCategoryIndex));
|
|
|
|
|
m_categoryList->setCurrentIndex(modelIndex);
|
|
|
|
|
if (initialPageIndex != -1)
|
|
|
|
|
categories.at(initialCategoryIndex)->tabWidget->setCurrentIndex(initialPageIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-19 17:47:13 +01:00
|
|
|
// The order of the slot connection matters here, the filter slot
|
|
|
|
|
// opens the matching page after the model has filtered.
|
2009-11-27 13:54:27 +01:00
|
|
|
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)),
|
2009-11-19 17:47:13 +01:00
|
|
|
m_proxyModel, SLOT(setFilterFixedString(QString)));
|
2009-11-27 13:54:27 +01:00
|
|
|
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)), this, SLOT(filter(QString)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::createGui()
|
|
|
|
|
{
|
|
|
|
|
// Header label with large font and a bit of spacing (align with group boxes)
|
|
|
|
|
QFont headerLabelFont = m_headerLabel->font();
|
|
|
|
|
headerLabelFont.setBold(true);
|
|
|
|
|
// Paranoia: Should a font be set in pixels...
|
|
|
|
|
const int pointSize = headerLabelFont.pointSize();
|
|
|
|
|
if (pointSize > 0)
|
|
|
|
|
headerLabelFont.setPointSize(pointSize + 2);
|
|
|
|
|
m_headerLabel->setFont(headerLabelFont);
|
|
|
|
|
|
|
|
|
|
QHBoxLayout *headerHLayout = new QHBoxLayout;
|
2010-03-26 14:31:40 +01:00
|
|
|
const int leftMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin);
|
2009-11-27 13:54:27 +01:00
|
|
|
headerHLayout->addSpacerItem(new QSpacerItem(leftMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored));
|
|
|
|
|
headerHLayout->addWidget(m_headerLabel);
|
|
|
|
|
|
|
|
|
|
m_stackedLayout->setMargin(0);
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
|
|
|
|
QDialogButtonBox::Apply |
|
|
|
|
|
QDialogButtonBox::Cancel);
|
2009-11-27 13:54:27 +01:00
|
|
|
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
|
|
|
|
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
|
|
|
|
|
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
|
|
QGridLayout *mainGridLayout = new QGridLayout;
|
|
|
|
|
mainGridLayout->addWidget(m_filterLineEdit, 0, 0, 1, 1);
|
|
|
|
|
mainGridLayout->addLayout(headerHLayout, 0, 1, 1, 1);
|
2010-03-26 14:31:40 +01:00
|
|
|
mainGridLayout->addWidget(m_categoryList, 1, 0, 1, 1);
|
2009-11-27 13:54:27 +01:00
|
|
|
mainGridLayout->addLayout(m_stackedLayout, 1, 1, 1, 1);
|
2010-03-26 14:31:40 +01:00
|
|
|
mainGridLayout->addWidget(buttonBox, 2, 0, 1, 2);
|
2009-11-27 13:54:27 +01:00
|
|
|
mainGridLayout->setColumnStretch(0, 1);
|
|
|
|
|
mainGridLayout->setColumnStretch(1, 4);
|
|
|
|
|
setLayout(mainGridLayout);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
void SettingsDialog::showCategory(int index)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
Category *category = m_model->categories().at(index);
|
|
|
|
|
|
|
|
|
|
// Update current category and page
|
|
|
|
|
m_currentCategory = category->id;
|
|
|
|
|
const int currentTabIndex = category->tabWidget->currentIndex();
|
|
|
|
|
if (currentTabIndex != -1) {
|
|
|
|
|
IOptionsPage *page = category->pages.at(currentTabIndex);
|
|
|
|
|
m_currentPage = page->id();
|
|
|
|
|
m_visitedPages.insert(page);
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
2010-03-26 14:31:40 +01:00
|
|
|
|
|
|
|
|
m_stackedLayout->setCurrentIndex(category->index);
|
|
|
|
|
m_headerLabel->setText(category->displayName);
|
|
|
|
|
|
|
|
|
|
updateEnabledTabs(category, m_filterLineEdit->text());
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
void SettingsDialog::updateEnabledTabs(Category *category, const QString &searchText)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
for (int i = 0; i < category->pages.size(); ++i) {
|
|
|
|
|
const IOptionsPage *page = category->pages.at(i);
|
|
|
|
|
const bool enabled = searchText.isEmpty()
|
|
|
|
|
|| page->displayName().contains(searchText, Qt::CaseInsensitive)
|
|
|
|
|
|| page->matches(searchText);
|
|
|
|
|
category->tabWidget->setTabEnabled(i, enabled);
|
|
|
|
|
}
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
void SettingsDialog::currentChanged(const QModelIndex ¤t)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
if (current.isValid())
|
|
|
|
|
showCategory(m_proxyModel->mapToSource(current).row());
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
void SettingsDialog::currentTabChanged(int index)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QModelIndex modelIndex = m_proxyModel->mapToSource(m_categoryList->currentIndex());
|
|
|
|
|
if (!modelIndex.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Remember the current tab and mark it as visited
|
|
|
|
|
const Category *category = m_model->categories().at(modelIndex.row());
|
|
|
|
|
IOptionsPage *page = category->pages.at(index);
|
|
|
|
|
m_currentPage = page->id();
|
|
|
|
|
m_visitedPages.insert(page);
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::filter(const QString &text)
|
|
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
// When there is no current index, select the first one when possible
|
|
|
|
|
if (!m_categoryList->currentIndex().isValid() && m_model->rowCount() > 0)
|
|
|
|
|
m_categoryList->setCurrentIndex(m_proxyModel->index(0, 0));
|
|
|
|
|
|
|
|
|
|
const QModelIndex currentIndex = m_proxyModel->mapToSource(m_categoryList->currentIndex());
|
|
|
|
|
if (!currentIndex.isValid())
|
2009-11-19 17:47:13 +01:00
|
|
|
return;
|
2010-03-26 14:31:40 +01:00
|
|
|
|
|
|
|
|
Category *category = m_model->categories().at(currentIndex.row());
|
|
|
|
|
updateEnabledTabs(category, text);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsDialog::accept()
|
|
|
|
|
{
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = true;
|
2009-11-24 15:05:02 +01:00
|
|
|
foreach (IOptionsPage *page, m_visitedPages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->apply();
|
2009-11-24 15:05:02 +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::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()
|
|
|
|
|
{
|
2009-11-24 15:05:02 +01:00
|
|
|
foreach (IOptionsPage *page, m_visitedPages)
|
2009-01-13 15:41:33 +01:00
|
|
|
page->apply();
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SettingsDialog::execDialog()
|
|
|
|
|
{
|
2010-03-26 14:31:40 +01:00
|
|
|
m_categoryList->setFocus();
|
2009-03-18 16:43:01 +01:00
|
|
|
m_applied = false;
|
|
|
|
|
exec();
|
|
|
|
|
return m_applied;
|
2009-01-05 13:45:30 +01:00
|
|
|
}
|
2009-03-19 18:14:54 +01:00
|
|
|
|
|
|
|
|
void SettingsDialog::done(int val)
|
|
|
|
|
{
|
|
|
|
|
QSettings *settings = ICore::instance()->settings();
|
2009-11-19 17:47:13 +01:00
|
|
|
settings->setValue(QLatin1String(categoryKeyC), m_currentCategory);
|
|
|
|
|
settings->setValue(QLatin1String(pageKeyC), m_currentPage);
|
2009-03-19 18:14:54 +01:00
|
|
|
QDialog::done(val);
|
|
|
|
|
}
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2009-12-10 14:01:37 +01:00
|
|
|
/**
|
|
|
|
|
* Override to make sure the settings dialog starts up as small as possible.
|
|
|
|
|
*/
|
|
|
|
|
QSize SettingsDialog::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return minimumSize();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|