1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
36 #include "texteditor_global.h"
38 #include <QtCore/QVariant>
39 #include <QtGui/QTextBlock>
45 namespace TextEditor {
47 // Tab settings: Data type the GeneralSettingsPage acts on
48 // with some convenience functions for formatting.
49 class TEXTEDITOR_EXPORT TabSettings
52 // This enum must match the indexes of tabKeyBehavior widget
56 TabLeadingWhitespaceIndents = 2
59 // This enum must match the indexes of continuationAlignBehavior widget
60 enum ContinuationAlignBehavior {
61 NoContinuationAlign = 0,
62 ContinuationAlignWithSpaces = 1,
63 ContinuationAlignWithIndent = 2
68 void toSettings(const QString &category, QSettings *s) const;
69 void fromSettings(const QString &category, const QSettings *s);
71 void toMap(const QString &prefix, QVariantMap *map) const;
72 void fromMap(const QString &prefix, const QVariantMap &map);
74 int lineIndentPosition(const QString &text) const;
75 int firstNonSpace(const QString &text) const;
76 inline bool onlySpace(const QString &text) const { return firstNonSpace(text) == text.length(); }
77 int columnAt(const QString &text, int position) const;
78 int positionAtColumn(const QString &text, int column, int *offset = 0) const;
79 int spacesLeftFromPosition(const QString &text, int position) const;
80 int indentedColumn(int column, bool doIndent = true) const;
81 QString indentationString(int startColumn, int targetColumn, const QTextBlock ¤tBlock = QTextBlock()) const;
82 QString indentationString(const QString &text) const;
83 int indentationColumn(const QString &text) const;
84 int maximumPadding(const QString &text) const;
86 bool cursorIsAtBeginningOfLine(const QTextCursor &cursor) const;
88 void indentLine(QTextBlock block, int newIndent, int padding = 0) const;
89 void reindentLine(QTextBlock block, int delta) const;
91 int trailingWhitespaces(const QString &text) const;
92 bool isIndentationClean(const QTextBlock &block) const;
93 bool tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition = 0) const;
94 bool guessSpacesForTabs(const QTextBlock &block) const;
97 bool m_autoSpacesForTabs;
99 bool m_smartBackspace;
103 bool m_doubleIndentBlocks;
104 TabKeyBehavior m_tabKeyBehavior;
105 ContinuationAlignBehavior m_continuationAlignBehavior;
107 bool equals(const TabSettings &ts) const;
110 inline bool operator==(const TabSettings &t1, const TabSettings &t2) { return t1.equals(t2); }
111 inline bool operator!=(const TabSettings &t1, const TabSettings &t2) { return !t1.equals(t2); }
113 } // namespace TextEditor
115 #endif // TABSETTINGS_H