From bcbcb8d0d60b94fe9e739a9c95b4e78ac8184a0e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 14 Feb 2017 11:47:24 +0100 Subject: QQuickPopup: ensure that the cursor is correct when overlapping items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a popup is over an item that has a different cursor (such as a TextField), the cursor incorrectly took on that shape, because QQuickPopup didn’t have an explicitly set cursor. Task-number: QTBUG-58810 Change-Id: I4df6dd725cac027b2c30fe69ad81d9cd7e622c15 Reviewed-by: J-P Nurmi --- tests/auto/popup/data/cursor.qml | 61 ++++++++++++++++++++++++++++++++++++++++ tests/auto/popup/tst_popup.cpp | 33 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/auto/popup/data/cursor.qml (limited to 'tests') diff --git a/tests/auto/popup/data/cursor.qml b/tests/auto/popup/data/cursor.qml new file mode 100644 index 00000000..a00c00fa --- /dev/null +++ b/tests/auto/popup/data/cursor.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + width: 400 + height: 400 + + property alias popup: popup + property alias textField: textField + + TextField { + id: textField + } + Popup { + id: popup + x: textField.x + textField.width / 2 + y: textField.y + textField.height / 2 - height / 2 + width: 100 + height: 100 + } +} diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp index 25904003..ab96869a 100644 --- a/tests/auto/popup/tst_popup.cpp +++ b/tests/auto/popup/tst_popup.cpp @@ -72,6 +72,7 @@ private slots: void parentDestroyed(); void nested(); void grabber(); + void cursorShape(); }; void tst_popup::visible_data() @@ -721,6 +722,38 @@ void tst_popup::grabber() QCOMPARE(combo->isVisible(), false); } +void tst_popup::cursorShape() +{ + // Ensure that the mouse cursor has the correct shape when over a popup + // which is itself over an item with a different shape. + QQuickApplicationHelper helper(this, QStringLiteral("cursor.qml")); + QQuickApplicationWindow *window = helper.appWindow; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickPopup *popup = helper.appWindow->property("popup").value(); + QVERIFY(popup); + + popup->open(); + QVERIFY(popup->isVisible()); + + QQuickItem *textField = helper.appWindow->property("textField").value(); + QVERIFY(textField); + + // Move the mouse over the text field. + const QPoint textFieldPos(popup->x() - 10, popup->y() + popup->height() / 2); + QTest::mouseMove(window, textFieldPos); + QCOMPARE(window->cursor().shape(), textField->cursor().shape()); + + // Move the mouse over the popup where it overlaps with the text field. + const QPoint textFieldOverlapPos(popup->x() + 10, popup->y() + popup->height() / 2); + QTest::mouseMove(window, textFieldOverlapPos); + QCOMPARE(window->cursor().shape(), popup->popupItem()->cursor().shape()); + + popup->close(); + QTRY_VERIFY(!popup->isVisible()); +} + QTEST_MAIN(tst_popup) #include "tst_popup.moc" -- cgit v1.2.3