From b899758264bc29ecc80e04d4fbbe1832f01a9a08 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 19 Dec 2011 16:58:31 +0100 Subject: Debugger: Get rid of SG* prefix in qtquick2 plugin Change-Id: Ib8a40d633c169652258480748cfc162593ed9f6c Reviewed-by: Christiaan Janssen --- .../qmltooling/qmldbg_qtquick2/highlight.cpp | 100 +++++++ src/plugins/qmltooling/qmldbg_qtquick2/highlight.h | 99 ++++++ .../qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro | 12 +- .../qmldbg_qtquick2/qquickviewinspector.cpp | 332 +++++++++++++++++++++ .../qmldbg_qtquick2/qquickviewinspector.h | 112 +++++++ .../qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp | 4 +- .../qmltooling/qmldbg_qtquick2/selectiontool.cpp | 92 ++++++ .../qmltooling/qmldbg_qtquick2/selectiontool.h | 86 ++++++ .../qmltooling/qmldbg_qtquick2/sghighlight.cpp | 100 ------- .../qmltooling/qmldbg_qtquick2/sghighlight.h | 99 ------ .../qmltooling/qmldbg_qtquick2/sgselectiontool.cpp | 92 ------ .../qmltooling/qmldbg_qtquick2/sgselectiontool.h | 86 ------ .../qmltooling/qmldbg_qtquick2/sgviewinspector.cpp | 332 --------------------- .../qmltooling/qmldbg_qtquick2/sgviewinspector.h | 112 ------- 14 files changed, 829 insertions(+), 829 deletions(-) create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/highlight.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/highlight.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.cpp create mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.h delete mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.h delete mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.h delete mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.cpp delete mode 100644 src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.h (limited to 'src/plugins') diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/highlight.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/highlight.cpp new file mode 100644 index 0000000000..34b318c377 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/highlight.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 "highlight.h" + +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +Highlight::Highlight(QQuickItem *item, QQuickItem *parent) + : QQuickPaintedItem(parent) +{ + setItem(item); +} + +void Highlight::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 Highlight::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 SelectionHighlight::paint(QPainter *painter) +{ + painter->setPen(QColor(108, 141, 221)); + painter->drawRect(QRect(0, 0, width() - 1, height() - 1)); +} + + +void HoverHighlight::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/highlight.h b/src/plugins/qmltooling/qmldbg_qtquick2/highlight.h new file mode 100644 index 0000000000..c8813c542d --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/highlight.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 HIGHLIGHT_H +#define HIGHLIGHT_H + +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +class Highlight : public QQuickPaintedItem +{ + Q_OBJECT + +public: + Highlight(QQuickItem *parent) : QQuickPaintedItem(parent) {} + Highlight(QQuickItem *item, QQuickItem *parent); + + void setItem(QQuickItem *item); + +private slots: + void adjust(); + +private: + QWeakPointer m_item; +}; + +/** + * A highlight suitable for indicating selection. + */ +class SelectionHighlight : public Highlight +{ +public: + SelectionHighlight(QQuickItem *item, QQuickItem *parent) + : Highlight(item, parent) + {} + + void paint(QPainter *painter); +}; + +/** + * A highlight suitable for indicating hover. + */ +class HoverHighlight : public Highlight +{ +public: + HoverHighlight(QQuickItem *parent) + : Highlight(parent) + { + setZ(1); // hover highlight on top of selection highlight + } + + void paint(QPainter *painter); +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // HIGHLIGHT_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro b/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro index ed6ba4cf29..b9c6584afc 100644 --- a/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qmldbg_qtquick2.pro @@ -11,17 +11,17 @@ INCLUDEPATH *= $$PWD $$PWD/../shared SOURCES += \ qtquick2plugin.cpp \ - sghighlight.cpp \ - sgselectiontool.cpp \ - sgviewinspector.cpp \ + highlight.cpp \ + selectiontool.cpp \ + qquickviewinspector.cpp \ ../shared/abstracttool.cpp \ ../shared/abstractviewinspector.cpp HEADERS += \ qtquick2plugin.h \ - sghighlight.h \ - sgselectiontool.h \ - sgviewinspector.h \ + highlight.h \ + selectiontool.h \ + qquickviewinspector.h \ ../shared/abstracttool.h \ ../shared/abstractviewinspector.h \ ../shared/qdeclarativeinspectorprotocol.h \ diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.cpp new file mode 100644 index 0000000000..083143254f --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.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 "qquickviewinspector.h" + +#include "qdeclarativeinspectorprotocol.h" +#include "highlight.h" +#include "selectiontool.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; +} + + +QQuickViewInspector::QQuickViewInspector(QQuickView *view, QObject *parent) : + AbstractViewInspector(parent), + m_view(view), + m_overlay(new QQuickItem), + m_selectionTool(new SelectionTool(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 QQuickViewInspector::changeCurrentObjects(const QList &objects) +{ + QList items; + foreach (QObject *obj, objects) + if (QQuickItem *item = qobject_cast(obj)) + items << item; + + syncSelectedItems(items); +} + +void QQuickViewInspector::reloadView() +{ + // TODO + emit reloadRequested(); +} + +void QQuickViewInspector::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 QQuickViewInspector::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 QQuickViewInspector::windowFlags() const +{ + return getMasterWindow(m_view)->windowFlags(); +} + +void QQuickViewInspector::setWindowFlags(Qt::WindowFlags flags) +{ + QWindow *w = getMasterWindow(m_view); + w->setWindowFlags(flags); + // make flags are applied + w->setVisible(false); + w->setVisible(true); +} + +QDeclarativeEngine *QQuickViewInspector::declarativeEngine() const +{ + return m_view->engine(); +} + +QQuickItem *QQuickViewInspector::topVisibleItemAt(const QPointF &pos) const +{ + QQuickItem *root = m_view->rootItem(); + return itemAt(root, root->mapFromScene(pos), m_overlay); +} + +QList QQuickViewInspector::itemsAt(const QPointF &pos) const +{ + QQuickItem *root = m_view->rootItem(); + QList resultList; + collectItemsAt(root, root->mapFromScene(pos), m_overlay, resultList); + return resultList; +} + +QList QQuickViewInspector::selectedItems() const +{ + QList selection; + foreach (const QWeakPointer &selectedItem, m_selectedItems) { + if (selectedItem) + selection << selectedItem.data(); + } + return selection; +} + +void QQuickViewInspector::setSelectedItems(const QList &items) +{ + if (!syncSelectedItems(items)) + return; + + QList objectList; + foreach (QQuickItem *item, items) + objectList << item; + + sendCurrentObjects(objectList); +} + +bool QQuickViewInspector::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 SelectionHighlight(item, m_overlay)); + } + + return selectionChanged; +} + +void QQuickViewInspector::removeFromSelectedItems(QObject *object) +{ + if (QQuickItem *item = qobject_cast(object)) { + if (m_selectedItems.removeOne(item)) + delete m_highlightItems.take(item); + } +} + +bool QQuickViewInspector::eventFilter(QObject *obj, QEvent *event) +{ + if (obj != m_view) + return QObject::eventFilter(obj, event); + + return AbstractViewInspector::eventFilter(obj, event); +} + +bool QQuickViewInspector::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 QQuickViewInspector::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/qquickviewinspector.h b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.h new file mode 100644 index 0000000000..94fa4c246a --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qquickviewinspector.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 QQUICKVIEWINSPECTOR_H +#define QQUICKVIEWINSPECTOR_H + +#include "abstractviewinspector.h" + +#include +#include + +QT_BEGIN_NAMESPACE +class QQuickView; +class QQuickItem; +QT_END_NAMESPACE + +namespace QmlJSDebugger { +namespace QtQuick2 { + +class SelectionTool; +class SelectionHighlight; + +class QQuickViewInspector : public AbstractViewInspector +{ + Q_OBJECT +public: + explicit QQuickViewInspector(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; + + SelectionTool *m_selectionTool; + + QList > m_selectedItems; + QHash m_highlightItems; + + bool m_designMode; +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // QQUICKVIEWINSPECTOR_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp index 33b8cc1b4e..2263c8220e 100644 --- a/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp +++ b/src/plugins/qmltooling/qmldbg_qtquick2/qtquick2plugin.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qtquick2plugin.h" -#include "sgviewinspector.h" +#include "qquickviewinspector.h" #include #include @@ -68,7 +68,7 @@ void QtQuick2Plugin::activate(QObject *view) { QQuickView *qtQuickView = qobject_cast(view); Q_ASSERT(qtQuickView); - m_inspector = new SGViewInspector(qtQuickView, qtQuickView); + m_inspector = new QQuickViewInspector(qtQuickView, qtQuickView); } void QtQuick2Plugin::deactivate() diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.cpp new file mode 100644 index 0000000000..ae93e21073 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "selectiontool.h" + +#include "highlight.h" +#include "qquickviewinspector.h" + +#include +#include +#include + +namespace QmlJSDebugger { +namespace QtQuick2 { + +SelectionTool::SelectionTool(QQuickViewInspector *inspector) : + AbstractTool(inspector), + m_hoverHighlight(new HoverHighlight(inspector->overlay())) +{ +} + +void SelectionTool::leaveEvent(QEvent *) +{ + m_hoverHighlight->setVisible(false); +} + +void SelectionTool::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) { + // todo: Show context menu + } +} + +void SelectionTool::hoverMoveEvent(QMouseEvent *event) +{ + QQuickItem *item = inspector()->topVisibleItemAt(event->pos()); + if (!item) { + m_hoverHighlight->setVisible(false); + } else { + m_hoverHighlight->setItem(item); + m_hoverHighlight->setVisible(true); + } +} + +QQuickViewInspector *SelectionTool::inspector() const +{ + return static_cast(AbstractTool::inspector()); +} + +} // namespace QtQuick2 +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.h b/src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.h new file mode 100644 index 0000000000..51752f3eb5 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_qtquick2/selectiontool.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 SELECTIONTOOL_H +#define SELECTIONTOOL_H + +#include "abstracttool.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QQuickItem) + +namespace QmlJSDebugger { +namespace QtQuick2 { + +class QQuickViewInspector; +class HoverHighlight; + +class SelectionTool : public AbstractTool +{ + Q_OBJECT +public: + explicit SelectionTool(QQuickViewInspector *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: + QQuickViewInspector *inspector() const; + + HoverHighlight *m_hoverHighlight; +}; + +} // namespace QtQuick2 +} // namespace QmlJSDebugger + +#endif // SELECTIONTOOL_H diff --git a/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp b/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp deleted file mode 100644 index ab254a3fdd..0000000000 --- a/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.cpp +++ /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$ -** -****************************************************************************/ - -#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 deleted file mode 100644 index d6c380e0d2..0000000000 --- a/src/plugins/qmltooling/qmldbg_qtquick2/sghighlight.h +++ /dev/null @@ -1,99 +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 { -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 deleted file mode 100644 index f96f7d2422..0000000000 --- a/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.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 "sgselectiontool.h" - -#include "sghighlight.h" -#include "sgviewinspector.h" - -#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) { - // todo: Show context menu - } -} - -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); - } -} - -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 deleted file mode 100644 index faf75be47f..0000000000 --- a/src/plugins/qmltooling/qmldbg_qtquick2/sgselectiontool.h +++ /dev/null @@ -1,86 +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(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: - 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 deleted file mode 100644 index a1c2c1a1b2..0000000000 --- a/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.cpp +++ /dev/null @@ -1,332 +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 { -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 deleted file mode 100644 index fa404a538a..0000000000 --- a/src/plugins/qmltooling/qmldbg_qtquick2/sgviewinspector.h +++ /dev/null @@ -1,112 +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 { -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 -- cgit v1.2.3