From 779fafcbfe6f92dd1288664fae512f69bc12418b Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Thu, 3 Feb 2011 15:48:14 +0100
Subject: [PATCH] Make C++ code style configurable.

Change-Id: Iaf08edb2361146e6b5e1cbafdb716a23c938875b
Done-with: Jarek Kobus
Task-number: QTCREATORBUG-2670
Task-number: QTCREATORBUG-4310
Task-number: QTCREATORBUG-2763
Task-number: QTCREATORBUG-3623
Task-number: QTCREATORBUG-567
Reviewed-on: http://codereview.qt.nokia.com/74
Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
---
 src/libs/qmljs/qmljscodeformatter.cpp         |   3 +-
 src/plugins/cppeditor/cppeditor.cpp           |  11 +-
 src/plugins/cppeditor/cppeditor.h             |   3 +
 src/plugins/cppeditor/cppeditor.pro           |   2 -
 src/plugins/cppeditor/cppplugin.cpp           |   3 +
 src/plugins/cppeditor/cppsnippetprovider.cpp  |   5 +-
 src/plugins/cpptools/cppcodeformatter.cpp     | 307 ++++----
 src/plugins/cpptools/cppcodeformatter.h       |  28 +-
 .../cpptools/cppcodestylepreferences.cpp      |  86 +++
 .../cpptools/cppcodestylepreferences.h        |  48 ++
 src/plugins/cpptools/cppcodestylesettings.cpp | 133 ++++
 src/plugins/cpptools/cppcodestylesettings.h   |  67 ++
 .../cpptools/cppcodestylesettingsfactory.cpp  |  45 ++
 .../cpptools/cppcodestylesettingsfactory.h    |  24 +
 .../cpptools/cppcodestylesettingspage.cpp     | 536 +++++++++++++
 .../cpptools/cppcodestylesettingspage.h       |  98 +++
 .../cpptools/cppcodestylesettingspage.ui      | 436 +++++++++++
 src/plugins/cpptools/cppfilesettingspage.cpp  |   4 +-
 .../cppqtstyleindenter.cpp                    |  33 +-
 .../cppqtstyleindenter.h                      |  20 +-
 .../cpptools/cpprefactoringchanges.cpp        |   7 +-
 src/plugins/cpptools/cpptools.pro             |  19 +-
 src/plugins/cpptools/cpptoolsconstants.h      |   9 +-
 src/plugins/cpptools/cpptoolsplugin.cpp       |  11 +
 src/plugins/cpptools/cpptoolsplugin.h         |   4 +
 src/plugins/cpptools/cpptoolssettings.cpp     |  80 ++
 src/plugins/cpptools/cpptoolssettings.h       |  80 ++
 src/plugins/fakevim/fakevimplugin.cpp         |   3 +-
 src/plugins/glsleditor/glslindenter.cpp       |  10 +-
 .../codestylesettingspropertiespage.cpp       |  62 ++
 .../codestylesettingspropertiespage.h         |  41 +
 .../codestylesettingspropertiespage.ui        |  47 ++
 .../projectexplorer/editorconfiguration.cpp   | 304 ++++----
 .../projectexplorer/editorconfiguration.h     |  37 +-
 .../editorsettingspropertiespage.cpp          |  43 +-
 .../images/CodeStyleSettings.png              | Bin 0 -> 932 bytes
 .../projectexplorer/projectexplorer.cpp       |   2 +
 .../projectexplorer/projectexplorer.pro       |   9 +-
 src/plugins/projectexplorer/session.cpp       |   5 +-
 src/plugins/qmldesigner/settingspage.cpp      |   2 +-
 src/plugins/qmljseditor/qmljseditor.cpp       |  10 +-
 src/plugins/qmljseditor/qmljseditor.h         |   1 +
 src/plugins/qmljseditor/qmljseditor.pro       |   2 -
 src/plugins/qmljseditor/qmljseditorplugin.cpp |   2 +
 .../qmljseditor/qmljssnippetprovider.cpp      |   3 +-
 .../qmljseditor/quicktoolbarsettingspage.cpp  |   2 +-
 .../qmljstools/qmljscodestylesettingspage.cpp | 197 +++++
 .../qmljstools/qmljscodestylesettingspage.h   |  77 ++
 .../qmljstools/qmljscodestylesettingspage.ui  |  67 ++
 .../qmljsindenter.cpp                         |   0
 .../qmljsindenter.h                           |   4 +-
 .../qmljstools/qmljsrefactoringchanges.cpp    |   1 +
 src/plugins/qmljstools/qmljstools-lib.pri     |  11 +-
 src/plugins/qmljstools/qmljstoolsconstants.h  |   6 +
 src/plugins/qmljstools/qmljstoolsplugin.cpp   |   6 +
 src/plugins/texteditor/basetexteditor.cpp     |  47 ++
 src/plugins/texteditor/basetexteditor.h       |   9 +
 src/plugins/texteditor/basetexteditor_p.h     |   3 +
 .../texteditor/behaviorsettingspage.cpp       |  46 +-
 src/plugins/texteditor/behaviorsettingspage.h |   6 +-
 .../texteditor/behaviorsettingswidget.cpp     | 104 +--
 .../texteditor/behaviorsettingswidget.h       |  35 +-
 .../texteditor/behaviorsettingswidget.ui      | 571 +++-----------
 .../codestylepreferencesmanager.cpp           |  54 ++
 .../texteditor/codestylepreferencesmanager.h  |  36 +
 .../texteditor/fallbackselectorwidget.cpp     | 125 +++
 .../texteditor/fallbackselectorwidget.h       |  55 ++
 .../icodestylepreferencesfactory.cpp          |   9 +
 .../texteditor/icodestylepreferencesfactory.h |  27 +
 .../texteditor/ifallbackpreferences.cpp       | 135 ++++
 src/plugins/texteditor/ifallbackpreferences.h |  69 ++
 src/plugins/texteditor/indenter.cpp           |   5 +
 src/plugins/texteditor/indenter.h             |   3 +
 src/plugins/texteditor/tabpreferences.cpp     |  88 +++
 src/plugins/texteditor/tabpreferences.h       |  47 ++
 .../texteditor/tabpreferenceswidget.cpp       |  93 +++
 src/plugins/texteditor/tabpreferenceswidget.h |  46 ++
 .../texteditor/tabpreferenceswidget.ui        |  44 ++
 src/plugins/texteditor/tabsettings.cpp        |   8 +-
 src/plugins/texteditor/tabsettings.h          |   2 +
 src/plugins/texteditor/tabsettingswidget.cpp  | 122 +++
 src/plugins/texteditor/tabsettingswidget.h    |  47 ++
 src/plugins/texteditor/tabsettingswidget.ui   | 288 +++++++
 src/plugins/texteditor/texteditor.pro         |  22 +-
 src/plugins/texteditor/texteditorsettings.cpp |  56 +-
 src/plugins/texteditor/texteditorsettings.h   |  18 +-
 .../codeformatter/tst_codeformatter.cpp       | 711 +++++++++++++++++-
 87 files changed, 5022 insertions(+), 965 deletions(-)
 create mode 100644 src/plugins/cpptools/cppcodestylepreferences.cpp
 create mode 100644 src/plugins/cpptools/cppcodestylepreferences.h
 create mode 100644 src/plugins/cpptools/cppcodestylesettings.cpp
 create mode 100644 src/plugins/cpptools/cppcodestylesettings.h
 create mode 100644 src/plugins/cpptools/cppcodestylesettingsfactory.cpp
 create mode 100644 src/plugins/cpptools/cppcodestylesettingsfactory.h
 create mode 100644 src/plugins/cpptools/cppcodestylesettingspage.cpp
 create mode 100644 src/plugins/cpptools/cppcodestylesettingspage.h
 create mode 100644 src/plugins/cpptools/cppcodestylesettingspage.ui
 rename src/plugins/{cppeditor => cpptools}/cppqtstyleindenter.cpp (82%)
 rename src/plugins/{cppeditor => cpptools}/cppqtstyleindenter.h (82%)
 create mode 100644 src/plugins/cpptools/cpptoolssettings.cpp
 create mode 100644 src/plugins/cpptools/cpptoolssettings.h
 create mode 100644 src/plugins/projectexplorer/codestylesettingspropertiespage.cpp
 create mode 100644 src/plugins/projectexplorer/codestylesettingspropertiespage.h
 create mode 100644 src/plugins/projectexplorer/codestylesettingspropertiespage.ui
 create mode 100644 src/plugins/projectexplorer/images/CodeStyleSettings.png
 create mode 100644 src/plugins/qmljstools/qmljscodestylesettingspage.cpp
 create mode 100644 src/plugins/qmljstools/qmljscodestylesettingspage.h
 create mode 100644 src/plugins/qmljstools/qmljscodestylesettingspage.ui
 rename src/plugins/{qmljseditor => qmljstools}/qmljsindenter.cpp (100%)
 rename src/plugins/{qmljseditor => qmljstools}/qmljsindenter.h (95%)
 create mode 100644 src/plugins/texteditor/codestylepreferencesmanager.cpp
 create mode 100644 src/plugins/texteditor/codestylepreferencesmanager.h
 create mode 100644 src/plugins/texteditor/fallbackselectorwidget.cpp
 create mode 100644 src/plugins/texteditor/fallbackselectorwidget.h
 create mode 100644 src/plugins/texteditor/icodestylepreferencesfactory.cpp
 create mode 100644 src/plugins/texteditor/icodestylepreferencesfactory.h
 create mode 100644 src/plugins/texteditor/ifallbackpreferences.cpp
 create mode 100644 src/plugins/texteditor/ifallbackpreferences.h
 create mode 100644 src/plugins/texteditor/tabpreferences.cpp
 create mode 100644 src/plugins/texteditor/tabpreferences.h
 create mode 100644 src/plugins/texteditor/tabpreferenceswidget.cpp
 create mode 100644 src/plugins/texteditor/tabpreferenceswidget.h
 create mode 100644 src/plugins/texteditor/tabpreferenceswidget.ui
 create mode 100644 src/plugins/texteditor/tabsettingswidget.cpp
 create mode 100644 src/plugins/texteditor/tabsettingswidget.h
 create mode 100644 src/plugins/texteditor/tabsettingswidget.ui

diff --git a/src/libs/qmljs/qmljscodeformatter.cpp b/src/libs/qmljs/qmljscodeformatter.cpp
index 8187b722ac2..0d4c74bd585 100644
--- a/src/libs/qmljs/qmljscodeformatter.cpp
+++ b/src/libs/qmljs/qmljscodeformatter.cpp
@@ -41,7 +41,8 @@
 using namespace QmlJS;
 
 CodeFormatter::BlockData::BlockData()
-    : m_blockRevision(-1)
+    : m_indentDepth(0)
+    , m_blockRevision(-1)
 {
 }
 
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 0e63fffcd4a..794cf1be9d8 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -36,7 +36,6 @@
 #include "cpphighlighter.h"
 #include "cppchecksymbols.h"
 #include "cpplocalsymbols.h"
-#include "cppqtstyleindenter.h"
 #include "cppautocompleter.h"
 #include "cppquickfixassistant.h"
 
@@ -66,6 +65,8 @@
 #include <cpptools/cpptoolsconstants.h>
 #include <cpptools/cppcodeformatter.h>
 #include <cpptools/cppcompletionassist.h>
+#include <cpptools/cppqtstyleindenter.h>
+#include <cpptools/cppcodestylesettings.h>
 
 #include <coreplugin/icore.h>
 #include <coreplugin/actionmanager/actionmanager.h>
@@ -423,7 +424,7 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent)
     setParenthesesMatchingEnabled(true);
     setMarksVisible(true);
     setCodeFoldingSupported(true);
-    setIndenter(new CppQtStyleIndenter);
+    setIndenter(new CppTools::CppQtStyleIndenter);
     setAutoCompleter(new CppAutoCompleter);
 
     baseTextDocument()->setSyntaxHighlighter(new CppHighlighter);
@@ -1814,6 +1815,12 @@ void CPPEditorWidget::unCommentSelection()
     Utils::unCommentSelection(this);
 }
 
+void CPPEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
+{
+    CppTools::QtStyleCodeFormatter formatter;
+    formatter.invalidateCache(document());
+}
+
 CPPEditorWidget::Link CPPEditorWidget::linkToSymbol(CPlusPlus::Symbol *symbol)
 {
     if (!symbol)
diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h
index 7ac1eee8e65..6b7cc87de12 100644
--- a/src/plugins/cppeditor/cppeditor.h
+++ b/src/plugins/cppeditor/cppeditor.h
@@ -61,6 +61,7 @@ class Symbol;
 
 namespace CppTools {
 class CppModelManagerInterface;
+class CppCodeStyleSettings;
 }
 
 namespace TextEditor {
@@ -216,6 +217,8 @@ protected:
 
     const CPlusPlus::Macro *findCanonicalMacro(const QTextCursor &cursor,
                                                CPlusPlus::Document::Ptr doc) const;
+protected Q_SLOTS:
+    void slotCodeStyleSettingsChanged(const QVariant &);
 
 private Q_SLOTS:
     void updateFileName();
diff --git a/src/plugins/cppeditor/cppeditor.pro b/src/plugins/cppeditor/cppeditor.pro
index 0431b33ee5d..48e114ab826 100644
--- a/src/plugins/cppeditor/cppeditor.pro
+++ b/src/plugins/cppeditor/cppeditor.pro
@@ -21,7 +21,6 @@ HEADERS += cppplugin.h \
     cpplocalsymbols.h \
     cpptypehierarchy.h \
     cppelementevaluator.h \
-    cppqtstyleindenter.h \
     cppautocompleter.h \
     cppcompleteswitch.h \
     cppsnippetprovider.h \
@@ -43,7 +42,6 @@ SOURCES += cppplugin.cpp \
     cpplocalsymbols.cpp \
     cpptypehierarchy.cpp \
     cppelementevaluator.cpp \
-    cppqtstyleindenter.cpp \
     cppautocompleter.cpp \
     cppcompleteswitch.cpp \
     cppsnippetprovider.cpp \
diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp
index 2612fd01e6b..c35b5272c9d 100644
--- a/src/plugins/cppeditor/cppplugin.cpp
+++ b/src/plugins/cppeditor/cppplugin.cpp
@@ -54,6 +54,7 @@
 #include <coreplugin/progressmanager/progressmanager.h>
 #include <coreplugin/navigationwidget.h>
 #include <texteditor/fontsettings.h>
+#include <texteditor/tabpreferences.h>
 #include <texteditor/storagesettings.h>
 #include <texteditor/texteditoractionhandler.h>
 #include <texteditor/texteditorplugin.h>
@@ -61,6 +62,7 @@
 #include <texteditor/texteditorconstants.h>
 #include <cplusplus/ModelManagerInterface.h>
 #include <cpptools/cpptoolsconstants.h>
+#include <cpptools/cpptoolssettings.h>
 
 #include <QtCore/QFileInfo>
 #include <QtCore/QSettings>
@@ -170,6 +172,7 @@ void CppPlugin::initializeEditor(CPPEditorWidget *editor)
 {
     m_actionHandler->setupActions(editor);
 
+    editor->setLanguageSettingsId(CppTools::Constants::CPP_SETTINGS_ID);
     TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
 
     // method combo box sorting
diff --git a/src/plugins/cppeditor/cppsnippetprovider.cpp b/src/plugins/cppeditor/cppsnippetprovider.cpp
index 47adad9cfe2..eb3c420af28 100644
--- a/src/plugins/cppeditor/cppsnippetprovider.cpp
+++ b/src/plugins/cppeditor/cppsnippetprovider.cpp
@@ -33,10 +33,11 @@
 #include "cppsnippetprovider.h"
 #include "cpphighlighter.h"
 #include "cppeditor.h"
-#include "cppqtstyleindenter.h"
 #include "cppautocompleter.h"
 #include "cppeditorconstants.h"
 
+#include <cpptools/cppqtstyleindenter.h>
+
 #include <texteditor/texteditorsettings.h>
 #include <texteditor/fontsettings.h>
 #include <texteditor/texteditorconstants.h>
@@ -73,6 +74,6 @@ void CppSnippetProvider::decorateEditor(TextEditor::SnippetEditorWidget *editor)
         fs.toTextCharFormats(CPPEditorWidget::highlighterFormatCategories());
     highlighter->setFormats(formats.constBegin(), formats.constEnd());
     editor->setSyntaxHighlighter(highlighter);
-    editor->setIndenter(new CppQtStyleIndenter);
+    editor->setIndenter(new CppTools::CppQtStyleIndenter);
     editor->setAutoCompleter(new CppAutoCompleter);
 }
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp
index fecee6d0436..b477cf06bb6 100644
--- a/src/plugins/cpptools/cppcodeformatter.cpp
+++ b/src/plugins/cpptools/cppcodeformatter.cpp
@@ -44,6 +44,8 @@
 #include <QtGui/QTextCursor>
 #include <QtGui/QTextBlock>
 
+#include "cppcodestylesettingspage.h"
+
 using namespace CPlusPlus;
 using namespace CppTools;
 using namespace TextEditor;
@@ -177,26 +179,25 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
             } break;
 
         case declaration_start:
-            if (tryExpression(true))
-                break;
             switch (kind) {
             case T_RBRACE:      leave(true); continue;
             case T_SEMICOLON:   leave(true); break;
-            case T_EQUAL:       enter(initializer); break;
+            case T_EQUAL:       enter(assign_open_or_initializer); break;
             case T_LBRACE:      enter(defun_open); break;
             case T_COLON:       enter(member_init_open); enter(member_init); break;
             case T_OPERATOR:    enter(operator_declaration); break;
+            default:            tryExpression(true); break;
             } break;
 
-        case initializer:
+        case assign_open_or_initializer:
             switch (kind) {
             case T_LBRACE:      enter(brace_list_open); break;
-            default:            turnInto(expression); continue;
+            case T_RBRACE:      leave(true); continue;
+            case T_SEMICOLON:   leave(); continue;
+            default:            enter(assign_open); continue;
             } break;
 
         case expression:
-            if (tryExpression())
-                break;
             switch (kind) {
             case T_RBRACE:      leave(true); continue;
             case T_SEMICOLON:   leave(); continue;
@@ -208,30 +209,34 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
                     continue;
                 }
                 break;
+            default:            tryExpression(); break;
+            } break;
+
+        case assign_open:
+            switch (kind) {
+            case T_RBRACE:      leave(true); continue;
+            case T_SEMICOLON:   leave(); continue;
+            default:            tryExpression(); break;
             } break;
 
         case arglist_open:
-            if (tryExpression())
-                break;
             switch (kind) {
             case T_SEMICOLON:   leave(true); break;
             case T_RBRACE:      leave(true); continue;
             case T_RPAREN:      leave(); break;
+            default:            tryExpression(); break;
             } break;
 
         case ternary_op:
-            if (tryExpression())
-                break;
             switch (kind) {
             case T_RPAREN:
             case T_COMMA:
             case T_SEMICOLON:   leave(); continue; // always nested, propagate
+            default:            tryExpression(); break;
             } break;
 
         case stream_op:
         case stream_op_cont:
-            if (kind != T_LESS_LESS && kind != T_GREATER_GREATER && tryExpression())
-                break;
             switch (kind) {
             case T_LESS_LESS:
             case T_GREATER_GREATER:
@@ -243,6 +248,7 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
             case T_RPAREN:
             case T_COMMA:
             case T_SEMICOLON:   leave(); continue; // always nested, propagate
+            default:            tryExpression(); break;
             } break;
 
         case member_init_open:
@@ -261,11 +267,10 @@ void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
             } break;
 
         case member_init_paren_open:
-            if (tryExpression())
-                break;
             switch (kind) {
             case T_RPAREN:      leave(); continue;
             case T_SEMICOLON:   leave(); continue; // try to recover
+            default:            tryExpression(); break;
             } break;
 
         case defun_open:
@@ -681,6 +686,22 @@ bool CodeFormatter::tryExpression(bool alsoExpression)
     case T_LPAREN:          newState = arglist_open; break;
     case T_QUESTION:        newState = ternary_op; break;
 
+    case T_EQUAL:
+    case T_AMPER_EQUAL:
+    case T_CARET_EQUAL:
+    case T_SLASH_EQUAL:
+    case T_EXCLAIM_EQUAL:
+    case T_GREATER_GREATER_EQUAL:
+    case T_LESS_LESS_EQUAL:
+    case T_MINUS_EQUAL:
+    case T_PERCENT_EQUAL:
+    case T_PIPE_EQUAL:
+    case T_PLUS_EQUAL:
+    case T_STAR_EQUAL:
+    case T_TILDE_EQUAL:
+        newState = assign_open;
+        break;
+
     case T_LESS_LESS:
     case T_GREATER_GREATER:
         newState = stream_op;
@@ -977,63 +998,26 @@ namespace Internal {
 }
 
 QtStyleCodeFormatter::QtStyleCodeFormatter()
-    : m_indentSize(4)
-    , m_indentSubstatementBraces(false)
-    , m_indentSubstatementStatements(true)
-    , m_indentDeclarationBraces(false)
-    , m_indentDeclarationMembers(true)
 {
 }
 
-QtStyleCodeFormatter::QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings)
-    : m_indentSize(tabSettings.m_indentSize)
-    , m_indentSubstatementBraces(false)
-    , m_indentSubstatementStatements(true)
-    , m_indentDeclarationBraces(false)
-    , m_indentDeclarationMembers(true)
+QtStyleCodeFormatter::QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings,
+                                           const CppCodeStyleSettings &settings)
+    : m_tabSettings(tabSettings)
+    , m_styleSettings(settings)
 {
     setTabSize(tabSettings.m_tabSize);
-    if (tabSettings.m_indentBraces && tabSettings.m_doubleIndentBlocks) { // gnu style
-        setIndentSubstatementBraces(true);
-        setIndentSubstatementStatements(true);
-        setIndentDeclarationBraces(false);
-        setIndentDeclarationMembers(true);
-    } else if (tabSettings.m_indentBraces) { // whitesmiths style
-        setIndentSubstatementBraces(true);
-        setIndentSubstatementStatements(false);
-        setIndentDeclarationBraces(true);
-        setIndentDeclarationMembers(false);
-    } else { // default Qt style
-        setIndentSubstatementBraces(false);
-        setIndentSubstatementStatements(true);
-        setIndentDeclarationBraces(false);
-        setIndentDeclarationMembers(true);
-    }
 }
 
-void QtStyleCodeFormatter::setIndentSize(int size)
+void QtStyleCodeFormatter::setTabSettings(const TextEditor::TabSettings &tabSettings)
 {
-    m_indentSize = size;
-}
-
-void QtStyleCodeFormatter::setIndentSubstatementBraces(bool onOff)
-{
-    m_indentSubstatementBraces = onOff;
-}
-
-void QtStyleCodeFormatter::setIndentSubstatementStatements(bool onOff)
-{
-    m_indentSubstatementStatements = onOff;
-}
-
-void QtStyleCodeFormatter::setIndentDeclarationBraces(bool onOff)
-{
-    m_indentDeclarationBraces = onOff;
+    m_tabSettings = tabSettings;
+    setTabSize(tabSettings.m_tabSize);
 }
 
-void QtStyleCodeFormatter::setIndentDeclarationMembers(bool onOff)
+void QtStyleCodeFormatter::setCodeStyleSettings(const CppCodeStyleSettings &settings)
 {
-    m_indentDeclarationMembers = onOff;
+    m_styleSettings = settings;
 }
 
 void QtStyleCodeFormatter::saveBlockData(QTextBlock *block, const BlockData &data) const
@@ -1100,7 +1084,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
             *savedIndentDepth = tokenPosition;
             *indentDepth = tokenPosition;
         }
-        *paddingDepth = 2*m_indentSize;
+        *paddingDepth = 2*m_tabSettings.m_indentSize;
         break;
 
     case template_param:
@@ -1108,9 +1092,9 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
             *paddingDepth = nextTokenPosition-*indentDepth;
         else {
             if (*paddingDepth == 0)
-                *paddingDepth = 2*m_indentSize;
+                *paddingDepth = 2*m_tabSettings.m_indentSize;
             else
-                *paddingDepth += m_indentSize;
+                *paddingDepth += m_tabSettings.m_indentSize;
         }
         break;
 
@@ -1121,7 +1105,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
     case return_statement:
         if (firstToken)
             *indentDepth = *savedIndentDepth = tokenPosition;
-        *paddingDepth = 2*m_indentSize;
+        *paddingDepth = 2*m_tabSettings.m_indentSize;
         break;
 
     case declaration_start:
@@ -1133,25 +1117,36 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
         // after the return type in "void\nfoo() {}"
         for (int i = 0; state(i).type != topmost_intro; ++i) {
             if (state(i).type == defun_open) {
-                *paddingDepth = 2*m_indentSize;
+                *paddingDepth = 2*m_tabSettings.m_indentSize;
                 break;
             }
         }
         break;
 
+    case assign_open:
+        if (parentState.type == assign_open_or_initializer)
+            break;
+        // fallthrough
+    case assign_open_or_initializer:
+        if (!lastToken && m_styleSettings.alignAssignments)
+            *paddingDepth = nextTokenPosition-*indentDepth;
+        else
+            *paddingDepth = 2*m_tabSettings.m_indentSize;
+        break;
+
     case arglist_open:
     case condition_paren_open:
         if (!lastToken)
             *paddingDepth = nextTokenPosition-*indentDepth;
         else
-            *paddingDepth += m_indentSize;
+            *paddingDepth += m_tabSettings.m_indentSize;
         break;
 
     case ternary_op:
         if (!lastToken)
             *paddingDepth = spaceOrNextTokenPosition-*indentDepth;
         else
-            *paddingDepth += m_indentSize;
+            *paddingDepth += m_tabSettings.m_indentSize;
         break;
 
     case stream_op:
@@ -1169,7 +1164,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
         if (firstToken)
             *paddingDepth = tokenPosition-*indentDepth;
         else
-            *paddingDepth = m_indentSize - 2; // they'll get another 2 from member_init
+            *paddingDepth = m_tabSettings.m_indentSize - 2; // they'll get another 2 from member_init
         break;
 
     case member_init:
@@ -1177,24 +1172,45 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
         break;
 
     case member_init_paren_open:
-        *paddingDepth += m_indentSize;
+        *paddingDepth += m_tabSettings.m_indentSize;
         break;
 
     case case_cont:
-        *indentDepth += m_indentSize;
+        if (m_styleSettings.indentStatementsRelativeToSwitchLabels)
+            *indentDepth += m_tabSettings.m_indentSize;
         break;
 
