From a1a9929acaeccd7027605ffeb9794b034b146c92 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 14 Mar 2011 10:47:36 +1000 Subject: Fix TextEdit mouseSelectionMode overriding selectByMouse. If selectByMouse is false don't allow any text selection on mouse move. Change-Id: Ic9f309899bc0de48066a2393e088e15b3a2f06db Task-number: QTBUG-18072 Reviewed-by: Martin Jones --- src/gui/text/qtextcontrol.cpp | 11 +++++++++-- .../qdeclarativetextedit/data/mouseselection_false_words.qml | 7 +++++++ .../qdeclarativetextedit/data/mouseselection_true_words.qml | 7 +++++++ .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index f5da079..6babca1 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -1607,7 +1607,10 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons if (!(buttons & Qt::LeftButton)) return; - if (!((interactionFlags & Qt::TextSelectableByMouse) || (interactionFlags & Qt::TextEditable))) + const bool selectable = interactionFlags & Qt::TextSelectableByMouse; + const bool editable = interactionFlags & Qt::TextEditable; + + if (!selectable && !editable) return; if (!(mousePressed @@ -1623,6 +1626,10 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons startDrag(); return; } + + if (!selectable) + return; + const qreal mouseX = qreal(mousePos.x()); int newCursorPos = q->hitTest(mousePos, Qt::FuzzyHit); @@ -1638,7 +1645,7 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons extendBlockwiseSelection(newCursorPos); else if (selectedWordOnDoubleClick.hasSelection()) extendWordwiseSelection(newCursorPos, mouseX); - else if (interactionFlags & Qt::TextSelectableByMouse) + else setCursorPosition(newCursorPos, QTextCursor::KeepAnchor); if (interactionFlags & Qt::TextEditable) { diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml new file mode 100644 index 0000000..22a9871 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +TextEdit { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: false +} diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml new file mode 100644 index 0000000..d61da46 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +TextEdit { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: true +} diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 7aac76c..f62c2c5 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -1305,6 +1305,8 @@ void tst_qdeclarativetextedit::mouseSelection_data() QTest::newRow("on") << SRCDIR "/data/mouseselection_true.qml" << true; QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << false; QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << false; + QTest::newRow("on word selection") << SRCDIR "/data/mouseselection_true_words.qml" << true; + QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << false; } void tst_qdeclarativetextedit::mouseSelection() -- cgit v0.12 From 8b7c98123eadf9263c6bde4b1263bd64fc388c8d Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Mon, 14 Mar 2011 12:06:04 +0200 Subject: QS60Style: QTreeView::indexRowSizeHint returns incorrect value Fix for http://bugreports.qt.nokia.com/browse/QTBUG-17786. QS60Style tries to work around the hardcoded margin that the QCommonStyle adds to menu items (line 4782 in my QCommonStyle.cpp). Unfortunately regular itemview items are handled in the same code branch in QS60Style, so the class incorrectly reduces the itemview height 8 pixels. The reduction should only happen with menu items. Task-number: QTBUG-17786 Reviewed-by: Laszlo Agocs --- src/gui/styles/qs60style.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 38a4b7c..87d990e 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2643,10 +2643,13 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); //native items have small empty areas at the beginning and end of menu item sz.setWidth(sz.width() + 2 * pixelMetric(PM_MenuHMargin) + 2 * QS60StylePrivate::pixelMetric(PM_FrameCornerWidth)); - if (QS60StylePrivate::isTouchSupported()) + if (QS60StylePrivate::isTouchSupported()) { //Make itemview easier to use in touch devices + sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin)); //QCommonStyle does not adjust height with horizontal margin, it only adjusts width - sz.setHeight(sz.height() + 2 * pixelMetric(PM_FocusFrameVMargin) - 8); //QCommonstyle adds 8 to height that this style handles through PM values + if (ct == CT_MenuItem) + sz.setHeight(sz.height() - 8); //QCommonstyle adds 8 to height that this style handles through PM values + } break; #ifndef QT_NO_COMBOBOX case CT_ComboBox: { -- cgit v0.12