Commit 2fad22c0 authored by Jarek Kobus's avatar Jarek Kobus Committed by Jarek Kobus

Add restore fallback functionality, make better tr()

Task-number: QTCREATORBUG-5025
Change-Id: Ia3f6fa2380dd1a93f120873f584662a267ca4d50
Reviewed-on: http://codereview.qt.nokia.com/360Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent e4367681
......@@ -234,6 +234,7 @@ CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
m_ui->categoryTab->setCurrentIndex(0);
m_ui->tabPreferencesWidget->setFlat(true);
m_ui->fallbackWidget->setLabelText(tr("Code style settings:"));
}
CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget()
......@@ -321,15 +322,11 @@ void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSe
void CppCodeStylePreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback)
{
m_ui->tabPreferencesWidget->setEnabled(!fallback);
m_ui->contentGroupBox->setEnabled(!fallback);
m_ui->bracesGroupBox->setEnabled(!fallback);
m_ui->switchGroupBox->setEnabled(!fallback);
m_ui->alignmentGroupBox->setEnabled(!fallback);
// if C++ global is used for style, use it for tab settings as well
if (fallback && m_tabPreferences && m_cppCodeStylePreferences->currentFallback())
m_tabPreferences->setCurrentFallback(m_cppCodeStylePreferences->currentFallback()->id());
updatePreview();
}
......
......@@ -17,7 +17,7 @@
<item>
<widget class="QWidget" name="fallbackContainer" native="true">
<layout class="QHBoxLayout" name="fallbackLayout">
<property name="leftMargin">
<property name="margin">
<number>0</number>
</property>
<item>
......
......@@ -42,14 +42,14 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
<< textEditorSettings->tabPreferences(), this);
m_d->m_tabPreferences->setCurrentFallback(textEditorSettings->tabPreferences());
m_d->m_tabPreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
m_d->m_tabPreferences->setDisplayName(tr("global C++"));
m_d->m_tabPreferences->setDisplayName(tr("Global C++", "Settings"));
m_d->m_tabPreferences->setId(idKey);
textEditorSettings->registerLanguageTabPreferences(CppTools::Constants::CPP_SETTINGS_ID, m_d->m_tabPreferences);
m_d->m_cppCodeStylePreferences
= new CppCodeStylePreferences(QList<TextEditor::IFallbackPreferences *>(), this);
m_d->m_cppCodeStylePreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
m_d->m_cppCodeStylePreferences->setDisplayName(tr("global C++"));
m_d->m_cppCodeStylePreferences->setDisplayName(tr("Global C++", "Settings"));
m_d->m_cppCodeStylePreferences->setId(idKey);
textEditorSettings->registerLanguageCodeStylePreferences(CppTools::Constants::CPP_SETTINGS_ID, m_d->m_cppCodeStylePreferences);
}
......
......@@ -94,7 +94,7 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate)
QList<IFallbackPreferences *> fallbacks;
fallbacks << TextEditorSettings::instance()->tabPreferences();
m_d->m_tabPreferences = new TabPreferences(fallbacks, this);
m_d->m_tabPreferences->setDisplayName(tr("project text editor"));
m_d->m_tabPreferences->setDisplayName(tr("Project", "Settings"));
m_d->m_tabPreferences->setId(kId);
CodeStylePreferencesManager *manager =
......@@ -127,7 +127,7 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate)
IFallbackPreferences *preferences = factory->createPreferences(
QList<IFallbackPreferences *>() << originalPreferences);
preferences->setId(languageId + QLatin1String("Project"));
preferences->setDisplayName(tr("project %1").arg(factory->displayName()));
preferences->setDisplayName(tr("Project %1", "Settings, %1 is a language (C++ or QML)").arg(factory->displayName()));
preferences->setCurrentFallback(originalPreferences);
m_d->m_languageCodeStylePreferences.insert(languageId, preferences);
}
......
......@@ -62,6 +62,7 @@ public:
EditorConfiguration();
~EditorConfiguration();
void setUseGlobalSettings(bool use);
bool useGlobalSettings() const;
void cloneGlobalSettings();
......@@ -89,7 +90,6 @@ signals:
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
private slots:
void setUseGlobalSettings(bool use);
void setStorageSettings(const TextEditor::StorageSettings &settings);
void setBehaviorSettings(const TextEditor::BehaviorSettings &settings);
......
......@@ -72,12 +72,10 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
const EditorConfiguration *config = m_project->editorConfiguration();
settingsToUi(config);
setGlobalSettingsEnabled(config->useGlobalSettings());
globalSettingsActivated(config->useGlobalSettings() ? 0 : 1);
connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)),
this, SLOT(setGlobalSettingsEnabled(bool)));
connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)),
config, SLOT(setUseGlobalSettings(bool)));
connect(m_ui.globalSelector, SIGNAL(activated(int)),
this, SLOT(globalSettingsActivated(int)));
connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues()));
connect(m_ui.behaviorSettingsWidget, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
config, SLOT(setStorageSettings(TextEditor::StorageSettings)));
......@@ -94,17 +92,20 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
{
m_ui.behaviorSettingsWidget->setTabPreferences(config->tabPreferences());
m_ui.useGlobalCheckBox->setChecked(config->useGlobalSettings());
m_ui.globalSelector->setCurrentIndex(config->useGlobalSettings() ? 0 : 1);
m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec());
m_ui.behaviorSettingsWidget->setAssignedStorageSettings(config->storageSettings());
m_ui.behaviorSettingsWidget->setAssignedBehaviorSettings(config->behaviorSettings());
m_ui.behaviorSettingsWidget->setAssignedExtraEncodingSettings(config->extraEncodingSettings());
}
void EditorSettingsWidget::setGlobalSettingsEnabled(bool enabled)
void EditorSettingsWidget::globalSettingsActivated(int index)
{
m_ui.behaviorSettingsWidget->setActive(!enabled);
m_ui.restoreButton->setEnabled(!enabled);
const bool useGlobal = !index;
m_ui.behaviorSettingsWidget->setActive(!useGlobal);
m_ui.restoreButton->setEnabled(!useGlobal);
EditorConfiguration *config = m_project->editorConfiguration();
config->setUseGlobalSettings(useGlobal);
}
void EditorSettingsWidget::restoreDefaultValues()
......
......@@ -60,7 +60,7 @@ public:
EditorSettingsWidget(Project *project);
private slots:
void setGlobalSettingsEnabled(bool enabled);
void globalSettingsActivated(int index);
void restoreDefaultValues();
private:
......
......@@ -6,35 +6,56 @@
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>98</height>
<width>401</width>
<height>111</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="useGlobalCheckBox">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Use global settings</string>
<string>Editor settings:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="TextEditor::BehaviorSettingsWidget" name="behaviorSettingsWidget" native="true"/>
<item row="0" column="1">
<widget class="QComboBox" name="globalSelector">
<item>
<property name="text">
<string>Global</string>
</property>
</item>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="restoreButton">
<property name="text">
<string>Restore Global</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>224</width>
<width>3</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<item row="1" column="0" colspan="4">
<widget class="TextEditor::BehaviorSettingsWidget" name="behaviorSettingsWidget" native="true"/>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -47,13 +68,6 @@
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="restoreButton">
<property name="text">
<string>Restore Global Values</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......
......@@ -40,7 +40,7 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
<< textEditorSettings->tabPreferences(), this);
m_d->m_tabPreferences->setCurrentFallback(textEditorSettings->tabPreferences());
m_d->m_tabPreferences->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
m_d->m_tabPreferences->setDisplayName(tr("global QML"));
m_d->m_tabPreferences->setDisplayName(tr("Global Qt Quick", "Settings"));
m_d->m_tabPreferences->setId(idKey);
textEditorSettings->registerLanguageTabPreferences(QmlJSTools::Constants::QML_JS_SETTINGS_ID, m_d->m_tabPreferences);
}
......
......@@ -92,7 +92,7 @@ BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters
m_d(new BehaviorSettingsPagePrivate(p))
{
m_d->m_tabPreferences = new TabPreferences(QList<IFallbackPreferences *>(), this);
m_d->m_tabPreferences->setDisplayName(tr("global text editor"));
m_d->m_tabPreferences->setDisplayName(tr("Global", "Settings"));
m_d->m_tabPreferences->setId(idKey);
m_d->init();
}
......
......@@ -5,7 +5,10 @@
#include <QtGui/QBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QCheckBox>
#include <QtGui/QToolButton>
#include <QtGui/QMenu>
#include <QtCore/QTextStream>
#include <QtCore/QSignalMapper>
using namespace TextEditor;
......@@ -15,10 +18,11 @@ FallbackSelectorWidget::FallbackSelectorWidget(QWidget *parent) :
QWidget(parent),
m_fallbackPreferences(0),
m_layout(0),
m_checkBox(0),
m_comboBox(0),
m_comboBoxLabel(0),
m_fallbackWidgetVisible(true)
m_restoreButton(0),
m_fallbackWidgetVisible(true),
m_labelText(tr("Settings:"))
{
hide();
}
......@@ -45,36 +49,47 @@ void FallbackSelectorWidget::setFallbackPreferences(TextEditor::IFallbackPrefere
m_layout = new QHBoxLayout(this);
m_layout->setContentsMargins(QMargins());
m_restoreButton = new QToolButton(this);
QSignalMapper *mapper = new QSignalMapper(this);
m_comboBoxLabel = new QLabel(m_labelText, this);
m_comboBoxLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_layout->addWidget(m_comboBoxLabel);
m_comboBox = new QComboBox(this);
m_layout->addWidget(m_comboBox);
m_comboBox->addItem(tr("Custom"), QVariant::fromValue<TextEditor::IFallbackPreferences *>(0));
connect(m_comboBox, SIGNAL(activated(int)),
this, SLOT(slotComboBoxActivated(int)));
QMenu *menu = new QMenu(this);
if (fallbacks.count() == 1) {
m_checkBox = new QCheckBox(this);
m_layout->addWidget(m_checkBox);
m_layout->addStretch();
m_checkBox->setText(tr("Use %1 settings").arg(fallbacks.at(0)->displayName()));
connect(m_checkBox, SIGNAL(clicked(bool)),
this, SLOT(slotCheckBoxClicked(bool)));
IFallbackPreferences *fallback = fallbacks.first();
m_restoreButton->setText(tr("Restore %1", "%1 is settings name (e.g. Global C++)").arg(fallback->displayName()));
connect(m_restoreButton, SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(m_restoreButton, fallback);
} else {
m_comboBoxLabel = new QLabel(tr("Settings:"), this);
m_layout->addWidget(m_comboBoxLabel);
m_comboBox = new QComboBox(this);
m_layout->addWidget(m_comboBox);
m_layout->setStretch(1, 1);
m_comboBox->addItem(tr("Custom"), QVariant::fromValue<TextEditor::IFallbackPreferences *>(0));
connect(m_comboBox, SIGNAL(activated(int)),
this, SLOT(slotComboBoxActivated(int)));
for (int i = 0; i < fallbacks.count(); i++) {
IFallbackPreferences *fallback = fallbacks.at(i);
QString displayName = fallback->displayName();
if (!displayName.isEmpty())
displayName[0] = displayName[0].toUpper();
m_comboBox->insertItem(i, displayName, QVariant::fromValue(fallback));
}
m_restoreButton->setText(tr("Restore"));
m_restoreButton->setPopupMode(QToolButton::InstantPopup);
m_restoreButton->setMenu(menu);
}
for (int i = 0; i < fallbacks.count(); i++) {
IFallbackPreferences *fallback = fallbacks.at(i);
const QString displayName = fallback->displayName();
const QVariant data = QVariant::fromValue(fallback);
m_comboBox->insertItem(i, displayName, data);
QAction *restoreAction = new QAction(displayName, this);
menu->addAction(restoreAction);
connect(restoreAction, SIGNAL(triggered()), mapper, SLOT(map()));
mapper->setMapping(restoreAction, fallback);
}
m_layout->addWidget(m_restoreButton);
slotCurrentFallbackChanged(m_fallbackPreferences->currentFallback());
connect(m_fallbackPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
connect(mapper, SIGNAL(mapped(QObject*)), this, SLOT(slotRestoreValues(QObject*)));
}
}
......@@ -90,27 +105,25 @@ void FallbackSelectorWidget::slotComboBoxActivated(int index)
blockSignals(wasBlocked);
}
void FallbackSelectorWidget::slotCheckBoxClicked(bool checked)
{
TextEditor::IFallbackPreferences *fallback = 0;
if (checked && !m_fallbackPreferences->fallbacks().isEmpty())
fallback = m_fallbackPreferences->fallbacks().first();
const bool wasBlocked = blockSignals(true);
m_fallbackPreferences->setCurrentFallback(fallback);
blockSignals(wasBlocked);
}
void FallbackSelectorWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback)
{
const bool wasBlocked = blockSignals(true);
if (m_comboBox)
m_comboBox->setCurrentIndex(m_comboBox->findData(QVariant::fromValue(fallback)));
if (m_checkBox)
m_checkBox->setChecked(fallback);
if (m_restoreButton)
m_restoreButton->setEnabled(!fallback);
blockSignals(wasBlocked);
}
void FallbackSelectorWidget::slotRestoreValues(QObject *fallbackObject)
{
TextEditor::IFallbackPreferences *fallback
= qobject_cast<TextEditor::IFallbackPreferences *>(fallbackObject);
if (!fallback)
return;
m_fallbackPreferences->setValue(fallback->currentValue());
}
void FallbackSelectorWidget::setFallbacksVisible(bool on)
{
m_fallbackWidgetVisible = on;
......@@ -118,6 +131,13 @@ void FallbackSelectorWidget::setFallbacksVisible(bool on)
setVisible(m_fallbackWidgetVisible && !m_fallbackPreferences->fallbacks().isEmpty());
}
void FallbackSelectorWidget::setLabelText(const QString &text)
{
m_labelText = text;
if (m_comboBoxLabel)
m_comboBoxLabel->setText(text);
}
QString FallbackSelectorWidget::searchKeywords() const
{
// no useful keywords here
......
......@@ -11,6 +11,7 @@ class QHBoxLayout;
class QComboBox;
class QLabel;
class QCheckBox;
class QToolButton;
QT_END_NAMESPACE
namespace TextEditor {
......@@ -27,27 +28,26 @@ public:
QString searchKeywords() const;
void setFallbacksVisible(bool on);
void setLabelText(const QString &text);
signals:
private slots:
void slotComboBoxActivated(int index);
void slotCheckBoxClicked(bool checked);
void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *);
void slotRestoreValues(QObject *);
private:
IFallbackPreferences *m_fallbackPreferences;
QHBoxLayout *m_layout;
QCheckBox *m_checkBox;
QComboBox *m_comboBox;
QLabel *m_comboBoxLabel;
QToolButton *m_restoreButton;
bool m_fallbackWidgetVisible;
QMap<IFallbackPreferences *, int> m_fallbackToIndex;
QMap<int, IFallbackPreferences *> m_indexToFallback;
QString m_labelText;
};
} // namespace TextEditor
......
......@@ -12,6 +12,7 @@ TabPreferencesWidget::TabPreferencesWidget(QWidget *parent) :
m_tabPreferences(0)
{
m_ui->setupUi(this);
m_ui->fallbackWidget->setLabelText(tr("Tab settings:"));
}
TabPreferencesWidget::~TabPreferencesWidget()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment