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 <coreplugin/editormanager/ieditor.h>
40 #include <QtCore/QObject>
41 #include <QtCore/QList>
42 #include <QtCore/QMap>
52 namespace TextEditor {
56 class TEXTEDITOR_EXPORT ITextMark : public QObject
60 ITextMark(QObject *parent = 0) : QObject(parent) {}
61 virtual ~ITextMark() {}
63 virtual QIcon icon() const = 0;
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;
70 // determine order on markers on the same line.
75 HighPriority // shown on top.
78 virtual Priority priority() const = 0;
81 typedef QList<ITextMark *> TextMarks;
84 class TEXTEDITOR_EXPORT ITextMarkable : public QObject
88 ITextMarkable(QObject *parent = 0) : QObject(parent) {}
89 virtual ~ITextMarkable() {}
90 virtual bool addMark(ITextMark *mark, int line) = 0;
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;
98 class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
102 enum PositionOperation {
111 virtual ~ITextEditor() {}
113 virtual int find(const QString &string) const = 0;
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;
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;
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;
137 virtual ITextMarkable *markableInterface() = 0;
139 virtual void setContextHelpId(const QString &) = 0;
141 enum TextCodecReason {
142 TextCodecOtherReason,
143 TextCodecFromSystemSetting,
144 TextCodecFromProjectSetting
147 virtual void setTextCodec(QTextCodec *, TextCodecReason reason = TextCodecOtherReason) = 0;
148 virtual QTextCodec *textCodec() const = 0;
150 static QMap<QString, QString> openedTextEditorsContents();
151 static QMap<QString, QTextCodec *> openedTextEditorsEncodings();
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);
163 } // namespace TextEditor
165 #endif // ITEXTEDITOR_H