diff options
author | Pekka Vuorela <pekka.ta.vuorela@nokia.com> | 2011-10-06 15:10:24 +0300 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-11 16:03:01 +0200 |
commit | bd34df230da21154536cdc7c2886206bb53d2a78 (patch) | |
tree | 8a9b09e047bc497fa2e733eb2299fe04d56b4c49 /src/widgets/widgets/qwidgettextcontrol.cpp | |
parent | 76ca6642a9ddb5ffe21691918a4a803760f0f487 (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/widgets/widgets/qwidgettextcontrol.cpp')
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 23 |
1 files changed, 17 insertions, 6 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() |