diff options
53 files changed, 2288 insertions, 1277 deletions
diff --git a/doc/src/declarative/example-textballoons.qdoc b/doc/src/declarative/example-textballoons.qdoc index 90de999265..7c21d18a51 100644 --- a/doc/src/declarative/example-textballoons.qdoc +++ b/doc/src/declarative/example-textballoons.qdoc @@ -51,11 +51,11 @@ \section1 TextBalloon Class Declaration - The \c TextBalloon class inherits from QSGPaintedItem. QSGPaintedItem class + The \c TextBalloon class inherits from QSGPaintedItem. QSGPaintedItem is the base class for all QPainter based items in the QML Scene Graph framework. - \snippet examples/declarative/painteditem/textballoons/textballoonplugin/textballoon.h 0 + \snippet examples/declarative/painteditem/textballoons/textballoon.h 0 To implement a QSGPaintedItem you must implement QSGPaintedIem's pure virtual function \l {QSGPaintedItem::}{paint()} which implements the @@ -66,13 +66,13 @@ We have to be sure to initialize the rightAligned property for a TextBalloon item. - \snippet examples/declarative/painteditem/textballoons/textballoonplugin/textballoon.cpp 0 + \snippet examples/declarative/painteditem/textballoons/textballoon.cpp 0 Then we implement the \c paint() function which is automatically called by the Scenegraph framework to paint the contents of the item. The function paints the item in local coordinates. - \snippet examples/declarative/painteditem/textballoons/textballoonplugin/textballoon.cpp 1 + \snippet examples/declarative/painteditem/textballoons/textballoon.cpp 1 We start with setting the pen and brush on the item to define the look of the item. After that we start drawing. Note that the \l {QSGPaintedItem::}{boundingRect()} diff --git a/src/declarative/debugger/qdeclarativeinspectorservice.cpp b/src/declarative/debugger/qdeclarativeinspectorservice.cpp index 9fec006f56..f1ae354066 100644 --- a/src/declarative/debugger/qdeclarativeinspectorservice.cpp +++ b/src/declarative/debugger/qdeclarativeinspectorservice.cpp @@ -47,8 +47,6 @@ #include <QtCore/QDir> #include <QtCore/QPluginLoader> -#include <QtDeclarative/QDeclarativeView> - QT_BEGIN_NAMESPACE Q_GLOBAL_STATIC(QDeclarativeInspectorService, serviceInstance) @@ -64,12 +62,12 @@ QDeclarativeInspectorService *QDeclarativeInspectorService::instance() return serviceInstance(); } -void QDeclarativeInspectorService::addView(QDeclarativeView *view) +void QDeclarativeInspectorService::addView(QObject *view) { m_views.append(view); } -void QDeclarativeInspectorService::removeView(QDeclarativeView *view) +void QDeclarativeInspectorService::removeView(QObject *view) { m_views.removeAll(view); } diff --git a/src/declarative/debugger/qdeclarativeinspectorservice_p.h b/src/declarative/debugger/qdeclarativeinspectorservice_p.h index 9fe0d601fa..db94103210 100644 --- a/src/declarative/debugger/qdeclarativeinspectorservice_p.h +++ b/src/declarative/debugger/qdeclarativeinspectorservice_p.h @@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QDeclarativeView; class QDeclarativeInspectorInterface; class Q_DECLARATIVE_EXPORT QDeclarativeInspectorService : public QDeclarativeDebugService @@ -64,9 +63,9 @@ public: QDeclarativeInspectorService(); static QDeclarativeInspectorService *instance(); - void addView(QDeclarativeView *); - void removeView(QDeclarativeView *); - QList<QDeclarativeView*> views() const { return m_views; } + void addView(QObject *); + void removeView(QObject *); + QList<QObject*> views() const { return m_views; } void sendMessage(const QByteArray &message); @@ -80,7 +79,7 @@ protected: private: static QDeclarativeInspectorInterface *loadInspectorPlugin(); - QList<QDeclarativeView*> m_views; + QList<QObject*> m_views; QDeclarativeInspectorInterface *m_inspectorPlugin; }; diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp index b87ba296e2..9bbed05dd5 100644 --- a/src/declarative/items/qsgitem.cpp +++ b/src/declarative/items/qsgitem.cpp @@ -1900,13 +1900,12 @@ QSGItem *QSGItem::childAt(qreal x, qreal y) const // XXX todo - should this include transform etc.? const QList<QSGItem *> children = childItems(); for (int i = children.count()-1; i >= 0; --i) { - if (QSGItem *child = qobject_cast<QSGItem *>(children.at(i))) { - if (child->isVisible() && child->x() <= x + QSGItem *child = children.at(i); + if (child->isVisible() && child->x() <= x && child->x() + child->width() >= x && child->y() <= y && child->y() + child->height() >= y) - return child; - } + return child; } return 0; } diff --git a/src/declarative/items/qsgtextnode.cpp b/src/declarative/items/qsgtextnode.cpp index b8dee689d5..3120d7e4eb 100644 --- a/src/declarative/items/qsgtextnode.cpp +++ b/src/declarative/items/qsgtextnode.cpp @@ -206,7 +206,15 @@ void QSGTextNode::addTextLayout(const QPointF &position, QTextLayout *textLayout for (int i=0; i<glyphsList.size(); ++i) { QGlyphRun glyphs = glyphsList.at(i); QRawFont font = glyphs.rawFont(); - prevNode = addGlyphs(position + QPointF(0, font.ascent()), glyphs, color, style, styleColor, prevNode); + addGlyphs(position + QPointF(0, font.ascent()), glyphs, color, style, styleColor); + } + + QFont font = textLayout->font(); + QRawFont rawFont = QRawFont::fromFont(font); + if (font.strikeOut() || font.underline() || font.overline()) { + addTextDecorations(position + QPointF(0, rawFont.ascent()), + rawFont, color, textLayout->boundingRect().width(), + font.overline(), font.strikeOut(), font.underline()); } } diff --git a/src/declarative/items/qsgview.cpp b/src/declarative/items/qsgview.cpp index 830a232db2..d3c8b6d233 100644 --- a/src/declarative/items/qsgview.cpp +++ b/src/declarative/items/qsgview.cpp @@ -46,6 +46,7 @@ #include "qsgitemchangelistener_p.h" #include <private/qdeclarativedebugtrace_p.h> +#include <private/qdeclarativeinspectorservice_p.h> #include <QtDeclarative/qdeclarativeengine.h> #include <private/qdeclarativeengine_p.h> @@ -92,6 +93,8 @@ void QSGViewPrivate::init() { q_func()->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); QDeclarativeEnginePrivate::get(&engine)->sgContext = QSGCanvasPrivate::context; + + QDeclarativeInspectorService::instance()->addView(q_func()); } QSGViewPrivate::QSGViewPrivate() @@ -101,7 +104,9 @@ QSGViewPrivate::QSGViewPrivate() QSGViewPrivate::~QSGViewPrivate() { - delete root; + QDeclarativeInspectorService::instance()->removeView(q_func()); + + delete root; } void QSGViewPrivate::execute() diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp new file mode 100644 index 0000000000..39ced2a9d0 --- /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 0000000000..0a216bfa83 --- /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 0000000000..3323d54246 --- /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 0000000000..7202bcca40 --- /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 36e6ba0ad7..dce147c842 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 17eb6ea6ce..04b5f4e46e 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 3f95005f45..da9f442026 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 e2928f7f72..81883ee0aa 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 bdae3d8298..72e1380146 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 580c175c5b..a28ffea63a 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 c28893ef6a..fb7118fbc2 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 da622e18a0..4dccc0b6f3 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 d32847d5bd..b08682a396 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 9abcb2b70c..aa15a34730 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 4450fc5110..c57bc0e26c 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 fa6eb306b9..7b8cc12e62 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 267079a2a1..4e144589b7 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 5da9fb884d..730cca52d5 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 c55cba3966..6085d8131a 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 7562f3e854..2c281cda3c 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 ee9843bedc..34c1469208 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 40b5fc0208..ac65711a91 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 0a7267434a..4e0e37518a 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 0401804184..2abf1660f0 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 2ed3179856..5d99886601 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 07ce881851..e41d70a61b 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 154ddf2c6f..091466284f 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 c3e064c21e..8ef75a4114 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 969c9d55d7..c8ade825a2 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 14fa4d5390..de935591cb 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 a266eb90b5..82d8e7a75f 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp @@ -42,11 +42,13 @@ #include "qdeclarativeinspectorplugin.h" #include "qdeclarativeviewinspector_p.h" +#include "sgviewinspector.h" #include <QtCore/qplugin.h> #include <QtDeclarative/private/qdeclarativeinspectorservice_p.h> +#include <QtDeclarative/QSGView> -QT_BEGIN_NAMESPACE +namespace QmlJSDebugger { QDeclarativeInspectorPlugin::QDeclarativeInspectorPlugin() : m_inspector(0) @@ -61,13 +63,16 @@ QDeclarativeInspectorPlugin::~QDeclarativeInspectorPlugin() void QDeclarativeInspectorPlugin::activate() { QDeclarativeInspectorService *service = QDeclarativeInspectorService::instance(); - QList<QDeclarativeView*> views = service->views(); + QList<QObject*> views = service->views(); if (views.isEmpty()) return; // TODO: Support multiple views - QDeclarativeView *view = service->views().at(0); - m_inspector = new QDeclarativeViewInspector(view, view); + QObject *firstView = views.first(); + if (QDeclarativeView *declarativeView = qobject_cast<QDeclarativeView*>(firstView)) + m_inspector = new QDeclarativeViewInspector(declarativeView, declarativeView); + else if (QSGView *sgView = qobject_cast<QSGView*>(firstView)) + m_inspector = new SGViewInspector(sgView, sgView); } void QDeclarativeInspectorPlugin::deactivate() @@ -75,7 +80,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 3e28643eff..542925366c 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 2878bc188a..082abeb9bd 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 19bfdaa3b5..3351df9d0b 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 0000000000..c77cd2c522 --- /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 4efa093fb1..bfa857cf41 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 11cbe0f447..0000000000 --- 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 385326a806..427a1779e3 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro +++ b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro @@ -1,7 +1,7 @@ load(qt_module) TARGET = qmldbg_inspector -QT += declarative-private +QT += declarative-private core-private gui-private opengl-private load(qt_plugin) @@ -9,6 +9,7 @@ DESTDIR = $$QT.declarative.plugins/qmltooling QTDIR_build:REQUIRES += "contains(QT_CONFIG, declarative)" SOURCES += \ + abstractviewinspector.cpp \ qdeclarativeinspectorplugin.cpp \ qdeclarativeviewinspector.cpp \ editor/abstractliveedittool.cpp \ @@ -23,27 +24,36 @@ SOURCES += \ editor/zoomtool.cpp \ editor/colorpickertool.cpp \ editor/qmltoolbar.cpp \ - editor/toolbarcolorbox.cpp + editor/toolbarcolorbox.cpp \ + abstracttool.cpp \ + sgviewinspector.cpp \ + sgselectiontool.cpp \ + sghighlight.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 \ + sgviewinspector.h \ + sgselectiontool.h \ + sghighlight.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 40ec32542d..5335222865 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 diff --git a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp new file mode 100644 index 0000000000..4488214a31 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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 "sghighlight.h" + +#include <QtGui/QPainter> + +namespace QmlJSDebugger { + +SGHighlight::SGHighlight(QSGItem *item, QSGItem *parent) + : QSGPaintedItem(parent) +{ + setItem(item); +} + +void SGHighlight::setItem(QSGItem *item) +{ + if (m_item) + m_item.data()->disconnect(this); + + if (item) { + connect(item, SIGNAL(xChanged()), SLOT(adjust())); + connect(item, SIGNAL(yChanged()), SLOT(adjust())); + connect(item, SIGNAL(widthChanged()), SLOT(adjust())); + connect(item, SIGNAL(heightChanged()), SLOT(adjust())); + connect(item, SIGNAL(rotationChanged()), SLOT(adjust())); + connect(item, SIGNAL(transformOriginChanged(TransformOrigin)), + SLOT(adjust())); + } + + m_item = item; + adjust(); +} + +void SGHighlight::adjust() +{ + const QSGItem *item = m_item.data(); + setSize(QSizeF(item->width(), item->height())); + setPos(parentItem()->mapFromItem(item->parentItem(), item->pos())); + setRotation(item->rotation()); + setTransformOrigin(item->transformOrigin()); +} + + +void SGSelectionHighlight::paint(QPainter *painter) +{ + painter->setPen(QColor(108, 141, 221)); + painter->drawRect(QRect(0, 0, width() - 1, height() - 1)); +} + + +void SGHoverHighlight::paint(QPainter *painter) +{ + painter->setPen(QPen(QColor(0, 22, 159))); + painter->drawRect(QRect(1, 1, width() - 3, height() - 3)); + painter->setPen(QColor(158, 199, 255)); + painter->drawRect(QRect(0, 0, width() - 1, height() - 1)); +} + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h new file mode 100644 index 0000000000..f3e8edd442 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 SGHIGHLIGHT_H +#define SGHIGHLIGHT_H + +#include <QtCore/QWeakPointer> +#include <QtDeclarative/QSGPaintedItem> + +namespace QmlJSDebugger { + +class SGHighlight : public QSGPaintedItem +{ + Q_OBJECT + +public: + SGHighlight(QSGItem *parent) : QSGPaintedItem(parent) {} + SGHighlight(QSGItem *item, QSGItem *parent); + + void setItem(QSGItem *item); + +private slots: + void adjust(); + +private: + QWeakPointer<QSGItem> m_item; +}; + +/** + * A highlight suitable for indicating selection. + */ +class SGSelectionHighlight : public SGHighlight +{ +public: + SGSelectionHighlight(QSGItem *item, QSGItem *parent) + : SGHighlight(item, parent) + {} + + void paint(QPainter *painter); +}; + +/** + * A highlight suitable for indicating hover. + */ +class SGHoverHighlight : public SGHighlight +{ +public: + SGHoverHighlight(QSGItem *parent) + : SGHighlight(parent) + { + setZ(1); // hover highlight on top of selection highlight + } + + void paint(QPainter *painter); +}; + +} // namespace QmlJSDebugger + +#endif // SGHIGHLIGHT_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp new file mode 100644 index 0000000000..36e2818674 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sgselectiontool.h" + +#include "sghighlight.h" +#include "sgviewinspector.h" + +#include <QtGui/QMenu> +#include <QtGui/QMouseEvent> +#include <QtDeclarative/QSGView> +#include <QtDeclarative/QSGItem> + +namespace QmlJSDebugger { + +SGSelectionTool::SGSelectionTool(SGViewInspector *inspector) : + AbstractTool(inspector), + m_hoverHighlight(new SGHoverHighlight(inspector->overlay())) +{ +} + +void SGSelectionTool::leaveEvent(QEvent *) +{ + m_hoverHighlight->setVisible(false); +} + +void SGSelectionTool::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + if (QSGItem *item = inspector()->topVisibleItemAt(event->pos())) + inspector()->setSelectedItems(QList<QSGItem*>() << item); + } else if (event->button() == Qt::RightButton) { + QList<QSGItem*> items = inspector()->itemsAt(event->pos()); + createContextMenu(items, event->globalPos()); + } +} + +void SGSelectionTool::hoverMoveEvent(QMouseEvent *event) +{ + QSGItem *item = inspector()->topVisibleItemAt(event->pos()); + if (!item) { + m_hoverHighlight->setVisible(false); + } else { + m_hoverHighlight->setItem(item); + m_hoverHighlight->setVisible(true); + } +} + +void SGSelectionTool::createContextMenu(const QList<QSGItem *> &items, QPoint pos) +{ + QMenu contextMenu; + connect(&contextMenu, SIGNAL(hovered(QAction*)), + this, SLOT(contextMenuElementHovered(QAction*))); + + const QList<QSGItem*> selectedItems = inspector()->selectedItems(); + int shortcutKey = Qt::Key_1; + + foreach (QSGItem *item, items) { + const QString title = inspector()->titleForItem(item); + QAction *elementAction = contextMenu.addAction(title); + elementAction->setData(QVariant::fromValue(item)); + + connect(elementAction, SIGNAL(triggered()), this, SLOT(contextMenuElementSelected())); + + if (selectedItems.contains(item)) { + QFont font = elementAction->font(); + font.setBold(true); + elementAction->setFont(font); + } + + if (shortcutKey <= Qt::Key_9) { + elementAction->setShortcut(QKeySequence(shortcutKey)); + shortcutKey++; + } + } + + contextMenu.exec(pos); +} + +void SGSelectionTool::contextMenuElementHovered(QAction *action) +{ + if (QSGItem *item = action->data().value<QSGItem*>()) + m_hoverHighlight->setItem(item); +} + +void SGSelectionTool::contextMenuElementSelected() +{ + if (QSGItem *item = static_cast<QAction*>(sender())->data().value<QSGItem*>()) + inspector()->setSelectedItems(QList<QSGItem*>() << item); +} + +SGViewInspector *SGSelectionTool::inspector() const +{ + return static_cast<SGViewInspector*>(AbstractTool::inspector()); +} + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h new file mode 100644 index 0000000000..9f2171f572 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SGSELECTIONTOOL_H +#define SGSELECTIONTOOL_H + +#include "abstracttool.h" + +#include <QtCore/QList> +#include <QtCore/QPoint> + +QT_FORWARD_DECLARE_CLASS(QAction) +QT_FORWARD_DECLARE_CLASS(QSGItem) + +namespace QmlJSDebugger { + +class SGViewInspector; +class SGHoverHighlight; + +class SGSelectionTool : public AbstractTool +{ + Q_OBJECT +public: + explicit SGSelectionTool(SGViewInspector *inspector); + + void leaveEvent(QEvent *); + + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *) {} + void mouseReleaseEvent(QMouseEvent *) {} + void mouseDoubleClickEvent(QMouseEvent *) {} + + void hoverMoveEvent(QMouseEvent *); + void wheelEvent(QWheelEvent *) {} + + void keyPressEvent(QKeyEvent *) {} + void keyReleaseEvent(QKeyEvent *) {} + +private slots: + void contextMenuElementHovered(QAction *action); + void contextMenuElementSelected(); + +private: + void createContextMenu(const QList<QSGItem*> &items, QPoint pos); + + SGViewInspector *inspector() const; + + SGHoverHighlight *m_hoverHighlight; +}; + +} // namespace QmlJSDebugger + +#endif // SGSELECTIONTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp new file mode 100644 index 0000000000..bb9ad52fee --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sgviewinspector.h" + +#include "qdeclarativeinspectorprotocol.h" +#include "sghighlight.h" +#include "sgselectiontool.h" + +#include <QtDeclarative/private/qdeclarativeinspectorservice_p.h> +#include <QtDeclarative/private/qdeclarativedebughelper_p.h> +#include <QtDeclarative/private/qsgitem_p.h> + +#include <QtDeclarative/QSGView> +#include <QtDeclarative/QSGItem> +#include <QtGui/QMouseEvent> + +#include <cfloat> + +namespace QmlJSDebugger { + +/* + * Collects all the items at the given position, from top to bottom. + */ +static void collectItemsAt(QSGItem *item, const QPointF &pos, QSGItem *overlay, + QList<QSGItem *> &resultList) +{ + if (item == overlay) + return; + + if (item->flags() & QSGItem::ItemClipsChildrenToShape) { + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return; + } + + QList<QSGItem *> children = QSGItemPrivate::get(item)->paintOrderChildItems(); + for (int i = children.count() - 1; i >= 0; --i) { + QSGItem *child = children.at(i); + collectItemsAt(child, item->mapToItem(child, pos), overlay, resultList); + } + + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return; + + resultList.append(item); +} + +/* + * Returns the first visible item at the given position, or 0 when no such + * child exists. + */ +static QSGItem *itemAt(QSGItem *item, const QPointF &pos, QSGItem *overlay) +{ + if (item == overlay) + return 0; + + if (!item->isVisible() || item->opacity() == 0.0) + return 0; + + if (item->flags() & QSGItem::ItemClipsChildrenToShape) { + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return 0; + } + + QList<QSGItem *> children = QSGItemPrivate::get(item)->paintOrderChildItems(); + for (int i = children.count() - 1; i >= 0; --i) { + QSGItem *child = children.at(i); + if (QSGItem *betterCandidate = itemAt(child, item->mapToItem(child, pos), overlay)) + return betterCandidate; + } + + if (!(item->flags() & QSGItem::ItemHasContents)) + return 0; + + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return 0; + + return item; +} + + +SGViewInspector::SGViewInspector(QSGView *view, QObject *parent) : + AbstractViewInspector(parent), + m_view(view), + m_overlay(new QSGItem), + m_selectionTool(new SGSelectionTool(this)), + m_designMode(true) +{ + // Try to make sure the overlay is always on top + m_overlay->setZ(FLT_MAX); + + // Make sure mouse hover events are received + m_view->setMouseTracking(true); + + if (QSGItem *root = view->rootItem()) + m_overlay->setParentItem(root); + + view->installEventFilter(this); + setCurrentTool(m_selectionTool); +} + +void SGViewInspector::changeCurrentObjects(const QList<QObject*> &objects) +{ + QList<QSGItem*> items; + foreach (QObject *obj, objects) + if (QSGItem *item = qobject_cast<QSGItem*>(obj)) + items << item; + + syncSelectedItems(items); +} + +void SGViewInspector::reloadView() +{ + // TODO + emit reloadRequested(); +} + +void SGViewInspector::reparentQmlObject(QObject *object, QObject *newParent) +{ + if (!newParent) + return; + + object->setParent(newParent); + QSGItem *newParentItem = qobject_cast<QSGItem*>(newParent); + QSGItem *item = qobject_cast<QSGItem*>(object); + if (newParentItem && item) + item->setParentItem(newParentItem); +} + +void SGViewInspector::changeTool(InspectorProtocol::Tool tool) +{ + switch (tool) { + case InspectorProtocol::ColorPickerTool: + // TODO + emit colorPickerActivated(); + break; + case InspectorProtocol::SelectMarqueeTool: + // TODO + emit marqueeSelectToolActivated(); + break; + case InspectorProtocol::SelectTool: + setCurrentTool(m_selectionTool); + emit selectToolActivated(); + break; + case InspectorProtocol::ZoomTool: + // TODO + emit zoomToolActivated(); + break; + } +} + +QDeclarativeEngine *SGViewInspector::declarativeEngine() const +{ + return m_view->engine(); +} + +QWidget *SGViewInspector::viewWidget() const +{ + return m_view; +} + +QSGItem *SGViewInspector::topVisibleItemAt(const QPointF &pos) const +{ + QSGItem *root = m_view->rootItem(); + return itemAt(root, root->mapFromScene(pos), m_overlay); +} + +QList<QSGItem *> SGViewInspector::itemsAt(const QPointF &pos) const +{ + QSGItem *root = m_view->rootItem(); + QList<QSGItem *> resultList; + collectItemsAt(root, root->mapFromScene(pos), m_overlay, resultList); + return resultList; +} + +QList<QSGItem*> SGViewInspector::selectedItems() const +{ + QList<QSGItem *> selection; + foreach (const QWeakPointer<QSGItem> &selectedItem, m_selectedItems) { + if (selectedItem) + selection << selectedItem.data(); + } + return selection; +} + +void SGViewInspector::setSelectedItems(const QList<QSGItem *> &items) +{ + if (!syncSelectedItems(items)) + return; + + QList<QObject*> objectList; + foreach (QSGItem *item, items) + objectList << item; + + sendCurrentObjects(objectList); +} + +bool SGViewInspector::syncSelectedItems(const QList<QSGItem *> &items) +{ + bool selectionChanged = false; + + // Disconnect and remove items that are no longer selected + foreach (const QWeakPointer<QSGItem> &item, m_selectedItems) { + if (!item) // Don't see how this can happen due to handling of destroyed() + continue; + if (items.contains(item.data())) + continue; + + selectionChanged = true; + item.data()->disconnect(this); + m_selectedItems.removeOne(item); + delete m_highlightItems.take(item.data()); + } + + // Connect and add newly selected items + foreach (QSGItem *item, items) { + if (m_selectedItems.contains(item)) + continue; + + selectionChanged = true; + connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(removeFromSelectedItems(QObject*))); + m_selectedItems.append(item); + m_highlightItems.insert(item, new SGSelectionHighlight(item, m_overlay)); + } + + return selectionChanged; +} + +void SGViewInspector::removeFromSelectedItems(QObject *object) +{ + if (QSGItem *item = qobject_cast<QSGItem*>(object)) { + if (m_selectedItems.removeOne(item)) + delete m_highlightItems.take(item); + } +} + +bool SGViewInspector::eventFilter(QObject *obj, QEvent *event) +{ + if (obj != m_view) + return QObject::eventFilter(obj, event); + + return AbstractViewInspector::eventFilter(obj, event); +} + +bool SGViewInspector::mouseMoveEvent(QMouseEvent *event) +{ + if (QSGItem *item = topVisibleItemAt(event->pos())) + m_view->setToolTip(titleForItem(item)); + else + m_view->setToolTip(QString()); + + return AbstractViewInspector::mouseMoveEvent(event); +} + +QString SGViewInspector::titleForItem(QSGItem *item) const +{ + QString className = QLatin1String(item->metaObject()->className()); + QString objectStringId = idStringForObject(item); + + className.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+"))); + className.remove(QRegExp(QLatin1String("_QML_\\d+"))); + if (className.startsWith(QLatin1String("QSG"))) + className = className.mid(3); + + QString constructedName; + + if (!objectStringId.isEmpty()) { + constructedName = objectStringId + QLatin1String(" (") + className + QLatin1Char(')'); + } else if (!item->objectName().isEmpty()) { + constructedName = item->objectName() + QLatin1String(" (") + className + QLatin1Char(')'); + } else { + constructedName = className; + } + + return constructedName; +} + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h new file mode 100644 index 0000000000..14a5bb1872 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSGVIEWINSPECTOR_H +#define QSGVIEWINSPECTOR_H + +#include "abstractviewinspector.h" + +#include <QtCore/QWeakPointer> +#include <QtCore/QHash> + +QT_BEGIN_NAMESPACE +class QSGView; +class QSGItem; +QT_END_NAMESPACE + +namespace QmlJSDebugger { + +class SGSelectionTool; +class SGSelectionHighlight; + +class SGViewInspector : public AbstractViewInspector +{ + Q_OBJECT +public: + explicit SGViewInspector(QSGView *view, QObject *parent = 0); + + // AbstractViewInspector + void changeCurrentObjects(const QList<QObject*> &objects); + void reloadView(); + void reparentQmlObject(QObject *object, QObject *newParent); + void changeTool(InspectorProtocol::Tool tool); + QWidget *viewWidget() const; + QDeclarativeEngine *declarativeEngine() const; + + QSGView *view() const { return m_view; } + QSGItem *overlay() const { return m_overlay; } + + QSGItem *topVisibleItemAt(const QPointF &pos) const; + QList<QSGItem *> itemsAt(const QPointF &pos) const; + + QList<QSGItem *> selectedItems() const; + void setSelectedItems(const QList<QSGItem*> &items); + + QString titleForItem(QSGItem *item) const; + +protected: + bool eventFilter(QObject *obj, QEvent *event); + + bool mouseMoveEvent(QMouseEvent *); + +private slots: + void removeFromSelectedItems(QObject *); + +private: + bool syncSelectedItems(const QList<QSGItem*> &items); + + QSGView *m_view; + QSGItem *m_overlay; + + SGSelectionTool *m_selectionTool; + + QList<QWeakPointer<QSGItem> > m_selectedItems; + QHash<QSGItem*, SGSelectionHighlight*> m_highlightItems; + + bool m_designMode; +}; + +} // namespace QmlJSDebugger + +#endif // QSGVIEWINSPECTOR_H diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index dda5d3da87..7e50118041 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -66,6 +66,7 @@ #endif QString pluginImportPath; +bool verbose = false; void collectReachableMetaObjects(const QMetaObject *meta, QSet<const QMetaObject *> *metas) { @@ -88,13 +89,15 @@ void collectReachableMetaObjects(QObject *object, QSet<const QMetaObject *> *met return; const QMetaObject *meta = object->metaObject(); - qDebug() << "Processing object" << meta->className(); + if (verbose) + qDebug() << "Processing object" << meta->className(); collectReachableMetaObjects(meta, metas); for (int index = 0; index < meta->propertyCount(); ++index) { QMetaProperty prop = meta->property(index); if (QDeclarativeMetaType::isQObject(prop.userType())) { - qDebug() << " Processing property" << prop.name(); + if (verbose) + qDebug() << " Processing property" << prop.name(); currentProperty = QString("%1::%2").arg(meta->className(), prop.name()); // if the property was not initialized during construction, @@ -157,29 +160,36 @@ QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode, collectReachableMetaObjects(ty, &metas); } - // Adjust ids of extended objects. - // The chain ends up being: - // __extended__.originalname - the base object - // __extension_0_.originalname - first extension - // .. - // __extension_n-2_.originalname - second to last extension - // originalname - last extension - // ### does this actually work for multiple extensions? it seems like the prototypes might be wrong - foreach (const QByteArray &extendedCpp, extensions.keys()) { - cppToId.remove(extendedCpp); - const QByteArray extendedId = convertToId(extendedCpp); - cppToId.insert(extendedCpp, "__extended__." + extendedId); - QSet<QByteArray> extensionCppNames = extensions.value(extendedCpp); - int c = 0; + // Adjust exports of the base object if there are extensions. + // For each export of a base object there can be a single extension object overriding it. + // Example: QDeclarativeGraphicsWidget overrides the QtQuick/QGraphicsWidget export + // of QGraphicsWidget. + foreach (const QByteArray &baseCpp, extensions.keys()) { + QSet<const QDeclarativeType *> baseExports = qmlTypesByCppName.value(baseCpp); + + const QSet<QByteArray> extensionCppNames = extensions.value(baseCpp); foreach (const QByteArray &extensionCppName, extensionCppNames) { - if (c != extensionCppNames.size() - 1) { - QByteArray adjustedName = QString("__extension__%1.%2").arg(QString::number(c), QString(extendedId)).toAscii(); - cppToId.insert(extensionCppName, adjustedName); - } else { - cppToId.insert(extensionCppName, extendedId); + const QSet<const QDeclarativeType *> extensionExports = qmlTypesByCppName.value(extensionCppName); + + // remove extension exports from base imports + // unfortunately the QDeclarativeType pointers don't match, so can't use QSet::substract + QSet<const QDeclarativeType *> newBaseExports; + foreach (const QDeclarativeType *baseExport, baseExports) { + bool match = false; + foreach (const QDeclarativeType *extensionExport, extensionExports) { + if (baseExport->module() == extensionExport->module() + && baseExport->majorVersion() == extensionExport->majorVersion() + && baseExport->minorVersion() == extensionExport->minorVersion()) { + match = true; + break; + } + } + if (!match) + newBaseExports.insert(baseExport); } - ++c; + baseExports = newBaseExports; } + qmlTypesByCppName[baseCpp] = baseExports; } // find even more QMetaObjects by instantiating QML types and running @@ -187,9 +197,15 @@ QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode, foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { if (ty->isExtendedType()) continue; + if (!ty->isCreatable()) + continue; + if (ty->typeName() == "QDeclarativeComponent") + continue; QByteArray tyName = ty->qmlTypeName(); tyName = tyName.mid(tyName.lastIndexOf('/') + 1); + if (tyName.isEmpty()) + continue; QByteArray code = importCode.toUtf8(); code += tyName; @@ -202,7 +218,7 @@ QSet<const QMetaObject *> collectReachableMetaObjects(const QString &importCode, if (object) collectReachableMetaObjects(object, &metas); else - qDebug() << "Could not create" << tyName << ":" << c.errorString(); + qWarning() << "Could not create" << tyName << ":" << c.errorString(); } return metas; @@ -424,9 +440,9 @@ void sigSegvHandler(int) { void printUsage(const QString &appName) { qWarning() << qPrintable(QString( - "Usage: %1 [-notrelocatable] module.uri version [module/import/path]\n" - " %1 -path path/to/qmldir/directory [version]\n" - " %1 -builtins\n" + "Usage: %1 [-v] [-notrelocatable] module.uri version [module/import/path]\n" + " %1 [-v] -path path/to/qmldir/directory [version]\n" + " %1 [-v] -builtins\n" "Example: %1 Qt.labs.particles 4.7 /home/user/dev/qt-install/imports").arg( appName)); } @@ -436,13 +452,13 @@ int main(int argc, char *argv[]) #ifdef Q_OS_UNIX // qmldump may crash, but we don't want any crash handlers to pop up // therefore we intercept the segfault and just exit() ourselves - struct sigaction action; + struct sigaction sigAction; - sigemptyset(&action.sa_mask); - action.sa_handler = &sigSegvHandler; - action.sa_flags = 0; + sigemptyset(&sigAction.sa_mask); + sigAction.sa_handler = &sigSegvHandler; + sigAction.sa_flags = 0; - sigaction(SIGSEGV, &action, 0); + sigaction(SIGSEGV, &sigAction, 0); #endif #ifdef QT_SIMULATOR @@ -452,10 +468,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); const QStringList args = app.arguments(); const QString appName = QFileInfo(app.applicationFilePath()).baseName(); - if (!(args.size() >= 3 - || (args.size() == 2 - && (args.at(1) == QLatin1String("--builtins") - || args.at(1) == QLatin1String("-builtins"))))) { + if (args.size() < 2) { printUsage(appName); return EXIT_INVALIDARGUMENTS; } @@ -463,8 +476,9 @@ int main(int argc, char *argv[]) QString pluginImportUri; QString pluginImportVersion; bool relocatable = true; - bool pathImport = false; - if (args.size() >= 3) { + enum Action { Uri, Path, Builtins }; + Action action = Uri; + { QStringList positionalArgs; foreach (const QString &arg, args) { if (!arg.startsWith(QLatin1Char('-'))) { @@ -477,14 +491,19 @@ int main(int argc, char *argv[]) relocatable = false; } else if (arg == QLatin1String("--path") || arg == QLatin1String("-path")) { - pathImport = true; + action = Path; + } else if (arg == QLatin1String("--builtins") + || arg == QLatin1String("-builtins")) { + action = Builtins; + } else if (arg == QLatin1String("-v")) { + verbose = true; } else { qWarning() << "Invalid argument: " << arg; return EXIT_INVALIDARGUMENTS; } } - if (!pathImport) { + if (action == Uri) { if (positionalArgs.size() != 3 && positionalArgs.size() != 4) { qWarning() << "Incorrect number of positional arguments"; return EXIT_INVALIDARGUMENTS; @@ -493,7 +512,7 @@ int main(int argc, char *argv[]) pluginImportVersion = positionalArgs[2]; if (positionalArgs.size() >= 4) pluginImportPath = positionalArgs[3]; - } else { + } else if (action == Path) { if (positionalArgs.size() != 2 && positionalArgs.size() != 3) { qWarning() << "Incorrect number of positional arguments"; return EXIT_INVALIDARGUMENTS; @@ -501,6 +520,11 @@ int main(int argc, char *argv[]) pluginImportPath = QDir::fromNativeSeparators(positionalArgs[1]); if (positionalArgs.size() == 3) pluginImportVersion = positionalArgs[2]; + } else if (action == Builtins) { + if (positionalArgs.size() != 1) { + qWarning() << "Incorrect number of positional arguments"; + return EXIT_INVALIDARGUMENTS; + } } } @@ -516,11 +540,11 @@ int main(int argc, char *argv[]) // this will hold the meta objects we want to dump information of QSet<const QMetaObject *> metas; - if (pluginImportUri.isEmpty() && !pathImport) { + if (action == Builtins) { metas = defaultReachable; } else { // find all QMetaObjects reachable when the specified module is imported - if (!pathImport) { + if (action != Path) { importCode += QString("import %0 %1\n").arg(pluginImportUri, pluginImportVersion).toAscii(); } else { // pluginImportVersion can be empty @@ -567,7 +591,7 @@ int main(int argc, char *argv[]) QmlStreamWriter qml(&bytes); qml.writeStartDocument(); - qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 0); + qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 1); qml.write("\n" "// This file describes the plugin-supplied types contained in the library.\n" "// It is used for QML tooling purposes only.\n" diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro index b9fc0fc0ad..2e5ac5e366 100644 --- a/tools/qmlplugindump/qmlplugindump.pro +++ b/tools/qmlplugindump/qmlplugindump.pro @@ -16,5 +16,22 @@ HEADERS += \ OTHER_FILES += Info.plist macx: QMAKE_INFO_PLIST = Info.plist +# Build debug and release versions of the tool on Windows - +# if debug and release versions of Qt have been built. +!build_pass:win32 { + CONFIG -= debug release debug_and_release build_all + + contains(QT_CONFIG,debug):contains(QT_CONFIG,release) { + CONFIG += debug_and_release build_all + } else { + contains(QT_CONFIG,debug): CONFIG += debug + contains(QT_CONFIG,release): CONFIG += release + } +} + +CONFIG(debug, debug|release) { + win32: TARGET = $$join(TARGET,,,d) +} + target.path = $$[QT_INSTALL_BINS] INSTALLS += target |