summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org>2011-08-23 19:04:16 -0300
committerQt by Nokia <qt-info@nokia.com>2011-08-24 04:23:40 +0200
commit0d572fc7d251691a34fe5b99c60868835409047e (patch)
tree4b68d2246e990730af1d711304a656eed06eb866
parent6b18f28e38149a4f35e48dc2a7f52bc7a23587c3 (diff)
Do not deliver mouse wheel events when item is not visible
This patch change the code to also skip invisible items (it was done for disabled already) when deciding whether or not deliver the wheel event to an item. The rationale here is to follow the same rule as the other mouse events. An autotest was added to verify and maintain this behavior. Change-Id: If0fe6d64d1f7cfb8679ce11edda7c02dc3783f94 Reviewed-on: http://codereview.qt.nokia.com/3429 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
-rw-r--r--src/declarative/items/qsgcanvas.cpp2
-rw-r--r--tests/auto/declarative/qsgitem/tst_qsgitem.cpp49
2 files changed, 49 insertions, 2 deletions
diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp
index 11b3b030ed..6873c41cef 100644
--- a/src/declarative/items/qsgcanvas.cpp
+++ b/src/declarative/items/qsgcanvas.cpp
@@ -1306,7 +1306,7 @@ bool QSGCanvasPrivate::deliverWheelEvent(QSGItem *item, QWheelEvent *event)
QList<QSGItem *> children = itemPrivate->paintOrderChildItems();
for (int ii = children.count() - 1; ii >= 0; --ii) {
QSGItem *child = children.at(ii);
- if (!child->isEnabled())
+ if (!child->isVisible() || !child->isEnabled())
continue;
if (deliverWheelEvent(child, event))
return true;
diff --git a/tests/auto/declarative/qsgitem/tst_qsgitem.cpp b/tests/auto/declarative/qsgitem/tst_qsgitem.cpp
index e591ab8c86..7799fef9de 100644
--- a/tests/auto/declarative/qsgitem/tst_qsgitem.cpp
+++ b/tests/auto/declarative/qsgitem/tst_qsgitem.cpp
@@ -52,16 +52,18 @@ class TestItem : public QSGItem
{
Q_OBJECT
public:
- TestItem(QSGItem *parent = 0) : QSGItem(parent), focused(false), pressCount(0), releaseCount(0) {}
+ TestItem(QSGItem *parent = 0) : QSGItem(parent), focused(false), pressCount(0), releaseCount(0), wheelCount(0) {}
bool focused;
int pressCount;
int releaseCount;
+ int wheelCount;
protected:
virtual void focusInEvent(QFocusEvent *) { Q_ASSERT(!focused); focused = true; }
virtual void focusOutEvent(QFocusEvent *) { Q_ASSERT(focused); focused = false; }
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) { event->accept(); ++pressCount; }
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { event->accept(); ++releaseCount; }
+ virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; }
};
class TestPolishItem : public QSGItem
@@ -123,6 +125,9 @@ private slots:
void mouseGrab();
void polishOutsideAnimation();
+ void wheelEvent_data();
+ void wheelEvent();
+
private:
void ensureFocus(QWidget *w) {
w->show();
@@ -845,6 +850,48 @@ void tst_qsgitem::polishOutsideAnimation()
delete canvas;
}
+void tst_qsgitem::wheelEvent_data()
+{
+ QTest::addColumn<bool>("visible");
+ QTest::addColumn<bool>("enabled");
+
+ QTest::newRow("visible and enabled") << true << true;
+ QTest::newRow("visible and disabled") << true << false;
+ QTest::newRow("invisible and enabled") << false << true;
+ QTest::newRow("invisible and disabled") << false << false;
+}
+
+void tst_qsgitem::wheelEvent()
+{
+ QFETCH(bool, visible);
+ QFETCH(bool, enabled);
+
+ const bool shouldReceiveWheelEvents = visible && enabled;
+
+ QSGCanvas *canvas = new QSGCanvas;
+ canvas->resize(200, 200);
+ canvas->show();
+
+ TestItem *item = new TestItem;
+ item->setSize(QSizeF(200, 100));
+ item->setParentItem(canvas->rootItem());
+
+ item->setEnabled(enabled);
+ item->setVisible(visible);
+
+ QWheelEvent event(QPoint(100, 50), -120, Qt::NoButton, Qt::NoModifier, Qt::Vertical);
+ event.setAccepted(false);
+ QApplication::sendEvent(canvas, &event);
+
+ if (shouldReceiveWheelEvents) {
+ QVERIFY(event.isAccepted());
+ QCOMPARE(item->wheelCount, 1);
+ } else {
+ QVERIFY(!event.isAccepted());
+ QCOMPARE(item->wheelCount, 0);
+ }
+}
+
QTEST_MAIN(tst_qsgitem)
#include "tst_qsgitem.moc"