OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / tabsettings.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef TABSETTINGS_H
34 #define TABSETTINGS_H
35
36 #include "texteditor_global.h"
37
38 #include <QtCore/QVariant>
39 #include <QtGui/QTextBlock>
40
41 QT_BEGIN_NAMESPACE
42 class QSettings;
43 QT_END_NAMESPACE
44
45 namespace TextEditor {
46
47 // Tab settings: Data type the GeneralSettingsPage acts on
48 // with some convenience functions for formatting.
49 class TEXTEDITOR_EXPORT TabSettings
50 {
51 public:
52     // This enum must match the indexes of tabKeyBehavior widget
53     enum TabKeyBehavior {
54         TabNeverIndents = 0,
55         TabAlwaysIndents = 1,
56         TabLeadingWhitespaceIndents = 2
57     };
58
59     // This enum must match the indexes of continuationAlignBehavior widget
60     enum ContinuationAlignBehavior {
61         NoContinuationAlign = 0,
62         ContinuationAlignWithSpaces = 1,
63         ContinuationAlignWithIndent = 2
64     };
65
66     TabSettings();
67
68     void toSettings(const QString &category, QSettings *s) const;
69     void fromSettings(const QString &category, const QSettings *s);
70
71     void toMap(const QString &prefix, QVariantMap *map) const;
72     void fromMap(const QString &prefix, const QVariantMap &map);
73
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 &currentBlock = QTextBlock()) const;
82     QString indentationString(const QString &text) const;
83     int indentationColumn(const QString &text) const;
84     int maximumPadding(const QString &text) const;
85
86     bool cursorIsAtBeginningOfLine(const QTextCursor &cursor) const;
87
88     void indentLine(QTextBlock block, int newIndent, int padding = 0) const;
89     void reindentLine(QTextBlock block, int delta) const;
90
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;
95
96     bool m_spacesForTabs;
97     bool m_autoSpacesForTabs;
98     bool m_autoIndent;
99     bool m_smartBackspace;
100     int m_tabSize;
101     int m_indentSize;
102     bool m_indentBraces;
103     bool m_doubleIndentBlocks;
104     TabKeyBehavior m_tabKeyBehavior;
105     ContinuationAlignBehavior m_continuationAlignBehavior;
106
107     bool equals(const TabSettings &ts) const;
108 };
109
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); }
112
113 } // namespace TextEditor
114
115 #endif // TABSETTINGS_H