aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-09-13 12:36:18 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-09-13 12:38:34 +0200
commit26114a23d0af8b876b85870e5e7777cbd9626e63 (patch)
tree44ef068fe4eb28dfa7fc93870f6e6ee5439870ae /src/plugins/texteditor
parent642b6fb0d3511f5d125c7079f8a3db77fc3c5da4 (diff)
Indenter: Add an option to control the padding style.
Reviewed-by: Thorbjorn Lindeijer
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/behaviorsettingspage.cpp2
-rw-r--r--src/plugins/texteditor/behaviorsettingspage.ui63
-rw-r--r--src/plugins/texteditor/tabsettings.cpp18
-rw-r--r--src/plugins/texteditor/tabsettings.h8
4 files changed, 72 insertions, 19 deletions
diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp
index 9595415fb0..57a911a8de 100644
--- a/src/plugins/texteditor/behaviorsettingspage.cpp
+++ b/src/plugins/texteditor/behaviorsettingspage.cpp
@@ -158,6 +158,7 @@ void BehaviorSettingsPage::settingsFromUI(TabSettings &tabSettings,
tabSettings.m_doubleIndentBlocks = m_d->m_page.indentBlocksBehavior->currentIndex() >= 2;
tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)m_d->m_page.tabKeyBehavior->currentIndex();
+ tabSettings.m_paddingMode = (TabSettings::PaddingMode)m_d->m_page.paddingMode->currentIndex();
storageSettings.m_cleanWhitespace = m_d->m_page.cleanWhitespace->isChecked();
storageSettings.m_inEntireDocument = m_d->m_page.inEntireDocument->isChecked();
@@ -181,6 +182,7 @@ void BehaviorSettingsPage::settingsToUI()
(tabSettings.m_doubleIndentBlocks ? 2 : 1)
: 0);
m_d->m_page.tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior);
+ m_d->m_page.paddingMode->setCurrentIndex(tabSettings.m_paddingMode);
const StorageSettings &storageSettings = m_d->m_storageSettings;
m_d->m_page.cleanWhitespace->setChecked(storageSettings.m_cleanWhitespace);
diff --git a/src/plugins/texteditor/behaviorsettingspage.ui b/src/plugins/texteditor/behaviorsettingspage.ui
index 8ccf21d507..2b5d2bd795 100644
--- a/src/plugins/texteditor/behaviorsettingspage.ui
+++ b/src/plugins/texteditor/behaviorsettingspage.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>550</width>
- <height>464</height>
+ <width>576</width>
+ <height>538</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@@ -179,14 +179,14 @@
</item>
</widget>
</item>
- <item row="1" column="0">
+ <item row="2" column="0">
<widget class="QLabel" name="tabKeyIndentLabel">
<property name="text">
<string>Tab key performs auto-indent:</string>
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="2" column="1">
<widget class="QComboBox" name="tabKeyBehavior">
<item>
<property name="text">
@@ -205,6 +205,41 @@
</item>
</widget>
</item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="paddingStyleLabel">
+ <property name="text">
+ <string>Padding style:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="paddingMode">
+ <property name="toolTip">
+ <string>Padding is the part of indentation exceeding logical indentation and is usually used to align consecutive lines of code.
+
+Disable Padding: Do not pad at all. Lines will only be indented to the current logical indentation depth.
+
+Pad With Spaces: Always use spaces for padding, regardless of the choice between tabs and spaces above.
+
+Pad With Indentation: Padding will be part of the indentation and follow the settings above.</string>
+ </property>
+ <item>
+ <property name="text">
+ <string>Disable Padding</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Pad With Spaces</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Pad With Indentation</string>
+ </property>
+ </item>
+ </widget>
+ </item>
</layout>
</item>
</layout>
@@ -339,10 +374,6 @@
</spacer>
</item>
</layout>
- <zorder>groupBoxTabAndIndentSettings</zorder>
- <zorder>groupBoxStorageSettings</zorder>
- <zorder>groupBoxMouse</zorder>
- <zorder>indentBlocksLabel</zorder>
</widget>
<tabstops>
<tabstop>insertSpaces</tabstop>
@@ -364,12 +395,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>67</x>
- <y>252</y>
+ <x>87</x>
+ <y>323</y>
</hint>
<hint type="destinationlabel">
- <x>148</x>
- <y>281</y>
+ <x>205</x>
+ <y>353</y>
</hint>
</hints>
</connection>
@@ -380,12 +411,12 @@
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>40</x>
- <y>251</y>
+ <x>60</x>
+ <y>323</y>
</hint>
<hint type="destinationlabel">
- <x>77</x>
- <y>310</y>
+ <x>134</x>
+ <y>384</y>
</hint>
</hints>
</connection>
diff --git a/src/plugins/texteditor/tabsettings.cpp b/src/plugins/texteditor/tabsettings.cpp
index b9772bb37a..6277030eb1 100644
--- a/src/plugins/texteditor/tabsettings.cpp
+++ b/src/plugins/texteditor/tabsettings.cpp
@@ -45,6 +45,7 @@ static const char *indentBracesKey = "IndentBraces";
static const char *doubleIndentBlocksKey = "DoubleIndentBlocks";
static const char *tabKeyBehaviorKey = "TabKeyBehavior";
static const char *groupPostfix = "TabSettings";
+static const char *paddingModeKey = "PaddingMode";
namespace TextEditor {
@@ -57,7 +58,8 @@ TabSettings::TabSettings() :
m_indentSize(4),
m_indentBraces(false),
m_doubleIndentBlocks(false),
- m_tabKeyBehavior(TabNeverIndents)
+ m_tabKeyBehavior(TabNeverIndents),
+ m_paddingMode(PadWithSpaces)
{
}
@@ -76,6 +78,7 @@ void TabSettings::toSettings(const QString &category, QSettings *s) const
s->setValue(QLatin1String(indentBracesKey), m_indentBraces);
s->setValue(QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks);
s->setValue(QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior);
+ s->setValue(QLatin1String(paddingModeKey), m_paddingMode);
s->endGroup();
}
@@ -99,6 +102,7 @@ void TabSettings::fromSettings(const QString &category, const QSettings *s)
= s->value(group + QLatin1String(doubleIndentBlocksKey), m_doubleIndentBlocks).toBool();
m_tabKeyBehavior = (TabKeyBehavior)s->value(group + QLatin1String(tabKeyBehaviorKey), m_tabKeyBehavior).toInt();
+ m_paddingMode = (PaddingMode)s->value(group + QLatin1String(paddingModeKey), m_paddingMode).toInt();
}
@@ -319,13 +323,20 @@ void TabSettings::indentLine(QTextBlock block, int newIndent, int padding) const
const QString text = block.text();
const int oldBlockLength = text.size();
+ if (m_paddingMode == DisablePadding) {
+ newIndent -= padding;
+ padding = 0;
+ } else if (m_paddingMode == PadWithIndent) {
+ padding = 0;
+ }
+
// Quickly check whether indenting is required.
if (indentationColumn(text) == newIndent)
return;
QString indentString;
- if (!m_spacesForTabs && m_tabSize == m_indentSize) {
+ if (!m_spacesForTabs) {
// user likes tabs for spaces and uses tabs for indentation, preserve padding
indentString = indentationString(0, newIndent - padding, block);
indentString += QString(padding, QLatin1Char(' '));
@@ -388,7 +399,8 @@ bool TabSettings::equals(const TabSettings &ts) const
&& m_indentSize == ts.m_indentSize
&& m_indentBraces == ts.m_indentBraces
&& m_doubleIndentBlocks == ts.m_doubleIndentBlocks
- && m_tabKeyBehavior == ts.m_tabKeyBehavior;
+ && m_tabKeyBehavior == ts.m_tabKeyBehavior
+ && m_paddingMode == ts.m_paddingMode;
}
} // namespace TextEditor
diff --git a/src/plugins/texteditor/tabsettings.h b/src/plugins/texteditor/tabsettings.h
index 75ec461f0c..66c7fa0e6a 100644
--- a/src/plugins/texteditor/tabsettings.h
+++ b/src/plugins/texteditor/tabsettings.h
@@ -52,6 +52,13 @@ public:
TabLeadingWhitespaceIndents = 2
};
+ // This enum must match the indexes of paddingMode widget
+ enum PaddingMode {
+ DisablePadding = 0,
+ PadWithSpaces = 1,
+ PadWithIndent = 2
+ };
+
TabSettings();
void toSettings(const QString &category, QSettings *s) const;
@@ -89,6 +96,7 @@ public:
bool m_indentBraces;
bool m_doubleIndentBlocks;
TabKeyBehavior m_tabKeyBehavior;
+ PaddingMode m_paddingMode;
bool equals(const TabSettings &ts) const;
};