Commit 02314e24 authored by Erik Verbruggen's avatar Erik Verbruggen

Editor: add margin displaying to project settings.

This patch also moves the showMargin and marginColumn settings into a
new settings class.

Change-Id: I676447be751c13ee438edc1e31e5998b999c6771
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 28180a41
......@@ -42,6 +42,7 @@
#include <texteditor/behaviorsettings.h>
#include <texteditor/extraencodingsettings.h>
#include <texteditor/tabsettings.h>
#include <texteditor/marginsettings.h>
#include <texteditor/icodestylepreferencesfactory.h>
#include <QLatin1String>
......@@ -77,6 +78,7 @@ struct EditorConfigurationPrivate
StorageSettings m_storageSettings;
BehaviorSettings m_behaviorSettings;
ExtraEncodingSettings m_extraEncodingSettings;
MarginSettings m_marginSettings;
QTextCodec *m_textCodec;
QMap<Core::Id, ICodeStylePreferences *> m_languageCodeStylePreferences;
......@@ -134,6 +136,7 @@ void EditorConfiguration::cloneGlobalSettings()
setStorageSettings(TextEditorSettings::storageSettings());
setBehaviorSettings(TextEditorSettings::behaviorSettings());
setExtraEncodingSettings(TextEditorSettings::extraEncodingSettings());
setMarginSettings(TextEditorSettings::marginSettings());
d->m_textCodec = Core::EditorManager::defaultTextCodec();
}
......@@ -162,6 +165,11 @@ const ExtraEncodingSettings &EditorConfiguration::extraEncodingSettings() const
return d->m_extraEncodingSettings;
}
const MarginSettings &EditorConfiguration::marginSettings() const
{
return d->m_marginSettings;
}
ICodeStylePreferences *EditorConfiguration::codeStyle() const
{
return d->m_defaultCodeStyle;
......@@ -202,6 +210,7 @@ QVariantMap EditorConfiguration::toMap() const
d->m_storageSettings.toMap(kPrefix, &map);
d->m_behaviorSettings.toMap(kPrefix, &map);
d->m_extraEncodingSettings.toMap(kPrefix, &map);
d->m_marginSettings.toMap(kPrefix, &map);
return map;
}
......@@ -234,6 +243,7 @@ void EditorConfiguration::fromMap(const QVariantMap &map)
d->m_storageSettings.fromMap(kPrefix, map);
d->m_behaviorSettings.fromMap(kPrefix, map);
d->m_extraEncodingSettings.fromMap(kPrefix, map);
d->m_marginSettings.fromMap(kPrefix, map);
}
void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
......@@ -276,6 +286,8 @@ void EditorConfiguration::setUseGlobalSettings(bool use)
static void switchSettings_helper(const QObject *newSender, const QObject *oldSender,
BaseTextEditorWidget *baseTextEditor)
{
QObject::disconnect(oldSender, SIGNAL(marginSettingsChanged(TextEditor::MarginSettings)),
baseTextEditor, SLOT(setMarginSettings(TextEditor::MarginSettings)));
QObject::disconnect(oldSender, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
baseTextEditor, SLOT(setTypingSettings(TextEditor::TypingSettings)));
QObject::disconnect(oldSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
......@@ -285,6 +297,8 @@ static void switchSettings_helper(const QObject *newSender, const QObject *oldSe
QObject::disconnect(oldSender, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)),
baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
QObject::connect(newSender, SIGNAL(marginSettingsChanged(TextEditor::MarginSettings)),
baseTextEditor, SLOT(setMarginSettings(TextEditor::MarginSettings)));
QObject::connect(newSender, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
baseTextEditor, SLOT(setTypingSettings(TextEditor::TypingSettings)));
QObject::connect(newSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
......@@ -298,12 +312,14 @@ static void switchSettings_helper(const QObject *newSender, const QObject *oldSe
void EditorConfiguration::switchSettings(BaseTextEditorWidget *baseTextEditor) const
{
if (d->m_useGlobal) {
baseTextEditor->setMarginSettings(TextEditorSettings::marginSettings());
baseTextEditor->setTypingSettings(TextEditorSettings::typingSettings());
baseTextEditor->setStorageSettings(TextEditorSettings::storageSettings());
baseTextEditor->setBehaviorSettings(TextEditorSettings::behaviorSettings());
baseTextEditor->setExtraEncodingSettings(TextEditorSettings::extraEncodingSettings());
switchSettings_helper(TextEditorSettings::instance(), this, baseTextEditor);
} else {
baseTextEditor->setMarginSettings(marginSettings());
baseTextEditor->setTypingSettings(typingSettings());
baseTextEditor->setStorageSettings(storageSettings());
baseTextEditor->setBehaviorSettings(behaviorSettings());
......@@ -336,11 +352,35 @@ void EditorConfiguration::setExtraEncodingSettings(const TextEditor::ExtraEncodi
emit extraEncodingSettingsChanged(d->m_extraEncodingSettings);
}
void EditorConfiguration::setMarginSettings(const MarginSettings &settings)
{
if (d->m_marginSettings != settings) {
d->m_marginSettings = settings;
emit marginSettingsChanged(d->m_marginSettings);
}
}
void EditorConfiguration::setTextCodec(QTextCodec *textCodec)
{
d->m_textCodec = textCodec;
}
void EditorConfiguration::setShowWrapColumn(bool onoff)
{
if (d->m_marginSettings.m_showMargin != onoff) {
d->m_marginSettings.m_showMargin = onoff;
emit marginSettingsChanged(d->m_marginSettings);
}
}
void EditorConfiguration::setWrapColumn(int column)
{
if (d->m_marginSettings.m_marginColumn != column) {
d->m_marginSettings.m_marginColumn = column;
emit marginSettingsChanged(d->m_marginSettings);
}
}
void EditorConfiguration::slotAboutToRemoveProject(ProjectExplorer::Project *project)
{
if (project->editorConfiguration() != this)
......
......@@ -46,6 +46,7 @@ class TypingSettings;
class StorageSettings;
class BehaviorSettings;
class ExtraEncodingSettings;
class MarginSettings;
}
namespace ProjectExplorer {
......@@ -72,6 +73,7 @@ public:
const TextEditor::StorageSettings &storageSettings() const;
const TextEditor::BehaviorSettings &behaviorSettings() const;
const TextEditor::ExtraEncodingSettings &extraEncodingSettings() const;
const TextEditor::MarginSettings &marginSettings() const;
TextEditor::ICodeStylePreferences *codeStyle() const;
TextEditor::ICodeStylePreferences *codeStyle(Core::Id languageId) const;
......@@ -88,6 +90,7 @@ signals:
void storageSettingsChanged(const TextEditor::StorageSettings &);
void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
void marginSettingsChanged(const TextEditor::MarginSettings &);
private slots:
......@@ -95,6 +98,10 @@ private slots:
void setStorageSettings(const TextEditor::StorageSettings &settings);
void setBehaviorSettings(const TextEditor::BehaviorSettings &settings);
void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &settings);
void setMarginSettings(const TextEditor::MarginSettings &settings);
void setShowWrapColumn(bool onoff);
void setWrapColumn(int column);
void setTextCodec(QTextCodec *textCodec);
......
......@@ -30,6 +30,7 @@
#include "editorsettingspropertiespage.h"
#include "editorconfiguration.h"
#include "project.h"
#include <texteditor/marginsettings.h>
#include <QTextCodec>
......@@ -78,6 +79,10 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
connect(m_ui.globalSelector, SIGNAL(activated(int)),
this, SLOT(globalSettingsActivated(int)));
connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues()));
connect(m_ui.showWrapColumn, SIGNAL(toggled(bool)), config, SLOT(setShowWrapColumn(bool)));
connect(m_ui.wrapColumn, SIGNAL(valueChanged(int)), config, SLOT(setWrapColumn(int)));
connect(m_ui.behaviorSettingsWidget, SIGNAL(typingSettingsChanged(TextEditor::TypingSettings)),
config, SLOT(setTypingSettings(TextEditor::TypingSettings)));
connect(m_ui.behaviorSettingsWidget, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
......@@ -92,6 +97,8 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
{
m_ui.showWrapColumn->setChecked(config->marginSettings().m_showMargin);
m_ui.wrapColumn->setValue(config->marginSettings().m_marginColumn);
m_ui.behaviorSettingsWidget->setCodeStyle(config->codeStyle());
m_ui.globalSelector->setCurrentIndex(config->useGlobalSettings() ? 0 : 1);
m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec());
......@@ -104,6 +111,7 @@ void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
void EditorSettingsWidget::globalSettingsActivated(int index)
{
const bool useGlobal = !index;
m_ui.displaySettings->setEnabled(!useGlobal);
m_ui.behaviorSettingsWidget->setActive(!useGlobal);
m_ui.restoreButton->setEnabled(!useGlobal);
EditorConfiguration *config = m_project->editorConfiguration();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>401</width>
<height>111</height>
<height>173</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
......@@ -56,9 +56,51 @@
</spacer>
</item>
<item row="1" column="0" colspan="4">
<widget class="QGroupBox" name="displaySettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Display Settings</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="showWrapColumn">
<property name="text">
<string>Display right &amp;margin at column:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="wrapColumn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>53</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="4">
<widget class="TextEditor::BehaviorSettingsWidget" name="behaviorSettingsWidget" native="true"/>
</item>
<item row="2" column="0">
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -82,5 +124,22 @@
</customwidget>
</customwidgets>
<resources/>
<connections/>
<connections>
<connection>
<sender>showWrapColumn</sender>
<signal>toggled(bool)</signal>
<receiver>wrapColumn</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>211</x>
<y>75</y>
</hint>
<hint type="destinationlabel">
<x>283</x>
<y>82</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -4532,6 +4532,10 @@ const DisplaySettings &BaseTextEditorWidget::displaySettings() const
return d->m_displaySettings;
}
const MarginSettings &BaseTextEditorWidget::marginSettings() const
{
return d->m_marginSettings;
}
void BaseTextEditorWidget::indentOrUnindent(bool doIndent)
{
......@@ -5389,7 +5393,7 @@ void BaseTextEditorWidget::format()
void BaseTextEditorWidget::rewrapParagraph()
{
const int paragraphWidth = displaySettings().m_wrapColumn;
const int paragraphWidth = marginSettings().m_marginColumn;
const QRegExp anyLettersOrNumbers = QRegExp(QLatin1String("\\w"));
const int tabSize = tabSettings().m_tabSize;
......@@ -5612,7 +5616,6 @@ void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{
setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap);
setLineNumbersVisible(ds.m_displayLineNumbers);
setVisibleWrapColumn(ds.m_showWrapColumn ? ds.m_wrapColumn : 0);
setHighlightCurrentLine(ds.m_highlightCurrentLine);
setRevisionsVisible(ds.m_markTextChanges);
setCenterOnScroll(ds.m_centerCursorOnScroll);
......@@ -5642,6 +5645,15 @@ void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
extraArea()->update();
}
void BaseTextEditorWidget::setMarginSettings(const MarginSettings &ms)
{
setVisibleWrapColumn(ms.m_showMargin ? ms.m_marginColumn : 0);
d->m_marginSettings = ms;
viewport()->update();
extraArea()->update();
}
void BaseTextEditorWidget::setBehaviorSettings(const TextEditor::BehaviorSettings &bs)
{
d->m_behaviorSettings = bs;
......
......@@ -75,6 +75,7 @@ class FontSettings;
class BehaviorSettings;
class CompletionSettings;
class DisplaySettings;
class MarginSettings;
class TypingSettings;
class StorageSettings;
class Indenter;
......@@ -396,6 +397,7 @@ public:
void setCodeStyle(ICodeStylePreferences *settings);
const DisplaySettings &displaySettings() const;
const MarginSettings &marginSettings() const;
void markBlocksAsChanged(QList<int> blockNumbers);
......@@ -436,6 +438,7 @@ public slots:
void setFontSettingsIfVisible(const TextEditor::FontSettings &);
virtual void setTabSettings(const TextEditor::TabSettings &);
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
virtual void setMarginSettings(const TextEditor::MarginSettings &);
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
virtual void setTypingSettings(const TextEditor::TypingSettings &);
virtual void setStorageSettings(const TextEditor::StorageSettings &);
......
......@@ -33,6 +33,7 @@
#include "basetexteditor.h"
#include "behaviorsettings.h"
#include "displaysettings.h"
#include "marginsettings.h"
#include "fontsettings.h"
#include "refactoroverlay.h"
......@@ -138,6 +139,7 @@ public:
Core::Id m_tabSettingsId;
ICodeStylePreferences *m_codeStylePreferences;
DisplaySettings m_displaySettings;
MarginSettings m_marginSettings;
FontSettings m_fontSettings;
BehaviorSettings m_behaviorSettings;
......
......@@ -34,8 +34,6 @@
static const char displayLineNumbersKey[] = "DisplayLineNumbers";
static const char textWrappingKey[] = "TextWrapping";
static const char showWrapColumnKey[] = "ShowWrapColumn";
static const char wrapColumnKey[] = "WrapColumn";
static const char visualizeWhitespaceKey[] = "VisualizeWhitespace";
static const char displayFoldingMarkersKey[] = "DisplayFoldingMarkers";
static const char highlightCurrentLineKey[] = "HighlightCurrentLine2Key";
......@@ -54,8 +52,6 @@ namespace TextEditor {
DisplaySettings::DisplaySettings() :
m_displayLineNumbers(true),
m_textWrapping(false),
m_showWrapColumn(false),
m_wrapColumn(80),
m_visualizeWhitespace(false),
m_displayFoldingMarkers(true),
m_highlightCurrentLine(false),
......@@ -79,8 +75,6 @@ void DisplaySettings::toSettings(const QString &category, QSettings *s) const
s->beginGroup(group);
s->setValue(QLatin1String(displayLineNumbersKey), m_displayLineNumbers);
s->setValue(QLatin1String(textWrappingKey), m_textWrapping);
s->setValue(QLatin1String(showWrapColumnKey), m_showWrapColumn);
s->setValue(QLatin1String(wrapColumnKey), m_wrapColumn);
s->setValue(QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace);
s->setValue(QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers);
s->setValue(QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine);
......@@ -106,8 +100,6 @@ void DisplaySettings::fromSettings(const QString &category, const QSettings *s)
m_displayLineNumbers = s->value(group + QLatin1String(displayLineNumbersKey), m_displayLineNumbers).toBool();
m_textWrapping = s->value(group + QLatin1String(textWrappingKey), m_textWrapping).toBool();
m_showWrapColumn = s->value(group + QLatin1String(showWrapColumnKey), m_showWrapColumn).toBool();
m_wrapColumn = s->value(group + QLatin1String(wrapColumnKey), m_wrapColumn).toInt();
m_visualizeWhitespace = s->value(group + QLatin1String(visualizeWhitespaceKey), m_visualizeWhitespace).toBool();
m_displayFoldingMarkers = s->value(group + QLatin1String(displayFoldingMarkersKey), m_displayFoldingMarkers).toBool();
m_highlightCurrentLine = s->value(group + QLatin1String(highlightCurrentLineKey), m_highlightCurrentLine).toBool();
......@@ -125,8 +117,6 @@ bool DisplaySettings::equals(const DisplaySettings &ds) const
{
return m_displayLineNumbers == ds.m_displayLineNumbers
&& m_textWrapping == ds.m_textWrapping
&& m_showWrapColumn == ds.m_showWrapColumn
&& m_wrapColumn == ds.m_wrapColumn
&& m_visualizeWhitespace == ds.m_visualizeWhitespace
&& m_displayFoldingMarkers == ds.m_displayFoldingMarkers
&& m_highlightCurrentLine == ds.m_highlightCurrentLine
......
......@@ -48,8 +48,6 @@ public:
bool m_displayLineNumbers;
bool m_textWrapping;
bool m_showWrapColumn;
int m_wrapColumn;
bool m_visualizeWhitespace;
bool m_displayFoldingMarkers;
bool m_highlightCurrentLine;
......
......@@ -29,6 +29,7 @@
#include "displaysettingspage.h"
#include "displaysettings.h"
#include "marginsettings.h"
#include "ui_displaysettingspage.h"
#include <coreplugin/icore.h>
......@@ -46,6 +47,7 @@ struct DisplaySettingsPage::DisplaySettingsPagePrivate
QPointer<QWidget> m_widget;
Internal::Ui::DisplaySettingsPage *m_page;
DisplaySettings m_displaySettings;
MarginSettings m_marginSettings;
};
DisplaySettingsPage::DisplaySettingsPagePrivate::DisplaySettingsPagePrivate
......@@ -53,6 +55,7 @@ DisplaySettingsPage::DisplaySettingsPagePrivate::DisplaySettingsPagePrivate
: m_parameters(p), m_page(0)
{
m_displaySettings.fromSettings(m_parameters.settingsPrefix, Core::ICore::settings());
m_marginSettings.fromSettings(m_parameters.settingsPrefix, Core::ICore::settings());
}
DisplaySettingsPage::DisplaySettingsPage(const DisplaySettingsPageParameters &p,
......@@ -85,9 +88,10 @@ void DisplaySettingsPage::apply()
if (!d->m_page) // page was never shown
return;
DisplaySettings newDisplaySettings;
MarginSettings newMarginSettings;
settingsFromUI(newDisplaySettings);
setDisplaySettings(newDisplaySettings);
settingsFromUI(newDisplaySettings, newMarginSettings);
setDisplaySettings(newDisplaySettings, newMarginSettings);
}
void DisplaySettingsPage::finish()
......@@ -99,12 +103,13 @@ void DisplaySettingsPage::finish()
d->m_page = 0;
}
void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const
void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings,
MarginSettings &marginSettings) const
{
displaySettings.m_displayLineNumbers = d->m_page->displayLineNumbers->isChecked();
displaySettings.m_textWrapping = d->m_page->enableTextWrapping->isChecked();
displaySettings.m_showWrapColumn = d->m_page->showWrapColumn->isChecked();
displaySettings.m_wrapColumn = d->m_page->wrapColumn->value();
marginSettings.m_showMargin = d->m_page->showWrapColumn->isChecked();
marginSettings.m_marginColumn = d->m_page->wrapColumn->value();
displaySettings.m_visualizeWhitespace = d->m_page->visualizeWhitespace->isChecked();
displaySettings.m_displayFoldingMarkers = d->m_page->displayFoldingMarkers->isChecked();
displaySettings.m_highlightCurrentLine = d->m_page->highlightCurrentLine->isChecked();
......@@ -121,10 +126,11 @@ void DisplaySettingsPage::settingsFromUI(DisplaySettings &displaySettings) const
void DisplaySettingsPage::settingsToUI()
{
const DisplaySettings &displaySettings = d->m_displaySettings;
const MarginSettings &marginSettings = d->m_marginSettings;
d->m_page->displayLineNumbers->setChecked(displaySettings.m_displayLineNumbers);
d->m_page->enableTextWrapping->setChecked(displaySettings.m_textWrapping);
d->m_page->showWrapColumn->setChecked(displaySettings.m_showWrapColumn);
d->m_page->wrapColumn->setValue(displaySettings.m_wrapColumn);
d->m_page->showWrapColumn->setChecked(marginSettings.m_showMargin);
d->m_page->wrapColumn->setValue(marginSettings.m_marginColumn);
d->m_page->visualizeWhitespace->setChecked(displaySettings.m_visualizeWhitespace);
d->m_page->displayFoldingMarkers->setChecked(displaySettings.m_displayFoldingMarkers);
d->m_page->highlightCurrentLine->setChecked(displaySettings.m_highlightCurrentLine);
......@@ -143,7 +149,13 @@ const DisplaySettings &DisplaySettingsPage::displaySettings() const
return d->m_displaySettings;
}
void DisplaySettingsPage::setDisplaySettings(const DisplaySettings &newDisplaySettings)
const MarginSettings &DisplaySettingsPage::marginSettings() const
{
return d->m_marginSettings;
}
void DisplaySettingsPage::setDisplaySettings(const DisplaySettings &newDisplaySettings,
const MarginSettings &newMarginSettings)
{
if (newDisplaySettings != d->m_displaySettings) {
d->m_displaySettings = newDisplaySettings;
......@@ -151,4 +163,11 @@ void DisplaySettingsPage::setDisplaySettings(const DisplaySettings &newDisplaySe
emit displaySettingsChanged(newDisplaySettings);
}
if (newMarginSettings != d->m_marginSettings) {
d->m_marginSettings = newMarginSettings;
d->m_marginSettings.toSettings(d->m_parameters.settingsPrefix, Core::ICore::settings());
emit marginSettingsChanged(newMarginSettings);
}
}
......@@ -37,6 +37,7 @@
namespace TextEditor {
class DisplaySettings;
class MarginSettings;
class DisplaySettingsPageParameters
{
......@@ -60,14 +61,16 @@ public:
void finish();
const DisplaySettings &displaySettings() const;
const MarginSettings &marginSettings() const;
signals:
void displaySettingsChanged(const TextEditor::DisplaySettings &);
void marginSettingsChanged(const TextEditor::MarginSettings &);
private:
void settingsFromUI(DisplaySettings &displaySettings) const;
void settingsFromUI(DisplaySettings &displaySettings, MarginSettings &marginSettings) const;
void settingsToUI();
void setDisplaySettings(const DisplaySettings &);
void setDisplaySettings(const DisplaySettings &, const MarginSettings &newMarginSettings);
struct DisplaySettingsPagePrivate;
DisplaySettingsPagePrivate *d;
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU Lesser General Public License Usage
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "marginsettings.h"
#include <QSettings>
#include <QString>
#include <QVariantMap>
static const char showWrapColumnKey[] = "ShowMargin";
static const char wrapColumnKey[] = "MarginColumn";
static const char groupPostfix[] = "MarginSettings";
using namespace TextEditor;
MarginSettings::MarginSettings()
: m_showMargin(false)
, m_marginColumn(80)
{
}
void MarginSettings::toSettings(const QString &category, QSettings *s) const
{
QString group = QLatin1String(groupPostfix);
if (!category.isEmpty())
group.insert(0, category);
s->beginGroup(group);
s->setValue(QLatin1String(showWrapColumnKey), m_showMargin);
s->setValue(QLatin1String(wrapColumnKey), m_marginColumn);
s->endGroup();
}
void MarginSettings::fromSettings(const QString &category, const QSettings *s)
{
QString group = QLatin1String(groupPostfix);
if (!category.isEmpty())
group.insert(0, category);
group += QLatin1Char('/');
*this = MarginSettings(); // Assign defaults
m_showMargin = s->value(group + QLatin1String(showWrapColumnKey), m_showMargin).toBool();
m_marginColumn = s->value(group + QLatin1String(wrapColumnKey), m_marginColumn).toInt();
}
void MarginSettings::toMap(const QString &prefix, QVariantMap *map) const
{
map->insert(prefix + QLatin1String(showWrapColumnKey), m_showMargin);
map->insert(prefix + QLatin1String(wrapColumnKey), m_marginColumn);
}
void MarginSettings::fromMap(const QString &prefix, const QVariantMap &map)
{
m_showMargin = map.value(prefix + QLatin1String(showWrapColumnKey), m_showMargin).toBool();
m_marginColumn = map.value(prefix + QLatin1String(wrapColumnKey), m_marginColumn).toInt();
}
bool MarginSettings::equals(const MarginSettings &other) const
{
return m_showMargin == other.m_showMargin
&& m_marginColumn == other.m_marginColumn
;
}
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU Lesser General Public License Usage
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef TEXTEDITOR_MARGINSETTINGS_H
#define TEXTEDITOR_MARGINSETTINGS_H
#include "texteditor_global.h"
#include <QVariantMap>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace TextEditor {
class TEXTEDITOR_EXPORT MarginSettings
{
public:
MarginSettings();
void toSettings(const QString &category, QSettings *s) const;
void fromSettings(const QString &category, const QSettings *s);
void toMap(const QString &prefix, QVariantMap *map) const;
void fromMap(const QString &prefix, const QVariantMap &map);
bool equals(const MarginSettings &other) const;
bool m_showMargin;
int m_marginColumn;
};
inline bool operator==(const MarginSettings &one, const MarginSettings &two)
{ return one.equals(two); }
inline bool operator!=(const MarginSettings &one, const MarginSettings &two)
{ return !one.equals(two); }
} // namespace TextEditor
#endif // TEXTEDITOR_MARGINSETTINGS_H
......@@ -107,7 +107,8 @@ SOURCES += texteditorplugin.cpp \
circularclipboard.cpp \
circularclipboardassist.cpp \
itextmark.cpp \
codeassist/keywordscompletionassist.cpp
codeassist/keywordscompletionassist.cpp \
marginsettings.cpp
HEADERS += texteditorplugin.h \
textfilewizard.h \
......@@ -224,7 +225,8 @@ HEADERS += texteditorplugin.h \
circularclipboardassist.h \
itextmark.h \
codeassist/keywordscompletionassist.h \
basetextmarkregistry.h
basetextmarkregistry.h \
marginsettings.h
FORMS += \
displaysettingspage.ui \
......
......@@ -33,6 +33,7 @@
#include "behaviorsettings.h"
#include "behaviorsettingspage.h"