aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor/basetexteditor.cpp
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2014-09-03 08:35:58 +0200
committerhjk <hjk121@nokiamail.com>2014-09-03 08:43:16 +0200
commit57d9d86418f1eefe3f9bd13fcc3d735a1bdabea9 (patch)
treecc35ec61146e1475b0196a777dcdea6202c37b2b /src/plugins/texteditor/basetexteditor.cpp
parentf1d823e070168ddcee14434a0a38e17fe2660960 (diff)
TextEditor: Make BaseTextEditor reuse parts of *Widget interface
Change-Id: Ic93b2e14b22af26abf4a03b32c3ac0c22f88a63a Reviewed-by: hjk <hjk121@nokiamail.com>
Diffstat (limited to 'src/plugins/texteditor/basetexteditor.cpp')
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp52
1 files changed, 41 insertions, 11 deletions
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index bad40ae9d4..3d485eeb45 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -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));