summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>2011-10-06 15:10:24 +0300
committerQt by Nokia <qt-info@nokia.com>2011-10-11 16:03:01 +0200
commitbd34df230da21154536cdc7c2886206bb53d2a78 (patch)
tree8a9b09e047bc497fa2e733eb2299fe04d56b4c49 /src
parent76ca6642a9ddb5ffe21691918a4a803760f0f487 (diff)
QTextEdit - Fix selectionChange emission bug
QTextEdit did not emit selectionChange signal if selection availability did not change, but the start or end of the selection did. This was causing unit test to fail. Change-Id: Iea0cb0bae767bc8d2dd36141362f9a084af97266 Reviewed-on: http://codereview.qt-project.org/6426 Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp23
-rw-r--r--src/widgets/widgets/qwidgettextcontrol_p_p.h3
2 files changed, 19 insertions, 7 deletions
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 346499c26f..68dad9fe7a 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -119,7 +119,8 @@ QWidgetTextControlPrivate::QWidgetTextControlPrivate()
#ifndef QT_NO_DRAGANDDROP
mousePressed(false), mightStartDrag(false),
#endif
- lastSelectionState(false), ignoreAutomaticScrollbarAdjustement(false),
+ lastSelectionPosition(0), lastSelectionAnchor(0),
+ ignoreAutomaticScrollbarAdjustement(false),
overwriteMode(false),
acceptRichText(true),
preeditCursor(0), hideCursor(false),
@@ -577,15 +578,25 @@ void QWidgetTextControlPrivate::selectionChanged(bool forceEmitSelectionChanged
if (forceEmitSelectionChanged)
emit q->selectionChanged();
- bool current = cursor.hasSelection();
- if (current == lastSelectionState)
+ if (cursor.position() == lastSelectionPosition
+ && cursor.anchor() == lastSelectionAnchor)
return;
- lastSelectionState = current;
- emit q->copyAvailable(current);
- if (!forceEmitSelectionChanged)
+ bool selectionStateChange = (cursor.hasSelection()
+ != (lastSelectionPosition != lastSelectionAnchor));
+ if (selectionStateChange)
+ emit q->copyAvailable(cursor.hasSelection());
+
+ if (!forceEmitSelectionChanged
+ && (selectionStateChange
+ || (cursor.hasSelection()
+ && (cursor.position() != lastSelectionPosition
+ || cursor.anchor() != lastSelectionAnchor))))
emit q->selectionChanged();
+
emit q->microFocusChanged();
+ lastSelectionPosition = cursor.position();
+ lastSelectionAnchor = cursor.anchor();
}
void QWidgetTextControlPrivate::_q_updateCurrentCharFormatAndSelection()
diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h
index 8943bb70cf..0f163d7e04 100644
--- a/src/widgets/widgets/qwidgettextcontrol_p_p.h
+++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h
@@ -193,7 +193,8 @@ public:
QPoint dragStartPos;
QPointer<QWidget> contextWidget;
- bool lastSelectionState;
+ int lastSelectionPosition;
+ int lastSelectionAnchor;
bool ignoreAutomaticScrollbarAdjustement;