itexteditor.h 5.24 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30 31 32 33 34
#ifndef ITEXTEDITOR_H
#define ITEXTEDITOR_H

#include "texteditor_global.h"

35 36
#include "itextmark.h"

37
#include <coreplugin/textdocument.h>
38
#include <coreplugin/editormanager/editormanager.h>
con's avatar
con committed
39 40
#include <coreplugin/editormanager/ieditor.h>

41 42
#include <QMap>
#include <QIcon>
con's avatar
con committed
43 44

QT_BEGIN_NAMESPACE
45
class QIcon;
46 47
class QMenu;
class QPainter;
48
class QPoint;
49 50
class QRect;
class QTextBlock;
con's avatar
con committed
51 52
QT_END_NAMESPACE

53 54 55 56
namespace Utils {
    class CommentDefinition;
}

con's avatar
con committed
57 58
namespace TextEditor {

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
class TEXTEDITOR_EXPORT BlockRange
{
public:
    BlockRange() : _first(0), _last(-1) {}
    BlockRange(int firstPosition, int lastPosition)
      : _first(firstPosition), _last(lastPosition)
    {}

    inline bool isNull() const { return _last < _first; }

    int first() const { return _first; }
    int last() const { return _last; }

private:
    int _first;
    int _last;
};


78 79 80 81 82 83
class TEXTEDITOR_EXPORT ITextEditorDocument : public Core::TextDocument
{
    Q_OBJECT
public:
    explicit ITextEditorDocument(QObject *parent = 0);

84
    virtual QString plainText() const = 0;
85 86
    virtual QString textAt(int pos, int length) const = 0;
    virtual QChar characterAt(int pos) const = 0;
87 88

    virtual ITextMarkable *markableInterface() const = 0;
89 90
};

con's avatar
con committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104
class TEXTEDITOR_EXPORT ITextEditor : public Core::IEditor
{
    Q_OBJECT
public:
    enum PositionOperation {
        Current = 1,
        EndOfLine = 2,
        StartOfLine = 3,
        Anchor = 4,
        EndOfDoc = 5
    };

    ITextEditor() {}

105 106
    virtual ITextEditorDocument *textDocument();

107
    /*! Returns the position at \a posOp in characters from the beginning of the document */
con's avatar
con committed
108
    virtual int position(PositionOperation posOp = Current, int at = -1) const = 0;
109
    /*! Converts the \a pos in characters from beginning of document to \a line and \a column */
con's avatar
con committed
110
    virtual void convertPosition(int pos, int *line, int *column) const = 0;
111
    /*! Returns the cursor rectangle in pixels at \a pos, or current position if \a pos = -1 */
con's avatar
con committed
112
    virtual QRect cursorRect(int pos = -1) const = 0;
113
    /*! Returns the amount of visible columns (in characters) in the editor */
114
    virtual int columnCount() const = 0;
115
    /*! Returns the amount of visible lines (in characters) in the editor */
116
    virtual int rowCount() const = 0;
con's avatar
con committed
117 118 119

    virtual QString selectedText() const = 0;

120 121 122 123 124 125 126 127 128 129 130
    /*! Removes \a length characters to the right of the cursor. */
    virtual void remove(int length) = 0;
    /*! Inserts the given string to the right of the cursor. */
    virtual void insert(const QString &string) = 0;
    /*! Replaces \a length characters to the right of the cursor with the given string. */
    virtual void replace(int length, const QString &string) = 0;
    /*! Sets current cursor position to \a pos. */
    virtual void setCursorPosition(int pos) = 0;
    /*! Selects text between current cursor position and \a toPos. */
    virtual void select(int toPos) = 0;

131 132
    virtual const Utils::CommentDefinition* commentDefinition() const = 0;

133 134
    static QMap<QString, QString> openedTextDocumentContents();
    static QMap<QString, QTextCodec *> openedTextDocumentEncodings();
con's avatar
con committed
135

136 137
    enum MarkRequestKind {
        BreakpointRequest,
138 139
        BookmarkRequest,
        TaskMarkRequest
140 141
    };

con's avatar
con committed
142 143
signals:
    void contentsChanged();
144
    void markRequested(TextEditor::ITextEditor *editor, int line, TextEditor::ITextEditor::MarkRequestKind kind);
145
    void markContextMenuRequested(TextEditor::ITextEditor *editor, int line, QMenu *menu);
146
    void tooltipOverrideRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position, bool *handled);
con's avatar
con committed
147
    void tooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int position);
148
    void markTooltipRequested(TextEditor::ITextEditor *editor, const QPoint &globalPos, int line);
con's avatar
con committed
149 150 151 152 153 154
    void contextHelpIdRequested(TextEditor::ITextEditor *editor, int position);
};

} // namespace TextEditor

#endif // ITEXTEDITOR_H