Commit 57d9d864 authored by hjk's avatar hjk
Browse files

TextEditor: Make BaseTextEditor reuse parts of *Widget interface



Change-Id: Ic93b2e14b22af26abf4a03b32c3ac0c22f88a63a
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent f1d823e0
......@@ -2470,6 +2470,16 @@ int BaseTextEditorWidget::position(BaseTextEditor::PositionOperation posOp, int
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
{
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
{
QTextCursor tc = editorWidget()->textCursor();
if (pos >= 0)
tc.setPosition(pos);
QRect result = editorWidget()->cursorRect(tc);
result.moveTo(editorWidget()->viewport()->mapToGlobal(result.topLeft()));
return result;
return editorWidget()->cursorRect(pos);
}
QString BaseTextEditor::selectedText() const
......@@ -6647,7 +6652,12 @@ QString BaseTextEditor::selectedText() const
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.removeSelectedText();
}
......@@ -6659,17 +6669,27 @@ void BaseTextEditor::insert(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.insertText(string);
}
void BaseTextEditor::setCursorPosition(int pos)
{
editorWidget()->setBlockSelection(false);
QTextCursor tc = editorWidget()->textCursor();
editorWidget()->setCursorPosition(pos);
}
void BaseTextEditorWidget::setCursorPosition(int pos)
{
setBlockSelection(false);
QTextCursor tc = textCursor();
tc.setPosition(pos);
editorWidget()->setTextCursor(tc);
setTextCursor(tc);
}
void BaseTextEditor::select(int toPos)
......@@ -7064,6 +7084,16 @@ QString BaseTextEditor::textAt(int from, int to) const
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)
{
configureMimeType(MimeDatabase::findByType(mimeType));
......
......@@ -244,6 +244,9 @@ public:
int position(BaseTextEditor::PositionOperation posOp = BaseTextEditor::Current,
int at = -1) 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 *);
......@@ -571,6 +574,11 @@ public:
void setupAsPlainEditor();
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:
/*!
Reimplement this function to enable code navigation.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment