summaryrefslogtreecommitdiffstats
path: root/src/plugins/qmltooling
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2011-06-08 15:47:47 (GMT)
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2011-06-23 14:38:41 (GMT)
commit4995fedcfbfc4c82412bdc126dfd37b81841354c (patch)
tree7f8e1a5710ffda72cf67300682f2c16a68ef74b3 /src/plugins/qmltooling
parent21af9f0be1dd0d9be6c3767074fdfbd54e3b8372 (diff)
downloadQt-4995fedcfbfc4c82412bdc126dfd37b81841354c.zip
Qt-4995fedcfbfc4c82412bdc126dfd37b81841354c.tar.gz
Qt-4995fedcfbfc4c82412bdc126dfd37b81841354c.tar.bz2
QmlInspector: Share code between QGV/SG based QML debugging
Introduced AbstractViewInspector, which forms the base class for QDeclarativeViewInspector and SGViewInspector and is where common code, like handling the protocol is placed. Some virtual and pure virtual functions exist which the subclasses will override or implement for QDeclarativeView/QSGView specific stuff. (cherry picked from commit 092c7fb12d32b3d1cd933707bf9e55156e2ae306 in Qt 5 / QtDeclarative, to make synchronizing future changes easier) Change-Id: Iff0e655538bb3753507fa76be378f3dbd68988fc Reviewed-by: Kai Koehne
Diffstat (limited to 'src/plugins/qmltooling')
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp490
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h155
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h4
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp580
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h56
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h35
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro2
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h5
8 files changed, 732 insertions, 595 deletions
diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp
new file mode 100644
index 0000000..fdec0e7
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp
@@ -0,0 +1,490 @@
+/****************************************************************************
+**
+** 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 "abstractviewinspector.h"
+
+#include "editor/qmltoolbar_p.h"
+#include "qdeclarativeinspectorprotocol.h"
+
+#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeComponent>
+#include <QtDeclarative/private/qdeclarativedebughelper_p.h>
+#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h"
+
+#include <QtGui/QVBoxLayout>
+#include <QtCore/QSettings>
+
+static inline void initEditorResource() { Q_INIT_RESOURCE(editor); }
+
+QT_BEGIN_NAMESPACE
+
+const char * const KEY_TOOLBOX_GEOMETRY = "toolBox/geometry";
+
+
+class ToolBox : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ToolBox(QWidget *parent = 0);
+ ~ToolBox();
+
+ QmlToolBar *toolBar() const { return m_toolBar; }
+
+private:
+ QSettings m_settings;
+ QmlToolBar *m_toolBar;
+};
+
+ToolBox::ToolBox(QWidget *parent)
+ : QWidget(parent, Qt::Tool)
+ , m_settings(QLatin1String("Nokia"), QLatin1String("QmlInspector"), this)
+ , m_toolBar(new QmlToolBar)
+{
+ setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::CustomizeWindowHint);
+ setWindowTitle(tr("Qt Quick Toolbox"));
+
+ QVBoxLayout *verticalLayout = new QVBoxLayout;
+ verticalLayout->setMargin(0);
+ verticalLayout->addWidget(m_toolBar);
+ setLayout(verticalLayout);
+
+ restoreGeometry(m_settings.value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray());
+}
+
+ToolBox::~ToolBox()
+{
+ m_settings.setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY), saveGeometry());
+}
+
+
+AbstractViewInspector::AbstractViewInspector(QObject *parent) :
+ QObject(parent),
+ m_toolBox(0),
+ m_showAppOnTop(false),
+ m_designModeBehavior(false),
+ m_animationPaused(false),
+ m_slowDownFactor(1.0),
+ m_debugService(0)
+{
+ initEditorResource();
+
+ m_debugService = QDeclarativeInspectorService::instance();
+ connect(m_debugService, SIGNAL(gotMessage(QByteArray)),
+ this, SLOT(handleMessage(QByteArray)));
+}
+
+void AbstractViewInspector::createQmlObject(const QString &qml, QObject *parent,
+ const QStringList &importList,
+ const QString &filename)
+{
+ if (!parent)
+ return;
+
+ QString imports;
+ foreach (const QString &s, importList) {
+ imports += s;
+ imports += QLatin1Char('\n');
+ }
+
+ QDeclarativeContext *parentContext = declarativeEngine()->contextForObject(parent);
+ QDeclarativeComponent component(declarativeEngine());
+ QByteArray constructedQml = QString(imports + qml).toLatin1();
+
+ component.setData(constructedQml, QUrl::fromLocalFile(filename));
+ QObject *newObject = component.create(parentContext);
+ if (newObject)
+ reparentQmlObject(newObject, parent);
+}
+
+void AbstractViewInspector::clearComponentCache()
+{
+ declarativeEngine()->clearComponentCache();
+}
+
+void AbstractViewInspector::setDesignModeBehavior(bool value)
+{
+ if (m_designModeBehavior == value)
+ return;
+
+ m_designModeBehavior = value;
+ emit designModeBehaviorChanged(value);
+ sendDesignModeBehavior(value);
+}
+
+void AbstractViewInspector::setAnimationSpeed(qreal slowDownFactor)
+{
+ Q_ASSERT(slowDownFactor > 0);
+ if (m_slowDownFactor == slowDownFactor)
+ return;
+
+ animationSpeedChangeRequested(slowDownFactor);
+ sendAnimationSpeed(slowDownFactor);
+}
+
+void AbstractViewInspector::setAnimationPaused(bool paused)
+{
+ if (m_animationPaused == paused)
+ return;
+
+ animationPausedChangeRequested(paused);
+ sendAnimationPaused(paused);
+}
+
+void AbstractViewInspector::animationSpeedChangeRequested(qreal factor)
+{
+ if (m_slowDownFactor != factor) {
+ m_slowDownFactor = factor;
+ emit animationSpeedChanged(factor);
+ }
+
+ const float effectiveFactor = m_animationPaused ? 0 : factor;
+ QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor);
+}
+
+void AbstractViewInspector::animationPausedChangeRequested(bool paused)
+{
+ if (m_animationPaused != paused) {
+ m_animationPaused = paused;
+ emit animationPausedChanged(paused);
+ }
+
+ const float effectiveFactor = paused ? 0 : m_slowDownFactor;
+ QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor);
+}
+
+void AbstractViewInspector::setShowAppOnTop(bool appOnTop)
+{
+ if (viewWidget()) {
+ QWidget *window = viewWidget()->window();
+ Qt::WindowFlags flags = window->windowFlags();
+ if (appOnTop)
+ flags |= Qt::WindowStaysOnTopHint;
+ else
+ flags &= ~Qt::WindowStaysOnTopHint;
+
+ window->setWindowFlags(flags);
+ window->show();
+ }
+
+ m_showAppOnTop = appOnTop;
+ sendShowAppOnTop(appOnTop);
+
+ emit showAppOnTopChanged(appOnTop);
+}
+
+void AbstractViewInspector::setToolBoxVisible(bool visible)
+{
+#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR)
+ if (!m_toolBox && visible)
+ createToolBox();
+ if (m_toolBox)
+ m_toolBox->setVisible(visible);
+#else
+ Q_UNUSED(visible)
+#endif
+}
+
+void AbstractViewInspector::createToolBox()
+{
+ m_toolBox = new ToolBox(viewWidget());
+
+ QmlToolBar *toolBar = m_toolBox->toolBar();
+
+ QObject::connect(this, SIGNAL(selectedColorChanged(QColor)),
+ toolBar, SLOT(setColorBoxColor(QColor)));
+
+ QObject::connect(this, SIGNAL(designModeBehaviorChanged(bool)),
+ toolBar, SLOT(setDesignModeBehavior(bool)));
+
+ QObject::connect(toolBar, SIGNAL(designModeBehaviorChanged(bool)),
+ this, SLOT(setDesignModeBehavior(bool)));
+ QObject::connect(toolBar, SIGNAL(animationSpeedChanged(qreal)), this, SLOT(setAnimationSpeed(qreal)));
+ QObject::connect(toolBar, SIGNAL(animationPausedChanged(bool)), this, SLOT(setAnimationPaused(bool)));
+ QObject::connect(toolBar, SIGNAL(colorPickerSelected()), this, SLOT(changeToColorPickerTool()));
+ QObject::connect(toolBar, SIGNAL(zoomToolSelected()), this, SLOT(changeToZoomTool()));
+ QObject::connect(toolBar, SIGNAL(selectToolSelected()), this, SLOT(changeToSingleSelectTool()));
+ QObject::connect(toolBar, SIGNAL(marqueeSelectToolSelected()),
+ this, SLOT(changeToMarqueeSelectTool()));
+
+ QObject::connect(toolBar, SIGNAL(applyChangesFromQmlFileSelected()),
+ this, SLOT(applyChangesFromClient()));
+
+ QObject::connect(this, SIGNAL(animationSpeedChanged(qreal)), toolBar, SLOT(setAnimationSpeed(qreal)));
+ QObject::connect(this, SIGNAL(animationPausedChanged(bool)), toolBar, SLOT(setAnimationPaused(bool)));
+
+ QObject::connect(this, SIGNAL(selectToolActivated()), toolBar, SLOT(activateSelectTool()));
+
+ // disabled features
+ //connect(d->m_toolBar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient()));
+ //connect(q, SIGNAL(resizeToolActivated()), d->m_toolBar, SLOT(activateSelectTool()));
+ //connect(q, SIGNAL(moveToolActivated()), d->m_toolBar, SLOT(activateSelectTool()));
+
+ QObject::connect(this, SIGNAL(colorPickerActivated()), toolBar, SLOT(activateColorPicker()));
+ QObject::connect(this, SIGNAL(zoomToolActivated()), toolBar, SLOT(activateZoom()));
+ QObject::connect(this, SIGNAL(marqueeSelectToolActivated()),
+ toolBar, SLOT(activateMarqueeSelectTool()));
+}
+
+void AbstractViewInspector::changeToColorPickerTool()
+{
+ changeTool(InspectorProtocol::ColorPickerTool);
+}
+
+void AbstractViewInspector::changeToZoomTool()
+{
+ changeTool(InspectorProtocol::ZoomTool);
+}
+
+void AbstractViewInspector::changeToSingleSelectTool()
+{
+ changeTool(InspectorProtocol::SelectTool);
+}
+
+void AbstractViewInspector::changeToMarqueeSelectTool()
+{
+ changeTool(InspectorProtocol::SelectMarqueeTool);
+}
+
+void AbstractViewInspector::handleMessage(const QByteArray &message)
+{
+ QDataStream ds(message);
+
+ InspectorProtocol::Message type;
+ ds >> type;
+
+ switch (type) {
+ case InspectorProtocol::SetCurrentObjects: {
+ int itemCount = 0;
+ ds >> itemCount;
+
+ QList<QObject*> selectedObjects;
+ for (int i = 0; i < itemCount; ++i) {
+ int debugId = -1;
+ ds >> debugId;
+ if (QObject *obj = QDeclarativeDebugService::objectForId(debugId))
+ selectedObjects << obj;
+ }
+
+ changeCurrentObjects(selectedObjects);
+ break;
+ }
+ case InspectorProtocol::Reload: {
+ reloadView();
+ break;
+ }
+ case InspectorProtocol::SetAnimationSpeed: {
+ qreal speed;
+ ds >> speed;
+ animationSpeedChangeRequested(speed);
+ break;
+ }
+ case InspectorProtocol::SetAnimationPaused: {
+ bool paused;
+ ds >> paused;
+ animationPausedChangeRequested(paused);
+ break;
+ }
+ case InspectorProtocol::ChangeTool: {
+ InspectorProtocol::Tool tool;
+ ds >> tool;
+ changeTool(tool);
+ break;
+ }
+ case InspectorProtocol::SetDesignMode: {
+ bool inDesignMode;
+ ds >> inDesignMode;
+ setDesignModeBehavior(inDesignMode);
+ break;
+ }
+ case InspectorProtocol::ShowAppOnTop: {
+ bool showOnTop;
+ ds >> showOnTop;
+ setShowAppOnTop(showOnTop);
+ break;
+ }
+ case InspectorProtocol::CreateObject: {
+ QString qml;
+ int parentId;
+ QString filename;
+ QStringList imports;
+ ds >> qml >> parentId >> imports >> filename;
+ createQmlObject(qml, QDeclarativeDebugService::objectForId(parentId),
+ imports, filename);
+ break;
+ }
+ case InspectorProtocol::DestroyObject: {
+ int debugId;
+ ds >> debugId;
+ if (QObject *obj = QDeclarativeDebugService::objectForId(debugId))
+ obj->deleteLater();
+ break;
+ }
+ case InspectorProtocol::MoveObject: {
+ int debugId, newParent;
+ ds >> debugId >> newParent;
+ reparentQmlObject(QDeclarativeDebugService::objectForId(debugId),
+ QDeclarativeDebugService::objectForId(newParent));
+ break;
+ }
+ case InspectorProtocol::ObjectIdList: {
+ int itemCount;
+ ds >> itemCount;
+ m_stringIdForObjectId.clear();
+ for (int i = 0; i < itemCount; ++i) {
+ int itemDebugId;
+ QString itemIdString;
+ ds >> itemDebugId
+ >> itemIdString;
+
+ m_stringIdForObjectId.insert(itemDebugId, itemIdString);
+ }
+ break;
+ }
+ case InspectorProtocol::ClearComponentCache: {
+ clearComponentCache();
+ break;
+ }
+ default:
+ qWarning() << "Warning: Not handling message:" << type;
+ }
+}
+
+void AbstractViewInspector::sendDesignModeBehavior(bool inDesignMode)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::SetDesignMode
+ << inDesignMode;
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendCurrentObjects(const QList<QObject*> &objects)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::CurrentObjectsChanged
+ << objects.length();
+
+ foreach (QObject *object, objects) {
+ int id = QDeclarativeDebugService::idForObject(object);
+ ds << id;
+ }
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendCurrentTool(Constants::DesignTool toolId)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::ToolChanged
+ << toolId;
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendAnimationSpeed(qreal slowDownFactor)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::AnimationSpeedChanged
+ << slowDownFactor;
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendAnimationPaused(bool paused)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::AnimationPausedChanged
+ << paused;
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendReloaded()
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::Reloaded;
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendShowAppOnTop(bool showAppOnTop)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::ShowAppOnTop << showAppOnTop;
+
+ m_debugService->sendMessage(message);
+}
+
+void AbstractViewInspector::sendColorChanged(const QColor &color)
+{
+ QByteArray message;
+ QDataStream ds(&message, QIODevice::WriteOnly);
+
+ ds << InspectorProtocol::ColorChanged
+ << color;
+
+ m_debugService->sendMessage(message);
+}
+
+QString AbstractViewInspector::idStringForObject(QObject *obj) const
+{
+ const int id = QDeclarativeDebugService::idForObject(obj);
+ return m_stringIdForObjectId.value(id);
+}
+
+QT_END_NAMESPACE
+
+#include "abstractviewinspector.moc"
diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h
new file mode 100644
index 0000000..b89a6eb
--- /dev/null
+++ b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h
@@ -0,0 +1,155 @@
+/****************************************************************************
+**
+** 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 ABSTRACTVIEWINSPECTOR_H
+#define ABSTRACTVIEWINSPECTOR_H
+
+#include <QtCore/QHash>
+#include <QtCore/QObject>
+#include <QtCore/QStringList>
+#include <QtGui/QColor>
+
+#include "qdeclarativeinspectorprotocol.h"
+#include "qmlinspectorconstants_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QDeclarativeEngine;
+class QDeclarativeInspectorService;
+class ToolBox;
+
+/*
+ * The common code between QSGView and QDeclarativeView inspectors lives here,
+ */
+class AbstractViewInspector : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit AbstractViewInspector(QObject *parent = 0);
+
+ virtual void changeCurrentObjects(const QList<QObject*> &objects) = 0;
+
+ virtual void reloadView() = 0;
+
+ void createQmlObject(const QString &qml, QObject *parent,
+ const QStringList &importList,
+ const QString &filename = QString());
+
+ virtual void reparentQmlObject(QObject *object, QObject *newParent) = 0;
+
+ virtual void changeTool(InspectorProtocol::Tool tool) = 0;
+
+ void clearComponentCache();
+
+ virtual QWidget *viewWidget() const = 0;
+ virtual QDeclarativeEngine *declarativeEngine() const = 0;
+
+
+ bool showAppOnTop() const { return m_showAppOnTop; }
+ bool designModeBehavior() const { return m_designModeBehavior; }
+
+ bool animationPaused() const { return m_animationPaused; }
+ qreal slowDownFactor() const { return m_slowDownFactor; }
+
+ void sendCurrentObjects(const QList<QObject*> &);
+ void sendAnimationSpeed(qreal slowDownFactor);
+ void sendAnimationPaused(bool paused);
+ void sendCurrentTool(Constants::DesignTool toolId);
+ void sendReloaded();
+ void sendShowAppOnTop(bool showAppOnTop);
+
+ QString idStringForObject(QObject *obj) const;
+
+public slots:
+ void sendDesignModeBehavior(bool inDesignMode);
+ void sendColorChanged(const QColor &color);
+
+ void changeToColorPickerTool();
+ void changeToZoomTool();
+ void changeToSingleSelectTool();
+ void changeToMarqueeSelectTool();
+
+ virtual void setDesignModeBehavior(bool value);
+
+ void setShowAppOnTop(bool appOnTop);
+
+ void setAnimationSpeed(qreal factor);
+ void setAnimationPaused(bool paused);
+
+signals:
+ void designModeBehaviorChanged(bool inDesignMode);
+ void showAppOnTopChanged(bool showAppOnTop);
+ void reloadRequested();
+ void marqueeSelectToolActivated();
+ void selectToolActivated();
+ void zoomToolActivated();
+ void colorPickerActivated();
+ void selectedColorChanged(const QColor &color);
+
+ void animationSpeedChanged(qreal factor);
+ void animationPausedChanged(bool paused);
+
+private slots:
+ void handleMessage(const QByteArray &message);
+
+private:
+ void animationSpeedChangeRequested(qreal factor);
+ void animationPausedChangeRequested(bool paused);
+
+ void setToolBoxVisible(bool visible);
+ void createToolBox();
+
+ ToolBox *m_toolBox;
+
+ bool m_showAppOnTop;
+ bool m_designModeBehavior;
+
+ bool m_animationPaused;
+ qreal m_slowDownFactor;
+
+ QHash<int, QString> m_stringIdForObjectId;
+ QDeclarativeInspectorService *m_debugService;
+};
+
+QT_END_NAMESPACE
+
+#endif // ABSTRACTVIEWINSPECTOR_H
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h
index 3e28643..e271c07 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h
@@ -47,7 +47,7 @@
QT_BEGIN_NAMESPACE
-class QDeclarativeViewInspector;
+class AbstractViewInspector;
class QDeclarativeInspectorPlugin : public QObject, public QDeclarativeInspectorInterface
{
@@ -63,7 +63,7 @@ public:
void deactivate();
private:
- QPointer<QDeclarativeViewInspector> m_inspector;
+ QPointer<AbstractViewInspector> m_inspector;
};
QT_END_NAMESPACE
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp
index 19bfdaa..be0422d 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp
+++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp
@@ -39,84 +39,28 @@
**
****************************************************************************/
-#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h"
-#include "QtDeclarative/private/qdeclarativedebughelper_p.h"
-
#include "qdeclarativeviewinspector_p.h"
#include "qdeclarativeviewinspector_p_p.h"
-#include "qdeclarativeinspectorprotocol.h"
#include "editor/liveselectiontool_p.h"
#include "editor/zoomtool_p.h"
#include "editor/colorpickertool_p.h"
#include "editor/livelayeritem_p.h"
#include "editor/boundingrecthighlighter_p.h"
-#include "editor/qmltoolbar_p.h"
#include <QtDeclarative/QDeclarativeItem>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeExpression>
#include <QtGui/QWidget>
-#include <QtGui/QVBoxLayout>
#include <QtGui/QMouseEvent>
#include <QtGui/QGraphicsObject>
#include <QtGui/QApplication>
-#include <QtCore/QSettings>
-
-static inline void initEditorResource() { Q_INIT_RESOURCE(editor); }
QT_BEGIN_NAMESPACE
-const char * const KEY_TOOLBOX_GEOMETRY = "toolBox/geometry";
-
-const int SceneChangeUpdateInterval = 5000;
-
-
-class ToolBox : public QWidget
-{
- Q_OBJECT
-
-public:
- ToolBox(QWidget *parent = 0);
- ~ToolBox();
-
- QmlToolBar *toolBar() const { return m_toolBar; }
-
-private:
- QSettings m_settings;
- QmlToolBar *m_toolBar;
-};
-
-ToolBox::ToolBox(QWidget *parent)
- : QWidget(parent, Qt::Tool)
- , m_settings(QLatin1String("Nokia"), QLatin1String("QmlInspector"), this)
- , m_toolBar(new QmlToolBar)
-{
- setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::CustomizeWindowHint);
- setWindowTitle(tr("Qt Quick Toolbox"));
-
- QVBoxLayout *verticalLayout = new QVBoxLayout;
- verticalLayout->setMargin(0);
- verticalLayout->addWidget(m_toolBar);
- setLayout(verticalLayout);
-
- restoreGeometry(m_settings.value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray());
-}
-
-ToolBox::~ToolBox()
-{
- m_settings.setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY), saveGeometry());
-}
-
-
QDeclarativeViewInspectorPrivate::QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *q) :
- q(q),
- designModeBehavior(false),
- showAppOnTop(false),
- animationPaused(false),
- slowDownFactor(1.0f),
- toolBox(0)
+ q(q)
{
}
@@ -126,11 +70,9 @@ QDeclarativeViewInspectorPrivate::~QDeclarativeViewInspectorPrivate()
QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view,
QObject *parent) :
- QObject(parent),
+ AbstractViewInspector(parent),
data(new QDeclarativeViewInspectorPrivate(this))
{
- initEditorResource();
-
data->view = view;
data->manipulatorLayer = new LiveLayerItem(view->scene());
data->selectionTool = new LiveSelectionTool(this);
@@ -144,10 +86,6 @@ QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view,
data->setViewport(data->view->viewport());
- data->debugService = QDeclarativeInspectorService::instance();
- connect(data->debugService, SIGNAL(gotMessage(QByteArray)),
- this, SLOT(handleMessage(QByteArray)));
-
connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)),
data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status)));
@@ -156,29 +94,57 @@ QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view,
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)),
this, SLOT(sendColorChanged(QColor)));
- data->_q_changeToSingleSelectTool();
+ changeTool(InspectorProtocol::SelectTool);
}
QDeclarativeViewInspector::~QDeclarativeViewInspector()
{
}
-void QDeclarativeViewInspectorPrivate::_q_setToolBoxVisible(bool visible)
+void QDeclarativeViewInspector::changeCurrentObjects(const QList<QObject*> &objects)
{
-#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR)
- if (!toolBox && visible)
- createToolBox();
- if (toolBox)
- toolBox->setVisible(visible);
-#else
- Q_UNUSED(visible)
-#endif
+ QList<QGraphicsItem*> items;
+ QList<QGraphicsObject*> gfxObjects;
+ foreach (QObject *obj, objects) {
+ if (QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(obj)) {
+ items << declarativeItem;
+ gfxObjects << declarativeItem;
+ }
+ }
+ if (designModeBehavior()) {
+ data->setSelectedItemsForTools(items);
+ data->clearHighlight();
+ data->highlight(gfxObjects);
+ }
}
-void QDeclarativeViewInspectorPrivate::_q_reloadView()
+void QDeclarativeViewInspector::reloadView()
{
- clearHighlight();
- emit q->reloadRequested();
+ data->clearHighlight();
+ emit reloadRequested();
+}
+
+void QDeclarativeViewInspector::changeTool(InspectorProtocol::Tool tool)
+{
+ switch (tool) {
+ case InspectorProtocol::ColorPickerTool:
+ data->changeToColorPickerTool();
+ break;
+ case InspectorProtocol::SelectMarqueeTool:
+ data->changeToMarqueeSelectTool();
+ break;
+ case InspectorProtocol::SelectTool:
+ data->changeToSingleSelectTool();
+ break;
+ case InspectorProtocol::ZoomTool:
+ data->changeToZoomTool();
+ break;
+ }
+}
+
+QDeclarativeEngine *QDeclarativeViewInspector::declarativeEngine() const
+{
+ return data->view->engine();
}
void QDeclarativeViewInspectorPrivate::setViewport(QWidget *widget)
@@ -268,7 +234,7 @@ bool QDeclarativeViewInspector::eventFilter(QObject *obj, QEvent *event)
bool QDeclarativeViewInspector::leaveEvent(QEvent * /*event*/)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
data->clearHighlight();
return true;
@@ -276,7 +242,7 @@ bool QDeclarativeViewInspector::leaveEvent(QEvent * /*event*/)
bool QDeclarativeViewInspector::mousePressEvent(QMouseEvent *event)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
data->cursorPos = event->pos();
data->currentTool->mousePressEvent(event);
@@ -285,7 +251,7 @@ bool QDeclarativeViewInspector::mousePressEvent(QMouseEvent *event)
bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event)
{
- if (!data->designModeBehavior) {
+ if (!designModeBehavior()) {
data->clearEditorItems();
return false;
}
@@ -307,7 +273,7 @@ bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event)
bool QDeclarativeViewInspector::mouseReleaseEvent(QMouseEvent *event)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
data->cursorPos = event->pos();
@@ -317,7 +283,7 @@ bool QDeclarativeViewInspector::mouseReleaseEvent(QMouseEvent *event)
bool QDeclarativeViewInspector::keyPressEvent(QKeyEvent *event)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
data->currentTool->keyPressEvent(event);
@@ -326,25 +292,25 @@ bool QDeclarativeViewInspector::keyPressEvent(QKeyEvent *event)
bool QDeclarativeViewInspector::keyReleaseEvent(QKeyEvent *event)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
switch (event->key()) {
case Qt::Key_V:
- data->_q_changeToSingleSelectTool();
+ changeTool(InspectorProtocol::SelectTool);
break;
// disabled because multiselection does not do anything useful without design mode
// case Qt::Key_M:
-// data->_q_changeToMarqueeSelectTool();
+// changeTool(InspectorProtocol::SelectMarqueeTool);
// break;
case Qt::Key_I:
- data->_q_changeToColorPickerTool();
+ changeTool(InspectorProtocol::ColorPickerTool);
break;
case Qt::Key_Z:
- data->_q_changeToZoomTool();
+ changeTool(InspectorProtocol::ZoomTool);
break;
case Qt::Key_Space:
- setAnimationPaused(!data->animationPaused);
+ setAnimationPaused(!animationPaused());
break;
default:
break;
@@ -354,35 +320,7 @@ bool QDeclarativeViewInspector::keyReleaseEvent(QKeyEvent *event)
return true;
}
-void QDeclarativeViewInspectorPrivate::_q_createQmlObject(const QString &qml, QObject *parent,
- const QStringList &importList,
- const QString &filename)
-{
- if (!parent)
- return;
-
- QString imports;
- foreach (const QString &s, importList) {
- imports += s;
- imports += QLatin1Char('\n');
- }
-
- QDeclarativeContext *parentContext = view->engine()->contextForObject(parent);
- QDeclarativeComponent component(view->engine(), q);
- QByteArray constructedQml = QString(imports + qml).toLatin1();
-
- component.setData(constructedQml, QUrl::fromLocalFile(filename));
- QObject *newObject = component.create(parentContext);
- if (newObject) {
- newObject->setParent(parent);
- QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent);
- QDeclarativeItem *newItem = qobject_cast<QDeclarativeItem*>(newObject);
- if (parentItem && newItem)
- newItem->setParentItem(parentItem);
- }
-}
-
-void QDeclarativeViewInspectorPrivate::_q_reparentQmlObject(QObject *object, QObject *newParent)
+void QDeclarativeViewInspector::reparentQmlObject(QObject *object, QObject *newParent)
{
if (!newParent)
return;
@@ -394,11 +332,6 @@ void QDeclarativeViewInspectorPrivate::_q_reparentQmlObject(QObject *object, QOb
item->setParentItem(newParentItem);
}
-void QDeclarativeViewInspectorPrivate::_q_clearComponentCache()
-{
- view->engine()->clearComponentCache();
-}
-
void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj)
{
QList<QGraphicsItem*> items = selectedItems();
@@ -409,7 +342,7 @@ void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj)
bool QDeclarativeViewInspector::mouseDoubleClickEvent(QMouseEvent * /*event*/)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
return true;
@@ -417,70 +350,12 @@ bool QDeclarativeViewInspector::mouseDoubleClickEvent(QMouseEvent * /*event*/)
bool QDeclarativeViewInspector::wheelEvent(QWheelEvent *event)
{
- if (!data->designModeBehavior)
+ if (!designModeBehavior())
return false;
data->currentTool->wheelEvent(event);
return true;
}
-void QDeclarativeViewInspector::setDesignModeBehavior(bool value)
-{
- emit designModeBehaviorChanged(value);
-
- if (data->toolBox)
- data->toolBox->toolBar()->setDesignModeBehavior(value);
- sendDesignModeBehavior(value);
-
- data->designModeBehavior = value;
-
- if (!data->designModeBehavior)
- data->clearEditorItems();
-}
-
-bool QDeclarativeViewInspector::designModeBehavior()
-{
- return data->designModeBehavior;
-}
-
-bool QDeclarativeViewInspector::showAppOnTop() const
-{
- return data->showAppOnTop;
-}
-
-void QDeclarativeViewInspector::setShowAppOnTop(bool appOnTop)
-{
- if (data->view) {
- QWidget *window = data->view->window();
- Qt::WindowFlags flags = window->windowFlags();
- if (appOnTop)
- flags |= Qt::WindowStaysOnTopHint;
- else
- flags &= ~Qt::WindowStaysOnTopHint;
-
- window->setWindowFlags(flags);
- window->show();
- }
-
- data->showAppOnTop = appOnTop;
- sendShowAppOnTop(appOnTop);
-
- emit showAppOnTopChanged(appOnTop);
-}
-
-void QDeclarativeViewInspectorPrivate::changeTool(Constants::DesignTool tool,
- Constants::ToolFlags /*flags*/)
-{
- switch (tool) {
- case Constants::SelectionToolMode:
- _q_changeToSingleSelectTool();
- break;
- case Constants::NoTool:
- default:
- currentTool = 0;
- break;
- }
-}
-
void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(const QList<QGraphicsItem *> &items)
{
foreach (const QWeakPointer<QGraphicsObject> &obj, currentSelection) {
@@ -542,7 +417,7 @@ QList<QGraphicsItem *> QDeclarativeViewInspector::selectedItems() const
return data->selectedItems();
}
-QDeclarativeView *QDeclarativeViewInspector::declarativeView()
+QDeclarativeView *QDeclarativeViewInspector::declarativeView() const
{
return data->view;
}
@@ -591,7 +466,7 @@ QList<QGraphicsItem*> QDeclarativeViewInspectorPrivate::selectableItems(
return filterForSelection(itemlist);
}
-void QDeclarativeViewInspectorPrivate::_q_changeToSingleSelectTool()
+void QDeclarativeViewInspectorPrivate::changeToSingleSelectTool()
{
currentToolMode = Constants::SelectionToolMode;
selectionTool->setRubberbandSelectionMode(false);
@@ -613,7 +488,7 @@ void QDeclarativeViewInspectorPrivate::changeToSelectTool()
currentTool->updateSelectedItems();
}
-void QDeclarativeViewInspectorPrivate::_q_changeToMarqueeSelectTool()
+void QDeclarativeViewInspectorPrivate::changeToMarqueeSelectTool()
{
changeToSelectTool();
currentToolMode = Constants::MarqueeSelectionToolMode;
@@ -623,7 +498,7 @@ void QDeclarativeViewInspectorPrivate::_q_changeToMarqueeSelectTool()
q->sendCurrentTool(Constants::MarqueeSelectionToolMode);
}
-void QDeclarativeViewInspectorPrivate::_q_changeToZoomTool()
+void QDeclarativeViewInspectorPrivate::changeToZoomTool()
{
currentToolMode = Constants::ZoomMode;
currentTool->clear();
@@ -634,7 +509,7 @@ void QDeclarativeViewInspectorPrivate::_q_changeToZoomTool()
q->sendCurrentTool(Constants::ZoomMode);
}
-void QDeclarativeViewInspectorPrivate::_q_changeToColorPickerTool()
+void QDeclarativeViewInspectorPrivate::changeToColorPickerTool()
{
if (currentTool == colorPickerTool)
return;
@@ -648,53 +523,14 @@ void QDeclarativeViewInspectorPrivate::_q_changeToColorPickerTool()
q->sendCurrentTool(Constants::ColorPickerMode);
}
-void QDeclarativeViewInspector::setAnimationSpeed(qreal slowDownFactor)
-{
- Q_ASSERT(slowDownFactor > 0);
- if (data->slowDownFactor == slowDownFactor)
- return;
-
- animationSpeedChangeRequested(slowDownFactor);
- sendAnimationSpeed(slowDownFactor);
-}
-
-void QDeclarativeViewInspector::setAnimationPaused(bool paused)
-{
- if (data->animationPaused == paused)
- return;
-
- animationPausedChangeRequested(paused);
- sendAnimationPaused(paused);
-}
-
-void QDeclarativeViewInspector::animationSpeedChangeRequested(qreal factor)
-{
- if (data->slowDownFactor != factor) {
- data->slowDownFactor = factor;
- emit animationSpeedChanged(factor);
- }
-
- const float effectiveFactor = data->animationPaused ? 0 : factor;
- QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor);
-}
-void QDeclarativeViewInspector::animationPausedChangeRequested(bool paused)
-{
- if (data->animationPaused != paused) {
- data->animationPaused = paused;
- emit animationPausedChanged(paused);
- }
-
- const float effectiveFactor = paused ? 0 : data->slowDownFactor;
- QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor);
-}
-
-
-void QDeclarativeViewInspectorPrivate::_q_applyChangesFromClient()
+static bool isEditorItem(QGraphicsItem *item)
{
+ return (item->type() == Constants::EditorItemType
+ || item->type() == Constants::ResizeHandleItemType
+ || item->data(Constants::EditorItemDataKey).toBool());
}
-
QList<QGraphicsItem*> QDeclarativeViewInspectorPrivate::filterForSelection(
QList<QGraphicsItem*> &itemlist) const
{
@@ -706,36 +542,12 @@ QList<QGraphicsItem*> QDeclarativeViewInspectorPrivate::filterForSelection(
return itemlist;
}
-bool QDeclarativeViewInspectorPrivate::isEditorItem(QGraphicsItem *item) const
-{
- return (item->type() == Constants::EditorItemType
- || item->type() == Constants::ResizeHandleItemType
- || item->data(Constants::EditorItemDataKey).toBool());
-}
-
void QDeclarativeViewInspectorPrivate::_q_onStatusChanged(QDeclarativeView::Status status)
{
if (status == QDeclarativeView::Ready)
q->sendReloaded();
}
-void QDeclarativeViewInspectorPrivate::_q_onCurrentObjectsChanged(QList<QObject*> objects)
-{
- QList<QGraphicsItem*> items;
- QList<QGraphicsObject*> gfxObjects;
- foreach (QObject *obj, objects) {
- if (QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(obj)) {
- items << declarativeItem;
- gfxObjects << declarativeItem;
- }
- }
- if (designModeBehavior) {
- setSelectedItemsForTools(items);
- clearHighlight();
- highlight(gfxObjects);
- }
-}
-
// adjusts bounding boxes on edges of screen to be visible
QRectF QDeclarativeViewInspector::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace)
{
@@ -758,264 +570,4 @@ QRectF QDeclarativeViewInspector::adjustToScreenBoundaries(const QRectF &boundin
return boundingRect;
}
-void QDeclarativeViewInspectorPrivate::createToolBox()
-{
- toolBox = new ToolBox(q->declarativeView());
-
- QmlToolBar *toolBar = toolBox->toolBar();
-
- QObject::connect(q, SIGNAL(selectedColorChanged(QColor)),
- toolBar, SLOT(setColorBoxColor(QColor)));
-
- QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)),
- toolBar, SLOT(setDesignModeBehavior(bool)));
-
- QObject::connect(toolBar, SIGNAL(designModeBehaviorChanged(bool)),
- q, SLOT(setDesignModeBehavior(bool)));
- QObject::connect(toolBar, SIGNAL(animationSpeedChanged(qreal)), q, SLOT(setAnimationSpeed(qreal)));
- QObject::connect(toolBar, SIGNAL(animationPausedChanged(bool)), q, SLOT(setAnimationPaused(bool)));
- QObject::connect(toolBar, SIGNAL(colorPickerSelected()), this, SLOT(_q_changeToColorPickerTool()));
- QObject::connect(toolBar, SIGNAL(zoomToolSelected()), this, SLOT(_q_changeToZoomTool()));
- QObject::connect(toolBar, SIGNAL(selectToolSelected()), this, SLOT(_q_changeToSingleSelectTool()));
- QObject::connect(toolBar, SIGNAL(marqueeSelectToolSelected()),
- this, SLOT(_q_changeToMarqueeSelectTool()));
-
- QObject::connect(toolBar, SIGNAL(applyChangesFromQmlFileSelected()),
- this, SLOT(_q_applyChangesFromClient()));
-
- QObject::connect(q, SIGNAL(animationSpeedChanged(qreal)), toolBar, SLOT(setAnimationSpeed(qreal)));
- QObject::connect(q, SIGNAL(animationPausedChanged(bool)), toolBar, SLOT(setAnimationPaused(bool)));
-
- QObject::connect(q, SIGNAL(selectToolActivated()), toolBar, SLOT(activateSelectTool()));
-
- // disabled features
- //connect(d->m_toolBar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient()));
- //connect(q, SIGNAL(resizeToolActivated()), d->m_toolBar, SLOT(activateSelectTool()));
- //connect(q, SIGNAL(moveToolActivated()), d->m_toolBar, SLOT(activateSelectTool()));
-
- QObject::connect(q, SIGNAL(colorPickerActivated()), toolBar, SLOT(activateColorPicker()));
- QObject::connect(q, SIGNAL(zoomToolActivated()), toolBar, SLOT(activateZoom()));
- QObject::connect(q, SIGNAL(marqueeSelectToolActivated()),
- toolBar, SLOT(activateMarqueeSelectTool()));
-}
-
-void QDeclarativeViewInspector::handleMessage(const QByteArray &message)
-{
- QDataStream ds(message);
-
- InspectorProtocol::Message type;
- ds >> type;
-
- switch (type) {
- case InspectorProtocol::SetCurrentObjects: {
- int itemCount = 0;
- ds >> itemCount;
-
- QList<QObject*> selectedObjects;
- for (int i = 0; i < itemCount; ++i) {
- int debugId = -1;
- ds >> debugId;
- if (QObject *obj = QDeclarativeDebugService::objectForId(debugId))
- selectedObjects << obj;
- }
-
- data->_q_onCurrentObjectsChanged(selectedObjects);
- break;
- }
- case InspectorProtocol::Reload: {
- data->_q_reloadView();
- break;
- }
- case InspectorProtocol::SetAnimationSpeed: {
- qreal speed;
- ds >> speed;
- animationSpeedChangeRequested(speed);
- break;
- }
- case InspectorProtocol::SetAnimationPaused: {
- bool paused;
- ds >> paused;
- animationPausedChangeRequested(paused);
- break;
- }
- case InspectorProtocol::ChangeTool: {
- InspectorProtocol::Tool tool;
- ds >> tool;
- switch (tool) {
- case InspectorProtocol::ColorPickerTool:
- data->_q_changeToColorPickerTool();
- break;
- case InspectorProtocol::SelectTool:
- data->_q_changeToSingleSelectTool();
- break;
- case InspectorProtocol::SelectMarqueeTool:
- data->_q_changeToMarqueeSelectTool();
- break;
- case InspectorProtocol::ZoomTool:
- data->_q_changeToZoomTool();
- break;
- default:
- qWarning() << "Warning: Unhandled tool:" << tool;
- }
- break;
- }
- case InspectorProtocol::SetDesignMode: {
- bool inDesignMode;
- ds >> inDesignMode;
- setDesignModeBehavior(inDesignMode);
- break;
- }
- case InspectorProtocol::ShowAppOnTop: {
- bool showOnTop;
- ds >> showOnTop;
- setShowAppOnTop(showOnTop);
- break;
- }
- case InspectorProtocol::CreateObject: {
- QString qml;
- int parentId;
- QString filename;
- QStringList imports;
- ds >> qml >> parentId >> imports >> filename;
- data->_q_createQmlObject(qml, QDeclarativeDebugService::objectForId(parentId),
- imports, filename);
- break;
- }
- case InspectorProtocol::DestroyObject: {
- int debugId;
- ds >> debugId;
- if (QObject* obj = QDeclarativeDebugService::objectForId(debugId))
- obj->deleteLater();
- break;
- }
- case InspectorProtocol::MoveObject: {
- int debugId, newParent;
- ds >> debugId >> newParent;
- data->_q_reparentQmlObject(QDeclarativeDebugService::objectForId(debugId),
- QDeclarativeDebugService::objectForId(newParent));
- break;
- }
- case InspectorProtocol::ObjectIdList: {
- int itemCount;
- ds >> itemCount;
- data->stringIdForObjectId.clear();
- for (int i = 0; i < itemCount; ++i) {
- int itemDebugId;
- QString itemIdString;
- ds >> itemDebugId
- >> itemIdString;
-
- data->stringIdForObjectId.insert(itemDebugId, itemIdString);
- }
- break;
- }
- case InspectorProtocol::ClearComponentCache: {
- data->_q_clearComponentCache();
- break;
- }
- default:
- qWarning() << "Warning: Not handling message:" << type;
- }
-}
-
-void QDeclarativeViewInspector::sendDesignModeBehavior(bool inDesignMode)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::SetDesignMode
- << inDesignMode;
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendCurrentObjects(const QList<QObject*> &objects)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::CurrentObjectsChanged
- << objects.length();
-
- foreach (QObject *object, objects) {
- int id = QDeclarativeDebugService::idForObject(object);
- ds << id;
- }
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendCurrentTool(Constants::DesignTool toolId)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::ToolChanged
- << toolId;
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendAnimationSpeed(qreal slowDownFactor)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::AnimationSpeedChanged
- << slowDownFactor;
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendAnimationPaused(bool paused)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::AnimationPausedChanged
- << paused;
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendReloaded()
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::Reloaded;
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendShowAppOnTop(bool showAppOnTop)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::ShowAppOnTop << showAppOnTop;
-
- data->debugService->sendMessage(message);
-}
-
-void QDeclarativeViewInspector::sendColorChanged(const QColor &color)
-{
- QByteArray message;
- QDataStream ds(&message, QIODevice::WriteOnly);
-
- ds << InspectorProtocol::ColorChanged
- << color;
-
- data->debugService->sendMessage(message);
-}
-
-QString QDeclarativeViewInspector::idStringForObject(QObject *obj) const
-{
- int id = QDeclarativeDebugService::idForObject(obj);
- QString idString = data->stringIdForObjectId.value(id, QString());
- return idString;
-}
-
QT_END_NAMESPACE
-
-#include "qdeclarativeviewinspector.moc"
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h
index 4efa093..c89a259 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h
@@ -43,7 +43,9 @@
#define QDECLARATIVEVIEWINSPECTOR_P_H
#include <private/qdeclarativeglobal_p.h>
+
#include "qmlinspectorconstants_p.h"
+#include "abstractviewinspector.h"
#include <QtCore/QScopedPointer>
#include <QtDeclarative/QDeclarativeView>
@@ -60,7 +62,7 @@ QT_MODULE(Declarative)
class QDeclarativeViewInspectorPrivate;
-class QDeclarativeViewInspector : public QObject
+class QDeclarativeViewInspector : public AbstractViewInspector
{
Q_OBJECT
@@ -68,49 +70,21 @@ public:
explicit QDeclarativeViewInspector(QDeclarativeView *view, QObject *parent = 0);
~QDeclarativeViewInspector();
+ // AbstractViewInspector
+ void changeCurrentObjects(const QList<QObject*> &objects);
+ void reloadView();
+ void reparentQmlObject(QObject *object, QObject *newParent);
+ void changeTool(InspectorProtocol::Tool tool);
+ QWidget *viewWidget() const { return declarativeView(); }
+ QDeclarativeEngine *declarativeEngine() const;
+
void setSelectedItems(QList<QGraphicsItem *> items);
QList<QGraphicsItem *> selectedItems() const;
- QDeclarativeView *declarativeView();
+ QDeclarativeView *declarativeView() const;
QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace);
- bool showAppOnTop() const;
-
- void sendDesignModeBehavior(bool inDesignMode);
- void sendCurrentObjects(const QList<QObject*> &);
- void sendAnimationSpeed(qreal slowDownFactor);
- void sendAnimationPaused(bool paused);
- void sendCurrentTool(Constants::DesignTool toolId);
- void sendReloaded();
- void sendShowAppOnTop(bool showAppOnTop);
-
- QString idStringForObject(QObject *obj) const;
-
-public Q_SLOTS:
- void sendColorChanged(const QColor &color);
-
- void setDesignModeBehavior(bool value);
- bool designModeBehavior();
-
- void setShowAppOnTop(bool appOnTop);
-
- void setAnimationSpeed(qreal factor);
- void setAnimationPaused(bool paused);
-
-Q_SIGNALS:
- void designModeBehaviorChanged(bool inDesignMode);
- void showAppOnTopChanged(bool showAppOnTop);
- void reloadRequested();
- void marqueeSelectToolActivated();
- void selectToolActivated();
- void zoomToolActivated();
- void colorPickerActivated();
- void selectedColorChanged(const QColor &color);
-
- void animationSpeedChanged(qreal factor);
- void animationPausedChanged(bool paused);
-
protected:
bool eventFilter(QObject *obj, QEvent *event);
@@ -125,12 +99,6 @@ protected:
void setSelectedItemsForTools(QList<QGraphicsItem *> items);
-private slots:
- void handleMessage(const QByteArray &message);
-
- void animationSpeedChangeRequested(qreal factor);
- void animationPausedChangeRequested(bool paused);
-
private:
Q_DISABLE_COPY(QDeclarativeViewInspector)
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h
index 11cbe0f..a412df3 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h
@@ -61,7 +61,6 @@ class ZoomTool;
class ColorPickerTool;
class LiveLayerItem;
class BoundingRectHighlighter;
-class ToolBox;
class AbstractLiveEditTool;
class QDeclarativeViewInspectorPrivate : public QObject
@@ -73,9 +72,7 @@ public:
QDeclarativeView *view;
QDeclarativeViewInspector *q;
- QDeclarativeInspectorService *debugService;
QWeakPointer<QWidget> viewport;
- QHash<int, QString> stringIdForObjectId;
QPointF cursorPos;
QList<QWeakPointer<QGraphicsObject> > currentSelection;
@@ -90,18 +87,9 @@ public:
BoundingRectHighlighter *boundingRectHighlighter;
- bool designModeBehavior;
- bool showAppOnTop;
-
- bool animationPaused;
- qreal slowDownFactor;
-
- ToolBox *toolBox;
-
void setViewport(QWidget *widget);
void clearEditorItems();
- void createToolBox();
void changeToSelectTool();
QList<QGraphicsItem*> filterForSelection(QList<QGraphicsItem*> &itemlist) const;
@@ -113,32 +101,19 @@ public:
void setSelectedItems(const QList<QGraphicsItem *> &items);
QList<QGraphicsItem *> selectedItems() const;
- void changeTool(Constants::DesignTool tool,
- Constants::ToolFlags flags = Constants::NoToolFlags);
-
void clearHighlight();
void highlight(const QList<QGraphicsObject *> &item);
inline void highlight(QGraphicsObject *item)
{ highlight(QList<QGraphicsObject*>() << item); }
- bool isEditorItem(QGraphicsItem *item) const;
+ void changeToSingleSelectTool();
+ void changeToMarqueeSelectTool();
+ void changeToZoomTool();
+ void changeToColorPickerTool();
public slots:
- void _q_setToolBoxVisible(bool visible);
-
- void _q_reloadView();
void _q_onStatusChanged(QDeclarativeView::Status status);
- void _q_onCurrentObjectsChanged(QList<QObject*> objects);
- void _q_applyChangesFromClient();
- void _q_createQmlObject(const QString &qml, QObject *parent,
- const QStringList &imports, const QString &filename = QString());
- void _q_reparentQmlObject(QObject *, QObject *);
-
- void _q_changeToSingleSelectTool();
- void _q_changeToMarqueeSelectTool();
- void _q_changeToZoomTool();
- void _q_changeToColorPickerTool();
- void _q_clearComponentCache();
+
void _q_removeFromSelection(QObject *);
public:
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro
index f8d7ee8..fd2a744 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro
+++ b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro
@@ -7,6 +7,7 @@ QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/qmltooling
QTDIR_build:REQUIRES += "contains(QT_CONFIG, declarative)"
SOURCES += \
+ abstractviewinspector.cpp \
qdeclarativeinspectorplugin.cpp \
qdeclarativeviewinspector.cpp \
editor/abstractliveedittool.cpp \
@@ -24,6 +25,7 @@ SOURCES += \
editor/toolbarcolorbox.cpp
HEADERS += \
+ abstractviewinspector.h \
qdeclarativeinspectorplugin.h \
qdeclarativeinspectorprotocol.h \
qdeclarativeviewinspector_p.h \
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h b/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h
index 40ec325..9f6b116 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h
@@ -62,11 +62,6 @@ enum DesignTool {
ZoomMode = 6
};
-enum ToolFlags {
- NoToolFlags = 0,
- UseCursorPos = 1
-};
-
static const int DragStartTime = 50;
static const int DragStartDistance = 20;