From 1695f0622b4673c49ccb6b127f1a7d9b24611d80 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 26 Oct 2011 15:52:48 +0200 Subject: Debugger: Split inspector plugin into a qtquick1 and a qtquick2 plugin This allows the inspector to be used also when e.g. qtquick1 and widgets libraries are not available. Change-Id: Id8510ea2a1a9c2a776d67e6d7732a4e40363d5a3 Reviewed-by: Aurindam Jana --- .../qmltooling/qmldbg_inspector/abstracttool.cpp | 54 --- .../qmltooling/qmldbg_inspector/abstracttool.h | 85 ---- .../qmldbg_inspector/abstractviewinspector.cpp | 507 --------------------- .../qmldbg_inspector/abstractviewinspector.h | 166 ------- .../qdeclarativeinspectorplugin.cpp | 85 ---- .../qmldbg_inspector/qdeclarativeinspectorplugin.h | 71 --- .../qdeclarativeinspectorprotocol.h | 137 ------ .../qmldbg_inspector/qmldbg_inspector.pro | 57 --- .../qmldbg_inspector/qmlinspectorconstants.h | 77 ---- .../qtquick1/abstractliveedittool.cpp | 196 -------- .../qtquick1/abstractliveedittool.h | 104 ----- .../qtquick1/boundingrecthighlighter.cpp | 240 ---------- .../qtquick1/boundingrecthighlighter.h | 115 ----- .../qmldbg_inspector/qtquick1/colorpickertool.cpp | 98 ---- .../qmldbg_inspector/qtquick1/colorpickertool.h | 92 ---- .../qmldbg_inspector/qtquick1/livelayeritem.cpp | 92 ---- .../qmldbg_inspector/qtquick1/livelayeritem.h | 67 --- .../liverubberbandselectionmanipulator.cpp | 165 ------- .../qtquick1/liverubberbandselectionmanipulator.h | 96 ---- .../qtquick1/liveselectionindicator.cpp | 118 ----- .../qtquick1/liveselectionindicator.h | 80 ---- .../qtquick1/liveselectionrectangle.cpp | 113 ----- .../qtquick1/liveselectionrectangle.h | 77 ---- .../qtquick1/liveselectiontool.cpp | 423 ----------------- .../qmldbg_inspector/qtquick1/liveselectiontool.h | 120 ----- .../qtquick1/livesingleselectionmanipulator.cpp | 151 ------ .../qtquick1/livesingleselectionmanipulator.h | 89 ---- .../qtquick1/qdeclarativeviewinspector.cpp | 445 ------------------ .../qtquick1/qdeclarativeviewinspector.h | 100 ---- .../qtquick1/qdeclarativeviewinspector_p.h | 119 ----- .../qtquick1/subcomponentmasklayeritem.cpp | 130 ------ .../qtquick1/subcomponentmasklayeritem.h | 71 --- .../qmldbg_inspector/qtquick1/zoomtool.cpp | 328 ------------- .../qmldbg_inspector/qtquick1/zoomtool.h | 107 ----- .../qmltooling/qmldbg_inspector/sghighlight.cpp | 98 ---- .../qmltooling/qmldbg_inspector/sghighlight.h | 97 ---- .../qmldbg_inspector/sgselectiontool.cpp | 135 ------ .../qmltooling/qmldbg_inspector/sgselectiontool.h | 91 ---- .../qmldbg_inspector/sgviewinspector.cpp | 330 -------------- .../qmltooling/qmldbg_inspector/sgviewinspector.h | 110 ----- .../qmldbg_qtquick1/abstractliveedittool.cpp | 197 ++++++++ .../qmldbg_qtquick1/abstractliveedittool.h | 106 +++++ .../qmldbg_qtquick1/boundingrecthighlighter.cpp | 241 ++++++++++ .../qmldbg_qtquick1/boundingrecthighlighter.h | 117 +++++ .../qmltooling/qmldbg_qtquick1/colorpickertool.cpp | 100 ++++ .../qmltooling/qmldbg_qtquick1/colorpickertool.h | 94 ++++ .../qmltooling/qmldbg_qtquick1/livelayeritem.cpp | 94 ++++ .../qmltooling/qmldbg_qtquick1/livelayeritem.h | 69 +++ .../liverubberbandselectionmanipulator.cpp | 167 +++++++ .../liverubberbandselectionmanipulator.h | 98 ++++ .../qmldbg_qtquick1/liveselectionindicator.cpp | 120 +++++ .../qmldbg_qtquick1/liveselectionindicator.h | 82 ++++ .../qmldbg_qtquick1/liveselectionrectangle.cpp | 115 +++++ .../qmldbg_qtquick1/liveselectionrectangle.h | 79 ++++ .../qmldbg_qtquick1/liveselectiontool.cpp | 425 +++++++++++++++++ .../qmltooling/qmldbg_qtquick1/liveselectiontool.h | 122 +++++ .../livesingleselectionmanipulator.cpp | 153 +++++++ .../livesingleselectionmanipulator.h | 91 ++++ .../qmldbg_qtquick1/qdeclarativeviewinspector.cpp | 447 ++++++++++++++++++ .../qmldbg_qtquick1/qdeclarativeviewinspector.h | 102 +++++ .../qmldbg_qtquick1/qdeclarativeviewinspector_p.h | 121 +++++ .../qmltooling/qmldbg_qtquick1/qmldbg_qtquick1.pro | 50 ++ .../qmltooling/qmldbg_qtquick1/qtquick1plugin.cpp | 88 ++++ .../qmltooling/qmldbg_qtquick1/qtquick1plugin.h | 77 ++++ .../qmldbg_qtquick1/subcomponentmasklayeritem.cpp | 132 ++++++ .../qmldbg_qtquick1/subcomponentmasklayeritem.h | 73 +++ .../qmltooling/qmldbg_qtquick1/zoomtool.cpp | 330 ++++++++++++++ src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.h | 109 +++++ .../qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro | 31 ++ .../qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp | 88 ++++ .../qmltooling/qmldbg_qtquick2/qtquick2plugin.h | 77 ++++ .../qmltooling/qmldbg_qtquick2/sghighlight.cpp | 100 ++++ .../qmltooling/qmldbg_qtquick2/sghighlight.h | 99 ++++ .../qmltooling/qmldbg_qtquick2/sgselectiontool.cpp | 137 ++++++ .../qmltooling/qmldbg_qtquick2/sgselectiontool.h | 93 ++++ .../qmltooling/qmldbg_qtquick2/sgviewinspector.cpp | 332 ++++++++++++++ .../qmltooling/qmldbg_qtquick2/sgviewinspector.h | 112 +++++ src/plugins/qmltooling/qmltooling.pro | 5 +- src/plugins/qmltooling/shared/abstracttool.cpp | 54 +++ src/plugins/qmltooling/shared/abstracttool.h | 85 ++++ .../qmltooling/shared/abstractviewinspector.cpp | 504 ++++++++++++++++++++ .../qmltooling/shared/abstractviewinspector.h | 167 +++++++ .../shared/qdeclarativeinspectorprotocol.h | 137 ++++++ .../qmltooling/shared/qmlinspectorconstants.h | 77 ++++ 84 files changed, 6095 insertions(+), 5838 deletions(-) delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/abstracttool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector_p.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sghighlight.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector_p.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/qmldbg_qtquick1.pro create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.h create mode 100644 src/plugins/qmltooling/shared/abstracttool.cpp create mode 100644 src/plugins/qmltooling/shared/abstracttool.h create mode 100644 src/plugins/qmltooling/shared/abstractviewinspector.cpp create mode 100644 src/plugins/qmltooling/shared/abstractviewinspector.h create mode 100644 src/plugins/qmltooling/shared/qdeclarativeinspectorprotocol.h create mode 100644 src/plugins/qmltooling/shared/qmlinspectorconstants.h (limited to 'src/plugins') diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp b/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp deleted file mode 100644 index 39ced2a9d0..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.cpp +++ /dev/null @@ -1,54 +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$ -** -****************************************************************************/ - -#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 deleted file mode 100644 index 0a216bfa83..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/abstracttool.h +++ /dev/null @@ -1,85 +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 ABSTRACTTOOL_H -#define ABSTRACTTOOL_H - -#include - -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 deleted file mode 100644 index 1cebbd4283..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.cpp +++ /dev/null @@ -1,507 +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$ -** -****************************************************************************/ - -#include "abstractviewinspector.h" - -#include "abstracttool.h" -#include "qdeclarativeinspectorprotocol.h" - -#include -#include -#include -#include - -#include - -namespace QmlJSDebugger { - - -AbstractViewInspector::AbstractViewInspector(QObject *parent) : - QObject(parent), - m_currentTool(0), - m_showAppOnTop(false), - m_designModeBehavior(false), - m_animationPaused(false), - m_slowDownFactor(1.0), - m_debugService(0) -{ - 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; - QUnifiedTimer::instance()->setSlowModeEnabled(effectiveFactor != 1.0); - QUnifiedTimer::instance()->setSlowdownFactor(effectiveFactor); -} - -void AbstractViewInspector::animationPausedChangeRequested(bool paused) -{ - if (m_animationPaused != paused) { - m_animationPaused = paused; - emit animationPausedChanged(paused); - } - - const float effectiveFactor = paused ? 0 : m_slowDownFactor; - QUnifiedTimer::instance()->setSlowModeEnabled(effectiveFactor != 1.0); - QUnifiedTimer::instance()->setSlowdownFactor(effectiveFactor); -} - -void AbstractViewInspector::setShowAppOnTop(bool appOnTop) -{ - Qt::WindowFlags flags = windowFlags(); - if (appOnTop) - flags |= Qt::WindowStaysOnTopHint; - else - flags &= ~Qt::WindowStaysOnTopHint; - - setWindowFlags(flags); - - m_showAppOnTop = appOnTop; - sendShowAppOnTop(appOnTop); - - emit showAppOnTopChanged(appOnTop); -} - -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(event))) - return true; - break; - case QEvent::MouseMove: - if (mouseMoveEvent(static_cast(event))) - return true; - break; - case QEvent::MouseButtonRelease: - if (mouseReleaseEvent(static_cast(event))) - return true; - break; - case QEvent::KeyPress: - if (keyPressEvent(static_cast(event))) - return true; - break; - case QEvent::KeyRelease: - if (keyReleaseEvent(static_cast(event))) - return true; - break; - case QEvent::MouseButtonDblClick: - if (mouseDoubleClickEvent(static_cast(event))) - return true; - break; - case QEvent::Wheel: - if (wheelEvent(static_cast(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 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 &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 diff --git a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h deleted file mode 100644 index ee6eea5aee..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/abstractviewinspector.h +++ /dev/null @@ -1,166 +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 ABSTRACTVIEWINSPECTOR_H -#define ABSTRACTVIEWINSPECTOR_H - -#include -#include -#include -#include - -#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; - -/* - * The common code between QQuickView and QDeclarativeView inspectors lives here, - */ -class AbstractViewInspector : public QObject -{ - Q_OBJECT - -public: - explicit AbstractViewInspector(QObject *parent = 0); - - void createQmlObject(const QString &qml, QObject *parent, - const QStringList &importList, - const QString &filename = QString()); - void clearComponentCache(); - - 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 &); - void sendAnimationSpeed(qreal slowDownFactor); - void sendAnimationPaused(bool paused); - void sendCurrentTool(Constants::DesignTool toolId); - void sendReloaded(); - void sendShowAppOnTop(bool showAppOnTop); - - QString idStringForObject(QObject *obj) const; - - virtual void changeCurrentObjects(const QList &objects) = 0; - virtual void reloadView() = 0; - virtual void reparentQmlObject(QObject *object, QObject *newParent) = 0; - virtual void changeTool(InspectorProtocol::Tool tool) = 0; - virtual Qt::WindowFlags windowFlags() const = 0; - virtual void setWindowFlags(Qt::WindowFlags flags) = 0; - virtual QDeclarativeEngine *declarativeEngine() const = 0; - -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: - AbstractTool *currentTool() const { return m_currentTool; } - void setCurrentTool(AbstractTool *tool) { m_currentTool = tool; } - 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); - -private slots: - void handleMessage(const QByteArray &message); - void sendColorChanged(const QColor &color); - -private: - void sendDesignModeBehavior(bool inDesignMode); - - 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); - - void animationSpeedChangeRequested(qreal factor); - void animationPausedChangeRequested(bool paused); - - AbstractTool *m_currentTool; - - bool m_showAppOnTop; - bool m_designModeBehavior; - - bool m_animationPaused; - qreal m_slowDownFactor; - - QHash m_stringIdForObjectId; - QDeclarativeInspectorService *m_debugService; -}; - -} // namespace QmlJSDebugger - -#endif // ABSTRACTVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp deleted file mode 100644 index f4eec5011d..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.cpp +++ /dev/null @@ -1,85 +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$ -** -****************************************************************************/ - -#include "qdeclarativeinspectorplugin.h" - -#include "qtquick1/qdeclarativeviewinspector_p.h" -#include "sgviewinspector.h" - -#include -#include -#include - -namespace QmlJSDebugger { - -QDeclarativeInspectorPlugin::QDeclarativeInspectorPlugin() : - m_inspector(0) -{ -} - -QDeclarativeInspectorPlugin::~QDeclarativeInspectorPlugin() -{ - delete m_inspector; -} - -void QDeclarativeInspectorPlugin::activate() -{ - QDeclarativeInspectorService *service = QDeclarativeInspectorService::instance(); - QList views = service->views(); - if (views.isEmpty()) - return; - - // TODO: Support multiple views - QObject *firstView = views.first(); - if (QDeclarativeView *declarativeView = qobject_cast(firstView)) - m_inspector = new QDeclarativeViewInspector(declarativeView, declarativeView); - else if (QQuickView *sgView = qobject_cast(firstView)) - m_inspector = new SGViewInspector(sgView, sgView); -} - -void QDeclarativeInspectorPlugin::deactivate() -{ - delete m_inspector; -} - -} // 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 deleted file mode 100644 index 542925366c..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorplugin.h +++ /dev/null @@ -1,71 +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 QDECLARATIVEINSPECTORPLUGIN_H -#define QDECLARATIVEINSPECTORPLUGIN_H - -#include -#include - -namespace QmlJSDebugger { - -class AbstractViewInspector; - -class QDeclarativeInspectorPlugin : public QObject, public QDeclarativeInspectorInterface -{ - Q_OBJECT - Q_DISABLE_COPY(QDeclarativeInspectorPlugin) - Q_INTERFACES(QDeclarativeInspectorInterface) - -public: - QDeclarativeInspectorPlugin(); - ~QDeclarativeInspectorPlugin(); - - void activate(); - void deactivate(); - -private: - QPointer m_inspector; -}; - -} // namespace QmlJSDebugger - -#endif // QDECLARATIVEINSPECTORPLUGIN_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h b/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h deleted file mode 100644 index 082abeb9bd..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qdeclarativeinspectorprotocol.h +++ /dev/null @@ -1,137 +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 QDECLARATIVEINSPECTORPROTOCOL_H -#define QDECLARATIVEINSPECTORPROTOCOL_H - -#include -#include -#include -#include - -namespace QmlJSDebugger { - -class InspectorProtocol : public QObject -{ - Q_OBJECT - Q_ENUMS(Message Tool) - -public: - enum Message { - AnimationSpeedChanged = 0, - AnimationPausedChanged = 19, // highest value - ChangeTool = 1, - ClearComponentCache = 2, - ColorChanged = 3, - CreateObject = 5, - CurrentObjectsChanged = 6, - DestroyObject = 7, - MoveObject = 8, - ObjectIdList = 9, - Reload = 10, - Reloaded = 11, - SetAnimationSpeed = 12, - SetAnimationPaused = 18, - SetCurrentObjects = 14, - SetDesignMode = 15, - ShowAppOnTop = 16, - ToolChanged = 17 - }; - - enum Tool { - ColorPickerTool, - SelectMarqueeTool, - SelectTool, - ZoomTool - }; - - static inline QString toString(Message message) - { - return QLatin1String(staticMetaObject.enumerator(0).valueToKey(message)); - } - - static inline QString toString(Tool tool) - { - return QLatin1String(staticMetaObject.enumerator(1).valueToKey(tool)); - } -}; - -inline QDataStream & operator<< (QDataStream &stream, InspectorProtocol::Message message) -{ - return stream << static_cast(message); -} - -inline QDataStream & operator>> (QDataStream &stream, InspectorProtocol::Message &message) -{ - quint32 i; - stream >> i; - message = static_cast(i); - return stream; -} - -inline QDebug operator<< (QDebug dbg, InspectorProtocol::Message message) -{ - dbg << InspectorProtocol::toString(message); - return dbg; -} - -inline QDataStream & operator<< (QDataStream &stream, InspectorProtocol::Tool tool) -{ - return stream << static_cast(tool); -} - -inline QDataStream & operator>> (QDataStream &stream, InspectorProtocol::Tool &tool) -{ - quint32 i; - stream >> i; - tool = static_cast(i); - return stream; -} - -inline QDebug operator<< (QDebug dbg, InspectorProtocol::Tool tool) -{ - dbg << InspectorProtocol::toString(tool); - return dbg; -} - -} // namespace QmlJSDebugger - -#endif // QDECLARATIVEINSPECTORPROTOCOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro deleted file mode 100644 index 0c870bbf2d..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro +++ /dev/null @@ -1,57 +0,0 @@ -load(qt_module) - -TARGET = qmldbg_inspector -QT += declarative-private core-private gui-private opengl-private qtquick1 widgets widgets-private v8-private - -load(qt_plugin) - -DESTDIR = $$QT.declarative.plugins/qmltooling -QTDIR_build:REQUIRES += "contains(QT_CONFIG, declarative)" - -INCLUDEPATH *= $$PWD - -SOURCES += \ - abstractviewinspector.cpp \ - qdeclarativeinspectorplugin.cpp \ - qtquick1/qdeclarativeviewinspector.cpp \ - qtquick1/abstractliveedittool.cpp \ - qtquick1/liveselectiontool.cpp \ - qtquick1/livelayeritem.cpp \ - qtquick1/livesingleselectionmanipulator.cpp \ - qtquick1/liverubberbandselectionmanipulator.cpp \ - qtquick1/liveselectionrectangle.cpp \ - qtquick1/liveselectionindicator.cpp \ - qtquick1/boundingrecthighlighter.cpp \ - qtquick1/subcomponentmasklayeritem.cpp \ - qtquick1/zoomtool.cpp \ - qtquick1/colorpickertool.cpp \ - abstracttool.cpp \ - sgviewinspector.cpp \ - sgselectiontool.cpp \ - sghighlight.cpp - -HEADERS += \ - abstractviewinspector.h \ - qdeclarativeinspectorplugin.h \ - qdeclarativeinspectorprotocol.h \ - qmlinspectorconstants.h \ - qtquick1/qdeclarativeviewinspector.h \ - qtquick1/qdeclarativeviewinspector_p.h \ - qtquick1/abstractliveedittool.h \ - qtquick1/liveselectiontool.h \ - qtquick1/livelayeritem.h \ - qtquick1/livesingleselectionmanipulator.h \ - qtquick1/liverubberbandselectionmanipulator.h \ - qtquick1/liveselectionrectangle.h \ - qtquick1/liveselectionindicator.h \ - qtquick1/boundingrecthighlighter.h \ - qtquick1/subcomponentmasklayeritem.h \ - qtquick1/zoomtool.h \ - qtquick1/colorpickertool.h \ - abstracttool.h \ - sgviewinspector.h \ - sgselectiontool.h \ - sghighlight.h - -target.path += $$[QT_INSTALL_PLUGINS]/qmltooling -INSTALLS += target diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants.h b/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants.h deleted file mode 100644 index 5335222865..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qmlinspectorconstants.h +++ /dev/null @@ -1,77 +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 QMLINSPECTORCONSTANTS_H -#define QMLINSPECTORCONSTANTS_H - -#include - -namespace QmlJSDebugger { -namespace Constants { - -enum DesignTool { - NoTool = 0, - SelectionToolMode = 1, - MarqueeSelectionToolMode = 2, - MoveToolMode = 3, - ResizeToolMode = 4, - ColorPickerMode = 5, - ZoomMode = 6 -}; - -static const int DragStartTime = 50; - -static const int DragStartDistance = 20; - -static const double ZoomSnapDelta = 0.04; - -static const int EditorItemDataKey = 1000; - -enum GraphicsItemTypes { - EditorItemType = 0xEAAA, - ResizeHandleItemType = 0xEAEA -}; - - -} // namespace Constants -} // namespace QmlJSDebugger - -#endif // QMLINSPECTORCONSTANTS_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.cpp deleted file mode 100644 index c2482929ca..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.cpp +++ /dev/null @@ -1,196 +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$ -** -****************************************************************************/ - -#include "abstractliveedittool.h" -#include "qdeclarativeviewinspector_p.h" - -#include - -#include -#include -#include - -namespace QmlJSDebugger { - -AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewInspector *editorView) - : AbstractTool(editorView) -{ -} - - -AbstractLiveEditTool::~AbstractLiveEditTool() -{ -} - -QDeclarativeViewInspector *AbstractLiveEditTool::inspector() const -{ - return static_cast(AbstractTool::inspector()); -} - -QDeclarativeView *AbstractLiveEditTool::view() const -{ - return inspector()->declarativeView(); -} - -QGraphicsScene* AbstractLiveEditTool::scene() const -{ - return view()->scene(); -} - -void AbstractLiveEditTool::updateSelectedItems() -{ - selectedItemsChanged(items()); -} - -QList AbstractLiveEditTool::items() const -{ - return inspector()->selectedItems(); -} - -bool AbstractLiveEditTool::topItemIsMovable(const QList & itemList) -{ - QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList); - if (firstSelectableItem == 0) - return false; - if (toQDeclarativeItem(firstSelectableItem) != 0) - return true; - - return false; - -} - -bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList &itemList) -{ - QList selectedItems = inspector()->selectedItems(); - - foreach (QGraphicsItem *item, itemList) { - QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); - if (declarativeItem - && selectedItems.contains(declarativeItem) - /*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/) - return true; - } - - return false; - -} - -bool AbstractLiveEditTool::topItemIsResizeHandle(const QList &/*itemList*/) -{ - return false; -} - -QDeclarativeItem *AbstractLiveEditTool::toQDeclarativeItem(QGraphicsItem *item) -{ - return qobject_cast(item->toGraphicsObject()); -} - -QGraphicsItem *AbstractLiveEditTool::topMovableGraphicsItem(const QList &itemList) -{ - foreach (QGraphicsItem *item, itemList) { - if (item->flags().testFlag(QGraphicsItem::ItemIsMovable)) - return item; - } - return 0; -} - -QDeclarativeItem *AbstractLiveEditTool::topMovableDeclarativeItem(const QList - &itemList) -{ - foreach (QGraphicsItem *item, itemList) { - QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); - if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/) - return declarativeItem; - } - - return 0; -} - -QList AbstractLiveEditTool::toGraphicsObjectList(const QList - &itemList) -{ - QList gfxObjects; - foreach (QGraphicsItem *item, itemList) { - QGraphicsObject *obj = item->toGraphicsObject(); - if (obj) - gfxObjects << obj; - } - - return gfxObjects; -} - -QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) -{ - QString className(QLatin1String("QGraphicsItem")); - QString objectStringId; - - QString constructedName; - - QGraphicsObject *gfxObject = item->toGraphicsObject(); - if (gfxObject) { - className = QLatin1String(gfxObject->metaObject()->className()); - - className.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+"))); - className.remove(QRegExp(QLatin1String("_QML_\\d+"))); - if (className.startsWith(QLatin1String("QDeclarative"))) - className = className.remove(QLatin1String("QDeclarative")); - - QDeclarativeItem *declarativeItem = qobject_cast(gfxObject); - if (declarativeItem) { - objectStringId = inspector()->idStringForObject(declarativeItem); - } - - if (!objectStringId.isEmpty()) { - constructedName = objectStringId + QLatin1String(" (") + className + QLatin1Char(')'); - } else { - if (!gfxObject->objectName().isEmpty()) { - constructedName = gfxObject->objectName() + QLatin1String(" (") + className + QLatin1Char(')'); - } else { - constructedName = className; - } - } - } - - return constructedName; -} - - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.h deleted file mode 100644 index 04b5f4e46e..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/abstractliveedittool.h +++ /dev/null @@ -1,104 +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 ABSTRACTLIVEEDITTOOL_H -#define ABSTRACTLIVEEDITTOOL_H - -#include -#include "../abstracttool.h" - -QT_BEGIN_NAMESPACE -class QMouseEvent; -class QGraphicsItem; -class QDeclarativeItem; -class QKeyEvent; -class QGraphicsScene; -class QGraphicsObject; -class QWheelEvent; -class QDeclarativeView; -QT_END_NAMESPACE - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; - -class AbstractLiveEditTool : public AbstractTool -{ - Q_OBJECT -public: - AbstractLiveEditTool(QDeclarativeViewInspector *inspector); - - virtual ~AbstractLiveEditTool(); - - void leaveEvent(QEvent *) {} - - virtual void itemsAboutToRemoved(const QList &itemList) = 0; - - virtual void clear() = 0; - - void updateSelectedItems(); - QList items() const; - - bool topItemIsMovable(const QList &itemList); - bool topItemIsResizeHandle(const QList &itemList); - bool topSelectedItemIsMovable(const QList &itemList); - - QString titleForItem(QGraphicsItem *item); - - static QList toGraphicsObjectList(const QList &itemList); - static QGraphicsItem* topMovableGraphicsItem(const QList &itemList); - static QDeclarativeItem* topMovableDeclarativeItem(const QList &itemList); - static QDeclarativeItem *toQDeclarativeItem(QGraphicsItem *item); - -protected: - virtual void selectedItemsChanged(const QList &objectList) = 0; - - QDeclarativeViewInspector *inspector() const; - QDeclarativeView *view() const; - QGraphicsScene *scene() const; - -private: - QList m_itemList; -}; - -} - -#endif // ABSTRACTLIVEEDITTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.cpp deleted file mode 100644 index e097d3cd77..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.cpp +++ /dev/null @@ -1,240 +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$ -** -****************************************************************************/ - -#include "boundingrecthighlighter.h" - -#include "qdeclarativeviewinspector.h" -#include "../qmlinspectorconstants.h" - -#include - -#include -#include -#include - -namespace QmlJSDebugger { - -BoundingBox::BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, - QObject *parent) - : QObject(parent), - highlightedObject(itemToHighlight), - highlightPolygon(0), - highlightPolygonEdge(0) -{ - highlightPolygon = new BoundingBoxPolygonItem(parentItem); - highlightPolygonEdge = new BoundingBoxPolygonItem(parentItem); - - highlightPolygon->setPen(QPen(QColor(0, 22, 159))); - highlightPolygonEdge->setPen(QPen(QColor(158, 199, 255))); - - highlightPolygon->setFlag(QGraphicsItem::ItemIsSelectable, false); - highlightPolygonEdge->setFlag(QGraphicsItem::ItemIsSelectable, false); -} - -BoundingBox::~BoundingBox() -{ - highlightedObject.clear(); -} - -BoundingBoxPolygonItem::BoundingBoxPolygonItem(QGraphicsItem *item) : QGraphicsPolygonItem(item) -{ - QPen pen; - pen.setColor(QColor(108, 141, 221)); - pen.setWidth(1); - setPen(pen); -} - -int BoundingBoxPolygonItem::type() const -{ - return Constants::EditorItemType; -} - -BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewInspector *view) : - LiveLayerItem(view->declarativeView()->scene()), - m_view(view) -{ -} - -BoundingRectHighlighter::~BoundingRectHighlighter() -{ - -} - -void BoundingRectHighlighter::clear() -{ - foreach (BoundingBox *box, m_boxes) - freeBoundingBox(box); -} - -BoundingBox *BoundingRectHighlighter::boxFor(QGraphicsObject *item) const -{ - foreach (BoundingBox *box, m_boxes) { - if (box->highlightedObject.data() == item) - return box; - } - return 0; -} - -void BoundingRectHighlighter::highlight(QList items) -{ - if (items.isEmpty()) - return; - - QList newBoxes; - foreach (QGraphicsObject *itemToHighlight, items) { - BoundingBox *box = boxFor(itemToHighlight); - if (!box) - box = createBoundingBox(itemToHighlight); - - newBoxes << box; - } - qSort(newBoxes); - - if (newBoxes != m_boxes) { - clear(); - m_boxes << newBoxes; - } - - highlightAll(); -} - -void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight) -{ - if (!itemToHighlight) - return; - - BoundingBox *box = boxFor(itemToHighlight); - if (!box) { - box = createBoundingBox(itemToHighlight); - m_boxes << box; - qSort(m_boxes); - } - - highlightAll(); -} - -BoundingBox *BoundingRectHighlighter::createBoundingBox(QGraphicsObject *itemToHighlight) -{ - if (!m_freeBoxes.isEmpty()) { - BoundingBox *box = m_freeBoxes.last(); - if (box->highlightedObject.isNull()) { - box->highlightedObject = itemToHighlight; - box->highlightPolygon->show(); - box->highlightPolygonEdge->show(); - m_freeBoxes.removeLast(); - return box; - } - } - - BoundingBox *box = new BoundingBox(itemToHighlight, this, this); - - connect(itemToHighlight, SIGNAL(xChanged()), this, SLOT(refresh())); - connect(itemToHighlight, SIGNAL(yChanged()), this, SLOT(refresh())); - connect(itemToHighlight, SIGNAL(widthChanged()), this, SLOT(refresh())); - connect(itemToHighlight, SIGNAL(heightChanged()), this, SLOT(refresh())); - connect(itemToHighlight, SIGNAL(rotationChanged()), this, SLOT(refresh())); - connect(itemToHighlight, SIGNAL(destroyed(QObject*)), this, SLOT(itemDestroyed(QObject*))); - - return box; -} - -void BoundingRectHighlighter::removeBoundingBox(BoundingBox *box) -{ - delete box; - box = 0; -} - -void BoundingRectHighlighter::freeBoundingBox(BoundingBox *box) -{ - if (!box->highlightedObject.isNull()) { - disconnect(box->highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh())); - disconnect(box->highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh())); - disconnect(box->highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh())); - disconnect(box->highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh())); - disconnect(box->highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh())); - } - - box->highlightedObject.clear(); - box->highlightPolygon->hide(); - box->highlightPolygonEdge->hide(); - m_boxes.removeOne(box); - m_freeBoxes << box; -} - -void BoundingRectHighlighter::itemDestroyed(QObject *obj) -{ - foreach (BoundingBox *box, m_boxes) { - if (box->highlightedObject.data() == obj) { - freeBoundingBox(box); - break; - } - } -} - -void BoundingRectHighlighter::highlightAll() -{ - foreach (BoundingBox *box, m_boxes) { - if (box && box->highlightedObject.isNull()) { - // clear all highlights - clear(); - return; - } - QGraphicsObject *item = box->highlightedObject.data(); - - QRectF boundingRectInSceneSpace(item->mapToScene(item->boundingRect()).boundingRect()); - QRectF boundingRectInLayerItemSpace = mapRectFromScene(boundingRectInSceneSpace); - QRectF bboxRect = m_view->adjustToScreenBoundaries(boundingRectInLayerItemSpace); - QRectF edgeRect = bboxRect; - edgeRect.adjust(-1, -1, 1, 1); - - box->highlightPolygon->setPolygon(QPolygonF(bboxRect)); - box->highlightPolygonEdge->setPolygon(QPolygonF(edgeRect)); - } -} - -void BoundingRectHighlighter::refresh() -{ - if (!m_boxes.isEmpty()) - highlightAll(); -} - - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.h deleted file mode 100644 index 81883ee0aa..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/boundingrecthighlighter.h +++ /dev/null @@ -1,115 +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 BOUNDINGRECTHIGHLIGHTER_H -#define BOUNDINGRECTHIGHLIGHTER_H - -#include "livelayeritem.h" - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QGraphicsItem) -QT_FORWARD_DECLARE_CLASS(QPainter) -QT_FORWARD_DECLARE_CLASS(QWidget) -QT_FORWARD_DECLARE_CLASS(QStyleOptionGraphicsItem) -QT_FORWARD_DECLARE_CLASS(QTimer) - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; -class BoundingBox; - -class BoundingRectHighlighter : public LiveLayerItem -{ - Q_OBJECT -public: - explicit BoundingRectHighlighter(QDeclarativeViewInspector *view); - ~BoundingRectHighlighter(); - void clear(); - void highlight(QList items); - void highlight(QGraphicsObject* item); - -private slots: - void refresh(); - void itemDestroyed(QObject *); - -private: - BoundingBox *boxFor(QGraphicsObject *item) const; - void highlightAll(); - BoundingBox *createBoundingBox(QGraphicsObject *itemToHighlight); - void removeBoundingBox(BoundingBox *box); - void freeBoundingBox(BoundingBox *box); - -private: - Q_DISABLE_COPY(BoundingRectHighlighter) - - QDeclarativeViewInspector *m_view; - QList m_boxes; - QList m_freeBoxes; -}; - -class BoundingBox : public QObject -{ - Q_OBJECT -public: - explicit BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, - QObject *parent = 0); - ~BoundingBox(); - QWeakPointer highlightedObject; - QGraphicsPolygonItem *highlightPolygon; - QGraphicsPolygonItem *highlightPolygonEdge; - -private: - Q_DISABLE_COPY(BoundingBox) - -}; - -class BoundingBoxPolygonItem : public QGraphicsPolygonItem -{ -public: - explicit BoundingBoxPolygonItem(QGraphicsItem *item); - int type() const; -}; - -} // namespace QmlJSDebugger - -#endif // BOUNDINGRECTHIGHLIGHTER_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.cpp deleted file mode 100644 index 581c1f5b1a..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.cpp +++ /dev/null @@ -1,98 +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$ -** -****************************************************************************/ - -#include "colorpickertool.h" - -#include "qdeclarativeviewinspector.h" - -#include -#include -#include -#include -#include -#include -#include - -namespace QmlJSDebugger { - -ColorPickerTool::ColorPickerTool(QDeclarativeViewInspector *view) : - AbstractLiveEditTool(view) -{ - m_selectedColor.setRgb(0,0,0); -} - -ColorPickerTool::~ColorPickerTool() -{ -} - -void ColorPickerTool::mousePressEvent(QMouseEvent *event) -{ - pickColor(event->pos()); -} - -void ColorPickerTool::mouseMoveEvent(QMouseEvent *event) -{ - pickColor(event->pos()); -} - -void ColorPickerTool::clear() -{ - view()->setCursor(Qt::CrossCursor); -} - -void ColorPickerTool::pickColor(const QPoint &pos) -{ - QRgb fillColor = view()->backgroundBrush().color().rgb(); - if (view()->backgroundBrush().style() == Qt::NoBrush) - fillColor = view()->palette().color(QPalette::Base).rgb(); - - QRectF target(0,0, 1, 1); - QRect source(pos.x(), pos.y(), 1, 1); - QImage img(1, 1, QImage::Format_ARGB32); - img.fill(fillColor); - QPainter painter(&img); - view()->render(&painter, target, source); - m_selectedColor = QColor::fromRgb(img.pixel(0, 0)); - - emit selectedColorChanged(m_selectedColor); -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.h deleted file mode 100644 index a28ffea63a..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/colorpickertool.h +++ /dev/null @@ -1,92 +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 COLORPICKERTOOL_H -#define COLORPICKERTOOL_H - -#include "abstractliveedittool.h" - -#include - -QT_FORWARD_DECLARE_CLASS(QPoint) - -namespace QmlJSDebugger { - -class ColorPickerTool : public AbstractLiveEditTool -{ - Q_OBJECT -public: - explicit ColorPickerTool(QDeclarativeViewInspector *view); - - virtual ~ColorPickerTool(); - - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *) {} - void mouseDoubleClickEvent(QMouseEvent *) {} - - void hoverMoveEvent(QMouseEvent *) {} - - void keyPressEvent(QKeyEvent *) {} - void keyReleaseEvent(QKeyEvent *) {} - - void wheelEvent(QWheelEvent *) {} - - void itemsAboutToRemoved(const QList &) {} - - void clear(); - -signals: - void selectedColorChanged(const QColor &color); - -protected: - void selectedItemsChanged(const QList &) {} - -private: - void pickColor(const QPoint &pos); - -private: - QColor m_selectedColor; -}; - -} // namespace QmlJSDebugger - -#endif // COLORPICKERTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.cpp deleted file mode 100644 index fb7118fbc2..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.cpp +++ /dev/null @@ -1,92 +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$ -** -****************************************************************************/ - -#include "livelayeritem.h" - -#include "../qmlinspectorconstants.h" - -#include - -namespace QmlJSDebugger { - -LiveLayerItem::LiveLayerItem(QGraphicsScene* scene) - : QGraphicsObject() -{ - scene->addItem(this); - setZValue(1); - setFlag(QGraphicsItem::ItemIsMovable, false); -} - -LiveLayerItem::~LiveLayerItem() -{ -} - -void LiveLayerItem::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem * /*option*/, - QWidget * /*widget*/) -{ -} - -int LiveLayerItem::type() const -{ - return Constants::EditorItemType; -} - -QRectF LiveLayerItem::boundingRect() const -{ - return childrenBoundingRect(); -} - -QList LiveLayerItem::findAllChildItems() const -{ - return findAllChildItems(this); -} - -QList LiveLayerItem::findAllChildItems(const QGraphicsItem *item) const -{ - QList itemList(item->childItems()); - - foreach (QGraphicsItem *childItem, item->childItems()) - itemList += findAllChildItems(childItem); - - return itemList; -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.h deleted file mode 100644 index 15f9a27fa4..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livelayeritem.h +++ /dev/null @@ -1,67 +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 LIVELAYERITEM_H -#define LIVELAYERITEM_H - -#include - -namespace QmlJSDebugger { - -class LiveLayerItem : public QGraphicsObject -{ -public: - LiveLayerItem(QGraphicsScene *scene); - ~LiveLayerItem(); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = 0); - QRectF boundingRect() const; - int type() const; - - QList findAllChildItems() const; - -protected: - QList findAllChildItems(const QGraphicsItem *item) const; -}; - -} - -#endif // LIVELAYERITEM_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.cpp deleted file mode 100644 index 4987237f89..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.cpp +++ /dev/null @@ -1,165 +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$ -** -****************************************************************************/ - -#include "liverubberbandselectionmanipulator.h" - -#include "qdeclarativeviewinspector_p.h" - -#include - -#include - -namespace QmlJSDebugger { - -LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, - QDeclarativeViewInspector *editorView) - : m_selectionRectangleElement(layerItem), - m_editorView(editorView), - m_beginFormEditorItem(0), - m_isActive(false) -{ - m_selectionRectangleElement.hide(); -} - -void LiveRubberBandSelectionManipulator::clear() -{ - m_selectionRectangleElement.clear(); - m_isActive = false; - m_beginPoint = QPointF(); - m_itemList.clear(); - m_oldSelectionList.clear(); -} - -QGraphicsItem *LiveRubberBandSelectionManipulator::topFormEditorItem(const QList - &itemList) -{ - if (itemList.isEmpty()) - return 0; - - return itemList.first(); -} - -void LiveRubberBandSelectionManipulator::begin(const QPointF &beginPoint) -{ - m_beginPoint = beginPoint; - m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint); - m_selectionRectangleElement.show(); - m_isActive = true; - QDeclarativeViewInspectorPrivate *inspectorPrivate - = QDeclarativeViewInspectorPrivate::get(m_editorView); - m_beginFormEditorItem = topFormEditorItem(inspectorPrivate->selectableItems(beginPoint)); - m_oldSelectionList = m_editorView->selectedItems(); -} - -void LiveRubberBandSelectionManipulator::update(const QPointF &updatePoint) -{ - m_selectionRectangleElement.setRect(m_beginPoint, updatePoint); -} - -void LiveRubberBandSelectionManipulator::end() -{ - m_oldSelectionList.clear(); - m_selectionRectangleElement.hide(); - m_isActive = false; -} - -void LiveRubberBandSelectionManipulator::select(SelectionType selectionType) -{ - QDeclarativeViewInspectorPrivate *inspectorPrivate - = QDeclarativeViewInspectorPrivate::get(m_editorView); - QList itemList - = inspectorPrivate->selectableItems(m_selectionRectangleElement.rect(), - Qt::IntersectsItemShape); - QList newSelectionList; - - foreach (QGraphicsItem* item, itemList) { - if (item - && item->parentItem() - && !newSelectionList.contains(item) - //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test - ) - { - newSelectionList.append(item); - } - } - - if (newSelectionList.isEmpty() && m_beginFormEditorItem) - newSelectionList.append(m_beginFormEditorItem); - - QList resultList; - - switch (selectionType) { - case AddToSelection: { - resultList.append(m_oldSelectionList); - resultList.append(newSelectionList); - } - break; - case ReplaceSelection: { - resultList.append(newSelectionList); - } - break; - case RemoveFromSelection: { - QSet oldSelectionSet(m_oldSelectionList.toSet()); - QSet newSelectionSet(newSelectionList.toSet()); - resultList.append(oldSelectionSet.subtract(newSelectionSet).toList()); - } - } - - m_editorView->setSelectedItems(resultList); -} - - -void LiveRubberBandSelectionManipulator::setItems(const QList &itemList) -{ - m_itemList = itemList; -} - -QPointF LiveRubberBandSelectionManipulator::beginPoint() const -{ - return m_beginPoint; -} - -bool LiveRubberBandSelectionManipulator::isActive() const -{ - return m_isActive; -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.h deleted file mode 100644 index aa15a34730..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liverubberbandselectionmanipulator.h +++ /dev/null @@ -1,96 +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 RUBBERBANDSELECTIONMANIPULATOR_H -#define RUBBERBANDSELECTIONMANIPULATOR_H - -#include "liveselectionrectangle.h" - -#include - -QT_FORWARD_DECLARE_CLASS(QGraphicsItem) - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; - -class LiveRubberBandSelectionManipulator -{ -public: - enum SelectionType { - ReplaceSelection, - AddToSelection, - RemoveFromSelection - }; - - LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, - QDeclarativeViewInspector *editorView); - - void setItems(const QList &itemList); - - void begin(const QPointF& beginPoint); - void update(const QPointF& updatePoint); - void end(); - - void clear(); - - void select(SelectionType selectionType); - - QPointF beginPoint() const; - - bool isActive() const; - -protected: - QGraphicsItem *topFormEditorItem(const QList &itemList); - -private: - QList m_itemList; - QList m_oldSelectionList; - LiveSelectionRectangle m_selectionRectangleElement; - QPointF m_beginPoint; - QDeclarativeViewInspector *m_editorView; - QGraphicsItem *m_beginFormEditorItem; - bool m_isActive; -}; - -} - -#endif // RUBBERBANDSELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.cpp deleted file mode 100644 index 744cbf527e..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.cpp +++ /dev/null @@ -1,118 +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$ -** -****************************************************************************/ - -#include "liveselectionindicator.h" - -#include "qdeclarativeviewinspector_p.h" -#include "../qmlinspectorconstants.h" - -#include -#include -#include -#include - -namespace QmlJSDebugger { - -LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, - QGraphicsObject *layerItem) - : m_layerItem(layerItem) - , m_view(viewInspector) -{ -} - -LiveSelectionIndicator::~LiveSelectionIndicator() -{ - clear(); -} - -void LiveSelectionIndicator::show() -{ - foreach (QGraphicsRectItem *item, m_indicatorShapeHash) - item->show(); -} - -void LiveSelectionIndicator::hide() -{ - foreach (QGraphicsRectItem *item, m_indicatorShapeHash) - item->hide(); -} - -void LiveSelectionIndicator::clear() -{ - if (!m_layerItem.isNull()) { - QGraphicsScene *scene = m_layerItem.data()->scene(); - foreach (QGraphicsRectItem *item, m_indicatorShapeHash) { - scene->removeItem(item); - delete item; - } - } - - m_indicatorShapeHash.clear(); - -} - -void LiveSelectionIndicator::setItems(const QList > &itemList) -{ - clear(); - - foreach (const QWeakPointer &object, itemList) { - if (object.isNull()) - continue; - - QGraphicsItem *item = object.data(); - - if (!m_indicatorShapeHash.contains(item)) { - QGraphicsRectItem *selectionIndicator = new QGraphicsRectItem(m_layerItem.data()); - m_indicatorShapeHash.insert(item, selectionIndicator); - - const QRectF boundingRect = m_view->adjustToScreenBoundaries(item->mapRectToScene(item->boundingRect())); - const QRectF boundingRectInLayerItemSpace = m_layerItem.data()->mapRectFromScene(boundingRect); - - selectionIndicator->setData(Constants::EditorItemDataKey, true); - selectionIndicator->setFlag(QGraphicsItem::ItemIsSelectable, false); - selectionIndicator->setRect(boundingRectInLayerItemSpace); - selectionIndicator->setPen(QColor(108, 141, 221)); - } - } -} - -} //namespace QmlJSDebugger - diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.h deleted file mode 100644 index 7b8cc12e62..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionindicator.h +++ /dev/null @@ -1,80 +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 LIVESELECTIONINDICATOR_H -#define LIVESELECTIONINDICATOR_H - -#include -#include - -QT_BEGIN_NAMESPACE -class QGraphicsObject; -class QGraphicsRectItem; -class QGraphicsItem; -class QPolygonF; -QT_END_NAMESPACE - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; - -class LiveSelectionIndicator -{ -public: - LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, QGraphicsObject *layerItem); - ~LiveSelectionIndicator(); - - void show(); - void hide(); - - void clear(); - - void setItems(const QList > &itemList); - -private: - QHash m_indicatorShapeHash; - QWeakPointer m_layerItem; - QDeclarativeViewInspector *m_view; -}; - -} - -#endif // LIVESELECTIONINDICATOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.cpp deleted file mode 100644 index 23577561a4..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.cpp +++ /dev/null @@ -1,113 +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$ -** -****************************************************************************/ - -#include "liveselectionrectangle.h" - -#include "../qmlinspectorconstants.h" - -#include -#include -#include -#include - -#include - -#include - -namespace QmlJSDebugger { - -class SelectionRectShape : public QGraphicsRectItem -{ -public: - SelectionRectShape(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} - int type() const { return Constants::EditorItemType; } -}; - -LiveSelectionRectangle::LiveSelectionRectangle(QGraphicsObject *layerItem) - : m_controlShape(new SelectionRectShape(layerItem)), - m_layerItem(layerItem) -{ - m_controlShape->setPen(QPen(Qt::black)); - m_controlShape->setBrush(QColor(128, 128, 128, 50)); -} - -LiveSelectionRectangle::~LiveSelectionRectangle() -{ - if (m_layerItem) - m_layerItem.data()->scene()->removeItem(m_controlShape); -} - -void LiveSelectionRectangle::clear() -{ - hide(); -} -void LiveSelectionRectangle::show() -{ - m_controlShape->show(); -} - -void LiveSelectionRectangle::hide() -{ - m_controlShape->hide(); -} - -QRectF LiveSelectionRectangle::rect() const -{ - return m_controlShape->mapFromScene(m_controlShape->rect()).boundingRect(); -} - -void LiveSelectionRectangle::setRect(const QPointF &firstPoint, - const QPointF &secondPoint) -{ - double firstX = std::floor(firstPoint.x()) + 0.5; - double firstY = std::floor(firstPoint.y()) + 0.5; - double secondX = std::floor(secondPoint.x()) + 0.5; - double secondY = std::floor(secondPoint.y()) + 0.5; - QPointF topLeftPoint(firstX < secondX ? firstX : secondX, - firstY < secondY ? firstY : secondY); - QPointF bottomRightPoint(firstX > secondX ? firstX : secondX, - firstY > secondY ? firstY : secondY); - - QRectF rect(topLeftPoint, bottomRightPoint); - m_controlShape->setRect(rect); -} - -} diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.h deleted file mode 100644 index 730cca52d5..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectionrectangle.h +++ /dev/null @@ -1,77 +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 LIVESELECTIONRECTANGLE_H -#define LIVESELECTIONRECTANGLE_H - -#include - -QT_FORWARD_DECLARE_CLASS(QGraphicsObject) -QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem) -QT_FORWARD_DECLARE_CLASS(QPointF) -QT_FORWARD_DECLARE_CLASS(QRectF) - -namespace QmlJSDebugger { - -class LiveSelectionRectangle -{ -public: - LiveSelectionRectangle(QGraphicsObject *layerItem); - ~LiveSelectionRectangle(); - - void show(); - void hide(); - - void clear(); - - void setRect(const QPointF &firstPoint, - const QPointF &secondPoint); - - QRectF rect() const; - -private: - QGraphicsRectItem *m_controlShape; - QWeakPointer m_layerItem; -}; - -} // namespace QmlJSDebugger - -#endif // LIVESELECTIONRECTANGLE_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.cpp deleted file mode 100644 index dc51a1f595..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.cpp +++ /dev/null @@ -1,423 +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$ -** -****************************************************************************/ - -#include "liveselectiontool.h" -#include "livelayeritem.h" - -#include "qdeclarativeviewinspector_p.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -namespace QmlJSDebugger { - -LiveSelectionTool::LiveSelectionTool(QDeclarativeViewInspector *editorView) : - AbstractLiveEditTool(editorView), - m_rubberbandSelectionMode(false), - m_rubberbandSelectionManipulator( - QDeclarativeViewInspectorPrivate::get(editorView)->manipulatorLayer, editorView), - m_singleSelectionManipulator(editorView), - m_selectionIndicator(editorView, - QDeclarativeViewInspectorPrivate::get(editorView)->manipulatorLayer), - //m_resizeIndicator(editorView->manipulatorLayer()), - m_selectOnlyContentItems(true) -{ - -} - -LiveSelectionTool::~LiveSelectionTool() -{ -} - -void LiveSelectionTool::setRubberbandSelectionMode(bool value) -{ - m_rubberbandSelectionMode = value; -} - -LiveSingleSelectionManipulator::SelectionType LiveSelectionTool::getSelectionType(Qt::KeyboardModifiers - modifiers) -{ - LiveSingleSelectionManipulator::SelectionType selectionType - = LiveSingleSelectionManipulator::ReplaceSelection; - if (modifiers.testFlag(Qt::ControlModifier)) { - selectionType = LiveSingleSelectionManipulator::RemoveFromSelection; - } else if (modifiers.testFlag(Qt::ShiftModifier)) { - selectionType = LiveSingleSelectionManipulator::AddToSelection; - } - return selectionType; -} - -bool LiveSelectionTool::alreadySelected(const QList &itemList) const -{ - QDeclarativeViewInspectorPrivate *inspectorPrivate - = QDeclarativeViewInspectorPrivate::get(inspector()); - const QList selectedItems = inspectorPrivate->selectedItems(); - - if (selectedItems.isEmpty()) - return false; - - foreach (QGraphicsItem *item, itemList) - if (selectedItems.contains(item)) - return true; - - return false; -} - -void LiveSelectionTool::mousePressEvent(QMouseEvent *event) -{ - QDeclarativeViewInspectorPrivate *inspectorPrivate - = QDeclarativeViewInspectorPrivate::get(inspector()); - QList itemList = inspectorPrivate->selectableItems(event->pos()); - LiveSingleSelectionManipulator::SelectionType selectionType = getSelectionType(event->modifiers()); - - if (event->buttons() & Qt::LeftButton) { - m_mousePressTimer.start(); - - if (m_rubberbandSelectionMode) { - m_rubberbandSelectionManipulator.begin(event->pos()); - } else { - m_singleSelectionManipulator.begin(event->pos()); - m_singleSelectionManipulator.select(selectionType, m_selectOnlyContentItems); - } - } else if (event->buttons() & Qt::RightButton) { - createContextMenu(itemList, event->globalPos()); - } -} - -void LiveSelectionTool::createContextMenu(const QList &itemList, QPoint globalPos) -{ - QMenu contextMenu; - connect(&contextMenu, SIGNAL(hovered(QAction*)), - this, SLOT(contextMenuElementHovered(QAction*))); - - m_contextMenuItemList = itemList; - - contextMenu.addAction(tr("Items")); - contextMenu.addSeparator(); - int shortcutKey = Qt::Key_1; - int i = 0; - - foreach (QGraphicsItem * const item, itemList) { - QString itemTitle = titleForItem(item); - QAction *elementAction = contextMenu.addAction(itemTitle, this, - SLOT(contextMenuElementSelected())); - - if (inspector()->selectedItems().contains(item)) { - QFont boldFont = elementAction->font(); - boldFont.setBold(true); - elementAction->setFont(boldFont); - } - - elementAction->setData(i); - - if (shortcutKey <= Qt::Key_9) { - elementAction->setShortcut(QKeySequence(shortcutKey)); - shortcutKey++; - } - - ++i; - } - // add root item separately - // QString itemTitle = QString(tr("%1")).arg(titleForItem(view()->currentRootItem())); - // contextMenu.addAction(itemTitle, this, SLOT(contextMenuElementSelected())); - // m_contextMenuItemList.append(view()->currentRootItem()); - - contextMenu.exec(globalPos); - m_contextMenuItemList.clear(); -} - -void LiveSelectionTool::contextMenuElementSelected() -{ - QAction *senderAction = static_cast(sender()); - int itemListIndex = senderAction->data().toInt(); - if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { - - QPointF updatePt(0, 0); - QGraphicsItem *item = m_contextMenuItemList.at(itemListIndex); - m_singleSelectionManipulator.begin(updatePt); - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, - QList() << item, - false); - m_singleSelectionManipulator.end(updatePt); - } -} - -void LiveSelectionTool::contextMenuElementHovered(QAction *action) -{ - int itemListIndex = action->data().toInt(); - if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { - QGraphicsObject *item = m_contextMenuItemList.at(itemListIndex)->toGraphicsObject(); - QDeclarativeViewInspectorPrivate::get(inspector())->highlight(item); - } -} - -void LiveSelectionTool::mouseMoveEvent(QMouseEvent *event) -{ - if (m_singleSelectionManipulator.isActive()) { - QPointF mouseMovementVector = m_singleSelectionManipulator.beginPoint() - event->pos(); - - if ((mouseMovementVector.toPoint().manhattanLength() > Constants::DragStartDistance) - && (m_mousePressTimer.elapsed() > Constants::DragStartTime)) - { - m_singleSelectionManipulator.end(event->pos()); - //view()->changeToMoveTool(m_singleSelectionManipulator.beginPoint()); - return; - } - } else if (m_rubberbandSelectionManipulator.isActive()) { - QPointF mouseMovementVector = m_rubberbandSelectionManipulator.beginPoint() - event->pos(); - - if ((mouseMovementVector.toPoint().manhattanLength() > Constants::DragStartDistance) - && (m_mousePressTimer.elapsed() > Constants::DragStartTime)) { - m_rubberbandSelectionManipulator.update(event->pos()); - - if (event->modifiers().testFlag(Qt::ControlModifier)) - m_rubberbandSelectionManipulator.select( - LiveRubberBandSelectionManipulator::RemoveFromSelection); - else if (event->modifiers().testFlag(Qt::ShiftModifier)) - m_rubberbandSelectionManipulator.select( - LiveRubberBandSelectionManipulator::AddToSelection); - else - m_rubberbandSelectionManipulator.select( - LiveRubberBandSelectionManipulator::ReplaceSelection); - } - } -} - -void LiveSelectionTool::hoverMoveEvent(QMouseEvent * event) -{ -// ### commented out until move tool is re-enabled -// QList itemList = view()->items(event->pos()); -// if (!itemList.isEmpty() && !m_rubberbandSelectionMode) { -// -// foreach (QGraphicsItem *item, itemList) { -// if (item->type() == Constants::ResizeHandleItemType) { -// ResizeHandleItem* resizeHandle = ResizeHandleItem::fromGraphicsItem(item); -// if (resizeHandle) -// view()->changeTool(Constants::ResizeToolMode); -// return; -// } -// } -// if (topSelectedItemIsMovable(itemList)) -// view()->changeTool(Constants::MoveToolMode); -// } - QDeclarativeViewInspectorPrivate *inspectorPrivate - = QDeclarativeViewInspectorPrivate::get(inspector()); - - QList selectableItemList = inspectorPrivate->selectableItems(event->pos()); - if (!selectableItemList.isEmpty()) { - QGraphicsObject *item = selectableItemList.first()->toGraphicsObject(); - if (item) - QDeclarativeViewInspectorPrivate::get(inspector())->highlight(item); - - return; - } - - QDeclarativeViewInspectorPrivate::get(inspector())->clearHighlight(); -} - -void LiveSelectionTool::mouseReleaseEvent(QMouseEvent *event) -{ - if (m_singleSelectionManipulator.isActive()) { - m_singleSelectionManipulator.end(event->pos()); - } - else if (m_rubberbandSelectionManipulator.isActive()) { - - QPointF mouseMovementVector = m_rubberbandSelectionManipulator.beginPoint() - event->pos(); - if (mouseMovementVector.toPoint().manhattanLength() < Constants::DragStartDistance) { - m_singleSelectionManipulator.begin(event->pos()); - - if (event->modifiers().testFlag(Qt::ControlModifier)) - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::RemoveFromSelection, - m_selectOnlyContentItems); - else if (event->modifiers().testFlag(Qt::ShiftModifier)) - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::AddToSelection, - m_selectOnlyContentItems); - else - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, - m_selectOnlyContentItems); - - m_singleSelectionManipulator.end(event->pos()); - } else { - m_rubberbandSelectionManipulator.update(event->pos()); - - if (event->modifiers().testFlag(Qt::ControlModifier)) - m_rubberbandSelectionManipulator.select( - LiveRubberBandSelectionManipulator::RemoveFromSelection); - else if (event->modifiers().testFlag(Qt::ShiftModifier)) - m_rubberbandSelectionManipulator.select( - LiveRubberBandSelectionManipulator::AddToSelection); - else - m_rubberbandSelectionManipulator.select( - LiveRubberBandSelectionManipulator::ReplaceSelection); - - m_rubberbandSelectionManipulator.end(); - } - } -} - -void LiveSelectionTool::keyPressEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_Left: - case Qt::Key_Right: - case Qt::Key_Up: - case Qt::Key_Down: - // disabled for now, cannot move stuff yet. - //view()->changeTool(Constants::MoveToolMode); - //view()->currentTool()->keyPressEvent(event); - break; - } -} - -void LiveSelectionTool::wheelEvent(QWheelEvent *event) -{ - if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) - return; - - QDeclarativeViewInspectorPrivate *inspectorPrivate - = QDeclarativeViewInspectorPrivate::get(inspector()); - QList itemList = inspectorPrivate->selectableItems(event->pos()); - - if (itemList.isEmpty()) - return; - - int selectedIdx = 0; - if (!inspector()->selectedItems().isEmpty()) { - selectedIdx = itemList.indexOf(inspector()->selectedItems().first()); - if (selectedIdx >= 0) { - if (event->delta() > 0) { - selectedIdx++; - if (selectedIdx == itemList.length()) - selectedIdx = 0; - } else if (event->delta() < 0) { - selectedIdx--; - if (selectedIdx == -1) - selectedIdx = itemList.length() - 1; - } - } else { - selectedIdx = 0; - } - } - - QPointF updatePt(0, 0); - m_singleSelectionManipulator.begin(updatePt); - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::ReplaceSelection, - QList() << itemList.at(selectedIdx), - false); - m_singleSelectionManipulator.end(updatePt); - -} - -void LiveSelectionTool::setSelectOnlyContentItems(bool selectOnlyContentItems) -{ - m_selectOnlyContentItems = selectOnlyContentItems; -} - -void LiveSelectionTool::clear() -{ - view()->setCursor(Qt::ArrowCursor); - m_rubberbandSelectionManipulator.clear(), - m_singleSelectionManipulator.clear(); - m_selectionIndicator.clear(); - //m_resizeIndicator.clear(); -} - -void LiveSelectionTool::selectedItemsChanged(const QList &itemList) -{ - foreach (const QWeakPointer &obj, m_selectedItemList) { - if (!obj.isNull()) { - disconnect(obj.data(), SIGNAL(xChanged()), this, SLOT(repaintBoundingRects())); - disconnect(obj.data(), SIGNAL(yChanged()), this, SLOT(repaintBoundingRects())); - disconnect(obj.data(), SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects())); - disconnect(obj.data(), SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects())); - disconnect(obj.data(), SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects())); - } - } - - QList objects = toGraphicsObjectList(itemList); - m_selectedItemList.clear(); - - foreach (QGraphicsObject *obj, objects) { - m_selectedItemList.append(obj); - connect(obj, SIGNAL(xChanged()), this, SLOT(repaintBoundingRects())); - connect(obj, SIGNAL(yChanged()), this, SLOT(repaintBoundingRects())); - connect(obj, SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects())); - connect(obj, SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects())); - connect(obj, SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects())); - } - - m_selectionIndicator.setItems(m_selectedItemList); - //m_resizeIndicator.setItems(toGraphicsObjectList(itemList)); -} - -void LiveSelectionTool::repaintBoundingRects() -{ - m_selectionIndicator.setItems(m_selectedItemList); -} - -void LiveSelectionTool::selectUnderPoint(QMouseEvent *event) -{ - m_singleSelectionManipulator.begin(event->pos()); - - if (event->modifiers().testFlag(Qt::ControlModifier)) - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::RemoveFromSelection, - m_selectOnlyContentItems); - else if (event->modifiers().testFlag(Qt::ShiftModifier)) - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::AddToSelection, - m_selectOnlyContentItems); - else - m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, - m_selectOnlyContentItems); - - m_singleSelectionManipulator.end(event->pos()); -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.h deleted file mode 100644 index 2c281cda3c..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/liveselectiontool.h +++ /dev/null @@ -1,120 +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 LIVESELECTIONTOOL_H -#define LIVESELECTIONTOOL_H - -#include "abstractliveedittool.h" -#include "liverubberbandselectionmanipulator.h" -#include "livesingleselectionmanipulator.h" -#include "liveselectionindicator.h" - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QGraphicsItem) -QT_FORWARD_DECLARE_CLASS(QMouseEvent) -QT_FORWARD_DECLARE_CLASS(QKeyEvent) -QT_FORWARD_DECLARE_CLASS(QAction) - -namespace QmlJSDebugger { - -class LiveSelectionTool : public AbstractLiveEditTool -{ - Q_OBJECT - -public: - LiveSelectionTool(QDeclarativeViewInspector* editorView); - ~LiveSelectionTool(); - - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *) {} - void hoverMoveEvent(QMouseEvent *event); - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *) {} - void wheelEvent(QWheelEvent *event); - - void itemsAboutToRemoved(const QList &) {} -// QVariant itemChange(const QList &itemList, -// QGraphicsItem::GraphicsItemChange change, -// const QVariant &value ); - -// void update(); - - void clear(); - - void selectedItemsChanged(const QList &itemList); - - void selectUnderPoint(QMouseEvent *event); - - void setSelectOnlyContentItems(bool selectOnlyContentItems); - - void setRubberbandSelectionMode(bool value); - -private slots: - void contextMenuElementSelected(); - void contextMenuElementHovered(QAction *action); - void repaintBoundingRects(); - -private: - void createContextMenu(const QList &itemList, QPoint globalPos); - LiveSingleSelectionManipulator::SelectionType getSelectionType(Qt::KeyboardModifiers modifiers); - bool alreadySelected(const QList &itemList) const; - -private: - bool m_rubberbandSelectionMode; - LiveRubberBandSelectionManipulator m_rubberbandSelectionManipulator; - LiveSingleSelectionManipulator m_singleSelectionManipulator; - LiveSelectionIndicator m_selectionIndicator; - //ResizeIndicator m_resizeIndicator; - QTime m_mousePressTimer; - bool m_selectOnlyContentItems; - - QList > m_selectedItemList; - - QList m_contextMenuItemList; -}; - -} // namespace QmlJSDebugger - -#endif // LIVESELECTIONTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.cpp deleted file mode 100644 index 9c78018ef9..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.cpp +++ /dev/null @@ -1,151 +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$ -** -****************************************************************************/ - -#include "livesingleselectionmanipulator.h" - -#include "qdeclarativeviewinspector_p.h" - -#include - -namespace QmlJSDebugger { - -LiveSingleSelectionManipulator::LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView) - : m_editorView(editorView), - m_isActive(false) -{ -} - - -void LiveSingleSelectionManipulator::begin(const QPointF &beginPoint) -{ - m_beginPoint = beginPoint; - m_isActive = true; - m_oldSelectionList = QDeclarativeViewInspectorPrivate::get(m_editorView)->selectedItems(); -} - -void LiveSingleSelectionManipulator::update(const QPointF &/*updatePoint*/) -{ - m_oldSelectionList.clear(); -} - -void LiveSingleSelectionManipulator::clear() -{ - m_beginPoint = QPointF(); - m_oldSelectionList.clear(); -} - - -void LiveSingleSelectionManipulator::end(const QPointF &/*updatePoint*/) -{ - m_oldSelectionList.clear(); - m_isActive = false; -} - -void LiveSingleSelectionManipulator::select(SelectionType selectionType, - const QList &items, - bool /*selectOnlyContentItems*/) -{ - QGraphicsItem *selectedItem = 0; - - foreach (QGraphicsItem* item, items) - { - //FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); - if (item - /*&& !formEditorItem->qmlItemNode().isRootNode() - && (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems)*/) - { - selectedItem = item; - break; - } - } - - QList resultList; - - switch (selectionType) { - case AddToSelection: { - resultList.append(m_oldSelectionList); - if (selectedItem && !m_oldSelectionList.contains(selectedItem)) - resultList.append(selectedItem); - } - break; - case ReplaceSelection: { - if (selectedItem) - resultList.append(selectedItem); - } - break; - case RemoveFromSelection: { - resultList.append(m_oldSelectionList); - if (selectedItem) - resultList.removeAll(selectedItem); - } - break; - case InvertSelection: { - if (selectedItem - && !m_oldSelectionList.contains(selectedItem)) - { - resultList.append(selectedItem); - } - } - } - - m_editorView->setSelectedItems(resultList); -} - -void LiveSingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) -{ - QDeclarativeViewInspectorPrivate *inspectorPrivate = - QDeclarativeViewInspectorPrivate::get(m_editorView); - QList itemList = inspectorPrivate->selectableItems(m_beginPoint); - select(selectionType, itemList, selectOnlyContentItems); -} - - -bool LiveSingleSelectionManipulator::isActive() const -{ - return m_isActive; -} - -QPointF LiveSingleSelectionManipulator::beginPoint() const -{ - return m_beginPoint; -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.h deleted file mode 100644 index ac65711a91..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/livesingleselectionmanipulator.h +++ /dev/null @@ -1,89 +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 LIVESINGLESELECTIONMANIPULATOR_H -#define LIVESINGLESELECTIONMANIPULATOR_H - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QGraphicsItem) - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; - -class LiveSingleSelectionManipulator -{ -public: - LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView); - - enum SelectionType { - ReplaceSelection, - AddToSelection, - RemoveFromSelection, - InvertSelection - }; - - void begin(const QPointF& beginPoint); - void update(const QPointF& updatePoint); - void end(const QPointF& updatePoint); - - void select(SelectionType selectionType, const QList &items, - bool selectOnlyContentItems); - void select(SelectionType selectionType, bool selectOnlyContentItems); - - void clear(); - - QPointF beginPoint() const; - - bool isActive() const; - -private: - QList m_oldSelectionList; - QPointF m_beginPoint; - QDeclarativeViewInspector *m_editorView; - bool m_isActive; -}; - -} // namespace QmlJSDebugger - -#endif // LIVESINGLESELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.cpp deleted file mode 100644 index ca34f9e029..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.cpp +++ /dev/null @@ -1,445 +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$ -** -****************************************************************************/ - -#include "qdeclarativeviewinspector.h" -#include "qdeclarativeviewinspector_p.h" - -#include "liveselectiontool.h" -#include "zoomtool.h" -#include "colorpickertool.h" -#include "livelayeritem.h" -#include "boundingrecthighlighter.h" - -#include -#include - -namespace QmlJSDebugger { - -QDeclarativeViewInspectorPrivate::QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *q) : - q(q) -{ -} - -QDeclarativeViewInspectorPrivate::~QDeclarativeViewInspectorPrivate() -{ -} - -QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view, - QObject *parent) : - AbstractViewInspector(parent), - data(new QDeclarativeViewInspectorPrivate(this)) -{ - 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); - setCurrentTool(data->selectionTool); - - // to capture ChildRemoved event when viewport changes - data->view->installEventFilter(this); - - data->setViewport(data->view->viewport()); - - connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), - data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); - - connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), - SIGNAL(selectedColorChanged(QColor))); - connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), - this, SLOT(sendColorChanged(QColor))); - - changeTool(InspectorProtocol::SelectTool); -} - -QDeclarativeViewInspector::~QDeclarativeViewInspector() -{ -} - -void QDeclarativeViewInspector::changeCurrentObjects(const QList &objects) -{ - QList items; - QList gfxObjects; - foreach (QObject *obj, objects) { - if (QDeclarativeItem *declarativeItem = qobject_cast(obj)) { - items << declarativeItem; - gfxObjects << declarativeItem; - } - } - if (designModeBehavior()) { - data->setSelectedItemsForTools(items); - data->clearHighlight(); - data->highlight(gfxObjects); - } -} - -void QDeclarativeViewInspector::reloadView() -{ - 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; - } -} - -Qt::WindowFlags QDeclarativeViewInspector::windowFlags() const -{ - return declarativeView()->window()->windowFlags(); -} - -void QDeclarativeViewInspector::setWindowFlags(Qt::WindowFlags flags) -{ - declarativeView()->window()->setWindowFlags(flags); - declarativeView()->window()->show(); -} - -AbstractLiveEditTool *QDeclarativeViewInspector::currentTool() const -{ - return static_cast(AbstractViewInspector::currentTool()); -} - -QDeclarativeEngine *QDeclarativeViewInspector::declarativeEngine() const -{ - return data->view->engine(); -} - -void QDeclarativeViewInspectorPrivate::setViewport(QWidget *widget) -{ - if (viewport.data() == widget) - return; - - if (viewport) - viewport.data()->removeEventFilter(q); - - viewport = widget; - if (viewport) { - // make sure we get mouse move events - viewport.data()->setMouseTracking(true); - viewport.data()->installEventFilter(q); - } -} - -void QDeclarativeViewInspectorPrivate::clearEditorItems() -{ - clearHighlight(); - setSelectedItems(QList()); -} - -bool QDeclarativeViewInspector::eventFilter(QObject *obj, QEvent *event) -{ - if (obj == data->view) { - // Event from view - if (event->type() == QEvent::ChildRemoved) { - // Might mean that viewport has changed - if (data->view->viewport() != data->viewport.data()) - data->setViewport(data->view->viewport()); - } - return QObject::eventFilter(obj, event); - } - - return AbstractViewInspector::eventFilter(obj, event); -} - -bool QDeclarativeViewInspector::leaveEvent(QEvent *event) -{ - data->clearHighlight(); - return AbstractViewInspector::leaveEvent(event); -} - -bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event) -{ - QList selItems = data->selectableItems(event->pos()); - if (!selItems.isEmpty()) { - declarativeView()->setToolTip(currentTool()->titleForItem(selItems.first())); - } else { - declarativeView()->setToolTip(QString()); - } - - return AbstractViewInspector::mouseMoveEvent(event); -} - -void QDeclarativeViewInspector::reparentQmlObject(QObject *object, QObject *newParent) -{ - if (!newParent) - return; - - object->setParent(newParent); - QDeclarativeItem *newParentItem = qobject_cast(newParent); - QDeclarativeItem *item = qobject_cast(object); - if (newParentItem && item) - item->setParentItem(newParentItem); -} - -void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj) -{ - QList items = selectedItems(); - if (QGraphicsItem *item = qobject_cast(obj)) - items.removeOne(item); - setSelectedItems(items); -} - -void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(const QList &items) -{ - foreach (const QWeakPointer &obj, currentSelection) { - if (QGraphicsItem *item = obj.data()) { - if (!items.contains(item)) { - QObject::disconnect(obj.data(), SIGNAL(destroyed(QObject*)), - this, SLOT(_q_removeFromSelection(QObject*))); - currentSelection.removeOne(obj); - } - } - } - - foreach (QGraphicsItem *item, items) { - if (QGraphicsObject *obj = item->toGraphicsObject()) { - if (!currentSelection.contains(obj)) { - QObject::connect(obj, SIGNAL(destroyed(QObject*)), - this, SLOT(_q_removeFromSelection(QObject*))); - currentSelection.append(obj); - } - } - } - - q->currentTool()->updateSelectedItems(); -} - -void QDeclarativeViewInspectorPrivate::setSelectedItems(const QList &items) -{ - QList > oldList = currentSelection; - setSelectedItemsForTools(items); - if (oldList != currentSelection) { - QList objectList; - foreach (const QWeakPointer &graphicsObject, currentSelection) { - if (graphicsObject) - objectList << graphicsObject.data(); - } - - q->sendCurrentObjects(objectList); - } -} - -QList QDeclarativeViewInspectorPrivate::selectedItems() const -{ - QList selection; - foreach (const QWeakPointer &selectedObject, currentSelection) { - if (selectedObject.data()) - selection << selectedObject.data(); - } - - return selection; -} - -void QDeclarativeViewInspector::setSelectedItems(QList items) -{ - data->setSelectedItems(items); -} - -QList QDeclarativeViewInspector::selectedItems() const -{ - return data->selectedItems(); -} - -QDeclarativeView *QDeclarativeViewInspector::declarativeView() const -{ - return data->view; -} - -void QDeclarativeViewInspectorPrivate::clearHighlight() -{ - boundingRectHighlighter->clear(); -} - -void QDeclarativeViewInspectorPrivate::highlight(const QList &items) -{ - if (items.isEmpty()) - return; - - QList objectList; - foreach (QGraphicsItem *item, items) { - QGraphicsItem *child = item; - - if (child) { - QGraphicsObject *childObject = child->toGraphicsObject(); - if (childObject) - objectList << childObject; - } - } - - boundingRectHighlighter->highlight(objectList); -} - -QList QDeclarativeViewInspectorPrivate::selectableItems( - const QPointF &scenePos) const -{ - QList itemlist = view->scene()->items(scenePos); - return filterForSelection(itemlist); -} - -QList QDeclarativeViewInspectorPrivate::selectableItems(const QPoint &pos) const -{ - QList itemlist = view->items(pos); - return filterForSelection(itemlist); -} - -QList QDeclarativeViewInspectorPrivate::selectableItems( - const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const -{ - QList itemlist = view->scene()->items(sceneRect, selectionMode); - return filterForSelection(itemlist); -} - -void QDeclarativeViewInspectorPrivate::changeToSingleSelectTool() -{ - selectionTool->setRubberbandSelectionMode(false); - - changeToSelectTool(); - - emit q->selectToolActivated(); - q->sendCurrentTool(Constants::SelectionToolMode); -} - -void QDeclarativeViewInspectorPrivate::changeToSelectTool() -{ - if (q->currentTool() == selectionTool) - return; - - q->currentTool()->clear(); - q->setCurrentTool(selectionTool); - q->currentTool()->clear(); - q->currentTool()->updateSelectedItems(); -} - -void QDeclarativeViewInspectorPrivate::changeToMarqueeSelectTool() -{ - changeToSelectTool(); - selectionTool->setRubberbandSelectionMode(true); - - emit q->marqueeSelectToolActivated(); - q->sendCurrentTool(Constants::MarqueeSelectionToolMode); -} - -void QDeclarativeViewInspectorPrivate::changeToZoomTool() -{ - q->currentTool()->clear(); - q->setCurrentTool(zoomTool); - q->currentTool()->clear(); - - emit q->zoomToolActivated(); - q->sendCurrentTool(Constants::ZoomMode); -} - -void QDeclarativeViewInspectorPrivate::changeToColorPickerTool() -{ - if (q->currentTool() == colorPickerTool) - return; - - q->currentTool()->clear(); - q->setCurrentTool(colorPickerTool); - q->currentTool()->clear(); - - emit q->colorPickerActivated(); - q->sendCurrentTool(Constants::ColorPickerMode); -} - - -static bool isEditorItem(QGraphicsItem *item) -{ - return (item->type() == Constants::EditorItemType - || item->type() == Constants::ResizeHandleItemType - || item->data(Constants::EditorItemDataKey).toBool()); -} - -QList QDeclarativeViewInspectorPrivate::filterForSelection( - QList &itemlist) const -{ - foreach (QGraphicsItem *item, itemlist) { - if (isEditorItem(item)) - itemlist.removeOne(item); - } - - return itemlist; -} - -void QDeclarativeViewInspectorPrivate::_q_onStatusChanged(QDeclarativeView::Status status) -{ - if (status == QDeclarativeView::Ready) - q->sendReloaded(); -} - -// adjusts bounding boxes on edges of screen to be visible -QRectF QDeclarativeViewInspector::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace) -{ - int marginFromEdge = 1; - QRectF boundingRect(boundingRectInSceneSpace); - if (qAbs(boundingRect.left()) - 1 < 2) - boundingRect.setLeft(marginFromEdge); - - QRect rect = data->view->rect(); - - if (boundingRect.right() >= rect.right()) - boundingRect.setRight(rect.right() - marginFromEdge); - - if (qAbs(boundingRect.top()) - 1 < 2) - boundingRect.setTop(marginFromEdge); - - if (boundingRect.bottom() >= rect.bottom()) - boundingRect.setBottom(rect.bottom() - marginFromEdge); - - return boundingRect; -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.h deleted file mode 100644 index 5ac6b42eef..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector.h +++ /dev/null @@ -1,100 +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_H -#define QDECLARATIVEVIEWINSPECTOR_H - -#include - -#include "abstractviewinspector.h" - -#include -#include - -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 &objects); - void reloadView(); - void reparentQmlObject(QObject *object, QObject *newParent); - void changeTool(InspectorProtocol::Tool tool); - Qt::WindowFlags windowFlags() const; - void setWindowFlags(Qt::WindowFlags flags); - QDeclarativeEngine *declarativeEngine() const; - - void setSelectedItems(QList items); - QList 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 data; - friend class QDeclarativeViewInspectorPrivate; - friend class AbstractLiveEditTool; -}; - -} // namespace QmlJSDebugger - -#endif // QDECLARATIVEVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector_p.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector_p.h deleted file mode 100644 index a51f155404..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/qdeclarativeviewinspector_p.h +++ /dev/null @@ -1,119 +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_H -#define QDECLARATIVEVIEWINSPECTOR_P_H - -#include "qdeclarativeviewinspector.h" - -#include -#include -#include -#include - -#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h" - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; -class LiveSelectionTool; -class ZoomTool; -class ColorPickerTool; -class LiveLayerItem; -class BoundingRectHighlighter; -class AbstractLiveEditTool; - -class QDeclarativeViewInspectorPrivate : public QObject -{ - Q_OBJECT -public: - QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *); - ~QDeclarativeViewInspectorPrivate(); - - QDeclarativeView *view; - QDeclarativeViewInspector *q; - QWeakPointer viewport; - - QList > currentSelection; - - LiveSelectionTool *selectionTool; - ZoomTool *zoomTool; - ColorPickerTool *colorPickerTool; - LiveLayerItem *manipulatorLayer; - - BoundingRectHighlighter *boundingRectHighlighter; - - void setViewport(QWidget *widget); - - void clearEditorItems(); - void changeToSelectTool(); - QList filterForSelection(QList &itemlist) const; - - QList selectableItems(const QPoint &pos) const; - QList selectableItems(const QPointF &scenePos) const; - QList selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; - - void setSelectedItemsForTools(const QList &items); - void setSelectedItems(const QList &items); - QList selectedItems() const; - - void clearHighlight(); - void highlight(const QList &item); - inline void highlight(QGraphicsObject *item) - { highlight(QList() << item); } - - void changeToSingleSelectTool(); - void changeToMarqueeSelectTool(); - void changeToZoomTool(); - void changeToColorPickerTool(); - -public slots: - void _q_onStatusChanged(QDeclarativeView::Status status); - - void _q_removeFromSelection(QObject *); - -public: - static QDeclarativeViewInspectorPrivate *get(QDeclarativeViewInspector *v) { return v->d_func(); } -}; - -} // namespace QmlJSDebugger - -#endif // QDECLARATIVEVIEWINSPECTOR_P_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.cpp deleted file mode 100644 index 4e3aed2fb4..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.cpp +++ /dev/null @@ -1,130 +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$ -** -****************************************************************************/ - -#include "subcomponentmasklayeritem.h" - -#include "../qmlinspectorconstants.h" -#include "qdeclarativeviewinspector.h" - -#include - -namespace QmlJSDebugger { - -SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, - QGraphicsItem *parentItem) : - QGraphicsPolygonItem(parentItem), - m_inspector(inspector), - m_currentItem(0), - m_borderRect(new QGraphicsRectItem(this)) -{ - m_borderRect->setRect(0,0,0,0); - m_borderRect->setPen(QPen(QColor(60, 60, 60), 1)); - m_borderRect->setData(Constants::EditorItemDataKey, QVariant(true)); - - setBrush(QBrush(QColor(160,160,160))); - setPen(Qt::NoPen); -} - -int SubcomponentMaskLayerItem::type() const -{ - return Constants::EditorItemType; -} - -static QRectF resizeRect(const QRectF &newRect, const QRectF &oldRect) -{ - QRectF result = newRect; - if (oldRect.left() < newRect.left()) - result.setLeft(oldRect.left()); - - if (oldRect.top() < newRect.top()) - result.setTop(oldRect.top()); - - if (oldRect.right() > newRect.right()) - result.setRight(oldRect.right()); - - if (oldRect.bottom() > newRect.bottom()) - result.setBottom(oldRect.bottom()); - - return result; -} - -static QPolygonF regionToPolygon(const QRegion ®ion) -{ - QPainterPath path; - foreach (const QRect &rect, region.rects()) - path.addRect(rect); - return path.toFillPolygon(); -} - -void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) -{ - QGraphicsItem *prevItem = m_currentItem; - m_currentItem = item; - - if (!m_currentItem) - return; - - QRect viewRect = m_inspector->declarativeView()->rect(); - viewRect = m_inspector->declarativeView()->mapToScene(viewRect).boundingRect().toRect(); - - QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); - itemRect = item->mapRectToScene(itemRect); - - // if updating the same item as before, resize the rectangle only bigger, not smaller. - if (prevItem == item && prevItem != 0) { - m_itemPolyRect = resizeRect(itemRect, m_itemPolyRect); - } else { - m_itemPolyRect = itemRect; - } - QRectF borderRect = m_itemPolyRect; - borderRect.adjust(-1, -1, 1, 1); - m_borderRect->setRect(borderRect); - - const QRegion externalRegion = QRegion(viewRect).subtracted(m_itemPolyRect.toRect()); - setPolygon(regionToPolygon(externalRegion)); -} - -QGraphicsItem *SubcomponentMaskLayerItem::currentItem() const -{ - return m_currentItem; -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.h deleted file mode 100644 index 72c74663a1..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/subcomponentmasklayeritem.h +++ /dev/null @@ -1,71 +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 SUBCOMPONENTMASKLAYERITEM_H -#define SUBCOMPONENTMASKLAYERITEM_H - -#include - -namespace QmlJSDebugger { - -class QDeclarativeViewInspector; - -class SubcomponentMaskLayerItem : public QGraphicsPolygonItem -{ -public: - explicit SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, - QGraphicsItem *parentItem = 0); - int type() const; - void setCurrentItem(QGraphicsItem *item); - void setBoundingBox(const QRectF &boundingBox); - QGraphicsItem *currentItem() const; - QRectF itemRect() const; - -private: - QDeclarativeViewInspector *m_inspector; - QGraphicsItem *m_currentItem; - QGraphicsRectItem *m_borderRect; - QRectF m_itemPolyRect; -}; - -} // namespace QmlJSDebugger - -#endif // SUBCOMPONENTMASKLAYERITEM_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.cpp b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.cpp deleted file mode 100644 index 92f34b36e8..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.cpp +++ /dev/null @@ -1,328 +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$ -** -****************************************************************************/ - -#include "zoomtool.h" - -#include "qdeclarativeviewinspector_p.h" - -#include -#include -#include -#include -#include - -#include -#include - -namespace QmlJSDebugger { - -ZoomTool::ZoomTool(QDeclarativeViewInspector *view) : - AbstractLiveEditTool(view), - m_rubberbandManipulator(), - m_smoothZoomMultiplier(0.05f), - m_currentScale(1.0f) -{ - m_zoomTo100Action = new QAction(tr("Zoom to &100%"), this); - m_zoomInAction = new QAction(tr("Zoom In"), this); - m_zoomOutAction = new QAction(tr("Zoom Out"), this); - m_zoomInAction->setShortcut(QKeySequence(Qt::Key_Plus)); - m_zoomOutAction->setShortcut(QKeySequence(Qt::Key_Minus)); - - - LiveLayerItem *layerItem = QDeclarativeViewInspectorPrivate::get(view)->manipulatorLayer; - QGraphicsObject *layerObject = reinterpret_cast(layerItem); - m_rubberbandManipulator = new LiveRubberBandSelectionManipulator(layerObject, view); - - - connect(m_zoomTo100Action, SIGNAL(triggered()), SLOT(zoomTo100())); - connect(m_zoomInAction, SIGNAL(triggered()), SLOT(zoomIn())); - connect(m_zoomOutAction, SIGNAL(triggered()), SLOT(zoomOut())); -} - -ZoomTool::~ZoomTool() -{ - delete m_rubberbandManipulator; -} - -void ZoomTool::mousePressEvent(QMouseEvent *event) -{ - m_mousePos = event->pos(); - - QPointF scenePos = view()->mapToScene(event->pos()); - - if (event->buttons() & Qt::RightButton) { - QMenu contextMenu; - contextMenu.addAction(m_zoomTo100Action); - contextMenu.addSeparator(); - contextMenu.addAction(m_zoomInAction); - contextMenu.addAction(m_zoomOutAction); - contextMenu.exec(event->globalPos()); - } else if (event->buttons() & Qt::LeftButton) { - m_dragBeginPos = scenePos; - m_dragStarted = false; - } -} - -void ZoomTool::mouseMoveEvent(QMouseEvent *event) -{ - m_mousePos = event->pos(); - - QPointF scenePos = view()->mapToScene(event->pos()); - - if (event->buttons() & Qt::LeftButton - && (QPointF(scenePos - m_dragBeginPos).manhattanLength() - > Constants::DragStartDistance / 3) - && !m_dragStarted) - { - m_dragStarted = true; - m_rubberbandManipulator->begin(m_dragBeginPos); - return; - } - - if (m_dragStarted) - m_rubberbandManipulator->update(scenePos); - -} - -void ZoomTool::mouseReleaseEvent(QMouseEvent *event) -{ - m_mousePos = event->pos(); - QPointF scenePos = view()->mapToScene(event->pos()); - - if (m_dragStarted) { - m_rubberbandManipulator->end(); - - int x1 = qMin(scenePos.x(), m_rubberbandManipulator->beginPoint().x()); - int x2 = qMax(scenePos.x(), m_rubberbandManipulator->beginPoint().x()); - int y1 = qMin(scenePos.y(), m_rubberbandManipulator->beginPoint().y()); - int y2 = qMax(scenePos.y(), m_rubberbandManipulator->beginPoint().y()); - - QPointF scenePosTopLeft = QPoint(x1, y1); - QPointF scenePosBottomRight = QPoint(x2, y2); - - QRectF sceneArea(scenePosTopLeft, scenePosBottomRight); - - m_currentScale = qMin(view()->rect().width() / sceneArea.width(), - view()->rect().height() / sceneArea.height()); - - - QTransform transform; - transform.scale(m_currentScale, m_currentScale); - - view()->setTransform(transform); - view()->setSceneRect(sceneArea); - } else { - Qt::KeyboardModifier modifierKey = Qt::ControlModifier; -#ifdef Q_OS_MAC - modifierKey = Qt::AltModifier; -#endif - if (event->modifiers() & modifierKey) { - zoomOut(); - } else { - zoomIn(); - } - } -} - -void ZoomTool::zoomIn() -{ - m_currentScale = nextZoomScale(ZoomIn); - scaleView(view()->mapToScene(m_mousePos)); -} - -void ZoomTool::zoomOut() -{ - m_currentScale = nextZoomScale(ZoomOut); - scaleView(view()->mapToScene(m_mousePos)); -} - -void ZoomTool::mouseDoubleClickEvent(QMouseEvent *event) -{ - m_mousePos = event->pos(); -} - - -void ZoomTool::hoverMoveEvent(QMouseEvent *event) -{ - m_mousePos = event->pos(); -} - - -void ZoomTool::keyPressEvent(QKeyEvent * /*event*/) -{ -} - -void ZoomTool::wheelEvent(QWheelEvent *event) -{ - if (event->orientation() != Qt::Vertical) - return; - - Qt::KeyboardModifier smoothZoomModifier = Qt::ControlModifier; - if (event->modifiers() & smoothZoomModifier) { - int numDegrees = event->delta() / 8; - m_currentScale += m_smoothZoomMultiplier * (numDegrees / 15.0f); - - scaleView(view()->mapToScene(m_mousePos)); - - } else if (!event->modifiers()) { - if (event->delta() > 0) { - m_currentScale = nextZoomScale(ZoomIn); - } else if (event->delta() < 0) { - m_currentScale = nextZoomScale(ZoomOut); - } - scaleView(view()->mapToScene(m_mousePos)); - } -} - -void ZoomTool::keyReleaseEvent(QKeyEvent *event) -{ - switch (event->key()) { - case Qt::Key_Plus: - zoomIn(); - break; - case Qt::Key_Minus: - zoomOut(); - break; - case Qt::Key_1: - case Qt::Key_2: - case Qt::Key_3: - case Qt::Key_4: - case Qt::Key_5: - case Qt::Key_6: - case Qt::Key_7: - case Qt::Key_8: - case Qt::Key_9: - { - m_currentScale = ((event->key() - Qt::Key_0) * 1.0f); - scaleView(view()->mapToScene(m_mousePos)); // view()->mapToScene(view()->rect().center()) - break; - } - - default: - break; - } - -} - -void ZoomTool::clear() -{ - view()->setCursor(Qt::ArrowCursor); -} - -void ZoomTool::scaleView(const QPointF ¢erPos) -{ - - QTransform transform; - transform.scale(m_currentScale, m_currentScale); - view()->setTransform(transform); - - QPointF adjustedCenterPos = centerPos; - QSize rectSize(view()->rect().width() / m_currentScale, - view()->rect().height() / m_currentScale); - - QRectF sceneRect; - if (qAbs(m_currentScale - 1.0f) < Constants::ZoomSnapDelta) { - adjustedCenterPos.rx() = rectSize.width() / 2; - adjustedCenterPos.ry() = rectSize.height() / 2; - } - - if (m_currentScale < 1.0f) { - adjustedCenterPos.rx() = rectSize.width() / 2; - adjustedCenterPos.ry() = rectSize.height() / 2; - sceneRect.setRect(view()->rect().width() / 2 -rectSize.width() / 2, - view()->rect().height() / 2 -rectSize.height() / 2, - rectSize.width(), - rectSize.height()); - } else { - sceneRect.setRect(adjustedCenterPos.x() - rectSize.width() / 2, - adjustedCenterPos.y() - rectSize.height() / 2, - rectSize.width(), - rectSize.height()); - } - - view()->setSceneRect(sceneRect); -} - -void ZoomTool::zoomTo100() -{ - m_currentScale = 1.0f; - scaleView(view()->mapToScene(view()->rect().center())); -} - -qreal ZoomTool::nextZoomScale(ZoomDirection direction) const -{ - static QList zoomScales = - QList() - << 0.125f - << 1.0f / 6.0f - << 0.25f - << 1.0f / 3.0f - << 0.5f - << 2.0f / 3.0f - << 1.0f - << 2.0f - << 3.0f - << 4.0f - << 5.0f - << 6.0f - << 7.0f - << 8.0f - << 12.0f - << 16.0f - << 32.0f - << 48.0f; - - if (direction == ZoomIn) { - for (int i = 0; i < zoomScales.length(); ++i) { - if (zoomScales[i] > m_currentScale || i == zoomScales.length() - 1) - return zoomScales[i]; - } - } else { - for (int i = zoomScales.length() - 1; i >= 0; --i) { - if (zoomScales[i] < m_currentScale || i == 0) - return zoomScales[i]; - } - } - - return 1.0f; -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.h b/src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.h deleted file mode 100644 index de935591cb..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/qtquick1/zoomtool.h +++ /dev/null @@ -1,107 +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 ZOOMTOOL_H -#define ZOOMTOOL_H - -#include "abstractliveedittool.h" -#include "liverubberbandselectionmanipulator.h" - -QT_FORWARD_DECLARE_CLASS(QAction) - -namespace QmlJSDebugger { - -class ZoomTool : public AbstractLiveEditTool -{ - Q_OBJECT - -public: - enum ZoomDirection { - ZoomIn, - ZoomOut - }; - - explicit ZoomTool(QDeclarativeViewInspector *view); - - virtual ~ZoomTool(); - - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseDoubleClickEvent(QMouseEvent *event); - - void hoverMoveEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *keyEvent); - void itemsAboutToRemoved(const QList &) {} - - void clear(); - -protected: - void selectedItemsChanged(const QList &) {} - -private slots: - void zoomTo100(); - void zoomIn(); - void zoomOut(); - -private: - qreal nextZoomScale(ZoomDirection direction) const; - void scaleView(const QPointF ¢erPos); - -private: - bool m_dragStarted; - QPoint m_mousePos; // in view coords - QPointF m_dragBeginPos; - QAction *m_zoomTo100Action; - QAction *m_zoomInAction; - QAction *m_zoomOutAction; - LiveRubberBandSelectionManipulator *m_rubberbandManipulator; - - qreal m_smoothZoomMultiplier; - qreal m_currentScale; -}; - -} // namespace QmlJSDebugger - -#endif // ZOOMTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp deleted file mode 100644 index 1af789d389..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp +++ /dev/null @@ -1,98 +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$ -** -****************************************************************************/ - -#include "sghighlight.h" - -#include - -namespace QmlJSDebugger { - -SGHighlight::SGHighlight(QQuickItem *item, QQuickItem *parent) - : QQuickPaintedItem(parent) -{ - setItem(item); -} - -void SGHighlight::setItem(QQuickItem *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 QQuickItem *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 deleted file mode 100644 index 8d5659cc5d..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h +++ /dev/null @@ -1,97 +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 SGHIGHLIGHT_H -#define SGHIGHLIGHT_H - -#include -#include - -namespace QmlJSDebugger { - -class SGHighlight : public QQuickPaintedItem -{ - Q_OBJECT - -public: - SGHighlight(QQuickItem *parent) : QQuickPaintedItem(parent) {} - SGHighlight(QQuickItem *item, QQuickItem *parent); - - void setItem(QQuickItem *item); - -private slots: - void adjust(); - -private: - QWeakPointer m_item; -}; - -/** - * A highlight suitable for indicating selection. - */ -class SGSelectionHighlight : public SGHighlight -{ -public: - SGSelectionHighlight(QQuickItem *item, QQuickItem *parent) - : SGHighlight(item, parent) - {} - - void paint(QPainter *painter); -}; - -/** - * A highlight suitable for indicating hover. - */ -class SGHoverHighlight : public SGHighlight -{ -public: - SGHoverHighlight(QQuickItem *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 deleted file mode 100644 index bdfc28f5ec..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp +++ /dev/null @@ -1,135 +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$ -** -****************************************************************************/ - -#include "sgselectiontool.h" - -#include "sghighlight.h" -#include "sgviewinspector.h" - -#include -#include -#include -#include - -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 (QQuickItem *item = inspector()->topVisibleItemAt(event->pos())) - inspector()->setSelectedItems(QList() << item); - } else if (event->button() == Qt::RightButton) { - QList items = inspector()->itemsAt(event->pos()); - createContextMenu(items, event->globalPos()); - } -} - -void SGSelectionTool::hoverMoveEvent(QMouseEvent *event) -{ - QQuickItem *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 &items, QPoint pos) -{ - QMenu contextMenu; - connect(&contextMenu, SIGNAL(hovered(QAction*)), - this, SLOT(contextMenuElementHovered(QAction*))); - - const QList selectedItems = inspector()->selectedItems(); - int shortcutKey = Qt::Key_1; - - foreach (QQuickItem *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 (QQuickItem *item = action->data().value()) - m_hoverHighlight->setItem(item); -} - -void SGSelectionTool::contextMenuElementSelected() -{ - if (QQuickItem *item = static_cast(sender())->data().value()) - inspector()->setSelectedItems(QList() << item); -} - -SGViewInspector *SGSelectionTool::inspector() const -{ - return static_cast(AbstractTool::inspector()); -} - -} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h deleted file mode 100644 index 587701733d..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.h +++ /dev/null @@ -1,91 +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 SGSELECTIONTOOL_H -#define SGSELECTIONTOOL_H - -#include "abstracttool.h" - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QAction) -QT_FORWARD_DECLARE_CLASS(QQuickItem) - -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 &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 deleted file mode 100644 index 7b573cab27..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp +++ /dev/null @@ -1,330 +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$ -** -****************************************************************************/ - -#include "sgviewinspector.h" - -#include "qdeclarativeinspectorprotocol.h" -#include "sghighlight.h" -#include "sgselectiontool.h" - -#include - -#include -#include - -#include - -namespace QmlJSDebugger { - -/* - * Collects all the items at the given position, from top to bottom. - */ -static void collectItemsAt(QQuickItem *item, const QPointF &pos, QQuickItem *overlay, - QList &resultList) -{ - if (item == overlay) - return; - - if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { - if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) - return; - } - - QList children = QQuickItemPrivate::get(item)->paintOrderChildItems(); - for (int i = children.count() - 1; i >= 0; --i) { - QQuickItem *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 QQuickItem *itemAt(QQuickItem *item, const QPointF &pos, QQuickItem *overlay) -{ - if (item == overlay) - return 0; - - if (!item->isVisible() || item->opacity() == 0.0) - return 0; - - if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { - if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) - return 0; - } - - QList children = QQuickItemPrivate::get(item)->paintOrderChildItems(); - for (int i = children.count() - 1; i >= 0; --i) { - QQuickItem *child = children.at(i); - if (QQuickItem *betterCandidate = itemAt(child, item->mapToItem(child, pos), overlay)) - return betterCandidate; - } - - if (!(item->flags() & QQuickItem::ItemHasContents)) - return 0; - - if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) - return 0; - - return item; -} - - -SGViewInspector::SGViewInspector(QQuickView *view, QObject *parent) : - AbstractViewInspector(parent), - m_view(view), - m_overlay(new QQuickItem), - m_selectionTool(new SGSelectionTool(this)), - m_designMode(true) -{ - // Try to make sure the overlay is always on top - m_overlay->setZ(FLT_MAX); - - if (QQuickItem *root = view->rootItem()) - m_overlay->setParentItem(root); - - view->installEventFilter(this); - setCurrentTool(m_selectionTool); -} - -void SGViewInspector::changeCurrentObjects(const QList &objects) -{ - QList items; - foreach (QObject *obj, objects) - if (QQuickItem *item = qobject_cast(obj)) - items << item; - - syncSelectedItems(items); -} - -void SGViewInspector::reloadView() -{ - // TODO - emit reloadRequested(); -} - -void SGViewInspector::reparentQmlObject(QObject *object, QObject *newParent) -{ - if (!newParent) - return; - - object->setParent(newParent); - QQuickItem *newParentItem = qobject_cast(newParent); - QQuickItem *item = qobject_cast(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; - } -} - -QWindow *getMasterWindow(QWindow *w) -{ - QWindow *p = w->parent(); - while (p) { - w = p; - p = p->parent(); - } - return w; -} - -Qt::WindowFlags SGViewInspector::windowFlags() const -{ - return getMasterWindow(m_view)->windowFlags(); -} - -void SGViewInspector::setWindowFlags(Qt::WindowFlags flags) -{ - QWindow *w = getMasterWindow(m_view); - w->setWindowFlags(flags); - // make flags are applied - w->setVisible(false); - w->setVisible(true); -} - -QDeclarativeEngine *SGViewInspector::declarativeEngine() const -{ - return m_view->engine(); -} - -QQuickItem *SGViewInspector::topVisibleItemAt(const QPointF &pos) const -{ - QQuickItem *root = m_view->rootItem(); - return itemAt(root, root->mapFromScene(pos), m_overlay); -} - -QList SGViewInspector::itemsAt(const QPointF &pos) const -{ - QQuickItem *root = m_view->rootItem(); - QList resultList; - collectItemsAt(root, root->mapFromScene(pos), m_overlay, resultList); - return resultList; -} - -QList SGViewInspector::selectedItems() const -{ - QList selection; - foreach (const QWeakPointer &selectedItem, m_selectedItems) { - if (selectedItem) - selection << selectedItem.data(); - } - return selection; -} - -void SGViewInspector::setSelectedItems(const QList &items) -{ - if (!syncSelectedItems(items)) - return; - - QList objectList; - foreach (QQuickItem *item, items) - objectList << item; - - sendCurrentObjects(objectList); -} - -bool SGViewInspector::syncSelectedItems(const QList &items) -{ - bool selectionChanged = false; - - // Disconnect and remove items that are no longer selected - foreach (const QWeakPointer &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 (QQuickItem *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 (QQuickItem *item = qobject_cast(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) -{ - // TODO -// if (QQuickItem *item = topVisibleItemAt(event->pos())) -// m_view->setToolTip(titleForItem(item)); -// else -// m_view->setToolTip(QString()); - - return AbstractViewInspector::mouseMoveEvent(event); -} - -QString SGViewInspector::titleForItem(QQuickItem *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("QQuick"))) - className = className.mid(6); - - 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 deleted file mode 100644 index 788d6a0924..0000000000 --- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h +++ /dev/null @@ -1,110 +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 QSGVIEWINSPECTOR_H -#define QSGVIEWINSPECTOR_H - -#include "abstractviewinspector.h" - -#include -#include - -QT_BEGIN_NAMESPACE -class QQuickView; -class QQuickItem; -QT_END_NAMESPACE - -namespace QmlJSDebugger { - -class SGSelectionTool; -class SGSelectionHighlight; - -class SGViewInspector : public AbstractViewInspector -{ - Q_OBJECT -public: - explicit SGViewInspector(QQuickView *view, QObject *parent = 0); - - // AbstractViewInspector - void changeCurrentObjects(const QList &objects); - void reloadView(); - void reparentQmlObject(QObject *object, QObject *newParent); - void changeTool(InspectorProtocol::Tool tool); - Qt::WindowFlags windowFlags() const; - void setWindowFlags(Qt::WindowFlags flags); - QDeclarativeEngine *declarativeEngine() const; - - QQuickView *view() const { return m_view; } - QQuickItem *overlay() const { return m_overlay; } - - QQuickItem *topVisibleItemAt(const QPointF &pos) const; - QList itemsAt(const QPointF &pos) const; - - QList selectedItems() const; - void setSelectedItems(const QList &items); - - QString titleForItem(QQuickItem *item) const; - -protected: - bool eventFilter(QObject *obj, QEvent *event); - - bool mouseMoveEvent(QMouseEvent *); - -private slots: - void removeFromSelectedItems(QObject *); - -private: - bool syncSelectedItems(const QList &items); - - QQuickView *m_view; - QQuickItem *m_overlay; - - SGSelectionTool *m_selectionTool; - - QList > m_selectedItems; - QHash m_highlightItems; - - bool m_designMode; -}; - -} // namespace QmlJSDebugger - -#endif // QSGVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.cpp new file mode 100644 index 0000000000..09a39d6520 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** 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 "abstractliveedittool.h" +#include "qdeclarativeviewinspector_p.h" + +#include + +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewInspector *editorView) + : AbstractTool(editorView) +{ +} + + +AbstractLiveEditTool::~AbstractLiveEditTool() +{ +} + +QDeclarativeViewInspector *AbstractLiveEditTool::inspector() const +{ + return static_cast(AbstractTool::inspector()); +} + +QDeclarativeView *AbstractLiveEditTool::view() const +{ + return inspector()->declarativeView(); +} + +QGraphicsScene* AbstractLiveEditTool::scene() const +{ + return view()->scene(); +} + +void AbstractLiveEditTool::updateSelectedItems() +{ + selectedItemsChanged(items()); +} + +QList AbstractLiveEditTool::items() const +{ + return inspector()->selectedItems(); +} + +bool AbstractLiveEditTool::topItemIsMovable(const QList & itemList) +{ + QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList); + if (firstSelectableItem == 0) + return false; + if (toQDeclarativeItem(firstSelectableItem) != 0) + return true; + + return false; + +} + +bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList &itemList) +{ + QList selectedItems = inspector()->selectedItems(); + + foreach (QGraphicsItem *item, itemList) { + QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); + if (declarativeItem + && selectedItems.contains(declarativeItem) + /*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/) + return true; + } + + return false; + +} + +bool AbstractLiveEditTool::topItemIsResizeHandle(const QList &/*itemList*/) +{ + return false; +} + +QDeclarativeItem *AbstractLiveEditTool::toQDeclarativeItem(QGraphicsItem *item) +{ + return qobject_cast(item->toGraphicsObject()); +} + +QGraphicsItem *AbstractLiveEditTool::topMovableGraphicsItem(const QList &itemList) +{ + foreach (QGraphicsItem *item, itemList) { + if (item->flags().testFlag(QGraphicsItem::ItemIsMovable)) + return item; + } + return 0; +} + +QDeclarativeItem *AbstractLiveEditTool::topMovableDeclarativeItem(const QList + &itemList) +{ + foreach (QGraphicsItem *item, itemList) { + QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); + if (declarativeItem /*&& (declarativeItem->qmlItemNode().hasShowContent())*/) + return declarativeItem; + } + + return 0; +} + +QList AbstractLiveEditTool::toGraphicsObjectList(const QList + &itemList) +{ + QList gfxObjects; + foreach (QGraphicsItem *item, itemList) { + QGraphicsObject *obj = item->toGraphicsObject(); + if (obj) + gfxObjects << obj; + } + + return gfxObjects; +} + +QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) +{ + QString className(QLatin1String("QGraphicsItem")); + QString objectStringId; + + QString constructedName; + + QGraphicsObject *gfxObject = item->toGraphicsObject(); + if (gfxObject) { + className = QLatin1String(gfxObject->metaObject()->className()); + + className.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+"))); + className.remove(QRegExp(QLatin1String("_QML_\\d+"))); + if (className.startsWith(QLatin1String("QDeclarative"))) + className = className.remove(QLatin1String("QDeclarative")); + + QDeclarativeItem *declarativeItem = qobject_cast(gfxObject); + if (declarativeItem) { + objectStringId = inspector()->idStringForObject(declarativeItem); + } + + if (!objectStringId.isEmpty()) { + constructedName = objectStringId + QLatin1String(" (") + className + QLatin1Char(')'); + } else { + if (!gfxObject->objectName().isEmpty()) { + constructedName = gfxObject->objectName() + QLatin1String(" (") + className + QLatin1Char(')'); + } else { + constructedName = className; + } + } + } + + return constructedName; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.h b/src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.h new file mode 100644 index 0000000000..fd57076d0c --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/abstractliveedittool.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 ABSTRACTLIVEEDITTOOL_H +#define ABSTRACTLIVEEDITTOOL_H + +#include +#include "abstracttool.h" + +QT_BEGIN_NAMESPACE +class QMouseEvent; +class QGraphicsItem; +class QDeclarativeItem; +class QKeyEvent; +class QGraphicsScene; +class QGraphicsObject; +class QWheelEvent; +class QDeclarativeView; +QT_END_NAMESPACE + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; + +class AbstractLiveEditTool : public AbstractTool +{ + Q_OBJECT +public: + AbstractLiveEditTool(QDeclarativeViewInspector *inspector); + + virtual ~AbstractLiveEditTool(); + + void leaveEvent(QEvent *) {} + + virtual void itemsAboutToRemoved(const QList &itemList) = 0; + + virtual void clear() = 0; + + void updateSelectedItems(); + QList items() const; + + bool topItemIsMovable(const QList &itemList); + bool topItemIsResizeHandle(const QList &itemList); + bool topSelectedItemIsMovable(const QList &itemList); + + QString titleForItem(QGraphicsItem *item); + + static QList toGraphicsObjectList(const QList &itemList); + static QGraphicsItem* topMovableGraphicsItem(const QList &itemList); + static QDeclarativeItem* topMovableDeclarativeItem(const QList &itemList); + static QDeclarativeItem *toQDeclarativeItem(QGraphicsItem *item); + +protected: + virtual void selectedItemsChanged(const QList &objectList) = 0; + + QDeclarativeViewInspector *inspector() const; + QDeclarativeView *view() const; + QGraphicsScene *scene() const; + +private: + QList m_itemList; +}; + +} // namespace QtQuick1 +} // namesacpe QmlJSDebugger + +#endif // ABSTRACTLIVEEDITTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.cpp new file mode 100644 index 0000000000..7cf1e83520 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** 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 "boundingrecthighlighter.h" + +#include "qdeclarativeviewinspector.h" +#include "qmlinspectorconstants.h" + +#include + +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +BoundingBox::BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, + QObject *parent) + : QObject(parent), + highlightedObject(itemToHighlight), + highlightPolygon(0), + highlightPolygonEdge(0) +{ + highlightPolygon = new BoundingBoxPolygonItem(parentItem); + highlightPolygonEdge = new BoundingBoxPolygonItem(parentItem); + + highlightPolygon->setPen(QPen(QColor(0, 22, 159))); + highlightPolygonEdge->setPen(QPen(QColor(158, 199, 255))); + + highlightPolygon->setFlag(QGraphicsItem::ItemIsSelectable, false); + highlightPolygonEdge->setFlag(QGraphicsItem::ItemIsSelectable, false); +} + +BoundingBox::~BoundingBox() +{ + highlightedObject.clear(); +} + +BoundingBoxPolygonItem::BoundingBoxPolygonItem(QGraphicsItem *item) : QGraphicsPolygonItem(item) +{ + QPen pen; + pen.setColor(QColor(108, 141, 221)); + pen.setWidth(1); + setPen(pen); +} + +int BoundingBoxPolygonItem::type() const +{ + return Constants::EditorItemType; +} + +BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewInspector *view) : + LiveLayerItem(view->declarativeView()->scene()), + m_view(view) +{ +} + +BoundingRectHighlighter::~BoundingRectHighlighter() +{ + +} + +void BoundingRectHighlighter::clear() +{ + foreach (BoundingBox *box, m_boxes) + freeBoundingBox(box); +} + +BoundingBox *BoundingRectHighlighter::boxFor(QGraphicsObject *item) const +{ + foreach (BoundingBox *box, m_boxes) { + if (box->highlightedObject.data() == item) + return box; + } + return 0; +} + +void BoundingRectHighlighter::highlight(QList items) +{ + if (items.isEmpty()) + return; + + QList newBoxes; + foreach (QGraphicsObject *itemToHighlight, items) { + BoundingBox *box = boxFor(itemToHighlight); + if (!box) + box = createBoundingBox(itemToHighlight); + + newBoxes << box; + } + qSort(newBoxes); + + if (newBoxes != m_boxes) { + clear(); + m_boxes << newBoxes; + } + + highlightAll(); +} + +void BoundingRectHighlighter::highlight(QGraphicsObject* itemToHighlight) +{ + if (!itemToHighlight) + return; + + BoundingBox *box = boxFor(itemToHighlight); + if (!box) { + box = createBoundingBox(itemToHighlight); + m_boxes << box; + qSort(m_boxes); + } + + highlightAll(); +} + +BoundingBox *BoundingRectHighlighter::createBoundingBox(QGraphicsObject *itemToHighlight) +{ + if (!m_freeBoxes.isEmpty()) { + BoundingBox *box = m_freeBoxes.last(); + if (box->highlightedObject.isNull()) { + box->highlightedObject = itemToHighlight; + box->highlightPolygon->show(); + box->highlightPolygonEdge->show(); + m_freeBoxes.removeLast(); + return box; + } + } + + BoundingBox *box = new BoundingBox(itemToHighlight, this, this); + + connect(itemToHighlight, SIGNAL(xChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(yChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(widthChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(heightChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(rotationChanged()), this, SLOT(refresh())); + connect(itemToHighlight, SIGNAL(destroyed(QObject*)), this, SLOT(itemDestroyed(QObject*))); + + return box; +} + +void BoundingRectHighlighter::removeBoundingBox(BoundingBox *box) +{ + delete box; + box = 0; +} + +void BoundingRectHighlighter::freeBoundingBox(BoundingBox *box) +{ + if (!box->highlightedObject.isNull()) { + disconnect(box->highlightedObject.data(), SIGNAL(xChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(yChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(widthChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(heightChanged()), this, SLOT(refresh())); + disconnect(box->highlightedObject.data(), SIGNAL(rotationChanged()), this, SLOT(refresh())); + } + + box->highlightedObject.clear(); + box->highlightPolygon->hide(); + box->highlightPolygonEdge->hide(); + m_boxes.removeOne(box); + m_freeBoxes << box; +} + +void BoundingRectHighlighter::itemDestroyed(QObject *obj) +{ + foreach (BoundingBox *box, m_boxes) { + if (box->highlightedObject.data() == obj) { + freeBoundingBox(box); + break; + } + } +} + +void BoundingRectHighlighter::highlightAll() +{ + foreach (BoundingBox *box, m_boxes) { + if (box && box->highlightedObject.isNull()) { + // clear all highlights + clear(); + return; + } + QGraphicsObject *item = box->highlightedObject.data(); + + QRectF boundingRectInSceneSpace(item->mapToScene(item->boundingRect()).boundingRect()); + QRectF boundingRectInLayerItemSpace = mapRectFromScene(boundingRectInSceneSpace); + QRectF bboxRect = m_view->adjustToScreenBoundaries(boundingRectInLayerItemSpace); + QRectF edgeRect = bboxRect; + edgeRect.adjust(-1, -1, 1, 1); + + box->highlightPolygon->setPolygon(QPolygonF(bboxRect)); + box->highlightPolygonEdge->setPolygon(QPolygonF(edgeRect)); + } +} + +void BoundingRectHighlighter::refresh() +{ + if (!m_boxes.isEmpty()) + highlightAll(); +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.h b/src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.h new file mode 100644 index 0000000000..e99197f06d --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/boundingrecthighlighter.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** 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 BOUNDINGRECTHIGHLIGHTER_H +#define BOUNDINGRECTHIGHLIGHTER_H + +#include "livelayeritem.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) +QT_FORWARD_DECLARE_CLASS(QPainter) +QT_FORWARD_DECLARE_CLASS(QWidget) +QT_FORWARD_DECLARE_CLASS(QStyleOptionGraphicsItem) +QT_FORWARD_DECLARE_CLASS(QTimer) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; +class BoundingBox; + +class BoundingRectHighlighter : public LiveLayerItem +{ + Q_OBJECT +public: + explicit BoundingRectHighlighter(QDeclarativeViewInspector *view); + ~BoundingRectHighlighter(); + void clear(); + void highlight(QList items); + void highlight(QGraphicsObject* item); + +private slots: + void refresh(); + void itemDestroyed(QObject *); + +private: + BoundingBox *boxFor(QGraphicsObject *item) const; + void highlightAll(); + BoundingBox *createBoundingBox(QGraphicsObject *itemToHighlight); + void removeBoundingBox(BoundingBox *box); + void freeBoundingBox(BoundingBox *box); + +private: + Q_DISABLE_COPY(BoundingRectHighlighter) + + QDeclarativeViewInspector *m_view; + QList m_boxes; + QList m_freeBoxes; +}; + +class BoundingBox : public QObject +{ + Q_OBJECT +public: + explicit BoundingBox(QGraphicsObject *itemToHighlight, QGraphicsItem *parentItem, + QObject *parent = 0); + ~BoundingBox(); + QWeakPointer highlightedObject; + QGraphicsPolygonItem *highlightPolygon; + QGraphicsPolygonItem *highlightPolygonEdge; + +private: + Q_DISABLE_COPY(BoundingBox) + +}; + +class BoundingBoxPolygonItem : public QGraphicsPolygonItem +{ +public: + explicit BoundingBoxPolygonItem(QGraphicsItem *item); + int type() const; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // BOUNDINGRECTHIGHLIGHTER_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.cpp new file mode 100644 index 0000000000..3372f9c8e6 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.cpp @@ -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$ +** +****************************************************************************/ + +#include "colorpickertool.h" + +#include "qdeclarativeviewinspector.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +ColorPickerTool::ColorPickerTool(QDeclarativeViewInspector *view) : + AbstractLiveEditTool(view) +{ + m_selectedColor.setRgb(0,0,0); +} + +ColorPickerTool::~ColorPickerTool() +{ +} + +void ColorPickerTool::mousePressEvent(QMouseEvent *event) +{ + pickColor(event->pos()); +} + +void ColorPickerTool::mouseMoveEvent(QMouseEvent *event) +{ + pickColor(event->pos()); +} + +void ColorPickerTool::clear() +{ + view()->setCursor(Qt::CrossCursor); +} + +void ColorPickerTool::pickColor(const QPoint &pos) +{ + QRgb fillColor = view()->backgroundBrush().color().rgb(); + if (view()->backgroundBrush().style() == Qt::NoBrush) + fillColor = view()->palette().color(QPalette::Base).rgb(); + + QRectF target(0,0, 1, 1); + QRect source(pos.x(), pos.y(), 1, 1); + QImage img(1, 1, QImage::Format_ARGB32); + img.fill(fillColor); + QPainter painter(&img); + view()->render(&painter, target, source); + m_selectedColor = QColor::fromRgb(img.pixel(0, 0)); + + emit selectedColorChanged(m_selectedColor); +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.h b/src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.h new file mode 100644 index 0000000000..7e86b015eb --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/colorpickertool.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 COLORPICKERTOOL_H +#define COLORPICKERTOOL_H + +#include "abstractliveedittool.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QPoint) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class ColorPickerTool : public AbstractLiveEditTool +{ + Q_OBJECT +public: + explicit ColorPickerTool(QDeclarativeViewInspector *view); + + virtual ~ColorPickerTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *) {} + void mouseDoubleClickEvent(QMouseEvent *) {} + + void hoverMoveEvent(QMouseEvent *) {} + + void keyPressEvent(QKeyEvent *) {} + void keyReleaseEvent(QKeyEvent *) {} + + void wheelEvent(QWheelEvent *) {} + + void itemsAboutToRemoved(const QList &) {} + + void clear(); + +signals: + void selectedColorChanged(const QColor &color); + +protected: + void selectedItemsChanged(const QList &) {} + +private: + void pickColor(const QPoint &pos); + +private: + QColor m_selectedColor; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // COLORPICKERTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.cpp new file mode 100644 index 0000000000..7788eabe26 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 "livelayeritem.h" + +#include "qmlinspectorconstants.h" + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +LiveLayerItem::LiveLayerItem(QGraphicsScene* scene) + : QGraphicsObject() +{ + scene->addItem(this); + setZValue(1); + setFlag(QGraphicsItem::ItemIsMovable, false); +} + +LiveLayerItem::~LiveLayerItem() +{ +} + +void LiveLayerItem::paint(QPainter * /*painter*/, const QStyleOptionGraphicsItem * /*option*/, + QWidget * /*widget*/) +{ +} + +int LiveLayerItem::type() const +{ + return Constants::EditorItemType; +} + +QRectF LiveLayerItem::boundingRect() const +{ + return childrenBoundingRect(); +} + +QList LiveLayerItem::findAllChildItems() const +{ + return findAllChildItems(this); +} + +QList LiveLayerItem::findAllChildItems(const QGraphicsItem *item) const +{ + QList itemList(item->childItems()); + + foreach (QGraphicsItem *childItem, item->childItems()) + itemList += findAllChildItems(childItem); + + return itemList; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.h b/src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.h new file mode 100644 index 0000000000..d819cae8c6 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/livelayeritem.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 LIVELAYERITEM_H +#define LIVELAYERITEM_H + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class LiveLayerItem : public QGraphicsObject +{ +public: + LiveLayerItem(QGraphicsScene *scene); + ~LiveLayerItem(); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = 0); + QRectF boundingRect() const; + int type() const; + + QList findAllChildItems() const; + +protected: + QList findAllChildItems(const QGraphicsItem *item) const; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // LIVELAYERITEM_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.cpp new file mode 100644 index 0000000000..cfa0d4ff1a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.cpp @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 "liverubberbandselectionmanipulator.h" + +#include "qdeclarativeviewinspector_p.h" + +#include + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, + QDeclarativeViewInspector *editorView) + : m_selectionRectangleElement(layerItem), + m_editorView(editorView), + m_beginFormEditorItem(0), + m_isActive(false) +{ + m_selectionRectangleElement.hide(); +} + +void LiveRubberBandSelectionManipulator::clear() +{ + m_selectionRectangleElement.clear(); + m_isActive = false; + m_beginPoint = QPointF(); + m_itemList.clear(); + m_oldSelectionList.clear(); +} + +QGraphicsItem *LiveRubberBandSelectionManipulator::topFormEditorItem(const QList + &itemList) +{ + if (itemList.isEmpty()) + return 0; + + return itemList.first(); +} + +void LiveRubberBandSelectionManipulator::begin(const QPointF &beginPoint) +{ + m_beginPoint = beginPoint; + m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint); + m_selectionRectangleElement.show(); + m_isActive = true; + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(m_editorView); + m_beginFormEditorItem = topFormEditorItem(inspectorPrivate->selectableItems(beginPoint)); + m_oldSelectionList = m_editorView->selectedItems(); +} + +void LiveRubberBandSelectionManipulator::update(const QPointF &updatePoint) +{ + m_selectionRectangleElement.setRect(m_beginPoint, updatePoint); +} + +void LiveRubberBandSelectionManipulator::end() +{ + m_oldSelectionList.clear(); + m_selectionRectangleElement.hide(); + m_isActive = false; +} + +void LiveRubberBandSelectionManipulator::select(SelectionType selectionType) +{ + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(m_editorView); + QList itemList + = inspectorPrivate->selectableItems(m_selectionRectangleElement.rect(), + Qt::IntersectsItemShape); + QList newSelectionList; + + foreach (QGraphicsItem* item, itemList) { + if (item + && item->parentItem() + && !newSelectionList.contains(item) + //&& m_beginFormEditorItem->childItems().contains(item) // TODO activate this test + ) + { + newSelectionList.append(item); + } + } + + if (newSelectionList.isEmpty() && m_beginFormEditorItem) + newSelectionList.append(m_beginFormEditorItem); + + QList resultList; + + switch (selectionType) { + case AddToSelection: { + resultList.append(m_oldSelectionList); + resultList.append(newSelectionList); + } + break; + case ReplaceSelection: { + resultList.append(newSelectionList); + } + break; + case RemoveFromSelection: { + QSet oldSelectionSet(m_oldSelectionList.toSet()); + QSet newSelectionSet(newSelectionList.toSet()); + resultList.append(oldSelectionSet.subtract(newSelectionSet).toList()); + } + } + + m_editorView->setSelectedItems(resultList); +} + + +void LiveRubberBandSelectionManipulator::setItems(const QList &itemList) +{ + m_itemList = itemList; +} + +QPointF LiveRubberBandSelectionManipulator::beginPoint() const +{ + return m_beginPoint; +} + +bool LiveRubberBandSelectionManipulator::isActive() const +{ + return m_isActive; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.h b/src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.h new file mode 100644 index 0000000000..092e852679 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liverubberbandselectionmanipulator.h @@ -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$ +** +****************************************************************************/ + +#ifndef RUBBERBANDSELECTIONMANIPULATOR_H +#define RUBBERBANDSELECTIONMANIPULATOR_H + +#include "liveselectionrectangle.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; + +class LiveRubberBandSelectionManipulator +{ +public: + enum SelectionType { + ReplaceSelection, + AddToSelection, + RemoveFromSelection + }; + + LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, + QDeclarativeViewInspector *editorView); + + void setItems(const QList &itemList); + + void begin(const QPointF& beginPoint); + void update(const QPointF& updatePoint); + void end(); + + void clear(); + + void select(SelectionType selectionType); + + QPointF beginPoint() const; + + bool isActive() const; + +protected: + QGraphicsItem *topFormEditorItem(const QList &itemList); + +private: + QList m_itemList; + QList m_oldSelectionList; + LiveSelectionRectangle m_selectionRectangleElement; + QPointF m_beginPoint; + QDeclarativeViewInspector *m_editorView; + QGraphicsItem *m_beginFormEditorItem; + bool m_isActive; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // RUBBERBANDSELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.cpp new file mode 100644 index 0000000000..0c3f47e534 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** 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 "liveselectionindicator.h" + +#include "qdeclarativeviewinspector_p.h" +#include "qmlinspectorconstants.h" + +#include +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, + QGraphicsObject *layerItem) + : m_layerItem(layerItem) + , m_view(viewInspector) +{ +} + +LiveSelectionIndicator::~LiveSelectionIndicator() +{ + clear(); +} + +void LiveSelectionIndicator::show() +{ + foreach (QGraphicsRectItem *item, m_indicatorShapeHash) + item->show(); +} + +void LiveSelectionIndicator::hide() +{ + foreach (QGraphicsRectItem *item, m_indicatorShapeHash) + item->hide(); +} + +void LiveSelectionIndicator::clear() +{ + if (!m_layerItem.isNull()) { + QGraphicsScene *scene = m_layerItem.data()->scene(); + foreach (QGraphicsRectItem *item, m_indicatorShapeHash) { + scene->removeItem(item); + delete item; + } + } + + m_indicatorShapeHash.clear(); + +} + +void LiveSelectionIndicator::setItems(const QList > &itemList) +{ + clear(); + + foreach (const QWeakPointer &object, itemList) { + if (object.isNull()) + continue; + + QGraphicsItem *item = object.data(); + + if (!m_indicatorShapeHash.contains(item)) { + QGraphicsRectItem *selectionIndicator = new QGraphicsRectItem(m_layerItem.data()); + m_indicatorShapeHash.insert(item, selectionIndicator); + + const QRectF boundingRect = m_view->adjustToScreenBoundaries(item->mapRectToScene(item->boundingRect())); + const QRectF boundingRectInLayerItemSpace = m_layerItem.data()->mapRectFromScene(boundingRect); + + selectionIndicator->setData(Constants::EditorItemDataKey, true); + selectionIndicator->setFlag(QGraphicsItem::ItemIsSelectable, false); + selectionIndicator->setRect(boundingRectInLayerItemSpace); + selectionIndicator->setPen(QColor(108, 141, 221)); + } + } +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.h b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.h new file mode 100644 index 0000000000..db57834e95 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionindicator.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 LIVESELECTIONINDICATOR_H +#define LIVESELECTIONINDICATOR_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QGraphicsObject; +class QGraphicsRectItem; +class QGraphicsItem; +class QPolygonF; +QT_END_NAMESPACE + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; + +class LiveSelectionIndicator +{ +public: + LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, QGraphicsObject *layerItem); + ~LiveSelectionIndicator(); + + void show(); + void hide(); + + void clear(); + + void setItems(const QList > &itemList); + +private: + QHash m_indicatorShapeHash; + QWeakPointer m_layerItem; + QDeclarativeViewInspector *m_view; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // LIVESELECTIONINDICATOR_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.cpp new file mode 100644 index 0000000000..a867aa6daf --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** 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 "liveselectionrectangle.h" + +#include "qmlinspectorconstants.h" + +#include +#include +#include +#include + +#include + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class SelectionRectShape : public QGraphicsRectItem +{ +public: + SelectionRectShape(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} + int type() const { return Constants::EditorItemType; } +}; + +LiveSelectionRectangle::LiveSelectionRectangle(QGraphicsObject *layerItem) + : m_controlShape(new SelectionRectShape(layerItem)), + m_layerItem(layerItem) +{ + m_controlShape->setPen(QPen(Qt::black)); + m_controlShape->setBrush(QColor(128, 128, 128, 50)); +} + +LiveSelectionRectangle::~LiveSelectionRectangle() +{ + if (m_layerItem) + m_layerItem.data()->scene()->removeItem(m_controlShape); +} + +void LiveSelectionRectangle::clear() +{ + hide(); +} +void LiveSelectionRectangle::show() +{ + m_controlShape->show(); +} + +void LiveSelectionRectangle::hide() +{ + m_controlShape->hide(); +} + +QRectF LiveSelectionRectangle::rect() const +{ + return m_controlShape->mapFromScene(m_controlShape->rect()).boundingRect(); +} + +void LiveSelectionRectangle::setRect(const QPointF &firstPoint, + const QPointF &secondPoint) +{ + double firstX = std::floor(firstPoint.x()) + 0.5; + double firstY = std::floor(firstPoint.y()) + 0.5; + double secondX = std::floor(secondPoint.x()) + 0.5; + double secondY = std::floor(secondPoint.y()) + 0.5; + QPointF topLeftPoint(firstX < secondX ? firstX : secondX, + firstY < secondY ? firstY : secondY); + QPointF bottomRightPoint(firstX > secondX ? firstX : secondX, + firstY > secondY ? firstY : secondY); + + QRectF rect(topLeftPoint, bottomRightPoint); + m_controlShape->setRect(rect); +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.h b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.h new file mode 100644 index 0000000000..17eeda765b --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectionrectangle.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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 LIVESELECTIONRECTANGLE_H +#define LIVESELECTIONRECTANGLE_H + +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsObject) +QT_FORWARD_DECLARE_CLASS(QGraphicsRectItem) +QT_FORWARD_DECLARE_CLASS(QPointF) +QT_FORWARD_DECLARE_CLASS(QRectF) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class LiveSelectionRectangle +{ +public: + LiveSelectionRectangle(QGraphicsObject *layerItem); + ~LiveSelectionRectangle(); + + void show(); + void hide(); + + void clear(); + + void setRect(const QPointF &firstPoint, + const QPointF &secondPoint); + + QRectF rect() const; + +private: + QGraphicsRectItem *m_controlShape; + QWeakPointer m_layerItem; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // LIVESELECTIONRECTANGLE_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.cpp new file mode 100644 index 0000000000..5307409272 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.cpp @@ -0,0 +1,425 @@ +/**************************************************************************** +** +** 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 "liveselectiontool.h" +#include "livelayeritem.h" + +#include "qdeclarativeviewinspector_p.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +LiveSelectionTool::LiveSelectionTool(QDeclarativeViewInspector *editorView) : + AbstractLiveEditTool(editorView), + m_rubberbandSelectionMode(false), + m_rubberbandSelectionManipulator( + QDeclarativeViewInspectorPrivate::get(editorView)->manipulatorLayer, editorView), + m_singleSelectionManipulator(editorView), + m_selectionIndicator(editorView, + QDeclarativeViewInspectorPrivate::get(editorView)->manipulatorLayer), + //m_resizeIndicator(editorView->manipulatorLayer()), + m_selectOnlyContentItems(true) +{ + +} + +LiveSelectionTool::~LiveSelectionTool() +{ +} + +void LiveSelectionTool::setRubberbandSelectionMode(bool value) +{ + m_rubberbandSelectionMode = value; +} + +LiveSingleSelectionManipulator::SelectionType LiveSelectionTool::getSelectionType(Qt::KeyboardModifiers + modifiers) +{ + LiveSingleSelectionManipulator::SelectionType selectionType + = LiveSingleSelectionManipulator::ReplaceSelection; + if (modifiers.testFlag(Qt::ControlModifier)) { + selectionType = LiveSingleSelectionManipulator::RemoveFromSelection; + } else if (modifiers.testFlag(Qt::ShiftModifier)) { + selectionType = LiveSingleSelectionManipulator::AddToSelection; + } + return selectionType; +} + +bool LiveSelectionTool::alreadySelected(const QList &itemList) const +{ + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + const QList selectedItems = inspectorPrivate->selectedItems(); + + if (selectedItems.isEmpty()) + return false; + + foreach (QGraphicsItem *item, itemList) + if (selectedItems.contains(item)) + return true; + + return false; +} + +void LiveSelectionTool::mousePressEvent(QMouseEvent *event) +{ + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + QList itemList = inspectorPrivate->selectableItems(event->pos()); + LiveSingleSelectionManipulator::SelectionType selectionType = getSelectionType(event->modifiers()); + + if (event->buttons() & Qt::LeftButton) { + m_mousePressTimer.start(); + + if (m_rubberbandSelectionMode) { + m_rubberbandSelectionManipulator.begin(event->pos()); + } else { + m_singleSelectionManipulator.begin(event->pos()); + m_singleSelectionManipulator.select(selectionType, m_selectOnlyContentItems); + } + } else if (event->buttons() & Qt::RightButton) { + createContextMenu(itemList, event->globalPos()); + } +} + +void LiveSelectionTool::createContextMenu(const QList &itemList, QPoint globalPos) +{ + QMenu contextMenu; + connect(&contextMenu, SIGNAL(hovered(QAction*)), + this, SLOT(contextMenuElementHovered(QAction*))); + + m_contextMenuItemList = itemList; + + contextMenu.addAction(tr("Items")); + contextMenu.addSeparator(); + int shortcutKey = Qt::Key_1; + int i = 0; + + foreach (QGraphicsItem * const item, itemList) { + QString itemTitle = titleForItem(item); + QAction *elementAction = contextMenu.addAction(itemTitle, this, + SLOT(contextMenuElementSelected())); + + if (inspector()->selectedItems().contains(item)) { + QFont boldFont = elementAction->font(); + boldFont.setBold(true); + elementAction->setFont(boldFont); + } + + elementAction->setData(i); + + if (shortcutKey <= Qt::Key_9) { + elementAction->setShortcut(QKeySequence(shortcutKey)); + shortcutKey++; + } + + ++i; + } + // add root item separately + // QString itemTitle = QString(tr("%1")).arg(titleForItem(view()->currentRootItem())); + // contextMenu.addAction(itemTitle, this, SLOT(contextMenuElementSelected())); + // m_contextMenuItemList.append(view()->currentRootItem()); + + contextMenu.exec(globalPos); + m_contextMenuItemList.clear(); +} + +void LiveSelectionTool::contextMenuElementSelected() +{ + QAction *senderAction = static_cast(sender()); + int itemListIndex = senderAction->data().toInt(); + if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { + + QPointF updatePt(0, 0); + QGraphicsItem *item = m_contextMenuItemList.at(itemListIndex); + m_singleSelectionManipulator.begin(updatePt); + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, + QList() << item, + false); + m_singleSelectionManipulator.end(updatePt); + } +} + +void LiveSelectionTool::contextMenuElementHovered(QAction *action) +{ + int itemListIndex = action->data().toInt(); + if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { + QGraphicsObject *item = m_contextMenuItemList.at(itemListIndex)->toGraphicsObject(); + QDeclarativeViewInspectorPrivate::get(inspector())->highlight(item); + } +} + +void LiveSelectionTool::mouseMoveEvent(QMouseEvent *event) +{ + if (m_singleSelectionManipulator.isActive()) { + QPointF mouseMovementVector = m_singleSelectionManipulator.beginPoint() - event->pos(); + + if ((mouseMovementVector.toPoint().manhattanLength() > Constants::DragStartDistance) + && (m_mousePressTimer.elapsed() > Constants::DragStartTime)) + { + m_singleSelectionManipulator.end(event->pos()); + //view()->changeToMoveTool(m_singleSelectionManipulator.beginPoint()); + return; + } + } else if (m_rubberbandSelectionManipulator.isActive()) { + QPointF mouseMovementVector = m_rubberbandSelectionManipulator.beginPoint() - event->pos(); + + if ((mouseMovementVector.toPoint().manhattanLength() > Constants::DragStartDistance) + && (m_mousePressTimer.elapsed() > Constants::DragStartTime)) { + m_rubberbandSelectionManipulator.update(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::RemoveFromSelection); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::AddToSelection); + else + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::ReplaceSelection); + } + } +} + +void LiveSelectionTool::hoverMoveEvent(QMouseEvent * event) +{ +// ### commented out until move tool is re-enabled +// QList itemList = view()->items(event->pos()); +// if (!itemList.isEmpty() && !m_rubberbandSelectionMode) { +// +// foreach (QGraphicsItem *item, itemList) { +// if (item->type() == Constants::ResizeHandleItemType) { +// ResizeHandleItem* resizeHandle = ResizeHandleItem::fromGraphicsItem(item); +// if (resizeHandle) +// view()->changeTool(Constants::ResizeToolMode); +// return; +// } +// } +// if (topSelectedItemIsMovable(itemList)) +// view()->changeTool(Constants::MoveToolMode); +// } + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + + QList selectableItemList = inspectorPrivate->selectableItems(event->pos()); + if (!selectableItemList.isEmpty()) { + QGraphicsObject *item = selectableItemList.first()->toGraphicsObject(); + if (item) + QDeclarativeViewInspectorPrivate::get(inspector())->highlight(item); + + return; + } + + QDeclarativeViewInspectorPrivate::get(inspector())->clearHighlight(); +} + +void LiveSelectionTool::mouseReleaseEvent(QMouseEvent *event) +{ + if (m_singleSelectionManipulator.isActive()) { + m_singleSelectionManipulator.end(event->pos()); + } + else if (m_rubberbandSelectionManipulator.isActive()) { + + QPointF mouseMovementVector = m_rubberbandSelectionManipulator.beginPoint() - event->pos(); + if (mouseMovementVector.toPoint().manhattanLength() < Constants::DragStartDistance) { + m_singleSelectionManipulator.begin(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::RemoveFromSelection, + m_selectOnlyContentItems); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::AddToSelection, + m_selectOnlyContentItems); + else + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, + m_selectOnlyContentItems); + + m_singleSelectionManipulator.end(event->pos()); + } else { + m_rubberbandSelectionManipulator.update(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::RemoveFromSelection); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::AddToSelection); + else + m_rubberbandSelectionManipulator.select( + LiveRubberBandSelectionManipulator::ReplaceSelection); + + m_rubberbandSelectionManipulator.end(); + } + } +} + +void LiveSelectionTool::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Left: + case Qt::Key_Right: + case Qt::Key_Up: + case Qt::Key_Down: + // disabled for now, cannot move stuff yet. + //view()->changeTool(Constants::MoveToolMode); + //view()->currentTool()->keyPressEvent(event); + break; + } +} + +void LiveSelectionTool::wheelEvent(QWheelEvent *event) +{ + if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) + return; + + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + QList itemList = inspectorPrivate->selectableItems(event->pos()); + + if (itemList.isEmpty()) + return; + + int selectedIdx = 0; + if (!inspector()->selectedItems().isEmpty()) { + selectedIdx = itemList.indexOf(inspector()->selectedItems().first()); + if (selectedIdx >= 0) { + if (event->delta() > 0) { + selectedIdx++; + if (selectedIdx == itemList.length()) + selectedIdx = 0; + } else if (event->delta() < 0) { + selectedIdx--; + if (selectedIdx == -1) + selectedIdx = itemList.length() - 1; + } + } else { + selectedIdx = 0; + } + } + + QPointF updatePt(0, 0); + m_singleSelectionManipulator.begin(updatePt); + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::ReplaceSelection, + QList() << itemList.at(selectedIdx), + false); + m_singleSelectionManipulator.end(updatePt); + +} + +void LiveSelectionTool::setSelectOnlyContentItems(bool selectOnlyContentItems) +{ + m_selectOnlyContentItems = selectOnlyContentItems; +} + +void LiveSelectionTool::clear() +{ + view()->setCursor(Qt::ArrowCursor); + m_rubberbandSelectionManipulator.clear(), + m_singleSelectionManipulator.clear(); + m_selectionIndicator.clear(); + //m_resizeIndicator.clear(); +} + +void LiveSelectionTool::selectedItemsChanged(const QList &itemList) +{ + foreach (const QWeakPointer &obj, m_selectedItemList) { + if (!obj.isNull()) { + disconnect(obj.data(), SIGNAL(xChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(yChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects())); + disconnect(obj.data(), SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects())); + } + } + + QList objects = toGraphicsObjectList(itemList); + m_selectedItemList.clear(); + + foreach (QGraphicsObject *obj, objects) { + m_selectedItemList.append(obj); + connect(obj, SIGNAL(xChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(yChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(widthChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(heightChanged()), this, SLOT(repaintBoundingRects())); + connect(obj, SIGNAL(rotationChanged()), this, SLOT(repaintBoundingRects())); + } + + m_selectionIndicator.setItems(m_selectedItemList); + //m_resizeIndicator.setItems(toGraphicsObjectList(itemList)); +} + +void LiveSelectionTool::repaintBoundingRects() +{ + m_selectionIndicator.setItems(m_selectedItemList); +} + +void LiveSelectionTool::selectUnderPoint(QMouseEvent *event) +{ + m_singleSelectionManipulator.begin(event->pos()); + + if (event->modifiers().testFlag(Qt::ControlModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::RemoveFromSelection, + m_selectOnlyContentItems); + else if (event->modifiers().testFlag(Qt::ShiftModifier)) + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::AddToSelection, + m_selectOnlyContentItems); + else + m_singleSelectionManipulator.select(LiveSingleSelectionManipulator::InvertSelection, + m_selectOnlyContentItems); + + m_singleSelectionManipulator.end(event->pos()); +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.h b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.h new file mode 100644 index 0000000000..b6a9aacd0e --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/liveselectiontool.h @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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 LIVESELECTIONTOOL_H +#define LIVESELECTIONTOOL_H + +#include "abstractliveedittool.h" +#include "liverubberbandselectionmanipulator.h" +#include "livesingleselectionmanipulator.h" +#include "liveselectionindicator.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) +QT_FORWARD_DECLARE_CLASS(QMouseEvent) +QT_FORWARD_DECLARE_CLASS(QKeyEvent) +QT_FORWARD_DECLARE_CLASS(QAction) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class LiveSelectionTool : public AbstractLiveEditTool +{ + Q_OBJECT + +public: + LiveSelectionTool(QDeclarativeViewInspector* editorView); + ~LiveSelectionTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *) {} + void hoverMoveEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *) {} + void wheelEvent(QWheelEvent *event); + + void itemsAboutToRemoved(const QList &) {} +// QVariant itemChange(const QList &itemList, +// QGraphicsItem::GraphicsItemChange change, +// const QVariant &value ); + +// void update(); + + void clear(); + + void selectedItemsChanged(const QList &itemList); + + void selectUnderPoint(QMouseEvent *event); + + void setSelectOnlyContentItems(bool selectOnlyContentItems); + + void setRubberbandSelectionMode(bool value); + +private slots: + void contextMenuElementSelected(); + void contextMenuElementHovered(QAction *action); + void repaintBoundingRects(); + +private: + void createContextMenu(const QList &itemList, QPoint globalPos); + LiveSingleSelectionManipulator::SelectionType getSelectionType(Qt::KeyboardModifiers modifiers); + bool alreadySelected(const QList &itemList) const; + +private: + bool m_rubberbandSelectionMode; + LiveRubberBandSelectionManipulator m_rubberbandSelectionManipulator; + LiveSingleSelectionManipulator m_singleSelectionManipulator; + LiveSelectionIndicator m_selectionIndicator; + //ResizeIndicator m_resizeIndicator; + QTime m_mousePressTimer; + bool m_selectOnlyContentItems; + + QList > m_selectedItemList; + + QList m_contextMenuItemList; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // LIVESELECTIONTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.cpp new file mode 100644 index 0000000000..c07e3fae28 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** 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 "livesingleselectionmanipulator.h" + +#include "qdeclarativeviewinspector_p.h" + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +LiveSingleSelectionManipulator::LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView) + : m_editorView(editorView), + m_isActive(false) +{ +} + + +void LiveSingleSelectionManipulator::begin(const QPointF &beginPoint) +{ + m_beginPoint = beginPoint; + m_isActive = true; + m_oldSelectionList = QDeclarativeViewInspectorPrivate::get(m_editorView)->selectedItems(); +} + +void LiveSingleSelectionManipulator::update(const QPointF &/*updatePoint*/) +{ + m_oldSelectionList.clear(); +} + +void LiveSingleSelectionManipulator::clear() +{ + m_beginPoint = QPointF(); + m_oldSelectionList.clear(); +} + + +void LiveSingleSelectionManipulator::end(const QPointF &/*updatePoint*/) +{ + m_oldSelectionList.clear(); + m_isActive = false; +} + +void LiveSingleSelectionManipulator::select(SelectionType selectionType, + const QList &items, + bool /*selectOnlyContentItems*/) +{ + QGraphicsItem *selectedItem = 0; + + foreach (QGraphicsItem* item, items) + { + //FormEditorItem *formEditorItem = FormEditorItem::fromQGraphicsItem(item); + if (item + /*&& !formEditorItem->qmlItemNode().isRootNode() + && (formEditorItem->qmlItemNode().hasShowContent() || !selectOnlyContentItems)*/) + { + selectedItem = item; + break; + } + } + + QList resultList; + + switch (selectionType) { + case AddToSelection: { + resultList.append(m_oldSelectionList); + if (selectedItem && !m_oldSelectionList.contains(selectedItem)) + resultList.append(selectedItem); + } + break; + case ReplaceSelection: { + if (selectedItem) + resultList.append(selectedItem); + } + break; + case RemoveFromSelection: { + resultList.append(m_oldSelectionList); + if (selectedItem) + resultList.removeAll(selectedItem); + } + break; + case InvertSelection: { + if (selectedItem + && !m_oldSelectionList.contains(selectedItem)) + { + resultList.append(selectedItem); + } + } + } + + m_editorView->setSelectedItems(resultList); +} + +void LiveSingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) +{ + QDeclarativeViewInspectorPrivate *inspectorPrivate = + QDeclarativeViewInspectorPrivate::get(m_editorView); + QList itemList = inspectorPrivate->selectableItems(m_beginPoint); + select(selectionType, itemList, selectOnlyContentItems); +} + + +bool LiveSingleSelectionManipulator::isActive() const +{ + return m_isActive; +} + +QPointF LiveSingleSelectionManipulator::beginPoint() const +{ + return m_beginPoint; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.h b/src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.h new file mode 100644 index 0000000000..80923a06ce --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/livesingleselectionmanipulator.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 LIVESINGLESELECTIONMANIPULATOR_H +#define LIVESINGLESELECTIONMANIPULATOR_H + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QGraphicsItem) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; + +class LiveSingleSelectionManipulator +{ +public: + LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView); + + enum SelectionType { + ReplaceSelection, + AddToSelection, + RemoveFromSelection, + InvertSelection + }; + + void begin(const QPointF& beginPoint); + void update(const QPointF& updatePoint); + void end(const QPointF& updatePoint); + + void select(SelectionType selectionType, const QList &items, + bool selectOnlyContentItems); + void select(SelectionType selectionType, bool selectOnlyContentItems); + + void clear(); + + QPointF beginPoint() const; + + bool isActive() const; + +private: + QList m_oldSelectionList; + QPointF m_beginPoint; + QDeclarativeViewInspector *m_editorView; + bool m_isActive; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // LIVESINGLESELECTIONMANIPULATOR_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.cpp new file mode 100644 index 0000000000..27d252a9ec --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.cpp @@ -0,0 +1,447 @@ +/**************************************************************************** +** +** 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 "qdeclarativeviewinspector.h" +#include "qdeclarativeviewinspector_p.h" + +#include "liveselectiontool.h" +#include "zoomtool.h" +#include "colorpickertool.h" +#include "livelayeritem.h" +#include "boundingrecthighlighter.h" + +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +QDeclarativeViewInspectorPrivate::QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *q) : + q(q) +{ +} + +QDeclarativeViewInspectorPrivate::~QDeclarativeViewInspectorPrivate() +{ +} + +QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view, + QObject *parent) : + AbstractViewInspector(parent), + data(new QDeclarativeViewInspectorPrivate(this)) +{ + 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); + setCurrentTool(data->selectionTool); + + // to capture ChildRemoved event when viewport changes + data->view->installEventFilter(this); + + data->setViewport(data->view->viewport()); + + connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), + data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); + + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + SIGNAL(selectedColorChanged(QColor))); + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + this, SLOT(sendColorChanged(QColor))); + + changeTool(InspectorProtocol::SelectTool); +} + +QDeclarativeViewInspector::~QDeclarativeViewInspector() +{ +} + +void QDeclarativeViewInspector::changeCurrentObjects(const QList &objects) +{ + QList items; + QList gfxObjects; + foreach (QObject *obj, objects) { + if (QDeclarativeItem *declarativeItem = qobject_cast(obj)) { + items << declarativeItem; + gfxObjects << declarativeItem; + } + } + if (designModeBehavior()) { + data->setSelectedItemsForTools(items); + data->clearHighlight(); + data->highlight(gfxObjects); + } +} + +void QDeclarativeViewInspector::reloadView() +{ + 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; + } +} + +Qt::WindowFlags QDeclarativeViewInspector::windowFlags() const +{ + return declarativeView()->window()->windowFlags(); +} + +void QDeclarativeViewInspector::setWindowFlags(Qt::WindowFlags flags) +{ + declarativeView()->window()->setWindowFlags(flags); + declarativeView()->window()->show(); +} + +AbstractLiveEditTool *QDeclarativeViewInspector::currentTool() const +{ + return static_cast(AbstractViewInspector::currentTool()); +} + +QDeclarativeEngine *QDeclarativeViewInspector::declarativeEngine() const +{ + return data->view->engine(); +} + +void QDeclarativeViewInspectorPrivate::setViewport(QWidget *widget) +{ + if (viewport.data() == widget) + return; + + if (viewport) + viewport.data()->removeEventFilter(q); + + viewport = widget; + if (viewport) { + // make sure we get mouse move events + viewport.data()->setMouseTracking(true); + viewport.data()->installEventFilter(q); + } +} + +void QDeclarativeViewInspectorPrivate::clearEditorItems() +{ + clearHighlight(); + setSelectedItems(QList()); +} + +bool QDeclarativeViewInspector::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == data->view) { + // Event from view + if (event->type() == QEvent::ChildRemoved) { + // Might mean that viewport has changed + if (data->view->viewport() != data->viewport.data()) + data->setViewport(data->view->viewport()); + } + return QObject::eventFilter(obj, event); + } + + return AbstractViewInspector::eventFilter(obj, event); +} + +bool QDeclarativeViewInspector::leaveEvent(QEvent *event) +{ + data->clearHighlight(); + return AbstractViewInspector::leaveEvent(event); +} + +bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event) +{ + QList selItems = data->selectableItems(event->pos()); + if (!selItems.isEmpty()) { + declarativeView()->setToolTip(currentTool()->titleForItem(selItems.first())); + } else { + declarativeView()->setToolTip(QString()); + } + + return AbstractViewInspector::mouseMoveEvent(event); +} + +void QDeclarativeViewInspector::reparentQmlObject(QObject *object, QObject *newParent) +{ + if (!newParent) + return; + + object->setParent(newParent); + QDeclarativeItem *newParentItem = qobject_cast(newParent); + QDeclarativeItem *item = qobject_cast(object); + if (newParentItem && item) + item->setParentItem(newParentItem); +} + +void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj) +{ + QList items = selectedItems(); + if (QGraphicsItem *item = qobject_cast(obj)) + items.removeOne(item); + setSelectedItems(items); +} + +void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(const QList &items) +{ + foreach (const QWeakPointer &obj, currentSelection) { + if (QGraphicsItem *item = obj.data()) { + if (!items.contains(item)) { + QObject::disconnect(obj.data(), SIGNAL(destroyed(QObject*)), + this, SLOT(_q_removeFromSelection(QObject*))); + currentSelection.removeOne(obj); + } + } + } + + foreach (QGraphicsItem *item, items) { + if (QGraphicsObject *obj = item->toGraphicsObject()) { + if (!currentSelection.contains(obj)) { + QObject::connect(obj, SIGNAL(destroyed(QObject*)), + this, SLOT(_q_removeFromSelection(QObject*))); + currentSelection.append(obj); + } + } + } + + q->currentTool()->updateSelectedItems(); +} + +void QDeclarativeViewInspectorPrivate::setSelectedItems(const QList &items) +{ + QList > oldList = currentSelection; + setSelectedItemsForTools(items); + if (oldList != currentSelection) { + QList objectList; + foreach (const QWeakPointer &graphicsObject, currentSelection) { + if (graphicsObject) + objectList << graphicsObject.data(); + } + + q->sendCurrentObjects(objectList); + } +} + +QList QDeclarativeViewInspectorPrivate::selectedItems() const +{ + QList selection; + foreach (const QWeakPointer &selectedObject, currentSelection) { + if (selectedObject.data()) + selection << selectedObject.data(); + } + + return selection; +} + +void QDeclarativeViewInspector::setSelectedItems(QList items) +{ + data->setSelectedItems(items); +} + +QList QDeclarativeViewInspector::selectedItems() const +{ + return data->selectedItems(); +} + +QDeclarativeView *QDeclarativeViewInspector::declarativeView() const +{ + return data->view; +} + +void QDeclarativeViewInspectorPrivate::clearHighlight() +{ + boundingRectHighlighter->clear(); +} + +void QDeclarativeViewInspectorPrivate::highlight(const QList &items) +{ + if (items.isEmpty()) + return; + + QList objectList; + foreach (QGraphicsItem *item, items) { + QGraphicsItem *child = item; + + if (child) { + QGraphicsObject *childObject = child->toGraphicsObject(); + if (childObject) + objectList << childObject; + } + } + + boundingRectHighlighter->highlight(objectList); +} + +QList QDeclarativeViewInspectorPrivate::selectableItems( + const QPointF &scenePos) const +{ + QList itemlist = view->scene()->items(scenePos); + return filterForSelection(itemlist); +} + +QList QDeclarativeViewInspectorPrivate::selectableItems(const QPoint &pos) const +{ + QList itemlist = view->items(pos); + return filterForSelection(itemlist); +} + +QList QDeclarativeViewInspectorPrivate::selectableItems( + const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const +{ + QList itemlist = view->scene()->items(sceneRect, selectionMode); + return filterForSelection(itemlist); +} + +void QDeclarativeViewInspectorPrivate::changeToSingleSelectTool() +{ + selectionTool->setRubberbandSelectionMode(false); + + changeToSelectTool(); + + emit q->selectToolActivated(); + q->sendCurrentTool(Constants::SelectionToolMode); +} + +void QDeclarativeViewInspectorPrivate::changeToSelectTool() +{ + if (q->currentTool() == selectionTool) + return; + + q->currentTool()->clear(); + q->setCurrentTool(selectionTool); + q->currentTool()->clear(); + q->currentTool()->updateSelectedItems(); +} + +void QDeclarativeViewInspectorPrivate::changeToMarqueeSelectTool() +{ + changeToSelectTool(); + selectionTool->setRubberbandSelectionMode(true); + + emit q->marqueeSelectToolActivated(); + q->sendCurrentTool(Constants::MarqueeSelectionToolMode); +} + +void QDeclarativeViewInspectorPrivate::changeToZoomTool() +{ + q->currentTool()->clear(); + q->setCurrentTool(zoomTool); + q->currentTool()->clear(); + + emit q->zoomToolActivated(); + q->sendCurrentTool(Constants::ZoomMode); +} + +void QDeclarativeViewInspectorPrivate::changeToColorPickerTool() +{ + if (q->currentTool() == colorPickerTool) + return; + + q->currentTool()->clear(); + q->setCurrentTool(colorPickerTool); + q->currentTool()->clear(); + + emit q->colorPickerActivated(); + q->sendCurrentTool(Constants::ColorPickerMode); +} + + +static bool isEditorItem(QGraphicsItem *item) +{ + return (item->type() == Constants::EditorItemType + || item->type() == Constants::ResizeHandleItemType + || item->data(Constants::EditorItemDataKey).toBool()); +} + +QList QDeclarativeViewInspectorPrivate::filterForSelection( + QList &itemlist) const +{ + foreach (QGraphicsItem *item, itemlist) { + if (isEditorItem(item)) + itemlist.removeOne(item); + } + + return itemlist; +} + +void QDeclarativeViewInspectorPrivate::_q_onStatusChanged(QDeclarativeView::Status status) +{ + if (status == QDeclarativeView::Ready) + q->sendReloaded(); +} + +// adjusts bounding boxes on edges of screen to be visible +QRectF QDeclarativeViewInspector::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace) +{ + int marginFromEdge = 1; + QRectF boundingRect(boundingRectInSceneSpace); + if (qAbs(boundingRect.left()) - 1 < 2) + boundingRect.setLeft(marginFromEdge); + + QRect rect = data->view->rect(); + + if (boundingRect.right() >= rect.right()) + boundingRect.setRight(rect.right() - marginFromEdge); + + if (qAbs(boundingRect.top()) - 1 < 2) + boundingRect.setTop(marginFromEdge); + + if (boundingRect.bottom() >= rect.bottom()) + boundingRect.setBottom(rect.bottom() - marginFromEdge); + + return boundingRect; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.h b/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.h new file mode 100644 index 0000000000..f430aa7b65 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** 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 + +#include "abstractviewinspector.h" + +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class AbstractLiveEditTool; +class QDeclarativeViewInspectorPrivate; + +class QDeclarativeViewInspector : public AbstractViewInspector +{ + Q_OBJECT + +public: + explicit QDeclarativeViewInspector(QDeclarativeView *view, QObject *parent = 0); + ~QDeclarativeViewInspector(); + + // AbstractViewInspector + void changeCurrentObjects(const QList &objects); + void reloadView(); + void reparentQmlObject(QObject *object, QObject *newParent); + void changeTool(InspectorProtocol::Tool tool); + Qt::WindowFlags windowFlags() const; + void setWindowFlags(Qt::WindowFlags flags); + QDeclarativeEngine *declarativeEngine() const; + + void setSelectedItems(QList items); + QList 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 data; + friend class QDeclarativeViewInspectorPrivate; + friend class AbstractLiveEditTool; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector_p.h b/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector_p.h new file mode 100644 index 0000000000..98dc03f84a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/qdeclarativeviewinspector_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** 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_H +#define QDECLARATIVEVIEWINSPECTOR_P_H + +#include "qdeclarativeviewinspector.h" + +#include +#include +#include +#include + +#include "QtDeclarative/private/qdeclarativeinspectorservice_p.h" + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; +class LiveSelectionTool; +class ZoomTool; +class ColorPickerTool; +class LiveLayerItem; +class BoundingRectHighlighter; +class AbstractLiveEditTool; + +class QDeclarativeViewInspectorPrivate : public QObject +{ + Q_OBJECT +public: + QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *); + ~QDeclarativeViewInspectorPrivate(); + + QDeclarativeView *view; + QDeclarativeViewInspector *q; + QWeakPointer viewport; + + QList > currentSelection; + + LiveSelectionTool *selectionTool; + ZoomTool *zoomTool; + ColorPickerTool *colorPickerTool; + LiveLayerItem *manipulatorLayer; + + BoundingRectHighlighter *boundingRectHighlighter; + + void setViewport(QWidget *widget); + + void clearEditorItems(); + void changeToSelectTool(); + QList filterForSelection(QList &itemlist) const; + + QList selectableItems(const QPoint &pos) const; + QList selectableItems(const QPointF &scenePos) const; + QList selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; + + void setSelectedItemsForTools(const QList &items); + void setSelectedItems(const QList &items); + QList selectedItems() const; + + void clearHighlight(); + void highlight(const QList &item); + inline void highlight(QGraphicsObject *item) + { highlight(QList() << item); } + + void changeToSingleSelectTool(); + void changeToMarqueeSelectTool(); + void changeToZoomTool(); + void changeToColorPickerTool(); + +public slots: + void _q_onStatusChanged(QDeclarativeView::Status status); + + void _q_removeFromSelection(QObject *); + +public: + static QDeclarativeViewInspectorPrivate *get(QDeclarativeViewInspector *v) { return v->d_func(); } +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEVIEWINSPECTOR_P_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/qmldbg_qtquick1.pro b/src/plugins/qmltooling/qmldbg_qtquick1/qmldbg_qtquick1.pro new file mode 100644 index 0000000000..1b0229decc --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/qmldbg_qtquick1.pro @@ -0,0 +1,50 @@ +load(qt_module) + +TARGET = qmldbg_qtquick1 +QT += declarative-private core-private gui-private widget-private qtquick1 opengl-private + +load(qt_plugin) + +DESTDIR = $$QT.declarative.plugins/qmltooling + +INCLUDEPATH *= $$PWD $$PWD/../shared + +SOURCES += \ + abstractliveedittool.cpp \ + boundingrecthighlighter.cpp \ + colorpickertool.cpp \ + livelayeritem.cpp \ + liverubberbandselectionmanipulator.cpp \ + liveselectionindicator.cpp \ + liveselectionrectangle.cpp \ + liveselectiontool.cpp \ + livesingleselectionmanipulator.cpp \ + qdeclarativeviewinspector.cpp \ + qtquick1plugin.cpp \ + ../shared/abstracttool.cpp \ + ../shared/abstractviewinspector.cpp \ + subcomponentmasklayeritem.cpp \ + zoomtool.cpp + +HEADERS += \ + abstractliveedittool.h \ + boundingrecthighlighter.h \ + colorpickertool.h \ + livelayeritem.h \ + liverubberbandselectionmanipulator.h \ + liveselectionindicator.h \ + liveselectionrectangle.h \ + liveselectiontool.h \ + livesingleselectionmanipulator.h \ + qdeclarativeviewinspector.h \ + qdeclarativeviewinspector_p.h \ + qtquick1plugin.h \ + ../shared/abstracttool.h \ + ../shared/abstractviewinspector.h \ + ../shared/qdeclarativeinspectorprotocol.h \ + ../shared/qmlinspectorconstants.h \ + subcomponentmasklayeritem.h \ + zoomtool.h + +target.path += $$[QT_INSTALL_PLUGINS]/qmltooling +INSTALLS += target diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.cpp new file mode 100644 index 0000000000..a8ad4074ae --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 "qtquick1plugin.h" +#include "qdeclarativeviewinspector.h" + +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +QtQuick1Plugin::QtQuick1Plugin() : + m_inspector(0) +{ +} + +QtQuick1Plugin::~QtQuick1Plugin() +{ + delete m_inspector; +} + +bool QtQuick1Plugin::canHandleView(QObject *view) +{ + return qobject_cast(view); +} + +void QtQuick1Plugin::activate(QObject *view) +{ + QDeclarativeView *qDeclarativeView = qobject_cast(view); + Q_ASSERT(qDeclarativeView); + m_inspector = new QDeclarativeViewInspector(qDeclarativeView, qDeclarativeView); +} + +void QtQuick1Plugin::deactivate() +{ + delete m_inspector; +} + +void QtQuick1Plugin::clientMessage(const QByteArray &message) +{ + if (m_inspector) + m_inspector->handleMessage(message); +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +Q_EXPORT_PLUGIN2(qmldbg_qtquick1, QmlJSDebugger::QtQuick1::QtQuick1Plugin) diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.h b/src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.h new file mode 100644 index 0000000000..38048740b7 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/qtquick1plugin.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEINSPECTORPLUGIN_H +#define QDECLARATIVEINSPECTORPLUGIN_H + +#include +#include + +namespace QmlJSDebugger { + +class AbstractViewInspector; + +namespace QtQuick1 { + +class QtQuick1Plugin : public QObject, public QDeclarativeInspectorInterface +{ + Q_OBJECT + Q_DISABLE_COPY(QtQuick1Plugin) + Q_INTERFACES(QDeclarativeInspectorInterface) + +public: + QtQuick1Plugin(); + ~QtQuick1Plugin(); + + // QDeclarativeInspectorInterface + bool canHandleView(QObject *view); + void activate(QObject *view); + void deactivate(); + void clientMessage(const QByteArray &message); + +private: + QPointer m_inspector; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEINSPECTORPLUGIN_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.cpp new file mode 100644 index 0000000000..0b1b9f8598 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.cpp @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** 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 "subcomponentmasklayeritem.h" + +#include "qmlinspectorconstants.h" +#include "qdeclarativeviewinspector.h" + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, + QGraphicsItem *parentItem) : + QGraphicsPolygonItem(parentItem), + m_inspector(inspector), + m_currentItem(0), + m_borderRect(new QGraphicsRectItem(this)) +{ + m_borderRect->setRect(0,0,0,0); + m_borderRect->setPen(QPen(QColor(60, 60, 60), 1)); + m_borderRect->setData(Constants::EditorItemDataKey, QVariant(true)); + + setBrush(QBrush(QColor(160,160,160))); + setPen(Qt::NoPen); +} + +int SubcomponentMaskLayerItem::type() const +{ + return Constants::EditorItemType; +} + +static QRectF resizeRect(const QRectF &newRect, const QRectF &oldRect) +{ + QRectF result = newRect; + if (oldRect.left() < newRect.left()) + result.setLeft(oldRect.left()); + + if (oldRect.top() < newRect.top()) + result.setTop(oldRect.top()); + + if (oldRect.right() > newRect.right()) + result.setRight(oldRect.right()); + + if (oldRect.bottom() > newRect.bottom()) + result.setBottom(oldRect.bottom()); + + return result; +} + +static QPolygonF regionToPolygon(const QRegion ®ion) +{ + QPainterPath path; + foreach (const QRect &rect, region.rects()) + path.addRect(rect); + return path.toFillPolygon(); +} + +void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) +{ + QGraphicsItem *prevItem = m_currentItem; + m_currentItem = item; + + if (!m_currentItem) + return; + + QRect viewRect = m_inspector->declarativeView()->rect(); + viewRect = m_inspector->declarativeView()->mapToScene(viewRect).boundingRect().toRect(); + + QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); + itemRect = item->mapRectToScene(itemRect); + + // if updating the same item as before, resize the rectangle only bigger, not smaller. + if (prevItem == item && prevItem != 0) { + m_itemPolyRect = resizeRect(itemRect, m_itemPolyRect); + } else { + m_itemPolyRect = itemRect; + } + QRectF borderRect = m_itemPolyRect; + borderRect.adjust(-1, -1, 1, 1); + m_borderRect->setRect(borderRect); + + const QRegion externalRegion = QRegion(viewRect).subtracted(m_itemPolyRect.toRect()); + setPolygon(regionToPolygon(externalRegion)); +} + +QGraphicsItem *SubcomponentMaskLayerItem::currentItem() const +{ + return m_currentItem; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.h b/src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.h new file mode 100644 index 0000000000..c5f99f0a45 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/subcomponentmasklayeritem.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 SUBCOMPONENTMASKLAYERITEM_H +#define SUBCOMPONENTMASKLAYERITEM_H + +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class QDeclarativeViewInspector; + +class SubcomponentMaskLayerItem : public QGraphicsPolygonItem +{ +public: + explicit SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, + QGraphicsItem *parentItem = 0); + int type() const; + void setCurrentItem(QGraphicsItem *item); + void setBoundingBox(const QRectF &boundingBox); + QGraphicsItem *currentItem() const; + QRectF itemRect() const; + +private: + QDeclarativeViewInspector *m_inspector; + QGraphicsItem *m_currentItem; + QGraphicsRectItem *m_borderRect; + QRectF m_itemPolyRect; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // SUBCOMPONENTMASKLAYERITEM_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.cpp b/src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.cpp new file mode 100644 index 0000000000..daf44e23ec --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.cpp @@ -0,0 +1,330 @@ +/**************************************************************************** +** +** 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 "zoomtool.h" + +#include "qdeclarativeviewinspector_p.h" + +#include +#include +#include +#include +#include + +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick1 { + +ZoomTool::ZoomTool(QDeclarativeViewInspector *view) : + AbstractLiveEditTool(view), + m_rubberbandManipulator(), + m_smoothZoomMultiplier(0.05f), + m_currentScale(1.0f) +{ + m_zoomTo100Action = new QAction(tr("Zoom to &100%"), this); + m_zoomInAction = new QAction(tr("Zoom In"), this); + m_zoomOutAction = new QAction(tr("Zoom Out"), this); + m_zoomInAction->setShortcut(QKeySequence(Qt::Key_Plus)); + m_zoomOutAction->setShortcut(QKeySequence(Qt::Key_Minus)); + + + LiveLayerItem *layerItem = QDeclarativeViewInspectorPrivate::get(view)->manipulatorLayer; + QGraphicsObject *layerObject = reinterpret_cast(layerItem); + m_rubberbandManipulator = new LiveRubberBandSelectionManipulator(layerObject, view); + + + connect(m_zoomTo100Action, SIGNAL(triggered()), SLOT(zoomTo100())); + connect(m_zoomInAction, SIGNAL(triggered()), SLOT(zoomIn())); + connect(m_zoomOutAction, SIGNAL(triggered()), SLOT(zoomOut())); +} + +ZoomTool::~ZoomTool() +{ + delete m_rubberbandManipulator; +} + +void ZoomTool::mousePressEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + + QPointF scenePos = view()->mapToScene(event->pos()); + + if (event->buttons() & Qt::RightButton) { + QMenu contextMenu; + contextMenu.addAction(m_zoomTo100Action); + contextMenu.addSeparator(); + contextMenu.addAction(m_zoomInAction); + contextMenu.addAction(m_zoomOutAction); + contextMenu.exec(event->globalPos()); + } else if (event->buttons() & Qt::LeftButton) { + m_dragBeginPos = scenePos; + m_dragStarted = false; + } +} + +void ZoomTool::mouseMoveEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + + QPointF scenePos = view()->mapToScene(event->pos()); + + if (event->buttons() & Qt::LeftButton + && (QPointF(scenePos - m_dragBeginPos).manhattanLength() + > Constants::DragStartDistance / 3) + && !m_dragStarted) + { + m_dragStarted = true; + m_rubberbandManipulator->begin(m_dragBeginPos); + return; + } + + if (m_dragStarted) + m_rubberbandManipulator->update(scenePos); + +} + +void ZoomTool::mouseReleaseEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); + QPointF scenePos = view()->mapToScene(event->pos()); + + if (m_dragStarted) { + m_rubberbandManipulator->end(); + + int x1 = qMin(scenePos.x(), m_rubberbandManipulator->beginPoint().x()); + int x2 = qMax(scenePos.x(), m_rubberbandManipulator->beginPoint().x()); + int y1 = qMin(scenePos.y(), m_rubberbandManipulator->beginPoint().y()); + int y2 = qMax(scenePos.y(), m_rubberbandManipulator->beginPoint().y()); + + QPointF scenePosTopLeft = QPoint(x1, y1); + QPointF scenePosBottomRight = QPoint(x2, y2); + + QRectF sceneArea(scenePosTopLeft, scenePosBottomRight); + + m_currentScale = qMin(view()->rect().width() / sceneArea.width(), + view()->rect().height() / sceneArea.height()); + + + QTransform transform; + transform.scale(m_currentScale, m_currentScale); + + view()->setTransform(transform); + view()->setSceneRect(sceneArea); + } else { + Qt::KeyboardModifier modifierKey = Qt::ControlModifier; +#ifdef Q_OS_MAC + modifierKey = Qt::AltModifier; +#endif + if (event->modifiers() & modifierKey) { + zoomOut(); + } else { + zoomIn(); + } + } +} + +void ZoomTool::zoomIn() +{ + m_currentScale = nextZoomScale(ZoomIn); + scaleView(view()->mapToScene(m_mousePos)); +} + +void ZoomTool::zoomOut() +{ + m_currentScale = nextZoomScale(ZoomOut); + scaleView(view()->mapToScene(m_mousePos)); +} + +void ZoomTool::mouseDoubleClickEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); +} + + +void ZoomTool::hoverMoveEvent(QMouseEvent *event) +{ + m_mousePos = event->pos(); +} + + +void ZoomTool::keyPressEvent(QKeyEvent * /*event*/) +{ +} + +void ZoomTool::wheelEvent(QWheelEvent *event) +{ + if (event->orientation() != Qt::Vertical) + return; + + Qt::KeyboardModifier smoothZoomModifier = Qt::ControlModifier; + if (event->modifiers() & smoothZoomModifier) { + int numDegrees = event->delta() / 8; + m_currentScale += m_smoothZoomMultiplier * (numDegrees / 15.0f); + + scaleView(view()->mapToScene(m_mousePos)); + + } else if (!event->modifiers()) { + if (event->delta() > 0) { + m_currentScale = nextZoomScale(ZoomIn); + } else if (event->delta() < 0) { + m_currentScale = nextZoomScale(ZoomOut); + } + scaleView(view()->mapToScene(m_mousePos)); + } +} + +void ZoomTool::keyReleaseEvent(QKeyEvent *event) +{ + switch (event->key()) { + case Qt::Key_Plus: + zoomIn(); + break; + case Qt::Key_Minus: + zoomOut(); + break; + case Qt::Key_1: + case Qt::Key_2: + case Qt::Key_3: + case Qt::Key_4: + case Qt::Key_5: + case Qt::Key_6: + case Qt::Key_7: + case Qt::Key_8: + case Qt::Key_9: + { + m_currentScale = ((event->key() - Qt::Key_0) * 1.0f); + scaleView(view()->mapToScene(m_mousePos)); // view()->mapToScene(view()->rect().center()) + break; + } + + default: + break; + } + +} + +void ZoomTool::clear() +{ + view()->setCursor(Qt::ArrowCursor); +} + +void ZoomTool::scaleView(const QPointF ¢erPos) +{ + + QTransform transform; + transform.scale(m_currentScale, m_currentScale); + view()->setTransform(transform); + + QPointF adjustedCenterPos = centerPos; + QSize rectSize(view()->rect().width() / m_currentScale, + view()->rect().height() / m_currentScale); + + QRectF sceneRect; + if (qAbs(m_currentScale - 1.0f) < Constants::ZoomSnapDelta) { + adjustedCenterPos.rx() = rectSize.width() / 2; + adjustedCenterPos.ry() = rectSize.height() / 2; + } + + if (m_currentScale < 1.0f) { + adjustedCenterPos.rx() = rectSize.width() / 2; + adjustedCenterPos.ry() = rectSize.height() / 2; + sceneRect.setRect(view()->rect().width() / 2 -rectSize.width() / 2, + view()->rect().height() / 2 -rectSize.height() / 2, + rectSize.width(), + rectSize.height()); + } else { + sceneRect.setRect(adjustedCenterPos.x() - rectSize.width() / 2, + adjustedCenterPos.y() - rectSize.height() / 2, + rectSize.width(), + rectSize.height()); + } + + view()->setSceneRect(sceneRect); +} + +void ZoomTool::zoomTo100() +{ + m_currentScale = 1.0f; + scaleView(view()->mapToScene(view()->rect().center())); +} + +qreal ZoomTool::nextZoomScale(ZoomDirection direction) const +{ + static QList zoomScales = + QList() + << 0.125f + << 1.0f / 6.0f + << 0.25f + << 1.0f / 3.0f + << 0.5f + << 2.0f / 3.0f + << 1.0f + << 2.0f + << 3.0f + << 4.0f + << 5.0f + << 6.0f + << 7.0f + << 8.0f + << 12.0f + << 16.0f + << 32.0f + << 48.0f; + + if (direction == ZoomIn) { + for (int i = 0; i < zoomScales.length(); ++i) { + if (zoomScales[i] > m_currentScale || i == zoomScales.length() - 1) + return zoomScales[i]; + } + } else { + for (int i = zoomScales.length() - 1; i >= 0; --i) { + if (zoomScales[i] < m_currentScale || i == 0) + return zoomScales[i]; + } + } + + return 1.0f; +} + +} // namespace QtQuick1 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.h b/src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.h new file mode 100644 index 0000000000..bc26aae894 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick1/zoomtool.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 ZOOMTOOL_H +#define ZOOMTOOL_H + +#include "abstractliveedittool.h" +#include "liverubberbandselectionmanipulator.h" + +QT_FORWARD_DECLARE_CLASS(QAction) + +namespace QmlJSDebugger { +namespace QtQuick1 { + +class ZoomTool : public AbstractLiveEditTool +{ + Q_OBJECT + +public: + enum ZoomDirection { + ZoomIn, + ZoomOut + }; + + explicit ZoomTool(QDeclarativeViewInspector *view); + + virtual ~ZoomTool(); + + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + + void hoverMoveEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent *event); + + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *keyEvent); + void itemsAboutToRemoved(const QList &) {} + + void clear(); + +protected: + void selectedItemsChanged(const QList &) {} + +private slots: + void zoomTo100(); + void zoomIn(); + void zoomOut(); + +private: + qreal nextZoomScale(ZoomDirection direction) const; + void scaleView(const QPointF ¢erPos); + +private: + bool m_dragStarted; + QPoint m_mousePos; // in view coords + QPointF m_dragBeginPos; + QAction *m_zoomTo100Action; + QAction *m_zoomInAction; + QAction *m_zoomOutAction; + LiveRubberBandSelectionManipulator *m_rubberbandManipulator; + + qreal m_smoothZoomMultiplier; + qreal m_currentScale; +}; + +} // namespace QtQuick1 +} // namespace QmlJSDebugger + +#endif // ZOOMTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro b/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro new file mode 100644 index 0000000000..a06c1bdc10 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro @@ -0,0 +1,31 @@ +load(qt_module) + +TARGET = qmldbg_qtquick2 +QT += declarative-private core-private gui-private opengl-private v8-private + +load(qt_plugin) + +DESTDIR = $$QT.declarative.plugins/qmltooling + +INCLUDEPATH *= $$PWD $$PWD/../shared + +SOURCES += \ + qtquick2plugin.cpp \ + sghighlight.cpp \ + sgselectiontool.cpp \ + sgviewinspector.cpp \ + ../shared/abstracttool.cpp \ + ../shared/abstractviewinspector.cpp + +HEADERS += \ + qtquick2plugin.h \ + sghighlight.h \ + sgselectiontool.h \ + sgviewinspector.h \ + ../shared/abstracttool.h \ + ../shared/abstractviewinspector.h \ + ../shared/qdeclarativeinspectorprotocol.h \ + ../shared/qmlinspectorconstants.h + +target.path += $$[QT_INSTALL_PLUGINS]/qmltooling +INSTALLS += target diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp new file mode 100644 index 0000000000..5ed919c87c --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 "qtquick2plugin.h" +#include "sgviewinspector.h" + +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +QtQuick2Plugin::QtQuick2Plugin() : + m_inspector(0) +{ +} + +QtQuick2Plugin::~QtQuick2Plugin() +{ + delete m_inspector; +} + +bool QtQuick2Plugin::canHandleView(QObject *view) +{ + return qobject_cast(view); +} + +void QtQuick2Plugin::activate(QObject *view) +{ + QQuickView *qtQuickView = qobject_cast(view); + Q_ASSERT(qtQuickView); + m_inspector = new SGViewInspector(qtQuickView, qtQuickView); +} + +void QtQuick2Plugin::deactivate() +{ + delete m_inspector; +} + +void QtQuick2Plugin::clientMessage(const QByteArray &message) +{ + if (m_inspector) + m_inspector->handleMessage(message); +} + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +Q_EXPORT_PLUGIN2(qmldbg_qtquick2, QmlJSDebugger::QtQuick2::QtQuick2Plugin) diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.h b/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.h new file mode 100644 index 0000000000..89edcad6b7 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEINSPECTORPLUGIN_H +#define QDECLARATIVEINSPECTORPLUGIN_H + +#include +#include + +namespace QmlJSDebugger { + +class AbstractViewInspector; + +namespace QtQuick2 { + +class QtQuick2Plugin : public QObject, public QDeclarativeInspectorInterface +{ + Q_OBJECT + Q_DISABLE_COPY(QtQuick2Plugin) + Q_INTERFACES(QDeclarativeInspectorInterface) + +public: + QtQuick2Plugin(); + ~QtQuick2Plugin(); + + // QDeclarativeInspectorInterface + bool canHandleView(QObject *view); + void activate(QObject *view); + void deactivate(); + void clientMessage(const QByteArray &message); + +private: + QPointer m_inspector; +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEINSPECTORPLUGIN_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp new file mode 100644 index 0000000000..ab254a3fdd --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp @@ -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$ +** +****************************************************************************/ + +#include "sghighlight.h" + +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +SGHighlight::SGHighlight(QQuickItem *item, QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + setItem(item); +} + +void SGHighlight::setItem(QQuickItem *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 QQuickItem *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 QtQuick2 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.h b/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.h new file mode 100644 index 0000000000..8ba1af6576 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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 +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +class SGHighlight : public QQuickPaintedItem +{ + Q_OBJECT + +public: + SGHighlight(QQuickItem *parent) : QQuickPaintedItem(parent) {} + SGHighlight(QQuickItem *item, QQuickItem *parent); + + void setItem(QQuickItem *item); + +private slots: + void adjust(); + +private: + QWeakPointer m_item; +}; + +/** + * A highlight suitable for indicating selection. + */ +class SGSelectionHighlight : public SGHighlight +{ +public: + SGSelectionHighlight(QQuickItem *item, QQuickItem *parent) + : SGHighlight(item, parent) + {} + + void paint(QPainter *painter); +}; + +/** + * A highlight suitable for indicating hover. + */ +class SGHoverHighlight : public SGHighlight +{ +public: + SGHoverHighlight(QQuickItem *parent) + : SGHighlight(parent) + { + setZ(1); // hover highlight on top of selection highlight + } + + void paint(QPainter *painter); +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // SGHIGHLIGHT_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.cpp new file mode 100644 index 0000000000..025aa2d603 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +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 (QQuickItem *item = inspector()->topVisibleItemAt(event->pos())) + inspector()->setSelectedItems(QList() << item); + } else if (event->button() == Qt::RightButton) { + QList items = inspector()->itemsAt(event->pos()); + createContextMenu(items, event->globalPos()); + } +} + +void SGSelectionTool::hoverMoveEvent(QMouseEvent *event) +{ + QQuickItem *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 &items, QPoint pos) +{ + QMenu contextMenu; + connect(&contextMenu, SIGNAL(hovered(QAction*)), + this, SLOT(contextMenuElementHovered(QAction*))); + + const QList selectedItems = inspector()->selectedItems(); + int shortcutKey = Qt::Key_1; + + foreach (QQuickItem *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 (QQuickItem *item = action->data().value()) + m_hoverHighlight->setItem(item); +} + +void SGSelectionTool::contextMenuElementSelected() +{ + if (QQuickItem *item = static_cast(sender())->data().value()) + inspector()->setSelectedItems(QList() << item); +} + +SGViewInspector *SGSelectionTool::inspector() const +{ + return static_cast(AbstractTool::inspector()); +} + +} // namespace QtQuick2 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.h b/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.h new file mode 100644 index 0000000000..fe338bd85a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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 +#include + +QT_FORWARD_DECLARE_CLASS(QAction) +QT_FORWARD_DECLARE_CLASS(QQuickItem) + +namespace QmlJSDebugger { +namespace QtQuick2 { + +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 &items, QPoint pos); + + SGViewInspector *inspector() const; + + SGHoverHighlight *m_hoverHighlight; +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // SGSELECTIONTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.cpp new file mode 100644 index 0000000000..06eb6eac97 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.cpp @@ -0,0 +1,332 @@ +/**************************************************************************** +** +** 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 + +#include +#include + +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +/* + * Collects all the items at the given position, from top to bottom. + */ +static void collectItemsAt(QQuickItem *item, const QPointF &pos, QQuickItem *overlay, + QList &resultList) +{ + if (item == overlay) + return; + + if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return; + } + + QList children = QQuickItemPrivate::get(item)->paintOrderChildItems(); + for (int i = children.count() - 1; i >= 0; --i) { + QQuickItem *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 QQuickItem *itemAt(QQuickItem *item, const QPointF &pos, QQuickItem *overlay) +{ + if (item == overlay) + return 0; + + if (!item->isVisible() || item->opacity() == 0.0) + return 0; + + if (item->flags() & QQuickItem::ItemClipsChildrenToShape) { + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return 0; + } + + QList children = QQuickItemPrivate::get(item)->paintOrderChildItems(); + for (int i = children.count() - 1; i >= 0; --i) { + QQuickItem *child = children.at(i); + if (QQuickItem *betterCandidate = itemAt(child, item->mapToItem(child, pos), overlay)) + return betterCandidate; + } + + if (!(item->flags() & QQuickItem::ItemHasContents)) + return 0; + + if (!QRectF(0, 0, item->width(), item->height()).contains(pos)) + return 0; + + return item; +} + + +SGViewInspector::SGViewInspector(QQuickView *view, QObject *parent) : + AbstractViewInspector(parent), + m_view(view), + m_overlay(new QQuickItem), + m_selectionTool(new SGSelectionTool(this)), + m_designMode(true) +{ + // Try to make sure the overlay is always on top + m_overlay->setZ(FLT_MAX); + + if (QQuickItem *root = view->rootItem()) + m_overlay->setParentItem(root); + + view->installEventFilter(this); + setCurrentTool(m_selectionTool); +} + +void SGViewInspector::changeCurrentObjects(const QList &objects) +{ + QList items; + foreach (QObject *obj, objects) + if (QQuickItem *item = qobject_cast(obj)) + items << item; + + syncSelectedItems(items); +} + +void SGViewInspector::reloadView() +{ + // TODO + emit reloadRequested(); +} + +void SGViewInspector::reparentQmlObject(QObject *object, QObject *newParent) +{ + if (!newParent) + return; + + object->setParent(newParent); + QQuickItem *newParentItem = qobject_cast(newParent); + QQuickItem *item = qobject_cast(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; + } +} + +QWindow *getMasterWindow(QWindow *w) +{ + QWindow *p = w->parent(); + while (p) { + w = p; + p = p->parent(); + } + return w; +} + +Qt::WindowFlags SGViewInspector::windowFlags() const +{ + return getMasterWindow(m_view)->windowFlags(); +} + +void SGViewInspector::setWindowFlags(Qt::WindowFlags flags) +{ + QWindow *w = getMasterWindow(m_view); + w->setWindowFlags(flags); + // make flags are applied + w->setVisible(false); + w->setVisible(true); +} + +QDeclarativeEngine *SGViewInspector::declarativeEngine() const +{ + return m_view->engine(); +} + +QQuickItem *SGViewInspector::topVisibleItemAt(const QPointF &pos) const +{ + QQuickItem *root = m_view->rootItem(); + return itemAt(root, root->mapFromScene(pos), m_overlay); +} + +QList SGViewInspector::itemsAt(const QPointF &pos) const +{ + QQuickItem *root = m_view->rootItem(); + QList resultList; + collectItemsAt(root, root->mapFromScene(pos), m_overlay, resultList); + return resultList; +} + +QList SGViewInspector::selectedItems() const +{ + QList selection; + foreach (const QWeakPointer &selectedItem, m_selectedItems) { + if (selectedItem) + selection << selectedItem.data(); + } + return selection; +} + +void SGViewInspector::setSelectedItems(const QList &items) +{ + if (!syncSelectedItems(items)) + return; + + QList objectList; + foreach (QQuickItem *item, items) + objectList << item; + + sendCurrentObjects(objectList); +} + +bool SGViewInspector::syncSelectedItems(const QList &items) +{ + bool selectionChanged = false; + + // Disconnect and remove items that are no longer selected + foreach (const QWeakPointer &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 (QQuickItem *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 (QQuickItem *item = qobject_cast(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) +{ + // TODO +// if (QQuickItem *item = topVisibleItemAt(event->pos())) +// m_view->setToolTip(titleForItem(item)); +// else +// m_view->setToolTip(QString()); + + return AbstractViewInspector::mouseMoveEvent(event); +} + +QString SGViewInspector::titleForItem(QQuickItem *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("QQuick"))) + className = className.mid(6); + + 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 QtQuick2 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.h b/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.h new file mode 100644 index 0000000000..fa404a538a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSGVIEWINSPECTOR_H +#define QSGVIEWINSPECTOR_H + +#include "abstractviewinspector.h" + +#include +#include + +QT_BEGIN_NAMESPACE +class QQuickView; +class QQuickItem; +QT_END_NAMESPACE + +namespace QmlJSDebugger { +namespace QtQuick2 { + +class SGSelectionTool; +class SGSelectionHighlight; + +class SGViewInspector : public AbstractViewInspector +{ + Q_OBJECT +public: + explicit SGViewInspector(QQuickView *view, QObject *parent = 0); + + // AbstractViewInspector + void changeCurrentObjects(const QList &objects); + void reloadView(); + void reparentQmlObject(QObject *object, QObject *newParent); + void changeTool(InspectorProtocol::Tool tool); + Qt::WindowFlags windowFlags() const; + void setWindowFlags(Qt::WindowFlags flags); + QDeclarativeEngine *declarativeEngine() const; + + QQuickView *view() const { return m_view; } + QQuickItem *overlay() const { return m_overlay; } + + QQuickItem *topVisibleItemAt(const QPointF &pos) const; + QList itemsAt(const QPointF &pos) const; + + QList selectedItems() const; + void setSelectedItems(const QList &items); + + QString titleForItem(QQuickItem *item) const; + +protected: + bool eventFilter(QObject *obj, QEvent *event); + + bool mouseMoveEvent(QMouseEvent *); + +private slots: + void removeFromSelectedItems(QObject *); + +private: + bool syncSelectedItems(const QList &items); + + QQuickView *m_view; + QQuickItem *m_overlay; + + SGSelectionTool *m_selectionTool; + + QList > m_selectedItems; + QHash m_highlightItems; + + bool m_designMode; +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // QSGVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmltooling.pro b/src/plugins/qmltooling/qmltooling.pro index 5b735cb716..d03ee07fc9 100644 --- a/src/plugins/qmltooling/qmltooling.pro +++ b/src/plugins/qmltooling/qmltooling.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = qmldbg_tcp -SUBDIRS += qmldbg_inspector +SUBDIRS = qmldbg_tcp +SUBDIRS += qmldbg_qtquick2 +SUBDIRS += qmldbg_qtquick1 diff --git a/src/plugins/qmltooling/shared/abstracttool.cpp b/src/plugins/qmltooling/shared/abstracttool.cpp new file mode 100644 index 0000000000..39ced2a9d0 --- /dev/null +++ b/src/plugins/qmltooling/shared/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/shared/abstracttool.h b/src/plugins/qmltooling/shared/abstracttool.h new file mode 100644 index 0000000000..0a216bfa83 --- /dev/null +++ b/src/plugins/qmltooling/shared/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 + +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/shared/abstractviewinspector.cpp b/src/plugins/qmltooling/shared/abstractviewinspector.cpp new file mode 100644 index 0000000000..796c4dce67 --- /dev/null +++ b/src/plugins/qmltooling/shared/abstractviewinspector.cpp @@ -0,0 +1,504 @@ +/**************************************************************************** +** +** 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 "qdeclarativeinspectorprotocol.h" + +#include +#include +#include +#include + +#include + +namespace QmlJSDebugger { + + +AbstractViewInspector::AbstractViewInspector(QObject *parent) : + QObject(parent), + m_currentTool(0), + m_showAppOnTop(false), + m_designModeBehavior(false), + m_animationPaused(false), + m_slowDownFactor(1.0), + m_debugService(QDeclarativeInspectorService::instance()) +{ +} + +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; + QUnifiedTimer::instance()->setSlowModeEnabled(effectiveFactor != 1.0); + QUnifiedTimer::instance()->setSlowdownFactor(effectiveFactor); +} + +void AbstractViewInspector::animationPausedChangeRequested(bool paused) +{ + if (m_animationPaused != paused) { + m_animationPaused = paused; + emit animationPausedChanged(paused); + } + + const float effectiveFactor = paused ? 0 : m_slowDownFactor; + QUnifiedTimer::instance()->setSlowModeEnabled(effectiveFactor != 1.0); + QUnifiedTimer::instance()->setSlowdownFactor(effectiveFactor); +} + +void AbstractViewInspector::setShowAppOnTop(bool appOnTop) +{ + Qt::WindowFlags flags = windowFlags(); + if (appOnTop) + flags |= Qt::WindowStaysOnTopHint; + else + flags &= ~Qt::WindowStaysOnTopHint; + + setWindowFlags(flags); + + m_showAppOnTop = appOnTop; + sendShowAppOnTop(appOnTop); + + emit showAppOnTopChanged(appOnTop); +} + +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(event))) + return true; + break; + case QEvent::MouseMove: + if (mouseMoveEvent(static_cast(event))) + return true; + break; + case QEvent::MouseButtonRelease: + if (mouseReleaseEvent(static_cast(event))) + return true; + break; + case QEvent::KeyPress: + if (keyPressEvent(static_cast(event))) + return true; + break; + case QEvent::KeyRelease: + if (keyReleaseEvent(static_cast(event))) + return true; + break; + case QEvent::MouseButtonDblClick: + if (mouseDoubleClickEvent(static_cast(event))) + return true; + break; + case QEvent::Wheel: + if (wheelEvent(static_cast(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 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 &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 diff --git a/src/plugins/qmltooling/shared/abstractviewinspector.h b/src/plugins/qmltooling/shared/abstractviewinspector.h new file mode 100644 index 0000000000..a51efb0b83 --- /dev/null +++ b/src/plugins/qmltooling/shared/abstractviewinspector.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include + +#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; + +/* + * The common code between QQuickView and QDeclarativeView inspectors lives here, + */ +class AbstractViewInspector : public QObject +{ + Q_OBJECT + +public: + explicit AbstractViewInspector(QObject *parent = 0); + + void handleMessage(const QByteArray &message); + + void createQmlObject(const QString &qml, QObject *parent, + const QStringList &importList, + const QString &filename = QString()); + void clearComponentCache(); + + 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 &); + void sendAnimationSpeed(qreal slowDownFactor); + void sendAnimationPaused(bool paused); + void sendCurrentTool(Constants::DesignTool toolId); + void sendReloaded(); + void sendShowAppOnTop(bool showAppOnTop); + + QString idStringForObject(QObject *obj) const; + + virtual void changeCurrentObjects(const QList &objects) = 0; + virtual void reloadView() = 0; + virtual void reparentQmlObject(QObject *object, QObject *newParent) = 0; + virtual void changeTool(InspectorProtocol::Tool tool) = 0; + virtual Qt::WindowFlags windowFlags() const = 0; + virtual void setWindowFlags(Qt::WindowFlags flags) = 0; + virtual QDeclarativeEngine *declarativeEngine() const = 0; + +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: + AbstractTool *currentTool() const { return m_currentTool; } + void setCurrentTool(AbstractTool *tool) { m_currentTool = tool; } + 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); + +private slots: + void sendColorChanged(const QColor &color); + +private: + void sendDesignModeBehavior(bool inDesignMode); + + 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); + + void animationSpeedChangeRequested(qreal factor); + void animationPausedChangeRequested(bool paused); + + AbstractTool *m_currentTool; + + bool m_showAppOnTop; + bool m_designModeBehavior; + + bool m_animationPaused; + qreal m_slowDownFactor; + + QHash m_stringIdForObjectId; + QDeclarativeInspectorService *m_debugService; +}; + +} // namespace QmlJSDebugger + +#endif // ABSTRACTVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/shared/qdeclarativeinspectorprotocol.h b/src/plugins/qmltooling/shared/qdeclarativeinspectorprotocol.h new file mode 100644 index 0000000000..082abeb9bd --- /dev/null +++ b/src/plugins/qmltooling/shared/qdeclarativeinspectorprotocol.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 QDECLARATIVEINSPECTORPROTOCOL_H +#define QDECLARATIVEINSPECTORPROTOCOL_H + +#include +#include +#include +#include + +namespace QmlJSDebugger { + +class InspectorProtocol : public QObject +{ + Q_OBJECT + Q_ENUMS(Message Tool) + +public: + enum Message { + AnimationSpeedChanged = 0, + AnimationPausedChanged = 19, // highest value + ChangeTool = 1, + ClearComponentCache = 2, + ColorChanged = 3, + CreateObject = 5, + CurrentObjectsChanged = 6, + DestroyObject = 7, + MoveObject = 8, + ObjectIdList = 9, + Reload = 10, + Reloaded = 11, + SetAnimationSpeed = 12, + SetAnimationPaused = 18, + SetCurrentObjects = 14, + SetDesignMode = 15, + ShowAppOnTop = 16, + ToolChanged = 17 + }; + + enum Tool { + ColorPickerTool, + SelectMarqueeTool, + SelectTool, + ZoomTool + }; + + static inline QString toString(Message message) + { + return QLatin1String(staticMetaObject.enumerator(0).valueToKey(message)); + } + + static inline QString toString(Tool tool) + { + return QLatin1String(staticMetaObject.enumerator(1).valueToKey(tool)); + } +}; + +inline QDataStream & operator<< (QDataStream &stream, InspectorProtocol::Message message) +{ + return stream << static_cast(message); +} + +inline QDataStream & operator>> (QDataStream &stream, InspectorProtocol::Message &message) +{ + quint32 i; + stream >> i; + message = static_cast(i); + return stream; +} + +inline QDebug operator<< (QDebug dbg, InspectorProtocol::Message message) +{ + dbg << InspectorProtocol::toString(message); + return dbg; +} + +inline QDataStream & operator<< (QDataStream &stream, InspectorProtocol::Tool tool) +{ + return stream << static_cast(tool); +} + +inline QDataStream & operator>> (QDataStream &stream, InspectorProtocol::Tool &tool) +{ + quint32 i; + stream >> i; + tool = static_cast(i); + return stream; +} + +inline QDebug operator<< (QDebug dbg, InspectorProtocol::Tool tool) +{ + dbg << InspectorProtocol::toString(tool); + return dbg; +} + +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEINSPECTORPROTOCOL_H diff --git a/src/plugins/qmltooling/shared/qmlinspectorconstants.h b/src/plugins/qmltooling/shared/qmlinspectorconstants.h new file mode 100644 index 0000000000..5335222865 --- /dev/null +++ b/src/plugins/qmltooling/shared/qmlinspectorconstants.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 QMLINSPECTORCONSTANTS_H +#define QMLINSPECTORCONSTANTS_H + +#include + +namespace QmlJSDebugger { +namespace Constants { + +enum DesignTool { + NoTool = 0, + SelectionToolMode = 1, + MarqueeSelectionToolMode = 2, + MoveToolMode = 3, + ResizeToolMode = 4, + ColorPickerMode = 5, + ZoomMode = 6 +}; + +static const int DragStartTime = 50; + +static const int DragStartDistance = 20; + +static const double ZoomSnapDelta = 0.04; + +static const int EditorItemDataKey = 1000; + +enum GraphicsItemTypes { + EditorItemType = 0xEAAA, + ResizeHandleItemType = 0xEAEA +}; + + +} // namespace Constants +} // namespace QmlJSDebugger + +#endif // QMLINSPECTORCONSTANTS_H -- cgit v1.2.3