diff options
6 files changed, 206 insertions, 64 deletions
diff --git a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro index 355395c294..427a1779e3 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro +++ b/src/plugins/qmltooling/qmldbg_inspector/qmldbg_inspector.pro @@ -27,7 +27,8 @@ SOURCES += \ editor/toolbarcolorbox.cpp \ abstracttool.cpp \ sgviewinspector.cpp \ - sgselectiontool.cpp + sgselectiontool.cpp \ + sghighlight.cpp HEADERS += \ abstractviewinspector.h \ @@ -51,7 +52,8 @@ HEADERS += \ editor/toolbarcolorbox.h \ abstracttool.h \ sgviewinspector.h \ - sgselectiontool.h + sgselectiontool.h \ + sghighlight.h RESOURCES += editor/editor.qrc diff --git a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp new file mode 100644 index 0000000000..4488214a31 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sghighlight.h" + +#include <QtGui/QPainter> + +namespace QmlJSDebugger { + +SGHighlight::SGHighlight(QSGItem *item, QSGItem *parent) + : QSGPaintedItem(parent) +{ + setItem(item); +} + +void SGHighlight::setItem(QSGItem *item) +{ + if (m_item) + m_item.data()->disconnect(this); + + if (item) { + connect(item, SIGNAL(xChanged()), SLOT(adjust())); + connect(item, SIGNAL(yChanged()), SLOT(adjust())); + connect(item, SIGNAL(widthChanged()), SLOT(adjust())); + connect(item, SIGNAL(heightChanged()), SLOT(adjust())); + connect(item, SIGNAL(rotationChanged()), SLOT(adjust())); + connect(item, SIGNAL(transformOriginChanged(TransformOrigin)), + SLOT(adjust())); + } + + m_item = item; + adjust(); +} + +void SGHighlight::adjust() +{ + const QSGItem *item = m_item.data(); + setSize(QSizeF(item->width(), item->height())); + setPos(parentItem()->mapFromItem(item->parentItem(), item->pos())); + setRotation(item->rotation()); + setTransformOrigin(item->transformOrigin()); +} + + +void SGSelectionHighlight::paint(QPainter *painter) +{ + painter->setPen(QColor(108, 141, 221)); + painter->drawRect(QRect(0, 0, width() - 1, height() - 1)); +} + + +void SGHoverHighlight::paint(QPainter *painter) +{ + painter->setPen(QPen(QColor(0, 22, 159))); + painter->drawRect(QRect(1, 1, width() - 3, height() - 3)); + painter->setPen(QColor(158, 199, 255)); + painter->drawRect(QRect(0, 0, width() - 1, height() - 1)); +} + +} // namespace QmlJSDebugger diff --git a/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h new file mode 100644 index 0000000000..f3e8edd442 --- /dev/null +++ b/src/plugins/qmltooling/qmldbg_inspector/sghighlight.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SGHIGHLIGHT_H +#define SGHIGHLIGHT_H + +#include <QtCore/QWeakPointer> +#include <QtDeclarative/QSGPaintedItem> + +namespace QmlJSDebugger { + +class SGHighlight : public QSGPaintedItem +{ + Q_OBJECT + +public: + SGHighlight(QSGItem *parent) : QSGPaintedItem(parent) {} + SGHighlight(QSGItem *item, QSGItem *parent); + + void setItem(QSGItem *item); + +private slots: + void adjust(); + +private: + QWeakPointer<QSGItem> m_item; +}; + +/** + * A highlight suitable for indicating selection. + */ +class SGSelectionHighlight : public SGHighlight +{ +public: + SGSelectionHighlight(QSGItem *item, QSGItem *parent) + : SGHighlight(item, parent) + {} + + void paint(QPainter *painter); +}; + +/** + * A highlight suitable for indicating hover. + */ +class SGHoverHighlight : public SGHighlight +{ +public: + SGHoverHighlight(QSGItem *parent) + : SGHighlight(parent) + { + setZ(1); // hover highlight on top of selection highlight + } + + void paint(QPainter *painter); +}; + +} // namespace QmlJSDebugger + +#endif // SGHIGHLIGHT_H diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp index 7260933b5d..36e2818674 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp @@ -41,41 +41,16 @@ #include "sgselectiontool.h" +#include "sghighlight.h" #include "sgviewinspector.h" #include <QtGui/QMenu> #include <QtGui/QMouseEvent> #include <QtDeclarative/QSGView> #include <QtDeclarative/QSGItem> -#include <QtDeclarative/QSGPaintedItem> namespace QmlJSDebugger { -class SGHoverHighlight : public QSGPaintedItem -{ -public: - SGHoverHighlight(QSGItem *parent) : QSGPaintedItem(parent) - { - setZ(1); // hover highlight on top of selection indicator - } - - void setItem(QSGItem *item) - { - setSize(QSizeF(item->width(), item->height())); - setPos(parentItem()->mapFromItem(item, QPointF())); - setVisible(true); - } - - void 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)); - } -}; - - SGSelectionTool::SGSelectionTool(SGViewInspector *inspector) : AbstractTool(inspector), m_hoverHighlight(new SGHoverHighlight(inspector->overlay())) @@ -101,10 +76,12 @@ void SGSelectionTool::mousePressEvent(QMouseEvent *event) void SGSelectionTool::hoverMoveEvent(QMouseEvent *event) { QSGItem *item = inspector()->topVisibleItemAt(event->pos()); - if (!item) + if (!item) { m_hoverHighlight->setVisible(false); - else + } else { m_hoverHighlight->setItem(item); + m_hoverHighlight->setVisible(true); + } } void SGSelectionTool::createContextMenu(const QList<QSGItem *> &items, QPoint pos) diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp index b1d19182d7..bb9ad52fee 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp +++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp @@ -42,6 +42,7 @@ #include "sgviewinspector.h" #include "qdeclarativeinspectorprotocol.h" +#include "sghighlight.h" #include "sgselectiontool.h" #include <QtDeclarative/private/qdeclarativeinspectorservice_p.h> @@ -50,7 +51,6 @@ #include <QtDeclarative/QSGView> #include <QtDeclarative/QSGItem> -#include <QtDeclarative/QSGPaintedItem> #include <QtGui/QMouseEvent> #include <cfloat> @@ -117,20 +117,6 @@ static QSGItem *itemAt(QSGItem *item, const QPointF &pos, QSGItem *overlay) } -class SGSelectionHighlight : public QSGPaintedItem -{ -public: - SGSelectionHighlight(QSGItem *parent) : QSGPaintedItem(parent) - { } - - void paint(QPainter *painter) - { - painter->setPen(QColor(108, 141, 221)); - painter->drawRect(QRect(0, 0, width() - 1, height() - 1)); - } -}; - - SGViewInspector::SGViewInspector(QSGView *view, QObject *parent) : AbstractViewInspector(parent), m_view(view), @@ -271,14 +257,8 @@ bool SGViewInspector::syncSelectedItems(const QList<QSGItem *> &items) selectionChanged = true; connect(item, SIGNAL(destroyed(QObject*)), this, SLOT(removeFromSelectedItems(QObject*))); - connect(item, SIGNAL(xChanged()), this, SLOT(adjustSelectionHighlight())); - connect(item, SIGNAL(yChanged()), this, SLOT(adjustSelectionHighlight())); - connect(item, SIGNAL(widthChanged()), this, SLOT(adjustSelectionHighlight())); - connect(item, SIGNAL(heightChanged()), this, SLOT(adjustSelectionHighlight())); - connect(item, SIGNAL(rotationChanged()), this, SLOT(adjustSelectionHighlight())); m_selectedItems.append(item); - m_highlightItems.insert(item, new SGSelectionHighlight(m_overlay)); - adjustSelectionHighlight(item); + m_highlightItems.insert(item, new SGSelectionHighlight(item, m_overlay)); } return selectionChanged; @@ -292,17 +272,6 @@ void SGViewInspector::removeFromSelectedItems(QObject *object) } } -void SGViewInspector::adjustSelectionHighlight(QSGItem *item) -{ - if (!item) - item = static_cast<QSGItem*>(sender()); - - SGSelectionHighlight *highlight = m_highlightItems.value(item); - - highlight->setSize(QSizeF(item->width(), item->height())); - highlight->setPos(m_overlay->mapFromItem(item->parentItem(), item->pos())); -} - bool SGViewInspector::eventFilter(QObject *obj, QEvent *event) { if (obj != m_view) diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h index d1f64994ea..14a5bb1872 100644 --- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h +++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h @@ -89,7 +89,6 @@ protected: private slots: void removeFromSelectedItems(QObject *); - void adjustSelectionHighlight(QSGItem *item = 0); private: bool syncSelectedItems(const QList<QSGItem*> &items); |