Provide visual debugging for MouseArea and TouchArea
authorYann Bodson <yann.bodson@nokia.com>
Thu, 16 Feb 2012 03:45:40 +0000 (13:45 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 17 Feb 2012 03:28:35 +0000 (04:28 +0100)
Display MouseAreas and TouchAreas as semi transparent rectangles
when the environment variable QML_VISUAL_TOUCH_DEBUGGING is set.

Task-number: QTBUG-24283
Change-Id: Iec8482a79ed1d4b802c29a5f7104af4e0a6eab7d
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
src/quick/items/qquickmousearea.cpp
src/quick/items/qquickmousearea_p.h
src/quick/items/qquickmultipointtoucharea.cpp
src/quick/items/qquickmultipointtoucharea_p.h

index cf6045e..b870443 100644 (file)
@@ -52,6 +52,9 @@
 #include <float.h>
 
 QT_BEGIN_NAMESPACE
+
+DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)
+
 static const int PressAndHoldDelay = 800;
 
 QQuickDrag::QQuickDrag(QObject *parent)
@@ -198,6 +201,9 @@ void QQuickMouseAreaPrivate::init()
     Q_Q(QQuickMouseArea);
     q->setAcceptedMouseButtons(Qt::LeftButton);
     q->setFiltersChildMouseEvents(true);
+    if (qmlVisualTouchDebugging()) {
+        q->setFlag(QQuickItem::ItemHasContents);
+    }
 }
 
 void QQuickMouseAreaPrivate::saveEvent(QMouseEvent *event)
@@ -1165,4 +1171,21 @@ QQuickDrag *QQuickMouseArea::drag()
     return d->drag;
 }
 
+QSGNode *QQuickMouseArea::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
+{
+    Q_UNUSED(data);
+    Q_D(QQuickMouseArea);
+
+    if (!qmlVisualTouchDebugging())
+        return 0;
+
+    QSGRectangleNode *rectangle = static_cast<QSGRectangleNode *>(oldNode);
+    if (!rectangle) rectangle = d->sceneGraphContext()->createRectangleNode();
+
+    rectangle->setRect(QRectF(0, 0, width(), height()));
+    rectangle->setColor(QColor(255, 0, 0, 50));
+    rectangle->update();
+    return rectangle;
+}
+
 QT_END_NAMESPACE
index 98034a6..7513ca3 100644 (file)
@@ -207,6 +207,7 @@ protected:
     virtual void geometryChanged(const QRectF &newGeometry,
                                  const QRectF &oldGeometry);
     virtual void itemChange(ItemChange change, const ItemChangeData& value);
+    virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
 
 private:
     void handlePress();
index 32c8c38..766ce67 100644 (file)
@@ -41,6 +41,8 @@
 
 #include "qquickmultipointtoucharea_p.h"
 #include <QtQuick/qquickcanvas.h>
+#include <private/qsgadaptationlayer_p.h>
+#include <private/qquickitem_p.h>
 #include <QEvent>
 #include <QMouseEvent>
 #include <math.h>
@@ -48,6 +50,8 @@
 
 QT_BEGIN_NAMESPACE
 
+DEFINE_BOOL_CONFIG_OPTION(qmlVisualTouchDebugging, QML_VISUAL_TOUCH_DEBUGGING)
+
 /*!
     \qmlclass TouchPoint QQuickTouchPoint
     \inqmlmodule QtQuick 2
@@ -307,6 +311,9 @@ QQuickMultiPointTouchArea::QQuickMultiPointTouchArea(QQuickItem *parent)
 {
     setAcceptedMouseButtons(Qt::LeftButton);
     setFiltersChildMouseEvents(true);
+    if (qmlVisualTouchDebugging()) {
+        setFlag(QQuickItem::ItemHasContents);
+    }
 }
 
 QQuickMultiPointTouchArea::~QQuickMultiPointTouchArea()
@@ -738,4 +745,20 @@ bool QQuickMultiPointTouchArea::shouldFilter(QEvent *event)
     return false;
 }
 
+QSGNode *QQuickMultiPointTouchArea::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
+{
+    Q_UNUSED(data);
+
+    if (!qmlVisualTouchDebugging())
+        return 0;
+
+    QSGRectangleNode *rectangle = static_cast<QSGRectangleNode *>(oldNode);
+    if (!rectangle) rectangle = QQuickItemPrivate::get(this)->sceneGraphContext()->createRectangleNode();
+
+    rectangle->setRect(QRectF(0, 0, width(), height()));
+    rectangle->setColor(QColor(255, 0, 0, 50));
+    rectangle->update();
+    return rectangle;
+}
+
 QT_END_NAMESPACE
index b56d88b..e611ce3 100644 (file)
@@ -251,6 +251,7 @@ protected:
     bool sendMouseEvent(QMouseEvent *event);
     bool shouldFilter(QEvent *event);
     void grabGesture();
+    virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
 
 private:
     void ungrab();