+    case namespace_open:
     case class_open:
     case enum_open:
     case defun_open: {
         // undo the continuation indent of the parent
         *savedPaddingDepth = 0;
 
+        // whether the { is followed by a non-comment token
         bool followedByData = (!lastToken && !tokenAt(tokenIndex() + 1).isComment());
         if (followedByData)
-            *savedPaddingDepth = tokenPosition-*indentDepth;
-
-        *indentDepth += m_indentSize;
+            *savedPaddingDepth = tokenPosition-*indentDepth; // pad the } to align with the {
+
+        if (newState == class_open) {
+            if (m_styleSettings.indentAccessSpecifiers
+                    || m_styleSettings.indentDeclarationsRelativeToAccessSpecifiers)
+                *indentDepth += m_tabSettings.m_indentSize;
+            if (m_styleSettings.indentAccessSpecifiers && m_styleSettings.indentDeclarationsRelativeToAccessSpecifiers)
+                *indentDepth += m_tabSettings.m_indentSize;
+        } else if (newState == defun_open) {
+            if (m_styleSettings.indentFunctionBody || m_styleSettings.indentFunctionBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+            if (m_styleSettings.indentFunctionBody && m_styleSettings.indentFunctionBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+        } else if (newState == namespace_open) {
+            if (m_styleSettings.indentNamespaceBody || m_styleSettings.indentNamespaceBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+            if (m_styleSettings.indentNamespaceBody && m_styleSettings.indentNamespaceBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+        } else {
+            *indentDepth += m_tabSettings.m_indentSize;
+        }
 
         if (followedByData) {
             *paddingDepth = nextTokenPosition-*indentDepth;
@@ -1206,42 +1222,40 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
         // undo parent continuation indent
         *savedPaddingDepth = 0;
 
-        if (firstToken) {
-            *savedIndentDepth = tokenPosition;
-            *indentDepth = *savedIndentDepth;
-        } else if (m_indentSubstatementBraces && !m_indentSubstatementStatements) {
-            // ### The preceding check is quite arbitrary.
-            // It actually needs another flag to determine whether the closing curly
-            // should be indented or not
-            *indentDepth = *savedIndentDepth += m_indentSize;
-        }
-
-        if (m_indentSubstatementStatements) {
-            if (parentState.type != switch_statement)
-                *indentDepth += m_indentSize;
+        if (parentState.type == switch_statement) {
+            if (m_styleSettings.indentSwitchLabels)
+                *indentDepth += m_tabSettings.m_indentSize;
+        } else {
+            if (m_styleSettings.indentBlockBody || m_styleSettings.indentBlockBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+            if (m_styleSettings.indentBlockBody && m_styleSettings.indentBlockBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
         }
         break;
 
     case brace_list_open:
         if (!lastToken) {
-            if (parentState.type == initializer)
+            if (parentState.type == assign_open_or_initializer)
                 *savedPaddingDepth = tokenPosition-*indentDepth;
             *paddingDepth = nextTokenPosition-*indentDepth;
         } else {
             // avoid existing continuation indents
-            if (parentState.type == initializer)
+            if (parentState.type == assign_open_or_initializer)
                 *savedPaddingDepth = state(1).savedPaddingDepth;
-            *paddingDepth = *savedPaddingDepth + m_indentSize;
+            *paddingDepth = *savedPaddingDepth + m_tabSettings.m_indentSize;
         }
         break;
 
     case block_open:
         // case_cont already adds some indent, revert it for a block
-        if (parentState.type == case_cont && !m_indentSubstatementBraces)
-            *indentDepth = *savedIndentDepth = parentState.savedIndentDepth;
+        if (parentState.type == case_cont) {
+            *indentDepth = parentState.savedIndentDepth;
+            if (m_styleSettings.indentBlocksRelativeToSwitchLabels)
+                *indentDepth += m_tabSettings.m_indentSize;
+        }
 
-        if (m_indentSubstatementStatements)
-            *indentDepth += m_indentSize;
+        if (m_styleSettings.indentBlockBody)
+            *indentDepth += m_tabSettings.m_indentSize;
         break;
 
     case condition_open:
@@ -1250,8 +1264,9 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
         *savedPaddingDepth = *paddingDepth;
 
         // fixed extra indent when continuing 'if (', but not for 'else if ('
-        if (nextTokenPosition-*indentDepth <= m_indentSize)
-            *paddingDepth = 2*m_indentSize;
+        if (m_styleSettings.extraPaddingForConditionsIfConfusingAlign
+                && nextTokenPosition-*indentDepth <= m_tabSettings.m_indentSize)
+            *paddingDepth = 2*m_tabSettings.m_indentSize;
         else
             *paddingDepth = nextTokenPosition-*indentDepth;
         break;
@@ -1286,7 +1301,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
 
     case cpp_macro:
     case cpp_macro_cont:
-        *indentDepth = m_indentSize;
+        *indentDepth = m_tabSettings.m_indentSize;
         break;
     }
 
@@ -1316,7 +1331,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
     // adjusting the indentDepth here instead of in enter() gives 'else if' the correct indentation
     // ### could be moved?
     if (topState.type == substatement)
-        *indentDepth += m_indentSize;
+        *indentDepth += m_tabSettings.m_indentSize;
 
     // keep user-adjusted indent in multiline comments
     if (topState.type == multiline_comment_start
@@ -1333,7 +1348,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
     case T_COLON:
         // ### ok for constructor initializer lists - what about ? and bitfields?
         if (topState.type == expression && previousState.type == declaration_start) {
-            *paddingDepth = m_indentSize;
+            *paddingDepth = m_tabSettings.m_indentSize;
         } else if (topState.type == ternary_op) {
             if (*paddingDepth >= 2)
                 *paddingDepth -= 2;
@@ -1344,24 +1359,41 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
     case T_LBRACE: {
         if (topState.type == case_cont) {
             *indentDepth = topState.savedIndentDepth;
-            if (m_indentSubstatementBraces)
-                *indentDepth += m_indentSize;
+            if (m_styleSettings.indentBlocksRelativeToSwitchLabels)
+                *indentDepth += m_tabSettings.m_indentSize;
             *paddingDepth = 0;
         // function definition - argument list is expression state
-        } else if (topState.type == expression && previousState.type == declaration_start) {
-            *indentDepth = previousState.savedIndentDepth;
-            if (m_indentDeclarationBraces)
-                *indentDepth += m_indentSize;
+        // or constructor
+        } else if ((topState.type == expression && previousState.type == declaration_start)
+                   || topState.type == member_init || topState.type == member_init_open) {
+            // the declaration_start indent is the base
+            if (topState.type == member_init) {
+                *indentDepth = state(2).savedIndentDepth;
+            } else {
+                *indentDepth = previousState.savedIndentDepth;
+            }
+            if (m_styleSettings.indentFunctionBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
             *paddingDepth = 0;
         } else if (topState.type == class_start) {
             *indentDepth = topState.savedIndentDepth;
-            if (m_indentDeclarationBraces)
-                *indentDepth += m_indentSize;
+            if (m_styleSettings.indentClassBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+            *paddingDepth = 0;
+        } else if (topState.type == enum_start) {
+            *indentDepth = topState.savedIndentDepth;
+            if (m_styleSettings.indentEnumBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
+            *paddingDepth = 0;
+        } else if (topState.type == namespace_start) {
+            *indentDepth = topState.savedIndentDepth;
+            if (m_styleSettings.indentNamespaceBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
             *paddingDepth = 0;
         } else if (topState.type == substatement) {
             *indentDepth = topState.savedIndentDepth;
-            if (m_indentSubstatementBraces)
-                *indentDepth += m_indentSize;
+            if (m_styleSettings.indentBlockBraces)
+                *indentDepth += m_tabSettings.m_indentSize;
             *paddingDepth = 0;
         } else if (topState.type != defun_open
                 && topState.type != block_open
@@ -1376,8 +1408,10 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
     }
     case T_RBRACE: {
         if (topState.type == block_open && previousState.type == case_cont) {
-            *indentDepth = topState.savedIndentDepth;
-            *paddingDepth = topState.savedPaddingDepth;
+            *indentDepth = previousState.savedIndentDepth;
+            *paddingDepth = previousState.savedPaddingDepth;
+            if (m_styleSettings.indentBlocksRelativeToSwitchLabels)
+                *indentDepth += m_tabSettings.m_indentSize;
             break;
         }
         for (int i = 0; state(i).type != topmost_intro; ++i) {
@@ -1386,17 +1420,18 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
                     || type == namespace_open
                     || type == extern_open
                     || type == enum_open
-                    || type == defun_open) {
-                *indentDepth = state(i).savedIndentDepth;
-                if (m_indentDeclarationBraces)
-                    *indentDepth += m_indentSize;
-                *paddingDepth = state(i).savedPaddingDepth;
-                break;
-            } else if (type == substatement_open
-                       || type == brace_list_open
-                       || type == block_open) {
+                    || type == defun_open
+                    || type == substatement_open
+                    || type == brace_list_open
+                    || type == block_open) {
                 *indentDepth = state(i).savedIndentDepth;
                 *paddingDepth = state(i).savedPaddingDepth;
+                if ((type == defun_open && m_styleSettings.indentFunctionBraces)
+                        || (type == class_open && m_styleSettings.indentClassBraces)
+                        || (type == namespace_open && m_styleSettings.indentNamespaceBraces)
+                        || (type == enum_open && m_styleSettings.indentEnumBraces)
+                        || (type == substatement_open && m_styleSettings.indentBlockBraces))
+                    *indentDepth += m_tabSettings.m_indentSize;
                 break;
             }
         }
@@ -1411,13 +1446,12 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
     //    break;
     case T_DEFAULT:
     case T_CASE: {
-        int lastSubstatementIndent = 0;
         for (int i = 0; state(i).type != topmost_intro; ++i) {
             const int type = state(i).type;
-            if (type == substatement_open) {
-                lastSubstatementIndent = state(i).savedIndentDepth;
-            } else if (type == switch_statement) {
-                *indentDepth = lastSubstatementIndent;
+            if (type == switch_statement) {
+                *indentDepth = state(i).savedIndentDepth;
+                if (m_styleSettings.indentSwitchLabels)
+                    *indentDepth += m_tabSettings.m_indentSize;
                 break;
             } else if (type == case_cont) {
                 *indentDepth = state(i).savedIndentDepth;
@@ -1432,9 +1466,13 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
     case T_PRIVATE:
     case T_PROTECTED:
     case T_Q_SIGNALS:
-        if (topState.type == class_open) {
-            if (tokenAt(1).is(T_COLON) || tokenAt(2).is(T_COLON))
+        if (m_styleSettings.indentDeclarationsRelativeToAccessSpecifiers
+                && topState.type == class_open) {
+            if (tokenAt(1).is(T_COLON) || tokenAt(2).is(T_COLON)) {
                 *indentDepth = topState.savedIndentDepth;
+                if (m_styleSettings.indentAccessSpecifiers)
+                    *indentDepth += m_tabSettings.m_indentSize;
+            }
         }
         break;
     case T_ELSE:
@@ -1460,8 +1498,8 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
                 && (kind == T_COMMENT || kind == T_DOXY_COMMENT)
                 && (lexerState == Lexer::State_Default
                     || tokens.size() != 1)) {
-            if (*indentDepth >= m_indentSize)
-                *indentDepth -= m_indentSize;
+            if (*indentDepth >= m_tabSettings.m_indentSize)
+                *indentDepth -= m_tabSettings.m_indentSize;
             else
                 *indentDepth = 0;
         }
@@ -1476,7 +1514,18 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
                 *indentDepth = 0;
         }
         break;
+    case T_BREAK:
+    case T_CONTINUE:
+    case T_RETURN:
+        if (topState.type == case_cont) {
+            *indentDepth = topState.savedIndentDepth;
+            if (m_styleSettings.indentControlFlowRelativeToSwitchLabels)
+                *indentDepth += m_tabSettings.m_indentSize;
+        }
     }
+    // ensure padding and indent are >= 0
+    *indentDepth = qMax(0, *indentDepth);
+    *paddingDepth = qMax(0, *paddingDepth);
 }
 
 bool QtStyleCodeFormatter::shouldClearPaddingOnEnter(int state)
diff --git a/src/plugins/cpptools/cppcodeformatter.h b/src/plugins/cpptools/cppcodeformatter.h
index 2a21d2ffc01..21f06135a8b 100644
--- a/src/plugins/cpptools/cppcodeformatter.h
+++ b/src/plugins/cpptools/cppcodeformatter.h
@@ -35,8 +35,10 @@
 
 #include "cpptools_global.h"
 
-#include <cplusplus/SimpleLexer.h>
 #include <Token.h>
+#include <cplusplus/SimpleLexer.h>
+#include <texteditor/tabsettings.h>
+#include <cpptools/cppcodestylesettings.h>
 
 #include <QtCore/QChar>
 #include <QtCore/QStack>
@@ -49,10 +51,6 @@ class QTextDocument;
 class QTextBlock;
 QT_END_NAMESPACE
 
-namespace TextEditor {
-    class TabSettings;
-}
-
 namespace CppTools {
 namespace Internal {
 class CppCodeFormatterData;
@@ -176,7 +174,7 @@ public: // must be public to make Q_GADGET introspection work
         assign_open, // after an assignment token
 
         expression, // after a '=' in a declaration_start once we're sure it's not '= {'
-        initializer // after a '=' in a declaration start
+        assign_open_or_initializer // after a '=' in a declaration start
     };
     Q_ENUMS(StateType)
 
@@ -261,14 +259,11 @@ class CPPTOOLS_EXPORT QtStyleCodeFormatter : public CodeFormatter
 {
 public:
     QtStyleCodeFormatter();
-    explicit QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings);
-
-    void setIndentSize(int size);
+    QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings,
+                         const CppCodeStyleSettings &settings);
 
-    void setIndentSubstatementBraces(bool onOff);
-    void setIndentSubstatementStatements(bool onOff);
-    void setIndentDeclarationBraces(bool onOff);
-    void setIndentDeclarationMembers(bool onOff);
+    void setTabSettings(const TextEditor::TabSettings &tabSettings);
+    void setCodeStyleSettings(const CppCodeStyleSettings &settings);
 
 protected:
     virtual void onEnter(int newState, int *indentDepth, int *savedIndentDepth, int *paddingDepth, int *savedPaddingDepth) const;
@@ -283,11 +278,8 @@ protected:
     static bool shouldClearPaddingOnEnter(int state);
 
 private:
-    int m_indentSize;
-    bool m_indentSubstatementBraces;
-    bool m_indentSubstatementStatements;
-    bool m_indentDeclarationBraces;
-    bool m_indentDeclarationMembers;
+    TextEditor::TabSettings m_tabSettings;
+    CppCodeStyleSettings m_styleSettings;
 };
 
 } // namespace CppTools
diff --git a/src/plugins/cpptools/cppcodestylepreferences.cpp b/src/plugins/cpptools/cppcodestylepreferences.cpp
new file mode 100644
index 00000000000..981216c5b26
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylepreferences.cpp
@@ -0,0 +1,86 @@
+#include "cppcodestylepreferences.h"
+
+using namespace CppTools;
+
+static const char *settingsSuffixKey = "CodeStyleSettings";
+
+static const char *currentFallbackKey = "CurrentFallback";
+
+CppCodeStylePreferences::CppCodeStylePreferences(const QList<TextEditor::IFallbackPreferences *> &fallbacks, QObject *parent) :
+    IFallbackPreferences(fallbacks, parent)
+{
+    connect(this, SIGNAL(currentValueChanged(QVariant)),
+            this, SLOT(slotCurrentValueChanged(QVariant)));
+}
+
+QVariant CppCodeStylePreferences::value() const
+{
+    QVariant v;
+    v.setValue(settings());
+    return v;
+}
+
+void CppCodeStylePreferences::setValue(const QVariant &data)
+{
+    if (!data.canConvert<CppCodeStyleSettings>())
+        return;
+
+    setSettings(data.value<CppCodeStyleSettings>());
+}
+
+CppCodeStyleSettings CppCodeStylePreferences::settings() const
+{
+    return m_data;
+}
+
+void CppCodeStylePreferences::setSettings(const CppCodeStyleSettings &data)
+{
+    if (m_data == data)
+        return;
+
+    m_data = data;
+
+    QVariant v;
+    v.setValue(data);
+    emit valueChanged(v);
+    emit settingsChanged(m_data);
+    if (!currentFallback()) {
+        emit currentValueChanged(v);
+    }
+}
+
+CppCodeStyleSettings CppCodeStylePreferences::currentSettings() const
+{
+    QVariant v = currentValue();
+    if (!v.canConvert<CppCodeStyleSettings>()) {
+        // warning
+        return CppCodeStyleSettings();
+    }
+    return v.value<CppCodeStyleSettings>();
+}
+
+void CppCodeStylePreferences::slotCurrentValueChanged(const QVariant &value)
+{
+    if (!value.canConvert<CppCodeStyleSettings>())
+        return;
+
+    emit currentSettingsChanged(value.value<CppCodeStyleSettings>());
+}
+
+QString CppCodeStylePreferences::settingsSuffix() const
+{
+    return settingsSuffixKey;
+}
+
+void CppCodeStylePreferences::toMap(const QString &prefix, QVariantMap *map) const
+{
+    m_data.toMap(prefix, map);
+    map->insert(prefix + QLatin1String(currentFallbackKey), currentFallbackId());
+}
+
+void CppCodeStylePreferences::fromMap(const QString &prefix, const QVariantMap &map)
+{
+    m_data.fromMap(prefix, map);
+    setCurrentFallback(map.value(prefix + QLatin1String(currentFallbackKey), QLatin1String("Global")).toString());
+}
+
diff --git a/src/plugins/cpptools/cppcodestylepreferences.h b/src/plugins/cpptools/cppcodestylepreferences.h
new file mode 100644
index 00000000000..991e15f0171
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylepreferences.h
@@ -0,0 +1,48 @@
+#ifndef CPPCODESTYLEPREFERENCES_H
+#define CPPCODESTYLEPREFERENCES_H
+
+#include "cpptools_global.h"
+#include "cppcodestylesettings.h"
+#include <texteditor/ifallbackpreferences.h>
+
+namespace CppTools {
+
+class CPPTOOLS_EXPORT CppCodeStylePreferences : public TextEditor::IFallbackPreferences
+{
+    Q_OBJECT
+public:
+    explicit CppCodeStylePreferences(
+        const QList<TextEditor::IFallbackPreferences *> &fallbacks,
+        QObject *parent = 0);
+
+    virtual QVariant value() const;
+    virtual void setValue(const QVariant &);
+
+    CppCodeStyleSettings settings() const;
+
+    // tracks parent hierarchy until currentParentSettings is null
+    CppCodeStyleSettings currentSettings() const;
+
+    virtual void toMap(const QString &prefix, QVariantMap *map) const;
+    virtual void fromMap(const QString &prefix, const QVariantMap &map);
+
+public slots:
+    void setSettings(const CppTools::CppCodeStyleSettings &data);
+
+signals:
+    void settingsChanged(const CppTools::CppCodeStyleSettings &);
+    void currentSettingsChanged(const CppTools::CppCodeStyleSettings &);
+
+protected:
+    virtual QString settingsSuffix() const;
+
+private slots:
+    void slotCurrentValueChanged(const QVariant &);
+
+private:
+    CppCodeStyleSettings m_data;
+};
+
+} // namespace CppTools
+
+#endif // CPPCODESTYLEPREFERENCES_H
diff --git a/src/plugins/cpptools/cppcodestylesettings.cpp b/src/plugins/cpptools/cppcodestylesettings.cpp
new file mode 100644
index 00000000000..13a06e26336
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettings.cpp
@@ -0,0 +1,133 @@
+#include "cppcodestylesettings.h"
+
+#include <utils/settingsutils.h>
+
+static const char *groupPostfix = "IndentSettings";
+static const char *indentBlockBracesKey = "IndentBlockBraces";
+static const char *indentBlockBodyKey = "IndentBlockBody";
+static const char *indentClassBracesKey = "IndentClassBraces";
+static const char *indentEnumBracesKey = "IndentEnumBraces";
+static const char *indentNamespaceBracesKey = "IndentNamespaceBraces";
+static const char *indentNamespaceBodyKey = "IndentNamespaceBody";
+static const char *indentAccessSpecifiersKey = "IndentAccessSpecifiers";
+static const char *indentDeclarationsRelativeToAccessSpecifiersKey = "IndentDeclarationsRelativeToAccessSpecifiers";
+static const char *indentFunctionBodyKey = "IndentFunctionBody";
+static const char *indentFunctionBracesKey = "IndentFunctionBraces";
+static const char *indentSwitchLabelsKey = "IndentSwitchLabels";
+static const char *indentStatementsRelativeToSwitchLabelsKey = "IndentStatementsRelativeToSwitchLabels";
+static const char *indentBlocksRelativeToSwitchLabelsKey = "IndentBlocksRelativeToSwitchLabels";
+static const char *indentControlFlowRelativeToSwitchLabelsKey = "IndentControlFlowRelativeToSwitchLabels";
+static const char *extraPaddingForConditionsIfConfusingAlignKey = "ExtraPaddingForConditionsIfConfusingAlign";
+static const char *alignAssignmentsKey = "AlignAssignments";
+
+using namespace CppTools;
+
+// ------------------ CppCodeStyleSettingsWidget
+
+CppCodeStyleSettings::CppCodeStyleSettings() :
+    indentBlockBraces(false)
+  , indentBlockBody(true)
+  , indentClassBraces(false)
+  , indentEnumBraces(false)
+  , indentNamespaceBraces(false)
+  , indentNamespaceBody(false)
+  , indentAccessSpecifiers(false)
+  , indentDeclarationsRelativeToAccessSpecifiers(true)
+  , indentFunctionBody(true)
+  , indentFunctionBraces(false)
+  , indentSwitchLabels(false)
+  , indentStatementsRelativeToSwitchLabels(true)
+  , indentBlocksRelativeToSwitchLabels(false)
+  , indentControlFlowRelativeToSwitchLabels(true)
+  , extraPaddingForConditionsIfConfusingAlign(true)
+  , alignAssignments(false)
+{
+}
+
+void CppCodeStyleSettings::toSettings(const QString &category, QSettings *s) const
+{
+    Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
+}
+
+void CppCodeStyleSettings::fromSettings(const QString &category, const QSettings *s)
+{
+    *this = CppCodeStyleSettings(); // Assign defaults
+    Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
+}
+
+void CppCodeStyleSettings::toMap(const QString &prefix, QVariantMap *map) const
+{
+    map->insert(prefix + QLatin1String(indentBlockBracesKey), indentBlockBraces);
+    map->insert(prefix + QLatin1String(indentBlockBodyKey), indentBlockBody);
+    map->insert(prefix + QLatin1String(indentClassBracesKey), indentClassBraces);
+    map->insert(prefix + QLatin1String(indentEnumBracesKey), indentEnumBraces);
+    map->insert(prefix + QLatin1String(indentNamespaceBracesKey), indentNamespaceBraces);
+    map->insert(prefix + QLatin1String(indentNamespaceBodyKey), indentNamespaceBody);
+    map->insert(prefix + QLatin1String(indentAccessSpecifiersKey), indentAccessSpecifiers);
+    map->insert(prefix + QLatin1String(indentDeclarationsRelativeToAccessSpecifiersKey), indentDeclarationsRelativeToAccessSpecifiers);
+    map->insert(prefix + QLatin1String(indentFunctionBodyKey), indentFunctionBody);
+    map->insert(prefix + QLatin1String(indentFunctionBracesKey), indentFunctionBraces);
+    map->insert(prefix + QLatin1String(indentSwitchLabelsKey), indentSwitchLabels);
+    map->insert(prefix + QLatin1String(indentStatementsRelativeToSwitchLabelsKey), indentStatementsRelativeToSwitchLabels);
+    map->insert(prefix + QLatin1String(indentBlocksRelativeToSwitchLabelsKey), indentBlocksRelativeToSwitchLabels);
+    map->insert(prefix + QLatin1String(indentControlFlowRelativeToSwitchLabelsKey), indentControlFlowRelativeToSwitchLabels);
+    map->insert(prefix + QLatin1String(extraPaddingForConditionsIfConfusingAlignKey), extraPaddingForConditionsIfConfusingAlign);
+    map->insert(prefix + QLatin1String(alignAssignmentsKey), alignAssignments);
+}
+
+void CppCodeStyleSettings::fromMap(const QString &prefix, const QVariantMap &map)
+{
+    indentBlockBraces = map.value(prefix + QLatin1String(indentBlockBracesKey),
+                                indentBlockBraces).toBool();
+    indentBlockBody = map.value(prefix + QLatin1String(indentBlockBodyKey),
+                                indentBlockBody).toBool();
+    indentClassBraces = map.value(prefix + QLatin1String(indentClassBracesKey),
+                                indentClassBraces).toBool();
+    indentEnumBraces = map.value(prefix + QLatin1String(indentEnumBracesKey),
+                                indentEnumBraces).toBool();
+    indentNamespaceBraces = map.value(prefix + QLatin1String(indentNamespaceBracesKey),
+                                indentNamespaceBraces).toBool();
+    indentNamespaceBody = map.value(prefix + QLatin1String(indentNamespaceBodyKey),
+                                indentNamespaceBody).toBool();
+    indentAccessSpecifiers = map.value(prefix + QLatin1String(indentAccessSpecifiersKey),
+                                indentAccessSpecifiers).toBool();
+    indentDeclarationsRelativeToAccessSpecifiers = map.value(prefix + QLatin1String(indentDeclarationsRelativeToAccessSpecifiersKey),
+                                indentDeclarationsRelativeToAccessSpecifiers).toBool();
+    indentFunctionBody = map.value(prefix + QLatin1String(indentFunctionBodyKey),
+                                indentFunctionBody).toBool();
+    indentFunctionBraces = map.value(prefix + QLatin1String(indentFunctionBracesKey),
+                                indentFunctionBraces).toBool();
+    indentSwitchLabels = map.value(prefix + QLatin1String(indentSwitchLabelsKey),
+                                indentSwitchLabels).toBool();
+    indentStatementsRelativeToSwitchLabels = map.value(prefix + QLatin1String(indentStatementsRelativeToSwitchLabelsKey),
+                                indentStatementsRelativeToSwitchLabels).toBool();
+    indentBlocksRelativeToSwitchLabels = map.value(prefix + QLatin1String(indentBlocksRelativeToSwitchLabelsKey),
+                                indentBlocksRelativeToSwitchLabels).toBool();
+    indentControlFlowRelativeToSwitchLabels = map.value(prefix + QLatin1String(indentControlFlowRelativeToSwitchLabelsKey),
+                                indentControlFlowRelativeToSwitchLabels).toBool();
+    extraPaddingForConditionsIfConfusingAlign = map.value(prefix + QLatin1String(extraPaddingForConditionsIfConfusingAlignKey),
+                                extraPaddingForConditionsIfConfusingAlign).toBool();
+    alignAssignments = map.value(prefix + QLatin1String(alignAssignmentsKey),
+                                alignAssignments).toBool();
+}
+
+bool CppCodeStyleSettings::equals(const CppCodeStyleSettings &rhs) const
+{
+    return indentBlockBraces == rhs.indentBlockBraces
+           && indentBlockBody == rhs.indentBlockBody
+           && indentClassBraces == rhs.indentClassBraces
+           && indentEnumBraces == rhs.indentEnumBraces
+           && indentNamespaceBraces == rhs.indentNamespaceBraces
+           && indentNamespaceBody == rhs.indentNamespaceBody
+           && indentAccessSpecifiers == rhs.indentAccessSpecifiers
+           && indentDeclarationsRelativeToAccessSpecifiers == rhs.indentDeclarationsRelativeToAccessSpecifiers
+           && indentFunctionBody == rhs.indentFunctionBody
+           && indentFunctionBraces == rhs.indentFunctionBraces
+           && indentSwitchLabels == rhs.indentSwitchLabels
+           && indentStatementsRelativeToSwitchLabels == rhs.indentStatementsRelativeToSwitchLabels
+           && indentBlocksRelativeToSwitchLabels == rhs.indentBlocksRelativeToSwitchLabels
+           && indentControlFlowRelativeToSwitchLabels == rhs.indentControlFlowRelativeToSwitchLabels
+           && extraPaddingForConditionsIfConfusingAlign == rhs.extraPaddingForConditionsIfConfusingAlign
+           && alignAssignments == rhs.alignAssignments;
+}
+
diff --git a/src/plugins/cpptools/cppcodestylesettings.h b/src/plugins/cpptools/cppcodestylesettings.h
new file mode 100644
index 00000000000..20651ed11c0
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettings.h
@@ -0,0 +1,67 @@
+#ifndef CPPCODESTYLESETTINGS_H
+#define CPPCODESTYLESETTINGS_H
+
+#include "cpptools_global.h"
+
+#include <QtCore/QMetaType>
+#include <QtCore/QVariant>
+
+QT_BEGIN_NAMESPACE
+class QSettings;
+QT_END_NAMESPACE
+
+namespace CppTools {
+
+struct CPPTOOLS_EXPORT CppCodeStyleSettings
+{
+    CppCodeStyleSettings();
+
+    bool indentBlockBraces;
+    bool indentBlockBody;
+    bool indentClassBraces;
+    bool indentEnumBraces;
+    bool indentNamespaceBraces;
+    bool indentNamespaceBody;
+    bool indentAccessSpecifiers;
+    bool indentDeclarationsRelativeToAccessSpecifiers;
+    bool indentFunctionBody;
+    bool indentFunctionBraces;
+    bool indentSwitchLabels;
+    bool indentStatementsRelativeToSwitchLabels;
+    bool indentBlocksRelativeToSwitchLabels;
+    bool indentControlFlowRelativeToSwitchLabels;
+
+    // false: if (a &&
+    //            b)
+    //            c;
+    // true:  if (a &&
+    //                b)
+    //            c;
+    // but always: while (a &&
+    //                    b)
+    //                 foo;
+    bool extraPaddingForConditionsIfConfusingAlign;
+
+    // false: a = a +
+    //                b;
+    // true:  a = a +
+    //            b
+    bool alignAssignments;
+
+    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 CppCodeStyleSettings &rhs) const;
+};
+
+inline bool operator==(const CppCodeStyleSettings &s1, const CppCodeStyleSettings &s2) { return s1.equals(s2); }
+inline bool operator!=(const CppCodeStyleSettings &s1, const CppCodeStyleSettings &s2) { return !s1.equals(s2); }
+
+} // namespace CppTools
+
+Q_DECLARE_METATYPE(CppTools::CppCodeStyleSettings)
+
+#endif // CPPCODESTYLESETTINGS_H
diff --git a/src/plugins/cpptools/cppcodestylesettingsfactory.cpp b/src/plugins/cpptools/cppcodestylesettingsfactory.cpp
new file mode 100644
index 00000000000..93856279f3b
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettingsfactory.cpp
@@ -0,0 +1,45 @@
+#include "cppcodestylesettingsfactory.h"
+#include "cppcodestylesettings.h"
+#include "cppcodestylesettingspage.h"
+#include "cppcodestylepreferences.h"
+#include "cpptoolsconstants.h"
+#include <texteditor/tabpreferences.h>
+#include <texteditor/tabsettings.h>
+#include <QtGui/QLayout>
+
+using namespace CppTools;
+
+CppCodeStylePreferencesFactory::CppCodeStylePreferencesFactory()
+{
+}
+
+QString CppCodeStylePreferencesFactory::languageId()
+{
+    return Constants::CPP_SETTINGS_ID;
+}
+
+QString CppCodeStylePreferencesFactory::displayName()
+{
+    return Constants::CPP_SETTINGS_NAME;
+}
+
+TextEditor::IFallbackPreferences *CppCodeStylePreferencesFactory::createPreferences(
+    const QList<TextEditor::IFallbackPreferences *> &fallbacks) const
+{
+    return new CppCodeStylePreferences(fallbacks);
+}
+
+QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::IFallbackPreferences *preferences,
+                                                           TextEditor::TabPreferences *tabPreferences,
+                                                           QWidget *parent) const
+{
+    CppCodeStylePreferences *cppPreferences = qobject_cast<CppCodeStylePreferences *>(preferences);
+    if (!cppPreferences)
+        return 0;
+    Internal::CppCodeStylePreferencesWidget *widget = new Internal::CppCodeStylePreferencesWidget(parent);
+    widget->layout()->setMargin(0);
+    widget->setCppCodeStylePreferences(cppPreferences);
+    widget->setTabPreferences(tabPreferences);
+    return widget;
+}
+
diff --git a/src/plugins/cpptools/cppcodestylesettingsfactory.h b/src/plugins/cpptools/cppcodestylesettingsfactory.h
new file mode 100644
index 00000000000..53681d6dd00
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettingsfactory.h
@@ -0,0 +1,24 @@
+#ifndef CPPCODESTYLESETTINGSFACTORY_H
+#define CPPCODESTYLESETTINGSFACTORY_H
+
+#include <texteditor/icodestylepreferencesfactory.h>
+
+namespace CppTools {
+
+class CppCodeStylePreferencesFactory : public TextEditor::ICodeStylePreferencesFactory
+{
+public:
+    CppCodeStylePreferencesFactory();
+
+    virtual QString languageId();
+    virtual QString displayName();
+    virtual TextEditor::IFallbackPreferences *createPreferences(const QList<TextEditor::IFallbackPreferences *> &fallbacks) const;
+    virtual QWidget *createEditor(TextEditor::IFallbackPreferences *settings,
+                                          TextEditor::TabPreferences *tabSettings,
+                                          QWidget *parent) const;
+
+};
+
+} // namespace CppTools
+
+#endif // CPPCODESTYLESETTINGSFACTORY_H
diff --git a/src/plugins/cpptools/cppcodestylesettingspage.cpp b/src/plugins/cpptools/cppcodestylesettingspage.cpp
new file mode 100644
index 00000000000..ba01ed3fb32
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettingspage.cpp
@@ -0,0 +1,536 @@
+#include "cppcodestylesettingspage.h"
+#include "cppcodestylepreferences.h"
+#include "ui_cppcodestylesettingspage.h"
+#include "cpptoolsconstants.h"
+#include "cpptoolssettings.h"
+#include "cppqtstyleindenter.h"
+#include <texteditor/snippets/isnippetprovider.h>
+#include <texteditor/fontsettings.h>
+#include <texteditor/displaysettings.h>
+#include <texteditor/texteditorsettings.h>
+#include <texteditor/tabsettings.h>
+#include <texteditor/tabpreferences.h>
+#include <extensionsystem/pluginmanager.h>
+#include <cppeditor/cppeditorconstants.h>
+#include <coreplugin/icore.h>
+#include <QtGui/QTextBlock>
+#include <QtCore/QTextStream>
+
+static const char *defaultCodeStyleSnippets[] = {
+    "#include <math.h>\n"
+    "\n"
+    "class Complex\n"
+    "    {\n"
+    "public:\n"
+    "    Complex(double re, double im)\n"
+    "        : _re(re), _im(im)\n"
+    "        {}\n"
+    "    double modulus() const\n"
+    "        {\n"
+    "        return sqrt(_re * _re + _im * _im);\n"
+    "        }\n"
+    "private:\n"
+    "    double _re;\n"
+    "    double _im;\n"
+    "    };\n"
+    "\n"
+    "void bar(int i)\n"
+    "    {\n"
+    "    static int counter = 0;\n"
+    "    counter += i;\n"
+    "    }\n"
+    "\n"
+    "namespace Foo\n"
+    "    {\n"
+    "    namespace Bar\n"
+    "        {\n"
+    "        void foo(int a, int b)\n"
+    "            {\n"
+    "            for (int i = 0; i < a; i++)\n"
+    "                {\n"
+    "                if (i < b)\n"
+    "                    bar(i);\n"
+    "                else\n"
+    "                    {\n"
+    "                    bar(i);\n"
+    "                    bar(b);\n"
+    "                    }\n"
+    "                }\n"
+    "            }\n"
+    "        } // namespace Bar\n"
+    "    } // namespace Foo\n"
+    ,
+    "#include <math.h>\n"
+    "\n"
+    "class Complex\n"
+    "    {\n"
+    "public:\n"
+    "    Complex(double re, double im)\n"
+    "        : _re(re), _im(im)\n"
+    "        {}\n"
+    "    double modulus() const\n"
+    "        {\n"
+    "        return sqrt(_re * _re + _im * _im);\n"
+    "        }\n"
+    "private:\n"
+    "    double _re;\n"
+    "    double _im;\n"
+    "    };\n"
+    "\n"
+    "void bar(int i)\n"
+    "    {\n"
+    "    static int counter = 0;\n"
+    "    counter += i;\n"
+    "    }\n"
+    "\n"
+    "namespace Foo\n"
+    "    {\n"
+    "    namespace Bar\n"
+    "        {\n"
+    "        void foo(int a, int b)\n"
+    "            {\n"
+    "            for (int i = 0; i < a; i++)\n"
+    "                {\n"
+    "                if (i < b)\n"
+    "                    bar(i);\n"
+    "                else\n"
+    "                    {\n"
+    "                    bar(i);\n"
+    "                    bar(b);\n"
+    "                    }\n"
+    "                }\n"
+    "            }\n"
+    "        } // namespace Bar\n"
+    "    } // namespace Foo\n"
+    ,
+    "namespace Foo\n"
+    "{\n"
+    "namespace Bar\n"
+    "{\n"
+    "class FooBar\n"
+    "    {\n"
+    "public:\n"
+    "    FooBar(int a)\n"
+    "        : _a(a)\n"
+    "        {}\n"
+    "    int calculate() const\n"
+    "        {\n"
+    "        if (a > 10)\n"
+    "            {\n"
+    "            int b = 2 * a;\n"
+    "            return a * b;\n"
+    "            }\n"
+    "        return -a;\n"
+    "        }\n"
+    "private:\n"
+    "    int _a;\n"
+    "    };\n"
+    "}\n"
+    "}\n"
+    ,
+    "#include \"bar.h\"\n"
+    "\n"
+    "int foo(int a)\n"
+    "    {\n"
+    "    switch (a)\n"
+    "        {\n"
+    "        case 1:\n"
+    "            bar(1);\n"
+    "            break;\n"
+    "        case 2:\n"
+    "            {\n"
+    "            bar(2);\n"
+    "            break;\n"
+    "            }\n"
+    "        case 3:\n"
+    "        default:\n"
+    "            bar(3);\n"
+    "            break;\n"
+    "        }\n"
+    "    return 0;\n"
+    "    }\n"
+    ,
+    "void foo() {\n"
+    "    if (a &&\n"
+    "        b)\n"
+    "        c;\n"
+    "\n"
+    "    while (a ||\n"
+    "           b)\n"
+    "        break;\n"
+    "    a = b +\n"
+    "        c;\n"
+    "    myInstance.longMemberName +=\n"
+    "            foo;\n"
+    "    myInstance.longMemberName += bar +\n"
+    "                                 foo;\n"
+    "}\n"
+};
+
+using namespace TextEditor;
+
+namespace CppTools {
+
+namespace Internal {
+
+// ------------------ CppCodeStyleSettingsWidget
+
+CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
+    : QWidget(parent),
+      m_tabPreferences(0),
+      m_cppCodeStylePreferences(0),
+      m_ui(new ::Ui::CppCodeStyleSettingsPage)
+{
+    m_ui->setupUi(this);
+
+    m_previews << m_ui->previewTextEditGeneral << m_ui->previewTextEditContent
+               << m_ui->previewTextEditBraces << m_ui->previewTextEditSwitch
+               << m_ui->previewTextEditPadding;
+    for (int i = 0; i < m_previews.size(); ++i) {
+        m_previews[i]->setPlainText(defaultCodeStyleSnippets[i]);
+    }
+
+    const QList<ISnippetProvider *> &providers =
+        ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
+    foreach (ISnippetProvider *provider, providers) {
+        if (provider->groupId() == QLatin1String(CppEditor::Constants::CPP_SNIPPETS_GROUP_ID)) {
+            foreach (TextEditor::SnippetEditorWidget *preview, m_previews)
+                provider->decorateEditor(preview);
+            break;
+        }
+    }
+    TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
+    setFontSettings(settings->fontSettings());
+    connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
+       this, SLOT(setFontSettings(TextEditor::FontSettings)));
+
+    setVisualizeWhitespace(true);
+
+    connect(m_ui->indentBlockBraces, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentBlockBody, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentClassBraces, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentNamespaceBraces, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentEnumBraces, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentNamespaceBody, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentSwitchLabels, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentCaseStatements, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentCaseBlocks, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentCaseBreak, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentAccessSpecifiers, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentDeclarationsRelativeToAccessSpecifiers, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentFunctionBody, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->indentFunctionBraces, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->extraPaddingConditions, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+    connect(m_ui->alignAssignments, SIGNAL(toggled(bool)),
+       this, SLOT(slotCppCodeStyleSettingsChanged()));
+
+    m_ui->categoryTab->setCurrentIndex(0);
+
+    m_ui->tabPreferencesWidget->setFlat(true);
+}
+
+CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget()
+{
+    delete m_ui;
+}
+
+void CppCodeStylePreferencesWidget::setTabPreferences(TextEditor::TabPreferences *preferences)
+{
+    m_tabPreferences = preferences;
+    m_ui->tabPreferencesWidget->setTabPreferences(preferences);
+    connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
+            this, SLOT(slotSettingsChanged()));
+    updatePreview();
+}
+
+void CppCodeStylePreferencesWidget::setCppCodeStylePreferences(CppCodeStylePreferences *preferences)
+{
+    m_cppCodeStylePreferences = preferences;
+    m_ui->fallbackWidget->setFallbackPreferences(preferences);
+    m_ui->fallbackContainer->setVisible(!m_ui->fallbackWidget->isHidden());
+
+    connect(m_cppCodeStylePreferences, SIGNAL(settingsChanged(CppTools::CppCodeStyleSettings)),
+            this, SLOT(setCppCodeStyleSettings(CppTools::CppCodeStyleSettings)));
+    connect(m_cppCodeStylePreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
+            this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
+    connect(this, SIGNAL(cppCodeStyleSettingsChanged(CppTools::CppCodeStyleSettings)),
+            m_cppCodeStylePreferences, SLOT(setSettings(CppTools::CppCodeStyleSettings)));
+
+    setCppCodeStyleSettings(m_cppCodeStylePreferences->settings());
+    slotCurrentFallbackChanged(m_cppCodeStylePreferences->currentFallback());
+
+    connect(m_cppCodeStylePreferences, SIGNAL(currentSettingsChanged(CppTools::CppCodeStyleSettings)),
+            this, SLOT(slotSettingsChanged()));
+    updatePreview();
+}
+
+CppCodeStyleSettings CppCodeStylePreferencesWidget::cppCodeStyleSettings() const
+{
+    CppCodeStyleSettings set;
+
+    set.indentBlockBraces = m_ui->indentBlockBraces->isChecked();
+    set.indentBlockBody = m_ui->indentBlockBody->isChecked();
+    set.indentClassBraces = m_ui->indentClassBraces->isChecked();
+    set.indentEnumBraces = m_ui->indentEnumBraces->isChecked();
+    set.indentNamespaceBraces = m_ui->indentNamespaceBraces->isChecked();
+    set.indentNamespaceBody = m_ui->indentNamespaceBody->isChecked();
+    set.indentAccessSpecifiers = m_ui->indentAccessSpecifiers->isChecked();
+    set.indentDeclarationsRelativeToAccessSpecifiers = m_ui->indentDeclarationsRelativeToAccessSpecifiers->isChecked();
+    set.indentFunctionBody = m_ui->indentFunctionBody->isChecked();
+    set.indentFunctionBraces = m_ui->indentFunctionBraces->isChecked();
+    set.indentSwitchLabels = m_ui->indentSwitchLabels->isChecked();
+    set.indentStatementsRelativeToSwitchLabels = m_ui->indentCaseStatements->isChecked();
+    set.indentBlocksRelativeToSwitchLabels = m_ui->indentCaseBlocks->isChecked();
+    set.indentControlFlowRelativeToSwitchLabels = m_ui->indentCaseBreak->isChecked();
+    set.extraPaddingForConditionsIfConfusingAlign = m_ui->extraPaddingConditions->isChecked();
+    set.alignAssignments = m_ui->alignAssignments->isChecked();
+
+    return set;
+}
+
+void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSettings &s)
+{
+    const bool wasBlocked = blockSignals(true);
+    m_ui->indentBlockBraces->setChecked(s.indentBlockBraces);
+    m_ui->indentBlockBody->setChecked(s.indentBlockBody);
+    m_ui->indentClassBraces->setChecked(s.indentClassBraces);
+    m_ui->indentEnumBraces->setChecked(s.indentEnumBraces);
+    m_ui->indentNamespaceBraces->setChecked(s.indentNamespaceBraces);
+    m_ui->indentNamespaceBody->setChecked(s.indentNamespaceBody);
+    m_ui->indentAccessSpecifiers->setChecked(s.indentAccessSpecifiers);
+    m_ui->indentDeclarationsRelativeToAccessSpecifiers->setChecked(s.indentDeclarationsRelativeToAccessSpecifiers);
+    m_ui->indentFunctionBody->setChecked(s.indentFunctionBody);
+    m_ui->indentFunctionBraces->setChecked(s.indentFunctionBraces);
+    m_ui->indentSwitchLabels->setChecked(s.indentSwitchLabels);
+    m_ui->indentCaseStatements->setChecked(s.indentStatementsRelativeToSwitchLabels);
+    m_ui->indentCaseBlocks->setChecked(s.indentBlocksRelativeToSwitchLabels);
+    m_ui->indentCaseBreak->setChecked(s.indentControlFlowRelativeToSwitchLabels);
+    m_ui->extraPaddingConditions->setChecked(s.extraPaddingForConditionsIfConfusingAlign);
+    m_ui->alignAssignments->setChecked(s.alignAssignments);
+    blockSignals(wasBlocked);
+
+    updatePreview();
+}
+
+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();
+}
+
+QString CppCodeStylePreferencesWidget::searchKeywords() const
+{
+    QString rc;
+    QLatin1Char sep(' ');
+    QTextStream(&rc)
+       << sep << m_ui->tabPreferencesWidget->searchKeywords()
+       << sep << m_ui->fallbackWidget->searchKeywords()
+       << sep << m_ui->indentBlockBraces->text()
+       << sep << m_ui->indentBlockBody->text()
+       << sep << m_ui->indentClassBraces->text()
+       << sep << m_ui->indentEnumBraces->text()
+       << sep << m_ui->indentNamespaceBraces->text()
+       << sep << m_ui->indentNamespaceBody->text()
+       << sep << m_ui->indentAccessSpecifiers->text()
+       << sep << m_ui->indentDeclarationsRelativeToAccessSpecifiers->text()
+       << sep << m_ui->indentFunctionBody->text()
+       << sep << m_ui->indentFunctionBraces->text()
+       << sep << m_ui->indentSwitchLabels->text()
+       << sep << m_ui->indentCaseStatements->text()
+       << sep << m_ui->indentCaseBlocks->text()
+       << sep << m_ui->indentCaseBreak->text()
+       << sep << m_ui->contentGroupBox->title()
+       << sep << m_ui->bracesGroupBox->title()
+       << sep << m_ui->switchGroupBox->title()
+       << sep << m_ui->alignmentGroupBox->title()
+       << sep << m_ui->extraPaddingConditions->text()
+       << sep << m_ui->alignAssignments->text()
+          ;
+    for (int i = 0; i < m_ui->categoryTab->count(); i++)
+        QTextStream(&rc) << sep << m_ui->categoryTab->tabText(i);
+    rc.remove(QLatin1Char('&'));
+    return rc;
+}
+
+void CppCodeStylePreferencesWidget::slotCppCodeStyleSettingsChanged()
+{
+    emit cppCodeStyleSettingsChanged(cppCodeStyleSettings());
+    updatePreview();
+}
+
+void CppCodeStylePreferencesWidget::slotSettingsChanged()
+{
+    updatePreview();
+}
+
+void CppCodeStylePreferencesWidget::updatePreview()
+{
+    foreach (TextEditor::SnippetEditorWidget *preview, m_previews) {
+        QTextDocument *doc = preview->document();
+
+        const TextEditor::TabSettings ts = m_tabPreferences
+                ? m_tabPreferences->currentSettings()
+                : CppToolsSettings::instance()->tabPreferences()->settings();
+        CppCodeStylePreferences *cppCodeStylePreferences = m_cppCodeStylePreferences
+                ? m_cppCodeStylePreferences
+                : CppToolsSettings::instance()->cppCodeStylePreferences();
+        const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentSettings();
+        preview->setTabSettings(ts);
+        preview->setCodeStylePreferences(cppCodeStylePreferences);
+        QtStyleCodeFormatter formatter(ts, ccss);
+        formatter.invalidateCache(doc);
+
+        QTextBlock block = doc->firstBlock();
+        QTextCursor tc = preview->textCursor();
+        tc.beginEditBlock();
+        while (block.isValid()) {
+            int indent;
+            int padding;
+            formatter.indentFor(block, &indent, &padding);
+            ts.indentLine(block, indent + padding, padding);
+            formatter.updateLineStateChange(block);
+
+            block = block.next();
+        }
+        tc.endEditBlock();
+    }
+}
+
+void CppCodeStylePreferencesWidget::setFontSettings(const TextEditor::FontSettings &fontSettings)
+{
+    foreach (TextEditor::SnippetEditorWidget *editor, m_previews)
+        editor->setFont(fontSettings.font());
+}
+
+void CppCodeStylePreferencesWidget::setVisualizeWhitespace(bool on)
+{
+    foreach (TextEditor::SnippetEditorWidget *editor, m_previews) {
+        DisplaySettings displaySettings = editor->displaySettings();
+        displaySettings.m_visualizeWhitespace = on;
+        editor->setDisplaySettings(displaySettings);
+    }
+}
+
+
+// ------------------ CppCodeStyleSettingsPage
+
+CppCodeStyleSettingsPage::CppCodeStyleSettingsPage(
+        QWidget *parent) :
+    Core::IOptionsPage(parent),
+    m_pageTabPreferences(0)
+{
+}
+
+CppCodeStyleSettingsPage::~CppCodeStyleSettingsPage()
+{
+}
+
+QString CppCodeStyleSettingsPage::id() const
+{
+    return QLatin1String(Constants::CPP_CODE_STYLE_SETTINGS_ID);
+}
+
+QString CppCodeStyleSettingsPage::displayName() const
+{
+    return QCoreApplication::translate("CppTools", Constants::CPP_CODE_STYLE_SETTINGS_NAME);
+}
+
+QString CppCodeStyleSettingsPage::category() const
+{
+    return QLatin1String(Constants::CPP_SETTINGS_CATEGORY);
+}
+
+QString CppCodeStyleSettingsPage::displayCategory() const
+{
+    return QCoreApplication::translate("CppTools", Constants::CPP_SETTINGS_TR_CATEGORY);
+}
+
+QIcon CppCodeStyleSettingsPage::categoryIcon() const
+{
+    return QIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPP_ICON));
+}
+
+QWidget *CppCodeStyleSettingsPage::createPage(QWidget *parent)
+{
+    m_widget = new CppCodeStylePreferencesWidget(parent);
+
+    TextEditor::TabPreferences *originalTabPreferences
+            = CppToolsSettings::instance()->tabPreferences();
+    m_pageTabPreferences = new TextEditor::TabPreferences(originalTabPreferences->fallbacks(), m_widget);
+    m_pageTabPreferences->setSettings(originalTabPreferences->settings());
+    m_pageTabPreferences->setCurrentFallback(originalTabPreferences->currentFallback());
+    m_widget->setTabPreferences(m_pageTabPreferences);
+
+    CppCodeStylePreferences *originalCodeStylePreferences
+            = CppToolsSettings::instance()->cppCodeStylePreferences();
+    m_pageCppCodeStylePreferences = new CppCodeStylePreferences(originalCodeStylePreferences->fallbacks(), m_widget);
+    m_pageCppCodeStylePreferences->setSettings(originalCodeStylePreferences->settings());
+    m_pageCppCodeStylePreferences->setCurrentFallback(originalCodeStylePreferences->currentFallback());
+    m_widget->setCppCodeStylePreferences(m_pageCppCodeStylePreferences);
+
+    if (m_searchKeywords.isEmpty())
+        m_searchKeywords = m_widget->searchKeywords();
+    return m_widget;
+}
+
+void CppCodeStyleSettingsPage::apply()
+{
+    if (m_widget) {
+        QSettings *s = Core::ICore::instance()->settings();
+
+        TextEditor::TabPreferences *originalTabPreferences = CppToolsSettings::instance()->tabPreferences();
+        if (originalTabPreferences->settings() != m_pageTabPreferences->settings()) {
+            originalTabPreferences->setSettings(m_pageTabPreferences->settings());
+            if (s)
+                originalTabPreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
+        }
+        if (originalTabPreferences->currentFallback() != m_pageTabPreferences->currentFallback()) {
+            originalTabPreferences->setCurrentFallback(m_pageTabPreferences->currentFallback());
+            if (s)
+                originalTabPreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
+        }
+
+        CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStylePreferences();
+        if (originalCppCodeStylePreferences->settings() != m_pageCppCodeStylePreferences->settings()) {
+            originalCppCodeStylePreferences->setSettings(m_pageCppCodeStylePreferences->settings());
+            if (s)
+                originalCppCodeStylePreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
+        }
+        if (originalCppCodeStylePreferences->currentFallback() != m_pageCppCodeStylePreferences->currentFallback()) {
+            originalCppCodeStylePreferences->setCurrentFallback(m_pageCppCodeStylePreferences->currentFallback());
+            if (s)
+                originalCppCodeStylePreferences->toSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
+        }
+    }
+}
+
+bool CppCodeStyleSettingsPage::matches(const QString &s) const
+{
+    return m_searchKeywords.contains(s, Qt::CaseInsensitive);
+}
+
+} // namespace Internal
+} // namespace CppTools
diff --git a/src/plugins/cpptools/cppcodestylesettingspage.h b/src/plugins/cpptools/cppcodestylesettingspage.h
new file mode 100644
index 00000000000..fd4e78bf85b
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettingspage.h
@@ -0,0 +1,98 @@
+#ifndef CPPCODESTYLESETTINGSPAGE_H
+#define CPPCODESTYLESETTINGSPAGE_H
+
+#include "cpptools_global.h"
+
+#include <coreplugin/dialogs/ioptionspage.h>
+#include <QtGui/QWidget>
+#include <QtCore/QPointer>
+#include <QtCore/QSharedPointer>
+#include <QtCore/QVariant>
+#include <QtCore/QStringList>
+
+#include "cppcodestylesettings.h"
+#include "cppcodeformatter.h"
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+    class CppCodeStyleSettingsPage;
+}
+QT_END_NAMESPACE
+
+namespace TextEditor {
+    class FontSettings;
+    class TabSettings;
+    class TabPreferences;
+    class IFallbackPreferences;
+    class SnippetEditorWidget;
+}
+
+namespace CppTools {
+
+class CppCodeStylePreferences;
+
+namespace Internal {
+
+class CppCodeStylePreferencesWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit CppCodeStylePreferencesWidget(QWidget *parent = 0);
+    virtual ~CppCodeStylePreferencesWidget();
+
+    void setTabPreferences(TextEditor::TabPreferences *tabPreferences);
+    void setCppCodeStylePreferences(CppTools::CppCodeStylePreferences *codeStylePreferences);
+
+    QString searchKeywords() const;
+
+private slots:
+    void setFontSettings(const TextEditor::FontSettings &fontSettings);
+    void setVisualizeWhitespace(bool on);
+    void slotCppCodeStyleSettingsChanged();
+    void slotSettingsChanged();
+    void updatePreview();
+    void setCppCodeStyleSettings(const CppTools::CppCodeStyleSettings &settings);
+    void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *);
+
+signals:
+    void cppCodeStyleSettingsChanged(const CppTools::CppCodeStyleSettings &);
+private:
+    CppCodeStyleSettings cppCodeStyleSettings() const;
+
+    TextEditor::TabPreferences *m_tabPreferences;
+    CppCodeStylePreferences *m_cppCodeStylePreferences;
+    Ui::CppCodeStyleSettingsPage *m_ui;
+    QList<TextEditor::SnippetEditorWidget *> m_previews;
+};
+
+
+class CppCodeStyleSettingsPage : public Core::IOptionsPage
+{
+    Q_OBJECT
+
+public:
+    explicit CppCodeStyleSettingsPage(QWidget *parent = 0);
+    ~CppCodeStyleSettingsPage();
+
+    virtual QString id() const;
+    virtual QString displayName() const;
+    virtual QString category() const;
+    virtual QString displayCategory() const;
+    virtual QIcon categoryIcon() const;
+
+    virtual QWidget *createPage(QWidget *parent);
+    virtual void apply();
+    virtual void finish() { }
+    virtual bool matches(const QString &) const;
+
+private:
+    QString m_searchKeywords;
+    TextEditor::TabPreferences *m_pageTabPreferences;
+    CppCodeStylePreferences *m_pageCppCodeStylePreferences;
+    QPointer<CppCodeStylePreferencesWidget> m_widget;
+};
+
+} // namespace Internal
+} // namespace CppTools
+
+#endif // CPPCODESTYLESETTINGSPAGE_H
diff --git a/src/plugins/cpptools/cppcodestylesettingspage.ui b/src/plugins/cpptools/cppcodestylesettingspage.ui
new file mode 100644
index 00000000000..74561d23674
--- /dev/null
+++ b/src/plugins/cpptools/cppcodestylesettingspage.ui
@@ -0,0 +1,436 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>CppCodeStyleSettingsPage</class>
+ <widget class="QWidget" name="CppCodeStyleSettingsPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>759</width>
+    <height>467</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_3">
+   <item>
+    <widget class="QWidget" name="fallbackContainer" native="true">
+     <layout class="QHBoxLayout" name="fallbackLayout">
+      <property name="leftMargin">
+       <number>0</number>
+      </property>
+      <item>
+       <widget class="TextEditor::FallbackSelectorWidget" name="fallbackWidget" native="true"/>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>40</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QTabWidget" name="categoryTab">
+     <property name="currentIndex">
+      <number>4</number>
+     </property>
+     <widget class="QWidget" name="generalTab">
+      <attribute name="title">
+       <string>General</string>
+      </attribute>
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <widget class="TextEditor::TabPreferencesWidget" name="tabPreferencesWidget" native="true">
+         <property name="focusPolicy">
+          <enum>Qt::TabFocus</enum>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="TextEditor::SnippetEditorWidget" name="previewTextEditGeneral">
+         <property name="plainText">
+          <string/>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="contentTab">
+      <attribute name="title">
+       <string>Content</string>
+      </attribute>
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <item>
+        <widget class="QGroupBox" name="contentGroupBox">
+         <property name="title">
+          <string>Indent</string>
+         </property>
+         <property name="flat">
+          <bool>true</bool>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout">
+          <property name="leftMargin">
+           <number>0</number>
+          </property>
+          <property name="rightMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QCheckBox" name="indentAccessSpecifiers">
+            <property name="text">
+             <string>&quot;public&quot;, &quot;protected&quot; and
+&quot;private&quot; within class body</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentDeclarationsRelativeToAccessSpecifiers">
+            <property name="text">
+             <string>Declarations relative to &quot;public&quot;,
+&quot;protected&quot; and &quot;private&quot;</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentFunctionBody">
+            <property name="text">
+             <string>Statements within method body</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentBlockBody">
+            <property name="text">
+             <string>Statements within blocks</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentNamespaceBody">
+            <property name="text">
+             <string>Declarations within
+&quot;namespace&quot; definition</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>17</width>
+              <height>114</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="TextEditor::SnippetEditorWidget" name="previewTextEditContent">
+         <property name="plainText">
+          <string/>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="bracesTab">
+      <attribute name="title">
+       <string>Braces</string>
+      </attribute>
+      <layout class="QHBoxLayout" name="horizontalLayout_3">
+       <item>
+        <widget class="QGroupBox" name="bracesGroupBox">
+         <property name="title">
+          <string>Indent Braces</string>
+         </property>
+         <property name="flat">
+          <bool>true</bool>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout_2">
+          <property name="leftMargin">
+           <number>0</number>
+          </property>
+          <property name="rightMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QCheckBox" name="indentClassBraces">
+            <property name="text">
+             <string>Class declarations</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentNamespaceBraces">
+            <property name="text">
+             <string>Namespace declarations</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentEnumBraces">
+            <property name="text">
+             <string>Enum declarations</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentFunctionBraces">
+            <property name="text">
+             <string>Method declarations</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentBlockBraces">
+            <property name="text">
+             <string>Blocks</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer_3">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>20</width>
+              <height>195</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="TextEditor::SnippetEditorWidget" name="previewTextEditBraces">
+         <property name="plainText">
+          <string/>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="switchTab">
+      <attribute name="title">
+       <string>&quot;switch&quot;</string>
+      </attribute>
+      <layout class="QHBoxLayout" name="horizontalLayout_4">
+       <item>
+        <widget class="QGroupBox" name="switchGroupBox">
+         <property name="title">
+          <string>Indent within &quot;switch&quot;</string>
+         </property>
+         <property name="flat">
+          <bool>true</bool>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout_4">
+          <property name="leftMargin">
+           <number>0</number>
+          </property>
+          <property name="rightMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QCheckBox" name="indentSwitchLabels">
+            <property name="text">
+             <string>&quot;case&quot; or &quot;default&quot;</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentCaseStatements">
+            <property name="text">
+             <string>Statements relative to
+&quot;case&quot; or &quot;default&quot;</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentCaseBlocks">
+            <property name="text">
+             <string>Blocks relative to
+&quot;case&quot; or &quot;default&quot;</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="indentCaseBreak">
+            <property name="text">
+             <string>&quot;break&quot; statement relative to
+&quot;case&quot; or &quot;default&quot;</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer_4">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>20</width>
+              <height>143</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="TextEditor::SnippetEditorWidget" name="previewTextEditSwitch">
+         <property name="plainText">
+          <string/>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="alignmentTab">
+      <attribute name="title">
+       <string>Alignment</string>
+      </attribute>
+      <layout class="QHBoxLayout" name="horizontalLayout_5">
+       <item>
+        <widget class="QGroupBox" name="alignmentGroupBox">
+         <property name="title">
+          <string>Align</string>
+         </property>
+         <property name="flat">
+          <bool>true</bool>
+         </property>
+         <layout class="QVBoxLayout" name="verticalLayout_5">
+          <property name="leftMargin">
+           <number>0</number>
+          </property>
+          <property name="rightMargin">
+           <number>0</number>
+          </property>
+          <property name="bottomMargin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QCheckBox" name="alignAssignments">
+            <property name="toolTip">
+             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
+Enables alignment to tokens after =, += etc. When the option is disabled regular continuation line indentation will be used.&lt;br&gt;
+&lt;br&gt;
+With alignment:
+&lt;pre&gt;
+a = a +
+    b
+&lt;/pre&gt;
+Without alignment:
+&lt;pre&gt;
+a = a +
+        b
+&lt;/pre&gt;
+&lt;/body&gt;&lt;/html&gt;</string>
+            </property>
+            <property name="text">
+             <string>Align after assignments</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QCheckBox" name="extraPaddingConditions">
+            <property name="toolTip">
+             <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
+The extra padding usually only affects if statement conditions. Without extra padding:
+&lt;pre&gt;
+if (a &amp;&amp;
+    b)
+    c;
+&lt;/pre&gt;
+With extra padding:
+&lt;pre&gt;
+if (a &amp;&amp;
+        b)
+    c;
+&lt;/pre&gt;
+&lt;/body&gt;&lt;/html&gt;</string>
+            </property>
+            <property name="text">
+             <string>Add extra padding to conditions
+if they would align to the next line</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer_2">
+            <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>
+       </item>
+       <item>
+        <widget class="TextEditor::SnippetEditorWidget" name="previewTextEditPadding">
+         <property name="plainText">
+          <string/>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>TextEditor::SnippetEditorWidget</class>
+   <extends>QPlainTextEdit</extends>
+   <header location="global">texteditor/snippets/snippeteditor.h</header>
+  </customwidget>
+  <customwidget>
+   <class>TextEditor::TabPreferencesWidget</class>
+   <extends>QWidget</extends>
+   <header location="global">texteditor/tabpreferenceswidget.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
+   <class>TextEditor::FallbackSelectorWidget</class>
+   <extends>QWidget</extends>
+   <header location="global">texteditor/fallbackselectorwidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/cpptools/cppfilesettingspage.cpp b/src/plugins/cpptools/cppfilesettingspage.cpp
index 7c87527e3d1..87d533623a4 100644
--- a/src/plugins/cpptools/cppfilesettingspage.cpp
+++ b/src/plugins/cpptools/cppfilesettingspage.cpp
@@ -333,12 +333,12 @@ CppFileSettingsPage::~CppFileSettingsPage()
 
 QString CppFileSettingsPage::id() const
 {
-    return QLatin1String(Constants::CPP_SETTINGS_ID);
+    return QLatin1String(Constants::CPP_FILE_SETTINGS_ID);
 }
 
 QString CppFileSettingsPage::displayName() const
 {
-    return QCoreApplication::translate("CppTools", Constants::CPP_SETTINGS_NAME);
+    return QCoreApplication::translate("CppTools", Constants::CPP_FILE_SETTINGS_NAME);
 }
 
 QString CppFileSettingsPage::category() const
diff --git a/src/plugins/cppeditor/cppqtstyleindenter.cpp b/src/plugins/cpptools/cppqtstyleindenter.cpp
similarity index 82%
rename from src/plugins/cppeditor/cppqtstyleindenter.cpp
rename to src/plugins/cpptools/cppqtstyleindenter.cpp
index ed17df8a699..892cc173492 100644
--- a/src/plugins/cppeditor/cppqtstyleindenter.cpp
+++ b/src/plugins/cpptools/cppqtstyleindenter.cpp
@@ -32,20 +32,26 @@
 
 #include "cppqtstyleindenter.h"
 
-#include <cpptools/cppcodeformatter.h>
+#include "cppcodeformatter.h"
+#include "cpptoolssettings.h"
+#include "cppcodestylepreferences.h"
+#include "cpptoolsconstants.h"
 #include <texteditor/basetexteditor.h>
 #include <texteditor/tabsettings.h>
+#include <texteditor/texteditorsettings.h>
 
 #include <QtCore/QChar>
 #include <QtGui/QTextDocument>
 #include <QtGui/QTextBlock>
 #include <QtGui/QTextCursor>
 
-using namespace CppEditor;
-using namespace Internal;
+using namespace CppTools;
 
 CppQtStyleIndenter::CppQtStyleIndenter()
-{}
+    : m_cppCodeStylePreferences(0)
+{
+    m_cppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStylePreferences();
+}
 
 CppQtStyleIndenter::~CppQtStyleIndenter()
 {}
@@ -89,7 +95,7 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
     Q_UNUSED(doc)
 
     const TextEditor::TabSettings &ts = editor->tabSettings();
-    CppTools::QtStyleCodeFormatter codeFormatter(ts);
+    CppTools::QtStyleCodeFormatter codeFormatter(ts, codeStyleSettings());
 
     codeFormatter.updateStateUntil(block);
     int indent;
@@ -123,7 +129,7 @@ void CppQtStyleIndenter::indent(QTextDocument *doc,
         const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
 
         const TextEditor::TabSettings &ts = editor->tabSettings();
-        CppTools::QtStyleCodeFormatter codeFormatter(ts);
+        CppTools::QtStyleCodeFormatter codeFormatter(ts, codeStyleSettings());
         codeFormatter.updateStateUntil(block);
 
         QTextCursor tc = editor->textCursor();
@@ -141,3 +147,18 @@ void CppQtStyleIndenter::indent(QTextDocument *doc,
         indentBlock(doc, cursor.block(), typedChar, editor);
     }
 }
+
+void CppQtStyleIndenter::setCodeStylePreferences(TextEditor::IFallbackPreferences *preferences)
+{
+    CppTools::CppCodeStylePreferences *cppCodeStylePreferences
+            = qobject_cast<CppTools::CppCodeStylePreferences *>(preferences);
+    if (cppCodeStylePreferences)
+        m_cppCodeStylePreferences = cppCodeStylePreferences;
+}
+
+CppCodeStyleSettings CppQtStyleIndenter::codeStyleSettings() const
+{
+    if (m_cppCodeStylePreferences)
+        return m_cppCodeStylePreferences->currentSettings();
+    return CppCodeStyleSettings();
+}
diff --git a/src/plugins/cppeditor/cppqtstyleindenter.h b/src/plugins/cpptools/cppqtstyleindenter.h
similarity index 82%
rename from src/plugins/cppeditor/cppqtstyleindenter.h
rename to src/plugins/cpptools/cppqtstyleindenter.h
index 23435e6104a..a544e8b304c 100644
--- a/src/plugins/cppeditor/cppqtstyleindenter.h
+++ b/src/plugins/cpptools/cppqtstyleindenter.h
@@ -33,12 +33,18 @@
 #ifndef CPPQTSTYLEINDENTER_H
 #define CPPQTSTYLEINDENTER_H
 
+#include "cpptools_global.h"
 #include <texteditor/indenter.h>
+#include "cppcodestylesettingspage.h"
 
-namespace CppEditor {
-namespace Internal {
+namespace TextEditor
+{
+class IFallbackPreferences;
+}
+
+namespace CppTools {
 
-class CppQtStyleIndenter : public TextEditor::Indenter
+class CPPTOOLS_EXPORT CppQtStyleIndenter : public TextEditor::Indenter
 {
 public:
     CppQtStyleIndenter();
@@ -54,9 +60,13 @@ public:
                         const QTextCursor &cursor,
                         const QChar &typedChar,
                         TextEditor::BaseTextEditorWidget *editor);
+
+    virtual void setCodeStylePreferences(TextEditor::IFallbackPreferences *preferences);
+private:
+    CppCodeStyleSettings codeStyleSettings() const;
+    CppCodeStylePreferences *m_cppCodeStylePreferences;
 };
 
-} // Internal
-} // CppEditor
+} // CppTools
 
 #endif // CPPQTSTYLEINDENTER_H
diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp
index f82a48dd65f..53883128869 100644
--- a/src/plugins/cpptools/cpprefactoringchanges.cpp
+++ b/src/plugins/cpptools/cpprefactoringchanges.cpp
@@ -31,11 +31,14 @@
 **************************************************************************/
 
 #include "cpprefactoringchanges.h"
+#include "cppcodestylepreferences.h"
 
 #include <TranslationUnit.h>
 #include <AST.h>
 #include <cpptools/cppcodeformatter.h>
 #include <cpptools/cppmodelmanager.h>
+#include <cpptools/cpptoolssettings.h>
+#include <cpptools/cpptoolsconstants.h>
 #include <texteditor/texteditorsettings.h>
 #include <texteditor/tabsettings.h>
 #include <projectexplorer/editorconfiguration.h>
@@ -76,7 +79,9 @@ void CppRefactoringChanges::indentSelection(const QTextCursor &selection,
 
     const TextEditor::TabSettings &tabSettings =
         ProjectExplorer::actualTabSettings(fileName, textEditor);
-    CppTools::QtStyleCodeFormatter codeFormatter(tabSettings);
+    // TODO: add similar method like above one
+    CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
+        CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
     codeFormatter.updateStateUntil(block);
 
     do {
diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro
index ca8d89ce8af..2351c5c5ea3 100644
--- a/src/plugins/cpptools/cpptools.pro
+++ b/src/plugins/cpptools/cpptools.pro
@@ -18,6 +18,7 @@ HEADERS += completionsettingspage.h \
     cpptoolsconstants.h \
     cpptoolseditorsupport.h \
     cpptoolsplugin.h \
+    cppqtstyleindenter.h \
     searchsymbols.h \
     cppdoxygen.h \
     cppfilesettingspage.h \
@@ -28,7 +29,12 @@ HEADERS += completionsettingspage.h \
     insertionpointlocator.h \
     cpprefactoringchanges.h \
     abstracteditorsupport.h \
-    cppcompletionassist.h
+    cppcompletionassist.h \
+    cppcodestylesettingspage.h \
+    cpptoolssettings.h \
+    cppcodestylesettings.h \
+    cppcodestylesettingsfactory.h \
+    cppcodestylepreferences.h
 
 SOURCES += completionsettingspage.cpp \
     cppclassesfilter.cpp \
@@ -38,6 +44,7 @@ SOURCES += completionsettingspage.cpp \
     cpplocatorfilter.cpp \
     cpptoolseditorsupport.cpp \
     cpptoolsplugin.cpp \
+    cppqtstyleindenter.cpp \
     searchsymbols.cpp \
     cppdoxygen.cpp \
     cppfilesettingspage.cpp \
@@ -48,7 +55,13 @@ SOURCES += completionsettingspage.cpp \
     uicodecompletionsupport.cpp \
     insertionpointlocator.cpp \
     cpprefactoringchanges.cpp \
-    cppcompletionassist.cpp
+    cppcompletionassist.cpp \
+    cppcodestylesettingspage.cpp \
+    cpptoolssettings.cpp \
+    cppcodestylesettings.cpp \
+    cppcodestylesettingsfactory.cpp \
+    cppcodestylepreferences.cpp
 
 FORMS += completionsettingspage.ui \
-    cppfilesettingspage.ui
+    cppfilesettingspage.ui \
+    cppcodestylesettingspage.ui
diff --git a/src/plugins/cpptools/cpptoolsconstants.h b/src/plugins/cpptools/cpptoolsconstants.h
index 403c65dcb7b..11cd419837f 100644
--- a/src/plugins/cpptools/cpptoolsconstants.h
+++ b/src/plugins/cpptools/cpptoolsconstants.h
@@ -53,12 +53,17 @@ const char * const CPPTOOLS_SETTINGSGROUP = "CppTools";
 const char * const LOWERCASE_CPPFILES_KEY = "LowerCaseFiles";
 enum { lowerCaseFilesDefault = 1 };
 
-const char * const CPP_SETTINGS_ID = "File Naming";
-const char * const CPP_SETTINGS_NAME = QT_TRANSLATE_NOOP("CppTools", "File Naming");
+const char * const CPP_CODE_STYLE_SETTINGS_ID = "A.Code Style";
+const char * const CPP_CODE_STYLE_SETTINGS_NAME = QT_TRANSLATE_NOOP("CppTools", "Code Style");
+const char * const CPP_FILE_SETTINGS_ID = "B.File Naming";
+const char * const CPP_FILE_SETTINGS_NAME = QT_TRANSLATE_NOOP("CppTools", "File Naming");
 const char * const CPP_SETTINGS_CATEGORY = "I.C++";
 const char * const CPP_SETTINGS_TR_CATEGORY = QT_TRANSLATE_NOOP("CppTools", "C++");
 const char * const SETTINGS_CATEGORY_CPP_ICON = ":/core/images/category_cpp.png";
 
+const char * const CPP_SETTINGS_ID = "Cpp";
+const char * const CPP_SETTINGS_NAME = QT_TRANSLATE_NOOP("CppTools", "C++");
+
 } // namespace Constants
 } // namespace CppTools
 
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp
index 480cb3b7a24..cf2762677db 100644
--- a/src/plugins/cpptools/cpptoolsplugin.cpp
+++ b/src/plugins/cpptools/cpptoolsplugin.cpp
@@ -33,6 +33,7 @@
 #include "cpptoolsplugin.h"
 #include "completionsettingspage.h"
 #include "cppfilesettingspage.h"
+#include "cppcodestylesettingspage.h"
 #include "cppclassesfilter.h"
 #include "cppfunctionsfilter.h"
 #include "cppcurrentdocumentfilter.h"
@@ -41,6 +42,8 @@
 #include "cpplocatorfilter.h"
 #include "symbolsfindfilter.h"
 #include "cppcompletionassist.h"
+#include "cpptoolssettings.h"
+#include "cppcodestylesettingsfactory.h"
 
 #include <extensionsystem/pluginmanager.h>
 
@@ -56,6 +59,8 @@
 #include <coreplugin/vcsmanager.h>
 #include <coreplugin/filemanager.h>
 #include <texteditor/texteditorsettings.h>
+#include <texteditor/tabsettings.h>
+#include <texteditor/codestylepreferencesmanager.h>
 #include <cppeditor/cppeditorconstants.h>
 
 #include <QtCore/QtConcurrentRun>
@@ -103,6 +108,8 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
     Core::ICore *core = Core::ICore::instance();
     Core::ActionManager *am = core->actionManager();
 
+    m_settings = new CppToolsSettings(this); // force registration of cpp tools settings
+
     // Objects
     m_modelManager = new CppModelManager(this);
     Core::VcsManager *vcsManager = core->vcsManager();
@@ -121,6 +128,10 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
     addAutoReleasedObject(new CompletionSettingsPage);
     addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings));
     addAutoReleasedObject(new SymbolsFindFilter(m_modelManager));
+    addAutoReleasedObject(new CppCodeStyleSettingsPage);
+
+    TextEditor::CodeStylePreferencesManager::instance()->registerFactory(
+                new CppTools::CppCodeStylePreferencesFactory());
 
     // Menus
     Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS);
diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h
index 91dc50f0d68..a7a5dcac073 100644
--- a/src/plugins/cpptools/cpptoolsplugin.h
+++ b/src/plugins/cpptools/cpptoolsplugin.h
@@ -51,6 +51,9 @@ class QDir;
 QT_END_NAMESPACE
 
 namespace CppTools {
+
+class CppToolsSettings;
+
 namespace Internal {
 
 class CppModelManager;
@@ -81,6 +84,7 @@ private:
 
     CppModelManager *m_modelManager;
     QSharedPointer<CppFileSettings> m_fileSettings;
+    CppToolsSettings *m_settings;
 
     static CppToolsPlugin *m_instance;
 };
diff --git a/src/plugins/cpptools/cpptoolssettings.cpp b/src/plugins/cpptools/cpptoolssettings.cpp
new file mode 100644
index 00000000000..439c15e5380
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolssettings.cpp
@@ -0,0 +1,80 @@
+#include "cpptoolssettings.h"
+#include "cpptoolsconstants.h"
+#include "cppcodestylepreferences.h"
+
+#include <texteditor/texteditorsettings.h>
+#include <texteditor/tabpreferences.h>
+
+#include <utils/qtcassert.h>
+#include <coreplugin/icore.h>
+#include <QtCore/QSettings>
+
+static const char *idKey = "CppGlobal";
+
+using namespace CppTools;
+
+namespace CppTools {
+namespace Internal {
+
+class CppToolsSettingsPrivate
+{
+public:
+    CppCodeStylePreferences *m_cppCodeStylePreferences;
+    TextEditor::TabPreferences *m_tabPreferences;
+};
+
+} // namespace Internal
+} // namespace CppTools
+
+CppToolsSettings *CppToolsSettings::m_instance = 0;
+
+CppToolsSettings::CppToolsSettings(QObject *parent)
+    : QObject(parent)
+    , m_d(new Internal::CppToolsSettingsPrivate)
+{
+    QTC_ASSERT(!m_instance, return);
+    m_instance = this;
+
+    if (const QSettings *s = Core::ICore::instance()->settings()) {
+        TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
+        m_d->m_tabPreferences
+                = new TextEditor::TabPreferences(QList<TextEditor::IFallbackPreferences *>()
+                                                 << 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->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->setId(idKey);
+        textEditorSettings->registerLanguageCodeStylePreferences(CppTools::Constants::CPP_SETTINGS_ID, m_d->m_cppCodeStylePreferences);
+    }
+}
+
+CppToolsSettings::~CppToolsSettings()
+{
+    delete m_d;
+
+    m_instance = 0;
+}
+
+CppToolsSettings *CppToolsSettings::instance()
+{
+    return m_instance;
+}
+
+CppCodeStylePreferences *CppToolsSettings::cppCodeStylePreferences() const
+{
+    return m_d->m_cppCodeStylePreferences;
+}
+
+TextEditor::TabPreferences *CppToolsSettings::tabPreferences() const
+{
+    return m_d->m_tabPreferences;
+}
+
+
diff --git a/src/plugins/cpptools/cpptoolssettings.h b/src/plugins/cpptools/cpptoolssettings.h
new file mode 100644
index 00000000000..48712012afe
--- /dev/null
+++ b/src/plugins/cpptools/cpptoolssettings.h
@@ -0,0 +1,80 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** No Commercial Usage
+**
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**************************************************************************/
+
+#ifndef CPPTOOLSSETTINGS_H
+#define CPPTOOLSSETTINGS_H
+
+#include "cpptools_global.h"
+
+#include <QtCore/QObject>
+
+namespace TextEditor
+{
+class TabPreferences;
+}
+
+namespace CppTools
+{
+class CppCodeStylePreferences;
+
+
+namespace Internal
+{
+class CppToolsSettingsPrivate;
+}
+
+/**
+ * This class provides a central place for cpp tools settings.
+ */
+class CPPTOOLS_EXPORT CppToolsSettings : public QObject
+{
+    Q_OBJECT
+
+public:
+    explicit CppToolsSettings(QObject *parent);
+    ~CppToolsSettings();
+
+    static CppToolsSettings *instance();
+
+    CppCodeStylePreferences *cppCodeStylePreferences() const;
+    TextEditor::TabPreferences *tabPreferences() const;
+
+private:
+    Internal::CppToolsSettingsPrivate *m_d;
+
+    static CppToolsSettings *m_instance;
+};
+
+} // namespace CppTools
+
+#endif // CPPTOOLSSETTINGS_H
diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp
index d65121f184b..dd078eaf394 100644
--- a/src/plugins/fakevim/fakevimplugin.cpp
+++ b/src/plugins/fakevim/fakevimplugin.cpp
@@ -59,6 +59,7 @@
 #include <texteditor/basetextmark.h>
 #include <texteditor/texteditorconstants.h>
 #include <texteditor/tabsettings.h>
+#include <texteditor/tabpreferences.h>
 #include <texteditor/texteditorsettings.h>
 #include <texteditor/indenter.h>
 #include <texteditor/codeassist/basicproposalitem.h>
@@ -237,7 +238,7 @@ QWidget *FakeVimOptionPage::createPage(QWidget *parent)
 
 void FakeVimOptionPage::copyTextEditorSettings()
 {
-    TabSettings ts = TextEditorSettings::instance()->tabSettings();
+    TabSettings ts = TextEditorSettings::instance()->tabPreferences()->settings();
     m_ui.checkBoxExpandTab->setChecked(ts.m_spacesForTabs);
     m_ui.spinBoxTabStop->setValue(ts.m_tabSize);
     m_ui.spinBoxShiftWidth->setValue(ts.m_indentSize);
diff --git a/src/plugins/glsleditor/glslindenter.cpp b/src/plugins/glsleditor/glslindenter.cpp
index a466dbac816..1180764c171 100644
--- a/src/plugins/glsleditor/glslindenter.cpp
+++ b/src/plugins/glsleditor/glslindenter.cpp
@@ -33,6 +33,8 @@
 #include "glslindenter.h"
 
 #include <cpptools/cppcodeformatter.h>
+#include <cpptools/cpptoolssettings.h>
+#include <cpptools/cppcodestylepreferences.h>
 #include <texteditor/basetexteditor.h>
 #include <texteditor/tabsettings.h>
 
@@ -69,7 +71,9 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
     Q_UNUSED(doc)
 
     const TextEditor::TabSettings &ts = editor->tabSettings();
-    CppTools::QtStyleCodeFormatter codeFormatter(ts);
+    // TODO: do something with it
+    CppTools::QtStyleCodeFormatter codeFormatter(ts,
+              CppTools::CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
 
     codeFormatter.updateStateUntil(block);
     int indent;
@@ -99,7 +103,9 @@ void GLSLIndenter::indent(QTextDocument *doc,
         const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
 
         const TextEditor::TabSettings &ts = editor->tabSettings();
-        CppTools::QtStyleCodeFormatter codeFormatter(ts);
+        // TODO: do something with it
+        CppTools::QtStyleCodeFormatter codeFormatter(ts,
+                  CppTools::CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
         codeFormatter.updateStateUntil(block);
 
         QTextCursor tc = editor->textCursor();
diff --git a/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp b/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp
new file mode 100644
index 00000000000..414d01c8a6c
--- /dev/null
+++ b/src/plugins/projectexplorer/codestylesettingspropertiespage.cpp
@@ -0,0 +1,62 @@
+#include "codestylesettingspropertiespage.h"
+#include "editorconfiguration.h"
+#include "project.h"
+#include <texteditor/codestylepreferencesmanager.h>
+#include <texteditor/icodestylepreferencesfactory.h>
+
+#include <QtCore/QTextCodec>
+
+using namespace TextEditor;
+using namespace ProjectExplorer;
+using namespace ProjectExplorer::Internal;
+
+QString CodeStyleSettingsPanelFactory::id() const
+{
+    return QLatin1String(CODESTYLESETTINGS_PANEL_ID);
+}
+
+QString CodeStyleSettingsPanelFactory::displayName() const
+{
+    return QCoreApplication::translate("CodeStyleSettingsPanelFactory", "Code Style Settings");
+}
+
+bool CodeStyleSettingsPanelFactory::supports(Project *project)
+{
+    Q_UNUSED(project);
+    return true;
+}
+
+PropertiesPanel *CodeStyleSettingsPanelFactory::createPanel(Project *project)
+{
+    PropertiesPanel *panel = new PropertiesPanel;
+    panel->setWidget(new CodeStyleSettingsWidget(project));
+    panel->setIcon(QIcon(":/projectexplorer/images/CodeStyleSettings.png"));
+    panel->setDisplayName(QCoreApplication::translate("CodeStyleSettingsPanel", "Code Style Settings"));
+    return panel;
+}
+
+CodeStyleSettingsWidget::CodeStyleSettingsWidget(Project *project) : QWidget(), m_project(project)
+{
+    m_ui.setupUi(this);
+
+    const EditorConfiguration *config = m_project->editorConfiguration();
+    CodeStylePreferencesManager *manager =
+            CodeStylePreferencesManager::instance();
+
+    QList<ICodeStylePreferencesFactory *> factories = manager->factories();
+    for (int i = 0; i < factories.count(); i++) {
+        ICodeStylePreferencesFactory *factory = factories.at(i);
+        const QString languageId = factory->languageId();
+        TabPreferences *tabPreferences = config->tabPreferences(languageId);
+        IFallbackPreferences *codeStylePreferences = config->codeStylePreferences(languageId);
+
+        QWidget *widget = factory->createEditor(codeStylePreferences, tabPreferences, m_ui.stackedWidget);
+        m_ui.stackedWidget->addWidget(widget);
+        m_ui.languageComboBox->addItem(factory->displayName());
+    }
+
+    connect(m_ui.languageComboBox, SIGNAL(currentIndexChanged(int)),
+            m_ui.stackedWidget, SLOT(setCurrentIndex(int)));
+}
+
+
diff --git a/src/plugins/projectexplorer/codestylesettingspropertiespage.h b/src/plugins/projectexplorer/codestylesettingspropertiespage.h
new file mode 100644
index 00000000000..07ba4ae4b71
--- /dev/null
+++ b/src/plugins/projectexplorer/codestylesettingspropertiespage.h
@@ -0,0 +1,41 @@
+#ifndef CODESTYLESETTINGSPROPERTIESPAGE_H
+#define CODESTYLESETTINGSPROPERTIESPAGE_H
+
+#include "iprojectproperties.h"
+#include "ui_codestylesettingspropertiespage.h"
+
+namespace ProjectExplorer {
+
+class EditorConfiguration;
+
+namespace Internal {
+
+const char * const CODESTYLESETTINGS_PANEL_ID("ProjectExplorer.CodeStyleSettingsPanel");
+
+class CodeStyleSettingsPanelFactory : public IProjectPanelFactory
+{
+public:
+    QString id() const;
+    QString displayName() const;
+    PropertiesPanel *createPanel(Project *project);
+    bool supports(Project *project);
+};
+
+class CodeStyleSettingsWidget;
+
+class CodeStyleSettingsWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    CodeStyleSettingsWidget(Project *project);
+
+private:
+    ProjectExplorer::Ui::CodeStyleSettingsPropertiesPage m_ui;
+    Project *m_project;
+};
+
+} // namespace Internal
+} // namespace ProjectExplorer
+
+
+#endif // CODESTYLESETTINGSPROPERTIESPAGE_H
diff --git a/src/plugins/projectexplorer/codestylesettingspropertiespage.ui b/src/plugins/projectexplorer/codestylesettingspropertiespage.ui
new file mode 100644
index 00000000000..4a0cd2c92cf
--- /dev/null
+++ b/src/plugins/projectexplorer/codestylesettingspropertiespage.ui
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ProjectExplorer::CodeStyleSettingsPropertiesPage</class>
+ <widget class="QWidget" name="ProjectExplorer::CodeStyleSettingsPropertiesPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>293</width>
+    <height>180</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QLabel" name="languageLabel">
+     <property name="text">
+      <string>Language:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QComboBox" name="languageComboBox"/>
+   </item>
+   <item row="0" column="2">
+    <spacer name="horizontalSpacer">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>73</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="1" column="0" colspan="3">
+    <widget class="QStackedWidget" name="stackedWidget"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp
index 1880567efda..a2881e51cb5 100644
--- a/src/plugins/projectexplorer/editorconfiguration.cpp
+++ b/src/plugins/projectexplorer/editorconfiguration.cpp
@@ -41,17 +41,26 @@
 #include <texteditor/basetexteditor.h>
 #include <texteditor/texteditorsettings.h>
 #include <texteditor/tabsettings.h>
+#include <texteditor/tabpreferences.h>
 #include <texteditor/storagesettings.h>
 #include <texteditor/behaviorsettings.h>
 #include <texteditor/extraencodingsettings.h>
+#include <texteditor/codestylepreferencesmanager.h>
+#include <texteditor/icodestylepreferencesfactory.h>
 
 #include <QtCore/QLatin1String>
 #include <QtCore/QByteArray>
 #include <QtCore/QTextCodec>
+#include <QtCore/QDebug>
 
 static const QLatin1String kPrefix("EditorConfiguration.");
 static const QLatin1String kUseGlobal("EditorConfiguration.UseGlobal");
 static const QLatin1String kCodec("EditorConfiguration.Codec");
+static const QLatin1String kTabPrefix("EditorConfiguration.Tab.");
+static const QLatin1String kTabCount("EditorConfiguration.Tab.Count");
+static const QLatin1String kCodeStylePrefix("EditorConfiguration.CodeStyle.");
+static const QLatin1String kCodeStyleCount("EditorConfiguration.CodeStyle.Count");
+static const QLatin1String kId("Project");
 
 using namespace TextEditor;
 
@@ -61,27 +70,73 @@ struct EditorConfigurationPrivate
 {
     EditorConfigurationPrivate()
         : m_useGlobal(true)
-        , m_tabSettings(TextEditorSettings::instance()->tabSettings())
+        , m_tabPreferences(0)
         , m_storageSettings(TextEditorSettings::instance()->storageSettings())
         , m_behaviorSettings(TextEditorSettings::instance()->behaviorSettings())
         , m_extraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings())
         , m_textCodec(Core::EditorManager::instance()->defaultTextCodec())
-    {}
+    {
+    }
 
     bool m_useGlobal;
-    TabSettings m_tabSettings;
+    TabPreferences *m_tabPreferences;
     StorageSettings m_storageSettings;
     BehaviorSettings m_behaviorSettings;
     ExtraEncodingSettings m_extraEncodingSettings;
     QTextCodec *m_textCodec;
+
+    QMap<QString, TabPreferences *> m_languageTabPreferences;
+    QMap<QString, IFallbackPreferences *> m_languageCodeStylePreferences;
 };
 
 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->setId(kId);
+
+    CodeStylePreferencesManager *manager =
+            CodeStylePreferencesManager::instance();
+    TextEditorSettings *settings = TextEditorSettings::instance();
+
+    const QMap<QString, TabPreferences *> languageTabPreferences = settings->languageTabPreferences();
+    QMapIterator<QString, TabPreferences *> itTab(languageTabPreferences);
+    while (itTab.hasNext()) {
+        itTab.next();
+        const QString languageId = itTab.key();
+        TabPreferences *originalPreferences = itTab.value();
+        TabPreferences *preferences = new TabPreferences(
+                    QList<IFallbackPreferences *>()
+                    << originalPreferences->fallbacks()
+                    << originalPreferences
+                    << tabPreferences(), this);
+        preferences->setId(languageId + QLatin1String("Project"));
+        preferences->setCurrentFallback(originalPreferences);
+        m_d->m_languageTabPreferences.insert(languageId, preferences);
+    }
+
+    const QMap<QString, IFallbackPreferences *> languageCodeStylePreferences = settings->languageCodeStylePreferences();
+    QMapIterator<QString, IFallbackPreferences *> itCodeStyle(languageCodeStylePreferences);
+    while (itCodeStyle.hasNext()) {
+        itCodeStyle.next();
+        const QString languageId = itCodeStyle.key();
+        IFallbackPreferences *originalPreferences = itCodeStyle.value();
+        ICodeStylePreferencesFactory *factory = manager->factory(languageId);
+        IFallbackPreferences *preferences = factory->createPreferences(
+                    QList<IFallbackPreferences *>() << originalPreferences);
+        preferences->setId(languageId + QLatin1String("Project"));
+        preferences->setDisplayName(tr("project %1").arg(factory->displayName()));
+        preferences->setCurrentFallback(originalPreferences);
+        m_d->m_languageCodeStylePreferences.insert(languageId, preferences);
+    }
 }
 
 EditorConfiguration::~EditorConfiguration()
 {
+    qDeleteAll(m_d->m_languageTabPreferences.values());
+    qDeleteAll(m_d->m_languageCodeStylePreferences.values());
 }
 
 bool EditorConfiguration::useGlobalSettings() const
@@ -91,16 +146,11 @@ bool EditorConfiguration::useGlobalSettings() const
 
 void EditorConfiguration::cloneGlobalSettings()
 {
-    m_d->m_tabSettings = TextEditorSettings::instance()->tabSettings();
-    m_d->m_storageSettings = TextEditorSettings::instance()->storageSettings();
-    m_d->m_behaviorSettings = TextEditorSettings::instance()->behaviorSettings();
-    m_d->m_extraEncodingSettings = TextEditorSettings::instance()->extraEncodingSettings();
+    m_d->m_tabPreferences->setSettings(TextEditorSettings::instance()->tabPreferences()->settings());
+    setStorageSettings(TextEditorSettings::instance()->storageSettings());
+    setBehaviorSettings(TextEditorSettings::instance()->behaviorSettings());
+    setExtraEncodingSettings(TextEditorSettings::instance()->extraEncodingSettings());
     m_d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec();
-
-    emitTabSettingsChanged();
-    emitStorageSettingsChanged();
-    emitBehaviorSettingsChanged();
-    emitExtraEncodingSettingsChanged();
 }
 
 QTextCodec *EditorConfiguration::textCodec() const
@@ -108,9 +158,9 @@ QTextCodec *EditorConfiguration::textCodec() const
     return m_d->m_textCodec;
 }
 
-const TabSettings &EditorConfiguration::tabSettings() const
+TabPreferences *EditorConfiguration::tabPreferences() const
 {
-    return m_d->m_tabSettings;
+    return m_d->m_tabPreferences;
 }
 
 const StorageSettings &EditorConfiguration::storageSettings() const
@@ -128,12 +178,64 @@ const ExtraEncodingSettings &EditorConfiguration::extraEncodingSettings() const
     return m_d->m_extraEncodingSettings;
 }
 
+TabPreferences *EditorConfiguration::tabPreferences(const QString &languageId) const
+{
+    TabPreferences *prefs = m_d->m_languageTabPreferences.value(languageId);
+    if (!prefs)
+        prefs = m_d->m_tabPreferences;
+    return prefs;
+}
+
+QMap<QString, TabPreferences *> EditorConfiguration::languageTabPreferences() const
+{
+    return m_d->m_languageTabPreferences;
+}
+
+IFallbackPreferences *EditorConfiguration::codeStylePreferences(const QString &languageId) const
+{
+    return m_d->m_languageCodeStylePreferences.value(languageId);
+}
+
+QMap<QString, IFallbackPreferences *> EditorConfiguration::languageCodeStylePreferences() const
+{
+    return m_d->m_languageCodeStylePreferences;
+}
+
 QVariantMap EditorConfiguration::toMap() const
 {
     QVariantMap map;
     map.insert(kUseGlobal, m_d->m_useGlobal);
     map.insert(kCodec, m_d->m_textCodec->name());
-    m_d->m_tabSettings.toMap(kPrefix, &map);
+
+    map.insert(kTabCount, m_d->m_languageTabPreferences.count());
+    QMapIterator<QString, TabPreferences *> itTab(m_d->m_languageTabPreferences);
+    int i = 0;
+    while (itTab.hasNext()) {
+        itTab.next();
+        QVariantMap settingsIdMap;
+        settingsIdMap.insert(QLatin1String("language"), itTab.key());
+        QVariantMap value;
+        itTab.value()->toMap(QString(), &value);
+        settingsIdMap.insert(QLatin1String("value"), value);
+        map.insert(kTabPrefix + QString::number(i), settingsIdMap);
+        i++;
+    }
+
+    map.insert(kCodeStyleCount, m_d->m_languageCodeStylePreferences.count());
+    QMapIterator<QString, IFallbackPreferences *> itCodeStyle(m_d->m_languageCodeStylePreferences);
+    i = 0;
+    while (itCodeStyle.hasNext()) {
+        itCodeStyle.next();
+        QVariantMap settingsIdMap;
+        settingsIdMap.insert(QLatin1String("language"), itCodeStyle.key());
+        QVariantMap value;
+        itCodeStyle.value()->toMap(QString(), &value);
+        settingsIdMap.insert(QLatin1String("value"), value);
+        map.insert(kCodeStylePrefix + QString::number(i), settingsIdMap);
+        i++;
+    }
+
+    m_d->m_tabPreferences->toMap(kPrefix, &map);
     m_d->m_storageSettings.toMap(kPrefix, &map);
     m_d->m_behaviorSettings.toMap(kPrefix, &map);
     m_d->m_extraEncodingSettings.toMap(kPrefix, &map);
@@ -150,17 +252,52 @@ void EditorConfiguration::fromMap(const QVariantMap &map)
     if (!m_d->m_textCodec)
         m_d->m_textCodec = Core::EditorManager::instance()->defaultTextCodec();
 
-    m_d->m_tabSettings.fromMap(kPrefix, map);
+    const int tabCount = map.value(kTabCount, 0).toInt();
+    for (int i = 0; i < tabCount; ++i) {
+        QVariantMap settingsIdMap = map.value(kTabPrefix + QString::number(i)).toMap();
+        if (settingsIdMap.isEmpty()) {
+            qWarning() << "No data for tab settings list" << i << "found!";
+            continue;
+        }
+        QString languageId = settingsIdMap.value(QLatin1String("language")).toString();
+        QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
+        TabPreferences *preferences = m_d->m_languageTabPreferences.value(languageId);
+        if (preferences) {
+             preferences->fromMap(QString(), value);
+        }
+    }
+
+    const int codeStyleCount = map.value(kCodeStyleCount, 0).toInt();
+    for (int i = 0; i < codeStyleCount; ++i) {
+        QVariantMap settingsIdMap = map.value(kCodeStylePrefix + QString::number(i)).toMap();
+        if (settingsIdMap.isEmpty()) {
+            qWarning() << "No data for code style settings list" << i << "found!";
+            continue;
+        }
+        QString languageId = settingsIdMap.value(QLatin1String("language")).toString();
+        QVariantMap value = settingsIdMap.value(QLatin1String("value")).toMap();
+        IFallbackPreferences *preferences = m_d->m_languageCodeStylePreferences.value(languageId);
+        if (preferences) {
+             preferences->fromMap(QString(), value);
+        }
+    }
+
+    m_d->m_tabPreferences->fromMap(kPrefix, map);
+    m_d->m_tabPreferences->setCurrentFallback(m_d->m_useGlobal
+                    ? TextEditorSettings::instance()->tabPreferences() : 0);
     m_d->m_storageSettings.fromMap(kPrefix, map);
     m_d->m_behaviorSettings.fromMap(kPrefix, map);
     m_d->m_extraEncodingSettings.fromMap(kPrefix, map);
 }
 
-void EditorConfiguration::apply(ITextEditor *textEditor) const
+void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
 {
+    BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(textEditor->widget());
+    baseTextEditor->setTabPreferences(tabPreferences(baseTextEditor->languageSettingsId()));
+    baseTextEditor->setCodeStylePreferences(codeStylePreferences(baseTextEditor->languageSettingsId()));
     if (!m_d->m_useGlobal) {
         textEditor->setTextCodec(m_d->m_textCodec, ITextEditor::TextCodecFromProjectSetting);
-        if (BaseTextEditorWidget *baseTextEditor = qobject_cast<BaseTextEditorWidget *>(textEditor->widget()))
+        if (baseTextEditor)
             switchSettings(baseTextEditor);
     }
 }
@@ -168,6 +305,8 @@ void EditorConfiguration::apply(ITextEditor *textEditor) const
 void EditorConfiguration::setUseGlobalSettings(bool use)
 {
     m_d->m_useGlobal = use;
+    m_d->m_tabPreferences->setCurrentFallback(m_d->m_useGlobal
+                    ? TextEditorSettings::instance()->tabPreferences() : 0);
     const SessionManager *session = ProjectExplorerPlugin::instance()->session();
     QList<Core::IEditor *> opened = Core::EditorManager::instance()->openedEditors();
     foreach (Core::IEditor *editor, opened) {
@@ -192,13 +331,10 @@ void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
                                                 const OldSenderT *oldSender,
                                                 BaseTextEditorWidget *baseTextEditor) const
 {
-    baseTextEditor->setTabSettings(newSender->tabSettings());
     baseTextEditor->setStorageSettings(newSender->storageSettings());
     baseTextEditor->setBehaviorSettings(newSender->behaviorSettings());
     baseTextEditor->setExtraEncodingSettings(newSender->extraEncodingSettings());
 
-    disconnect(oldSender, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
-               baseTextEditor, SLOT(setTabSettings(TextEditor::TabSettings)));
     disconnect(oldSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
                baseTextEditor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
     disconnect(oldSender, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -206,8 +342,6 @@ void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
     disconnect(oldSender, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)),
                baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
 
-    connect(newSender, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
-            baseTextEditor, SLOT(setTabSettings(TextEditor::TabSettings)));
     connect(newSender, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
             baseTextEditor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
     connect(newSender, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -216,101 +350,22 @@ void EditorConfiguration::switchSettings_helper(const NewSenderT *newSender,
             baseTextEditor, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
 }
 
-void EditorConfiguration::setInsertSpaces(bool spaces)
-{
-    m_d->m_tabSettings.m_spacesForTabs = spaces;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setAutoInsertSpaces(bool autoSpaces)
-{
-    m_d->m_tabSettings.m_autoSpacesForTabs = autoSpaces;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setAutoIndent(bool autoIndent)
-{
-    m_d->m_tabSettings.m_autoIndent = autoIndent;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setSmartBackSpace(bool smartBackSpace)
-{
-    m_d->m_tabSettings.m_smartBackspace = smartBackSpace;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setTabSize(int size)
-{
-    m_d->m_tabSettings.m_tabSize = size;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setIndentSize(int size)
-{
-    m_d->m_tabSettings.m_indentSize = size;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setIndentBlocksBehavior(int index)
-{
-    m_d->m_tabSettings.m_indentBraces = index >= 1;
-    m_d->m_tabSettings.m_doubleIndentBlocks = index >= 2;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setTabKeyBehavior(int index)
-{
-    m_d->m_tabSettings.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)index;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setContinuationAlignBehavior(int index)
-{
-    m_d->m_tabSettings.m_continuationAlignBehavior = (TabSettings::ContinuationAlignBehavior)index;
-    emitTabSettingsChanged();
-}
-
-void EditorConfiguration::setCleanWhiteSpace(bool cleanWhiteSpace)
-{
-    m_d->m_storageSettings.m_cleanWhitespace = cleanWhiteSpace;
-    emitStorageSettingsChanged();
-}
-
-void EditorConfiguration::setInEntireDocument(bool entireDocument)
-{
-    m_d->m_storageSettings.m_inEntireDocument = entireDocument;
-    emitStorageSettingsChanged();
-}
-
-void EditorConfiguration::setAddFinalNewLine(bool newLine)
-{
-    m_d->m_storageSettings.m_addFinalNewLine = newLine;
-    emitStorageSettingsChanged();
-}
-
-void EditorConfiguration::setCleanIndentation(bool cleanIndentation)
-{
-    m_d->m_storageSettings.m_cleanIndentation = cleanIndentation;
-    emitStorageSettingsChanged();
-}
-
-void EditorConfiguration::setMouseNavigation(bool mouseNavigation)
+void EditorConfiguration::setStorageSettings(const TextEditor::StorageSettings &settings)
 {
-    m_d->m_behaviorSettings.m_mouseNavigation = mouseNavigation;
-    emitBehaviorSettingsChanged();
+    m_d->m_storageSettings = settings;
+    emit storageSettingsChanged(m_d->m_storageSettings);
 }
 
-void EditorConfiguration::setScrollWheelZooming(bool scrollZooming)
+void EditorConfiguration::setBehaviorSettings(const TextEditor::BehaviorSettings &settings)
 {
-    m_d->m_behaviorSettings.m_scrollWheelZooming = scrollZooming;
-    emitBehaviorSettingsChanged();
+    m_d->m_behaviorSettings = settings;
+    emit behaviorSettingsChanged(m_d->m_behaviorSettings);
 }
 
-void EditorConfiguration::setUtf8BomSettings(int index)
+void EditorConfiguration::setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &settings)
 {
-    m_d->m_extraEncodingSettings.m_utf8BomSetting = (ExtraEncodingSettings::Utf8BomSetting)index;
-    emitExtraEncodingSettingsChanged();
+    m_d->m_extraEncodingSettings = settings;
+    emit extraEncodingSettingsChanged(m_d->m_extraEncodingSettings);
 }
 
 void EditorConfiguration::setTextCodec(QTextCodec *textCodec)
@@ -318,36 +373,17 @@ void EditorConfiguration::setTextCodec(QTextCodec *textCodec)
     m_d->m_textCodec = textCodec;
 }
 
-void EditorConfiguration::emitTabSettingsChanged()
-{
-    emit tabSettingsChanged(m_d->m_tabSettings);
-}
-
-void EditorConfiguration::emitStorageSettingsChanged()
-{
-    emit storageSettingsChanged(m_d->m_storageSettings);
-}
-
-void EditorConfiguration::emitBehaviorSettingsChanged()
-{
-    emit behaviorSettingsChanged(m_d->m_behaviorSettings);
-}
-
-void EditorConfiguration::emitExtraEncodingSettingsChanged()
-{
-    emit extraEncodingSettingsChanged(m_d->m_extraEncodingSettings);
-}
-
-const TabSettings &actualTabSettings(const QString &fileName, const BaseTextEditorWidget *baseTextEditor)
+TabSettings actualTabSettings(const QString &fileName,
+                                     const BaseTextEditorWidget *baseTextEditor)
 {
     if (baseTextEditor) {
         return baseTextEditor->tabSettings();
     } else {
         const SessionManager *session = ProjectExplorerPlugin::instance()->session();
         if (Project *project = session->projectForFile(fileName))
-            return project->editorConfiguration()->tabSettings();
+            return project->editorConfiguration()->tabPreferences()->settings();
         else
-            return TextEditorSettings::instance()->tabSettings();
+            return TextEditorSettings::instance()->tabPreferences()->settings();
     }
 }
 
diff --git a/src/plugins/projectexplorer/editorconfiguration.h b/src/plugins/projectexplorer/editorconfiguration.h
index e852f4bdce1..11e61309575 100644
--- a/src/plugins/projectexplorer/editorconfiguration.h
+++ b/src/plugins/projectexplorer/editorconfiguration.h
@@ -43,6 +43,8 @@ namespace TextEditor {
 class ITextEditor;
 class BaseTextEditorWidget;
 class TabSettings;
+class TabPreferences;
+class IFallbackPreferences;
 class StorageSettings;
 class BehaviorSettings;
 class ExtraEncodingSettings;
@@ -66,18 +68,22 @@ public:
     // The default codec is returned in the case the project doesn't override it.
     QTextCodec *textCodec() const;
 
-    const TextEditor::TabSettings &tabSettings() const;
+    TextEditor::TabPreferences *tabPreferences() const;
     const TextEditor::StorageSettings &storageSettings() const;
     const TextEditor::BehaviorSettings &behaviorSettings() const;
     const TextEditor::ExtraEncodingSettings &extraEncodingSettings() const;
 
-    void apply(TextEditor::ITextEditor *textEditor) const;
+    TextEditor::TabPreferences *tabPreferences(const QString &languageId) const;
+    QMap<QString, TextEditor::TabPreferences *> languageTabPreferences() const;
+    TextEditor::IFallbackPreferences *codeStylePreferences(const QString &languageId) const;
+    QMap<QString, TextEditor::IFallbackPreferences *> languageCodeStylePreferences() const;
+
+    void configureEditor(TextEditor::ITextEditor *textEditor) const;
 
     QVariantMap toMap() const;
     void fromMap(const QVariantMap &map);
 
 signals:
-    void tabSettingsChanged(const TextEditor::TabSettings &);
     void storageSettingsChanged(const TextEditor::StorageSettings &);
     void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
     void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
@@ -85,25 +91,9 @@ signals:
 private slots:
     void setUseGlobalSettings(bool use);
 
-    void setInsertSpaces(bool spaces);
-    void setAutoInsertSpaces(bool autoSpaces);
-    void setAutoIndent(bool autoIndent);
-    void setSmartBackSpace(bool smartBackSpace);
-    void setTabSize(int size);
-    void setIndentSize(int size);
-    void setIndentBlocksBehavior(int index);
-    void setTabKeyBehavior(int index);
-    void setContinuationAlignBehavior(int index);
-
-    void setCleanWhiteSpace(bool cleanWhiteSpace);
-    void setInEntireDocument(bool entireDocument);
-    void setAddFinalNewLine(bool newLine);
-    void setCleanIndentation(bool cleanIndentation);
-
-    void setMouseNavigation(bool mouseNavigation);
-    void setScrollWheelZooming(bool scrollZooming);
-
-    void setUtf8BomSettings(int index);
+    void setStorageSettings(const TextEditor::StorageSettings &settings);
+    void setBehaviorSettings(const TextEditor::BehaviorSettings &settings);
+    void setExtraEncodingSettings(const TextEditor::ExtraEncodingSettings &settings);
 
     void setTextCodec(QTextCodec *textCodec);
 
@@ -114,7 +104,6 @@ private:
                                const OldSenderT *oldSender,
                                TextEditor::BaseTextEditorWidget *baseTextEditor) const;
 
-    void emitTabSettingsChanged();
     void emitStorageSettingsChanged();
     void emitBehaviorSettingsChanged();
     void emitExtraEncodingSettingsChanged();
@@ -125,7 +114,7 @@ private:
 // Return the editor settings in the case it's not null. Otherwise, try to find the project
 // the file belongs to and return the project settings. If the file doesn't belong to any
 // project return the global settings.
-PROJECTEXPLORER_EXPORT const TextEditor::TabSettings &actualTabSettings(
+PROJECTEXPLORER_EXPORT TextEditor::TabSettings actualTabSettings(
     const QString &fileName, const TextEditor::BaseTextEditorWidget *baseTextEditor);
 
 } // ProjectExplorer
diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp
index 0cb1ae26806..ab685897f39 100644
--- a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp
+++ b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp
@@ -33,6 +33,7 @@
 #include "editorsettingspropertiespage.h"
 #include "editorconfiguration.h"
 #include "project.h"
+#include <texteditor/tabpreferences.h>
 
 #include <QtCore/QTextCodec>
 
@@ -78,47 +79,23 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj
     connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)),
             config, SLOT(setUseGlobalSettings(bool)));
     connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues()));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(insertSpacesChanged(bool)),
-            config, SLOT(setInsertSpaces(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(autoInsertSpacesChanged(bool)),
-            config, SLOT(setAutoInsertSpaces(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(autoIndentChanged(bool)),
-            config, SLOT(setAutoIndent(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(smartBackSpaceChanged(bool)),
-            config, SLOT(setSmartBackSpace(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(tabSizeChanged(int)),
-            config, SLOT(setTabSize(int)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(indentSizeChanged(int)),
-            config, SLOT(setIndentSize(int)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(indentBlocksBehaviorChanged(int)),
-            config, SLOT(setIndentBlocksBehavior(int)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(tabKeyBehaviorChanged(int)),
-            config, SLOT(setTabKeyBehavior(int)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(continuationAlignBehaviorChanged(int)),
-            config, SLOT(setContinuationAlignBehavior(int)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(cleanWhiteSpaceChanged(bool)),
-            config, SLOT(setCleanWhiteSpace(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(inEntireDocumentChanged(bool)),
-            config, SLOT(setInEntireDocument(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(addFinalNewLineChanged(bool)),
-            config, SLOT(setAddFinalNewLine(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(cleanIndentationChanged(bool)),
-            config, SLOT(setCleanIndentation(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(mouseNavigationChanged(bool)),
-            config, SLOT(setMouseNavigation(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(scrollWheelZoomingChanged(bool)),
-            config, SLOT(setScrollWheelZooming(bool)));
-    connect(m_ui.behaviorSettingsWidget, SIGNAL(utf8BomSettingsChanged(int)),
-            config, SLOT(setUtf8BomSettings(int)));
+    connect(m_ui.behaviorSettingsWidget, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
+            config, SLOT(setStorageSettings(TextEditor::StorageSettings)));
+    connect(m_ui.behaviorSettingsWidget, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
+            config, SLOT(setBehaviorSettings(TextEditor::BehaviorSettings)));
+    connect(m_ui.behaviorSettingsWidget, SIGNAL(extraEncodingSettingsChanged(TextEditor::ExtraEncodingSettings)),
+            config, SLOT(setExtraEncodingSettings(TextEditor::ExtraEncodingSettings)));
     connect(m_ui.behaviorSettingsWidget, SIGNAL(textCodecChanged(QTextCodec*)),
             config, SLOT(setTextCodec(QTextCodec*)));
+
+    m_ui.behaviorSettingsWidget->setFallbacksVisible(false);
 }
 
 void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config)
 {
+    m_ui.behaviorSettingsWidget->setTabPreferences(config->tabPreferences());
     m_ui.useGlobalCheckBox->setChecked(config->useGlobalSettings());
     m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec());
-    m_ui.behaviorSettingsWidget->setAssignedTabSettings(config->tabSettings());
     m_ui.behaviorSettingsWidget->setAssignedStorageSettings(config->storageSettings());
     m_ui.behaviorSettingsWidget->setAssignedBehaviorSettings(config->behaviorSettings());
     m_ui.behaviorSettingsWidget->setAssignedExtraEncodingSettings(config->extraEncodingSettings());
diff --git a/src/plugins/projectexplorer/images/CodeStyleSettings.png b/src/plugins/projectexplorer/images/CodeStyleSettings.png
new file mode 100644
index 0000000000000000000000000000000000000000..ebd869fb32bbf4f597a0aa224565f7a428e817c0
GIT binary patch
literal 932
zcmV;V16%xwP)<h;3K|Lk000e1NJLTq001xm001xu1^@s6R|5Hm0000PbVXQnQ*UN;
zcVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU#MoC0LRCwCVSxajaK@gsHXCFUBL<CVG
z;K_@GAgBo9(FkEqLWpD&QI|zTA|8aCTt&pAViG}P;>BwqkAsT(M>PAMackHf+O}t=
zy1FK@Au!wB)Ad!=SC5{ED2hDO2!g=8a7d%oY6;W4pYsw)Sej96_Vs!_uhZ#xLI|&3
zucz+wIjqA0SY7Y;`!RUT@DCfTX@CM)IsX3uSX~3l4+aDDxjt6t(ewAo6#KDx7o`mF
z9{$t;G2l!g5cu=cJ$CD>^CsS7yzjdT=347^yT)}V3gsPeZ1Mq1j*r5@NX{^R-g+~~
zM<E@&{`>pJ9Vg4fJXl`mJvMQWDdYm!6tonoS_iRd9G`la`QFzLi|ArSRl?c>>fE>W
z+hhP)mbV$?Ahwy;=fLvA;n1mYT6us|39vlS$3|fm3Z1yHlstcVzd%v~z(dxdc+FV>
z2^!||(rZ@MaiLzJl{jy2yWRG}FeJavo<?mz=pCjDV6q2JUVLnw;&xZ(;($%-?=ecS
zwGw-4w@4XB4O&j>u=GNCz)V5wN=Md8eCEoN%ntMOtDumWVynd4Z)a1fBRfp)w8>V9
zvw9r8SQV)RnnGA%X~n82C7gp;|DwQItXM1Y#MNcvo~_q6lbe;=q#cwJXaxXh8npnp
zel6qz?EG0JPY{5o7Au!Ew)+6KSaE=558|`emXpsRE@R`_jf49tp%$yn=hG}Saq$c(
z26WyR$$6G;R6Q6j;}ZPj%nOv8Kenbx)-B{l2Go(o%7(ibFzmgMekg#)e!J(eE^8q(
zHEC19OB9Ipr`O4VSz-W!7HCr{mEzy<41WNO`y#|np?H&@z6}(SsZhp-+R&+M9DuD9
zXf~Vd0!^7MYYs-aTqY@S4)cFv)w0s^GSGDoP-rx2(T_A5jgX?iFNh%-1Caky07YXE
zdbCCQ+<2oftVu0|w#Td0YJy6keR=rEg+liHW3aK1Q<s*!4A9B*?%D!1)h3Ej6!@(Q
z0Um<Y)xLl4-6CtD;x1(SqXSiUN7ZUIRzkaZ36lpj>;2;y4eVdE;p#>^Cd)udg&>8w
z)0ZEiglw<OlP&L3iMytkL4iu85?|nVR_pA5Y%B2}0R{j{%_hi+q32To0000<MNUMn
GLSTYj`@0GN

literal 0
HcmV?d00001

diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 9771ca56cb0..31ba223aa1d 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -53,6 +53,7 @@
 #include "currentprojectfilter.h"
 #include "customexecutablerunconfiguration.h"
 #include "editorsettingspropertiespage.h"
+#include "codestylesettingspropertiespage.h"
 #include "dependenciespanel.h"
 #include "foldernavigationwidget.h"
 #include "iprojectmanager.h"
@@ -389,6 +390,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
     addAutoReleasedObject(new BuildSettingsPanelFactory);
     addAutoReleasedObject(new RunSettingsPanelFactory);
     addAutoReleasedObject(new EditorSettingsPanelFactory);
+    addAutoReleasedObject(new CodeStyleSettingsPanelFactory);
     addAutoReleasedObject(new DependenciesPanelFactory(d->m_session));
 
     ProcessStepFactory *processStepFactory = new ProcessStepFactory;
diff --git a/src/plugins/projectexplorer/projectexplorer.pro b/src/plugins/projectexplorer/projectexplorer.pro
index ae75f21ec78..60466c6b45f 100644
--- a/src/plugins/projectexplorer/projectexplorer.pro
+++ b/src/plugins/projectexplorer/projectexplorer.pro
@@ -99,7 +99,8 @@ HEADERS += projectexplorer.h \
     publishing/ipublishingwizardfactory.h \
     headerpath.h \
     gcctoolchainfactories.h \
-    appoutputpane.h
+    appoutputpane.h \
+    codestylesettingspropertiespage.h
 
 SOURCES += projectexplorer.cpp \
     abi.cpp \
@@ -184,7 +185,8 @@ SOURCES += projectexplorer.cpp \
     customexecutableconfigurationwidget.cpp \
     sessionnodeimpl.cpp \
     publishing/publishingwizardselectiondialog.cpp \
-    appoutputpane.cpp
+    appoutputpane.cpp \
+    codestylesettingspropertiespage.cpp
 
 FORMS += processstep.ui \
     toolchainoptionspage.ui \
@@ -197,7 +199,8 @@ FORMS += processstep.ui \
     projectwelcomepagewidget.ui \
     targetsettingswidget.ui \
     doubletabwidget.ui \
-    publishing/publishingwizardselectiondialog.ui
+    publishing/publishingwizardselectiondialog.ui \
+    codestylesettingspropertiespage.ui
 
 equals(TEST, 1) {
     SOURCES += \
diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index 339a52aae8f..9699943ec5a 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -827,9 +827,8 @@ void SessionManager::configureEditor(Core::IEditor *editor, const QString &fileN
     if (TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor*>(editor)) {
         Project *project = projectForFile(fileName);
         // Global settings are the default.
-        if (project && !project->editorConfiguration()->useGlobalSettings()) {
-            project->editorConfiguration()->apply(textEditor);
-        }
+        if (project)
+            project->editorConfiguration()->configureEditor(textEditor);
     }
 }
 
diff --git a/src/plugins/qmldesigner/settingspage.cpp b/src/plugins/qmldesigner/settingspage.cpp
index 4a11e7d8707..486ba9eb367 100644
--- a/src/plugins/qmldesigner/settingspage.cpp
+++ b/src/plugins/qmldesigner/settingspage.cpp
@@ -84,7 +84,7 @@ SettingsPage::SettingsPage() :
 
 QString SettingsPage::id() const
 {
-    return QLatin1String("QmlDesigner");
+    return QLatin1String("B.QmlDesigner");
 }
 
 QString SettingsPage::displayName() const
diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 017ae2b80ca..6d0f030f749 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -38,7 +38,6 @@
 #include "qmloutlinemodel.h"
 #include "qmljsfindreferences.h"
 #include "qmljssemantichighlighter.h"
-#include "qmljsindenter.h"
 #include "qmljsautocompleter.h"
 #include "qmljscompletionassist.h"
 #include "qmljsquickfixassist.h"
@@ -53,6 +52,7 @@
 #include <qmljs/parser/qmljsast_p.h>
 #include <qmljs/parser/qmljsengine_p.h>
 
+#include <qmljstools/qmljsindenter.h>
 #include <qmljstools/qmljsqtstylecodeformatter.h>
 
 #include <coreplugin/actionmanager/actionmanager.h>
@@ -1448,6 +1448,14 @@ void QmlJSTextEditorWidget::unCommentSelection()
     Utils::unCommentSelection(this);
 }
 
+void QmlJSTextEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
+{
+    QmlJSTools::QtStyleCodeFormatter formatter(ts);
+    formatter.invalidateCache(document());
+
+    TextEditor::BaseTextEditorWidget::setTabSettings(ts);
+}
+
 void QmlJSTextEditorWidget::forceSemanticRehighlight()
 {
     m_semanticHighlighter->rehighlight(currentSource(/* force = */ true));
diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h
index dabe5bf295f..ee66b782b84 100644
--- a/src/plugins/qmljseditor/qmljseditor.h
+++ b/src/plugins/qmljseditor/qmljseditor.h
@@ -164,6 +164,7 @@ public:
                                                         TextEditor::AssistReason reason) const;
 
 public slots:
+    virtual void setTabSettings(const TextEditor::TabSettings &ts);
     void forceSemanticRehighlight();
     void followSymbolUnderCursor();
     void findUsages();
diff --git a/src/plugins/qmljseditor/qmljseditor.pro b/src/plugins/qmljseditor/qmljseditor.pro
index b52dcfc679e..78c09fdf8fc 100644
--- a/src/plugins/qmljseditor/qmljseditor.pro
+++ b/src/plugins/qmljseditor/qmljseditor.pro
@@ -30,7 +30,6 @@ HEADERS += \
     qmljsfindreferences.h \
     qmljseditoreditable.h \
     qmljssemantichighlighter.h \
-    qmljsindenter.h \
     qmljsautocompleter.h \
     jsfilewizard.h \
     qmljssnippetprovider.h \
@@ -61,7 +60,6 @@ SOURCES += \
     qmljsfindreferences.cpp \
     qmljseditoreditable.cpp \
     qmljssemantichighlighter.cpp \
-    qmljsindenter.cpp \
     qmljsautocompleter.cpp \
     jsfilewizard.cpp \
     qmljssnippetprovider.cpp \
diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp
index e18c8e6e4ea..9051907e6aa 100644
--- a/src/plugins/qmljseditor/qmljseditorplugin.cpp
+++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp
@@ -49,6 +49,7 @@
 
 #include <qmljs/qmljsicons.h>
 #include <qmljs/qmljsmodelmanagerinterface.h>
+#include <qmljstools/qmljstoolsconstants.h>
 
 #include <qmldesigner/qmldesignerconstants.h>
 
@@ -264,6 +265,7 @@ void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::QmlJSTextEditorWidget *edi
 
     m_actionHandler->setupActions(editor);
 
+    editor->setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
     TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
 }
 
diff --git a/src/plugins/qmljseditor/qmljssnippetprovider.cpp b/src/plugins/qmljseditor/qmljssnippetprovider.cpp
index f48dccf1e36..9d140cb4345 100644
--- a/src/plugins/qmljseditor/qmljssnippetprovider.cpp
+++ b/src/plugins/qmljseditor/qmljssnippetprovider.cpp
@@ -33,7 +33,6 @@
 #include "qmljssnippetprovider.h"
 #include "qmljshighlighter.h"
 #include "qmljseditor.h"
-#include "qmljsindenter.h"
 #include "qmljsautocompleter.h"
 #include "qmljseditorconstants.h"
 
@@ -42,6 +41,8 @@
 #include <texteditor/texteditorconstants.h>
 #include <texteditor/snippets/snippeteditor.h>
 
+#include <qmljstools/qmljsindenter.h>
+
 #include <QtCore/QLatin1String>
 #include <QtCore/QCoreApplication>
 
diff --git a/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp b/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp
index 523fdcaa9db..2d95efe9fcb 100644
--- a/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp
+++ b/src/plugins/qmljseditor/quicktoolbarsettingspage.cpp
@@ -130,7 +130,7 @@ QuickToolBarSettingsPage::QuickToolBarSettingsPage() :
 
 QString QuickToolBarSettingsPage::id() const
 {
-    return QLatin1String("QmlToolbar");
+    return QLatin1String("C.QmlToolbar");
 }
 
 QString QuickToolBarSettingsPage::displayName() const
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.cpp b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
new file mode 100644
index 00000000000..01968e4bdb0
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.cpp
@@ -0,0 +1,197 @@
+#include "qmljscodestylesettingspage.h"
+#include "ui_qmljscodestylesettingspage.h"
+#include "qmljstoolsconstants.h"
+#include "qmljsindenter.h"
+#include "qmljsqtstylecodeformatter.h"
+
+#include <texteditor/snippets/isnippetprovider.h>
+#include <texteditor/fontsettings.h>
+#include <texteditor/tabsettings.h>
+#include <texteditor/tabpreferences.h>
+#include <texteditor/displaysettings.h>
+#include <texteditor/texteditorsettings.h>
+#include <extensionsystem/pluginmanager.h>
+#include <qmldesigner/qmldesignerconstants.h>
+#include <qmljseditor/qmljseditorconstants.h>
+#include <coreplugin/icore.h>
+
+#include <QtCore/QTextStream>
+
+using namespace TextEditor;
+
+namespace QmlJSTools {
+namespace Internal {
+
+// ------------------ CppCodeStyleSettingsWidget
+
+QmlJSCodeStyleSettingsWidget::QmlJSCodeStyleSettingsWidget(QWidget *parent) :
+    QWidget(parent),
+    m_tabPreferences(0),
+    m_ui(new ::Ui::QmlJSCodeStyleSettingsPage)
+{
+    m_ui->setupUi(this);
+
+    const QList<ISnippetProvider *> &providers =
+        ExtensionSystem::PluginManager::instance()->getObjects<ISnippetProvider>();
+    foreach (ISnippetProvider *provider, providers) {
+        if (provider->groupId() == QLatin1String(QmlJSEditor::Constants::QML_SNIPPETS_GROUP_ID)) {
+            provider->decorateEditor(m_ui->previewTextEdit);
+            break;
+        }
+    }
+    TextEditor::TextEditorSettings *settings = TextEditorSettings::instance();
+    setFontSettings(settings->fontSettings());
+    connect(settings, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
+       this, SLOT(setFontSettings(TextEditor::FontSettings)));
+
+    setVisualizeWhitespace(true);
+
+    updatePreview();
+}
+
+QmlJSCodeStyleSettingsWidget::~QmlJSCodeStyleSettingsWidget()
+{
+    delete m_ui;
+}
+
+void QmlJSCodeStyleSettingsWidget::setTabPreferences(TextEditor::TabPreferences *tabPreferences)
+{
+    m_tabPreferences = tabPreferences;
+    m_ui->tabPreferencesWidget->setTabPreferences(tabPreferences);
+    connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
+            this, SLOT(slotTabSettingsChanged()));
+    updatePreview();
+}
+
+
+QString QmlJSCodeStyleSettingsWidget::searchKeywords() const
+{
+    QString rc;
+    QLatin1Char sep(' ');
+    QTextStream(&rc)
+       << sep << m_ui->tabPreferencesWidget->searchKeywords()
+          ;
+    rc.remove(QLatin1Char('&'));
+    return rc;
+}
+
+void QmlJSCodeStyleSettingsWidget::setFontSettings(const TextEditor::FontSettings &fontSettings)
+{
+    m_ui->previewTextEdit->setFont(fontSettings.font());
+}
+
+void QmlJSCodeStyleSettingsWidget::setVisualizeWhitespace(bool on)
+{
+    DisplaySettings displaySettings = m_ui->previewTextEdit->displaySettings();
+    displaySettings.m_visualizeWhitespace = on;
+    m_ui->previewTextEdit->setDisplaySettings(displaySettings);
+}
+
+void QmlJSCodeStyleSettingsWidget::slotTabSettingsChanged()
+{
+    updatePreview();
+}
+
+void QmlJSCodeStyleSettingsWidget::updatePreview()
+{
+    QTextDocument *doc = m_ui->previewTextEdit->document();
+
+    const TextEditor::TabSettings &ts = m_tabPreferences
+            ? m_tabPreferences->currentSettings() : TextEditorSettings::instance()->tabPreferences()->settings();
+    m_ui->previewTextEdit->setTabSettings(ts);
+    QtStyleCodeFormatter formatter(ts);
+    formatter.invalidateCache(doc);
+
+    QTextBlock block = doc->firstBlock();
+    QTextCursor tc = m_ui->previewTextEdit->textCursor();
+    tc.beginEditBlock();
+    while (block.isValid()) {
+        int depth = formatter.indentFor(block);
+        ts.indentLine(block, depth);
+        formatter.updateLineStateChange(block);
+
+        block = block.next();
+    }
+    tc.endEditBlock();
+}
+
+// ------------------ CppCodeStyleSettingsPage
+
+QmlJSCodeStyleSettingsPage::QmlJSCodeStyleSettingsPage(/*QSharedPointer<CppFileSettings> &settings,*/
+                     QWidget *parent) :
+    Core::IOptionsPage(parent)/*,
+    m_settings(settings)*/
+{
+    if (const QSettings *s = Core::ICore::instance()->settings()) {
+        TextEditor::TabSettings tabSettings;
+        // read it from old global settings for the first time?
+        tabSettings.fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
+//        TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
+//        textEditorSettings->setTabSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID,
+//                                           tabSettings);
+    }
+}
+
+QmlJSCodeStyleSettingsPage::~QmlJSCodeStyleSettingsPage()
+{
+}
+
+QString QmlJSCodeStyleSettingsPage::id() const
+{
+    return QLatin1String(Constants::QML_JS_CODE_STYLE_SETTINGS_ID);
+}
+
+QString QmlJSCodeStyleSettingsPage::displayName() const
+{
+    return QCoreApplication::translate("QmlJSTools", Constants::QML_JS_CODE_STYLE_SETTINGS_NAME);
+}
+
+QString QmlJSCodeStyleSettingsPage::category() const
+{
+    return QLatin1String("Qt Quick");
+}
+
+QString QmlJSCodeStyleSettingsPage::displayCategory() const
+{
+    return QCoreApplication::translate("Qt Quick", "Qt Quick");
+}
+
+QIcon QmlJSCodeStyleSettingsPage::categoryIcon() const
+{
+    return QIcon(QLatin1String(QmlDesigner::Constants::SETTINGS_CATEGORY_QML_ICON));
+}
+
+QWidget *QmlJSCodeStyleSettingsPage::createPage(QWidget *parent)
+{
+    m_widget = new QmlJSCodeStyleSettingsWidget(parent);
+    m_widget->setTabPreferences(
+                TextEditorSettings::instance()->tabPreferences(
+                    QmlJSTools::Constants::QML_JS_SETTINGS_ID));
+
+    if (m_searchKeywords.isEmpty())
+        m_searchKeywords = m_widget->searchKeywords();
+    return m_widget;
+}
+
+void QmlJSCodeStyleSettingsPage::apply()
+{
+//    if (m_widget) {
+//        const TabSettings newTabSettings = m_widget->tabSettings();
+//        TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
+//        if (newTabSettings != textEditorSettings->tabSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID)) {
+//            textEditorSettings->setTabSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID,
+//                                               newTabSettings);
+//            if (QSettings *s = Core::ICore::instance()->settings()) {
+//                newTabSettings.toSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
+//            }
+//        }
+//    }
+}
+
+bool QmlJSCodeStyleSettingsPage::matches(const QString &s) const
+{
+    return m_searchKeywords.contains(s, Qt::CaseInsensitive);
+}
+
+} // namespace Internal
+} // namespace CppTools
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.h b/src/plugins/qmljstools/qmljscodestylesettingspage.h
new file mode 100644
index 00000000000..c7574e30e37
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.h
@@ -0,0 +1,77 @@
+#ifndef QMLJSCODESTYLESETTINGSPAGE_H
+#define QMLJSCODESTYLESETTINGSPAGE_H
+
+#include <coreplugin/dialogs/ioptionspage.h>
+#include <QtGui/QWidget>
+#include <QtCore/QPointer>
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+    class QmlJSCodeStyleSettingsPage;
+}
+class QSettings;
+QT_END_NAMESPACE
+
+namespace TextEditor {
+    class FontSettings;
+    class TabSettings;
+    class TabPreferences;
+}
+
+namespace QmlJSTools {
+namespace Internal {
+
+class QmlJSCodeStyleSettingsWidget : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit QmlJSCodeStyleSettingsWidget(QWidget *parent = 0);
+    virtual ~QmlJSCodeStyleSettingsWidget();
+
+    void setTabPreferences(TextEditor::TabPreferences *tabPreferences);
+
+    QString searchKeywords() const;
+
+private slots:
+    void setFontSettings(const TextEditor::FontSettings &fontSettings);
+    void setVisualizeWhitespace(bool on);
+    void slotTabSettingsChanged();
+    void updatePreview();
+
+private:
+
+    TextEditor::TabPreferences *m_tabPreferences;
+    Ui::QmlJSCodeStyleSettingsPage *m_ui;
+};
+
+
+class QmlJSCodeStyleSettingsPage : public Core::IOptionsPage
+{
+    Q_OBJECT
+
+public:
+    explicit QmlJSCodeStyleSettingsPage(QWidget *parent = 0);
+    ~QmlJSCodeStyleSettingsPage();
+
+    virtual QString id() const;
+    virtual QString displayName() const;
+    virtual QString category() const;
+    virtual QString displayCategory() const;
+    virtual QIcon categoryIcon() const;
+
+    virtual QWidget *createPage(QWidget *parent);
+    virtual void apply();
+    virtual void finish() { }
+    virtual bool matches(const QString &) const;
+
+
+private:
+    QString m_searchKeywords;
+    QPointer<QmlJSCodeStyleSettingsWidget> m_widget;
+};
+
+} // namespace Internal
+} // namespace CppTools
+
+#endif // QMLJSCODESTYLESETTINGSPAGE_H
diff --git a/src/plugins/qmljstools/qmljscodestylesettingspage.ui b/src/plugins/qmljstools/qmljscodestylesettingspage.ui
new file mode 100644
index 00000000000..601aa03fc6a
--- /dev/null
+++ b/src/plugins/qmljstools/qmljscodestylesettingspage.ui
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QmlJSCodeStyleSettingsPage</class>
+ <widget class="QWidget" name="QmlJSCodeStyleSettingsPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>342</width>
+    <height>304</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="TextEditor::TabPreferencesWidget" name="tabPreferencesWidget" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="TextEditor::SnippetEditorWidget" name="previewTextEdit">
+     <property name="plainText">
+      <string>import QtQuick 1.0
+
+Rectangle {
+    width: 360
+    height: 360
+    Text {
+        anchors.centerIn: parent
+        text: &quot;Hello World&quot;
+    }
+    MouseArea {
+        anchors.fill: parent
+        onClicked: {
+            Qt.quit();
+        }
+    }
+}
+</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>TextEditor::SnippetEditorWidget</class>
+   <extends>QPlainTextEdit</extends>
+   <header location="global">texteditor/snippets/snippeteditor.h</header>
+  </customwidget>
+  <customwidget>
+   <class>TextEditor::TabPreferencesWidget</class>
+   <extends>QWidget</extends>
+   <header location="global">texteditor/tabpreferenceswidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/qmljseditor/qmljsindenter.cpp b/src/plugins/qmljstools/qmljsindenter.cpp
similarity index 100%
rename from src/plugins/qmljseditor/qmljsindenter.cpp
rename to src/plugins/qmljstools/qmljsindenter.cpp
diff --git a/src/plugins/qmljseditor/qmljsindenter.h b/src/plugins/qmljstools/qmljsindenter.h
similarity index 95%
rename from src/plugins/qmljseditor/qmljsindenter.h
rename to src/plugins/qmljstools/qmljsindenter.h
index 5b39fe4c08a..da29d56ecef 100644
--- a/src/plugins/qmljseditor/qmljsindenter.h
+++ b/src/plugins/qmljstools/qmljsindenter.h
@@ -33,12 +33,14 @@
 #ifndef QMLJSINDENTER_H
 #define QMLJSINDENTER_H
 
+#include "qmljstools_global.h"
+
 #include <texteditor/indenter.h>
 
 namespace QmlJSEditor {
 namespace Internal {
 
-class Indenter : public TextEditor::Indenter
+class QMLJSTOOLS_EXPORT Indenter : public TextEditor::Indenter
 {
 public:
     Indenter();
diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
index 15ce9ff6d1b..b4d1027ed87 100644
--- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
+++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp
@@ -32,6 +32,7 @@
 
 #include "qmljsrefactoringchanges.h"
 #include "qmljsqtstylecodeformatter.h"
+#include "qmljstoolsconstants.h"
 
 #include <qmljs/parser/qmljsast_p.h>
 #include <qmljs/qmljsmodelmanagerinterface.h>
diff --git a/src/plugins/qmljstools/qmljstools-lib.pri b/src/plugins/qmljstools/qmljstools-lib.pri
index 6c622dba074..607830d55cd 100644
--- a/src/plugins/qmljstools/qmljstools-lib.pri
+++ b/src/plugins/qmljstools/qmljstools-lib.pri
@@ -13,7 +13,9 @@ HEADERS += \
     $$PWD/qmljsrefactoringchanges.h \
     $$PWD/qmljsplugindumper.h \
     $$PWD/qmljsfunctionfilter.h \
-    $$PWD/qmljslocatordata.h
+    $$PWD/qmljslocatordata.h \
+    $$PWD/qmljsindenter.h \
+    $$PWD/qmljscodestylesettingspage.h
 
 SOURCES += \
     $$PWD/qmljstoolsplugin.cpp \
@@ -22,4 +24,9 @@ SOURCES += \
     $$PWD/qmljsrefactoringchanges.cpp \
     $$PWD/qmljsplugindumper.cpp \
     $$PWD/qmljsfunctionfilter.cpp \
-    $$PWD/qmljslocatordata.cpp
+    $$PWD/qmljslocatordata.cpp \
+    $$PWD/qmljsindenter.cpp \
+    $$PWD/qmljscodestylesettingspage.cpp
+
+FORMS += \
+    $$PWD/qmljscodestylesettingspage.ui
diff --git a/src/plugins/qmljstools/qmljstoolsconstants.h b/src/plugins/qmljstools/qmljstoolsconstants.h
index bca7764b312..73cfa2c5c47 100644
--- a/src/plugins/qmljstools/qmljstoolsconstants.h
+++ b/src/plugins/qmljstools/qmljstoolsconstants.h
@@ -43,6 +43,12 @@ const char * const JS_MIMETYPE = "application/javascript";
 
 const char * const TASK_INDEX = "QmlJSEditor.TaskIndex";
 
+const char * const QML_JS_CODE_STYLE_SETTINGS_ID = "A.Code Style";
+const char * const QML_JS_CODE_STYLE_SETTINGS_NAME = QT_TRANSLATE_NOOP("QmlJSTools", "Code Style");
+
+const char * const QML_JS_SETTINGS_ID = "QmlJS";
+const char * const QML_JS_SETTINGS_NAME = QT_TRANSLATE_NOOP("QmlJSTools", "Qt Quick");
+
 } // namespace Constants
 } // namespace QmlJSEditor
 
diff --git a/src/plugins/qmljstools/qmljstoolsplugin.cpp b/src/plugins/qmljstools/qmljstoolsplugin.cpp
index 3373a8d1541..322070c93ef 100644
--- a/src/plugins/qmljstools/qmljstoolsplugin.cpp
+++ b/src/plugins/qmljstools/qmljstoolsplugin.cpp
@@ -34,6 +34,11 @@
 #include "qmljsmodelmanager.h"
 #include "qmljsfunctionfilter.h"
 #include "qmljslocatordata.h"
+#include "qmljscodestylesettingspage.h"
+#include "qmljstoolsconstants.h"
+
+#include <texteditor/texteditorsettings.h>
+#include <texteditor/tabsettings.h>
 
 #include <extensionsystem/pluginmanager.h>
 
@@ -82,6 +87,7 @@ bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
     LocatorData *locatorData = new LocatorData;
     addAutoReleasedObject(locatorData);
     addAutoReleasedObject(new FunctionFilter(locatorData));
+//    addAutoReleasedObject(new QmlJSCodeStyleSettingsPage);
 
     return true;
 }
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 565ed6a01d9..d5a80b21681 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -39,6 +39,7 @@
 #include "codecselector.h"
 #include "completionsettings.h"
 #include "tabsettings.h"
+#include "tabpreferences.h"
 #include "texteditorconstants.h"
 #include "texteditorplugin.h"
 #include "syntaxhighlighter.h"
@@ -2341,6 +2342,8 @@ BaseTextEditorPrivate::BaseTextEditorPrivate()
     m_formatRange(false),
     m_parenthesesMatchingTimer(0),
     m_extraArea(0),
+    m_tabPreferences(0),
+    m_codeStylePreferences(0),
     extraAreaSelectionAnchorBlockNumber(-1),
     extraAreaToggleMarkBlockNumber(-1),
     extraAreaHighlightFoldedBlockNumber(-1),
@@ -4308,6 +4311,50 @@ const TabSettings &BaseTextEditorWidget::tabSettings() const
     return d->m_document->tabSettings();
 }
 
+void BaseTextEditorWidget::setLanguageSettingsId(const QString &settingsId)
+{
+    d->m_tabSettingsId = settingsId;
+}
+
+QString BaseTextEditorWidget::languageSettingsId() const
+{
+    return d->m_tabSettingsId;
+}
+
+void BaseTextEditorWidget::setTabPreferences(TabPreferences *tabPreferences)
+{
+    if (d->m_tabPreferences) {
+        disconnect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
+                this, SLOT(setTabSettings(TextEditor::TabSettings)));
+    }
+    d->m_tabPreferences = tabPreferences;
+    if (d->m_tabPreferences) {
+        connect(d->m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
+                this, SLOT(setTabSettings(TextEditor::TabSettings)));
+        setTabSettings(d->m_tabPreferences->currentSettings());
+    }
+}
+
+void BaseTextEditorWidget::setCodeStylePreferences(IFallbackPreferences *preferences)
+{
+    indenter()->setCodeStylePreferences(preferences);
+    if (d->m_codeStylePreferences) {
+        disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
+                this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
+    }
+    d->m_codeStylePreferences = preferences;
+    if (d->m_codeStylePreferences) {
+        connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
+                this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
+        slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue());
+    }
+}
+
+void BaseTextEditorWidget::slotCodeStyleSettingsChanged(const QVariant &)
+{
+
+}
+
 const DisplaySettings &BaseTextEditorWidget::displaySettings() const
 {
     return d->m_displaySettings;
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index dd8e141a041..e7915545d63 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -54,11 +54,13 @@ namespace Utils {
 
 namespace TextEditor {
 class TabSettings;
+class TabPreferences;
 class RefactorOverlay;
 struct RefactorMarker;
 class IAssistMonitorInterface;
 class IAssistInterface;
 class IAssistProvider;
+class IFallbackPreferences;
 
 namespace Internal {
     class BaseTextEditorPrivate;
@@ -368,6 +370,12 @@ public:
     virtual void extraAreaMouseEvent(QMouseEvent *);
 
     const TabSettings &tabSettings() const;
+    void setLanguageSettingsId(const QString &settingsId);
+    QString languageSettingsId() const;
+
+    void setTabPreferences(TabPreferences *preferences);
+    void setCodeStylePreferences(IFallbackPreferences *settings);
+
     const DisplaySettings &displaySettings() const;
 
     void markBlocksAsChanged(QList<int> blockNumbers);
@@ -493,6 +501,7 @@ protected slots:
     virtual void slotUpdateRequest(const QRect &r, int dy);
     virtual void slotCursorPositionChanged();
     virtual void slotUpdateBlockNotify(const QTextBlock &);
+    virtual void slotCodeStyleSettingsChanged(const QVariant &);
 
 signals:
     void requestFontZoom(int zoom);
diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h
index 189e5874245..d8619e24dac 100644
--- a/src/plugins/texteditor/basetexteditor_p.h
+++ b/src/plugins/texteditor/basetexteditor_p.h
@@ -208,6 +208,9 @@ public:
 
     QWidget *m_extraArea;
 
+    QString m_tabSettingsId;
+    TabPreferences *m_tabPreferences;
+    IFallbackPreferences *m_codeStylePreferences;
     DisplaySettings m_displaySettings;
     FontSettings m_fontSettings;
     BehaviorSettings m_behaviorSettings;
diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp
index 1415b191a55..7b240f1028b 100644
--- a/src/plugins/texteditor/behaviorsettingspage.cpp
+++ b/src/plugins/texteditor/behaviorsettingspage.cpp
@@ -37,6 +37,7 @@
 #include "tabsettings.h"
 #include "extraencodingsettings.h"
 #include "ui_behaviorsettingspage.h"
+#include "tabpreferences.h"
 
 #include <coreplugin/icore.h>
 #include <coreplugin/coreconstants.h>
@@ -45,6 +46,8 @@
 #include <QtCore/QSettings>
 #include <QtCore/QTextCodec>
 
+static const char *idKey = "Global";
+
 using namespace TextEditor;
 
 struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
@@ -54,7 +57,10 @@ struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
     const BehaviorSettingsPageParameters m_parameters;
     Ui::BehaviorSettingsPage *m_page;
 
-    TabSettings m_tabSettings;
+    void init();
+
+    TabPreferences *m_tabPreferences;
+    TabPreferences *m_pageTabPreferences;
     StorageSettings m_storageSettings;
     BehaviorSettings m_behaviorSettings;
     ExtraEncodingSettings m_extraEncodingSettings;
@@ -64,10 +70,16 @@ struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
 
 BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate
     (const BehaviorSettingsPageParameters &p)
-    : m_parameters(p), m_page(0)
+    : m_parameters(p), m_page(0), m_pageTabPreferences(0)
+{
+}
+
+void BehaviorSettingsPage::BehaviorSettingsPagePrivate::init()
 {
     if (const QSettings *s = Core::ICore::instance()->settings()) {
-        m_tabSettings.fromSettings(m_parameters.settingsPrefix, s);
+        TabSettings ts;
+        ts.fromSettings(m_parameters.settingsPrefix, s);
+        m_tabPreferences->setSettings(ts);
         m_storageSettings.fromSettings(m_parameters.settingsPrefix, s);
         m_behaviorSettings.fromSettings(m_parameters.settingsPrefix, s);
         m_extraEncodingSettings.fromSettings(m_parameters.settingsPrefix, s);
@@ -79,6 +91,10 @@ BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters
   : TextEditorOptionsPage(parent),
     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->setId(idKey);
+    m_d->init();
 }
 
 BehaviorSettingsPage::~BehaviorSettingsPage()
@@ -101,6 +117,8 @@ QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
     QWidget *w = new QWidget(parent);
     m_d->m_page = new Ui::BehaviorSettingsPage;
     m_d->m_page->setupUi(w);
+    m_d->m_pageTabPreferences = new TabPreferences(QList<IFallbackPreferences *>(), w);
+    m_d->m_page->behaviorWidget->setTabPreferences(m_d->m_pageTabPreferences);
 
     settingsToUI();
 
@@ -125,12 +143,10 @@ void BehaviorSettingsPage::apply()
 
     QSettings *s = Core::ICore::instance()->settings();
 
-    if (newTabSettings != m_d->m_tabSettings) {
-        m_d->m_tabSettings = newTabSettings;
+    if (newTabSettings != m_d->m_tabPreferences->settings()) {
+        m_d->m_tabPreferences->setSettings(newTabSettings);
         if (s)
-            m_d->m_tabSettings.toSettings(m_d->m_parameters.settingsPrefix, s);
-
-        emit tabSettingsChanged(newTabSettings);
+            m_d->m_tabPreferences->settings().toSettings(m_d->m_parameters.settingsPrefix, s);
     }
 
     if (newStorageSettings != m_d->m_storageSettings) {
@@ -168,7 +184,7 @@ void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings,
                                           BehaviorSettings *behaviorSettings,
                                           ExtraEncodingSettings *extraEncodingSettings) const
 {
-    m_d->m_page->behaviorWidget->assignedTabSettings(tabSettings);
+    *tabSettings = m_d->m_pageTabPreferences->settings();
     m_d->m_page->behaviorWidget->assignedStorageSettings(storageSettings);
     m_d->m_page->behaviorWidget->assignedBehaviorSettings(behaviorSettings);
     m_d->m_page->behaviorWidget->assignedExtraEncodingSettings(extraEncodingSettings);
@@ -176,7 +192,7 @@ void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings,
 
 void BehaviorSettingsPage::settingsToUI()
 {
-    m_d->m_page->behaviorWidget->setAssignedTabSettings(m_d->m_tabSettings);
+    m_d->m_pageTabPreferences->setSettings(m_d->m_tabPreferences->settings());
     m_d->m_page->behaviorWidget->setAssignedStorageSettings(m_d->m_storageSettings);
     m_d->m_page->behaviorWidget->setAssignedBehaviorSettings(m_d->m_behaviorSettings);
     m_d->m_page->behaviorWidget->setAssignedExtraEncodingSettings(m_d->m_extraEncodingSettings);
@@ -192,11 +208,6 @@ void BehaviorSettingsPage::finish()
     m_d->m_page = 0;
 }
 
-const TabSettings &BehaviorSettingsPage::tabSettings() const
-{
-    return m_d->m_tabSettings;
-}
-
 const StorageSettings &BehaviorSettingsPage::storageSettings() const
 {
     return m_d->m_storageSettings;
@@ -212,6 +223,11 @@ const ExtraEncodingSettings &BehaviorSettingsPage::extraEncodingSettings() const
     return m_d->m_extraEncodingSettings;
 }
 
+TabPreferences *BehaviorSettingsPage::tabPreferences() const
+{
+    return m_d->m_tabPreferences;
+}
+
 bool BehaviorSettingsPage::matches(const QString &s) const
 {
     return m_d->m_searchKeywords.contains(s, Qt::CaseInsensitive);
diff --git a/src/plugins/texteditor/behaviorsettingspage.h b/src/plugins/texteditor/behaviorsettingspage.h
index bd4ff34b2ad..0f7467178be 100644
--- a/src/plugins/texteditor/behaviorsettingspage.h
+++ b/src/plugins/texteditor/behaviorsettingspage.h
@@ -44,6 +44,8 @@ class StorageSettings;
 class BehaviorSettings;
 class ExtraEncodingSettings;
 
+class TabPreferences;
+
 class BehaviorSettingsPageParameters
 {
 public:
@@ -69,13 +71,13 @@ public:
     void finish();
     bool matches(const QString &s) const;
 
-    const TabSettings &tabSettings() const;
     const StorageSettings &storageSettings() const;
     const BehaviorSettings &behaviorSettings() const;
     const ExtraEncodingSettings &extraEncodingSettings() const;
 
+    TabPreferences *tabPreferences() const;
+
 signals:
-    void tabSettingsChanged(const TextEditor::TabSettings &);
     void storageSettingsChanged(const TextEditor::StorageSettings &);
     void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
     void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
diff --git a/src/plugins/texteditor/behaviorsettingswidget.cpp b/src/plugins/texteditor/behaviorsettingswidget.cpp
index b9324f1b1df..5354eec3906 100644
--- a/src/plugins/texteditor/behaviorsettingswidget.cpp
+++ b/src/plugins/texteditor/behaviorsettingswidget.cpp
@@ -51,7 +51,7 @@ namespace TextEditor {
 
 struct BehaviorSettingsWidgetPrivate
 {
-    Ui::BehaviorSettingsWidget m_ui;
+    ::Ui::BehaviorSettingsWidget m_ui;
     QList<QTextCodec *> m_codecs;
 };
 
@@ -78,36 +78,22 @@ BehaviorSettingsWidget::BehaviorSettingsWidget(QWidget *parent)
         m_d->m_codecs.append(codec);
     }
 
-    connect(m_d->m_ui.insertSpaces, SIGNAL(clicked(bool)), this, SIGNAL(insertSpacesChanged(bool)));
-    connect(m_d->m_ui.autoInsertSpaces, SIGNAL(clicked(bool)),
-            this, SIGNAL(autoInsertSpacesChanged(bool)));
-    connect(m_d->m_ui.autoIndent, SIGNAL(clicked(bool)), this, SIGNAL(autoIndentChanged(bool)));
-    connect(m_d->m_ui.smartBackspace, SIGNAL(clicked(bool)),
-            this, SIGNAL(smartBackSpaceChanged(bool)));
-    connect(m_d->m_ui.tabSize, SIGNAL(valueChanged(int)), this, SIGNAL(tabSizeChanged(int)));
-    connect(m_d->m_ui.indentSize, SIGNAL(valueChanged(int)), this, SIGNAL(indentSizeChanged(int)));
-    connect(m_d->m_ui.indentBlocksBehavior, SIGNAL(currentIndexChanged(int)),
-            this, SIGNAL(indentBlocksBehaviorChanged(int)));
-    connect(m_d->m_ui.tabKeyBehavior, SIGNAL(currentIndexChanged(int)),
-            this, SIGNAL(tabKeyBehaviorChanged(int)));
-    connect(m_d->m_ui.continuationAlignBehavior, SIGNAL(currentIndexChanged(int)),
-            this, SIGNAL(continuationAlignBehaviorChanged(int)));
     connect(m_d->m_ui.cleanWhitespace, SIGNAL(clicked(bool)),
-            this, SIGNAL(cleanWhiteSpaceChanged(bool)));
+            this, SLOT(slotStorageSettingsChanged()));
     connect(m_d->m_ui.inEntireDocument, SIGNAL(clicked(bool)),
-            this, SIGNAL(inEntireDocumentChanged(bool)));
+            this, SLOT(slotStorageSettingsChanged()));
     connect(m_d->m_ui.addFinalNewLine, SIGNAL(clicked(bool)),
-            this, SIGNAL(addFinalNewLineChanged(bool)));
+            this, SLOT(slotStorageSettingsChanged()));
     connect(m_d->m_ui.cleanIndentation, SIGNAL(clicked(bool)),
-            this, SIGNAL(cleanIndentationChanged(bool)));
-    connect(m_d->m_ui.mouseNavigation, SIGNAL(clicked(bool)),
-            this, SIGNAL(mouseNavigationChanged(bool)));
+            this, SLOT(slotStorageSettingsChanged()));
+    connect(m_d->m_ui.mouseNavigation, SIGNAL(clicked()),
+            this, SLOT(slotBehaviorSettingsChanged()));
     connect(m_d->m_ui.scrollWheelZooming, SIGNAL(clicked(bool)),
-            this, SIGNAL(scrollWheelZoomingChanged(bool)));
+            this, SLOT(slotBehaviorSettingsChanged()));
     connect(m_d->m_ui.utf8BomBox, SIGNAL(currentIndexChanged(int)),
-            this, SIGNAL(utf8BomSettingsChanged(int)));
+            this, SLOT(slotExtraEncodingChanged()));
     connect(m_d->m_ui.encodingBox, SIGNAL(currentIndexChanged(int)),
-            this, SLOT(handleEncodingBoxChange(int)));
+            this, SLOT(slotEncodingBoxChanged(int)));
 }
 
 BehaviorSettingsWidget::~BehaviorSettingsWidget()
@@ -117,10 +103,10 @@ BehaviorSettingsWidget::~BehaviorSettingsWidget()
 
 void BehaviorSettingsWidget::setActive(bool active)
 {
+    m_d->m_ui.tabPreferencesWidget->setEnabled(active);
     m_d->m_ui.groupBoxEncodings->setEnabled(active);
     m_d->m_ui.groupBoxMouse->setEnabled(active);
     m_d->m_ui.groupBoxStorageSettings->setEnabled(active);
-    m_d->m_ui.groupBoxTabAndIndentSettings->setEnabled(active);
 }
 
 void BehaviorSettingsWidget::setAssignedCodec(QTextCodec *codec)
@@ -138,36 +124,9 @@ QTextCodec *BehaviorSettingsWidget::assignedCodec() const
     return m_d->m_codecs.at(m_d->m_ui.encodingBox->currentIndex());
 }
 
-void BehaviorSettingsWidget::setAssignedTabSettings(const TabSettings &tabSettings)
+void BehaviorSettingsWidget::setTabPreferences(TabPreferences *tabPreferences)
 {
-    m_d->m_ui.insertSpaces->setChecked(tabSettings.m_spacesForTabs);
-    m_d->m_ui.autoInsertSpaces->setChecked(tabSettings.m_autoSpacesForTabs);
-    m_d->m_ui.autoIndent->setChecked(tabSettings.m_autoIndent);
-    m_d->m_ui.smartBackspace->setChecked(tabSettings.m_smartBackspace);
-    m_d->m_ui.tabSize->setValue(tabSettings.m_tabSize);
-    m_d->m_ui.indentSize->setValue(tabSettings.m_indentSize);
-    m_d->m_ui.indentBlocksBehavior->setCurrentIndex(tabSettings.m_indentBraces ?
-                                                      (tabSettings.m_doubleIndentBlocks ? 2 : 1)
-                                                        : 0);
-    m_d->m_ui.tabKeyBehavior->setCurrentIndex(tabSettings.m_tabKeyBehavior);
-    m_d->m_ui.continuationAlignBehavior->setCurrentIndex(tabSettings.m_continuationAlignBehavior);
-}
-
-void BehaviorSettingsWidget::assignedTabSettings(TabSettings *tabSettings) const
-{
-    tabSettings->m_spacesForTabs = m_d->m_ui.insertSpaces->isChecked();
-    tabSettings->m_autoSpacesForTabs = m_d->m_ui.autoInsertSpaces->isChecked();
-    tabSettings->m_autoIndent = m_d->m_ui.autoIndent->isChecked();
-    tabSettings->m_smartBackspace = m_d->m_ui.smartBackspace->isChecked();
-    tabSettings->m_tabSize = m_d->m_ui.tabSize->value();
-    tabSettings->m_indentSize = m_d->m_ui.indentSize->value();
-    tabSettings->m_indentBraces = m_d->m_ui.indentBlocksBehavior->currentIndex() >= 1;
-    tabSettings->m_doubleIndentBlocks = m_d->m_ui.indentBlocksBehavior->currentIndex() >= 2;
-
-    tabSettings->m_tabKeyBehavior =
-        (TabSettings::TabKeyBehavior)m_d->m_ui.tabKeyBehavior->currentIndex();
-    tabSettings->m_continuationAlignBehavior =
-        (TabSettings::ContinuationAlignBehavior)m_d->m_ui.continuationAlignBehavior->currentIndex();
+    m_d->m_ui.tabPreferencesWidget->setTabPreferences(tabPreferences);
 }
 
 void BehaviorSettingsWidget::setAssignedStorageSettings(const StorageSettings &storageSettings)
@@ -216,13 +175,7 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
     static const QLatin1Char sep(' ');
     QString keywords;
     QTextStream(&keywords)
-        << m_d->m_ui.insertSpaces->text()
-        << sep << m_d->m_ui.autoInsertSpaces->text()
-        << sep << m_d->m_ui.autoIndent->text()
-        << sep << m_d->m_ui.smartBackspace->text()
-        << sep << m_d->m_ui.indentBlocksLabel->text()
-        << sep << m_d->m_ui.continuationAlignLabel->text()
-        << sep << m_d->m_ui.tabKeyIndentLabel->text()
+        << sep << m_d->m_ui.tabPreferencesWidget->searchKeywords()
         << sep << m_d->m_ui.cleanWhitespace->text()
         << sep << m_d->m_ui.inEntireDocument->text()
         << sep << m_d->m_ui.cleanIndentation->text()
@@ -231,7 +184,6 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
         << sep << m_d->m_ui.utf8BomLabel->text()
         << sep << m_d->m_ui.mouseNavigation->text()
         << sep << m_d->m_ui.scrollWheelZooming->text()
-        << sep << m_d->m_ui.groupBoxTabAndIndentSettings->title()
         << sep << m_d->m_ui.groupBoxStorageSettings->title()
         << sep << m_d->m_ui.groupBoxEncodings->title()
         << sep << m_d->m_ui.groupBoxMouse->title();
@@ -239,7 +191,33 @@ QString BehaviorSettingsWidget::collectUiKeywords() const
     return keywords;
 }
 
-void BehaviorSettingsWidget::handleEncodingBoxChange(int index)
+void BehaviorSettingsWidget::setFallbacksVisible(bool on)
+{
+    m_d->m_ui.tabPreferencesWidget->setFallbacksVisible(on);
+}
+
+void BehaviorSettingsWidget::slotStorageSettingsChanged()
+{
+    StorageSettings settings;
+    assignedStorageSettings(&settings);
+    emit storageSettingsChanged(settings);
+}
+
+void BehaviorSettingsWidget::slotBehaviorSettingsChanged()
+{
+    StorageSettings settings;
+    assignedStorageSettings(&settings);
+    emit storageSettingsChanged(settings);
+}
+
+void BehaviorSettingsWidget::slotExtraEncodingChanged()
+{
+    ExtraEncodingSettings settings;
+    assignedExtraEncodingSettings(&settings);
+    emit extraEncodingSettingsChanged(settings);
+}
+
+void BehaviorSettingsWidget::slotEncodingBoxChanged(int index)
 {
     emit textCodecChanged(m_d->m_codecs.at(index));
 }
diff --git a/src/plugins/texteditor/behaviorsettingswidget.h b/src/plugins/texteditor/behaviorsettingswidget.h
index c8c65d991bc..e2553551ae7 100644
--- a/src/plugins/texteditor/behaviorsettingswidget.h
+++ b/src/plugins/texteditor/behaviorsettingswidget.h
@@ -43,7 +43,7 @@ QT_END_NAMESPACE
 
 namespace TextEditor {
 
-class TabSettings;
+class TabPreferences;
 class StorageSettings;
 class BehaviorSettings;
 class ExtraEncodingSettings;
@@ -63,8 +63,7 @@ public:
     void setAssignedCodec(QTextCodec *codec);
     QTextCodec *assignedCodec() const;
 
-    void setAssignedTabSettings(const TabSettings &tabSettings);
-    void assignedTabSettings(TabSettings *tabSettings) const;
+    void setTabPreferences(TabPreferences *tabPreferences);
 
     void setAssignedStorageSettings(const StorageSettings &storageSettings);
     void assignedStorageSettings(StorageSettings *storageSettings) const;
@@ -77,31 +76,19 @@ public:
 
     QString collectUiKeywords() const;
 
-signals:
-    void insertSpacesChanged(bool spaces);
-    void autoInsertSpacesChanged(bool autoSpaces);
-    void autoIndentChanged(bool autoIndent);
-    void smartBackSpaceChanged(bool smartBackSpace);
-    void tabSizeChanged(int size);
-    void indentSizeChanged(int size);
-    void indentBlocksBehaviorChanged(int index);
-    void tabKeyBehaviorChanged(int index);
-    void continuationAlignBehaviorChanged(int index);
-
-    void cleanWhiteSpaceChanged(bool cleanWhiteSpace);
-    void inEntireDocumentChanged(bool entireDocument);
-    void addFinalNewLineChanged(bool newLine);
-    void cleanIndentationChanged(bool cleanIndentation);
-
-    void mouseNavigationChanged(bool mouseNavigation);
-    void scrollWheelZoomingChanged(bool scrollZooming);
-
-    void utf8BomSettingsChanged(int index);
+    void setFallbacksVisible(bool on);
 
+signals:
+    void storageSettingsChanged(const TextEditor::StorageSettings &settings);
+    void behaviorSettingsChanged(const TextEditor::BehaviorSettings &settings);
+    void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &settings);
     void textCodecChanged(QTextCodec *codec);
 
 private slots:
-    void handleEncodingBoxChange(int index);
+    void slotStorageSettingsChanged();
+    void slotBehaviorSettingsChanged();
+    void slotExtraEncodingChanged();
+    void slotEncodingBoxChanged(int index);
 
 private:
     BehaviorSettingsWidgetPrivate *m_d;
diff --git a/src/plugins/texteditor/behaviorsettingswidget.ui b/src/plugins/texteditor/behaviorsettingswidget.ui
index 3c1ee24b3a2..20641b50273 100644
--- a/src/plugins/texteditor/behaviorsettingswidget.ui
+++ b/src/plugins/texteditor/behaviorsettingswidget.ui
@@ -6,394 +6,92 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>762</width>
-    <height>463</height>
+    <width>518</width>
+    <height>410</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout_3">
    <property name="margin">
     <number>0</number>
    </property>
-   <item row="0" column="0" colspan="2">
-    <widget class="QGroupBox" name="groupBoxTabAndIndentSettings">
+   <item row="0" column="0" rowspan="3">
+    <widget class="TextEditor::TabPreferencesWidget" name="tabPreferencesWidget" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="1">
+    <widget class="QGroupBox" name="groupBoxStorageSettings">
+     <property name="toolTip">
+      <string>Cleanup actions which are automatically performed right before the file is saved to disk.</string>
+     </property>
      <property name="title">
-      <string>Tabs and Indentation</string>
+      <string>Cleanups Upon Saving</string>
      </property>
      <layout class="QGridLayout" name="gridLayout_2">
-      <item row="0" column="0">
-       <widget class="QCheckBox" name="insertSpaces">
-        <property name="text">
-         <string>Insert &amp;spaces instead of tabs</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1">
-       <widget class="QLabel" name="labelTabSize">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
+      <item row="0" column="0" colspan="2">
+       <widget class="QCheckBox" name="cleanWhitespace">
+        <property name="toolTip">
+         <string>Removes trailing whitespace upon saving.</string>
         </property>
         <property name="text">
-         <string>Ta&amp;b size:</string>
-        </property>
-        <property name="buddy">
-         <cstring>tabSize</cstring>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="2">
-       <widget class="QSpinBox" name="tabSize">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="minimum">
-         <number>1</number>
-        </property>
-        <property name="maximum">
-         <number>20</number>
+         <string>&amp;Clean whitespace</string>
         </property>
        </widget>
       </item>
-      <item row="0" column="3">
-       <spacer name="horizontalSpacer_3">
+      <item row="1" column="0">
+       <spacer name="horizontalSpacer_2">
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Fixed</enum>
+        </property>
         <property name="sizeHint" stdset="0">
          <size>
-          <width>0</width>
-          <height>22</height>
+          <width>30</width>
+          <height>20</height>
          </size>
         </property>
        </spacer>
       </item>
-      <item row="1" column="0">
-       <layout class="QHBoxLayout" name="horizontalLayout_3">
-        <item>
-         <spacer name="horizontalSpacer_5">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Fixed</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>30</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-        <item>
-         <widget class="QCheckBox" name="autoInsertSpaces">
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-          <property name="toolTip">
-           <string>Automatically determine based on the nearest indented line (previous line preferred over next line)</string>
-          </property>
-          <property name="text">
-           <string>Based on the surrounding lines</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
       <item row="1" column="1">
-       <widget class="QLabel" name="labelIndentSize">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
+       <widget class="QCheckBox" name="inEntireDocument">
+        <property name="enabled">
+         <bool>false</bool>
         </property>
-        <property name="text">
-         <string>&amp;Indent size:</string>
-        </property>
-        <property name="buddy">
-         <cstring>indentSize</cstring>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="2">
-       <widget class="QSpinBox" name="indentSize">
         <property name="sizePolicy">
-         <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+         <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
         </property>
-        <property name="minimum">
-         <number>1</number>
-        </property>
-        <property name="maximum">
-         <number>20</number>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="0">
-       <widget class="QCheckBox" name="autoIndent">
-        <property name="text">
-         <string>Enable automatic &amp;indentation</string>
-        </property>
-       </widget>
-      </item>
-      <item row="3" column="0">
-       <widget class="QCheckBox" name="smartBackspace">
         <property name="toolTip">
-         <string>Backspace will go back one indentation level instead of one space.</string>
+         <string>Clean whitespace in entire document instead of only for changed parts.</string>
         </property>
         <property name="text">
-         <string>&amp;Backspace follows indentation</string>
+         <string>In entire &amp;document</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="0">
-       <layout class="QGridLayout" name="gridLayout">
-        <item row="0" column="0">
-         <widget class="QLabel" name="indentBlocksLabel">
-          <property name="text">
-           <string>Block indentation style:</string>
-          </property>
-         </widget>
-        </item>
-        <item row="0" column="1">
-         <widget class="QComboBox" name="indentBlocksBehavior">
-          <property name="toolTip">
-           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
-Controls the indentation style of curly brace blocks.
-
-&lt;ul&gt;
-&lt;li&gt;Exclude Braces: The braces are not indented.
-&lt;pre&gt;
-void foo()
-{
-    if (a)
-    {
-        bar();
-    }
-}
-&lt;/pre&gt;
-&lt;/li&gt;
-
-&lt;li&gt;Include Braces: The braces are indented. The contents of the block are on the same level as the braces.
-&lt;pre&gt;
-void foo()
-    {
-    if (a)
-        {
-        bar();
-        }
-    }
-&lt;/pre&gt;
-&lt;/li&gt;
-
-&lt;li&gt;GNU Style: Indent the braces for blocks in statements. The contents are indented twice.
-&lt;pre&gt;
-void foo()
-{
-  if (a)
-    {
-      bar();
-    }
-}
-&lt;/pre&gt;
-&lt;/li&gt;
-&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
-          </property>
-          <item>
-           <property name="text">
-            <string>Exclude Braces</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>Include Braces</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>GNU Style</string>
-           </property>
-          </item>
-         </widget>
-        </item>
-        <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="2" column="1">
-         <widget class="QComboBox" name="tabKeyBehavior">
-          <item>
-           <property name="text">
-            <string>Never</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>Always</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>In Leading White Space</string>
-           </property>
-          </item>
-         </widget>
-        </item>
-        <item row="1" column="0">
-         <widget class="QLabel" name="continuationAlignLabel">
-          <property name="text">
-           <string>Align continuation lines:</string>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="1">
-         <widget class="QComboBox" name="continuationAlignBehavior">
-          <property name="toolTip">
-           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
-Influences the indentation of continuation lines.
-
-&lt;ul&gt;
-&lt;li&gt;Not At All: Do not align at all. Lines will only be indented to the current logical indentation depth.
-&lt;pre&gt;
-(tab)int i = foo(a, b
-(tab)c, d);
-&lt;/pre&gt;
-&lt;/li&gt;
-
-&lt;li&gt;With Spaces: Always use spaces for alignment, regardless of the other indentation settings.
-&lt;pre&gt;
-(tab)int i = foo(a, b
-(tab)            c, d);
-&lt;/pre&gt;
-&lt;/li&gt;
-
-&lt;li&gt;With Regular Indent: Use tabs and/or spaces for alignment, as configured above.
-&lt;pre&gt;
-(tab)int i = foo(a, b
-(tab)(tab)(tab)  c, d);
-&lt;/pre&gt;
-&lt;/li&gt;
-&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
-          </property>
-          <item>
-           <property name="text">
-            <string>Not At All</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>With Spaces</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>With Regular Indent</string>
-           </property>
-          </item>
-         </widget>
-        </item>
-       </layout>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <widget class="QGroupBox" name="groupBoxStorageSettings">
-     <property name="toolTip">
-      <string>Cleanup actions which are automatically performed right before the file is saved to disk.</string>
-     </property>
-     <property name="title">
-      <string>Cleanups Upon Saving</string>
-     </property>
-     <layout class="QVBoxLayout" name="verticalLayout_3">
-      <item>
-       <widget class="QCheckBox" name="cleanWhitespace">
+      <item row="2" column="1">
+       <widget class="QCheckBox" name="cleanIndentation">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
         <property name="toolTip">
-         <string>Removes trailing whitespace upon saving.</string>
+         <string>Correct leading whitespace according to tab settings.</string>
         </property>
         <property name="text">
-         <string>&amp;Clean whitespace</string>
+         <string>Clean indentation</string>
         </property>
        </widget>
       </item>
-      <item>
-       <layout class="QHBoxLayout" name="horizontalLayout_2">
-        <item>
-         <spacer name="horizontalSpacer_2">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Fixed</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>30</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-        <item>
-         <widget class="QCheckBox" name="inEntireDocument">
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-          <property name="toolTip">
-           <string>Clean whitespace in entire document instead of only for changed parts.</string>
-          </property>
-          <property name="text">
-           <string>In entire &amp;document</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-      <item>
-       <layout class="QHBoxLayout" name="cleanIndentationLayout">
-        <item>
-         <spacer name="cleanIndentationSpacer">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Fixed</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>30</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-        <item>
-         <widget class="QCheckBox" name="cleanIndentation">
-          <property name="enabled">
-           <bool>false</bool>
-          </property>
-          <property name="toolTip">
-           <string>Correct leading whitespace according to tab settings.</string>
-          </property>
-          <property name="text">
-           <string>Clean indentation</string>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-      <item>
+      <item row="3" column="0" colspan="2">
        <widget class="QCheckBox" name="addFinalNewLine">
         <property name="text">
          <string>&amp;Ensure newline at end of file</string>
@@ -408,7 +106,7 @@ Influences the indentation of continuation lines.
      <property name="title">
       <string>File Encodings</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout_4">
+     <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">
        <widget class="QLabel" name="encodingLabel">
         <property name="text">
@@ -417,37 +115,33 @@ Influences the indentation of continuation lines.
        </widget>
       </item>
       <item row="0" column="1">
-       <layout class="QHBoxLayout" name="horizontalLayout_6">
-        <item>
-         <widget class="QComboBox" name="encodingBox">
-          <property name="sizePolicy">
-           <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
-            <horstretch>0</horstretch>
-            <verstretch>0</verstretch>
-           </sizepolicy>
-          </property>
-          <property name="sizeAdjustPolicy">
-           <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
-          </property>
-          <property name="minimumContentsLength">
-           <number>20</number>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <spacer name="horizontalSpacer_6">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>285</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
-       </layout>
+       <widget class="QComboBox" name="encodingBox">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="sizeAdjustPolicy">
+         <enum>QComboBox::AdjustToMinimumContentsLengthWithIcon</enum>
+        </property>
+        <property name="minimumContentsLength">
+         <number>20</number>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2">
+       <spacer name="horizontalSpacer_6">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>285</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
       </item>
       <item row="1" column="0">
        <widget class="QLabel" name="utf8BomLabel">
@@ -457,67 +151,37 @@ Influences the indentation of continuation lines.
        </widget>
       </item>
       <item row="1" column="1">
-       <layout class="QHBoxLayout" name="horizontalLayout_4">
-        <item>
-         <widget class="QComboBox" name="utf8BomBox">
-          <property name="toolTip">
-           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
+       <widget class="QComboBox" name="utf8BomBox">
+        <property name="toolTip">
+         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
 &lt;p&gt;How text editors should deal with UTF-8 Byte Order Marks. The options are:&lt;/p&gt;
 &lt;ul &gt;&lt;li&gt;&lt;i&gt;Add If Encoding Is UTF-8:&lt;/i&gt; always add a BOM when saving a file in UTF-8 encoding. Note that this will not work if the encoding is &lt;i&gt;System&lt;/i&gt;, as Qt Creator does not know what it actually is.&lt;/li&gt;
 &lt;li&gt;&lt;i&gt;Keep If Already Present: &lt;/i&gt;save the file with a BOM if it already had one when it was loaded.&lt;/li&gt;
 &lt;li&gt;&lt;i&gt;Always Delete:&lt;/i&gt; never write an UTF-8 BOM, possibly deleting a pre-existing one.&lt;/li&gt;&lt;/ul&gt;
 &lt;p&gt;Note that UTF-8 BOMs are uncommon and treated incorrectly by some editors, so it usually makes little sense to add any.&lt;/p&gt;
 &lt;p&gt;This setting does &lt;b&gt;not&lt;/b&gt; influence the use of UTF-16 and UTF-32 BOMs.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
-          </property>
-          <item>
-           <property name="text">
-            <string>Add If Encoding Is UTF-8</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>Keep If Already Present</string>
-           </property>
-          </item>
-          <item>
-           <property name="text">
-            <string>Always Delete</string>
-           </property>
-          </item>
-         </widget>
+        </property>
+        <item>
+         <property name="text">
+          <string>Add If Encoding Is UTF-8</string>
+         </property>
         </item>
         <item>
-         <spacer name="horizontalSpacer_4">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>40</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
+         <property name="text">
+          <string>Keep If Already Present</string>
+         </property>
         </item>
-       </layout>
-      </item>
-      <item row="2" column="0" colspan="2">
-       <spacer name="verticalSpacer_2">
-        <property name="orientation">
-         <enum>Qt::Vertical</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>20</width>
-          <height>40</height>
-         </size>
-        </property>
-       </spacer>
+        <item>
+         <property name="text">
+          <string>Always Delete</string>
+         </property>
+        </item>
+       </widget>
       </item>
      </layout>
     </widget>
    </item>
-   <item row="2" column="0" colspan="2">
+   <item row="2" column="1">
     <widget class="QGroupBox" name="groupBoxMouse">
      <property name="title">
       <string>Mouse</string>
@@ -537,17 +201,46 @@ Influences the indentation of continuation lines.
         </property>
        </widget>
       </item>
+      <item>
+       <spacer name="verticalSpacer_2">
+        <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>
    </item>
+   <item row="3" column="1">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>3</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
   </layout>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>TextEditor::TabPreferencesWidget</class>
+   <extends>QWidget</extends>
+   <header location="global">texteditor/tabpreferenceswidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
  <tabstops>
-  <tabstop>insertSpaces</tabstop>
-  <tabstop>tabSize</tabstop>
-  <tabstop>autoIndent</tabstop>
-  <tabstop>smartBackspace</tabstop>
-  <tabstop>tabKeyBehavior</tabstop>
   <tabstop>cleanWhitespace</tabstop>
   <tabstop>inEntireDocument</tabstop>
   <tabstop>cleanIndentation</tabstop>
@@ -587,21 +280,5 @@ Influences the indentation of continuation lines.
     </hint>
    </hints>
   </connection>
-  <connection>
-   <sender>insertSpaces</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>autoInsertSpaces</receiver>
-   <slot>setEnabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>105</x>
-     <y>49</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>105</x>
-     <y>78</y>
-    </hint>
-   </hints>
-  </connection>
  </connections>
 </ui>
diff --git a/src/plugins/texteditor/codestylepreferencesmanager.cpp b/src/plugins/texteditor/codestylepreferencesmanager.cpp
new file mode 100644
index 00000000000..f3e31995905
--- /dev/null
+++ b/src/plugins/texteditor/codestylepreferencesmanager.cpp
@@ -0,0 +1,54 @@
+#include "codestylepreferencesmanager.h"
+#include "icodestylepreferencesfactory.h"
+
+using namespace TextEditor;
+
+CodeStylePreferencesManager *CodeStylePreferencesManager::m_instance = 0;
+
+namespace TextEditor {
+namespace Internal {
+
+class CodeStylePreferencesManagerPrivate
+{
+public:
+    QMap<QString, ICodeStylePreferencesFactory *> m_idToFactory;
+    QList<ICodeStylePreferencesFactory *> m_factories;
+};
+
+} // namespace Internal
+} // namespace TextEditor
+
+CodeStylePreferencesManager::CodeStylePreferencesManager()
+    : QObject(),
+      d(new Internal::CodeStylePreferencesManagerPrivate())
+{
+}
+
+CodeStylePreferencesManager::~CodeStylePreferencesManager()
+{
+    delete d;
+}
+
+CodeStylePreferencesManager *CodeStylePreferencesManager::instance()
+{
+    if (!m_instance)
+        m_instance = new CodeStylePreferencesManager();
+    return m_instance;
+}
+
+void CodeStylePreferencesManager::registerFactory(ICodeStylePreferencesFactory *settings)
+{
+    d->m_idToFactory.insert(settings->languageId(), settings);
+    d->m_factories = d->m_idToFactory.values();
+}
+
+QList<ICodeStylePreferencesFactory *> CodeStylePreferencesManager::factories() const
+{
+    return d->m_factories;
+}
+
+ICodeStylePreferencesFactory *CodeStylePreferencesManager::factory(const QString &languageId) const
+{
+    return d->m_idToFactory.value(languageId);
+}
+
diff --git a/src/plugins/texteditor/codestylepreferencesmanager.h b/src/plugins/texteditor/codestylepreferencesmanager.h
new file mode 100644
index 00000000000..1b26228d0b4
--- /dev/null
+++ b/src/plugins/texteditor/codestylepreferencesmanager.h
@@ -0,0 +1,36 @@
+#ifndef CODESTYLEPREFERENCESMANAGER_H
+#define CODESTYLEPREFERENCESMANAGER_H
+
+#include "texteditor_global.h"
+
+#include <QtCore/QObject>
+#include <QtCore/QVariant>
+
+namespace TextEditor {
+
+namespace Internal {
+class CodeStylePreferencesManagerPrivate;
+}
+
+class ICodeStylePreferencesFactory;
+
+class TEXTEDITOR_EXPORT CodeStylePreferencesManager : public QObject
+{
+    Q_OBJECT
+public:
+    static CodeStylePreferencesManager *instance();
+
+    void registerFactory(ICodeStylePreferencesFactory *settings);
+    QList<ICodeStylePreferencesFactory *> factories() const;
+    ICodeStylePreferencesFactory *factory(const QString &languageId) const;
+
+private:
+    CodeStylePreferencesManager();
+    ~CodeStylePreferencesManager();
+    Internal::CodeStylePreferencesManagerPrivate *d;
+    static CodeStylePreferencesManager *m_instance;
+};
+
+} // namespace TextEditor
+
+#endif // CODESTYLEPREFERENCESMANAGER_H
diff --git a/src/plugins/texteditor/fallbackselectorwidget.cpp b/src/plugins/texteditor/fallbackselectorwidget.cpp
new file mode 100644
index 00000000000..a690c2caeb8
--- /dev/null
+++ b/src/plugins/texteditor/fallbackselectorwidget.cpp
@@ -0,0 +1,125 @@
+#include "fallbackselectorwidget.h"
+#include "ifallbackpreferences.h"
+
+#include <QtGui/QComboBox>
+#include <QtGui/QBoxLayout>
+#include <QtGui/QLabel>
+#include <QtGui/QCheckBox>
+#include <QtCore/QTextStream>
+
+using namespace TextEditor;
+
+Q_DECLARE_METATYPE(TextEditor::IFallbackPreferences *)
+
+FallbackSelectorWidget::FallbackSelectorWidget(QWidget *parent) :
+    QWidget(parent),
+    m_fallbackPreferences(0),
+    m_layout(0),
+    m_checkBox(0),
+    m_comboBox(0),
+    m_comboBoxLabel(0),
+    m_fallbackWidgetVisible(true)
+{
+    hide();
+}
+
+void FallbackSelectorWidget::setFallbackPreferences(TextEditor::IFallbackPreferences *fallbackPreferences)
+{
+    if (m_fallbackPreferences == fallbackPreferences)
+        return; // nothing changes
+
+    // cleanup old
+    if (m_fallbackPreferences) {
+        disconnect(m_fallbackPreferences, SIGNAL(currentFallbackChanged(IFallbackPreferences*)),
+                this, SLOT(slotCurrentFallbackChanged(IFallbackPreferences*)));
+        hide();
+
+        if (m_layout)
+            delete m_layout;
+    }
+    m_fallbackPreferences = fallbackPreferences;
+    // fillup new
+    if (m_fallbackPreferences) {
+        const QList<IFallbackPreferences *> fallbacks = m_fallbackPreferences->fallbacks();
+        setVisible(m_fallbackWidgetVisible && !fallbacks.isEmpty());
+
+        m_layout = new QHBoxLayout(this);
+        m_layout->setContentsMargins(QMargins());
+
+        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)));
+        } 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));
+            }
+        }
+        slotCurrentFallbackChanged(m_fallbackPreferences->currentFallback());
+
+        connect(m_fallbackPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
+                this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
+    }
+}
+
+void FallbackSelectorWidget::slotComboBoxActivated(int index)
+{
+    if (!m_comboBox || index < 0 || index >= m_comboBox->count())
+        return;
+    TextEditor::IFallbackPreferences *fallback =
+            m_comboBox->itemData(index).value<TextEditor::IFallbackPreferences *>();
+
+    const bool wasBlocked = blockSignals(true);
+    m_fallbackPreferences->setCurrentFallback(fallback);
+    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);
+    blockSignals(wasBlocked);
+}
+
+void FallbackSelectorWidget::setFallbacksVisible(bool on)
+{
+    m_fallbackWidgetVisible = on;
+    if (m_fallbackPreferences)
+        setVisible(m_fallbackWidgetVisible && !m_fallbackPreferences->fallbacks().isEmpty());
+}
+
+QString FallbackSelectorWidget::searchKeywords() const
+{
+    // no useful keywords here
+    return QString();
+}
diff --git a/src/plugins/texteditor/fallbackselectorwidget.h b/src/plugins/texteditor/fallbackselectorwidget.h
new file mode 100644
index 00000000000..60cea0d89b8
--- /dev/null
+++ b/src/plugins/texteditor/fallbackselectorwidget.h
@@ -0,0 +1,55 @@
+#ifndef FALLBACKSELECTORWIDGET_H
+#define FALLBACKSELECTORWIDGET_H
+
+#include "texteditor_global.h"
+
+#include <QtGui/QWidget>
+#include <QtCore/QMap>
+
+QT_BEGIN_NAMESPACE
+class QHBoxLayout;
+class QComboBox;
+class QLabel;
+class QCheckBox;
+QT_END_NAMESPACE
+
+namespace TextEditor {
+
+class IFallbackPreferences;
+
+class TEXTEDITOR_EXPORT FallbackSelectorWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit FallbackSelectorWidget(QWidget *parent = 0);
+
+    void setFallbackPreferences(TextEditor::IFallbackPreferences *tabPreferences);
+    QString searchKeywords() const;
+
+    void setFallbacksVisible(bool on);
+
+signals:
+
+private slots:
+    void slotComboBoxActivated(int index);
+    void slotCheckBoxClicked(bool checked);
+    void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *);
+
+private:
+    IFallbackPreferences *m_fallbackPreferences;
+
+    QHBoxLayout *m_layout;
+
+    QCheckBox *m_checkBox;
+    QComboBox *m_comboBox;
+    QLabel *m_comboBoxLabel;
+
+    bool m_fallbackWidgetVisible;
+    QMap<IFallbackPreferences *, int> m_fallbackToIndex;
+    QMap<int, IFallbackPreferences *> m_indexToFallback;
+
+};
+
+} // namespace TextEditor
+
+#endif // FALLBACKSELECTORWIDGET_H
diff --git a/src/plugins/texteditor/icodestylepreferencesfactory.cpp b/src/plugins/texteditor/icodestylepreferencesfactory.cpp
new file mode 100644
index 00000000000..888bd013362
--- /dev/null
+++ b/src/plugins/texteditor/icodestylepreferencesfactory.cpp
@@ -0,0 +1,9 @@
+#include "icodestylepreferencesfactory.h"
+
+using namespace TextEditor;
+
+ICodeStylePreferencesFactory::ICodeStylePreferencesFactory(QObject *parent) :
+    QObject(parent)
+{
+}
+
diff --git a/src/plugins/texteditor/icodestylepreferencesfactory.h b/src/plugins/texteditor/icodestylepreferencesfactory.h
new file mode 100644
index 00000000000..d0c49d884eb
--- /dev/null
+++ b/src/plugins/texteditor/icodestylepreferencesfactory.h
@@ -0,0 +1,27 @@
+#ifndef ICODESTYLEPREFERENCESFACTORY_H
+#define ICODESTYLEPREFERENCESFACTORY_H
+
+#include "texteditor_global.h"
+
+#include <QtCore/QObject>
+
+namespace TextEditor {
+
+class IFallbackPreferences;
+class TabPreferences;
+
+class TEXTEDITOR_EXPORT ICodeStylePreferencesFactory : public QObject
+{
+    Q_OBJECT
+public:
+    explicit ICodeStylePreferencesFactory(QObject *parent = 0);
+
+    virtual QString languageId() = 0;
+    virtual QString displayName() = 0;
+    virtual IFallbackPreferences *createPreferences(const QList<IFallbackPreferences *> &fallbacks) const = 0;
+    virtual QWidget *createEditor(IFallbackPreferences *preferences, TabPreferences *tabSettings, QWidget *parent) const = 0;
+};
+
+} // namespace TextEditor
+
+#endif // ICODESTYLEPREFERENCESFACTORY_H
diff --git a/src/plugins/texteditor/ifallbackpreferences.cpp b/src/plugins/texteditor/ifallbackpreferences.cpp
new file mode 100644
index 00000000000..d583d2d169f
--- /dev/null
+++ b/src/plugins/texteditor/ifallbackpreferences.cpp
@@ -0,0 +1,135 @@
+#include "ifallbackpreferences.h"
+
+#include <utils/settingsutils.h>
+
+#include <QtCore/QSettings>
+#include <QtCore/QStringList>
+
+using namespace TextEditor;
+
+namespace TextEditor {
+namespace Internal {
+
+class IFallbackPreferencesPrivate
+{
+public:
+    IFallbackPreferencesPrivate()
+        : m_currentFallback(0)
+    {}
+
+    QList<IFallbackPreferences *> m_fallbacks;
+    QMap<QString, IFallbackPreferences *> m_idToFallback;
+    IFallbackPreferences *m_currentFallback;
+    QString m_id;
+    QString m_displayName;
+};
+
+}
+}
+
+IFallbackPreferences::IFallbackPreferences(
+    const QList<IFallbackPreferences *> &fallbacks,
+    QObject *parent) :
+    QObject(parent),
+    d(new Internal::IFallbackPreferencesPrivate)
+{
+    d->m_fallbacks = fallbacks;
+    for (int i = 0; i < fallbacks.count(); i++) {
+        IFallbackPreferences *fallback = fallbacks.at(i);
+        d->m_idToFallback.insert(fallback->id(), fallback);
+    }
+}
+
+IFallbackPreferences::~IFallbackPreferences()
+{
+    delete d;
+}
+
+QString IFallbackPreferences::id() const
+{
+    return d->m_id;
+}
+
+void IFallbackPreferences::setId(const QString &name)
+{
+    d->m_id = name;
+}
+
+QString IFallbackPreferences::displayName() const
+{
+    return d->m_displayName;
+}
+
+void IFallbackPreferences::setDisplayName(const QString &name)
+{
+    d->m_displayName = name;
+}
+
+QVariant IFallbackPreferences::currentValue() const
+{
+    return currentPreferences()->value();
+}
+
+IFallbackPreferences *IFallbackPreferences::currentPreferences() const
+{
+    IFallbackPreferences *prefs = (IFallbackPreferences *)this;
+    while (prefs->currentFallback())
+        prefs = prefs->currentFallback();
+    return prefs;
+}
+
+QList<IFallbackPreferences *> IFallbackPreferences::fallbacks() const
+{
+    return d->m_fallbacks;
+}
+
+IFallbackPreferences *IFallbackPreferences::currentFallback() const
+{
+    return d->m_currentFallback;
+}
+
+void IFallbackPreferences::setCurrentFallback(IFallbackPreferences *fallback)
+{
+    if (fallback && !d->m_fallbacks.contains(fallback)) {
+        // warning
+        return;
+    }
+    if (d->m_currentFallback == fallback)
+        return; // nothing changes
+
+    if (d->m_currentFallback) {
+        disconnect(d->m_currentFallback, SIGNAL(currentValueChanged(QVariant)),
+                   this, SIGNAL(currentValueChanged(QVariant)));
+    }
+    d->m_currentFallback = fallback;
+    if (d->m_currentFallback) {
+        connect(d->m_currentFallback, SIGNAL(currentValueChanged(QVariant)),
+                this, SIGNAL(currentValueChanged(QVariant)));
+    }
+    emit currentFallbackChanged(d->m_currentFallback);
+    emit currentValueChanged(currentValue());
+}
+
+QString IFallbackPreferences::currentFallbackId() const
+{
+    if (currentFallback())
+        return currentFallback()->id();
+    return id(); // or 0?
+}
+
+void IFallbackPreferences::setCurrentFallback(const QString &id)
+{
+    setCurrentFallback(d->m_idToFallback.value(id));
+}
+
+void IFallbackPreferences::toSettings(const QString &category, QSettings *s) const
+{
+    Utils::toSettings(settingsSuffix(), category, s, this);
+}
+
+void IFallbackPreferences::fromSettings(const QString &category, const QSettings *s)
+{
+    Utils::fromSettings(settingsSuffix(), category, s, this);
+}
+
+
diff --git a/src/plugins/texteditor/ifallbackpreferences.h b/src/plugins/texteditor/ifallbackpreferences.h
new file mode 100644
index 00000000000..157e6742ea5
--- /dev/null
+++ b/src/plugins/texteditor/ifallbackpreferences.h
@@ -0,0 +1,69 @@
+#ifndef IFALLBACKPREFERENCES_H
+#define IFALLBACKPREFERENCES_H
+
+#include "texteditor_global.h"
+
+#include <QtCore/QObject>
+#include <QtCore/QVariant>
+
+QT_BEGIN_NAMESPACE
+class QSettings;
+QT_END_NAMESPACE
+
+namespace TextEditor {
+
+namespace Internal {
+class IFallbackPreferencesPrivate;
+}
+
+class TabSettings;
+
+class TEXTEDITOR_EXPORT IFallbackPreferences : public QObject
+{
+    Q_OBJECT
+public:
+    explicit IFallbackPreferences(const QList<IFallbackPreferences *> &fallbacks, QObject *parentObject = 0);
+    virtual ~IFallbackPreferences();
+
+    QString id() const;
+    void setId(const QString &name);
+
+    QString displayName() const;
+    void setDisplayName(const QString &name);
+
+    virtual QVariant value() const = 0;
+    virtual void setValue(const QVariant &) = 0;
+
+    QVariant currentValue() const; // may be from grandparent
+
+    IFallbackPreferences *currentPreferences() const; // may be grandparent
+
+    QList<IFallbackPreferences *> fallbacks() const;
+    IFallbackPreferences *currentFallback() const; // null or one of the above list
+    void setCurrentFallback(IFallbackPreferences *fallback);
+
+    QString currentFallbackId() const;
+    void setCurrentFallback(const QString &id);
+
+    void toSettings(const QString &category, QSettings *s) const;
+    void fromSettings(const QString &category, const QSettings *s);
+
+    // make below 2 protected?
+    virtual void toMap(const QString &prefix, QVariantMap *map) const = 0;
+    virtual void fromMap(const QString &prefix, const QVariantMap &map) = 0;
+
+signals:
+    void valueChanged(const QVariant &);
+    void currentValueChanged(const QVariant &);
+    void currentFallbackChanged(TextEditor::IFallbackPreferences *currentFallback);
+
+protected:
+    virtual QString settingsSuffix() const = 0;
+
+private:
+    Internal::IFallbackPreferencesPrivate *d;
+};
+
+} // namespace TextEditor
+
+#endif // IFALLBACKPREFERENCES_H
diff --git a/src/plugins/texteditor/indenter.cpp b/src/plugins/texteditor/indenter.cpp
index e1541fd930f..02e24e390eb 100644
--- a/src/plugins/texteditor/indenter.cpp
+++ b/src/plugins/texteditor/indenter.cpp
@@ -106,3 +106,8 @@ void Indenter::reindent(QTextDocument *doc, const QTextCursor &cursor, BaseTextE
         indentBlock(doc, cursor.block(), QChar::Null, editor);
     }
 }
+
+void Indenter::setCodeStylePreferences(IFallbackPreferences *)
+{
+
+}
diff --git a/src/plugins/texteditor/indenter.h b/src/plugins/texteditor/indenter.h
index b0dcd9ba968..2f32c78e77f 100644
--- a/src/plugins/texteditor/indenter.h
+++ b/src/plugins/texteditor/indenter.h
@@ -47,6 +47,7 @@ QT_END_NAMESPACE
 namespace TextEditor {
 
 class BaseTextEditorWidget;
+class IFallbackPreferences;
 
 class TEXTEDITOR_EXPORT Indenter
 {
@@ -72,6 +73,8 @@ public:
     // Reindent at cursor. Selection will be adjusted according to the indentation
     // change of the first block.
     virtual void reindent(QTextDocument *doc, const QTextCursor &cursor, BaseTextEditorWidget *editor);
+
+    virtual void setCodeStylePreferences(IFallbackPreferences *preferences);
 };
 
 } // namespace TextEditor
diff --git a/src/plugins/texteditor/tabpreferences.cpp b/src/plugins/texteditor/tabpreferences.cpp
new file mode 100644
index 00000000000..a471830e4e0
--- /dev/null
+++ b/src/plugins/texteditor/tabpreferences.cpp
@@ -0,0 +1,88 @@
+#include "tabpreferences.h"
+#include "tabsettings.h"
+
+using namespace TextEditor;
+
+static const char *settingsSuffixKey = "TabPreferences";
+
+static const char *currentFallbackKey = "CurrentFallback";
+
+TabPreferences::TabPreferences(
+    const QList<IFallbackPreferences *> &fallbacks, QObject *parent)
+    : IFallbackPreferences(fallbacks, parent)
+{
+    connect(this, SIGNAL(currentValueChanged(QVariant)),
+            this, SLOT(slotCurrentValueChanged(QVariant)));
+}
+
+QVariant TabPreferences::value() const
+{
+    QVariant v;
+    v.setValue(settings());
+    return v;
+}
+
+void TabPreferences::setValue(const QVariant &value)
+{
+    if (!value.canConvert<TabSettings>())
+        return;
+
+    setSettings(value.value<TabSettings>());
+}
+
+TabSettings TabPreferences::settings() const
+{
+    return m_data;
+}
+
+void TabPreferences::setSettings(const TextEditor::TabSettings &data)
+{
+    if (m_data == data)
+        return;
+
+    m_data = data;
+
+    QVariant v;
+    v.setValue(data);
+    emit valueChanged(v);
+    emit settingsChanged(m_data);
+    if (!currentFallback()) {
+        emit currentValueChanged(v);
+    }
+}
+
+TabSettings TabPreferences::currentSettings() const
+{
+    QVariant v = currentValue();
+    if (!v.canConvert<TabSettings>()) {
+        // warning
+        return TabSettings();
+    }
+    return v.value<TabSettings>();
+}
+
+void TabPreferences::slotCurrentValueChanged(const QVariant &value)
+{
+    if (!value.canConvert<TabSettings>())
+        return;
+
+    emit currentSettingsChanged(value.value<TabSettings>());
+}
+
+QString TabPreferences::settingsSuffix() const
+{
+    return settingsSuffixKey;
+}
+
+void TabPreferences::toMap(const QString &prefix, QVariantMap *map) const
+{
+    m_data.toMap(prefix, map);
+    map->insert(prefix + QLatin1String(currentFallbackKey), currentFallbackId());
+}
+
+void TabPreferences::fromMap(const QString &prefix, const QVariantMap &map)
+{
+    m_data.fromMap(prefix, map);
+    setCurrentFallback(map.value(prefix + QLatin1String(currentFallbackKey), QLatin1String("Global")).toString());
+}
+
diff --git a/src/plugins/texteditor/tabpreferences.h b/src/plugins/texteditor/tabpreferences.h
new file mode 100644
index 00000000000..42b63e2cbfa
--- /dev/null
+++ b/src/plugins/texteditor/tabpreferences.h
@@ -0,0 +1,47 @@
+#ifndef TABPREFERENCES_H
+#define TABPREFERENCES_H
+
+#include "ifallbackpreferences.h"
+#include "tabsettings.h"
+
+namespace TextEditor {
+
+class TEXTEDITOR_EXPORT TabPreferences : public IFallbackPreferences
+{
+    Q_OBJECT
+public:
+    explicit TabPreferences(
+        const QList<IFallbackPreferences *> &fallbacks,
+        QObject *parentObject = 0);
+
+    virtual QVariant value() const;
+    virtual void setValue(const QVariant &);
+
+    TabSettings settings() const;
+
+    // tracks parent hierarchy until currentParentSettings is null
+    TabSettings currentSettings() const;
+
+    virtual void toMap(const QString &prefix, QVariantMap *map) const;
+    virtual void fromMap(const QString &prefix, const QVariantMap &map);
+
+public slots:
+    void setSettings(const TextEditor::TabSettings &tabSettings);
+
+signals:
+    void settingsChanged(const TextEditor::TabSettings &);
+    void currentSettingsChanged(const TextEditor::TabSettings &);
+
+protected:
+    virtual QString settingsSuffix() const;
+
+private slots:
+    void slotCurrentValueChanged(const QVariant &);
+
+private:
+    TabSettings m_data;
+};
+
+} // namespace TextEditor
+
+#endif // TABPREFERENCES_H
diff --git a/src/plugins/texteditor/tabpreferenceswidget.cpp b/src/plugins/texteditor/tabpreferenceswidget.cpp
new file mode 100644
index 00000000000..c98bdbc9ff7
--- /dev/null
+++ b/src/plugins/texteditor/tabpreferenceswidget.cpp
@@ -0,0 +1,93 @@
+#include "tabpreferenceswidget.h"
+#include "ui_tabpreferenceswidget.h"
+#include "tabpreferences.h"
+
+#include <QtCore/QTextStream>
+
+namespace TextEditor {
+
+TabPreferencesWidget::TabPreferencesWidget(QWidget *parent) :
+    QWidget(parent),
+    m_ui(new Ui::TabPreferencesWidget),
+    m_tabPreferences(0)
+{
+    m_ui->setupUi(this);
+}
+
+TabPreferencesWidget::~TabPreferencesWidget()
+{
+    delete m_ui;
+}
+
+void TabPreferencesWidget::setTabPreferences(TabPreferences *tabPreferences)
+{
+    if (m_tabPreferences == tabPreferences)
+        return; // nothing changes
+
+    // cleanup old
+    if (m_tabPreferences) {
+        disconnect(m_tabPreferences, SIGNAL(settingsChanged(TabSettings)),
+                m_ui->tabSettingsWidget, SLOT(setSettings(TabSettings)));
+        disconnect(m_tabPreferences, SIGNAL(currentFallbackChanged(IFallbackPreferences*)),
+                this, SLOT(slotCurrentFallbackChanged(IFallbackPreferences*)));
+        disconnect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TabSettings)),
+                m_tabPreferences, SLOT(setSettings(TabSettings)));
+        m_ui->tabSettingsWidget->setEnabled(true);
+    }
+    m_tabPreferences = tabPreferences;
+    m_ui->fallbackWidget->setFallbackPreferences(tabPreferences);
+    // fillup new
+    if (m_tabPreferences) {
+        slotCurrentFallbackChanged(m_tabPreferences->currentFallback());
+
+        connect(m_tabPreferences, SIGNAL(settingsChanged(TextEditor::TabSettings)),
+                m_ui->tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings)));
+        connect(m_tabPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
+                this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
+        connect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
+                m_tabPreferences, SLOT(setSettings(TextEditor::TabSettings)));
+
+        m_ui->tabSettingsWidget->setSettings(m_tabPreferences->settings());
+    }
+}
+
+void TabPreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback)
+{
+    m_ui->tabSettingsWidget->setEnabled(!fallback);
+}
+
+QString TabPreferencesWidget::searchKeywords() const
+{
+    QString rc;
+    QLatin1Char sep(' ');
+    QTextStream(&rc)
+            << sep << m_ui->fallbackWidget->searchKeywords()
+            << sep << m_ui->tabSettingsWidget->searchKeywords()
+               ;
+    rc.remove(QLatin1Char('&'));
+    return rc;
+}
+
+void TabPreferencesWidget::setFallbacksVisible(bool on)
+{
+    m_ui->fallbackWidget->setFallbacksVisible(on);
+}
+
+void TabPreferencesWidget::setFlat(bool on)
+{
+     m_ui->tabSettingsWidget->setFlat(on);
+}
+
+void TabPreferencesWidget::changeEvent(QEvent *e)
+{
+    QWidget::changeEvent(e);
+    switch (e->type()) {
+    case QEvent::LanguageChange:
+        m_ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+} // namespace TextEditor
diff --git a/src/plugins/texteditor/tabpreferenceswidget.h b/src/plugins/texteditor/tabpreferenceswidget.h
new file mode 100644
index 00000000000..0c96ba878ff
--- /dev/null
+++ b/src/plugins/texteditor/tabpreferenceswidget.h
@@ -0,0 +1,46 @@
+#ifndef TABPREFERENCESWIDGET_H
+#define TABPREFERENCESWIDGET_H
+
+#include "texteditor_global.h"
+
+#include <QtGui/QWidget>
+#include <QtCore/QMap>
+
+
+namespace TextEditor {
+
+class TabPreferences;
+class IFallbackPreferences;
+
+namespace Ui {
+    class TabPreferencesWidget;
+}
+
+class TEXTEDITOR_EXPORT TabPreferencesWidget : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit TabPreferencesWidget(QWidget *parent = 0);
+    ~TabPreferencesWidget();
+
+    void setTabPreferences(TabPreferences *tabPreferences);
+    QString searchKeywords() const;
+
+    void setFallbacksVisible(bool on);
+    void setFlat(bool on);
+
+protected:
+    void changeEvent(QEvent *e);
+
+private slots:
+    void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback);
+
+private:
+    Ui::TabPreferencesWidget *m_ui;
+    TabPreferences *m_tabPreferences;
+};
+
+
+} // namespace TextEditor
+#endif // TABPREFERENCESWIDGET_H
diff --git a/src/plugins/texteditor/tabpreferenceswidget.ui b/src/plugins/texteditor/tabpreferenceswidget.ui
new file mode 100644
index 00000000000..e982b65ace9
--- /dev/null
+++ b/src/plugins/texteditor/tabpreferenceswidget.ui
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TextEditor::TabPreferencesWidget</class>
+ <widget class="QWidget" name="TextEditor::TabPreferencesWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>122</width>
+    <height>97</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="margin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="TextEditor::FallbackSelectorWidget" name="fallbackWidget" native="true"/>
+   </item>
+   <item>
+    <widget class="TextEditor::TabSettingsWidget" name="tabSettingsWidget" native="true"/>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>TextEditor::TabSettingsWidget</class>
+   <extends>QWidget</extends>
+   <header location="global">texteditor/tabsettingswidget.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
+   <class>TextEditor::FallbackSelectorWidget</class>
+   <extends>QWidget</extends>
+   <header location="global">texteditor/fallbackselectorwidget.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/texteditor/tabsettings.cpp b/src/plugins/texteditor/tabsettings.cpp
index 2cad99c6302..3f9ecd220cf 100644
--- a/src/plugins/texteditor/tabsettings.cpp
+++ b/src/plugins/texteditor/tabsettings.cpp
@@ -338,8 +338,10 @@ void TabSettings::indentLine(QTextBlock block, int newIndent, int padding) const
     }
 
     // Quickly check whether indenting is required.
-    if (indentationColumn(text) == newIndent)
-        return;
+    // fixme: after changing "use spaces for tabs" the change was not reflected
+    // because of the following optimisation. Commenting it out for now.
+//    if (indentationColumn(text) == newIndent)
+//        return;
 
     QString indentString;
 
@@ -405,7 +407,7 @@ bool TabSettings::equals(const TabSettings &ts) const
         && m_tabSize == ts.m_tabSize
         && m_indentSize == ts.m_indentSize
         && m_indentBraces == ts.m_indentBraces
-	&& m_doubleIndentBlocks == ts.m_doubleIndentBlocks
+        && m_doubleIndentBlocks == ts.m_doubleIndentBlocks
         && m_tabKeyBehavior == ts.m_tabKeyBehavior
         && m_continuationAlignBehavior == ts.m_continuationAlignBehavior;
 }
diff --git a/src/plugins/texteditor/tabsettings.h b/src/plugins/texteditor/tabsettings.h
index d51588921a5..2daa170a06a 100644
--- a/src/plugins/texteditor/tabsettings.h
+++ b/src/plugins/texteditor/tabsettings.h
@@ -112,4 +112,6 @@ inline bool operator!=(const TabSettings &t1, const TabSettings &t2) { return !t
 
 } // namespace TextEditor
 
+Q_DECLARE_METATYPE(TextEditor::TabSettings)
+
 #endif // TABSETTINGS_H
diff --git a/src/plugins/texteditor/tabsettingswidget.cpp b/src/plugins/texteditor/tabsettingswidget.cpp
new file mode 100644
index 00000000000..9e4336902f0
--- /dev/null
+++ b/src/plugins/texteditor/tabsettingswidget.cpp
@@ -0,0 +1,122 @@
+#include "tabsettingswidget.h"
+#include "ui_tabsettingswidget.h"
+#include "tabsettings.h"
+
+#include <QtCore/QTextStream>
+
+namespace TextEditor {
+
+TabSettingsWidget::TabSettingsWidget(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::TabSettingsWidget)
+{
+    ui->setupUi(this);
+
+    connect(ui->insertSpaces, SIGNAL(toggled(bool)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->insertSpaces, SIGNAL(toggled(bool)),
+            this, SLOT(updateWidget()));
+    connect(ui->autoInsertSpaces, SIGNAL(toggled(bool)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->autoIndent, SIGNAL(toggled(bool)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->smartBackspace, SIGNAL(toggled(bool)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->tabSize, SIGNAL(valueChanged(int)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->indentSize, SIGNAL(valueChanged(int)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->tabKeyBehavior, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(slotSettingsChanged()));
+    connect(ui->continuationAlignBehavior, SIGNAL(currentIndexChanged(int)),
+            this, SLOT(slotSettingsChanged()));
+
+    setFlat(false);
+}
+
+TabSettingsWidget::~TabSettingsWidget()
+{
+    delete ui;
+}
+
+void TabSettingsWidget::setSettings(const TextEditor::TabSettings& s)
+{
+    const bool wasBlocked = blockSignals(true);
+    ui->insertSpaces->setChecked(s.m_spacesForTabs);
+    ui->autoInsertSpaces->setChecked(s.m_autoSpacesForTabs);
+    ui->autoIndent->setChecked(s.m_autoIndent);
+    ui->smartBackspace->setChecked(s.m_smartBackspace);
+    ui->tabSize->setValue(s.m_tabSize);
+    ui->indentSize->setValue(s.m_indentSize);
+    ui->tabKeyBehavior->setCurrentIndex(s.m_tabKeyBehavior);
+    ui->continuationAlignBehavior->setCurrentIndex(s.m_continuationAlignBehavior);
+    blockSignals(wasBlocked);
+
+    updateWidget();
+}
+
+TabSettings TabSettingsWidget::settings() const
+{
+    TabSettings set;
+
+    set.m_spacesForTabs = ui->insertSpaces->isChecked();
+    set.m_autoSpacesForTabs = ui->autoInsertSpaces->isChecked();
+    set.m_autoIndent = ui->autoIndent->isChecked();
+    set.m_smartBackspace = ui->smartBackspace->isChecked();
+    set.m_tabSize = ui->tabSize->value();
+    set.m_indentSize = ui->indentSize->value();
+    set.m_tabKeyBehavior = (TabSettings::TabKeyBehavior)(ui->tabKeyBehavior->currentIndex());
+    set.m_continuationAlignBehavior = (TabSettings::ContinuationAlignBehavior)(ui->continuationAlignBehavior->currentIndex());
+
+    return set;
+}
+
+void TabSettingsWidget::slotSettingsChanged()
+{
+    emit settingsChanged(settings());
+}
+
+void TabSettingsWidget::setFlat(bool on)
+{
+     ui->tabsAndIndentationGroupBox->setFlat(on);
+     const int margin = on ? 0 : -1;
+     ui->tabsAndIndentationGroupBox->layout()->setContentsMargins(margin, -1, margin, margin);
+}
+
+QString TabSettingsWidget::searchKeywords() const
+{
+    QString rc;
+    QLatin1Char sep(' ');
+    QTextStream(&rc)
+            << sep << ui->tabsAndIndentationGroupBox->title()
+            << sep << ui->insertSpaces->text()
+            << sep << ui->autoInsertSpaces->text()
+            << sep << ui->autoIndent->text()
+            << sep << ui->smartBackspace->text()
+            << sep << ui->tabSizeLabel->text()
+            << sep << ui->indentSizeLabel->text()
+            << sep << ui->tabKeyBehaviorLabel->text()
+            << sep << ui->continuationAlignBehaviorLabel->text()
+               ;
+    rc.remove(QLatin1Char('&'));
+    return rc;
+}
+
+void TabSettingsWidget::updateWidget()
+{
+    ui->autoInsertSpaces->setEnabled(ui->insertSpaces->isChecked());
+}
+
+void TabSettingsWidget::changeEvent(QEvent *e)
+{
+    QWidget::changeEvent(e);
+    switch (e->type()) {
+    case QEvent::LanguageChange:
+        ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+} // namespace TextEditor
diff --git a/src/plugins/texteditor/tabsettingswidget.h b/src/plugins/texteditor/tabsettingswidget.h
new file mode 100644
index 00000000000..ff79a9d8f85
--- /dev/null
+++ b/src/plugins/texteditor/tabsettingswidget.h
@@ -0,0 +1,47 @@
+#ifndef TEXTEDITOR_TABSETTINGSWIDGET_H
+#define TEXTEDITOR_TABSETTINGSWIDGET_H
+
+#include "texteditor_global.h"
+#include <QWidget>
+
+namespace TextEditor {
+
+class TabSettings;
+
+namespace Ui {
+    class TabSettingsWidget;
+}
+
+class TEXTEDITOR_EXPORT TabSettingsWidget : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit TabSettingsWidget(QWidget *parent = 0);
+    ~TabSettingsWidget();
+
+    TabSettings settings() const;
+
+    void setFlat(bool on);
+    QString searchKeywords() const;
+
+public slots:
+    void setSettings(const TextEditor::TabSettings& s);
+
+signals:
+    void settingsChanged(const TextEditor::TabSettings &);
+
+protected:
+    void changeEvent(QEvent *e);
+
+private slots:
+    void slotSettingsChanged();
+    void updateWidget();
+
+private:
+    Ui::TabSettingsWidget *ui;
+};
+
+
+} // namespace TextEditor
+#endif // TEXTEDITOR_TABSETTINGSWIDGET_H
diff --git a/src/plugins/texteditor/tabsettingswidget.ui b/src/plugins/texteditor/tabsettingswidget.ui
new file mode 100644
index 00000000000..63494f7b8ab
--- /dev/null
+++ b/src/plugins/texteditor/tabsettingswidget.ui
@@ -0,0 +1,288 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TextEditor::TabSettingsWidget</class>
+ <widget class="QWidget" name="TextEditor::TabSettingsWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>362</width>
+    <height>384</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="margin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QGroupBox" name="tabsAndIndentationGroupBox">
+     <property name="title">
+      <string>Tabs And Indentation</string>
+     </property>
+     <property name="flat">
+      <bool>true</bool>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_2">
+      <property name="margin">
+       <number>0</number>
+      </property>
+      <item row="0" column="0" colspan="2">
+       <widget class="QCheckBox" name="insertSpaces">
+        <property name="text">
+         <string>Insert &amp;spaces instead of tabs</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <spacer name="horizontalSpacer_5">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Fixed</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>30</width>
+          <height>24</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="1" colspan="2">
+       <widget class="QCheckBox" name="autoInsertSpaces">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
+        <property name="toolTip">
+         <string>Automatically determine based on the nearest indented line (previous line preferred over next line)</string>
+        </property>
+        <property name="text">
+         <string>Based on the surrounding lines</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="0" colspan="2">
+       <layout class="QGridLayout" name="gridLayout">
+        <item row="0" column="0">
+         <widget class="QLabel" name="tabSizeLabel">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="text">
+           <string>Ta&amp;b size:</string>
+          </property>
+          <property name="buddy">
+           <cstring>tabSize</cstring>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="1">
+         <spacer name="horizontalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item row="0" column="2">
+         <widget class="QSpinBox" name="tabSize">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="minimum">
+           <number>1</number>
+          </property>
+          <property name="maximum">
+           <number>20</number>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="0">
+         <widget class="QLabel" name="indentSizeLabel">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="text">
+           <string>&amp;Indent size:</string>
+          </property>
+          <property name="buddy">
+           <cstring>indentSize</cstring>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="2">
+         <widget class="QSpinBox" name="indentSize">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="minimum">
+           <number>1</number>
+          </property>
+          <property name="maximum">
+           <number>20</number>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item row="2" column="2">
+       <spacer name="horizontalSpacer">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>49</width>
+          <height>59</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="3" column="0" colspan="3">
+       <widget class="QCheckBox" name="autoIndent">
+        <property name="text">
+         <string>Enable automatic &amp;indentation</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="0" colspan="3">
+       <widget class="QCheckBox" name="smartBackspace">
+        <property name="toolTip">
+         <string>Backspace will go back one indentation level instead of one space.</string>
+        </property>
+        <property name="text">
+         <string>&amp;Backspace follows indentation</string>
+        </property>
+       </widget>
+      </item>
+      <item row="5" column="0" colspan="2">
+       <widget class="QLabel" name="continuationAlignBehaviorLabel">
+        <property name="text">
+         <string>Align continuation lines:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="6" column="1">
+       <widget class="QComboBox" name="continuationAlignBehavior">
+        <property name="toolTip">
+         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;
+Influences the indentation of continuation lines.
+
+&lt;ul&gt;
+&lt;li&gt;Not At All: Do not align at all. Lines will only be indented to the current logical indentation depth.
+&lt;pre&gt;
+(tab)int i = foo(a, b
+(tab)c, d);
+&lt;/pre&gt;
+&lt;/li&gt;
+
+&lt;li&gt;With Spaces: Always use spaces for alignment, regardless of the other indentation settings.
+&lt;pre&gt;
+(tab)int i = foo(a, b
+(tab)            c, d);
+&lt;/pre&gt;
+&lt;/li&gt;
+
+&lt;li&gt;With Regular Indent: Use tabs and/or spaces for alignment, as configured above.
+&lt;pre&gt;
+(tab)int i = foo(a, b
+(tab)(tab)(tab)  c, d);
+&lt;/pre&gt;
+&lt;/li&gt;
+&lt;/ul&gt;&lt;/body&gt;&lt;/html&gt;</string>
+        </property>
+        <item>
+         <property name="text">
+          <string>Not At All</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>With Spaces</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>With Regular Indent</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="7" column="0" colspan="2">
+       <widget class="QLabel" name="tabKeyBehaviorLabel">
+        <property name="text">
+         <string>Tab key performs auto-indent:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="8" column="1">
+       <widget class="QComboBox" name="tabKeyBehavior">
+        <item>
+         <property name="text">
+          <string>Never</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>Always</string>
+         </property>
+        </item>
+        <item>
+         <property name="text">
+          <string>In Leading White Space</string>
+         </property>
+        </item>
+       </widget>
+      </item>
+      <item row="9" column="1">
+       <spacer name="verticalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>13</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <tabstops>
+  <tabstop>insertSpaces</tabstop>
+  <tabstop>autoInsertSpaces</tabstop>
+  <tabstop>tabSize</tabstop>
+  <tabstop>indentSize</tabstop>
+  <tabstop>autoIndent</tabstop>
+  <tabstop>smartBackspace</tabstop>
+  <tabstop>continuationAlignBehavior</tabstop>
+  <tabstop>tabKeyBehavior</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro
index 2056ae391e6..fdd93828746 100644
--- a/src/plugins/texteditor/texteditor.pro
+++ b/src/plugins/texteditor/texteditor.pro
@@ -99,7 +99,14 @@ SOURCES += texteditorplugin.cpp \
     codeassist/genericproposalwidget.cpp \
     codeassist/basicproposalitem.cpp \
     codeassist/basicproposalitemlistmodel.cpp \
-    codeassist/iassistproposalmodel.cpp
+    codeassist/iassistproposalmodel.cpp \
+    tabsettingswidget.cpp \
+    codestylepreferencesmanager.cpp \
+    ifallbackpreferences.cpp \
+    tabpreferences.cpp \
+    icodestylepreferencesfactory.cpp \
+    tabpreferenceswidget.cpp \
+    fallbackselectorwidget.cpp
 
 HEADERS += texteditorplugin.h \
     textfilewizard.h \
@@ -203,7 +210,14 @@ HEADERS += texteditorplugin.h \
     codeassist/genericproposalwidget.h \
     codeassist/basicproposalitem.h \
     codeassist/basicproposalitemlistmodel.h \
-    codeassist/iassistproposalmodel.h
+    codeassist/iassistproposalmodel.h \
+    tabsettingswidget.h \
+    codestylepreferencesmanager.h \
+    ifallbackpreferences.h \
+    tabpreferences.h \
+    icodestylepreferencesfactory.h \
+    tabpreferenceswidget.h \
+    fallbackselectorwidget.h
 
 FORMS += \
     displaysettingspage.ui \
@@ -213,6 +227,8 @@ FORMS += \
     generichighlighter/managedefinitionsdialog.ui \
     snippets/snippetssettingspage.ui \
     behaviorsettingswidget.ui \
-    behaviorsettingspage.ui
+    behaviorsettingspage.ui \
+    tabsettingswidget.ui \
+    tabpreferenceswidget.ui
 RESOURCES += texteditor.qrc
 OTHER_FILES += TextEditor.mimetypes.xml
diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp
index ed10c71bf3f..378dd5e95cf 100644
--- a/src/plugins/texteditor/texteditorsettings.cpp
+++ b/src/plugins/texteditor/texteditorsettings.cpp
@@ -42,6 +42,7 @@
 #include "fontsettingspage.h"
 #include "storagesettings.h"
 #include "tabsettings.h"
+#include "tabpreferences.h"
 #include "extraencodingsettings.h"
 #include "texteditorplugin.h"
 #include "highlightersettingspage.h"
@@ -69,6 +70,9 @@ public:
     HighlighterSettingsPage *m_highlighterSettingsPage;
     SnippetsSettingsPage *m_snippetsSettingsPage;
 
+    QMap<QString, TabPreferences *> m_languageTabPreferences;
+    QMap<QString, IFallbackPreferences *> m_languageCodeStylePreferences;
+
     CompletionSettings m_completionSettings;
 
     void fontZoomRequested(int pointSize);
@@ -186,8 +190,6 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
 
     connect(m_d->m_fontSettingsPage, SIGNAL(changed(TextEditor::FontSettings)),
             this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)));
-    connect(m_d->m_behaviorSettingsPage, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
-            this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)));
     connect(m_d->m_behaviorSettingsPage, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
             this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)));
     connect(m_d->m_behaviorSettingsPage, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -228,8 +230,6 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
     // Connect to settings change signals
     connect(this, SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
             editor, SLOT(setFontSettingsIfVisible(TextEditor::FontSettings)));
-    connect(this, SIGNAL(tabSettingsChanged(TextEditor::TabSettings)),
-            editor, SLOT(setTabSettings(TextEditor::TabSettings)));
     connect(this, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)),
             editor, SLOT(setStorageSettings(TextEditor::StorageSettings)));
     connect(this, SIGNAL(behaviorSettingsChanged(TextEditor::BehaviorSettings)),
@@ -248,25 +248,21 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
 
     // Apply current settings (tab settings depend on font settings)
     editor->setFontSettings(fontSettings());
-    editor->setTabSettings(tabSettings());
+    editor->setTabSettings(tabPreferences()->settings());
     editor->setStorageSettings(storageSettings());
     editor->setBehaviorSettings(behaviorSettings());
     editor->setDisplaySettings(displaySettings());
     editor->setCompletionSettings(completionSettings());
     editor->setExtraEncodingSettings(extraEncodingSettings());
+    editor->setTabPreferences(tabPreferences(editor->languageSettingsId()));
+    editor->setCodeStylePreferences(codeStylePreferences(editor->languageSettingsId()));
 }
 
-
 const FontSettings &TextEditorSettings::fontSettings() const
 {
     return m_d->m_fontSettingsPage->fontSettings();
 }
 
-const TabSettings &TextEditorSettings::tabSettings() const
-{
-    return m_d->m_behaviorSettingsPage->tabSettings();
-}
-
 const StorageSettings &TextEditorSettings::storageSettings() const
 {
     return m_d->m_behaviorSettingsPage->storageSettings();
@@ -309,4 +305,42 @@ void TextEditorSettings::setCompletionSettings(const TextEditor::CompletionSetti
     emit completionSettingsChanged(m_d->m_completionSettings);
 }
 
+TabPreferences *TextEditorSettings::tabPreferences() const
+{
+    return m_d->m_behaviorSettingsPage->tabPreferences();
+}
+
+TabPreferences *TextEditorSettings::tabPreferences(const QString &languageId) const
+{
+    TabPreferences *prefs = m_d->m_languageTabPreferences.value(languageId);
+    if (!prefs)
+        prefs = tabPreferences();
+    return prefs;
+}
+
+QMap<QString, TabPreferences *> TextEditorSettings::languageTabPreferences() const
+{
+    return m_d->m_languageTabPreferences;
+}
+
+void TextEditorSettings::registerLanguageTabPreferences(const QString &languageId, TabPreferences *prefs)
+{
+    m_d->m_languageTabPreferences.insert(languageId, prefs);
+}
+
+IFallbackPreferences *TextEditorSettings::codeStylePreferences(const QString &languageId) const
+{
+    return m_d->m_languageCodeStylePreferences.value(languageId);
+}
+
+QMap<QString, IFallbackPreferences *> TextEditorSettings::languageCodeStylePreferences() const
+{
+    return m_d->m_languageCodeStylePreferences;
+}
+
+void TextEditorSettings::registerLanguageCodeStylePreferences(const QString &languageId, IFallbackPreferences *prefs)
+{
+    m_d->m_languageCodeStylePreferences.insert(languageId, prefs);
+}
+
 #include "moc_texteditorsettings.cpp"
diff --git a/src/plugins/texteditor/texteditorsettings.h b/src/plugins/texteditor/texteditorsettings.h
index 60a3c69c09f..7385a0a8206 100644
--- a/src/plugins/texteditor/texteditorsettings.h
+++ b/src/plugins/texteditor/texteditorsettings.h
@@ -37,6 +37,11 @@
 
 #include <QtCore/QObject>
 
+QT_BEGIN_NAMESPACE
+template <class Key, class T>
+class QMap;
+QT_END_NAMESPACE
+
 namespace TextEditor {
 
 class BaseTextEditorWidget;
@@ -48,6 +53,8 @@ class DisplaySettings;
 class CompletionSettings;
 class HighlighterSettings;
 class ExtraEncodingSettings;
+class TabPreferences;
+class IFallbackPreferences;
 
 namespace Internal {
 class TextEditorSettingsPrivate;
@@ -71,7 +78,6 @@ public:
     void initializeEditor(BaseTextEditorWidget *editor);
 
     const FontSettings &fontSettings() const;
-    const TabSettings &tabSettings() const;
     const StorageSettings &storageSettings() const;
     const BehaviorSettings &behaviorSettings() const;
     const DisplaySettings &displaySettings() const;
@@ -81,9 +87,17 @@ public:
 
     void setCompletionSettings(const TextEditor::CompletionSettings &);
 
+    TabPreferences *tabPreferences() const;
+    TabPreferences *tabPreferences(const QString &languageId) const;
+    QMap<QString, TabPreferences *> languageTabPreferences() const;
+    void registerLanguageTabPreferences(const QString &languageId, TabPreferences *prefs);
+
+    IFallbackPreferences *codeStylePreferences(const QString &languageId) const;
+    QMap<QString, IFallbackPreferences *> languageCodeStylePreferences() const;
+    void registerLanguageCodeStylePreferences(const QString &languageId, IFallbackPreferences *prefs);
+
 signals:
     void fontSettingsChanged(const TextEditor::FontSettings &);
-    void tabSettingsChanged(const TextEditor::TabSettings &);
     void storageSettingsChanged(const TextEditor::StorageSettings &);
     void behaviorSettingsChanged(const TextEditor::BehaviorSettings &);
     void displaySettingsChanged(const TextEditor::DisplaySettings &);
diff --git a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
index ade32d8c2e9..d8b9a33daea 100644
--- a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
+++ b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
@@ -62,6 +62,8 @@ private Q_SLOTS:
     void cStyleComments();
     void cppStyleComments();
     void expressionContinuation();
+    void assignContinuation1();
+    void assignContinuation2();
     void classAccess();
     void ternary();
     void objcAtDeclarations();
@@ -72,6 +74,11 @@ private Q_SLOTS:
     void bug2();
     void bug3();
     void switch1();
+    void switch2();
+    void switch3();
+    void switch4();
+    void switch5();
+    void blocks();
     void memberInitializer();
     void templates();
     void operatorOverloads();
@@ -93,6 +100,26 @@ private Q_SLOTS:
     void labels();
     void functionsWithExtraSpecifier();
     void externSpec();
+    void indentNamespace();
+    void indentNamespace2();
+    void accessSpecifiers1();
+    void accessSpecifiers2();
+    void accessSpecifiers3();
+    void accessSpecifiers4();
+    void accessSpecifiers5();
+    void accessSpecifiers6();
+    void functionBodyAndBraces1();
+    void functionBodyAndBraces2();
+    void functionBodyAndBraces3();
+    void functionBodyAndBraces4();
+    void constructor();
+    void caseBody1();
+    void caseBody2();
+    void caseBody3();
+    void caseBody4();
+    void caseBody5();
+    void caseBody6();
+    void blockBraces1();
 };
 
 struct Line {
@@ -148,19 +175,10 @@ QString concatLines(QList<Line> lines)
     return result;
 }
 
-void checkIndent(QList<Line> data, int style = 0)
+void checkIndent(QList<Line> data, QtStyleCodeFormatter formatter)
 {
     QString text = concatLines(data);
     QTextDocument document(text);
-    QtStyleCodeFormatter formatter;
-    if (style == 1) {// gnu
-        formatter.setIndentSubstatementBraces(true);
-    } else if (style == 2) { // whitesmiths
-        formatter.setIndentSubstatementStatements(false);
-        formatter.setIndentSubstatementBraces(true);
-        formatter.setIndentDeclarationMembers(false);
-        formatter.setIndentDeclarationBraces(true);
-    }
 
     int i = 0;
     foreach (const Line &l, data) {
@@ -178,6 +196,37 @@ void checkIndent(QList<Line> data, int style = 0)
     }
 }
 
+void checkIndent(QList<Line> data, CppCodeStyleSettings style)
+{
+    QtStyleCodeFormatter formatter;
+    formatter.setCodeStyleSettings(style);
+    checkIndent(data, formatter);
+}
+
+void checkIndent(QList<Line> data, int style = 0)
+{
+    CppCodeStyleSettings codeStyle;
+    QtStyleCodeFormatter formatter;
+    if (style == 1) {// gnu
+        codeStyle.indentBlockBraces = true;
+        codeStyle.indentSwitchLabels = true;
+        codeStyle.indentBlocksRelativeToSwitchLabels = true;
+    } else if (style == 2) { // whitesmiths
+        codeStyle.indentBlockBody = false;
+        codeStyle.indentBlockBraces = true;
+        codeStyle.indentClassBraces = true;
+        codeStyle.indentNamespaceBraces = true;
+        codeStyle.indentEnumBraces = true;
+        codeStyle.indentFunctionBody = false;
+        codeStyle.indentFunctionBraces = true;
+        codeStyle.indentSwitchLabels = true;
+        codeStyle.indentBlocksRelativeToSwitchLabels = true;
+    }
+    formatter.setCodeStyleSettings(codeStyle);
+
+    checkIndent(data, formatter);
+}
+
 void tst_CodeFormatter::ifStatementWithoutBraces1()
 {
     QList<Line> data;
@@ -585,6 +634,46 @@ void tst_CodeFormatter::expressionContinuation()
     checkIndent(data);
 }
 
+void tst_CodeFormatter::assignContinuation1()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    abcdefgh = a +")
+         << Line("    ~       b;")
+         << Line("    a = a +")
+         << Line("    ~       b;")
+         << Line("    (a = a +")
+         << Line("    ~       b);")
+         << Line("    abcdefgh =")
+         << Line("    ~       a + b;")
+         << Line("    a =")
+         << Line("    ~       a + b;")
+         << Line("}")
+         ;
+    checkIndent(data);
+}
+
+void tst_CodeFormatter::assignContinuation2()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    abcdefgh = a +")
+         << Line("    ~          b;")
+         << Line("    a = a +")
+         << Line("    ~   b;")
+         << Line("    (a = a +")
+         << Line("    ~    b);")
+         << Line("    abcdefgh =")
+         << Line("    ~       a + b;")
+         << Line("    a =")
+         << Line("    ~       a + b;")
+         << Line("}")
+         ;
+    CppCodeStyleSettings style;
+    style.alignAssignments = true;
+    checkIndent(data, style);
+}
+
 void tst_CodeFormatter::classAccess()
 {
     QList<Line> data;
@@ -772,17 +861,165 @@ void tst_CodeFormatter::switch1()
          << Line("    }")
          << Line("    case bar:")
          << Line("        break;")
-         << Line("    }")
          << Line("    case 4:")
          << Line("    {")
          << Line("        if (a) {")
          << Line("        }")
          << Line("    }")
+         << Line("    }")
          << Line("}")
          ;
     checkIndent(data);
 }
 
+void tst_CodeFormatter::switch2()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (a) {")
+         << Line("        case 1:")
+         << Line("            foo;")
+         << Line("            if (a);")
+         << Line("        case 2:")
+         << Line("        case 3: {")
+         << Line("            foo;")
+         << Line("        }")
+         << Line("        case 4:")
+         << Line("        {")
+         << Line("            foo;")
+         << Line("        }")
+         << Line("        case bar:")
+         << Line("            break;")
+         << Line("        case 4:")
+         << Line("        {")
+         << Line("            if (a) {")
+         << Line("            }")
+         << Line("        }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::switch3()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (a)")
+         << Line("        {")
+         << Line("    case 1:")
+         << Line("        foo;")
+         << Line("        if (a);")
+         << Line("    case 2:")
+         << Line("    case 3:")
+         << Line("        {")
+         << Line("            foo;")
+         << Line("        }")
+         << Line("    case bar:")
+         << Line("        break;")
+         << Line("    case 4:")
+         << Line("        {")
+         << Line("            if (a)")
+         << Line("                {")
+         << Line("                }")
+         << Line("        }")
+         << Line("        }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentBlockBraces = true;
+    codeStyle.indentBlocksRelativeToSwitchLabels= true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::switch4()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (a)")
+         << Line("        {")
+         << Line("        case 1:")
+         << Line("            foo;")
+         << Line("            if (a);")
+         << Line("        case 2:")
+         << Line("        case 4:")
+         << Line("            {")
+         << Line("                foo;")
+         << Line("            }")
+         << Line("        case bar:")
+         << Line("            break;")
+         << Line("        case 4:")
+         << Line("            {")
+         << Line("                if (a)")
+         << Line("                    {")
+         << Line("                    }")
+         << Line("            }")
+         << Line("        }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentBlockBraces = true;
+    codeStyle.indentBlocksRelativeToSwitchLabels = true;
+    codeStyle.indentSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::switch5()
+{
+    QList<Line> data;
+    data << Line("void foo()")
+         << Line("{")
+         << Line("    switch (a)")
+         << Line("        {")
+         << Line("        case 1:")
+         << Line("            foo;")
+         << Line("            if (a);")
+         << Line("        case 2:")
+         << Line("        case 4:")
+         << Line("            {")
+         << Line("            foo;")
+         << Line("            }")
+         << Line("        case bar:")
+         << Line("            break;")
+         << Line("        case 4:")
+         << Line("            {")
+         << Line("            if (a)")
+         << Line("                {")
+         << Line("                }")
+         << Line("            }")
+         << Line("        }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentBlockBraces = true;
+    codeStyle.indentBlockBody = false;
+    codeStyle.indentBlocksRelativeToSwitchLabels = true;
+    codeStyle.indentSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::blocks()
+{
+    QList<Line> data;
+    data << Line("void foo()")
+         << Line("{")
+         << Line("    int a;")
+         << Line("    {")
+         << Line("    int b;")
+         << Line("    {")
+         << Line("    int c;")
+         << Line("    }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentBlockBody = false;
+    codeStyle.indentBlockBraces = true;
+    checkIndent(data, codeStyle);
+}
+
 void tst_CodeFormatter::memberInitializer()
 {
     QList<Line> data;
@@ -870,8 +1107,8 @@ void tst_CodeFormatter::gnuStyle()
          << Line("            {")
          << Line("            }")
          << Line("        if (b) {")
-         << Line("            fpp;")
-         << Line("        }")
+         << Line("                fpp;")
+         << Line("            }")
          << Line("        {")
          << Line("            foo;")
          << Line("        }")
@@ -900,6 +1137,14 @@ void tst_CodeFormatter::whitesmithsStyle()
          << Line("        }")
          << Line("        }")
          << Line("    };")
+         << Line("enum E")
+         << Line("    {")
+         << Line("    FOO")
+         << Line("    };")
+         << Line("namespace")
+         << Line("    {")
+         << Line("    int i;")
+         << Line("    };")
          ;
     checkIndent(data, 2);
 }
@@ -1189,6 +1434,31 @@ void tst_CodeFormatter::functionsWithExtraSpecifier()
          << Line("namespace foo {")
          << Line("}")
          << Line("int a;")
+            ;
+       checkIndent(data);
+}
+
+void tst_CodeFormatter::indentNamespace()
+{
+    QList<Line> data;
+    data << Line("namespace Foo {")
+         << Line("int x;")
+         << Line("class C;")
+         << Line("struct S {")
+         << Line("    int a;")
+         << Line("};")
+         << Line("}")
+         << Line("int j;")
+         << Line("namespace {")
+         << Line("namespace Foo {")
+         << Line("int j;")
+         << Line("}")
+         << Line("int j;")
+         << Line("namespace {")
+         << Line("int j;")
+         << Line("}")
+         << Line("}")
+         << Line("int j;")
          ;
     checkIndent(data);
 }
@@ -1209,7 +1479,422 @@ void tst_CodeFormatter::externSpec()
     checkIndent(data);
 }
 
+void tst_CodeFormatter::indentNamespace2()
+{
+    QList<Line> data;
+    data << Line("namespace Foo {")
+         << Line("    int x;")
+         << Line("    class C;")
+         << Line("    struct S {")
+         << Line("        int a;")
+         << Line("    };")
+         << Line("}")
+         << Line("int j;")
+         << Line("namespace {")
+         << Line("    int j;")
+         << Line("    namespace Foo {")
+         << Line("        int j;")
+         << Line("    }")
+         << Line("    int j;")
+         << Line("    namespace {")
+         << Line("        int j;")
+         << Line("    }")
+         << Line("}")
+         << Line("int j;")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentNamespaceBody = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::accessSpecifiers1()
+{
+    QList<Line> data;
+    data << Line("class C {")
+         << Line("    public:")
+         << Line("    int i;")
+         << Line("    protected:")
+         << Line("    int i;")
+         << Line("    private:")
+         << Line("    int i;")
+         << Line("    private slots:")
+         << Line("    void foo();")
+         << Line("    signals:")
+         << Line("    void foo();")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentAccessSpecifiers = true;
+    codeStyle.indentDeclarationsRelativeToAccessSpecifiers = false;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::accessSpecifiers2()
+{
+    QList<Line> data;
+    data << Line("class C {")
+         << Line("    public:")
+         << Line("        int i;")
+         << Line("    protected:")
+         << Line("        int i;")
+         << Line("    private:")
+         << Line("        int i;")
+         << Line("    private slots:")
+         << Line("        void foo();")
+         << Line("    signals:")
+         << Line("        void foo();")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentAccessSpecifiers = true;
+    codeStyle.indentDeclarationsRelativeToAccessSpecifiers = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::accessSpecifiers3()
+{
+    QList<Line> data;
+    data << Line("class C {")
+         << Line("public:")
+         << Line("int i;")
+         << Line("protected:")
+         << Line("int i;")
+         << Line("private:")
+         << Line("int i;")
+         << Line("private slots:")
+         << Line("void foo();")
+         << Line("signals:")
+         << Line("void foo();")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentAccessSpecifiers = false;
+    codeStyle.indentDeclarationsRelativeToAccessSpecifiers = false;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::accessSpecifiers4()
+{
+    QList<Line> data;
+    data << Line("class C {")
+         << Line("public:")
+         << Line("    int i;")
+         << Line("protected:")
+         << Line("    int i;")
+         << Line("private:")
+         << Line("    int i;")
+         << Line("private slots:")
+         << Line("    void foo();")
+         << Line("signals:")
+         << Line("    void foo();")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentAccessSpecifiers = false;
+    codeStyle.indentDeclarationsRelativeToAccessSpecifiers = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::accessSpecifiers5()
+{
+    QList<Line> data;
+    data << Line("class C {")
+         << Line("public:")
+         << Line("      int i;", 4)
+         << Line("protected:")
+         << Line("      int i;")
+         << Line("private:")
+         << Line("  int i;", 6)
+         << Line("private slots:")
+         << Line("  void foo();")
+         << Line("signals:")
+         << Line("  void foo();")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentAccessSpecifiers = false;
+    codeStyle.indentDeclarationsRelativeToAccessSpecifiers = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::accessSpecifiers6()
+{
+    // not great, but the best we can do with the current scheme
+    QList<Line> data;
+    data << Line("class C {")
+         << Line("    public:")
+         << Line("      int i;", 8)
+         << Line("    protected:")
+         << Line("      int i;")
+         << Line("    private:")
+         << Line("  int i;", 6)
+         << Line("    private slots:")
+         << Line("  void foo();")
+         << Line("    signals:")
+         << Line("  void foo();")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentAccessSpecifiers = true;
+    codeStyle.indentDeclarationsRelativeToAccessSpecifiers = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::functionBodyAndBraces1()
+{
+    QList<Line> data;
+    data << Line("void foo()")
+         << Line("{")
+         << Line("    int i;")
+         << Line("}")
+         << Line("void bar()")
+         << Line("{")
+         << Line("      int i;", 4)
+         << Line("      int j;")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentFunctionBody = true;
+    codeStyle.indentFunctionBraces = false;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::functionBodyAndBraces2()
+{
+    QList<Line> data;
+    data << Line("void foo()")
+         << Line("    {")
+         << Line("        int i;")
+         << Line("    }")
+         << Line("void bar()")
+         << Line("    {")
+         << Line("          int i;", 8)
+         << Line("          int j;")
+         << Line("    }")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentFunctionBody = true;
+    codeStyle.indentFunctionBraces = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::functionBodyAndBraces3()
+{
+    QList<Line> data;
+    data << Line("void foo()")
+         << Line("{")
+         << Line("int i;")
+         << Line("}")
+         << Line("void bar()")
+         << Line("{")
+         << Line("  int i;", 0)
+         << Line("  int j;")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentFunctionBody = false;
+    codeStyle.indentFunctionBraces = false;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::functionBodyAndBraces4()
+{
+    QList<Line> data;
+    data << Line("void foo()")
+         << Line("    {")
+         << Line("    int i;")
+         << Line("    }")
+         << Line("void bar()")
+         << Line("    {")
+         << Line("      int i;", 4)
+         << Line("      int j;")
+         << Line("    };")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentFunctionBody = false;
+    codeStyle.indentFunctionBraces = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::constructor()
+{
+    QList<Line> data;
+    data << Line("class Foo {")
+         << Line("    Foo() : _a(0)")
+         << Line("        {")
+         << Line("        _b = 0")
+         << Line("        }")
+         << Line("    int _a;")
+         << Line("    int _b;")
+         << Line("};")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentFunctionBody = false;
+    codeStyle.indentFunctionBraces = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::caseBody1()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (f) {")
+         << Line("    case 1:")
+         << Line("    a = b;")
+         << Line("    break;")
+         << Line("    case 2:")
+         << Line("    a = b;")
+         << Line("    case 3: {")
+         << Line("        a = b;")
+         << Line("    }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentStatementsRelativeToSwitchLabels = false;
+    codeStyle.indentBlocksRelativeToSwitchLabels = false;
+    codeStyle.indentControlFlowRelativeToSwitchLabels = false;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::caseBody2()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (f) {")
+         << Line("    case 1:")
+         << Line("        a = b;")
+         << Line("        break;")
+         << Line("    case 2:")
+         << Line("        a = b;")
+         << Line("    case 3: {")
+         << Line("        a = b;")
+         << Line("    }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentStatementsRelativeToSwitchLabels = true;
+    codeStyle.indentBlocksRelativeToSwitchLabels = false;
+    codeStyle.indentControlFlowRelativeToSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::caseBody3()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (f) {")
+         << Line("    case 1:")
+         << Line("        a = b;")
+         << Line("        break;")
+         << Line("    case 2:")
+         << Line("        a = b;")
+         << Line("    case 3: {")
+         << Line("            a = b;")
+         << Line("        }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentStatementsRelativeToSwitchLabels = true;
+    codeStyle.indentBlocksRelativeToSwitchLabels = true;
+    codeStyle.indentControlFlowRelativeToSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::caseBody4()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (f) {")
+         << Line("        case 1:")
+         << Line("        a = b;")
+         << Line("        break;")
+         << Line("        case 2:")
+         << Line("        a = b;")
+         << Line("        case 3: {")
+         << Line("            a = b;")
+         << Line("        }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentSwitchLabels = true;
+    codeStyle.indentStatementsRelativeToSwitchLabels = false;
+    codeStyle.indentBlocksRelativeToSwitchLabels = false;
+    codeStyle.indentControlFlowRelativeToSwitchLabels = false;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::caseBody5()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (f) {")
+         << Line("        case 1:")
+         << Line("            a = b;")
+         << Line("            break;")
+         << Line("        case 2:")
+         << Line("            a = b;")
+         << Line("        case 3: {")
+         << Line("            a = b;")
+         << Line("        }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentSwitchLabels = true;
+    codeStyle.indentStatementsRelativeToSwitchLabels = true;
+    codeStyle.indentBlocksRelativeToSwitchLabels = false;
+    codeStyle.indentControlFlowRelativeToSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::caseBody6()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    switch (f) {")
+         << Line("        case 1:")
+         << Line("            a = b;")
+         << Line("            break;")
+         << Line("        case 2:")
+         << Line("            a = b;")
+         << Line("        case 3: {")
+         << Line("                a = b;")
+         << Line("            }")
+         << Line("    }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentSwitchLabels = true;
+    codeStyle.indentStatementsRelativeToSwitchLabels = true;
+    codeStyle.indentBlocksRelativeToSwitchLabels = true;
+    codeStyle.indentControlFlowRelativeToSwitchLabels = true;
+    checkIndent(data, codeStyle);
+}
+
+void tst_CodeFormatter::blockBraces1()
+{
+    QList<Line> data;
+    data << Line("void foo() {")
+         << Line("    if (a) {")
+         << Line("            int a;")
+         << Line("        }")
+         << Line("    if (a)")
+         << Line("        {")
+         << Line("            int a;")
+         << Line("        }")
+         << Line("}")
+         ;
+    CppCodeStyleSettings codeStyle;
+    codeStyle.indentBlockBraces = true;
+    checkIndent(data, codeStyle);
+}
+
 QTEST_APPLESS_MAIN(tst_CodeFormatter)
+
 #include "tst_codeformatter.moc"
 
 
-- 
GitLab