diff options
author | Martin Jones <martin.jones@nokia.com> | 2011-07-05 00:34:57 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2011-07-05 00:34:57 (GMT) |
commit | d4740963fa6284407c74c49ea587b0511c9bc4c9 (patch) | |
tree | 2786c28b05f6a6a29fede3a4617a433ec4b21687 /src/plugins | |
parent | b1c746eefffc84403e9a7c0ea9080408d6428bc3 (diff) | |
parent | 7d31d54a5fa9cea33013da490cd1dfa37c099fd8 (diff) | |
download | Qt-d4740963fa6284407c74c49ea587b0511c9bc4c9.zip Qt-d4740963fa6284407c74c49ea587b0511c9bc4c9.tar.gz Qt-d4740963fa6284407c74c49ea587b0511c9bc4c9.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml-review
Diffstat (limited to 'src/plugins')
39 files changed, 1315 insertions, 1211 deletions
diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp new file mode 100644 index 0000000..39ced2a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp @@ -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 "abstracttool.h" + +#include "abstractviewinspector.h" + +namespace QmlJSDebugger { + +AbstractTool::AbstractTool(AbstractViewInspector *inspector) : + QObject(inspector), + m_inspector(inspector) +{ +} + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h new file mode 100644 index 0000000..0a216bf --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 ABSTRACTTOOL_H +#define ABSTRACTTOOL_H + +#include <QtCore/QObject> + +QT_BEGIN_NAMESPACE +class QMouseEvent; +class QKeyEvent; +class QWheelEvent; +QT_END_NAMESPACE + +namespace QmlJSDebugger { + +class AbstractViewInspector; + +class AbstractTool : public QObject +{ + Q_OBJECT + +public: + explicit AbstractTool(AbstractViewInspector *inspector); + + AbstractViewInspector *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: + AbstractViewInspector *m_inspector; +}; + +} // namespace QmlJSDebugger + +#endif // ABSTRACTTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp new file mode 100644 index 0000000..3323d54 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp @@ -0,0 +1,611 @@ +/**************************************************************************** +** +** 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 "abstracttool.h" +#include "editor/qmltoolbar.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 <QtGui/QMouseEvent> +#include <QtCore/QSettings> + +static inline void initEditorResource() { Q_INIT_RESOURCE(editor); } + +namespace QmlJSDebugger { + +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_currentTool(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); +} + +bool AbstractViewInspector::eventFilter(QObject *obj, QEvent *event) +{ + if (!designModeBehavior()) + 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 AbstractViewInspector::leaveEvent(QEvent *event) +{ + m_currentTool->leaveEvent(event); + return true; +} + +bool AbstractViewInspector::mousePressEvent(QMouseEvent *event) +{ + m_currentTool->mousePressEvent(event); + return true; +} + +bool AbstractViewInspector::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons()) { + m_currentTool->mouseMoveEvent(event); + } else { + m_currentTool->hoverMoveEvent(event); + } + return true; +} + +bool AbstractViewInspector::mouseReleaseEvent(QMouseEvent *event) +{ + m_currentTool->mouseReleaseEvent(event); + return true; +} + +bool AbstractViewInspector::keyPressEvent(QKeyEvent *event) +{ + m_currentTool->keyPressEvent(event); + return true; +} + +bool AbstractViewInspector::keyReleaseEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_V: + changeTool(InspectorProtocol::SelectTool); + break; +// disabled because multiselection does not do anything useful without design mode +// case Qt::Key_M: +// changeTool(InspectorProtocol::SelectMarqueeTool); +// break; + case Qt::Key_I: + changeTool(InspectorProtocol::ColorPickerTool); + break; + case Qt::Key_Z: + changeTool(InspectorProtocol::ZoomTool); + break; + case Qt::Key_Space: + setAnimationPaused(!animationPaused()); + break; + default: + break; + } + + m_currentTool->keyReleaseEvent(event); + return true; +} + +bool AbstractViewInspector::mouseDoubleClickEvent(QMouseEvent *event) +{ + m_currentTool->mouseDoubleClickEvent(event); + return true; +} + +bool AbstractViewInspector::wheelEvent(QWheelEvent *event) +{ + m_currentTool->wheelEvent(event); + return true; +} + +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); +} + +} // namespace QmlJSDebugger + +#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..7202bcc --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h @@ -0,0 +1,178 @@ +/**************************************************************************** +** +** 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.h" + +QT_BEGIN_NAMESPACE +class QDeclarativeEngine; +class QDeclarativeInspectorService; +class QKeyEvent; +class QMouseEvent; +class QWheelEvent; +QT_END_NAMESPACE + +namespace QmlJSDebugger { + +class AbstractTool; +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); + +protected: + bool eventFilter(QObject *, QEvent *); + + virtual bool leaveEvent(QEvent *); + virtual bool mousePressEvent(QMouseEvent *event); + virtual bool mouseMoveEvent(QMouseEvent *event); + virtual bool mouseReleaseEvent(QMouseEvent *event); + virtual bool keyPressEvent(QKeyEvent *event); + virtual bool keyReleaseEvent(QKeyEvent *keyEvent); + virtual bool mouseDoubleClickEvent(QMouseEvent *event); + virtual bool wheelEvent(QWheelEvent *event); + + AbstractTool *currentTool() const { return m_currentTool; } + void setCurrentTool(AbstractTool *tool) { m_currentTool = tool; } + +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; + AbstractTool *m_currentTool; + + bool m_showAppOnTop; + bool m_designModeBehavior; + + bool m_animationPaused; + qreal m_slowDownFactor; + + QHash<int, QString> m_stringIdForObjectId; + QDeclarativeInspectorService *m_debugService; +}; + +} // namespace QmlJSDebugger + +#endif // ABSTRACTVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp index 36e6ba0..dce147c 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "abstractliveedittool_p.h" -#include "../qdeclarativeviewinspector_p_p.h" +#include "abstractliveedittool.h" +#include "../qdeclarativeviewinspector_p.h" #include <QDeclarativeEngine> @@ -48,10 +48,10 @@ #include <QGraphicsItem> #include <QDeclarativeItem> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewInspector *editorView) - : QObject(editorView), m_inspector(editorView) + : AbstractTool(editorView) { } @@ -62,12 +62,12 @@ AbstractLiveEditTool::~AbstractLiveEditTool() QDeclarativeViewInspector *AbstractLiveEditTool::inspector() const { - return m_inspector; + return static_cast<QDeclarativeViewInspector*>(AbstractTool::inspector()); } QDeclarativeView *AbstractLiveEditTool::view() const { - return m_inspector->declarativeView(); + return inspector()->declarativeView(); } QGraphicsScene* AbstractLiveEditTool::scene() const @@ -175,7 +175,7 @@ QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(gfxObject); if (declarativeItem) { - objectStringId = m_inspector->idStringForObject(declarativeItem); + objectStringId = inspector()->idStringForObject(declarativeItem); } if (!objectStringId.isEmpty()) { @@ -192,4 +192,5 @@ QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) return constructedName; } -QT_END_NAMESPACE + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.h index 17eb6ea..04b5f4e 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/abstractliveedittool.h @@ -43,7 +43,7 @@ #define ABSTRACTLIVEEDITTOOL_H #include <QtCore/QList> -#include <QtCore/QObject> +#include "../abstracttool.h" QT_BEGIN_NAMESPACE class QMouseEvent; @@ -56,15 +56,11 @@ class QWheelEvent; class QDeclarativeView; QT_END_NAMESPACE -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class QDeclarativeViewInspector; -class AbstractLiveEditTool : public QObject +class AbstractLiveEditTool : public AbstractTool { Q_OBJECT public: @@ -72,16 +68,8 @@ public: virtual ~AbstractLiveEditTool(); - virtual void mousePressEvent(QMouseEvent *event) = 0; - virtual void mouseMoveEvent(QMouseEvent *event) = 0; - virtual void mouseReleaseEvent(QMouseEvent *event) = 0; - virtual void mouseDoubleClickEvent(QMouseEvent *event) = 0; + void leaveEvent(QEvent *) {} - virtual void hoverMoveEvent(QMouseEvent *event) = 0; - virtual void wheelEvent(QWheelEvent *event) = 0; - - virtual void keyPressEvent(QKeyEvent *event) = 0; - virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0; virtual void itemsAboutToRemoved(const QList<QGraphicsItem*> &itemList) = 0; virtual void clear() = 0; @@ -108,12 +96,9 @@ protected: QGraphicsScene *scene() const; private: - QDeclarativeViewInspector *m_inspector; QList<QGraphicsItem*> m_itemList; }; -QT_END_NAMESPACE - -QT_END_HEADER +} #endif // ABSTRACTLIVEEDITTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter.cpp index 3f95005..da9f442 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter.cpp @@ -39,10 +39,10 @@ ** ****************************************************************************/ -#include "boundingrecthighlighter_p.h" +#include "boundingrecthighlighter.h" -#include "../qdeclarativeviewinspector_p.h" -#include "../qmlinspectorconstants_p.h" +#include "../qdeclarativeviewinspector.h" +#include "../qmlinspectorconstants.h" #include <QtGui/QGraphicsPolygonItem> @@ -50,7 +50,7 @@ #include <QtCore/QObject> #include <QtCore/QDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { BoundingBox::BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, QObject *parent) @@ -236,4 +236,5 @@ void BoundingRectHighlighter::refresh() highlightAll(); } -QT_END_NAMESPACE + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter.h index e2928f7..81883ee 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/boundingrecthighlighter.h @@ -42,7 +42,7 @@ #ifndef BOUNDINGRECTHIGHLIGHTER_H #define BOUNDINGRECTHIGHLIGHTER_H -#include "livelayeritem_p.h" +#include "livelayeritem.h" #include <QtCore/QObject> #include <QtCore/QWeakPointer> @@ -53,11 +53,7 @@ QT_FORWARD_DECLARE_CLASS(QWidget) QT_FORWARD_DECLARE_CLASS(QStyleOptionGraphicsItem) QT_FORWARD_DECLARE_CLASS(QTimer) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class QDeclarativeViewInspector; class BoundingBox; @@ -114,8 +110,6 @@ public: int type() const; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // BOUNDINGRECTHIGHLIGHTER_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool.cpp index bdae3d8..72e1380 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "colorpickertool_p.h" +#include "colorpickertool.h" -#include "../qdeclarativeviewinspector_p.h" +#include "../qdeclarativeviewinspector.h" #include <QtGui/QMouseEvent> #include <QtGui/QKeyEvent> @@ -51,7 +51,7 @@ #include <QtGui/QApplication> #include <QtGui/QPalette> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { ColorPickerTool::ColorPickerTool(QDeclarativeViewInspector *view) : AbstractLiveEditTool(view) @@ -61,56 +61,23 @@ ColorPickerTool::ColorPickerTool(QDeclarativeViewInspector *view) : ColorPickerTool::~ColorPickerTool() { - } -void ColorPickerTool::mousePressEvent(QMouseEvent * /*event*/) -{ -} - -void ColorPickerTool::mouseMoveEvent(QMouseEvent *event) +void ColorPickerTool::mousePressEvent(QMouseEvent *event) { pickColor(event->pos()); } -void ColorPickerTool::mouseReleaseEvent(QMouseEvent *event) +void ColorPickerTool::mouseMoveEvent(QMouseEvent *event) { pickColor(event->pos()); } -void ColorPickerTool::mouseDoubleClickEvent(QMouseEvent * /*event*/) -{ -} - - -void ColorPickerTool::hoverMoveEvent(QMouseEvent * /*event*/) -{ -} - -void ColorPickerTool::keyPressEvent(QKeyEvent * /*event*/) -{ -} - -void ColorPickerTool::keyReleaseEvent(QKeyEvent * /*keyEvent*/) -{ -} -void ColorPickerTool::wheelEvent(QWheelEvent * /*event*/) -{ -} - -void ColorPickerTool::itemsAboutToRemoved(const QList<QGraphicsItem*> &/*itemList*/) -{ -} - void ColorPickerTool::clear() { view()->setCursor(Qt::CrossCursor); } -void ColorPickerTool::selectedItemsChanged(const QList<QGraphicsItem*> &/*itemList*/) -{ -} - void ColorPickerTool::pickColor(const QPoint &pos) { QRgb fillColor = view()->backgroundBrush().color().rgb(); @@ -128,4 +95,4 @@ void ColorPickerTool::pickColor(const QPoint &pos) emit selectedColorChanged(m_selectedColor); } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool.h index 580c175..a28ffea 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/colorpickertool.h @@ -42,17 +42,13 @@ #ifndef COLORPICKERTOOL_H #define COLORPICKERTOOL_H -#include "abstractliveedittool_p.h" +#include "abstractliveedittool.h" #include <QtGui/QColor> QT_FORWARD_DECLARE_CLASS(QPoint) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class ColorPickerTool : public AbstractLiveEditTool { @@ -64,17 +60,17 @@ public: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *) {} + void mouseDoubleClickEvent(QMouseEvent *) {} - void hoverMoveEvent(QMouseEvent *event); + void hoverMoveEvent(QMouseEvent *) {} - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *keyEvent); + void keyPressEvent(QKeyEvent *) {} + void keyReleaseEvent(QKeyEvent *) {} - void wheelEvent(QWheelEvent *event); + void wheelEvent(QWheelEvent *) {} - void itemsAboutToRemoved(const QList<QGraphicsItem*> &itemList); + void itemsAboutToRemoved(const QList<QGraphicsItem*> &) {} void clear(); @@ -82,8 +78,7 @@ signals: void selectedColorChanged(const QColor &color); protected: - - void selectedItemsChanged(const QList<QGraphicsItem*> &itemList); + void selectedItemsChanged(const QList<QGraphicsItem*> &) {} private: void pickColor(const QPoint &pos); @@ -92,8 +87,6 @@ private: QColor m_selectedColor; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // COLORPICKERTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem.cpp index c28893e..fb7118f 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem.cpp @@ -39,13 +39,13 @@ ** ****************************************************************************/ -#include "livelayeritem_p.h" +#include "livelayeritem.h" -#include "../qmlinspectorconstants_p.h" +#include "../qmlinspectorconstants.h" #include <QGraphicsScene> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { LiveLayerItem::LiveLayerItem(QGraphicsScene* scene) : QGraphicsObject() @@ -89,4 +89,4 @@ QList<QGraphicsItem*> LiveLayerItem::findAllChildItems(const QGraphicsItem *item return itemList; } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem.h index da622e1..4dccc0b 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/livelayeritem.h @@ -44,11 +44,7 @@ #include <QtGui/QGraphicsObject> -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class LiveLayerItem : public QGraphicsObject { @@ -66,8 +62,6 @@ protected: QList<QGraphicsItem*> findAllChildItems(const QGraphicsItem *item) const; }; -QT_END_NAMESPACE - -QT_END_HEADER +} #endif // LIVELAYERITEM_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator.cpp index d32847d..b08682a 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator.cpp @@ -39,15 +39,15 @@ ** ****************************************************************************/ -#include "liverubberbandselectionmanipulator_p.h" +#include "liverubberbandselectionmanipulator.h" -#include "../qdeclarativeviewinspector_p_p.h" +#include "../qdeclarativeviewinspector_p.h" #include <QtGui/QGraphicsItem> #include <QtCore/QDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeViewInspector *editorView) @@ -162,4 +162,4 @@ bool LiveRubberBandSelectionManipulator::isActive() const return m_isActive; } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator.h index 9abcb2b..aa15a34 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liverubberbandselectionmanipulator.h @@ -42,17 +42,13 @@ #ifndef RUBBERBANDSELECTIONMANIPULATOR_H #define RUBBERBANDSELECTIONMANIPULATOR_H -#include "liveselectionrectangle_p.h" +#include "liveselectionrectangle.h" #include <QtCore/QPointF> QT_FORWARD_DECLARE_CLASS(QGraphicsItem) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class QDeclarativeViewInspector; @@ -95,8 +91,6 @@ private: bool m_isActive; }; -QT_END_NAMESPACE - -QT_END_HEADER +} #endif // RUBBERBANDSELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator.cpp index 4450fc5..c57bc0e 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator.cpp @@ -39,17 +39,17 @@ ** ****************************************************************************/ -#include "liveselectionindicator_p.h" +#include "liveselectionindicator.h" -#include "../qdeclarativeviewinspector_p_p.h" -#include "../qmlinspectorconstants_p.h" +#include "../qdeclarativeviewinspector_p.h" +#include "../qmlinspectorconstants.h" #include <QtGui/QGraphicsRectItem> #include <QtGui/QGraphicsObject> #include <QtGui/QGraphicsScene> #include <QtGui/QPen> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, QGraphicsObject *layerItem) @@ -114,4 +114,5 @@ void LiveSelectionIndicator::setItems(const QList<QWeakPointer<QGraphicsObject> } } -QT_END_NAMESPACE +} //namespace QmlJSDebugger + diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator.h index fa6eb30..7b8cc12 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionindicator.h @@ -52,11 +52,7 @@ class QGraphicsItem; class QPolygonF; QT_END_NAMESPACE -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class QDeclarativeViewInspector; @@ -79,8 +75,6 @@ private: QDeclarativeViewInspector *m_view; }; -QT_END_NAMESPACE - -QT_END_HEADER +} #endif // LIVESELECTIONINDICATOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle.cpp index 267079a..4e14458 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "liveselectionrectangle_p.h" +#include "liveselectionrectangle.h" -#include "../qmlinspectorconstants_p.h" +#include "../qmlinspectorconstants.h" #include <QtGui/QPen> #include <QtGui/QGraphicsRectItem> @@ -52,7 +52,7 @@ #include <cmath> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { class SelectionRectShape : public QGraphicsRectItem { @@ -110,4 +110,4 @@ void LiveSelectionRectangle::setRect(const QPointF &firstPoint, m_controlShape->setRect(rect); } -QT_END_NAMESPACE +} diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle.h index 5da9fb8..730cca5 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectionrectangle.h @@ -49,11 +49,7 @@ QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem) QT_FORWARD_DECLARE_CLASS(QPointF) QT_FORWARD_DECLARE_CLASS(QRectF) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class LiveSelectionRectangle { @@ -76,8 +72,6 @@ private: QWeakPointer<QGraphicsObject> m_layerItem; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // LIVESELECTIONRECTANGLE_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool.cpp index c55cba3..6085d81 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool.cpp @@ -39,10 +39,10 @@ ** ****************************************************************************/ -#include "liveselectiontool_p.h" -#include "livelayeritem_p.h" +#include "liveselectiontool.h" +#include "livelayeritem.h" -#include "../qdeclarativeviewinspector_p_p.h" +#include "../qdeclarativeviewinspector_p.h" #include <QtGui/QApplication> #include <QtGui/QWheelEvent> @@ -57,7 +57,7 @@ #include <QtCore/QDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { LiveSelectionTool::LiveSelectionTool(QDeclarativeViewInspector *editorView) : AbstractLiveEditTool(editorView), @@ -132,7 +132,7 @@ void LiveSelectionTool::mousePressEvent(QMouseEvent *event) } } -void LiveSelectionTool::createContextMenu(QList<QGraphicsItem*> itemList, QPoint globalPos) +void LiveSelectionTool::createContextMenu(const QList<QGraphicsItem*> &itemList, QPoint globalPos) { QMenu contextMenu; connect(&contextMenu, SIGNAL(hovered(QAction*)), @@ -143,7 +143,6 @@ void LiveSelectionTool::createContextMenu(QList<QGraphicsItem*> itemList, QPoint contextMenu.addAction(tr("Items")); contextMenu.addSeparator(); int shortcutKey = Qt::Key_1; - bool addKeySequence = true; int i = 0; foreach (QGraphicsItem * const item, itemList) { @@ -158,12 +157,11 @@ void LiveSelectionTool::createContextMenu(QList<QGraphicsItem*> itemList, QPoint } elementAction->setData(i); - if (addKeySequence) - elementAction->setShortcut(QKeySequence(shortcutKey)); - shortcutKey++; - if (shortcutKey > Qt::Key_9) - addKeySequence = false; + if (shortcutKey <= Qt::Key_9) { + elementAction->setShortcut(QKeySequence(shortcutKey)); + shortcutKey++; + } ++i; } @@ -305,10 +303,6 @@ void LiveSelectionTool::mouseReleaseEvent(QMouseEvent *event) } } -void LiveSelectionTool::mouseDoubleClickEvent(QMouseEvent * /*event*/) -{ -} - void LiveSelectionTool::keyPressEvent(QKeyEvent *event) { switch (event->key()) { @@ -323,11 +317,6 @@ void LiveSelectionTool::keyPressEvent(QKeyEvent *event) } } -void LiveSelectionTool::keyReleaseEvent(QKeyEvent * /*keyEvent*/) -{ - -} - void LiveSelectionTool::wheelEvent(QWheelEvent *event) { if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) @@ -372,10 +361,6 @@ void LiveSelectionTool::setSelectOnlyContentItems(bool selectOnlyContentItems) m_selectOnlyContentItems = selectOnlyContentItems; } -void LiveSelectionTool::itemsAboutToRemoved(const QList<QGraphicsItem*> &/*itemList*/) -{ -} - void LiveSelectionTool::clear() { view()->setCursor(Qt::ArrowCursor); @@ -435,4 +420,4 @@ void LiveSelectionTool::selectUnderPoint(QMouseEvent *event) m_singleSelectionManipulator.end(event->pos()); } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool.h index 7562f3e..2c281cd 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/liveselectiontool.h @@ -42,10 +42,10 @@ #ifndef LIVESELECTIONTOOL_H #define LIVESELECTIONTOOL_H -#include "abstractliveedittool_p.h" -#include "liverubberbandselectionmanipulator_p.h" -#include "livesingleselectionmanipulator_p.h" -#include "liveselectionindicator_p.h" +#include "abstractliveedittool.h" +#include "liverubberbandselectionmanipulator.h" +#include "livesingleselectionmanipulator.h" +#include "liveselectionindicator.h" #include <QtCore/QList> #include <QtCore/QTime> @@ -55,11 +55,7 @@ QT_FORWARD_DECLARE_CLASS(QMouseEvent) QT_FORWARD_DECLARE_CLASS(QKeyEvent) QT_FORWARD_DECLARE_CLASS(QAction) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class LiveSelectionTool : public AbstractLiveEditTool { @@ -72,13 +68,13 @@ public: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *) {} void hoverMoveEvent(QMouseEvent *event); void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *keyEvent); + void keyReleaseEvent(QKeyEvent *) {} void wheelEvent(QWheelEvent *event); - void itemsAboutToRemoved(const QList<QGraphicsItem*> &itemList); + void itemsAboutToRemoved(const QList<QGraphicsItem*> &) {} // QVariant itemChange(const QList<QGraphicsItem*> &itemList, // QGraphicsItem::GraphicsItemChange change, // const QVariant &value ); @@ -101,7 +97,7 @@ private slots: void repaintBoundingRects(); private: - void createContextMenu(QList<QGraphicsItem*> itemList, QPoint globalPos); + void createContextMenu(const QList<QGraphicsItem*> &itemList, QPoint globalPos); LiveSingleSelectionManipulator::SelectionType getSelectionType(Qt::KeyboardModifiers modifiers); bool alreadySelected(const QList<QGraphicsItem*> &itemList) const; @@ -119,8 +115,6 @@ private: QList<QGraphicsItem*> m_contextMenuItemList; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // LIVESELECTIONTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator.cpp index ee9843b..34c1469 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator.cpp @@ -39,13 +39,13 @@ ** ****************************************************************************/ -#include "livesingleselectionmanipulator_p.h" +#include "livesingleselectionmanipulator.h" -#include "../qdeclarativeviewinspector_p_p.h" +#include "../qdeclarativeviewinspector_p.h" #include <QtDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { LiveSingleSelectionManipulator::LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView) : m_editorView(editorView), @@ -148,4 +148,4 @@ QPointF LiveSingleSelectionManipulator::beginPoint() const return m_beginPoint; } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator.h index 40b5fc0..ac65711 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/livesingleselectionmanipulator.h @@ -47,11 +47,7 @@ QT_FORWARD_DECLARE_CLASS(QGraphicsItem) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class QDeclarativeViewInspector; @@ -88,8 +84,6 @@ private: bool m_isActive; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // LIVESINGLESELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar.cpp index 0a72674..4e0e375 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar.cpp @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#include "qmltoolbar_p.h" -#include "toolbarcolorbox_p.h" +#include "qmltoolbar.h" +#include "toolbarcolorbox.h" #include <QtGui/QLabel> #include <QtGui/QIcon> @@ -49,7 +49,7 @@ #include <QtCore/QDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { QmlToolBar::QmlToolBar(QWidget *parent) : QToolBar(parent) @@ -325,4 +325,4 @@ void QmlToolBar::activateToQml() emit applyChangesToQmlFileSelected(); } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar.h index 0401804..2abf166 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/qmltoolbar.h @@ -45,15 +45,11 @@ #include <QtGui/QToolBar> #include <QtGui/QIcon> -#include "../qmlinspectorconstants_p.h" +#include "../qmlinspectorconstants.h" QT_FORWARD_DECLARE_CLASS(QActionGroup) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class ToolBarColorBox; @@ -131,8 +127,6 @@ private: Ui *ui; }; -QT_END_NAMESPACE - -QT_END_HEADER +} #endif // QMLTOOLBAR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem.cpp index 2ed3179..5d99886 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem.cpp @@ -39,14 +39,14 @@ ** ****************************************************************************/ -#include "subcomponentmasklayeritem_p.h" +#include "subcomponentmasklayeritem.h" -#include "../qmlinspectorconstants_p.h" -#include "../qdeclarativeviewinspector_p.h" +#include "../qmlinspectorconstants.h" +#include "../qdeclarativeviewinspector.h" #include <QtGui/QPolygonF> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, QGraphicsItem *parentItem) : @@ -127,4 +127,4 @@ QGraphicsItem *SubcomponentMaskLayerItem::currentItem() const return m_currentItem; } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem.h index 07ce881..e41d70a 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/subcomponentmasklayeritem.h @@ -44,11 +44,7 @@ #include <QtGui/QGraphicsPolygonItem> -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class QDeclarativeViewInspector; @@ -70,8 +66,6 @@ private: QRectF m_itemPolyRect; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // SUBCOMPONENTMASKLAYERITEM_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox.cpp index 154ddf2..0914662 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "toolbarcolorbox_p.h" +#include "toolbarcolorbox.h" -#include "../qmlinspectorconstants_p.h" +#include "../qmlinspectorconstants.h" #include <QtGui/QPixmap> #include <QtGui/QPainter> @@ -56,7 +56,7 @@ #include <QtCore/QMimeData> #include <QtCore/QDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { ToolBarColorBox::ToolBarColorBox(QWidget *parent) : QLabel(parent) @@ -131,4 +131,4 @@ void ToolBarColorBox::copyColorToClipboard() clipboard->setText(m_color.name()); } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox.h index c3e064c..8ef75a4 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/toolbarcolorbox.h @@ -49,11 +49,7 @@ QT_FORWARD_DECLARE_CLASS(QContextMenuEvent) QT_FORWARD_DECLARE_CLASS(QAction) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class ToolBarColorBox : public QLabel { @@ -80,8 +76,6 @@ private: QColor m_color; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // TOOLBARCOLORBOX_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool.cpp b/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool.cpp index 969c9d5..c8ade82 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool.cpp @@ -39,9 +39,9 @@ ** ****************************************************************************/ -#include "zoomtool_p.h" +#include "zoomtool.h" -#include "../qdeclarativeviewinspector_p_p.h" +#include "../qdeclarativeviewinspector_p.h" #include <QtGui/QMouseEvent> #include <QtGui/QWheelEvent> @@ -52,7 +52,7 @@ #include <QtCore/QRectF> #include <QtCore/QDebug> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { ZoomTool::ZoomTool(QDeclarativeViewInspector *view) : AbstractLiveEditTool(view), @@ -242,19 +242,11 @@ void ZoomTool::keyReleaseEvent(QKeyEvent *event) } -void ZoomTool::itemsAboutToRemoved(const QList<QGraphicsItem*> &/*itemList*/) -{ -} - void ZoomTool::clear() { view()->setCursor(Qt::ArrowCursor); } -void ZoomTool::selectedItemsChanged(const QList<QGraphicsItem*> &/*itemList*/) -{ -} - void ZoomTool::scaleView(const QPointF ¢erPos) { @@ -333,4 +325,4 @@ qreal ZoomTool::nextZoomScale(ZoomDirection direction) const return 1.0f; } -QT_END_NAMESPACE +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool_p.h b/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool.h index 14fa4d5..de93559 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/editor/zoomtool.h @@ -42,16 +42,12 @@ #ifndef ZOOMTOOL_H #define ZOOMTOOL_H -#include "abstractliveedittool_p.h" -#include "liverubberbandselectionmanipulator_p.h" +#include "abstractliveedittool.h" +#include "liverubberbandselectionmanipulator.h" QT_FORWARD_DECLARE_CLASS(QAction) -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class ZoomTool : public AbstractLiveEditTool { @@ -77,12 +73,12 @@ public: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *keyEvent); - void itemsAboutToRemoved(const QList<QGraphicsItem*> &itemList); + void itemsAboutToRemoved(const QList<QGraphicsItem*> &) {} void clear(); protected: - void selectedItemsChanged(const QList<QGraphicsItem*> &itemList); + void selectedItemsChanged(const QList<QGraphicsItem*> &) {} private slots: void zoomTo100(); @@ -106,8 +102,6 @@ private: qreal m_currentScale; }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // ZOOMTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp index a266eb9..932f911 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp @@ -46,7 +46,7 @@ #include <QtCore/qplugin.h> #include <QtDeclarative/private/qdeclarativeinspectorservice_p.h> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { QDeclarativeInspectorPlugin::QDeclarativeInspectorPlugin() : m_inspector(0) @@ -75,7 +75,6 @@ void QDeclarativeInspectorPlugin::deactivate() delete m_inspector; } -Q_EXPORT_PLUGIN2(declarativeinspector, QDeclarativeInspectorPlugin) - -QT_END_NAMESPACE +} // namespace QmlJSDebugger +Q_EXPORT_PLUGIN2(declarativeinspector, QmlJSDebugger::QDeclarativeInspectorPlugin) diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h index 3e28643..5429253 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h @@ -45,9 +45,9 @@ #include <QtCore/QPointer> #include <QtDeclarative/private/qdeclarativeinspectorinterface_p.h> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { -class QDeclarativeViewInspector; +class AbstractViewInspector; class QDeclarativeInspectorPlugin : public QObject, public QDeclarativeInspectorInterface { @@ -63,9 +63,9 @@ public: void deactivate(); private: - QPointer<QDeclarativeViewInspector> m_inspector; + QPointer<AbstractViewInspector> m_inspector; }; -QT_END_NAMESPACE +} // namespace QmlJSDebugger #endif // QDECLARATIVEINSPECTORPLUGIN_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h index 2878bc1..082abeb 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h @@ -47,11 +47,7 @@ #include <QtCore/QMetaEnum> #include <QtCore/QObject> -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) +namespace QmlJSDebugger { class InspectorProtocol : public QObject { @@ -136,8 +132,6 @@ inline QDebug operator<< (QDebug dbg, InspectorProtocol::Tool tool) return dbg; } -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // QDECLARATIVEINSPECTORPROTOCOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp index 19bfdaa..3351df9 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.cpp @@ -39,84 +39,24 @@ ** ****************************************************************************/ -#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h" -#include "QtDeclarative/private/qdeclarativedebughelper_p.h" - +#include "qdeclarativeviewinspector.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 "editor/liveselectiontool.h" +#include "editor/zoomtool.h" +#include "editor/colorpickertool.h" +#include "editor/livelayeritem.h" +#include "editor/boundingrecthighlighter.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()); -} +namespace QmlJSDebugger { QDeclarativeViewInspectorPrivate::QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *q) : - q(q), - designModeBehavior(false), - showAppOnTop(false), - animationPaused(false), - slowDownFactor(1.0f), - toolBox(0) + q(q) { } @@ -126,28 +66,22 @@ 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); data->zoomTool = new ZoomTool(this); data->colorPickerTool = new ColorPickerTool(this); data->boundingRectHighlighter = new BoundingRectHighlighter(this); - data->currentTool = data->selectionTool; + setCurrentTool(data->selectionTool); // to capture ChildRemoved event when viewport changes data->view->installEventFilter(this); 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 +90,62 @@ 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; + } +} + +AbstractLiveEditTool *QDeclarativeViewInspector::currentTool() const +{ + return static_cast<AbstractLiveEditTool*>(AbstractViewInspector::currentTool()); +} + +QDeclarativeEngine *QDeclarativeViewInspector::declarativeEngine() const +{ + return data->view->engine(); } void QDeclarativeViewInspectorPrivate::setViewport(QWidget *widget) @@ -215,174 +182,28 @@ bool QDeclarativeViewInspector::eventFilter(QObject *obj, QEvent *event) return QObject::eventFilter(obj, event); } - // Event from viewport - 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; - } - } //switch - - // standard event processing - return QObject::eventFilter(obj, event); + return AbstractViewInspector::eventFilter(obj, event); } -bool QDeclarativeViewInspector::leaveEvent(QEvent * /*event*/) +bool QDeclarativeViewInspector::leaveEvent(QEvent *event) { - if (!data->designModeBehavior) - return false; data->clearHighlight(); - return true; -} - -bool QDeclarativeViewInspector::mousePressEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) - return false; - data->cursorPos = event->pos(); - data->currentTool->mousePressEvent(event); - return true; + return AbstractViewInspector::leaveEvent(event); } bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event) { - if (!data->designModeBehavior) { - data->clearEditorItems(); - return false; - } - data->cursorPos = event->pos(); - QList<QGraphicsItem*> selItems = data->selectableItems(event->pos()); if (!selItems.isEmpty()) { - declarativeView()->setToolTip(data->currentTool->titleForItem(selItems.first())); + declarativeView()->setToolTip(currentTool()->titleForItem(selItems.first())); } else { declarativeView()->setToolTip(QString()); } - if (event->buttons()) { - data->currentTool->mouseMoveEvent(event); - } else { - data->currentTool->hoverMoveEvent(event); - } - return true; -} - -bool QDeclarativeViewInspector::mouseReleaseEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) - return false; - - data->cursorPos = event->pos(); - data->currentTool->mouseReleaseEvent(event); - return true; -} - -bool QDeclarativeViewInspector::keyPressEvent(QKeyEvent *event) -{ - if (!data->designModeBehavior) - return false; - - data->currentTool->keyPressEvent(event); - return true; -} - -bool QDeclarativeViewInspector::keyReleaseEvent(QKeyEvent *event) -{ - if (!data->designModeBehavior) - return false; - - switch (event->key()) { - case Qt::Key_V: - data->_q_changeToSingleSelectTool(); - break; -// disabled because multiselection does not do anything useful without design mode -// case Qt::Key_M: -// data->_q_changeToMarqueeSelectTool(); -// break; - case Qt::Key_I: - data->_q_changeToColorPickerTool(); - break; - case Qt::Key_Z: - data->_q_changeToZoomTool(); - break; - case Qt::Key_Space: - setAnimationPaused(!data->animationPaused); - break; - default: - break; - } - data->currentTool->keyReleaseEvent(event); - return true; + return AbstractViewInspector::mouseMoveEvent(event); } -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 +215,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(); @@ -407,80 +223,6 @@ void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj) setSelectedItems(items); } -bool QDeclarativeViewInspector::mouseDoubleClickEvent(QMouseEvent * /*event*/) -{ - if (!data->designModeBehavior) - return false; - - return true; -} - -bool QDeclarativeViewInspector::wheelEvent(QWheelEvent *event) -{ - if (!data->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) { @@ -503,7 +245,7 @@ void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(const QList<QGra } } - currentTool->updateSelectedItems(); + q->currentTool()->updateSelectedItems(); } void QDeclarativeViewInspectorPrivate::setSelectedItems(const QList<QGraphicsItem *> &items) @@ -542,7 +284,7 @@ QList<QGraphicsItem *> QDeclarativeViewInspector::selectedItems() const return data->selectedItems(); } -QDeclarativeView *QDeclarativeViewInspector::declarativeView() +QDeclarativeView *QDeclarativeViewInspector::declarativeView() const { return data->view; } @@ -591,9 +333,8 @@ QList<QGraphicsItem*> QDeclarativeViewInspectorPrivate::selectableItems( return filterForSelection(itemlist); } -void QDeclarativeViewInspectorPrivate::_q_changeToSingleSelectTool() +void QDeclarativeViewInspectorPrivate::changeToSingleSelectTool() { - currentToolMode = Constants::SelectionToolMode; selectionTool->setRubberbandSelectionMode(false); changeToSelectTool(); @@ -604,97 +345,55 @@ void QDeclarativeViewInspectorPrivate::_q_changeToSingleSelectTool() void QDeclarativeViewInspectorPrivate::changeToSelectTool() { - if (currentTool == selectionTool) + if (q->currentTool() == selectionTool) return; - currentTool->clear(); - currentTool = selectionTool; - currentTool->clear(); - currentTool->updateSelectedItems(); + q->currentTool()->clear(); + q->setCurrentTool(selectionTool); + q->currentTool()->clear(); + q->currentTool()->updateSelectedItems(); } -void QDeclarativeViewInspectorPrivate::_q_changeToMarqueeSelectTool() +void QDeclarativeViewInspectorPrivate::changeToMarqueeSelectTool() { changeToSelectTool(); - currentToolMode = Constants::MarqueeSelectionToolMode; selectionTool->setRubberbandSelectionMode(true); emit q->marqueeSelectToolActivated(); q->sendCurrentTool(Constants::MarqueeSelectionToolMode); } -void QDeclarativeViewInspectorPrivate::_q_changeToZoomTool() +void QDeclarativeViewInspectorPrivate::changeToZoomTool() { - currentToolMode = Constants::ZoomMode; - currentTool->clear(); - currentTool = zoomTool; - currentTool->clear(); + q->currentTool()->clear(); + q->setCurrentTool(zoomTool); + q->currentTool()->clear(); emit q->zoomToolActivated(); q->sendCurrentTool(Constants::ZoomMode); } -void QDeclarativeViewInspectorPrivate::_q_changeToColorPickerTool() +void QDeclarativeViewInspectorPrivate::changeToColorPickerTool() { - if (currentTool == colorPickerTool) + if (q->currentTool() == colorPickerTool) return; - currentToolMode = Constants::ColorPickerMode; - currentTool->clear(); - currentTool = colorPickerTool; - currentTool->clear(); + q->currentTool()->clear(); + q->setCurrentTool(colorPickerTool); + q->currentTool()->clear(); emit q->colorPickerActivated(); 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 +405,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 +433,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" +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h new file mode 100644 index 0000000..c77cd2c --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEVIEWINSPECTOR_H +#define QDECLARATIVEVIEWINSPECTOR_H + +#include <private/qdeclarativeglobal_p.h> + +#include "qmlinspectorconstants.h" +#include "abstractviewinspector.h" + +#include <QtCore/QScopedPointer> +#include <QtDeclarative/QDeclarativeView> + +namespace QmlJSDebugger { + +class AbstractLiveEditTool; +class QDeclarativeViewInspectorPrivate; + +class QDeclarativeViewInspector : public AbstractViewInspector +{ + Q_OBJECT + +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() const; + + QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); + +protected: + bool eventFilter(QObject *obj, QEvent *event); + + bool leaveEvent(QEvent *); + bool mouseMoveEvent(QMouseEvent *event); + + AbstractLiveEditTool *currentTool() const; + +private: + Q_DISABLE_COPY(QDeclarativeViewInspector) + + inline QDeclarativeViewInspectorPrivate *d_func() { return data.data(); } + QScopedPointer<QDeclarativeViewInspectorPrivate> data; + friend class QDeclarativeViewInspectorPrivate; + friend class AbstractLiveEditTool; +}; + +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h index 4efa093..bfa857c 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p.h @@ -42,106 +42,76 @@ #ifndef QDECLARATIVEVIEWINSPECTOR_P_H #define QDECLARATIVEVIEWINSPECTOR_P_H -#include <private/qdeclarativeglobal_p.h> -#include "qmlinspectorconstants_p.h" +#include "qdeclarativeviewinspector.h" -#include <QtCore/QScopedPointer> -#include <QtDeclarative/QDeclarativeView> +#include <QtCore/QWeakPointer> +#include <QtCore/QPointF> -QT_FORWARD_DECLARE_CLASS(QDeclarativeItem) -QT_FORWARD_DECLARE_CLASS(QMouseEvent) -QT_FORWARD_DECLARE_CLASS(QToolBar) +#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h" -QT_BEGIN_HEADER +namespace QmlJSDebugger { -QT_BEGIN_NAMESPACE +class QDeclarativeViewInspector; +class LiveSelectionTool; +class ZoomTool; +class ColorPickerTool; +class LiveLayerItem; +class BoundingRectHighlighter; +class AbstractLiveEditTool; -QT_MODULE(Declarative) - -class QDeclarativeViewInspectorPrivate; - -class QDeclarativeViewInspector : public QObject +class QDeclarativeViewInspectorPrivate : public QObject { Q_OBJECT - public: - explicit QDeclarativeViewInspector(QDeclarativeView *view, QObject *parent = 0); - ~QDeclarativeViewInspector(); - - void setSelectedItems(QList<QGraphicsItem *> items); - QList<QGraphicsItem *> selectedItems() const; - - QDeclarativeView *declarativeView(); - - QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); + QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *); + ~QDeclarativeViewInspectorPrivate(); - bool showAppOnTop() const; + QDeclarativeView *view; + QDeclarativeViewInspector *q; + QWeakPointer<QWidget> viewport; - 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); + QList<QWeakPointer<QGraphicsObject> > currentSelection; - QString idStringForObject(QObject *obj) const; + LiveSelectionTool *selectionTool; + ZoomTool *zoomTool; + ColorPickerTool *colorPickerTool; + LiveLayerItem *manipulatorLayer; -public Q_SLOTS: - void sendColorChanged(const QColor &color); + BoundingRectHighlighter *boundingRectHighlighter; - void setDesignModeBehavior(bool value); - bool designModeBehavior(); + void setViewport(QWidget *widget); - void setShowAppOnTop(bool appOnTop); + void clearEditorItems(); + void changeToSelectTool(); + QList<QGraphicsItem*> filterForSelection(QList<QGraphicsItem*> &itemlist) const; - void setAnimationSpeed(qreal factor); - void setAnimationPaused(bool paused); + QList<QGraphicsItem*> selectableItems(const QPoint &pos) const; + QList<QGraphicsItem*> selectableItems(const QPointF &scenePos) const; + QList<QGraphicsItem*> selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; -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); - - 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); + void setSelectedItemsForTools(const QList<QGraphicsItem *> &items); + void setSelectedItems(const QList<QGraphicsItem *> &items); + QList<QGraphicsItem *> selectedItems() const; - void setSelectedItemsForTools(QList<QGraphicsItem *> items); + void clearHighlight(); + void highlight(const QList<QGraphicsObject *> &item); + inline void highlight(QGraphicsObject *item) + { highlight(QList<QGraphicsObject*>() << item); } -private slots: - void handleMessage(const QByteArray &message); + void changeToSingleSelectTool(); + void changeToMarqueeSelectTool(); + void changeToZoomTool(); + void changeToColorPickerTool(); - void animationSpeedChangeRequested(qreal factor); - void animationPausedChangeRequested(bool paused); +public slots: + void _q_onStatusChanged(QDeclarativeView::Status status); -private: - Q_DISABLE_COPY(QDeclarativeViewInspector) + void _q_removeFromSelection(QObject *); - inline QDeclarativeViewInspectorPrivate *d_func() { return data.data(); } - QScopedPointer<QDeclarativeViewInspectorPrivate> data; - friend class QDeclarativeViewInspectorPrivate; - friend class AbstractLiveEditTool; +public: + static QDeclarativeViewInspectorPrivate *get(QDeclarativeViewInspector *v) { return v->d_func(); } }; -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // QDECLARATIVEVIEWINSPECTOR_P_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h deleted file mode 100644 index 11cbe0f..0000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeviewinspector_p_p.h +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** -** -** 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 QDECLARATIVEVIEWINSPECTOR_P_P_H -#define QDECLARATIVEVIEWINSPECTOR_P_P_H - -#include "qdeclarativeviewinspector_p.h" - -#include <QtCore/QWeakPointer> -#include <QtCore/QPointF> - -#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QDeclarativeViewInspector; -class LiveSelectionTool; -class ZoomTool; -class ColorPickerTool; -class LiveLayerItem; -class BoundingRectHighlighter; -class ToolBox; -class AbstractLiveEditTool; - -class QDeclarativeViewInspectorPrivate : public QObject -{ - Q_OBJECT -public: - QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *); - ~QDeclarativeViewInspectorPrivate(); - - QDeclarativeView *view; - QDeclarativeViewInspector *q; - QDeclarativeInspectorService *debugService; - QWeakPointer<QWidget> viewport; - QHash<int, QString> stringIdForObjectId; - - QPointF cursorPos; - QList<QWeakPointer<QGraphicsObject> > currentSelection; - - Constants::DesignTool currentToolMode; - AbstractLiveEditTool *currentTool; - - LiveSelectionTool *selectionTool; - ZoomTool *zoomTool; - ColorPickerTool *colorPickerTool; - LiveLayerItem *manipulatorLayer; - - 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; - - QList<QGraphicsItem*> selectableItems(const QPoint &pos) const; - QList<QGraphicsItem*> selectableItems(const QPointF &scenePos) const; - QList<QGraphicsItem*> selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; - - void setSelectedItemsForTools(const QList<QGraphicsItem *> &items); - 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; - -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: - static QDeclarativeViewInspectorPrivate *get(QDeclarativeViewInspector *v) { return v->d_func(); } -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDECLARATIVEVIEWINSPECTOR_P_P_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro index f8d7ee8..0116441 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 \ @@ -21,27 +22,30 @@ SOURCES += \ editor/zoomtool.cpp \ editor/colorpickertool.cpp \ editor/qmltoolbar.cpp \ - editor/toolbarcolorbox.cpp + editor/toolbarcolorbox.cpp \ + abstracttool.cpp HEADERS += \ + abstractviewinspector.h \ qdeclarativeinspectorplugin.h \ qdeclarativeinspectorprotocol.h \ + qdeclarativeviewinspector.h \ qdeclarativeviewinspector_p.h \ - qdeclarativeviewinspector_p_p.h \ - qmlinspectorconstants_p.h \ - editor/abstractliveedittool_p.h \ - editor/liveselectiontool_p.h \ - editor/livelayeritem_p.h \ - editor/livesingleselectionmanipulator_p.h \ - editor/liverubberbandselectionmanipulator_p.h \ - editor/liveselectionrectangle_p.h \ - editor/liveselectionindicator_p.h \ - editor/boundingrecthighlighter_p.h \ - editor/subcomponentmasklayeritem_p.h \ - editor/zoomtool_p.h \ - editor/colorpickertool_p.h \ - editor/qmltoolbar_p.h \ - editor/toolbarcolorbox_p.h + qmlinspectorconstants.h \ + editor/abstractliveedittool.h \ + editor/liveselectiontool.h \ + editor/livelayeritem.h \ + editor/livesingleselectionmanipulator.h \ + editor/liverubberbandselectionmanipulator.h \ + editor/liveselectionrectangle.h \ + editor/liveselectionindicator.h \ + editor/boundingrecthighlighter.h \ + editor/subcomponentmasklayeritem.h \ + editor/zoomtool.h \ + editor/colorpickertool.h \ + editor/qmltoolbar.h \ + editor/toolbarcolorbox.h \ + abstracttool.h RESOURCES += editor/editor.qrc diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h b/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants.h index 40ec325..5335222 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants_p.h +++ b/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants.h @@ -44,12 +44,7 @@ #include <QtDeclarative/private/qdeclarativeglobal_p.h> -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - +namespace QmlJSDebugger { namespace Constants { enum DesignTool { @@ -62,11 +57,6 @@ enum DesignTool { ZoomMode = 6 }; -enum ToolFlags { - NoToolFlags = 0, - UseCursorPos = 1 -}; - static const int DragStartTime = 50; static const int DragStartDistance = 20; @@ -82,9 +72,6 @@ enum GraphicsItemTypes { } // namespace Constants - -QT_END_NAMESPACE - -QT_END_HEADER +} // namespace QmlJSDebugger #endif // QMLINSPECTORCONSTANTS_H |