2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02: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
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
|
2013-08-29 16:36:42 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
|
2012-12-29 03:12:33 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2014-02-13 13:54:39 +01:00
|
|
|
#include <utils/fancylineedit.h>
|
2014-06-23 11:54:39 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2012-12-29 03:12:33 +01:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QGridLayout>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QIcon>
|
|
|
|
|
#include <QLabel>
|
2012-12-29 03:12:33 +01:00
|
|
|
#include <QListView>
|
|
|
|
|
#include <QPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QScrollBar>
|
2012-12-29 03:12:33 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QSortFilterProxyModel>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSpacerItem>
|
|
|
|
|
#include <QStackedLayout>
|
2012-12-29 03:12:33 +01:00
|
|
|
#include <QStyle>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStyledItemDelegate>
|
2009-11-19 17:47:13 +01:00
|
|
|
|
|
|
|
|
static const char categoryKeyC[] = "General/LastPreferenceCategory";
|
|
|
|
|
static const char pageKeyC[] = "General/LastPreferencePage";
|
2010-04-21 11:42:33 +02:00
|
|
|
const int categoryIconSize = 24;
|
2009-11-19 17:47:13 +01:00
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-12-29 03:12:33 +01:00
|
|
|
static QPointer<SettingsDialog> m_instance = 0;
|
2010-07-01 17:12:20 +02:00
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
// ----------- Category model
|
|
|
|
|
|
2012-12-29 03:37:27 +01:00
|
|
|
class Category
|
|
|
|
|
{
|
2010-03-30 13:48:33 +02:00
|
|
|
public:
|
2013-12-06 15:55:14 +01:00
|
|
|
Category() : index(-1), providerPagesCreated(false) { }
|
|
|
|
|
|
2012-12-29 03:37:27 +01:00
|
|
|
Id id;
|
2013-02-18 18:47:54 +01:00
|
|
|
int index;
|
2010-03-26 14:31:40 +01:00
|
|
|
QString displayName;
|
2010-03-26 17:34:10 +01:00
|
|
|
QIcon icon;
|
2010-12-02 18:28:16 +01:00
|
|
|
QList<IOptionsPage *> pages;
|
|
|
|
|
QList<IOptionsPageProvider *> providers;
|
2013-12-06 15:55:14 +01:00
|
|
|
bool providerPagesCreated;
|
2010-03-26 14:31:40 +01:00
|
|
|
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;
|
|
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
void setPages(const QList<IOptionsPage*> &pages,
|
|
|
|
|
const QList<IOptionsPageProvider *> &providers);
|
2010-03-26 14:31:40 +01:00
|
|
|
const QList<Category*> &categories() const { return m_categories; }
|
|
|
|
|
|
|
|
|
|
private:
|
2012-12-29 03:37:27 +01:00
|
|
|
Category *findCategoryById(Id id);
|
2010-03-26 14:31:40 +01:00
|
|
|
|
|
|
|
|
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-12-02 18:28:16 +01:00
|
|
|
void CategoryModel::setPages(const QList<IOptionsPage*> &pages,
|
|
|
|
|
const QList<IOptionsPageProvider *> &providers)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2012-09-20 10:31:34 +02:00
|
|
|
beginResetModel();
|
|
|
|
|
|
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) {
|
2012-12-29 03:37:27 +01:00
|
|
|
const Id categoryId = page->category();
|
2010-03-26 14:31:40 +01:00
|
|
|
Category *category = findCategoryById(categoryId);
|
|
|
|
|
if (!category) {
|
|
|
|
|
category = new Category;
|
|
|
|
|
category->id = categoryId;
|
2010-12-02 18:28:16 +01:00
|
|
|
category->tabWidget = 0;
|
|
|
|
|
category->index = -1;
|
|
|
|
|
m_categories.append(category);
|
|
|
|
|
}
|
|
|
|
|
if (category->displayName.isEmpty())
|
2010-03-26 14:31:40 +01:00
|
|
|
category->displayName = page->displayCategory();
|
2010-12-02 18:28:16 +01:00
|
|
|
if (category->icon.isNull())
|
2010-03-26 17:34:10 +01:00
|
|
|
category->icon = page->categoryIcon();
|
2010-12-02 18:28:16 +01:00
|
|
|
category->pages.append(page);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (IOptionsPageProvider *provider, providers) {
|
2012-12-29 03:37:27 +01:00
|
|
|
const Id categoryId = provider->category();
|
2010-12-02 18:28:16 +01:00
|
|
|
Category *category = findCategoryById(categoryId);
|
|
|
|
|
if (!category) {
|
|
|
|
|
category = new Category;
|
|
|
|
|
category->id = categoryId;
|
|
|
|
|
category->tabWidget = 0;
|
|
|
|
|
category->index = -1;
|
2010-03-26 14:31:40 +01:00
|
|
|
m_categories.append(category);
|
|
|
|
|
}
|
2010-12-02 18:28:16 +01:00
|
|
|
if (category->displayName.isEmpty())
|
|
|
|
|
category->displayName = provider->displayCategory();
|
|
|
|
|
if (category->icon.isNull())
|
|
|
|
|
category->icon = provider->categoryIcon();
|
|
|
|
|
category->providers.append(provider);
|
2010-03-26 14:31:40 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 10:31:34 +02:00
|
|
|
endResetModel();
|
2009-11-19 17:47:13 +01:00
|
|
|
}
|
|
|
|
|
|
2012-12-29 03:37:27 +01:00
|
|
|
Category *CategoryModel::findCategoryById(Id 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
|
|
|
|
2013-12-06 15:55:14 +01:00
|
|
|
const QString pattern = filterRegExp().pattern();
|
2010-03-26 14:31:40 +01:00
|
|
|
const CategoryModel *cm = static_cast<CategoryModel*>(sourceModel());
|
2013-12-06 15:55:14 +01:00
|
|
|
const Category *category = cm->categories().at(sourceRow);
|
|
|
|
|
foreach (const IOptionsPage *page, category->pages) {
|
2010-03-26 14:31:40 +01:00
|
|
|
if (page->displayCategory().contains(pattern, Qt::CaseInsensitive)
|
2013-12-06 15:55:14 +01:00
|
|
|
|| page->displayName().contains(pattern, Qt::CaseInsensitive)
|
|
|
|
|
|| page->matches(pattern))
|
2010-03-26 14:31:40 +01:00
|
|
|
return true;
|
2009-11-20 12:56:49 +01:00
|
|
|
}
|
2009-11-19 17:47:13 +01:00
|
|
|
|
2013-12-06 15:55:14 +01:00
|
|
|
if (!category->providerPagesCreated) {
|
|
|
|
|
foreach (const IOptionsPageProvider *provider, category->providers) {
|
|
|
|
|
if (provider->matches(pattern))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-05-18 17:09:19 +02:00
|
|
|
|
|
|
|
|
class CategoryListViewDelegate : public QStyledItemDelegate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CategoryListViewDelegate(QObject *parent) : QStyledItemDelegate(parent) {}
|
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QSize size = QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
|
size.setHeight(qMax(size.height(), 32));
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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);
|
2010-05-18 17:09:19 +02:00
|
|
|
setItemDelegate(new CategoryListViewDelegate(this));
|
2013-06-12 19:12:35 +02:00
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2009-12-10 14:01:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2013-06-12 19:12:35 +02:00
|
|
|
|
|
|
|
|
// QListView installs a event filter on its scrollbars
|
|
|
|
|
virtual bool eventFilter(QObject *obj, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (obj == verticalScrollBar()
|
|
|
|
|
&& (event->type() == QEvent::Show
|
|
|
|
|
|| event->type() == QEvent::Hide))
|
|
|
|
|
updateGeometry();
|
|
|
|
|
return QListView::eventFilter(obj, event);
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
2013-01-18 11:16:53 +01:00
|
|
|
if (p1->category() != p2->category())
|
|
|
|
|
return p1->category().alphabeticallyBefore(p2->category());
|
|
|
|
|
return p1->id().alphabeticallyBefore(p2->id());
|
2009-11-27 16:12:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline QList<Core::IOptionsPage*> sortedOptionsPages()
|
|
|
|
|
{
|
2012-06-18 11:34:15 +02:00
|
|
|
QList<Core::IOptionsPage*> rc = ExtensionSystem::PluginManager::getObjects<IOptionsPage>();
|
2009-11-27 16:12:12 +01:00
|
|
|
qStableSort(rc.begin(), rc.end(), optionsPageLessThan);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-01 17:12:20 +02:00
|
|
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
2009-11-19 17:47:13 +01:00
|
|
|
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_stackedLayout(new QStackedLayout),
|
2014-02-13 13:54:39 +01:00
|
|
|
m_filterLineEdit(new Utils::FancyLineEdit),
|
2010-03-26 14:31:40 +01:00
|
|
|
m_categoryList(new CategoryListView),
|
2010-07-01 17:12:20 +02:00
|
|
|
m_headerLabel(new QLabel),
|
|
|
|
|
m_running(false),
|
2011-05-19 14:08:41 +02:00
|
|
|
m_applied(false),
|
|
|
|
|
m_finished(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-01 17:12:20 +02:00
|
|
|
m_applied = false;
|
2014-02-13 13:54:39 +01:00
|
|
|
m_filterLineEdit->setFiltering(true);
|
2010-07-01 17:12:20 +02:00
|
|
|
|
2009-11-27 13:54:27 +01:00
|
|
|
createGui();
|
2009-11-20 16:55:23 +01:00
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
2012-08-23 15:53:58 +02:00
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
|
setWindowTitle(tr("Preferences"));
|
|
|
|
|
else
|
|
|
|
|
setWindowTitle(tr("Options"));
|
2010-03-26 14:31:40 +01:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
m_model->setPages(m_pages,
|
2012-06-18 11:34:15 +02:00
|
|
|
ExtensionSystem::PluginManager::getObjects<IOptionsPageProvider>());
|
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)));
|
|
|
|
|
|
2010-07-01 17:12:20 +02:00
|
|
|
// The order of the slot connection matters here, the filter slot
|
|
|
|
|
// opens the matching page after the model has filtered.
|
|
|
|
|
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)),
|
|
|
|
|
m_proxyModel, SLOT(setFilterFixedString(QString)));
|
|
|
|
|
connect(m_filterLineEdit, SIGNAL(filterChanged(QString)), this, SLOT(filter(QString)));
|
|
|
|
|
m_categoryList->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-29 03:12:33 +01:00
|
|
|
void SettingsDialog::showPage(Id categoryId, Id pageId)
|
2010-07-01 17:12:20 +02:00
|
|
|
{
|
|
|
|
|
// handle the case of "show last page"
|
2012-12-29 03:37:27 +01:00
|
|
|
Id initialCategory = categoryId;
|
2013-01-16 15:22:58 +01:00
|
|
|
Id initialPage = pageId;
|
|
|
|
|
if (!initialCategory.isValid() && !initialPage.isValid()) {
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2013-01-15 13:28:17 +01:00
|
|
|
initialCategory = Id::fromSetting(settings->value(QLatin1String(categoryKeyC)));
|
2013-01-16 15:22:58 +01:00
|
|
|
initialPage = Id::fromSetting(settings->value(QLatin1String(pageKeyC)));
|
2010-07-01 17:12:20 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-23 11:54:39 +02:00
|
|
|
if (!initialCategory.isValid()) // no category given and no old setting
|
|
|
|
|
return;
|
|
|
|
|
|
2010-07-01 17:12:20 +02:00
|
|
|
int initialCategoryIndex = -1;
|
|
|
|
|
int initialPageIndex = -1;
|
|
|
|
|
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;
|
2014-06-23 11:54:39 +02:00
|
|
|
if (initialPage.isValid()) {
|
|
|
|
|
for (int j = 0; j < category->pages.size(); ++j) {
|
|
|
|
|
IOptionsPage *page = category->pages.at(j);
|
|
|
|
|
if (page->id() == initialPage)
|
|
|
|
|
initialPageIndex = j;
|
|
|
|
|
}
|
2010-07-01 17:12:20 +02:00
|
|
|
}
|
2014-06-23 11:54:39 +02:00
|
|
|
break;
|
2010-07-01 17:12:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-06-23 11:54:39 +02:00
|
|
|
|
|
|
|
|
QTC_ASSERT(initialCategoryIndex != -1,
|
|
|
|
|
qDebug("Unknown category: %s", initialCategory.name().constData()); return);
|
|
|
|
|
QTC_ASSERT(!initialPage.isValid() || initialPageIndex != -1,
|
|
|
|
|
qDebug("Unknown page: %s", initialPage.name().constData()));
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
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-27 13:54:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
2013-11-26 17:48:26 +01:00
|
|
|
m_stackedLayout->addWidget(new QWidget(this)); // no category selected, for example when filtering
|
2009-11-27 13:54:27 +01:00
|
|
|
|
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(1, 4);
|
|
|
|
|
setLayout(mainGridLayout);
|
2011-09-15 19:20:50 +02:00
|
|
|
setMinimumSize(1000, 550);
|
2013-10-23 14:48:32 +02:00
|
|
|
if (Utils::HostOsInfo::isMacHost())
|
|
|
|
|
setMinimumHeight(minimumHeight() * 1.1);
|
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);
|
2010-12-02 18:28:16 +01:00
|
|
|
ensureCategoryWidget(category);
|
2010-03-26 14:31:40 +01:00
|
|
|
// 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-12-02 18:28:16 +01:00
|
|
|
void SettingsDialog::ensureCategoryWidget(Category *category)
|
|
|
|
|
{
|
|
|
|
|
if (category->tabWidget != 0)
|
|
|
|
|
return;
|
2013-12-06 15:55:14 +01:00
|
|
|
if (!category->providerPagesCreated) {
|
|
|
|
|
foreach (const IOptionsPageProvider *provider, category->providers)
|
|
|
|
|
category->pages += provider->pages();
|
|
|
|
|
category->providerPagesCreated = true;
|
2010-12-02 18:28:16 +01:00
|
|
|
}
|
2013-12-06 15:55:14 +01:00
|
|
|
|
2010-12-02 18:28:16 +01:00
|
|
|
qStableSort(category->pages.begin(), category->pages.end(), optionsPageLessThan);
|
|
|
|
|
|
|
|
|
|
QTabWidget *tabWidget = new QTabWidget;
|
|
|
|
|
for (int j = 0; j < category->pages.size(); ++j) {
|
|
|
|
|
IOptionsPage *page = category->pages.at(j);
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *widget = page->widget();
|
2010-12-02 18:28:16 +01:00
|
|
|
tabWidget->addTab(widget, page->displayName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(tabWidget, SIGNAL(currentChanged(int)),
|
|
|
|
|
this, SLOT(currentTabChanged(int)));
|
|
|
|
|
|
|
|
|
|
category->tabWidget = tabWidget;
|
|
|
|
|
category->index = m_stackedLayout->addWidget(tabWidget);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 18:26:09 +01:00
|
|
|
void SettingsDialog::disconnectTabWidgets()
|
|
|
|
|
{
|
|
|
|
|
foreach (Category *category, m_model->categories()) {
|
|
|
|
|
if (category->tabWidget)
|
|
|
|
|
disconnect(category->tabWidget, SIGNAL(currentChanged(int)),
|
|
|
|
|
this, SLOT(currentTabChanged(int)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
void SettingsDialog::updateEnabledTabs(Category *category, const QString &searchText)
|
2009-11-19 17:47:13 +01:00
|
|
|
{
|
2013-11-18 16:09:47 +01:00
|
|
|
int firstEnabledTab = -1;
|
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()
|
2012-12-29 03:37:27 +01:00
|
|
|
|| page->category().toString().contains(searchText, Qt::CaseInsensitive)
|
2010-03-26 14:31:40 +01:00
|
|
|
|| page->displayName().contains(searchText, Qt::CaseInsensitive)
|
|
|
|
|
|| page->matches(searchText);
|
|
|
|
|
category->tabWidget->setTabEnabled(i, enabled);
|
2013-11-18 16:09:47 +01:00
|
|
|
if (enabled && firstEnabledTab < 0)
|
|
|
|
|
firstEnabledTab = i;
|
|
|
|
|
}
|
|
|
|
|
if (!category->tabWidget->isTabEnabled(category->tabWidget->currentIndex())
|
|
|
|
|
&& firstEnabledTab != -1) {
|
|
|
|
|
// QTabWidget is dumb, so this can happen
|
|
|
|
|
category->tabWidget->setCurrentIndex(firstEnabledTab);
|
2010-03-26 14:31:40 +01:00
|
|
|
}
|
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
|
|
|
{
|
2013-11-18 16:09:47 +01:00
|
|
|
if (current.isValid()) {
|
2010-03-26 14:31:40 +01:00
|
|
|
showCategory(m_proxyModel->mapToSource(current).row());
|
2013-11-18 16:09:47 +01:00
|
|
|
} else {
|
|
|
|
|
m_stackedLayout->setCurrentIndex(0);
|
2014-07-23 09:53:06 +02:00
|
|
|
m_headerLabel->clear();
|
2013-11-18 16:09:47 +01:00
|
|
|
}
|
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()
|
|
|
|
|
{
|
2011-05-19 14:08:41 +02:00
|
|
|
if (m_finished)
|
|
|
|
|
return;
|
|
|
|
|
m_finished = true;
|
2011-01-06 18:26:09 +01:00
|
|
|
disconnectTabWidgets();
|
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()
|
|
|
|
|
{
|
2011-05-19 14:08:41 +02:00
|
|
|
if (m_finished)
|
|
|
|
|
return;
|
|
|
|
|
m_finished = true;
|
2011-01-06 18:26:09 +01:00
|
|
|
disconnectTabWidgets();
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 18:14:54 +01:00
|
|
|
void SettingsDialog::done(int val)
|
|
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2013-01-16 15:22:58 +01:00
|
|
|
settings->setValue(QLatin1String(categoryKeyC), m_currentCategory.toSetting());
|
|
|
|
|
settings->setValue(QLatin1String(pageKeyC), m_currentPage.toSetting());
|
2010-07-01 17:12:20 +02:00
|
|
|
|
2012-08-17 09:09:15 +02:00
|
|
|
ICore::saveSettings(); // save all settings
|
|
|
|
|
|
2010-07-01 17:12:20 +02:00
|
|
|
// exit all additional event loops, see comment in execDialog()
|
|
|
|
|
QListIterator<QEventLoop *> it(m_eventLoops);
|
|
|
|
|
it.toBack();
|
|
|
|
|
while (it.hasPrevious()) {
|
|
|
|
|
QEventLoop *loop = it.previous();
|
|
|
|
|
loop->exit();
|
|
|
|
|
}
|
|
|
|
|
|
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-07-01 17:12:20 +02:00
|
|
|
SettingsDialog *SettingsDialog::getSettingsDialog(QWidget *parent,
|
2012-12-29 03:12:33 +01:00
|
|
|
Id initialCategory, Id initialPage)
|
2010-07-01 17:12:20 +02:00
|
|
|
{
|
2012-12-29 03:12:33 +01:00
|
|
|
if (!m_instance)
|
2010-07-01 17:12:20 +02:00
|
|
|
m_instance = new SettingsDialog(parent);
|
|
|
|
|
m_instance->showPage(initialCategory, initialPage);
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SettingsDialog::execDialog()
|
|
|
|
|
{
|
|
|
|
|
if (!m_running) {
|
|
|
|
|
m_running = true;
|
2011-05-19 14:08:41 +02:00
|
|
|
m_finished = false;
|
2010-07-01 17:12:20 +02:00
|
|
|
exec();
|
2010-10-21 14:10:31 +02:00
|
|
|
m_running = false;
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
// make sure that the current "single" instance is deleted
|
|
|
|
|
// we can't delete right away, since we still access the m_applied member
|
|
|
|
|
deleteLater();
|
2010-07-01 17:12:20 +02:00
|
|
|
} else {
|
|
|
|
|
// exec dialog is called while the instance is already running
|
|
|
|
|
// this can happen when a event triggers a code path that wants to
|
|
|
|
|
// show the settings dialog again
|
|
|
|
|
// e.g. when starting the debugger (with non-built debugging helpers),
|
|
|
|
|
// and manually opening the settings dialog, after the debugger hit
|
|
|
|
|
// a break point it will complain about missing helper, and offer the
|
|
|
|
|
// option to open the settings dialog.
|
|
|
|
|
// Keep the UI running by creating another event loop.
|
|
|
|
|
QEventLoop *loop = new QEventLoop(this);
|
|
|
|
|
m_eventLoops.append(loop);
|
|
|
|
|
loop->exec();
|
|
|
|
|
}
|
|
|
|
|
return m_applied;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 14:31:40 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|