QmlInspector: Initial support for QSGView based applications
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
Thu, 9 Jun 2011 08:52:10 +0000 (10:52 +0200)
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
Thu, 23 Jun 2011 14:26:11 +0000 (16:26 +0200)
Currently only displays a rectangle highlighting the item below the mouse,
but it's a start.

Change-Id: I9946a923add4c53780546ac4bf138fe731508da2

12 files changed:
src/declarative/debugger/qdeclarativeinspectorservice.cpp
src/declarative/debugger/qdeclarativeinspectorservice_p.h
src/declarative/items/qsgview.cpp
src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp
src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h
src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro
src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp [new file with mode: 0644]
src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h [new file with mode: 0644]
src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp [new file with mode: 0644]
src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h [new file with mode: 0644]
src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp [new file with mode: 0644]
src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h [new file with mode: 0644]

index 9fec006..f1ae354 100644 (file)
@@ -47,8 +47,6 @@
 #include <QtCore/QDir>
 #include <QtCore/QPluginLoader>
 
-#include <QtDeclarative/QDeclarativeView>
-
 QT_BEGIN_NAMESPACE
 
 Q_GLOBAL_STATIC(QDeclarativeInspectorService, serviceInstance)
@@ -64,12 +62,12 @@ QDeclarativeInspectorService *QDeclarativeInspectorService::instance()
     return serviceInstance();
 }
 
-void QDeclarativeInspectorService::addView(QDeclarativeView *view)
+void QDeclarativeInspectorService::addView(QObject *view)
 {
     m_views.append(view);
 }
 
-void QDeclarativeInspectorService::removeView(QDeclarativeView *view)
+void QDeclarativeInspectorService::removeView(QObject *view)
 {
     m_views.removeAll(view);
 }
index 9fe0d60..db94103 100644 (file)
@@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE
 
 QT_MODULE(Declarative)
 
-class QDeclarativeView;
 class QDeclarativeInspectorInterface;
 
 class Q_DECLARATIVE_EXPORT QDeclarativeInspectorService : public QDeclarativeDebugService
@@ -64,9 +63,9 @@ public:
     QDeclarativeInspectorService();
     static QDeclarativeInspectorService *instance();
 
-    void addView(QDeclarativeView *);
-    void removeView(QDeclarativeView *);
-    QList<QDeclarativeView*> views() const { return m_views; }
+    void addView(QObject *);
+    void removeView(QObject *);
+    QList<QObject*> views() const { return m_views; }
 
     void sendMessage(const QByteArray &message);
 
@@ -80,7 +79,7 @@ protected:
 private:
     static QDeclarativeInspectorInterface *loadInspectorPlugin();
 
-    QList<QDeclarativeView*> m_views;
+    QList<QObject*> m_views;
     QDeclarativeInspectorInterface *m_inspectorPlugin;
 };
 
index 830a232..d3c8b6d 100644 (file)
@@ -46,6 +46,7 @@
 #include "qsgitemchangelistener_p.h"
 
 #include <private/qdeclarativedebugtrace_p.h>
+#include <private/qdeclarativeinspectorservice_p.h>
 
 #include <QtDeclarative/qdeclarativeengine.h>
 #include <private/qdeclarativeengine_p.h>
@@ -92,6 +93,8 @@ void QSGViewPrivate::init()
 {
     q_func()->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
     QDeclarativeEnginePrivate::get(&engine)->sgContext = QSGCanvasPrivate::context;
+
+    QDeclarativeInspectorService::instance()->addView(q_func());
 }
 
 QSGViewPrivate::QSGViewPrivate()
@@ -101,7 +104,9 @@ QSGViewPrivate::QSGViewPrivate()
 
 QSGViewPrivate::~QSGViewPrivate() 
 { 
-    delete root; 
+    QDeclarativeInspectorService::instance()->removeView(q_func());
+
+    delete root;
 }
 
 void QSGViewPrivate::execute()
index a266eb9..36ee1e8 100644 (file)
 #include "qdeclarativeinspectorplugin.h"
 
 #include "qdeclarativeviewinspector_p.h"
+#include "sgviewinspector.h"
 
 #include <QtCore/qplugin.h>
 #include <QtDeclarative/private/qdeclarativeinspectorservice_p.h>
+#include <QtDeclarative/QSGView>
 
 QT_BEGIN_NAMESPACE
 
