aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>2010-12-13 11:22:02 +0200
committerPekka Vuorela <pekka.ta.vuorela@nokia.com>2010-12-13 11:30:07 +0200
commit7af002f49a93fd0290c864a306bee876d74117e1 (patch)
treecd577a8c6c6676f8421e00bd8ab2e50994a755fe
parenta224ad495f958d538ed48df7c4c33bd7d8207608 (diff)
Revert "Fixes: NB#188610 Masked texts are revealed when character is entered from HKB"
This reverts commit 5b71322e01af5346f02f32971d92943ee6b9d633.
-rwxr-xr-xsrc/corelib/widgets/mtextedit.cpp40
-rw-r--r--src/corelib/widgets/mtexteditmodel.h18
-rw-r--r--src/views/mtexteditview.cpp13
3 files changed, 21 insertions, 50 deletions
diff --git a/src/corelib/widgets/mtextedit.cpp b/src/corelib/widgets/mtextedit.cpp
index c8d1aba1..44eaf3a4 100755
--- a/src/corelib/widgets/mtextedit.cpp
+++ b/src/corelib/widgets/mtextedit.cpp
@@ -716,8 +716,9 @@ void MTextEditPrivate::setPreeditText(const QString &text,
int preeditTextLength = text.count();
QTextBlock block = textCursor->block();
+ QTextLayout *layout = block.layout();
- QList<MTextEditFormatRange> additionalFormats;
+ QList<QTextLayout::FormatRange> preeditStyles;
// set preeditCursor to -1 to hide cursor for preedit by default
int preeditCursor = -1;
@@ -729,11 +730,11 @@ void MTextEditPrivate::setPreeditText(const QString &text,
const QTextCharFormat format = attribute.value.value<QTextFormat>().toCharFormat();
if (format.isValid()) {
- MTextEditFormatRange formatRange;
- formatRange.start = attribute.start + textCursor->position() - block.position();
- formatRange.length = attribute.length;
- formatRange.format = format;
- additionalFormats.append(formatRange);
+ QTextLayout::FormatRange style;
+ style.start = attribute.start + textCursor->position() - block.position();
+ style.length = attribute.length;
+ style.format = format;
+ preeditStyles.append(style);
}
} else if (attribute.type == QInputMethodEvent::Cursor) {
if (attribute.length > 0) {
@@ -744,19 +745,18 @@ void MTextEditPrivate::setPreeditText(const QString &text,
}
q->model()->setPreeditCursor(preeditCursor);
- //MTextEditView formats the pre-edit text depending on the values set here.
- //
- //An alternative implementation would be to use QTextLayout::setAdditionalFormats.
- //But this would cause problems in MTextEditView because calling QTextLayout::setAdditionalFormats
- //causes a contentChange signal covering the whole text to be emitted.
-
- q->model()->setAdditionalFormats(additionalFormats);
+ // set the preedit styling as additional format of the current qtextlayout.
+ // preedit is implemented as selected normal text with additional formatting on current
+ // QTextLayout. Using the additional formats here seems a bit dangerous. In principle Qt
+ // says the layout from a block shouldn't be changed except from
+ // QAbstractTextDocumentLayout::documentChanged(), but in reality e.g. QTextEdit
+ // uses it like this, and even sets the preedit to the layout.
+ // If this becomes problematic, we should move this formatting to paintContext of the view.
+ layout->setAdditionalFormats(preeditStyles);
int listIndex = 0;
int count = 0;
-
insertTextWithPreeditStyling(text, listIndex, count);
-
clearUnusedPreeditStyling(listIndex, count);
// mark preedit as selection
@@ -809,8 +809,8 @@ void MTextEditPrivate::commitPreedit()
// clear styling
QTextBlock block = textCursor->block();
-
- q->model()->setAdditionalFormats(QList<MTextEditFormatRange>());
+ QTextLayout *layout = block.layout();
+ layout->clearAdditionalFormats();
if (validateCurrentBlock() == true) {
// make preedit selection part of the normal text
@@ -835,14 +835,13 @@ void MTextEditPrivate::commitPreedit()
*/
void MTextEditPrivate::removePreedit()
{
- Q_Q(MTextEdit);
-
if (isPreediting() == false) {
return;
}
QTextBlock block = cursor()->block();
- q->model()->setAdditionalFormats(QList<MTextEditFormatRange>());
+ QTextLayout *layout = block.layout();
+ layout->clearAdditionalFormats();
cursor()->removeSelectedText();
}
@@ -1295,7 +1294,6 @@ MTextEdit::MTextEdit(MTextEditModel::LineMode type, const QString &text,
model()->setDocument(new QTextDocument(text, this->model()));
model()->setLine(type);
-
d->init();
}
diff --git a/src/corelib/widgets/mtexteditmodel.h b/src/corelib/widgets/mtexteditmodel.h
index 2f7c0f80..87159e23 100644
--- a/src/corelib/widgets/mtexteditmodel.h
+++ b/src/corelib/widgets/mtexteditmodel.h
@@ -23,23 +23,8 @@
#include <mwidgetmodel.h>
#include <limits>
#include <QTextDocument>
-#include <QTextCharFormat>
#include "mnamespace.h"
-
-class MTextEditFormatRange
-{
- public:
- bool operator ==(const MTextEditFormatRange& other) const
- {
- return (start == other.start && length == other.length && format == other.format);
- }
-
- int start;
- int length;
- QTextCharFormat format;
-};
-
class M_CORE_EXPORT MTextEditModel : public MWidgetModel
{
Q_OBJECT
@@ -104,9 +89,8 @@ private:
M_MODEL_PROPERTY(int, toolbarId, ToolbarId, true, -1)
M_MODEL_PROPERTY(MTextEditModel::EchoMode, echo, Echo, true, MTextEditModel::Normal)
M_MODEL_PROPERTY(bool, isAutoSipEnabled, AutoSipEnabled, true, true)
- M_MODEL_PROPERTY(int, preeditCursor, PreeditCursor, true, -1)
- M_MODEL_PROPERTY(QList<MTextEditFormatRange>, additionalFormats, AdditionalFormats, true, QList<MTextEditFormatRange>())
+ M_MODEL_PROPERTY(int, preeditCursor, PreeditCursor, true, -1)
public:
void updateCursor() {
memberModified(MTextEditModel::Cursor);
diff --git a/src/views/mtexteditview.cpp b/src/views/mtexteditview.cpp
index d2971bdf..8cdfd97a 100644
--- a/src/views/mtexteditview.cpp
+++ b/src/views/mtexteditview.cpp
@@ -335,22 +335,12 @@ void MTextEditViewPrivate::setMouseTarget(const QPointF &point)
mouseTarget.setY(qBound<qreal>(0.0, point.y(), q->geometry().height()));
}
+
QAbstractTextDocumentLayout::PaintContext MTextEditViewPrivate::paintContext() const
{
Q_Q(const MTextEditView);
QAbstractTextDocumentLayout::PaintContext paintContext;
-
- foreach (MTextEditFormatRange formatRange, q->model()->additionalFormats()) {
- QTextCursor cursor(activeDocument());
- cursor.setPosition(formatRange.start, QTextCursor::MoveAnchor);
- cursor.setPosition(formatRange.start + formatRange.length, QTextCursor::KeepAnchor);
- QAbstractTextDocumentLayout::Selection selection;
- selection.cursor = cursor;
- selection.format = formatRange.format;
- paintContext.selections.append(selection);
- }
-
paintContext.palette.setColor(QPalette::Text, q->style()->textColor());
QTextCursor cursor = controller->textCursor();
MTextEditModel::EchoMode echoMode = q->model()->echo();
@@ -806,7 +796,6 @@ void MTextEditView::drawContents(QPainter *painter, const QStyleOptionGraphicsIt
if (d->focused == false && d->activeDocument()->isEmpty() == true) {
// with no focus and content we show the prompt text
QAbstractTextDocumentLayout::PaintContext paintContext;
-
QColor promptColor = style()->promptColor();
paintContext.palette.setColor(QPalette::Text, promptColor);