From 5e9d19cd66c56e8709efe04c896c960ff4f764f1 Mon Sep 17 00:00:00 2001
From: Lasse Holmstedt <lasse.holmstedt@nokia.com>
Date: Thu, 26 Aug 2010 17:11:17 +0200
Subject: [PATCH] QML Observer: Enter context when context menu item is
 selected

Right-clicking on an item in qml observer presents a context menu as
before, but instead of just selecting the item, the user enters its
context if it's possible.
---
 .../qmljsdebugger/editor/abstractformeditortool.cpp   |  6 ++++++
 .../qmljsdebugger/editor/abstractformeditortool.h     |  2 ++
 .../qtcreator/qmljsdebugger/editor/selectiontool.cpp  |  4 +++-
 .../qmljsdebugger/include/qdeclarativedesignview.h    |  1 +
 .../qmljsdebugger/qdeclarativedesignview.cpp          | 11 +++++++++++
 .../qmljsdebugger/qdeclarativedesignview_p.h          |  1 +
 6 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp
index 7d621c1e978..ece0b49637c 100644
--- a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp
+++ b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp
@@ -29,6 +29,7 @@
 
 #include "abstractformeditortool.h"
 #include "qdeclarativedesignview.h"
+#include "qdeclarativedesignview_p.h"
 
 #include <QDeclarativeEngine>
 
@@ -69,6 +70,11 @@ QList<QGraphicsItem*> AbstractFormEditorTool::items() const
     return view()->selectedItems();
 }
 
+void AbstractFormEditorTool::enterContext(QGraphicsItem *itemToEnter)
+{
+    view()->data->enterContext(itemToEnter);
+}
+
 bool AbstractFormEditorTool::topItemIsMovable(const QList<QGraphicsItem*> & itemList)
 {
     QGraphicsItem *firstSelectableItem = topMovableGraphicsItem(itemList);
diff --git a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h
index 2f8f3420f8f..63a3d3eb853 100644
--- a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h
+++ b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h
@@ -76,6 +76,8 @@ public:
     void updateSelectedItems();
     QList<QGraphicsItem*> items() const;
 
+    void enterContext(QGraphicsItem *itemToEnter);
+
     bool topItemIsMovable(const QList<QGraphicsItem*> &itemList);
     bool topItemIsResizeHandle(const QList<QGraphicsItem*> &itemList);
     bool topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList);
diff --git a/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp b/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp
index e64301414ac..dbcadd605bf 100644
--- a/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp
+++ b/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp
@@ -209,11 +209,13 @@ void SelectionTool::contextMenuElementSelected()
     if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) {
 
         QPointF updatePt(0, 0);
+        QGraphicsItem *item = m_contextMenuItemList.at(itemListIndex);
         m_singleSelectionManipulator.begin(updatePt);
         m_singleSelectionManipulator.select(SingleSelectionManipulator::InvertSelection,
-                                            QList<QGraphicsItem*>() << m_contextMenuItemList.at(itemListIndex),
+                                            QList<QGraphicsItem*>() << item,
                                             false);
         m_singleSelectionManipulator.end(updatePt);
+        enterContext(item);
     }
 }
 
diff --git a/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h b/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h
index 8909fda24f8..7ec687c2253 100644
--- a/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h
+++ b/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h
@@ -115,6 +115,7 @@ private:
     inline QDeclarativeDesignViewPrivate *d_func() { return data.data(); }
     QScopedPointer<QDeclarativeDesignViewPrivate> data;
     friend class QDeclarativeDesignViewPrivate;
+    friend class AbstractFormEditorTool;
 
 };
 
diff --git a/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp b/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp
index e5745540e58..90858d068a1 100644
--- a/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp
+++ b/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp
@@ -323,6 +323,7 @@ void QDeclarativeDesignView::mouseDoubleClickEvent(QMouseEvent *event)
     }
 
 }
+
 void QDeclarativeDesignView::wheelEvent(QWheelEvent *event)
 {
     if (!data->designModeBehavior) {
@@ -332,6 +333,16 @@ void QDeclarativeDesignView::wheelEvent(QWheelEvent *event)
     data->currentTool->wheelEvent(event);
 }
 
+void QDeclarativeDesignViewPrivate::enterContext(QGraphicsItem *itemToEnter)
+{
+    QGraphicsItem *itemUnderCurrentContext = itemToEnter;
+    if (itemUnderCurrentContext)
+        itemUnderCurrentContext = subcomponentEditorTool->firstChildOfContext(itemToEnter);
+
+    if (itemUnderCurrentContext)
+        subcomponentEditorTool->setCurrentItem(itemToEnter);
+}
+
 void QDeclarativeDesignView::setDesignModeBehavior(bool value)
 {
     emit designModeBehaviorChanged(value);
diff --git a/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h b/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h
index 0c79810ceec..a3494e9582f 100644
--- a/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h
+++ b/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h
@@ -114,6 +114,7 @@ public:
 
     QGraphicsItem *currentRootItem() const;
 
+    void enterContext(QGraphicsItem *itemToEnter);
 
     void _q_reloadView();
     void _q_onStatusChanged(QDeclarativeView::Status status);
-- 
GitLab