aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2012-07-03 12:29:57 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-04 02:45:03 +0200
commit9bf96613c1be7d4df7132a9c3c9ac1a8740f698f (patch)
tree351c19417586bf5ec688af3f8b40f91c9f1d1a5e
parentfc909a49d3e8fa2132bf0951499a1d5cb1d541ca (diff)
Allow mouse interaction with 0 opacity items.
Don't filter event delivery to items with 0 opacity, and update the documentation the for opacity, visible and enabled properties and how each affects event delivery. Task-number: QTBUG-19193 Change-Id: Id48e4af763c9a7bbcc13b303342d303155dcadc9 Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
-rw-r--r--src/plugins/accessible/quick/qaccessiblequickview.cpp2
-rw-r--r--src/quick/items/qquickcanvas.cpp11
-rw-r--r--src/quick/items/qquickitem.cpp32
-rw-r--r--src/quick/items/qquickmousearea.cpp2
-rw-r--r--tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp22
-rw-r--r--tests/auto/quick/qquickdrag/tst_qquickdrag.cpp6
6 files changed, 39 insertions, 36 deletions
diff --git a/src/plugins/accessible/quick/qaccessiblequickview.cpp b/src/plugins/accessible/quick/qaccessiblequickview.cpp
index 5f66f00d8a..c82c4e839d 100644
--- a/src/plugins/accessible/quick/qaccessiblequickview.cpp
+++ b/src/plugins/accessible/quick/qaccessiblequickview.cpp
@@ -118,7 +118,7 @@ QString QAccessibleQuickView::text(QAccessible::Text text) const
*/
static QQuickItem *childAt_helper(QQuickItem *item, int x, int y)
{
- if (item->opacity() == 0.0 || !item->isVisible() || !item->isEnabled())
+ if (!item->isVisible() || !item->isEnabled())
return 0;
if (item->flags() & QQuickItem::ItemClipsChildrenToShape) {
diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp
index a242ca1111..7e0f482ee0 100644
--- a/src/quick/items/qquickcanvas.cpp
+++ b/src/quick/items/qquickcanvas.cpp
@@ -1146,8 +1146,6 @@ bool QQuickCanvasPrivate::deliverInitialMousePressEvent(QQuickItem *item, QMouse
Q_Q(QQuickCanvas);
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
- if (itemPrivate->opacity() == 0.0)
- return false;
if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) {
QPointF p = item->mapFromScene(event->windowPos());
@@ -1306,8 +1304,6 @@ bool QQuickCanvasPrivate::deliverHoverEvent(QQuickItem *item, const QPointF &sce
Qt::KeyboardModifiers modifiers, bool &accepted)
{
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
- if (itemPrivate->opacity() == 0.0)
- return false;
if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) {
QPointF p = item->mapFromScene(scenePos);
@@ -1374,8 +1370,6 @@ bool QQuickCanvasPrivate::deliverWheelEvent(QQuickItem *item, QWheelEvent *event
{
Q_Q(QQuickCanvas);
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
- if (itemPrivate->opacity() == 0.0)
- return false;
if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) {
QPointF p = item->mapFromScene(event->posF());
@@ -1514,9 +1508,6 @@ bool QQuickCanvasPrivate::deliverTouchPoints(QQuickItem *item, QTouchEvent *even
{
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
- if (qFuzzyIsNull(itemPrivate->opacity()))
- return false;
-
if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) {
for (int i=0; i<newPoints.count(); i++) {
QPointF p = item->mapFromScene(newPoints[i].scenePos());
@@ -1770,7 +1761,7 @@ bool QQuickCanvasPrivate::deliverDragEvent(QQuickDragGrabber *grabber, QQuickIte
Q_Q(QQuickCanvas);
bool accepted = false;
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
- if (itemPrivate->opacity() == 0.0 || !item->isVisible() || !item->isEnabled())
+ if (!item->isVisible() || !item->isEnabled())
return false;
QPointF p = item->mapFromScene(event->pos());
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index df557f1e01..9c43645f1e 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2818,16 +2818,31 @@ void QQuickItemPrivate::transform_clear(QQmlListProperty<QQuickTransform> *prop)
explicit property changes. In such cases it may be better to use the
\l opacity property instead.)
- Setting this property to \c false automatically causes \l focus to be set
- to \c false, and this item will longer receive mouse and keyboard events.
- (In contrast, setting the \l opacity to 0 does not affect the \l focus
- property and the receiving of key events.)
+ If this property is set to \c false, the item will no longer receive mouse
+ events, but will continue to receive key events and will retain the keyboard
+ \l focus if it has been set. (In contrast, setting the \l enabled property
+ to \c false stops both mouse and keyboard events, and also removes focus
+ from the item.)
\note This property's value is only affected by changes to this property or
the parent's \c visible property. It does not change, for example, if this
item moves off-screen, or if the \l opacity changes to 0.
*/
+/*!
+ \qmlproperty bool QtQuick2::Item::enabled
+
+ This property holds whether the item receives mouse and keyboard events.
+ By default this is true.
+
+ Setting this property directly affects the \c enabled value of child
+ items. When set to \c false, the \c enabled values of all child items also
+ become \c false. When set to \c true, the \c enabled values of child items
+ are returned to \c true, unless they have explicitly been set to \c false.
+
+ Setting this property to \c false automatically causes \l activeFocus to be
+ set to \c false, and this item will longer receive keyboard events.
+*/
/*!
\qmlproperty AnchorLine QtQuick2::Item::anchors.top
@@ -4063,11 +4078,10 @@ void QQuickItem::setZ(qreal v)
\endqml
\endtable
- If an item's opacity is set to 0, the item will no longer receive mouse
- events, but will continue to receive key events and will retain the keyboard
- \l focus if it has been set. (In contrast, setting the \l visible property
- to \c false stops both mouse and keyboard events, and also removes focus
- from the item.)
+ Changing an items opacity will not affect delivery of input events. (In contrast
+ setting \l visible property to \c false stops mouse events, and setting the
+ \l enabled property to \c false stops mouse and keyboard events, and also removes
+ active focus from the item.)
*/
/*!
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 17458abee6..6897e3d904 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -271,8 +271,6 @@ bool QQuickMouseAreaPrivate::propagateHelper(QQuickMouseEvent *ev, QQuickItem *i
//But specific to MouseArea, so doesn't belong in canvas
Q_Q(const QQuickMouseArea);
QQuickItemPrivate *itemPrivate = QQuickItemPrivate::get(item);
- if (itemPrivate->opacity() == 0.0)
- return false;
if (itemPrivate->flags & QQuickItem::ItemClipsChildrenToShape) {
QPointF p = item->mapFromScene(sp);
diff --git a/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp
index 83c5b62ef8..badec53aee 100644
--- a/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp
+++ b/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp
@@ -157,7 +157,7 @@ public:
void reset() {
acceptTouchEvents = acceptMouseEvents = true;
setEnabled(true);
- setOpacity(1.0);
+ setVisible(true);
lastEvent = makeTouchData(QEvent::None, canvas(), 0, QList<QTouchEvent::TouchPoint>());//CHECK_VALID
@@ -456,7 +456,7 @@ void tst_qquickcanvas::touchEvent_propagation()
QFETCH(bool, acceptTouchEvents);
QFETCH(bool, acceptMouseEvents);
QFETCH(bool, enableItem);
- QFETCH(qreal, itemOpacity);
+ QFETCH(bool, showItem);
QQuickCanvas *canvas = new QQuickCanvas;
canvas->resize(250, 250);
@@ -487,7 +487,7 @@ void tst_qquickcanvas::touchEvent_propagation()
topItem->acceptTouchEvents = acceptTouchEvents;
topItem->acceptMouseEvents = acceptMouseEvents;
topItem->setEnabled(enableItem);
- topItem->setOpacity(itemOpacity);
+ topItem->setVisible(showItem);
// single touch to top item, should be received by middle item
QTest::touchEvent(canvas, touchDevice).press(0, pointInTopItem, canvas);
@@ -514,7 +514,7 @@ void tst_qquickcanvas::touchEvent_propagation()
middleItem->acceptTouchEvents = acceptTouchEvents;
middleItem->acceptMouseEvents = acceptMouseEvents;
middleItem->setEnabled(enableItem);
- middleItem->setOpacity(itemOpacity);
+ middleItem->setVisible(showItem);
// touch top and middle items, bottom item should get all events
QTest::touchEvent(canvas, touchDevice).press(0, pointInTopItem, canvas)
@@ -531,7 +531,7 @@ void tst_qquickcanvas::touchEvent_propagation()
// disable bottom item as well
bottomItem->acceptTouchEvents = acceptTouchEvents;
bottomItem->setEnabled(enableItem);
- bottomItem->setOpacity(itemOpacity);
+ bottomItem->setVisible(showItem);
// no events should be received
QTest::touchEvent(canvas, touchDevice).press(0, pointInTopItem, canvas)
@@ -549,10 +549,10 @@ void tst_qquickcanvas::touchEvent_propagation()
// disable middle item, touch on top item
middleItem->acceptTouchEvents = acceptTouchEvents;
middleItem->setEnabled(enableItem);
- middleItem->setOpacity(itemOpacity);
+ middleItem->setVisible(showItem);
QTest::touchEvent(canvas, touchDevice).press(0, pointInTopItem, canvas);
QTest::qWait(50);
- if (!enableItem || itemOpacity == 0) {
+ if (!enableItem || !showItem) {
// middle item is disabled or has 0 opacity, bottom item receives the event
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
@@ -579,11 +579,11 @@ void tst_qquickcanvas::touchEvent_propagation_data()
QTest::addColumn<bool>("acceptTouchEvents");
QTest::addColumn<bool>("acceptMouseEvents");
QTest::addColumn<bool>("enableItem");
- QTest::addColumn<qreal>("itemOpacity");
+ QTest::addColumn<bool>("showItem");
- QTest::newRow("disable events") << false << false << true << 1.0;
- QTest::newRow("disable item") << true << true << false << 1.0;
- QTest::newRow("opacity of 0") << true << true << true << 0.0;
+ QTest::newRow("disable events") << false << false << true << true;
+ QTest::newRow("disable item") << true << true << false << true;
+ QTest::newRow("hide item") << true << true << true << false;
}
void tst_qquickcanvas::touchEvent_cancel()
diff --git a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
index 0ebfa81201..12c1a03b3e 100644
--- a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
+++ b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
@@ -345,9 +345,9 @@ void tst_QQuickDrag::active()
evaluate<void>(item, "Drag.active = true");
QCOMPARE(evaluate<bool>(item, "Drag.active"), true);
QCOMPARE(evaluate<bool>(item, "dragActive"), true);
- QCOMPARE(evaluate<QObject *>(item, "Drag.target"), static_cast<QObject *>(0));
- QCOMPARE(evaluate<QObject *>(item, "dragTarget"), static_cast<QObject *>(0));
- QCOMPARE(dropTarget.enterEvents, 0); QCOMPARE(dropTarget.leaveEvents, 0);
+ QCOMPARE(evaluate<QObject *>(item, "Drag.target"), static_cast<QObject *>(&dropTarget));
+ QCOMPARE(evaluate<QObject *>(item, "dragTarget"), static_cast<QObject *>(&dropTarget));
+ QCOMPARE(dropTarget.enterEvents, 1); QCOMPARE(dropTarget.leaveEvents, 0);
evaluate<void>(item, "Drag.active = false");
dropTarget.setOpacity(1.0);