aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2011-06-09 18:15:34 +0200
committerThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>2011-06-23 16:26:11 +0200
commitf5e5eaf9effacc7b29e2c982452cfe8b765955d2 (patch)
tree38f5bae519b7f48e6526f99c27106f428a50f321 /src/plugins
parente045046c694ea98c5f3b651c99e1cb9eed2e045c (diff)
QmlInspector: Implement tool tip handling for SceneGraph
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp48
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp74
-rw-r--r--src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h7
3 files changed, 86 insertions, 43 deletions
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp
index a6c459a038..2d911a88f7 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp
+++ b/src/plugins/qmltooling/qmldbg_inspector/sgselectiontool.cpp
@@ -47,44 +47,9 @@
#include <QtDeclarative/QSGView>
#include <QtDeclarative/QSGItem>
#include <QtDeclarative/QSGPaintedItem>
-#include <QtDeclarative/private/qsgitem_p.h>
namespace QmlJSDebugger {
-/*
- * Returns the first visible item at the given position, or 0 when no such
- * child exists.
- */
-static QSGItem *itemAt(QSGItem *item, const QPointF &pos, QSGItem *overlay)
-{
- if (item == overlay)
- return 0;
-
- if (!item->isVisible() || item->opacity() == 0.0)
- return 0;
-
- if (item->flags() & QSGItem::ItemClipsChildrenToShape) {
- if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
- return 0;
- }
-
- QList<QSGItem *> children = QSGItemPrivate::get(item)->paintOrderChildItems();
- for (int i = children.count() - 1; i >= 0; --i) {
- QSGItem *child = children.at(i);
- if (QSGItem *betterCandidate = itemAt(child, item->mapToItem(child, pos), overlay))
- return betterCandidate;
- }
-
- if (!(item->flags() & QSGItem::ItemHasContents))
- return 0;
-
- if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
- return 0;
-
- return item;
-}
-
-
class SGHoverHighlight : public QSGPaintedItem
{
public:
@@ -117,24 +82,21 @@ void SGSelectionTool::leaveEvent(QEvent *)
void SGSelectionTool::mousePressEvent(QMouseEvent *event)
{
SGViewInspector *sgInspector = static_cast<SGViewInspector*>(inspector());
- QSGItem *root = sgInspector->view()->rootItem();
- QPointF mappedPos = root->mapFromScene(event->pos());
- QSGItem *item = itemAt(root, mappedPos, sgInspector->overlay());
- if (item && item != root)
+ QSGItem *item = sgInspector->topVisibleItemAt(event->pos());
+ if (item)
sgInspector->setSelectedItems(QList<QSGItem*>() << item);
}
void SGSelectionTool::hoverMoveEvent(QMouseEvent *event)
{
SGViewInspector *sgInspector = static_cast<SGViewInspector*>(inspector());
- QSGItem *root = sgInspector->view()->rootItem();
- QPointF mappedPos = root->mapFromScene(event->pos());
- QSGItem *item = itemAt(root, mappedPos, sgInspector->overlay());
- if (!item || item == root) {
+ QSGItem *item = sgInspector->topVisibleItemAt(event->pos());
+ if (!item) {
m_hoverHighlight->setVisible(false);
return;
}
+ QSGItem *root = sgInspector->view()->rootItem();
m_hoverHighlight->setSize(QSizeF(item->width(), item->height()));
m_hoverHighlight->setPos(root->mapFromItem(item->parentItem(), item->pos()));
m_hoverHighlight->setVisible(true);
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp
index 4d79ac6d76..fd9b29bcd5 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp
+++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.cpp
@@ -46,6 +46,7 @@
#include <QtDeclarative/private/qdeclarativeinspectorservice_p.h>
#include <QtDeclarative/private/qdeclarativedebughelper_p.h>
+#include <QtDeclarative/private/qsgitem_p.h>
#include <QtDeclarative/QSGView>
#include <QtDeclarative/QSGItem>
@@ -56,6 +57,40 @@
namespace QmlJSDebugger {
+/*
+ * Returns the first visible item at the given position, or 0 when no such
+ * child exists.
+ */
+static QSGItem *itemAt(QSGItem *item, const QPointF &pos, QSGItem *overlay)
+{
+ if (item == overlay)
+ return 0;
+
+ if (!item->isVisible() || item->opacity() == 0.0)
+ return 0;
+
+ if (item->flags() & QSGItem::ItemClipsChildrenToShape) {
+ if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
+ return 0;
+ }
+
+ QList<QSGItem *> children = QSGItemPrivate::get(item)->paintOrderChildItems();
+ for (int i = children.count() - 1; i >= 0; --i) {
+ QSGItem *child = children.at(i);
+ if (QSGItem *betterCandidate = itemAt(child, item->mapToItem(child, pos), overlay))
+ return betterCandidate;
+ }
+
+ if (!(item->flags() & QSGItem::ItemHasContents))
+ return 0;
+
+ if (!QRectF(0, 0, item->width(), item->height()).contains(pos))
+ return 0;
+
+ return item;
+}
+
+
class SGSelectionHighlight : public QSGPaintedItem
{
public:
@@ -150,6 +185,12 @@ QWidget *SGViewInspector::viewWidget() const
return m_view;
}
+QSGItem *SGViewInspector::topVisibleItemAt(const QPointF &pos)
+{
+ QSGItem *root = m_view->rootItem();
+ return itemAt(root, root->mapFromScene(pos), m_overlay);
+}
+
QList<QSGItem*> SGViewInspector::selectedItems() const
{
QList<QSGItem *> selection;
@@ -236,4 +277,37 @@ bool SGViewInspector::eventFilter(QObject *obj, QEvent *event)
return AbstractViewInspector::eventFilter(obj, event);
}
+bool SGViewInspector::mouseMoveEvent(QMouseEvent *event)
+{
+ if (QSGItem *item = topVisibleItemAt(event->pos()))
+ m_view->setToolTip(titleForItem(item));
+ else
+ m_view->setToolTip(QString());
+
+ return AbstractViewInspector::mouseMoveEvent(event);
+}
+
+QString SGViewInspector::titleForItem(QSGItem *item) const
+{
+ QString className = QLatin1String(item->metaObject()->className());
+ QString objectStringId = idStringForObject(item);
+
+ className.remove(QRegExp(QLatin1String("_QMLTYPE_\\d+")));
+ className.remove(QRegExp(QLatin1String("_QML_\\d+")));
+ if (className.startsWith(QLatin1String("QSG")))
+ className = className.mid(3);
+
+ QString constructedName;
+
+ if (!objectStringId.isEmpty()) {
+ constructedName = objectStringId + QLatin1String(" (") + className + QLatin1Char(')');
+ } else if (!item->objectName().isEmpty()) {
+ constructedName = item->objectName() + QLatin1String(" (") + className + QLatin1Char(')');
+ } else {
+ constructedName = className;
+ }
+
+ return constructedName;
+}
+
} // namespace QmlJSDebugger
diff --git a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h
index a54036d366..8cde72d793 100644
--- a/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h
+++ b/src/plugins/qmltooling/qmldbg_inspector/sgviewinspector.h
@@ -74,11 +74,16 @@ public:
QSGView *view() const { return m_view; }
QSGItem *overlay() const { return m_overlay; }
+ QSGItem *topVisibleItemAt(const QPointF &pos);
+
QList<QSGItem *> selectedItems() const;
void setSelectedItems(const QList<QSGItem*> &items);
+protected:
bool eventFilter(QObject *obj, QEvent *event);
+ bool mouseMoveEvent(QMouseEvent *);
+
private slots:
void removeFromSelectedItems(QObject *);
void adjustSelectionHighlight(QSGItem *item = 0);
@@ -86,6 +91,8 @@ private slots:
private:
bool syncSelectedItems(const QList<QSGItem*> &items);
+ QString titleForItem(QSGItem *item) const;
+
QSGView *m_view;
QSGItem *m_overlay;