Commit 65e11062 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Polish the settings dialog.

Add a title label to the pages. Use QGroupBoxes throughout.
Extend SavedAction to work with checkable QGroupBoxes. Polish UI files,
use common layout for VCS plugins. Performance: Apply only visited
settings pages. Add search keywords.

Task-number: QTCREATOR-26
parent c49bed11
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <QtGui/QLineEdit> #include <QtGui/QLineEdit>
#include <QtGui/QRadioButton> #include <QtGui/QRadioButton>
#include <QtGui/QSpinBox> #include <QtGui/QSpinBox>
#include <QtGui/QGroupBox>
using namespace Utils; using namespace Utils;
...@@ -238,19 +239,17 @@ QAction *SavedAction::updatedAction(const QString &text0) ...@@ -238,19 +239,17 @@ QAction *SavedAction::updatedAction(const QString &text0)
\sa settingsKey(), settingsGroup(), writeSettings() \sa settingsKey(), settingsGroup(), writeSettings()
*/ */
void SavedAction::readSettings(QSettings *settings) void SavedAction::readSettings(const QSettings *settings)
{ {
if (m_settingsGroup.isEmpty() || m_settingsKey.isEmpty()) if (m_settingsGroup.isEmpty() || m_settingsKey.isEmpty())
return; return;
settings->beginGroup(m_settingsGroup); QVariant var = settings->value(m_settingsGroup + QLatin1Char('/') + m_settingsKey, m_defaultValue);
QVariant var = settings->value(m_settingsKey, m_defaultValue);
// work around old ini files containing @Invalid() entries // work around old ini files containing @Invalid() entries
if (isCheckable() && !var.isValid()) if (isCheckable() && !var.isValid())
var = false; var = false;
setValue(var); setValue(var);
//qDebug() << "READING: " << var.isValid() << m_settingsKey << " -> " << m_value //qDebug() << "READING: " << var.isValid() << m_settingsKey << " -> " << m_value
// << " (default: " << m_defaultValue << ")" << var; // << " (default: " << m_defaultValue << ")" << var;
settings->endGroup();
} }
/* /*
...@@ -314,6 +313,11 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode) ...@@ -314,6 +313,11 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
this, SLOT(pathChooserEditingFinished())); this, SLOT(pathChooserEditingFinished()));
connect(pathChooser, SIGNAL(browsingFinished()), connect(pathChooser, SIGNAL(browsingFinished()),
this, SLOT(pathChooserEditingFinished())); this, SLOT(pathChooserEditingFinished()));
} else if (QGroupBox *groupBox= qobject_cast<QGroupBox *>(widget)) {
if (!groupBox->isCheckable())
qDebug() << "connectWidget to non-checkable group box" << widget << toString();
groupBox->setChecked(m_value.toBool());
connect(groupBox, SIGNAL(toggled(bool)), this, SLOT(groupBoxToggled(bool)));
} else { } else {
qDebug() << "Cannot connect widget " << widget << toString(); qDebug() << "Cannot connect widget " << widget << toString();
} }
...@@ -339,6 +343,8 @@ void SavedAction::apply(QSettings *s) ...@@ -339,6 +343,8 @@ void SavedAction::apply(QSettings *s)
setValue(spinBox->value()); setValue(spinBox->value());
else if (PathChooser *pathChooser = qobject_cast<PathChooser *>(m_widget)) else if (PathChooser *pathChooser = qobject_cast<PathChooser *>(m_widget))
setValue(pathChooser->path()); setValue(pathChooser->path());
else if (const QGroupBox *groupBox= qobject_cast<QGroupBox *>(m_widget))
setValue(groupBox->isChecked());
if (s) if (s)
writeSettings(s); writeSettings(s);
} }
...@@ -392,6 +398,12 @@ void SavedAction::pathChooserEditingFinished() ...@@ -392,6 +398,12 @@ void SavedAction::pathChooserEditingFinished()
setValue(pathChooser->path()); setValue(pathChooser->path());
} }
void SavedAction::groupBoxToggled(bool checked)
{
if (m_applyMode == ImmediateApply)
setValue(QVariant(checked));
}
void SavedAction::actionTriggered(bool) void SavedAction::actionTriggered(bool)
{ {
if (isCheckable()) if (isCheckable())
...@@ -436,3 +448,16 @@ void SavedActionSet::finish() ...@@ -436,3 +448,16 @@ void SavedActionSet::finish()
action->disconnectWidget(); action->disconnectWidget();
} }
QString SavedActionSet::searchKeyWords() const
{
const QChar blank = QLatin1Char(' ');
QString rc;
foreach (SavedAction *action, m_list) {
if (!rc.isEmpty())
rc += blank;
rc += action->text();
}
rc.remove(QLatin1Char('&'));
return rc;
}
...@@ -70,7 +70,7 @@ public: ...@@ -70,7 +70,7 @@ public:
virtual QString settingsGroup() const; virtual QString settingsGroup() const;
Q_SLOT virtual void setSettingsGroup(const QString &group); Q_SLOT virtual void setSettingsGroup(const QString &group);
virtual void readSettings(QSettings *settings); virtual void readSettings(const QSettings *settings);
Q_SLOT virtual void writeSettings(QSettings *settings); Q_SLOT virtual void writeSettings(QSettings *settings);
virtual void connectWidget(QWidget *widget, ApplyMode applyMode = DeferedApply); virtual void connectWidget(QWidget *widget, ApplyMode applyMode = DeferedApply);
...@@ -93,6 +93,7 @@ private: ...@@ -93,6 +93,7 @@ private:
Q_SLOT void actionTriggered(bool); Q_SLOT void actionTriggered(bool);
Q_SLOT void spinBoxValueChanged(int); Q_SLOT void spinBoxValueChanged(int);
Q_SLOT void spinBoxValueChanged(QString); Q_SLOT void spinBoxValueChanged(QString);
Q_SLOT void groupBoxToggled(bool checked);
QVariant m_value; QVariant m_value;
QVariant m_defaultValue; QVariant m_defaultValue;
...@@ -115,6 +116,9 @@ public: ...@@ -115,6 +116,9 @@ public:
void finish(); void finish();
void clear() { m_list.clear(); } void clear() { m_list.clear(); }
// Search keywords for options dialog search.
QString searchKeyWords() const;
private: private:
QList<SavedAction *> m_list; QList<SavedAction *> m_list;
}; };
......
...@@ -263,7 +263,7 @@ QWidget *CMakeSettingsPage::createPage(QWidget *parent) ...@@ -263,7 +263,7 @@ QWidget *CMakeSettingsPage::createPage(QWidget *parent)
{ {
QWidget *outerWidget = new QWidget(parent); QWidget *outerWidget = new QWidget(parent);
QVBoxLayout *outerLayout = new QVBoxLayout(outerWidget); QVBoxLayout *outerLayout = new QVBoxLayout(outerWidget);
QGroupBox *groupBox = new QGroupBox(trCategory()); QGroupBox *groupBox = new QGroupBox;
outerLayout->addWidget(groupBox); outerLayout->addWidget(groupBox);
outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
QFormLayout *formLayout = new QFormLayout(groupBox); QFormLayout *formLayout = new QFormLayout(groupBox);
......
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
#include <QtGui/QSortFilterProxyModel> #include <QtGui/QSortFilterProxyModel>
#include <QtGui/QItemSelectionModel> #include <QtGui/QItemSelectionModel>
#include <QtGui/QIcon> #include <QtGui/QIcon>
#include <QtGui/QLabel>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QSpacerItem>
#include <QtGui/QStyle>
enum ItemType { CategoryItem, PageItem }; enum ItemType { CategoryItem, PageItem };
...@@ -201,8 +206,37 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId, ...@@ -201,8 +206,37 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply())); connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
foreach(IOptionsPage *page, m_pages) // Create pages with title labels with a larger, bold font, left-aligned
stackedPages->addWidget(page->createPage(0)); // with the group boxes of the page.
const int pageCount = m_pages.size();
QFont titleLabelFont;
const int leftMargin = qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin) +
qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
for (int i = 0; i < pageCount; i++) {
// Title bar
QHBoxLayout *titleLayout = new QHBoxLayout;
titleLayout->addSpacerItem(new QSpacerItem(leftMargin, 0, QSizePolicy::Fixed, QSizePolicy::Ignored));
QLabel *titleLabel = new QLabel(m_pages.at(i)->trName());
if (i == 0) { // Create a bold header font from the default label font.
titleLabelFont = titleLabel->font();
titleLabelFont.setBold(true);
// Paranoia: Should a font be set in pixels...
const int pointSize = titleLabelFont.pointSize();
if (pointSize > 0)
titleLabelFont.setPointSize(pointSize + 2);
}
titleLabel->setFont(titleLabelFont);
titleLayout->addWidget(titleLabel);
// Page
QWidget *pageContainer =new QWidget;
QVBoxLayout *pageLayout = new QVBoxLayout(pageContainer);
pageLayout->addLayout(titleLayout);
pageLayout->addSpacerItem(new QSpacerItem(0, 6, QSizePolicy::Ignored, QSizePolicy::Fixed));
pageLayout->addWidget(m_pages.at(i)->createPage(0));
stackedPages->addWidget(pageContainer);
}
// foreach(IOptionsPage *page, m_pages)
// stackedPages->addWidget();
splitter->setCollapsible(1, false); splitter->setCollapsible(1, false);
pageTree->header()->setVisible(false); pageTree->header()->setVisible(false);
...@@ -247,10 +281,11 @@ void SettingsDialog::showPage(const QStandardItem *item) ...@@ -247,10 +281,11 @@ void SettingsDialog::showPage(const QStandardItem *item)
// if a category was hit. // if a category was hit.
switch (itemTypeOfItem(item)) { switch (itemTypeOfItem(item)) {
case PageItem: { case PageItem: {
const IOptionsPage *page = pageOfItem(item); IOptionsPage *page = pageOfItem(item);
m_currentCategory = page->category(); m_currentCategory = page->category();
m_currentPage = page->id(); m_currentPage = page->id();
stackedPages->setCurrentIndex(indexOfItem(item)); stackedPages->setCurrentIndex(indexOfItem(item));
m_visitedPages.insert(page);
} }
break; break;
case CategoryItem: case CategoryItem:
...@@ -318,10 +353,10 @@ void SettingsDialog::filter(const QString &text) ...@@ -318,10 +353,10 @@ void SettingsDialog::filter(const QString &text)
void SettingsDialog::accept() void SettingsDialog::accept()
{ {
m_applied = true; m_applied = true;
foreach (IOptionsPage *page, m_pages) { foreach (IOptionsPage *page, m_visitedPages)
page->apply(); page->apply();
foreach (IOptionsPage *page, m_pages)
page->finish(); page->finish();
}
done(QDialog::Accepted); done(QDialog::Accepted);
} }
...@@ -334,7 +369,7 @@ void SettingsDialog::reject() ...@@ -334,7 +369,7 @@ void SettingsDialog::reject()
void SettingsDialog::apply() void SettingsDialog::apply()
{ {
foreach (IOptionsPage *page, m_pages) foreach (IOptionsPage *page, m_visitedPages)
page->apply(); page->apply();
m_applied = true; m_applied = true;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "ui_settingsdialog.h" #include "ui_settingsdialog.h"
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QSet>
#include "coreplugin/dialogs/ioptionspage.h" #include "coreplugin/dialogs/ioptionspage.h"
...@@ -74,6 +75,8 @@ private: ...@@ -74,6 +75,8 @@ private:
void showPage(const QStandardItem *item); void showPage(const QStandardItem *item);
const QList<Core::IOptionsPage*> m_pages; const QList<Core::IOptionsPage*> m_pages;
QSet<Core::IOptionsPage*> m_visitedPages;
QSortFilterProxyModel *m_proxyModel; QSortFilterProxyModel *m_proxyModel;
QStandardItemModel *m_model; QStandardItemModel *m_model;
bool m_applied; bool m_applied;
......
...@@ -2,12 +2,17 @@ ...@@ -2,12 +2,17 @@
<ui version="4.0"> <ui version="4.0">
<class>Core::Internal::GeneralSettings</class> <class>Core::Internal::GeneralSettings</class>
<widget class="QWidget" name="Core::Internal::GeneralSettings"> <widget class="QWidget" name="Core::Internal::GeneralSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>363</width>
<height>296</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title">
<string>General settings</string>
</property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="rowWrapPolicy"> <property name="rowWrapPolicy">
<enum>QFormLayout::WrapLongRows</enum> <enum>QFormLayout::WrapLongRows</enum>
......
...@@ -74,7 +74,7 @@ QString CodePasterSettingsPage::trCategory() const ...@@ -74,7 +74,7 @@ QString CodePasterSettingsPage::trCategory() const
QWidget *CodePasterSettingsPage::createPage(QWidget *parent) QWidget *CodePasterSettingsPage::createPage(QWidget *parent)
{ {
QGroupBox *groupBox = new QGroupBox(category()); QGroupBox *groupBox = new QGroupBox();
QVBoxLayout *groupBoxLayout = new QVBoxLayout(groupBox); QVBoxLayout *groupBoxLayout = new QVBoxLayout(groupBox);
QFormLayout *formLayout = new QFormLayout; QFormLayout *formLayout = new QFormLayout;
QLineEdit *lineedit = new QLineEdit(m_host); QLineEdit *lineedit = new QLineEdit(m_host);
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title">
<string>PasteBin</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
......
...@@ -2,14 +2,6 @@ ...@@ -2,14 +2,6 @@
<ui version="4.0"> <ui version="4.0">
<class>CodePaster::SettingsPage</class> <class>CodePaster::SettingsPage</class>
<widget class="QWidget" name="CodePaster::SettingsPage"> <widget class="QWidget" name="CodePaster::SettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>453</width>
<height>320</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
...@@ -19,9 +11,6 @@ ...@@ -19,9 +11,6 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="title">
<string>General</string>
</property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="protocolLabel"> <widget class="QLabel" name="protocolLabel">
...@@ -59,14 +48,14 @@ ...@@ -59,14 +48,14 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="userEdit"/> <widget class="QLineEdit" name="userEdit"/>
</item> </item>
<item row="2" column="1"> <item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="clipboardBox"> <widget class="QCheckBox" name="clipboardBox">
<property name="text"> <property name="text">
<string>Copy Paste URL to clipboard</string> <string>Copy Paste URL to clipboard</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="displayBox"> <widget class="QCheckBox" name="displayBox">
<property name="text"> <property name="text">
<string>Display Output Pane after sending a post</string> <string>Display Output Pane after sending a post</string>
......
...@@ -13,9 +13,6 @@ ...@@ -13,9 +13,6 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Code Completion</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QCheckBox" name="caseSensitive"> <widget class="QCheckBox" name="caseSensitive">
......
...@@ -243,7 +243,8 @@ QString CppFileSettingsWidget::searchKeywords() const ...@@ -243,7 +243,8 @@ QString CppFileSettingsWidget::searchKeywords() const
QString rc; QString rc;
QTextStream(&rc) << m_ui->headerSuffixLabel->text() QTextStream(&rc) << m_ui->headerSuffixLabel->text()
<< ' ' << m_ui->sourceSuffixLabel->text() << ' ' << m_ui->sourceSuffixLabel->text()
<< ' ' << m_ui->lowerCaseFileNamesCheckBox->text(); << ' ' << m_ui->lowerCaseFileNamesCheckBox->text()
<< ' ' << m_ui->licenseTemplateLabel->text();
rc.remove(QLatin1Char('&')); rc.remove(QLatin1Char('&'));
return rc; return rc;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>424</width> <width>441</width>
<height>503</height> <height>503</height>
</rect> </rect>
</property> </property>
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="title">
<string>File Naming Conventions</string>
</property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum> <enum>QFormLayout::ExpandingFieldsGrow</enum>
...@@ -61,7 +58,7 @@ ...@@ -61,7 +58,7 @@
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="Utils::PathChooser" name="licenseTemplatePathChooser" native="true"/> <widget class="Utils::PathChooser" name="licenseTemplatePathChooser"/>
</item> </item>
</layout> </layout>
</widget> </widget>
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QTextStream>
#include <QtGui/QFileDialog> #include <QtGui/QFileDialog>
using namespace CVS::Internal; using namespace CVS::Internal;
...@@ -70,6 +71,17 @@ void SettingsPageWidget::setSettings(const CVSSettings &s) ...@@ -70,6 +71,17 @@ void SettingsPageWidget::setSettings(const CVSSettings &s)
m_ui.describeByCommitIdCheckBox->setChecked(s.describeByCommitId); m_ui.describeByCommitIdCheckBox->setChecked(s.describeByCommitId);
} }
QString SettingsPageWidget::searchKeywords() const
{
QString rc;
QTextStream(&rc) << m_ui.promptToSubmitCheckBox->text()
<< ' ' << m_ui.describeByCommitIdCheckBox->text()
<< ' ' << m_ui.commandLabel->text()
<< ' ' << m_ui.rootLabel->text() << ' ' << m_ui.diffOptionsLabel->text();
rc.remove(QLatin1Char('&'));
return rc;
}
SettingsPage::SettingsPage() SettingsPage::SettingsPage()
{ {
} }
...@@ -98,6 +110,8 @@ QWidget *SettingsPage::createPage(QWidget *parent) ...@@ -98,6 +110,8 @@ QWidget *SettingsPage::createPage(QWidget *parent)
{ {
m_widget = new SettingsPageWidget(parent); m_widget = new SettingsPageWidget(parent);
m_widget->setSettings(CVSPlugin::cvsPluginInstance()->settings()); m_widget->setSettings(CVSPlugin::cvsPluginInstance()->settings());
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
return m_widget; return m_widget;
} }
...@@ -105,3 +119,8 @@ void SettingsPage::apply() ...@@ -105,3 +119,8 @@ void SettingsPage::apply()
{ {
CVSPlugin::cvsPluginInstance()->setSettings(m_widget->settings()); CVSPlugin::cvsPluginInstance()->setSettings(m_widget->settings());
} }
bool SettingsPage::matches(const QString &s) const
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
...@@ -55,6 +55,8 @@ public: ...@@ -55,6 +55,8 @@ public:
CVSSettings settings() const; CVSSettings settings() const;
void setSettings(const CVSSettings &); void setSettings(const CVSSettings &);
QString searchKeywords() const;
private: private:
Ui::SettingsPage m_ui; Ui::SettingsPage m_ui;
}; };
...@@ -75,8 +77,10 @@ public: ...@@ -75,8 +77,10 @@ public:
QWidget *createPage(QWidget *parent); QWidget *createPage(QWidget *parent);
void apply(); void apply();
void finish() { } void finish() { }
virtual bool matches(const QString &) const;
private: private:
QString m_searchKeywords;
SettingsPageWidget* m_widget; SettingsPageWidget* m_widget;
}; };
......
...@@ -2,115 +2,81 @@ ...@@ -2,115 +2,81 @@
<ui version="4.0"> <ui version="4.0">
<class>CVS::Internal::SettingsPage</class> <class>CVS::Internal::SettingsPage</class>
<widget class="QWidget" name="CVS::Internal::SettingsPage">