forked from qt-creator/qt-creator
TextEditor: Make BaseTextEditor reuse parts of *Widget interface
Change-Id: Ic93b2e14b22af26abf4a03b32c3ac0c22f88a63a Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -2470,6 +2470,16 @@ int BaseTextEditorWidget::position(BaseTextEditor::PositionOperation posOp, int
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect BaseTextEditorWidget::cursorRect(int pos) const
|
||||||
|
{
|
||||||
|
QTextCursor tc = textCursor();
|
||||||
|
if (pos >= 0)
|
||||||
|
tc.setPosition(pos);
|
||||||
|
QRect result = cursorRect(tc);
|
||||||
|
result.moveTo(viewport()->mapToGlobal(result.topLeft()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::convertPosition(int pos, int *line, int *column) const
|
void BaseTextEditorWidget::convertPosition(int pos, int *line, int *column) const
|
||||||
{
|
{
|
||||||
Convenience::convertPosition(document(), pos, line, column);
|
Convenience::convertPosition(document(), pos, line, column);
|
||||||
@@ -6632,12 +6642,7 @@ void BaseTextEditor::convertPosition(int pos, int *line, int *column) const
|
|||||||
|
|
||||||
QRect BaseTextEditor::cursorRect(int pos) const
|
QRect BaseTextEditor::cursorRect(int pos) const
|
||||||
{
|
{
|
||||||
QTextCursor tc = editorWidget()->textCursor();
|
return editorWidget()->cursorRect(pos);
|
||||||
if (pos >= 0)
|
|
||||||
tc.setPosition(pos);
|
|
||||||
QRect result = editorWidget()->cursorRect(tc);
|
|
||||||
result.moveTo(editorWidget()->viewport()->mapToGlobal(result.topLeft()));
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString BaseTextEditor::selectedText() const
|
QString BaseTextEditor::selectedText() const
|
||||||
@@ -6647,7 +6652,12 @@ QString BaseTextEditor::selectedText() const
|
|||||||
|
|
||||||
void BaseTextEditor::remove(int length)
|
void BaseTextEditor::remove(int length)
|
||||||
{
|
{
|
||||||
QTextCursor tc = editorWidget()->textCursor();
|
editorWidget()->remove(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditorWidget::remove(int length)
|
||||||
|
{
|
||||||
|
QTextCursor tc = textCursor();
|
||||||
tc.setPosition(tc.position() + length, QTextCursor::KeepAnchor);
|
tc.setPosition(tc.position() + length, QTextCursor::KeepAnchor);
|
||||||
tc.removeSelectedText();
|
tc.removeSelectedText();
|
||||||
}
|
}
|
||||||
@@ -6659,17 +6669,27 @@ void BaseTextEditor::insert(const QString &string)
|
|||||||
|
|
||||||
void BaseTextEditor::replace(int length, const QString &string)
|
void BaseTextEditor::replace(int length, const QString &string)
|
||||||
{
|
{
|
||||||
QTextCursor tc = editorWidget()->textCursor();
|
editorWidget()->replace(length, string);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditorWidget::replace(int length, const QString &string)
|
||||||
|
{
|
||||||
|
QTextCursor tc = textCursor();
|
||||||
tc.setPosition(tc.position() + length, QTextCursor::KeepAnchor);
|
tc.setPosition(tc.position() + length, QTextCursor::KeepAnchor);
|
||||||
tc.insertText(string);
|
tc.insertText(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditor::setCursorPosition(int pos)
|
void BaseTextEditor::setCursorPosition(int pos)
|
||||||
{
|
{
|
||||||
editorWidget()->setBlockSelection(false);
|
editorWidget()->setCursorPosition(pos);
|
||||||
QTextCursor tc = editorWidget()->textCursor();
|
}
|
||||||
|
|
||||||
|
void BaseTextEditorWidget::setCursorPosition(int pos)
|
||||||
|
{
|
||||||
|
setBlockSelection(false);
|
||||||
|
QTextCursor tc = textCursor();
|
||||||
tc.setPosition(pos);
|
tc.setPosition(pos);
|
||||||
editorWidget()->setTextCursor(tc);
|
setTextCursor(tc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextEditor::select(int toPos)
|
void BaseTextEditor::select(int toPos)
|
||||||
@@ -7064,6 +7084,16 @@ QString BaseTextEditor::textAt(int from, int to) const
|
|||||||
return textDocument()->textAt(from, to);
|
return textDocument()->textAt(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QChar BaseTextEditorWidget::characterAt(int pos) const
|
||||||
|
{
|
||||||
|
return textDocument()->characterAt(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BaseTextEditorWidget::textAt(int from, int to) const
|
||||||
|
{
|
||||||
|
return textDocument()->textAt(from, to);
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditorWidget::configureMimeType(const QString &mimeType)
|
void BaseTextEditorWidget::configureMimeType(const QString &mimeType)
|
||||||
{
|
{
|
||||||
configureMimeType(MimeDatabase::findByType(mimeType));
|
configureMimeType(MimeDatabase::findByType(mimeType));
|
||||||
|
|||||||
@@ -244,6 +244,9 @@ public:
|
|||||||
int position(BaseTextEditor::PositionOperation posOp = BaseTextEditor::Current,
|
int position(BaseTextEditor::PositionOperation posOp = BaseTextEditor::Current,
|
||||||
int at = -1) const;
|
int at = -1) const;
|
||||||
void convertPosition(int pos, int *line, int *column) const;
|
void convertPosition(int pos, int *line, int *column) const;
|
||||||
|
using QPlainTextEdit::cursorRect;
|
||||||
|
QRect cursorRect(int pos) const;
|
||||||
|
void setCursorPosition(int pos);
|
||||||
|
|
||||||
void print(QPrinter *);
|
void print(QPrinter *);
|
||||||
|
|
||||||
@@ -571,6 +574,11 @@ public:
|
|||||||
void setupAsPlainEditor();
|
void setupAsPlainEditor();
|
||||||
void setupFallBackEditor(Core::Id id);
|
void setupFallBackEditor(Core::Id id);
|
||||||
|
|
||||||
|
void remove(int length);
|
||||||
|
void replace(int length, const QString &string);
|
||||||
|
QChar characterAt(int pos) const;
|
||||||
|
QString textAt(int from, int to) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*!
|
/*!
|
||||||
Reimplement this function to enable code navigation.
|
Reimplement this function to enable code navigation.
|
||||||
|
|||||||
Reference in New Issue
Block a user