2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#ifndef BASETEXTEDITOR_H
|
|
|
|
|
#define BASETEXTEDITOR_H
|
|
|
|
|
|
|
|
|
|
#include "itexteditable.h"
|
|
|
|
|
|
2009-05-29 16:12:19 +02:00
|
|
|
#include <find/ifindsupport.h>
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QPlainTextEdit>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QToolBar;
|
2009-10-01 16:38:08 +02:00
|
|
|
class QTimeLine;
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2009-10-05 11:06:05 +02:00
|
|
|
namespace Utils {
|
|
|
|
|
class LineColumnLabel;
|
2009-11-26 12:19:58 +01:00
|
|
|
class ChangeSet;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
class BaseTextEditorPrivate;
|
2009-11-25 15:55:45 +01:00
|
|
|
class TextEditorOverlay;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ITextMarkable;
|
|
|
|
|
|
|
|
|
|
class BaseTextDocument;
|
2010-04-26 14:02:09 +02:00
|
|
|
class BaseTextEditorEditable;
|
2008-12-02 12:01:29 +01:00
|
|
|
class FontSettings;
|
2009-12-08 17:37:40 +01:00
|
|
|
struct BehaviorSettings;
|
2009-12-08 17:43:01 +01:00
|
|
|
struct DisplaySettings;
|
2008-12-02 12:01:29 +01:00
|
|
|
struct StorageSettings;
|
2009-12-08 17:43:01 +01:00
|
|
|
struct TabSettings;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
|
2009-04-28 18:34:58 +02:00
|
|
|
class TEXTEDITOR_EXPORT BaseTextEditorAnimator : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
BaseTextEditorAnimator(QObject *parent);
|
|
|
|
|
|
2009-09-23 12:50:02 +02:00
|
|
|
inline void setPosition(int position) { m_position = position; }
|
|
|
|
|
inline int position() const { return m_position; }
|
2009-04-28 18:34:58 +02:00
|
|
|
|
|
|
|
|
void setData(QFont f, QPalette pal, const QString &text);
|
|
|
|
|
|
|
|
|
|
void draw(QPainter *p, const QPointF &pos);
|
|
|
|
|
QRectF rect() const;
|
|
|
|
|
|
2009-09-23 12:50:02 +02:00
|
|
|
inline qreal value() const { return m_value; }
|
|
|
|
|
inline QPointF lastDrawPos() const { return m_lastDrawPos; }
|
2009-04-28 18:34:58 +02:00
|
|
|
|
|
|
|
|
void finish();
|
|
|
|
|
|
2009-04-28 19:02:58 +02:00
|
|
|
bool isRunning() const;
|
|
|
|
|
|
2009-04-28 18:34:58 +02:00
|
|
|
signals:
|
2009-09-23 12:50:02 +02:00
|
|
|
void updateRequest(int position, QPointF lastPos, QRectF rect);
|
2009-04-28 18:34:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void step(qreal v);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QTimeLine *m_timeline;
|
|
|
|
|
qreal m_value;
|
|
|
|
|
int m_position;
|
2009-09-23 12:50:02 +02:00
|
|
|
QPointF m_lastDrawPos;
|
2009-04-28 18:34:58 +02:00
|
|
|
QFont m_font;
|
|
|
|
|
QPalette m_palette;
|
|
|
|
|
QString m_text;
|
|
|
|
|
QSizeF m_size;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2009-09-08 13:03:24 +02:00
|
|
|
class TEXTEDITOR_EXPORT BaseTextEditor : public QPlainTextEdit
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2010-04-12 20:49:40 +02:00
|
|
|
Q_PROPERTY(int verticalBlockSelection READ verticalBlockSelection)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
BaseTextEditor(QWidget *parent);
|
|
|
|
|
~BaseTextEditor();
|
|
|
|
|
|
2008-12-11 10:28:39 +01:00
|
|
|
static ITextEditor *openEditorAt(const QString &fileName, int line, int column = 0,
|
2010-03-10 12:48:53 +01:00
|
|
|
const QString &editorId = QString(),
|
|
|
|
|
bool *newEditor = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-26 12:19:58 +01:00
|
|
|
const Utils::ChangeSet &changeSet() const;
|
|
|
|
|
void setChangeSet(const Utils::ChangeSet &changeSet);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// EditorInterface
|
|
|
|
|
Core::IFile * file();
|
|
|
|
|
bool createNew(const QString &contents);
|
2010-02-26 11:08:17 +01:00
|
|
|
virtual bool open(const QString &fileName = QString());
|
2008-12-02 12:01:29 +01:00
|
|
|
QByteArray saveState() const;
|
|
|
|
|
bool restoreState(const QByteArray &state);
|
|
|
|
|
QString displayName() const;
|
|
|
|
|
|
|
|
|
|
// ITextEditor
|
|
|
|
|
|
2009-03-19 15:01:12 +01:00
|
|
|
void gotoLine(int line, int column = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
int position(
|
|
|
|
|
ITextEditor::PositionOperation posOp = ITextEditor::Current
|
|
|
|
|
, int at = -1) const;
|
|
|
|
|
void convertPosition(int pos, int *line, int *column) const;
|
|
|
|
|
|
2010-04-23 14:31:47 +02:00
|
|
|
BaseTextEditorEditable *editableInterface() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
ITextMarkable *markableInterface() const;
|
|
|
|
|
|
|
|
|
|
virtual void triggerCompletions();
|
2009-06-08 14:32:42 +02:00
|
|
|
virtual void triggerQuickFix();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QChar characterAt(int pos) const;
|
|
|
|
|
|
|
|
|
|
void print(QPrinter *);
|
|
|
|
|
|
|
|
|
|
void setSuggestedFileName(const QString &suggestedFileName);
|
|
|
|
|
QString mimeType() const;
|
|
|
|
|
void setMimeType(const QString &mt);
|
|
|
|
|
|
|
|
|
|
|
2009-11-02 14:02:18 +01:00
|
|
|
void appendStandardContextMenuActions(QMenu *menu);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Works only in conjunction with a syntax highlighter that puts
|
|
|
|
|
// parentheses into text block user data
|
|
|
|
|
void setParenthesesMatchingEnabled(bool b);
|
|
|
|
|
bool isParenthesesMatchingEnabled() const;
|
|
|
|
|
|
|
|
|
|
void setHighlightCurrentLine(bool b);
|
|
|
|
|
bool highlightCurrentLine() const;
|
|
|
|
|
|
|
|
|
|
void setLineNumbersVisible(bool b);
|
|
|
|
|
bool lineNumbersVisible() const;
|
|
|
|
|
|
2009-04-22 20:04:38 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void setMarksVisible(bool b);
|
|
|
|
|
bool marksVisible() const;
|
|
|
|
|
|
|
|
|
|
void setRequestMarkEnabled(bool b);
|
|
|
|
|
bool requestMarkEnabled() const;
|
|
|
|
|
|
|
|
|
|
void setLineSeparatorsAllowed(bool b);
|
|
|
|
|
bool lineSeparatorsAllowed() const;
|
|
|
|
|
|
|
|
|
|
void setCodeFoldingVisible(bool b);
|
|
|
|
|
bool codeFoldingVisible() const;
|
|
|
|
|
|
2009-03-16 17:23:50 +01:00
|
|
|
void setCodeFoldingSupported(bool b);
|
|
|
|
|
bool codeFoldingSupported() const;
|
|
|
|
|
|
2009-09-08 13:03:24 +02:00
|
|
|
void setMouseNavigationEnabled(bool b);
|
|
|
|
|
bool mouseNavigationEnabled() const;
|
|
|
|
|
|
2009-12-09 16:27:34 +01:00
|
|
|
void setScrollWheelZoomingEnabled(bool b);
|
|
|
|
|
bool scrollWheelZoomingEnabled() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void setRevisionsVisible(bool b);
|
|
|
|
|
bool revisionsVisible() const;
|
|
|
|
|
|
|
|
|
|
void setVisibleWrapColumn(int column);
|
|
|
|
|
int visibleWrapColumn() const;
|
|
|
|
|
|
|
|
|
|
void setActionHack(QObject *);
|
|
|
|
|
QObject *actionHack() const;
|
|
|
|
|
|
|
|
|
|
void setTextCodec(QTextCodec *codec);
|
|
|
|
|
QTextCodec *textCodec() const;
|
|
|
|
|
|
|
|
|
|
void setReadOnly(bool b);
|
|
|
|
|
|
2008-12-04 18:37:02 +01:00
|
|
|
void setTextCursor(const QTextCursor &cursor);
|
|
|
|
|
|
2010-03-29 16:44:27 +02:00
|
|
|
void insertCodeSnippet(const QTextCursor &cursor, const QString &snippet);
|
2010-01-19 16:36:48 +01:00
|
|
|
|
2010-04-12 20:49:40 +02:00
|
|
|
|
|
|
|
|
int verticalBlockSelection() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public slots:
|
|
|
|
|
void setDisplayName(const QString &title);
|
|
|
|
|
|
2009-12-03 18:35:36 +01:00
|
|
|
virtual void paste();
|
|
|
|
|
virtual void cut();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void zoomIn(int range = 1);
|
|
|
|
|
void zoomOut(int range = 1);
|
2009-11-30 19:00:36 +01:00
|
|
|
void zoomReset();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-14 17:24:35 +02:00
|
|
|
void cutLine();
|
2008-12-02 12:01:29 +01:00
|
|
|
void deleteLine();
|
|
|
|
|
void unCollapseAll();
|
|
|
|
|
void collapse();
|
|
|
|
|
void expand();
|
|
|
|
|
void selectEncoding();
|
|
|
|
|
|
2008-12-04 18:37:02 +01:00
|
|
|
void gotoBlockStart();
|
|
|
|
|
void gotoBlockEnd();
|
|
|
|
|
void gotoBlockStartWithSelection();
|
|
|
|
|
void gotoBlockEndWithSelection();
|
|
|
|
|
|
2008-12-04 19:25:20 +01:00
|
|
|
void selectBlockUp();
|
|
|
|
|
void selectBlockDown();
|
|
|
|
|
|
2008-12-10 18:01:33 +01:00
|
|
|
void moveLineUp();
|
|
|
|
|
void moveLineDown();
|
|
|
|
|
|
2009-05-15 23:17:11 +02:00
|
|
|
void copyLineUp();
|
|
|
|
|
void copyLineDown();
|
|
|
|
|
|
2010-01-20 17:51:05 +01:00
|
|
|
void joinLines();
|
2010-01-20 16:54:06 +01:00
|
|
|
|
2008-12-09 17:43:31 +01:00
|
|
|
void cleanWhitespace();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
|
|
// ITextEditor
|
|
|
|
|
void contentsChanged();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool event(QEvent *e);
|
|
|
|
|
void keyPressEvent(QKeyEvent *e);
|
|
|
|
|
void wheelEvent(QWheelEvent *e);
|
|
|
|
|
void changeEvent(QEvent *e);
|
2009-12-01 19:44:31 +01:00
|
|
|
void focusInEvent(QFocusEvent *e);
|
2009-11-30 19:13:20 +01:00
|
|
|
void focusOutEvent(QFocusEvent *e);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-06-17 19:12:19 +02:00
|
|
|
void showEvent(QShowEvent *);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// reimplemented to support block selection
|
|
|
|
|
QMimeData *createMimeDataFromSelection() const;
|
|
|
|
|
bool canInsertFromMimeData(const QMimeData *source) const;
|
|
|
|
|
void insertFromMimeData(const QMimeData *source);
|
|
|
|
|
|
2009-05-14 17:24:35 +02:00
|
|
|
private:
|
|
|
|
|
void maybeSelectLine();
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
|
|
|
|
void duplicateFrom(BaseTextEditor *editor);
|
2009-03-17 16:16:36 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
|
|
|
|
BaseTextDocument *baseTextDocument() const;
|
|
|
|
|
void setBaseTextDocument(BaseTextDocument *doc);
|
|
|
|
|
|
|
|
|
|
void setDefaultPath(const QString &defaultPath);
|
|
|
|
|
|
|
|
|
|
virtual BaseTextEditorEditable *createEditableInterface() = 0;
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void editorContentsChange(int position, int charsRemoved, int charsAdded);
|
|
|
|
|
void memorizeCursorPosition();
|
|
|
|
|
void restoreCursorPosition();
|
2009-05-29 16:12:19 +02:00
|
|
|
void highlightSearchResults(const QString &txt, Find::IFindSupport::FindFlags findFlags);
|
2010-04-13 12:06:26 +02:00
|
|
|
void setFindScope(const QTextCursor &start, const QTextCursor &end, int);
|
2008-12-02 12:01:29 +01:00
|
|
|
void currentEditorChanged(Core::IEditor *editor);
|
2010-04-08 12:30:38 +02:00
|
|
|
void maybeEmitContentsChangedBecauseOfUndo();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Internal::BaseTextEditorPrivate *d;
|
|
|
|
|
friend class Internal::BaseTextEditorPrivate;
|
2009-11-25 15:55:45 +01:00
|
|
|
friend class Internal::TextEditorOverlay;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
QWidget *extraArea() const;
|
|
|
|
|
virtual int extraAreaWidth(int *markWidthPtr = 0) const;
|
|
|
|
|
virtual void extraAreaPaintEvent(QPaintEvent *);
|
|
|
|
|
virtual void extraAreaLeaveEvent(QEvent *);
|
2009-03-17 16:16:36 +01:00
|
|
|
virtual void extraAreaMouseEvent(QMouseEvent *);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
const TabSettings &tabSettings() const;
|
|
|
|
|
const DisplaySettings &displaySettings() const;
|
|
|
|
|
|
|
|
|
|
void markBlocksAsChanged(QList<int> blockNumbers);
|
|
|
|
|
|
|
|
|
|
void ensureCursorVisible();
|
|
|
|
|
|
2008-12-05 13:19:57 +01:00
|
|
|
enum ExtraSelectionKind {
|
|
|
|
|
CurrentLineSelection,
|
|
|
|
|
ParenthesesMatchingSelection,
|
|
|
|
|
CodeWarningsSelection,
|
|
|
|
|
CodeSemanticsSelection,
|
2009-11-30 15:21:16 +01:00
|
|
|
UnusedSymbolSelection,
|
2009-01-13 13:08:21 +01:00
|
|
|
FakeVimSelection,
|
2009-11-30 15:21:16 +01:00
|
|
|
OtherSelection,
|
2010-01-19 12:28:50 +01:00
|
|
|
SnippetPlaceholderSelection,
|
2008-12-05 13:19:57 +01:00
|
|
|
NExtraSelectionKinds
|
|
|
|
|
};
|
|
|
|
|
void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
|
|
|
|
|
QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
|
2009-11-30 17:23:31 +01:00
|
|
|
QString extraSelectionTooltip(int pos) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-23 18:21:36 +01:00
|
|
|
struct BlockRange
|
|
|
|
|
{
|
|
|
|
|
BlockRange() : first(0), last(-1) {}
|
|
|
|
|
BlockRange(int first_position, int last_position)
|
|
|
|
|
: first(first_position), last(last_position)
|
|
|
|
|
{}
|
2008-12-02 12:01:29 +01:00
|
|
|
int first;
|
|
|
|
|
int last;
|
|
|
|
|
inline bool isNull() const { return last < first; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// the blocks list must be sorted
|
2009-01-23 19:13:00 +01:00
|
|
|
void setIfdefedOutBlocks(const QList<BlockRange> &blocks);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public slots:
|
2009-03-17 16:16:36 +01:00
|
|
|
virtual void format();
|
2009-07-21 10:37:00 +02:00
|
|
|
virtual void rewrapParagraph();
|
2009-03-17 16:16:36 +01:00
|
|
|
virtual void unCommentSelection();
|
|
|
|
|
virtual void setFontSettings(const TextEditor::FontSettings &);
|
2009-06-17 19:12:19 +02:00
|
|
|
void setFontSettingsIfVisible(const TextEditor::FontSettings &);
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual void setTabSettings(const TextEditor::TabSettings &);
|
|
|
|
|
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
|
2009-12-08 17:37:40 +01:00
|
|
|
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
|
2009-03-17 16:16:36 +01:00
|
|
|
virtual void setStorageSettings(const TextEditor::StorageSettings &);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool viewportEvent(QEvent *event);
|
|
|
|
|
|
|
|
|
|
void resizeEvent(QResizeEvent *);
|
|
|
|
|
void paintEvent(QPaintEvent *);
|
|
|
|
|
void timerEvent(QTimerEvent *);
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *);
|
|
|
|
|
void mousePressEvent(QMouseEvent *);
|
2009-09-08 13:03:24 +02:00
|
|
|
void mouseReleaseEvent(QMouseEvent *);
|
|
|
|
|
void leaveEvent(QEvent *);
|
|
|
|
|
void keyReleaseEvent(QKeyEvent *);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-02-19 11:25:30 +01:00
|
|
|
void dragEnterEvent(QDragEnterEvent *e);
|
|
|
|
|
|
2010-01-06 14:57:45 +01:00
|
|
|
public:
|
2009-09-08 13:03:24 +02:00
|
|
|
// Returns true if key triggers an indent.
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual bool isElectricCharacter(const QChar &ch) const;
|
2010-02-03 16:34:54 +01:00
|
|
|
|
|
|
|
|
void indentInsertedText(const QTextCursor &tc);
|
|
|
|
|
|
2010-01-06 14:57:45 +01:00
|
|
|
protected:
|
2009-09-17 12:36:40 +02:00
|
|
|
// Returns the text to complete at the cursor position, or an empty string
|
|
|
|
|
virtual QString autoComplete(QTextCursor &cursor, const QString &text) const;
|
|
|
|
|
// Handles backspace. When returning true, backspace processing is stopped
|
|
|
|
|
virtual bool autoBackspace(QTextCursor &cursor);
|
2009-09-17 12:47:16 +02:00
|
|
|
// Hook to insert special characters on enter. Returns the number of extra blocks inserted.
|
|
|
|
|
virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
|
2008-12-02 12:01:29 +01:00
|
|
|
// Indent a text block based on previous line. Default does nothing
|
|
|
|
|
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
|
|
|
|
|
// Indent at cursor. Calls indentBlock for selection or current line.
|
|
|
|
|
virtual void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
|
2009-09-29 12:44:00 +02:00
|
|
|
// Reindent at cursor. Selection will be adjusted according to the indentation change of the first block
|
|
|
|
|
virtual void reindent(QTextDocument *doc, const QTextCursor &cursor);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-01-12 12:56:21 +01:00
|
|
|
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
|
|
|
|
|
|
|
|
|
|
// Returns true if the cursor is inside a comment.
|
|
|
|
|
virtual bool isInComment(const QTextCursor &cursor) const;
|
|
|
|
|
|
|
|
|
|
virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, const QChar &la, int *skippedChars) const;
|
|
|
|
|
|
|
|
|
|
// Returns the text that needs to be inserted
|
|
|
|
|
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
|
|
|
|
|
|
|
|
|
|
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen);
|
|
|
|
|
|
|
|
|
|
static void countBrackets(QTextCursor cursor, int from, int end, QChar open, QChar close,
|
|
|
|
|
int *errors, int *stillopen);
|
|
|
|
|
|
2009-09-08 13:03:24 +02:00
|
|
|
struct Link
|
|
|
|
|
{
|
|
|
|
|
Link(const QString &fileName = QString(),
|
|
|
|
|
int line = 0,
|
|
|
|
|
int column = 0)
|
2010-02-01 16:13:21 +01:00
|
|
|
: begin(-1)
|
|
|
|
|
, end(-1)
|
2009-09-08 13:03:24 +02:00
|
|
|
, fileName(fileName)
|
|
|
|
|
, line(line)
|
|
|
|
|
, column(column)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool isValid() const
|
2010-02-01 16:13:21 +01:00
|
|
|
{ return begin != end; }
|
2009-09-08 13:03:24 +02:00
|
|
|
|
2009-11-03 14:29:49 +01:00
|
|
|
bool operator==(const Link &other) const
|
2010-02-01 16:13:21 +01:00
|
|
|
{ return begin == other.begin && end == other.end; }
|
2009-11-03 14:29:49 +01:00
|
|
|
|
2010-02-01 16:13:21 +01:00
|
|
|
int begin; // Link position
|
|
|
|
|
int end; // Link end position
|
2009-09-08 13:03:24 +02:00
|
|
|
|
|
|
|
|
QString fileName; // Target file
|
|
|
|
|
int line; // Target line
|
|
|
|
|
int column; // Target column
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Reimplement this function to enable code navigation.
|
|
|
|
|
|
|
|
|
|
\a resolveTarget is set to true when the target of the link is relevant
|
|
|
|
|
(it isn't until the link is used).
|
|
|
|
|
*/
|
|
|
|
|
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Reimplement this function if you want to customize the way a link is
|
2010-01-11 10:22:55 +01:00
|
|
|
opened. Returns whether the link was opened successfully.
|
2009-09-08 13:03:24 +02:00
|
|
|
*/
|
|
|
|
|
virtual bool openLink(const Link &link);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected slots:
|
|
|
|
|
virtual void slotUpdateExtraAreaWidth();
|
|
|
|
|
virtual void slotModificationChanged(bool);
|
|
|
|
|
virtual void slotUpdateRequest(const QRect &r, int dy);
|
|
|
|
|
virtual void slotCursorPositionChanged();
|
|
|
|
|
virtual void slotUpdateBlockNotify(const QTextBlock &);
|
|
|
|
|
|
|
|
|
|
signals:
|
2009-11-30 19:00:36 +01:00
|
|
|
void requestFontZoom(int zoom);
|
|
|
|
|
void requestZoomReset();
|
2008-12-02 12:01:29 +01:00
|
|
|
void requestBlockUpdate(const QTextBlock &);
|
2009-11-18 15:06:26 +01:00
|
|
|
void requestAutoCompletion(TextEditor::ITextEditable *editor, bool forced);
|
|
|
|
|
void requestQuickFix(TextEditor::ITextEditable *editor);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void indentOrUnindent(bool doIndent);
|
|
|
|
|
void handleHomeKey(bool anchor);
|
|
|
|
|
void handleBackspaceKey();
|
2008-12-10 18:01:33 +01:00
|
|
|
void moveLineUpDown(bool up);
|
2009-05-15 23:17:11 +02:00
|
|
|
void copyLineUpDown(bool up);
|
2009-03-19 14:18:26 +01:00
|
|
|
void saveCurrentCursorPositionForNavigation();
|
2010-02-08 16:54:14 +01:00
|
|
|
void updateHighlights();
|
2009-07-15 16:10:15 +02:00
|
|
|
void updateCurrentLineHighlight();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-05 10:20:43 +02:00
|
|
|
void drawFoldingMarker(QPainter *painter, const QPalette &pal,
|
|
|
|
|
const QRect &rect,
|
|
|
|
|
bool expanded,
|
|
|
|
|
bool active,
|
|
|
|
|
bool hovered) const;
|
2009-05-04 11:10:22 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void toggleBlockVisible(const QTextBlock &block);
|
2009-04-24 16:44:48 +02:00
|
|
|
QRect collapseBox();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QTextBlock collapsedBlockAt(const QPoint &pos, QRect *box = 0) const;
|
|
|
|
|
|
2009-11-03 14:29:49 +01:00
|
|
|
void updateLink(QMouseEvent *e);
|
2009-09-08 13:03:24 +02:00
|
|
|
void showLink(const Link &);
|
|
|
|
|
void clearLink();
|
2009-06-17 19:12:19 +02:00
|
|
|
|
2010-01-19 12:28:50 +01:00
|
|
|
void universalHelper(); // test function for development
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// parentheses matcher
|
|
|
|
|
private slots:
|
|
|
|
|
void _q_matchParentheses();
|
2009-04-23 17:28:53 +02:00
|
|
|
void _q_highlightBlocks();
|
2008-12-02 12:01:29 +01:00
|
|
|
void slotSelectionChanged();
|
2009-09-23 12:50:02 +02:00
|
|
|
void _q_animateUpdate(int position, QPointF lastPos, QRectF rect);
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2010-04-26 14:02:09 +02:00
|
|
|
class TEXTEDITOR_EXPORT BaseTextEditorEditable : public ITextEditable
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
friend class BaseTextEditor;
|
|
|
|
|
public:
|
|
|
|
|
BaseTextEditorEditable(BaseTextEditor *editor);
|
|
|
|
|
~BaseTextEditorEditable();
|
|
|
|
|
|
|
|
|
|
inline BaseTextEditor *editor() const { return e; }
|
|
|
|
|
|
|
|
|
|
// EditorInterface
|
|
|
|
|
inline QWidget *widget() { return e; }
|
|
|
|
|
inline Core::IFile * file() { return e->file(); }
|
|
|
|
|
inline bool createNew(const QString &contents) { return e->createNew(contents); }
|
|
|
|
|
inline bool open(const QString &fileName = QString())
|
|
|
|
|
{
|
|
|
|
|
return e->open(fileName);
|
|
|
|
|
}
|
|
|
|
|
inline QString displayName() const { return e->displayName(); }
|
|
|
|
|
inline void setDisplayName(const QString &title) { e->setDisplayName(title); }
|
|
|
|
|
|
|
|
|
|
inline QByteArray saveState() const { return e->saveState(); }
|
|
|
|
|
inline bool restoreState(const QByteArray &state) { return e->restoreState(state); }
|
2009-07-15 16:23:07 +02:00
|
|
|
QWidget *toolBar();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// ITextEditor
|
|
|
|
|
int find(const QString &string) const;
|
|
|
|
|
|
|
|
|
|
int currentLine() const;
|
|
|
|
|
int currentColumn() const;
|
2009-03-19 14:18:26 +01:00
|
|
|
void gotoLine(int line, int column = 0) { e->gotoLine(line, column); }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
inline int position(
|
|
|
|
|
ITextEditor::PositionOperation posOp = ITextEditor::Current
|
|
|
|
|
, int at = -1) const { return e->position(posOp, at); }
|
|
|
|
|
inline void convertPosition(int pos, int *line, int *column) const { e->convertPosition(pos, line, column); }
|
|
|
|
|
QRect cursorRect(int pos = -1) const;
|
|
|
|
|
|
|
|
|
|
QString contents() const;
|
|
|
|
|
QString selectedText() const;
|
|
|
|
|
QString textAt(int pos, int length) const;
|
|
|
|
|
inline QChar characterAt(int pos) const { return e->characterAt(pos); }
|
|
|
|
|
|
|
|
|
|
inline void triggerCompletions() { e->triggerCompletions(); } // slot?
|
2009-06-08 14:32:42 +02:00
|
|
|
inline void triggerQuickFix() { e->triggerQuickFix(); } // slot?
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
inline ITextMarkable *markableInterface() { return e->markableInterface(); }
|
|
|
|
|
|
|
|
|
|
void setContextHelpId(const QString &id) { m_contextHelpId = id; }
|
|
|
|
|
QString contextHelpId() const; // from IContext
|
|
|
|
|
|
|
|
|
|
inline void setTextCodec(QTextCodec *codec) { e->setTextCodec(codec); }
|
|
|
|
|
inline QTextCodec *textCodec() const { return e->textCodec(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ITextEditable
|
|
|
|
|
void remove(int length);
|
|
|
|
|
void insert(const QString &string);
|
|
|
|
|
void replace(int length, const QString &string);
|
|
|
|
|
void setCurPos(int pos);
|
|
|
|
|
void select(int toPos);
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void updateCursorPosition();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
BaseTextEditor *e;
|
|
|
|
|
mutable QString m_contextHelpId;
|
|
|
|
|
QToolBar *m_toolBar;
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::LineColumnLabel *m_cursorPositionLabel;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|
|
|
|
|
|
|
|
|
|
#endif // BASETEXTEDITOR_H
|