OSDN Git Service

ca2d667577dfc8b60a50f9722100b21b4d2b2b89
[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 (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef ITEXTEDITOR_H
35 #define ITEXTEDITOR_H
36
37 #include "texteditor_global.h"
38
39 #include <coreplugin/editormanager/ieditor.h>
40
41 #include <QtCore/QObject>
42 #include <QtCore/QList>
43 #include <QtCore/QMap>
44
45 QT_BEGIN_NAMESPACE
46 class QMenu;
47 class QTextBlock;
48 class QIcon;
49 class QRect;
50 class QPoint;
51 QT_END_NAMESPACE
52
53 namespace TextEditor {
54
55 class ITextEditor;
56
57 class TEXTEDITOR_EXPORT ITextMark : public QObject
58 {
59     Q_OBJECT
60 public:
61     ITextMark(QObject *parent = 0) : QObject(parent) {}
62     virtual ~ITextMark() {}
63
64     virtual QIcon icon() const = 0;
65
66     virtual void updateLineNumber(int lineNumber) = 0;
67     virtual void updateBlock(const QTextBlock &block) = 0;
68     virtual void removedFromEditor() = 0;
69     virtual void documentClosing() = 0;
70
71     // determine order on markers on the same line.
72     enum Priority
73     {
74         LowPriority,
75         NormalPriority,
76         HighPriority // shown on top.
77     };
78
79     virtual Priority priority() const = 0;
80 };
81
82 typedef QList<ITextMark *> TextMarks;
83
84
85 class TEXTEDITOR_EXPORT ITextMarkable : public QObject
86 {
87     Q_OBJECT
88 public:
89     ITextMarkable(QObject *parent = 0) : QObject(parent) {}
90     virtual ~ITextMarkable() {}
91     virtual bool addMark(ITextMark *mark, int line) = 0;
92
93     virtual TextMarks marksAt(int line) const = 0;
94     virtual void removeMark(ITextMark *mark) = 0;
95     virtual bool hasMark(ITextMark *mark) const = 0;
96     virtual void updateMark(ITextMark *mark) = 0;
97 };
98
99 class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
100 {
101     Q_OBJECT
102 public:
103     enum PositionOperation {
104         Current = 1,
105         EndOfLine = 2,
106         StartOfLine = 3,
107         Anchor = 4,
108         EndOfDoc = 5
109     };
110
111     ITextEditor() {}
112     virtual ~ITextEditor() {}
113
114     virtual int find(const QString &string) const = 0;
115
116     virtual int position(PositionOperation posOp = Current, int at = -1) const = 0;
117     virtual void convertPosition(int pos, int *line, int *column) const = 0;
118     virtual QRect cursorRect(int pos = -1) const = 0;
119     virtual int columnCount() const = 0;
120     virtual int rowCount() const = 0;
121
122     virtual QString contents() const = 0;
123     virtual QString selectedText() const = 0;
124     virtual QString textAt(int pos, int length) const = 0;
125     virtual QChar characterAt(int pos) const = 0;
126
127     /*! Removes \a length characters to the right of the cursor. */
128     virtual void remove(int length) = 0;
129     /*! Inserts the given string to the right of the cursor. */
130     virtual void insert(const QString &string) = 0;
131     /*! Replaces \a length characters to the right of the cursor with the given string. */
132     virtual void replace(int length, const QString &string) = 0;
133     /*! Sets current cursor position to \a pos. */
134     virtual void setCursorPosition(int pos) = 0;
135     /*! Selects text between current cursor position and \a toPos. */
136     virtual void select(int toPos) = 0;
137
138     virtual ITextMarkable *markableInterface() = 0;
139
140     virtual void setContextHelpId(const QString &) = 0;
141
142     enum TextCodecReason {
143         TextCodecOtherReason,
144         TextCodecFromSystemSetting,
145         TextCodecFromProjectSetting
146     };
147
148     virtual void setTextCodec(QTextCodec *, TextCodecReason reason = TextCodecOtherReason) = 0;
149     virtual QTextCodec *textCodec() const = 0;
150
151     static QMap<QString, QString> openedTextEditorsContents();
152     static QMap<QString, QTextCodec *> openedTextEditorsEncodings();
153
154 signals:
155     void contentsChanged();
156     void contentsChangedBecauseOfUndo();
157     void markRequested(TextEditor::ITextEditor *editor, int line);
158     void markContextMenuRequested(TextEditor::ITextEditor *editor, int line, QMenu *menu);
159     void tooltipOverrideRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position, bool *handled);
160     void tooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position);
161     void contextHelpIdRequested(TextEditor::ITextEditor *editor, int position);
162 };
163
164 } // namespace TextEditor
165
166 #endif // ITEXTEDITOR_H