@@ -61,13 +63,16 @@ QDeclarativeInspectorPlugin::~QDeclarativeInspectorPlugin()
 void QDeclarativeInspectorPlugin::activate()
 {
     QDeclarativeInspectorService *service = QDeclarativeInspectorService::instance();
-    QList<QDeclarativeView*> views = service->views();
+    QList<QObject*> views = service->views();
     if (views.isEmpty())
         return;
 
     // TODO: Support multiple views
-    QDeclarativeView *view = service->views().at(0);
-    m_inspector = new QDeclarativeViewInspector(view, view);
+    QObject *firstView = views.first();
+    if (QDeclarativeView *declarativeView = qobject_cast<QDeclarativeView*>(firstView))
+        m_inspector = new QDeclarativeViewInspector(declarativeView, declarativeView);
+    else if (QSGView *sgView = qobject_cast<QSGView*>(firstView))
+        m_inspector = new SGViewInspector(sgView, sgView);
 }
 
 void QDeclarativeInspectorPlugin::deactivate()
@@ -78,4 +83,3 @@ void QDeclarativeInspectorPlugin::deactivate()
 Q_EXPORT_PLUGIN2(declarativeinspector, QDeclarativeInspectorPlugin)
 
 QT_END_NAMESPACE
-
index 3e28643..af9c594 100644 (file)
@@ -63,7 +63,7 @@ public:
     void deactivate();
 
 private:
-    QPointer<QDeclarativeViewInspector> m_inspector;
+    QPointer<QObject> m_inspector;
 };
 
 QT_END_NAMESPACE
index 385326a..c60be1f 100644 (file)
@@ -1,7 +1,7 @@
 load(qt_module)
 
 TARGET = qmldbg_inspector
-QT       += declarative-private
+QT       += declarative-private core-private gui-private opengl-private
 
 load(qt_plugin)
 
@@ -23,7 +23,10 @@ SOURCES += \
     editor/zoomtool.cpp \
     editor/colorpickertool.cpp \
     editor/qmltoolbar.cpp \
-    editor/toolbarcolorbox.cpp
+    editor/toolbarcolorbox.cpp \
+    sgabstracttool.cpp \
+    sgviewinspector.cpp \
+    sgselectiontool.cpp
 
 HEADERS += \
     qdeclarativeinspectorplugin.h \
@@ -43,7 +46,10 @@ HEADERS += \
     editor/zoomtool_p.h \
     editor/colorpickertool_p.h \
     editor/qmltoolbar_p.h \
