1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
37 #include "texteditor_global.h"
39 #include <coreplugin/editormanager/ieditor.h>
41 #include <QtCore/QObject>
42 #include <QtCore/QList>
43 #include <QtCore/QMap>
53 namespace TextEditor {
57 class TEXTEDITOR_EXPORT ITextMark : public QObject
61 ITextMark(QObject *parent = 0) : QObject(parent) {}
62 virtual ~ITextMark() {}
64 virtual QIcon icon() const = 0;
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;
71 // determine order on markers on the same line.
76 HighPriority // shown on top.
79 virtual Priority priority() const = 0;
82 typedef QList<ITextMark *> TextMarks;
85 class TEXTEDITOR_EXPORT ITextMarkable : public QObject
89 ITextMarkable(QObject *parent = 0) : QObject(parent) {}
90 virtual ~ITextMarkable() {}
91 virtual bool addMark(ITextMark *mark, int line) = 0;
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;
99 class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
103 enum PositionOperation {
112 virtual ~ITextEditor() {}
114 virtual int find(const QString &string) const = 0;
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;
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;
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;
138 virtual ITextMarkable *markableInterface() = 0;
140 virtual void setContextHelpId(const QString &) = 0;
142 enum TextCodecReason {
143 TextCodecOtherReason,
144 TextCodecFromSystemSetting,
145 TextCodecFromProjectSetting
148 virtual void setTextCodec(QTextCodec *, TextCodecReason reason = TextCodecOtherReason) = 0;
149 virtual QTextCodec *textCodec() const = 0;
151 static QMap<QString, QString> openedTextEditorsContents();
152 static QMap<QString, QTextCodec *> openedTextEditorsEncodings();
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);
164 } // namespace TextEditor
166 #endif // ITEXTEDITOR_H