diff options
author | Dan Cape <dcape@qnx.com> | 2015-08-28 11:11:57 -0400 |
---|---|---|
committer | Dan Cape <dcape@qnx.com> | 2016-03-03 18:13:39 +0000 |
commit | 9456832163d3476e8f81440dd2978092a9000b72 (patch) | |
tree | e5ed5fd98d6d7d1a9d21760f43cc0f134302d809 /src/quick/items/qquicktextcontrol.cpp | |
parent | bf3de80424edf2b22c5f88a99c0bb18bffadfcf8 (diff) |
Add overwriteMode to QML TextEdit and QML TextInput
Overwrite mode was added to QML TextEdit and QML TextInput to match the
functionality provided by QTextEdit. Tests were updated as well to
ensure the mode functions as expected.
Task-number: QTBUG-26513
Change-Id: I1769159b298220107b09f9f13dc3af5f274715cc
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'src/quick/items/qquicktextcontrol.cpp')
-rw-r--r-- | src/quick/items/qquicktextcontrol.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index ab460034bb..127b51948a 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -44,6 +44,7 @@ #include <qcoreapplication.h> #include <qfont.h> +#include <qfontmetrics.h> #include <qevent.h> #include <qdebug.h> #include <qdrag.h> @@ -965,6 +966,14 @@ process: { QString text = e->text(); if (!text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'))) { + if (overwriteMode + // no need to call deleteChar() if we have a selection, insertText + // does it already + && !cursor.hasSelection() + && !cursor.atBlockEnd()) { + cursor.deleteChar(); + } + cursor.insertText(text); selectionChanged(); } else { @@ -1007,6 +1016,12 @@ QRectF QQuickTextControlPrivate::rectForPosition(int position) const if (line.isValid()) { qreal x = line.cursorToX(relativePos); qreal w = 0; + if (overwriteMode) { + if (relativePos < line.textLength() - line.textStart()) + w = line.cursorToX(relativePos + 1) - x; + else + w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw() + } r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(), textCursorWidth + w, line.height()); } else { r = QRectF(layoutPos.x(), layoutPos.y(), textCursorWidth, 10); // #### correct height @@ -1483,6 +1498,21 @@ bool QQuickTextControl::hasImState() const return d->hasImState; } +bool QQuickTextControl::overwriteMode() const +{ + Q_D(const QQuickTextControl); + return d->overwriteMode; +} + +void QQuickTextControl::setOverwriteMode(bool overwrite) +{ + Q_D(QQuickTextControl); + if (d->overwriteMode == overwrite) + return; + d->overwriteMode = overwrite; + emit overwriteModeChanged(overwrite); +} + bool QQuickTextControl::cursorVisible() const { Q_D(const QQuickTextControl); |