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

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 @@
#include <QtGui/QLineEdit>
#include <QtGui/QRadioButton>
#include <QtGui/QSpinBox>
#include <QtGui/QGroupBox>
using namespace Utils;
......@@ -238,19 +239,17 @@ QAction *SavedAction::updatedAction(const QString &text0)
\sa settingsKey(), settingsGroup(), writeSettings()
*/
void SavedAction::readSettings(QSettings *settings)
void SavedAction::readSettings(const QSettings *settings)
{
if (m_settingsGroup.isEmpty() || m_settingsKey.isEmpty())
return;
settings->beginGroup(m_settingsGroup);
QVariant var = settings->value(m_settingsKey, m_defaultValue);
QVariant var = settings->value(m_settingsGroup + QLatin1Char('/') + m_settingsKey, m_defaultValue);
// work around old ini files containing @Invalid() entries
if (isCheckable() && !var.isValid())
var = false;
setValue(var);
//qDebug() << "READING: " << var.isValid() << m_settingsKey << " -> " << m_value
// << " (default: " << m_defaultValue << ")" << var;
settings->endGroup();
}
/*
......@@ -314,6 +313,11 @@ void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode)
this, SLOT(pathChooserEditingFinished()));
connect(pathChooser, SIGNAL(browsingFinished()),
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 {
qDebug() << "Cannot connect widget " << widget << toString();
}
......@@ -339,6 +343,8 @@ void SavedAction::apply(QSettings *s)
setValue(spinBox->value());
else if (PathChooser *pathChooser = qobject_cast<PathChooser *>(m_widget))
setValue(pathChooser->path());
else if (const QGroupBox *groupBox= qobject_cast<QGroupBox *>(m_widget))
setValue(groupBox->isChecked());
if (s)
writeSettings(s);
}
......@@ -392,6 +398,12 @@ void SavedAction::pathChooserEditingFinished()
setValue(pathChooser->path());
}
void SavedAction::groupBoxToggled(bool checked)
{
if (m_applyMode == ImmediateApply)
setValue(QVariant(checked));
}
void SavedAction::actionTriggered(bool)
{
if (isCheckable())
......@@ -436,3 +448,16 @@ void SavedActionSet::finish()
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:
virtual QString settingsGroup() const;
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);
virtual void connectWidget(QWidget *widget, ApplyMode applyMode = DeferedApply);
......@@ -93,6 +93,7 @@ private:
Q_SLOT void actionTriggered(bool);
Q_SLOT void spinBoxValueChanged(int);
Q_SLOT void spinBoxValueChanged(QString);
Q_SLOT void groupBoxToggled(bool checked);
QVariant m_value;
QVariant m_defaultValue;
......@@ -115,6 +116,9 @@ public:
void finish();
void clear() { m_list.clear(); }
// Search keywords for options dialog search.
QString searchKeyWords() const;
private:
QList<SavedAction *> m_list;
};
......
......@@ -263,7 +263,7 @@ QWidget *CMakeSettingsPage::createPage(QWidget *parent)
{
QWidget *outerWidget = new QWidget(parent);
QVBoxLayout *outerLayout = new QVBoxLayout(outerWidget);
QGroupBox *groupBox = new QGroupBox(trCategory());
QGroupBox *groupBox = new QGroupBox;
outerLayout->addWidget(groupBox);
outerLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding));
QFormLayout *formLayout = new QFormLayout(groupBox);
......
......@@ -42,6 +42,11 @@
#include <QtGui/QSortFilterProxyModel>
#include <QtGui/QItemSelectionModel>
#include <QtGui/QIcon>
#include <QtGui/QLabel>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QSpacerItem>
#include <QtGui/QStyle>
enum ItemType { CategoryItem, PageItem };
......@@ -201,8 +206,37 @@ SettingsDialog::SettingsDialog(QWidget *parent, const QString &categoryId,
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply()));
foreach(IOptionsPage *page, m_pages)
stackedPages->addWidget(page->createPage(0));
// Create pages with title labels with a larger, bold font, left-aligned
// 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);
pageTree->header()->setVisible(false);
......@@ -247,10 +281,11 @@ void SettingsDialog::showPage(const QStandardItem *item)
// if a category was hit.
switch (itemTypeOfItem(item)) {
case PageItem: {
const IOptionsPage *page = pageOfItem(item);
IOptionsPage *page = pageOfItem(item);
m_currentCategory = page->category();
m_currentPage = page->id();
stackedPages->setCurrentIndex(indexOfItem(item));
m_visitedPages.insert(page);
}
break;
case CategoryItem:
......@@ -318,10 +353,10 @@ void SettingsDialog::filter(const QString &text)
void SettingsDialog::accept()
{
m_applied = true;
foreach (IOptionsPage *page, m_pages) {
foreach (IOptionsPage *page, m_visitedPages)
page->apply();
foreach (IOptionsPage *page, m_pages)
page->finish();
}
done(QDialog::Accepted);
}
......@@ -334,7 +369,7 @@ void SettingsDialog::reject()
void SettingsDialog::apply()
{
foreach (IOptionsPage *page, m_pages)
foreach (IOptionsPage *page, m_visitedPages)
page->apply();
m_applied = true;
}
......
......@@ -33,6 +33,7 @@
#include "ui_settingsdialog.h"
#include <QtCore/QList>
#include <QtCore/QSet>
#include "coreplugin/dialogs/ioptionspage.h"
......@@ -74,6 +75,8 @@ private:
void showPage(const QStandardItem *item);
const QList<Core::IOptionsPage*> m_pages;
QSet<Core::IOptionsPage*> m_visitedPages;
QSortFilterProxyModel *m_proxyModel;
QStandardItemModel *m_model;
bool m_applied;
......
......@@ -2,12 +2,17 @@
<ui version="4.0">
<class>Core::Internal::GeneralSettings</class>
<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">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>General settings</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="rowWrapPolicy">
<enum>QFormLayout::WrapLongRows</enum>
......
......@@ -74,7 +74,7 @@ QString CodePasterSettingsPage::trCategory() const
QWidget *CodePasterSettingsPage::createPage(QWidget *parent)
{
QGroupBox *groupBox = new QGroupBox(category());
QGroupBox *groupBox = new QGroupBox();
QVBoxLayout *groupBoxLayout = new QVBoxLayout(groupBox);
QFormLayout *formLayout = new QFormLayout;
QLineEdit *lineedit = new QLineEdit(m_host);
......
......@@ -16,9 +16,6 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>PasteBin</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
......
......@@ -2,14 +2,6 @@
<ui version="4.0">
<class>CodePaster::SettingsPage</class>
<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">
<item>
<widget class="QGroupBox" name="groupBox">
......@@ -19,9 +11,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>General</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="protocolLabel">
......@@ -59,14 +48,14 @@
<item row="1" column="1">
<widget class="QLineEdit" name="userEdit"/>
</item>
<item row="2" column="1">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="clipboardBox">
<property name="text">
<string>Copy Paste URL to clipboard</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="displayBox">
<property name="text">
<string>Display Output Pane after sending a post</string>
......
......@@ -13,9 +13,6 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Code Completion</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="caseSensitive">
......
......@@ -243,7 +243,8 @@ QString CppFileSettingsWidget::searchKeywords() const
QString rc;
QTextStream(&rc) << m_ui->headerSuffixLabel->text()
<< ' ' << m_ui->sourceSuffixLabel->text()
<< ' ' << m_ui->lowerCaseFileNamesCheckBox->text();
<< ' ' << m_ui->lowerCaseFileNamesCheckBox->text()
<< ' ' << m_ui->licenseTemplateLabel->text();
rc.remove(QLatin1Char('&'));
return rc;
}
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>424</width>
<width>441</width>
<height>503</height>
</rect>
</property>
......@@ -19,9 +19,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>File Naming Conventions</string>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
......@@ -61,7 +58,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="Utils::PathChooser" name="licenseTemplatePathChooser" native="true"/>
<widget class="Utils::PathChooser" name="licenseTemplatePathChooser"/>
</item>
</layout>
</widget>
......
......@@ -37,6 +37,7 @@
#include <utils/pathchooser.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QTextStream>
#include <QtGui/QFileDialog>
using namespace CVS::Internal;
......@@ -70,6 +71,17 @@ void SettingsPageWidget::setSettings(const CVSSettings &s)
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()
{
}
......@@ -98,6 +110,8 @@ QWidget *SettingsPage::createPage(QWidget *parent)
{
m_widget = new SettingsPageWidget(parent);
m_widget->setSettings(CVSPlugin::cvsPluginInstance()->settings());
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
return m_widget;
}
......@@ -105,3 +119,8 @@ void SettingsPage::apply()
{
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:
CVSSettings settings() const;
void setSettings(const CVSSettings &);
QString searchKeywords() const;
private:
Ui::SettingsPage m_ui;
};
......@@ -75,8 +77,10 @@ public:
QWidget *createPage(QWidget *parent);
void apply();
void finish() { }
virtual bool matches(const QString &) const;
private:
QString m_searchKeywords;
SettingsPageWidget* m_widget;
};
......
......@@ -2,115 +2,81 @@
<ui version="4.0">
<class>CVS::Internal::SettingsPage</class>
<widget class="QWidget" name="CVS::Internal::SettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>575</width>
<height>437</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="promptToSubmitCheckBox">
<property name="text">
<string>Prompt to submit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="describeByCommitIdCheckBox">
<property name="toolTip">
<string>When checked, all files touched by a commit will be displayed when clicking on a revision number in the annotation view (retrieved via commit id). Otherwise, only the respective file will be displayed.</string>
</property>
<property name="text">
<string>Describe all files matching commit id:</string>
</property>
</widget>
</item>
<item>
<spacer name="topverticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="commandLabel">
<property name="text">
<string>CVS Command:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::PathChooser" name="commandPathChooser"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="rootLabel">
<property name="text">
<string>CVS Root:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="rootLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="diffOptionsLabel">
<property name="text">
<string>Diff Options:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="diffOptionsLineEdit"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
<widget class="QGroupBox" name="miscGroupBox">
<property name="title">
<string>Configuration</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="commandLabel">
<property name="text">
<string>CVS Command:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::PathChooser" name="commandPathChooser"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="rootLabel">
<property name="text">
<string>CVS Root:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="rootLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="miscGroupBox_2">
<property name="title">
<string>Miscellaneous</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="diffOptionsLabel">
<property name="text">
<string>Diff Options:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="diffOptionsLineEdit"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="promptToSubmitCheckBox">
<property name="text">
<string>Prompt on submit</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="describeByCommitIdCheckBox">
<property name="toolTip">
<string>When checked, all files touched by a commit will be displayed when clicking on a revision number in the annotation view (retrieved via commit id). Otherwise, only the respective file will be displayed.</string>
</property>
<property name="text">
<string>Describe all files matching commit id</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>105</width>
<height>20</height>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
......
......@@ -35,6 +35,7 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QUrl>
#include <QtCore/QTextStream>
#include <QtGui/QMessageBox>
#include <QtGui/QDesktopServices>
......@@ -127,6 +128,16 @@ void CdbOptionsPageWidget::downLoadLinkActivated(const QString &link)
QDesktopServices::openUrl(QUrl(link));
}
QString CdbOptionsPageWidget::searchKeywords() const
{
QString rc;
QTextStream(&rc) << m_ui.pathLabel->text() << ' ' << m_ui.symbolPathLabel->text()
<< ' ' << m_ui.sourcePathLabel->text()
<< ' ' << m_ui.verboseSymbolLoadingCheckBox->text();