-    editor/toolbarcolorbox_p.h
+    editor/toolbarcolorbox_p.h \
+    sgabstracttool.h \
+    sgviewinspector.h \
+    sgselectiontool.h
 
 RESOURCES += editor/editor.qrc
 
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.cpp
new file mode 100644 (file)
index 0000000..4557831
--- /dev/null
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "sgabstracttool.h"
+
+#include "sgviewinspector.h"
+
+QT_BEGIN_NAMESPACE
+
+SGAbstractTool::SGAbstractTool(SGViewInspector *inspector) :
+    QObject(inspector),
+    m_inspector(inspector)
+{
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h b/src/plugins/qmltooling/qmldbg_inspector/sgabstracttool.h
new file mode 100644 (file)
index 0000000..016f8f3
--- /dev/null
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SGABSTRACTTOOL_H
+#define SGABSTRACTTOOL_H
+
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+
+class QMouseEvent;
+class QKeyEvent;
+class QWheelEvent;
+
+class SGViewInspector;
+
+class SGAbstractTool : public QObject
+{
+    Q_OBJECT
+
+public:
+    explicit SGAbstractTool(SGViewInspector *inspector);
+
+    SGViewInspector *inspector() const { return m_inspector; }
+
+    virtual void leaveEvent(QEvent *event) = 0;
+
+    virtual void mousePressEvent(QMouseEvent *event) = 0;
+    virtual void mouseMoveEvent(QMouseEvent *event) = 0;
+    virtual void mouseReleaseEvent(QMouseEvent *event) = 0;
+    virtual void mouseDoubleClickEvent(QMouseEvent *event) = 0;
+
+    virtual void hoverMoveEvent(QMouseEvent *event) = 0;
+    virtual void wheelEvent(QWheelEvent *event) = 0;
+
+    virtual void keyPressEvent(QKeyEvent *event) = 0;
+    virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0;
+
+private:
+    SGViewInspector *m_inspector;
+};
+
+QT_END_NAMESPACE
+
+#endif // SGABSTRACTTOOL_H
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp
new file mode 100644 (file)
index 0000000..ec0a6ce
--- /dev/null
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "sgselectiontool.h"
+
+#include "sgviewinspector.h"
+
+#include <QtGui/QMouseEvent>
+#include <QtDeclarative/QSGView>
+#include <QtDeclarative/QSGItem>
+#include <QtDeclarative/private/qsgitem_p.h>
+#include <QtDeclarative/private/qsgrectangle_p.h>
+
+/*
+ * Returns the first visible item at the given position, or 0 when no such
+ * child exists.
+ */
+static QSGItem *itemAt(QSGItem *item, const QPointF &pos, QSGItem *overlay)
+{
+    if (item == overlay)
+        return 0;
+
+    if (!item->isVisible() || item->opacity() == 0.0)
+        return 0;
+
+    if (item->flags() & QSGItem::ItemClipsChildrenToShape) {
+        if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
+            return 0;
+    }
+
+    QList<QSGItem *> children = QSGItemPrivate::get(item)->paintOrderChildItems();
+    for (int i = children.count() - 1; i >= 0; --i) {
+        QSGItem *child = children.at(i);
+        if (QSGItem *betterCandidate = itemAt(child, item->mapToItem(child, pos), overlay))
+            return betterCandidate;
+    }
+
+    if (!(item->flags() & QSGItem::ItemHasContents))
+        return 0;
+
+    if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
+        return 0;
+
+    return item;
+}
+
+
+SGSelectionTool::SGSelectionTool(SGViewInspector *inspector) :
+    SGAbstractTool(inspector),
+    m_hoverHighlight(new QSGRectangle(inspector->overlay()))
+{
+    m_hoverHighlight->border()->setColor(QColor(64, 128, 255));
+    m_hoverHighlight->setColor(Qt::transparent);
+}
+
+void SGSelectionTool::leaveEvent(QEvent *)
+{
+    m_hoverHighlight->setVisible(false);
+}
+
+void SGSelectionTool::hoverMoveEvent(QMouseEvent *event)
+{
+    QSGItem *root = inspector()->view()->rootItem();
+    QPointF mappedPos = root->mapFromScene(event->pos());
+    QSGItem *item = itemAt(root, mappedPos, inspector()->overlay());
+    if (!item || item == root) {
+        m_hoverHighlight->setVisible(false);
+        return;
+    }
+
+    m_hoverHighlight->setSize(QSizeF(item->width() - 1, item->height() - 1));
+    m_hoverHighlight->setPos(root->mapFromItem(item->parentItem(), item->pos()));
+    m_hoverHighlight->setVisible(true);
+}
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h
new file mode 100644 (file)
index 0000000..4a64d50
--- /dev/null
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SGSELECTIONTOOL_H
+#define SGSELECTIONTOOL_H
+
+#include "sgabstracttool.h"
+
+#include <QtCore/QList>
+
+QT_BEGIN_NAMESPACE
+
+class QSGRectangle;
+
+class SGSelectionTool : public SGAbstractTool
+{
+    Q_OBJECT
+public:
+    explicit SGSelectionTool(SGViewInspector *inspector);
+
+    void leaveEvent(QEvent *);
+
+    void mousePressEvent(QMouseEvent *) {}
+    void mouseMoveEvent(QMouseEvent *) {}
+    void mouseReleaseEvent(QMouseEvent *) {}
+    void mouseDoubleClickEvent(QMouseEvent *) {}
+
+    void hoverMoveEvent(QMouseEvent *);
+    void wheelEvent(QWheelEvent *) {}
+
+    void keyPressEvent(QKeyEvent *) {}
+    void keyReleaseEvent(QKeyEvent *) {}
+
+signals:
+
+public slots:
+
+private:
+    QList<QSGRectangle*> m_highlightItems;
+    QSGRectangle *m_hoverHighlight;
+};
+
+QT_END_NAMESPACE
+
+#endif // SGSELECTIONTOOL_H
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp
new file mode 100644 (file)
index 0000000..6cd5582
--- /dev/null
@@ -0,0 +1,183 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "sgviewinspector.h"
+
+#include "qdeclarativeinspectorprotocol.h"
+
+#include "sgabstracttool.h"
+#include "sgselectiontool.h"
+
+#include <QtDeclarative/private/qdeclarativeinspectorservice_p.h>
+#include <QtDeclarative/private/qdeclarativedebughelper_p.h>
+
+#include <QtDeclarative/QSGView>
+#include <QtDeclarative/QSGItem>
+#include <QtGui/QMouseEvent>
+
+#include <cfloat>
+
+QT_BEGIN_NAMESPACE
+
+SGViewInspector::SGViewInspector(QSGView *view, QObject *parent) :
+    QObject(parent),
+    m_view(view),
+    m_overlay(new QSGItem),
+    m_currentTool(0),
+    m_selectionTool(new SGSelectionTool(this)),
+    m_designMode(true)
+{
+    // Try to make sure the overlay is always on top
+    m_overlay->setZ(FLT_MAX);
+
+    // Make sure mouse hover events are received
+    m_view->setMouseTracking(true);
+
+    if (QSGItem *root = view->rootItem())
+        m_overlay->setParentItem(root);
+
+    view->installEventFilter(this);
+    m_currentTool = m_selectionTool;
+}
+
+bool SGViewInspector::eventFilter(QObject *obj, QEvent *event)
+{
+    if (obj != m_view || !m_designMode)
+        return QObject::eventFilter(obj, event);
+
+    switch (event->type()) {
+    case QEvent::Leave:
+        if (leaveEvent(event))
+            return true;
+        break;
+    case QEvent::MouseButtonPress:
+        if (mousePressEvent(static_cast<QMouseEvent*>(event)))
+            return true;
+        break;
+    case QEvent::MouseMove:
+        if (mouseMoveEvent(static_cast<QMouseEvent*>(event)))
+            return true;
+        break;
+    case QEvent::MouseButtonRelease:
+        if (mouseReleaseEvent(static_cast<QMouseEvent*>(event)))
+            return true;
+        break;
+    case QEvent::KeyPress:
+        if (keyPressEvent(static_cast<QKeyEvent*>(event)))
+            return true;
+        break;
+    case QEvent::KeyRelease:
+        if (keyReleaseEvent(static_cast<QKeyEvent*>(event)))
+            return true;
+        break;
+    case QEvent::MouseButtonDblClick:
+        if (mouseDoubleClickEvent(static_cast<QMouseEvent*>(event)))
+            return true;
+        break;
+    case QEvent::Wheel:
+        if (wheelEvent(static_cast<QWheelEvent*>(event)))
+            return true;
+        break;
+    default:
+        break;
+    }
+
+    return QObject::eventFilter(obj, event);
+}
+
+bool SGViewInspector::leaveEvent(QEvent *event)
+{
+    m_currentTool->leaveEvent(event);
+    return true;
+}
+
+bool SGViewInspector::mousePressEvent(QMouseEvent *event)
+{
+    m_currentTool->mousePressEvent(event);
+    return true;
+}
+
+bool SGViewInspector::mouseMoveEvent(QMouseEvent *event)
+{
+    if (event->buttons()) {
+        m_currentTool->mouseMoveEvent(event);
+    } else {
+        m_currentTool->hoverMoveEvent(event);
+    }
+    return true;
+}
+
+bool SGViewInspector::mouseReleaseEvent(QMouseEvent *event)
+{
+    m_currentTool->mouseReleaseEvent(event);
+    return true;
+}
+
+bool SGViewInspector::keyPressEvent(QKeyEvent *event)
+{
+    m_currentTool->keyPressEvent(event);
+    return true;
+}
+
+bool SGViewInspector::keyReleaseEvent(QKeyEvent *event)
+{
+    switch (event->key()) {
+    default:
+        break;
+    }
+
+    m_currentTool->keyReleaseEvent(event);
+    return true;
+}
+
+bool SGViewInspector::mouseDoubleClickEvent(QMouseEvent *event)
+{
+    m_currentTool->mouseDoubleClickEvent(event);
+    return true;
+}
+
+bool SGViewInspector::wheelEvent(QWheelEvent *event)
+{
+    m_currentTool->wheelEvent(event);
+    return true;
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h
new file mode 100644 (file)
index 0000000..2262307
--- /dev/null
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QSGVIEWINSPECTOR_H
+#define QSGVIEWINSPECTOR_H
+
+#include <QtCore/QObject>
+#include <QtCore/QWeakPointer>
+
+QT_BEGIN_NAMESPACE
+
+class QMouseEvent;
+class QKeyEvent;
+class QWheelEvent;
+
+class QSGView;
+class QSGItem;
+
+class SGAbstractTool;
+class SGSelectionTool;
+
+class SGViewInspector : public QObject
+{
+    Q_OBJECT
+public:
+    explicit SGViewInspector(QSGView *view, QObject *parent = 0);
+
+    QSGView *view() const { return m_view; }
+    QSGItem *overlay() const { return m_overlay; }
+
+    bool eventFilter(QObject *obj, QEvent *event);
+
+private:
+    bool leaveEvent(QEvent *);
+    bool mousePressEvent(QMouseEvent *event);
+    bool mouseMoveEvent(QMouseEvent *event);
+    bool mouseReleaseEvent(QMouseEvent *event);
+    bool keyPressEvent(QKeyEvent *event);
+    bool keyReleaseEvent(QKeyEvent *keyEvent);
+    bool mouseDoubleClickEvent(QMouseEvent *event);
+    bool wheelEvent(QWheelEvent *event);
+
+    QSGView *m_view;
+    QSGItem *m_overlay;
+    SGAbstractTool *m_currentTool;
+
+    SGSelectionTool *m_selectionTool;
+
+    bool m_designMode;
+};
+
+QT_END_NAMESPACE
+
+#endif // QSGVIEWINSPECTOR_H