editor/toolbarcolorbox.cpp \
abstracttool.cpp \
sgviewinspector.cpp \
- sgselectiontool.cpp
+ sgselectiontool.cpp \
+ sghighlight.cpp
HEADERS += \
abstractviewinspector.h \
editor/toolbarcolorbox.h \
abstracttool.h \
sgviewinspector.h \
- sgselectiontool.h
+ sgselectiontool.h \
+ sghighlight.h
RESOURCES += editor/editor.qrc
--- /dev/null
+/****************************************************************************
+**
+** 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
--- /dev/null
+/****************************************************************************
+**
+** 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
#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()))
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)
#include "sgviewinspector.h"
#include "qdeclarativeinspectorprotocol.h"
+#include "sghighlight.h"
#include "sgselectiontool.h"
#include <QtDeclarative/private/qdeclarativeinspectorservice_p.h>
#include <QtDeclarative/QSGView>
#include <QtDeclarative/QSGItem>
-#include <QtDeclarative/QSGPaintedItem>
#include <QtGui/QMouseEvent>
#include <cfloat>
}
-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),
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;
}
}
-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)
private slots:
void removeFromSelectedItems(QObject *);
- void adjustSelectionHighlight(QSGItem *item = 0);
private:
bool syncSelectedItems(const QList<QSGItem*> &items);