TextEditor: Make BaseTextEditor reuse parts of *Widget interface

Change-Id: Ic93b2e14b22af26abf4a03b32c3ac0c22f88a63a
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
hjk
2014-09-03 08:35:58 +02:00
parent f1d823e070
commit 57d9d86418
2 changed files with 49 additions and 11 deletions

View File

@@ -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));