OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / itexteditor.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 ITEXTEDITOR_H
34 #define ITEXTEDITOR_H
35
36 #include "texteditor_global.h"
37
38 #include <coreplugin/editormanager/ieditor.h>
39
40 #include <QtCore/QObject>
41 #include <QtCore/QList>
42 #include <QtCore/QMap>
43
44 QT_BEGIN_NAMESPACE
45 class QMenu;
46 class QTextBlock;
47 class QIcon;
48 class QRect;
49 class QPoint;
50 QT_END_NAMESPACE
51
52 namespace TextEditor {
53
54 class ITextEditor;
55
56 class TEXTEDITOR_EXPORT ITextMark : public QObject
57 {
58     Q_OBJECT
59 public:
60     ITextMark(QObject *parent = 0) : QObject(parent) {}
61     virtual ~ITextMark() {}
62
63     virtual QIcon icon() const = 0;
64
65     virtual void updateLineNumber(int lineNumber) = 0;
66     virtual void updateBlock(const QTextBlock &block) = 0;
67     virtual void removedFromEditor() = 0;
68     virtual void documentClosing() = 0;
69
70     // determine order on markers on the same line.
71     enum Priority
72     {
73         LowPriority,
74         NormalPriority,
75         HighPriority // shown on top.
76     };
77
78     virtual Priority priority() const = 0;
79 };
80
81 typedef QList<ITextMark *> TextMarks;
82
83
84 class TEXTEDITOR_EXPORT ITextMarkable : public QObject
85 {
86     Q_OBJECT
87 public:
88     ITextMarkable(QObject *parent = 0) : QObject(parent) {}
89     virtual ~ITextMarkable() {}
90     virtual bool addMark(ITextMark *mark, int line) = 0;
91
92     virtual TextMarks marksAt(int line) const = 0;
93     virtual void removeMark(ITextMark *mark) = 0;
94     virtual bool hasMark(ITextMark *mark) const = 0;
95     virtual void updateMark(ITextMark *mark) = 0;
96 };
97
98 class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
99 {
100     Q_OBJECT
101 public:
102     enum PositionOperation {
103         Current = 1,
104         EndOfLine = 2,
105         StartOfLine = 3,
106         Anchor = 4,
107         EndOfDoc = 5
108     };
109
110     ITextEditor() {}
111     virtual ~ITextEditor() {}
112
113     virtual int find(const QString &string) const = 0;
114
115     virtual int position(PositionOperation posOp = Current, int at = -1) const = 0;
116     virtual void convertPosition(int pos, int *line, int *column) const = 0;
117     virtual QRect cursorRect(int pos = -1) const = 0;
118     virtual int columnCount() const = 0;
119     virtual int rowCount() const = 0;
120
121     virtual QString contents() const = 0;
122     virtual QString selectedText() const = 0;
123     virtual QString textAt(int pos, int length) const = 0;
124     virtual QChar characterAt(int pos) const = 0;
125
126     /*! Removes \a length characters to the right of the cursor. */
127     virtual void remove(int length) = 0;
128     /*! Inserts the given string to the right of the cursor. */
129     virtual void insert(const QString &string) = 0;
130     /*! Replaces \a length characters to the right of the cursor with the given string. */
131     virtual void replace(int length, const QString &string) = 0;
132     /*! Sets current cursor position to \a pos. */
133     virtual void setCursorPosition(int pos) = 0;
134     /*! Selects text between current cursor position and \a toPos. */
135     virtual void select(int toPos) = 0;
136
137     virtual ITextMarkable *markableInterface() = 0;
138
139     virtual void setContextHelpId(const QString &) = 0;
140
141     enum TextCodecReason {
142         TextCodecOtherReason,
143         TextCodecFromSystemSetting,
144         TextCodecFromProjectSetting
145     };
146
147     virtual void setTextCodec(QTextCodec *, TextCodecReason reason = TextCodecOtherReason) = 0;
148     virtual QTextCodec *textCodec() const = 0;
149
150     static QMap<QString, QString> openedTextEditorsContents();
151     static QMap<QString, QTextCodec *> openedTextEditorsEncodings();
152
153 signals:
154     void contentsChanged();
155     void contentsChangedBecauseOfUndo();
156     void markRequested(TextEditor::ITextEditor *editor, int line);
157     void markContextMenuRequested(TextEditor::ITextEditor *editor, int line, QMenu *menu);
158     void tooltipOverrideRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position, bool *handled);
159     void tooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position);
160     void contextHelpIdRequested(TextEditor::ITextEditor *editor, int position);
161 };
162
163 } // namespace TextEditor
164
165 #endif // ITEXTEDITOR_H