From 335f6ad0f7f81a2bd928346d30949bee646cebe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Mon, 30 May 2011 16:32:25 +0200 Subject: QmlJSInspector: Renamed Observer to Inspector Manually redid Qt 4.8 commit 206ebd5af21d94c3f3b49d2cb645105a63e6f5fb, to make future code synchronization easier. In order not to have to change the QmlApplicationViewer again, a compatibility class QDeclarativeViewObserver is retained that subclasses QDeclarativeViewInspector. Change-Id: Ief87ae2f8f76b1db0c9d65085e4832424b277603 Reviewed-on: http://codereview.qt.nokia.com/242 Reviewed-by: Qt Sanity Bot Reviewed-by: Kai Koehne --- .../qmljsdebugger/editor/abstractliveedittool.cpp | 20 +- .../qmljsdebugger/editor/abstractliveedittool.h | 8 +- .../editor/boundingrecthighlighter.cpp | 6 +- .../qmljsdebugger/editor/boundingrecthighlighter.h | 6 +- .../qml/qmljsdebugger/editor/colorpickertool.cpp | 4 +- .../qml/qmljsdebugger/editor/colorpickertool.h | 2 +- .../qtcreator/qml/qmljsdebugger/editor/editor.qrc | 4 +- .../editor/images/inspectormode-24.png | Bin 0 -> 1283 bytes .../qmljsdebugger/editor/images/inspectormode.png | Bin 0 -> 3539 bytes .../editor/images/observermode-24.png | Bin 1283 -> 0 bytes .../qmljsdebugger/editor/images/observermode.png | Bin 3539 -> 0 bytes .../qml/qmljsdebugger/editor/livelayeritem.cpp | 2 +- .../editor/liverubberbandselectionmanipulator.cpp | 16 +- .../editor/liverubberbandselectionmanipulator.h | 6 +- .../editor/liveselectionindicator.cpp | 8 +- .../qmljsdebugger/editor/liveselectionindicator.h | 6 +- .../editor/liveselectionrectangle.cpp | 2 +- .../qml/qmljsdebugger/editor/liveselectiontool.cpp | 44 +- .../qml/qmljsdebugger/editor/liveselectiontool.h | 2 +- .../editor/livesingleselectionmanipulator.cpp | 14 +- .../editor/livesingleselectionmanipulator.h | 6 +- .../qml/qmljsdebugger/editor/qmltoolbar.cpp | 4 +- .../qml/qmljsdebugger/editor/qmltoolbar.h | 2 +- .../editor/subcomponentmasklayeritem.cpp | 12 +- .../editor/subcomponentmasklayeritem.h | 6 +- .../qml/qmljsdebugger/editor/toolbarcolorbox.cpp | 2 +- .../qml/qmljsdebugger/editor/zoomtool.cpp | 6 +- .../qtcreator/qml/qmljsdebugger/editor/zoomtool.h | 2 +- .../include/qdeclarativeinspectorservice.h | 105 +++ .../include/qdeclarativeobserverservice.h | 105 --- .../include/qdeclarativeviewinspector.h | 120 +++ .../include/qdeclarativeviewobserver.h | 81 +- .../qmljsdebugger/include/qmlinspectorconstants.h | 71 ++ .../qmljsdebugger/include/qmlobserverconstants.h | 71 -- .../qml/qmljsdebugger/protocol/inspectorprotocol.h | 128 +++ .../qml/qmljsdebugger/protocol/observerprotocol.h | 128 --- .../qml/qmljsdebugger/protocol/protocol.pri | 2 +- .../qmljsdebugger/qdeclarativeinspectorservice.cpp | 286 +++++++ .../qmljsdebugger/qdeclarativeobserverservice.cpp | 286 ------- .../qmljsdebugger/qdeclarativeviewinspector.cpp | 950 +++++++++++++++++++++ .../qmljsdebugger/qdeclarativeviewinspector_p.h | 138 +++ .../qml/qmljsdebugger/qdeclarativeviewobserver.cpp | 950 --------------------- .../qml/qmljsdebugger/qdeclarativeviewobserver_p.h | 138 --- .../qml/qmljsdebugger/qmljsdebugger-src.pri | 11 +- share/qtcreator/qml/qmlobserver/qmlruntime.cpp | 36 +- share/qtcreator/qml/qmlobserver/qmlruntime.h | 4 +- .../qmljsinspector/images/inspectormode.png | Bin 0 -> 3539 bytes src/plugins/qmljsinspector/images/observermode.png | Bin 3539 -> 0 bytes src/plugins/qmljsinspector/qmlinspectortoolbar.cpp | 24 +- src/plugins/qmljsinspector/qmlinspectortoolbar.h | 2 +- src/plugins/qmljsinspector/qmljsclientproxy.cpp | 70 +- src/plugins/qmljsinspector/qmljsclientproxy.h | 4 +- src/plugins/qmljsinspector/qmljsinspector.cpp | 28 +- src/plugins/qmljsinspector/qmljsinspector.h | 4 +- src/plugins/qmljsinspector/qmljsinspector.pro | 4 +- src/plugins/qmljsinspector/qmljsinspector.qrc | 2 +- .../qmljsinspector/qmljsinspectorclient.cpp | 479 +++++++++++ src/plugins/qmljsinspector/qmljsinspectorclient.h | 113 +++ .../qmljsinspector/qmljslivetextpreview.cpp | 18 +- src/plugins/qmljsinspector/qmljslivetextpreview.h | 4 +- src/plugins/qmljsinspector/qmljsobserverclient.cpp | 479 ----------- src/plugins/qmljsinspector/qmljsobserverclient.h | 113 --- 62 files changed, 2599 insertions(+), 2545 deletions(-) create mode 100644 share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode-24.png create mode 100644 share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode.png delete mode 100644 share/qtcreator/qml/qmljsdebugger/editor/images/observermode-24.png delete mode 100644 share/qtcreator/qml/qmljsdebugger/editor/images/observermode.png create mode 100644 share/qtcreator/qml/qmljsdebugger/include/qdeclarativeinspectorservice.h delete mode 100644 share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h create mode 100644 share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewinspector.h create mode 100644 share/qtcreator/qml/qmljsdebugger/include/qmlinspectorconstants.h delete mode 100644 share/qtcreator/qml/qmljsdebugger/include/qmlobserverconstants.h create mode 100644 share/qtcreator/qml/qmljsdebugger/protocol/inspectorprotocol.h delete mode 100644 share/qtcreator/qml/qmljsdebugger/protocol/observerprotocol.h create mode 100644 share/qtcreator/qml/qmljsdebugger/qdeclarativeinspectorservice.cpp delete mode 100644 share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp create mode 100644 share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector.cpp create mode 100644 share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector_p.h delete mode 100644 share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp delete mode 100644 share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h create mode 100644 src/plugins/qmljsinspector/images/inspectormode.png delete mode 100644 src/plugins/qmljsinspector/images/observermode.png create mode 100644 src/plugins/qmljsinspector/qmljsinspectorclient.cpp create mode 100644 src/plugins/qmljsinspector/qmljsinspectorclient.h delete mode 100644 src/plugins/qmljsinspector/qmljsobserverclient.cpp delete mode 100644 src/plugins/qmljsinspector/qmljsobserverclient.h diff --git a/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.cpp b/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.cpp index 0cad361bc6..58afa5a9e2 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.cpp @@ -31,8 +31,8 @@ **************************************************************************/ #include "abstractliveedittool.h" -#include "qdeclarativeviewobserver.h" -#include "../qdeclarativeviewobserver_p.h" +#include "qdeclarativeviewinspector.h" +#include "../qdeclarativeviewinspector_p.h" #include @@ -42,8 +42,8 @@ namespace QmlJSDebugger { -AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewObserver *editorView) - : QObject(editorView), m_observer(editorView) +AbstractLiveEditTool::AbstractLiveEditTool(QDeclarativeViewInspector *editorView) + : QObject(editorView), m_inspector(editorView) { } @@ -52,14 +52,14 @@ AbstractLiveEditTool::~AbstractLiveEditTool() { } -QDeclarativeViewObserver *AbstractLiveEditTool::observer() const +QDeclarativeViewInspector *AbstractLiveEditTool::inspector() const { - return m_observer; + return m_inspector; } QDeclarativeView *AbstractLiveEditTool::view() const { - return m_observer->declarativeView(); + return m_inspector->declarativeView(); } QGraphicsScene* AbstractLiveEditTool::scene() const @@ -74,7 +74,7 @@ void AbstractLiveEditTool::updateSelectedItems() QList AbstractLiveEditTool::items() const { - return observer()->selectedItems(); + return inspector()->selectedItems(); } bool AbstractLiveEditTool::topItemIsMovable(const QList & itemList) @@ -91,7 +91,7 @@ bool AbstractLiveEditTool::topItemIsMovable(const QList & itemLi bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList &itemList) { - QList selectedItems = observer()->selectedItems(); + QList selectedItems = inspector()->selectedItems(); foreach (QGraphicsItem *item, itemList) { QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); @@ -167,7 +167,7 @@ QString AbstractLiveEditTool::titleForItem(QGraphicsItem *item) QDeclarativeItem *declarativeItem = qobject_cast(gfxObject); if (declarativeItem) { - objectStringId = QDeclarativeViewObserver::idStringForObject(declarativeItem); + objectStringId = QDeclarativeViewInspector::idStringForObject(declarativeItem); } if (!objectStringId.isEmpty()) { diff --git a/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.h b/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.h index 66896564f3..8fbfc9af47 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/abstractliveedittool.h @@ -49,7 +49,7 @@ QT_END_NAMESPACE namespace QmlJSDebugger { -class QDeclarativeViewObserver; +class QDeclarativeViewInspector; class FormEditorView; @@ -57,7 +57,7 @@ class AbstractLiveEditTool : public QObject { Q_OBJECT public: - AbstractLiveEditTool(QDeclarativeViewObserver *observer); + AbstractLiveEditTool(QDeclarativeViewInspector *inspector); virtual ~AbstractLiveEditTool(); @@ -93,12 +93,12 @@ public: protected: virtual void selectedItemsChanged(const QList &objectList) = 0; - QDeclarativeViewObserver *observer() const; + QDeclarativeViewInspector *inspector() const; QDeclarativeView *view() const; QGraphicsScene *scene() const; private: - QDeclarativeViewObserver *m_observer; + QDeclarativeViewInspector *m_inspector; QList m_itemList; }; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.cpp b/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.cpp index f174e1826f..0390e95f65 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.cpp @@ -31,8 +31,8 @@ **************************************************************************/ #include "boundingrecthighlighter.h" -#include "qdeclarativeviewobserver.h" -#include "qmlobserverconstants.h" +#include "qdeclarativeviewinspector.h" +#include "qmlinspectorconstants.h" #include @@ -81,7 +81,7 @@ int BoundingBoxPolygonItem::type() const return Constants::EditorItemType; } -BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewObserver *view) : +BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewInspector *view) : LiveLayerItem(view->declarativeView()->scene()), m_view(view), m_animFrame(0) diff --git a/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.h b/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.h index 461ca60c24..6e0e2b2e91 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/boundingrecthighlighter.h @@ -46,14 +46,14 @@ QT_FORWARD_DECLARE_CLASS(QTimer) namespace QmlJSDebugger { -class QDeclarativeViewObserver; +class QDeclarativeViewInspector; class BoundingBox; class BoundingRectHighlighter : public LiveLayerItem { Q_OBJECT public: - explicit BoundingRectHighlighter(QDeclarativeViewObserver *view); + explicit BoundingRectHighlighter(QDeclarativeViewInspector *view); ~BoundingRectHighlighter(); void clear(); void highlight(QList items); @@ -74,7 +74,7 @@ private: private: Q_DISABLE_COPY(BoundingRectHighlighter) - QDeclarativeViewObserver *m_view; + QDeclarativeViewInspector *m_view; QList m_boxes; QList m_freeBoxes; QTimer *m_animTimer; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.cpp b/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.cpp index ada22cc3f7..2ccc2a79d8 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.cpp @@ -31,7 +31,7 @@ **************************************************************************/ #include "colorpickertool.h" -#include "qdeclarativeviewobserver.h" +#include "qdeclarativeviewinspector.h" #include #include @@ -43,7 +43,7 @@ namespace QmlJSDebugger { -ColorPickerTool::ColorPickerTool(QDeclarativeViewObserver *view) : +ColorPickerTool::ColorPickerTool(QDeclarativeViewInspector *view) : AbstractLiveEditTool(view) { m_selectedColor.setRgb(0,0,0); diff --git a/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.h b/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.h index 479bd2ee5e..d176dde093 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/colorpickertool.h @@ -45,7 +45,7 @@ class ColorPickerTool : public AbstractLiveEditTool { Q_OBJECT public: - explicit ColorPickerTool(QDeclarativeViewObserver *view); + explicit ColorPickerTool(QDeclarativeViewInspector *view); virtual ~ColorPickerTool(); diff --git a/share/qtcreator/qml/qmljsdebugger/editor/editor.qrc b/share/qtcreator/qml/qmljsdebugger/editor/editor.qrc index 77744d57bb..fb2393caa1 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/editor.qrc +++ b/share/qtcreator/qml/qmljsdebugger/editor/editor.qrc @@ -18,7 +18,7 @@ images/zoom-24.png images/select-24.png images/select-marquee-24.png - images/observermode.png - images/observermode-24.png + images/inspectormode.png + images/inspectormode-24.png diff --git a/share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode-24.png b/share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode-24.png new file mode 100644 index 0000000000..5e74d867c0 Binary files /dev/null and b/share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode-24.png differ diff --git a/share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode.png b/share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode.png new file mode 100644 index 0000000000..daed21c944 Binary files /dev/null and b/share/qtcreator/qml/qmljsdebugger/editor/images/inspectormode.png differ diff --git a/share/qtcreator/qml/qmljsdebugger/editor/images/observermode-24.png b/share/qtcreator/qml/qmljsdebugger/editor/images/observermode-24.png deleted file mode 100644 index 5e74d867c0..0000000000 Binary files a/share/qtcreator/qml/qmljsdebugger/editor/images/observermode-24.png and /dev/null differ diff --git a/share/qtcreator/qml/qmljsdebugger/editor/images/observermode.png b/share/qtcreator/qml/qmljsdebugger/editor/images/observermode.png deleted file mode 100644 index daed21c944..0000000000 Binary files a/share/qtcreator/qml/qmljsdebugger/editor/images/observermode.png and /dev/null differ diff --git a/share/qtcreator/qml/qmljsdebugger/editor/livelayeritem.cpp b/share/qtcreator/qml/qmljsdebugger/editor/livelayeritem.cpp index cc60449a76..5a8b8e1020 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/livelayeritem.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/livelayeritem.cpp @@ -31,7 +31,7 @@ **************************************************************************/ #include "livelayeritem.h" -#include "qmlobserverconstants.h" +#include "qmlinspectorconstants.h" #include diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.cpp b/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.cpp index 9cf66391ee..b7a8ade5d3 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.cpp @@ -31,7 +31,7 @@ **************************************************************************/ #include "liverubberbandselectionmanipulator.h" -#include "../qdeclarativeviewobserver_p.h" +#include "../qdeclarativeviewinspector_p.h" #include @@ -40,7 +40,7 @@ namespace QmlJSDebugger { LiveRubberBandSelectionManipulator::LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, - QDeclarativeViewObserver *editorView) + QDeclarativeViewInspector *editorView) : m_selectionRectangleElement(layerItem), m_editorView(editorView), m_beginFormEditorItem(0), @@ -73,9 +73,9 @@ void LiveRubberBandSelectionManipulator::begin(const QPointF &beginPoint) m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint); m_selectionRectangleElement.show(); m_isActive = true; - QDeclarativeViewObserverPrivate *observerPrivate - = QDeclarativeViewObserverPrivate::get(m_editorView); - m_beginFormEditorItem = topFormEditorItem(observerPrivate->selectableItems(beginPoint)); + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(m_editorView); + m_beginFormEditorItem = topFormEditorItem(inspectorPrivate->selectableItems(beginPoint)); m_oldSelectionList = m_editorView->selectedItems(); } @@ -93,10 +93,10 @@ void LiveRubberBandSelectionManipulator::end() void LiveRubberBandSelectionManipulator::select(SelectionType selectionType) { - QDeclarativeViewObserverPrivate *observerPrivate - = QDeclarativeViewObserverPrivate::get(m_editorView); + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(m_editorView); QList itemList - = observerPrivate->selectableItems(m_selectionRectangleElement.rect(), + = inspectorPrivate->selectableItems(m_selectionRectangleElement.rect(), Qt::IntersectsItemShape); QList newSelectionList; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.h b/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.h index 056c3ecf7e..052284a409 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/liverubberbandselectionmanipulator.h @@ -42,7 +42,7 @@ QT_FORWARD_DECLARE_CLASS(QGraphicsItem) namespace QmlJSDebugger { -class QDeclarativeViewObserver; +class QDeclarativeViewInspector; class LiveRubberBandSelectionManipulator { @@ -54,7 +54,7 @@ public: }; LiveRubberBandSelectionManipulator(QGraphicsObject *layerItem, - QDeclarativeViewObserver *editorView); + QDeclarativeViewInspector *editorView); void setItems(const QList &itemList); @@ -78,7 +78,7 @@ private: QList m_oldSelectionList; LiveSelectionRectangle m_selectionRectangleElement; QPointF m_beginPoint; - QDeclarativeViewObserver *m_editorView; + QDeclarativeViewInspector *m_editorView; QGraphicsItem *m_beginFormEditorItem; bool m_isActive; }; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.cpp b/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.cpp index e046c23862..fb11850745 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.cpp @@ -31,8 +31,8 @@ **************************************************************************/ #include "liveselectionindicator.h" -#include "../qdeclarativeviewobserver_p.h" -#include "qmlobserverconstants.h" +#include "../qdeclarativeviewinspector_p.h" +#include "qmlinspectorconstants.h" #include #include @@ -41,10 +41,10 @@ namespace QmlJSDebugger { -LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewObserver *viewObserver, +LiveSelectionIndicator::LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, QGraphicsObject *layerItem) : m_layerItem(layerItem) - , m_view(viewObserver) + , m_view(viewInspector) { } diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.h b/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.h index be49a0bcd0..78df3cff4b 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/liveselectionindicator.h @@ -45,12 +45,12 @@ QT_END_NAMESPACE namespace QmlJSDebugger { -class QDeclarativeViewObserver; +class QDeclarativeViewInspector; class LiveSelectionIndicator { public: - LiveSelectionIndicator(QDeclarativeViewObserver *viewObserver, QGraphicsObject *layerItem); + LiveSelectionIndicator(QDeclarativeViewInspector *viewInspector, QGraphicsObject *layerItem); ~LiveSelectionIndicator(); void show(); @@ -63,7 +63,7 @@ public: private: QHash m_indicatorShapeHash; QWeakPointer m_layerItem; - QDeclarativeViewObserver *m_view; + QDeclarativeViewInspector *m_view; }; } diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liveselectionrectangle.cpp b/share/qtcreator/qml/qmljsdebugger/editor/liveselectionrectangle.cpp index 1202557469..98605e627b 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liveselectionrectangle.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/liveselectionrectangle.cpp @@ -31,7 +31,7 @@ **************************************************************************/ #include "liveselectionrectangle.h" -#include "qmlobserverconstants.h" +#include "qmlinspectorconstants.h" #include #include diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.cpp b/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.cpp index 63bb690c51..f9b8902132 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.cpp @@ -33,7 +33,7 @@ #include "liveselectiontool.h" #include "livelayeritem.h" -#include "../qdeclarativeviewobserver_p.h" +#include "../qdeclarativeviewinspector_p.h" #include #include @@ -50,14 +50,14 @@ namespace QmlJSDebugger { -LiveSelectionTool::LiveSelectionTool(QDeclarativeViewObserver *editorView) : +LiveSelectionTool::LiveSelectionTool(QDeclarativeViewInspector *editorView) : AbstractLiveEditTool(editorView), m_rubberbandSelectionMode(false), m_rubberbandSelectionManipulator( - QDeclarativeViewObserverPrivate::get(editorView)->manipulatorLayer, editorView), + QDeclarativeViewInspectorPrivate::get(editorView)->manipulatorLayer, editorView), m_singleSelectionManipulator(editorView), m_selectionIndicator(editorView, - QDeclarativeViewObserverPrivate::get(editorView)->manipulatorLayer), + QDeclarativeViewInspectorPrivate::get(editorView)->manipulatorLayer), //m_resizeIndicator(editorView->manipulatorLayer()), m_selectOnlyContentItems(true) { @@ -88,9 +88,9 @@ LiveSingleSelectionManipulator::SelectionType LiveSelectionTool::getSelectionTyp bool LiveSelectionTool::alreadySelected(const QList &itemList) const { - QDeclarativeViewObserverPrivate *observerPrivate - = QDeclarativeViewObserverPrivate::get(observer()); - const QList selectedItems = observerPrivate->selectedItems(); + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + const QList selectedItems = inspectorPrivate->selectedItems(); if (selectedItems.isEmpty()) return false; @@ -104,9 +104,9 @@ bool LiveSelectionTool::alreadySelected(const QList &itemList) c void LiveSelectionTool::mousePressEvent(QMouseEvent *event) { - QDeclarativeViewObserverPrivate *observerPrivate - = QDeclarativeViewObserverPrivate::get(observer()); - QList itemList = observerPrivate->selectableItems(event->pos()); + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + QList itemList = inspectorPrivate->selectableItems(event->pos()); LiveSingleSelectionManipulator::SelectionType selectionType = getSelectionType(event->modifiers()); if (event->buttons() & Qt::LeftButton) { @@ -142,7 +142,7 @@ void LiveSelectionTool::createContextMenu(QList itemList, QPoint QAction *elementAction = contextMenu.addAction(itemTitle, this, SLOT(contextMenuElementSelected())); - if (observer()->selectedItems().contains(item)) { + if (inspector()->selectedItems().contains(item)) { QFont boldFont = elementAction->font(); boldFont.setBold(true); elementAction->setFont(boldFont); @@ -188,7 +188,7 @@ void LiveSelectionTool::contextMenuElementHovered(QAction *action) int itemListIndex = action->data().toInt(); if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { QGraphicsObject *item = m_contextMenuItemList.at(itemListIndex)->toGraphicsObject(); - QDeclarativeViewObserverPrivate::get(observer())->highlight(item); + QDeclarativeViewInspectorPrivate::get(inspector())->highlight(item); } } @@ -241,19 +241,19 @@ void LiveSelectionTool::hoverMoveEvent(QMouseEvent * event) // if (topSelectedItemIsMovable(itemList)) // view()->changeTool(Constants::MoveToolMode); // } - QDeclarativeViewObserverPrivate *observerPrivate - = QDeclarativeViewObserverPrivate::get(observer()); + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); - QList selectableItemList = observerPrivate->selectableItems(event->pos()); + QList selectableItemList = inspectorPrivate->selectableItems(event->pos()); if (!selectableItemList.isEmpty()) { QGraphicsObject *item = selectableItemList.first()->toGraphicsObject(); if (item) - QDeclarativeViewObserverPrivate::get(observer())->highlight(item); + QDeclarativeViewInspectorPrivate::get(inspector())->highlight(item); return; } - QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); + QDeclarativeViewInspectorPrivate::get(inspector())->clearHighlight(); } void LiveSelectionTool::mouseReleaseEvent(QMouseEvent *event) @@ -324,16 +324,16 @@ void LiveSelectionTool::wheelEvent(QWheelEvent *event) if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) return; - QDeclarativeViewObserverPrivate *observerPrivate - = QDeclarativeViewObserverPrivate::get(observer()); - QList itemList = observerPrivate->selectableItems(event->pos()); + QDeclarativeViewInspectorPrivate *inspectorPrivate + = QDeclarativeViewInspectorPrivate::get(inspector()); + QList itemList = inspectorPrivate->selectableItems(event->pos()); if (itemList.isEmpty()) return; int selectedIdx = 0; - if (!observer()->selectedItems().isEmpty()) { - selectedIdx = itemList.indexOf(observer()->selectedItems().first()); + if (!inspector()->selectedItems().isEmpty()) { + selectedIdx = itemList.indexOf(inspector()->selectedItems().first()); if (selectedIdx >= 0) { if (event->delta() > 0) { selectedIdx++; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.h b/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.h index 4f0002aba4..4f843e4477 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/liveselectiontool.h @@ -54,7 +54,7 @@ class LiveSelectionTool : public AbstractLiveEditTool Q_OBJECT public: - LiveSelectionTool(QDeclarativeViewObserver* editorView); + LiveSelectionTool(QDeclarativeViewInspector* editorView); ~LiveSelectionTool(); void mousePressEvent(QMouseEvent *event); diff --git a/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.cpp b/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.cpp index 1a3fff9c58..bdf8abcb27 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.cpp @@ -31,13 +31,13 @@ **************************************************************************/ #include "livesingleselectionmanipulator.h" -#include "qdeclarativeviewobserver.h" -#include "../qdeclarativeviewobserver_p.h" +#include "qdeclarativeviewinspector.h" +#include "../qdeclarativeviewinspector_p.h" #include namespace QmlJSDebugger { -LiveSingleSelectionManipulator::LiveSingleSelectionManipulator(QDeclarativeViewObserver *editorView) +LiveSingleSelectionManipulator::LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView) : m_editorView(editorView), m_isActive(false) { @@ -48,7 +48,7 @@ void LiveSingleSelectionManipulator::begin(const QPointF &beginPoint) { m_beginPoint = beginPoint; m_isActive = true; - m_oldSelectionList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectedItems(); + m_oldSelectionList = QDeclarativeViewInspectorPrivate::get(m_editorView)->selectedItems(); } void LiveSingleSelectionManipulator::update(const QPointF &/*updatePoint*/) @@ -121,9 +121,9 @@ void LiveSingleSelectionManipulator::select(SelectionType selectionType, void LiveSingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) { - QDeclarativeViewObserverPrivate *observerPrivate = - QDeclarativeViewObserverPrivate::get(m_editorView); - QList itemList = observerPrivate->selectableItems(m_beginPoint); + QDeclarativeViewInspectorPrivate *inspectorPrivate = + QDeclarativeViewInspectorPrivate::get(m_editorView); + QList itemList = inspectorPrivate->selectableItems(m_beginPoint); select(selectionType, itemList, selectOnlyContentItems); } diff --git a/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.h b/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.h index ab1b9c4268..2850e624ed 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/livesingleselectionmanipulator.h @@ -40,12 +40,12 @@ QT_FORWARD_DECLARE_CLASS(QGraphicsItem); namespace QmlJSDebugger { -class QDeclarativeViewObserver; +class QDeclarativeViewInspector; class LiveSingleSelectionManipulator { public: - LiveSingleSelectionManipulator(QDeclarativeViewObserver *editorView); + LiveSingleSelectionManipulator(QDeclarativeViewInspector *editorView); enum SelectionType { ReplaceSelection, @@ -71,7 +71,7 @@ public: private: QList m_oldSelectionList; QPointF m_beginPoint; - QDeclarativeViewObserver *m_editorView; + QDeclarativeViewInspector *m_editorView; bool m_isActive; }; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.cpp b/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.cpp index b1c94221c7..02ec9d1b06 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.cpp @@ -52,8 +52,8 @@ QmlToolBar::QmlToolBar(QWidget *parent) ui->playIcon = QIcon(QLatin1String(":/qml/images/play-24.png")); ui->pauseIcon = QIcon(QLatin1String(":/qml/images/pause-24.png")); - ui->designmode = new QAction(QIcon(QLatin1String(":/qml/images/observermode-24.png")), - tr("Observer Mode"), this); + ui->designmode = new QAction(QIcon(QLatin1String(":/qml/images/inspectormode-24.png")), + tr("Inspector Mode"), this); ui->play = new QAction(ui->pauseIcon, tr("Play/Pause Animations"), this); ui->select = new QAction(QIcon(QLatin1String(":/qml/images/select-24.png")), tr("Select"), this); ui->selectMarquee = new QAction(QIcon(QLatin1String(":/qml/images/select-marquee-24.png")), diff --git a/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.h b/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.h index 81029de4d4..b1bf62f9e9 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/qmltoolbar.h @@ -36,7 +36,7 @@ #include #include -#include "qmlobserverconstants.h" +#include "qmlinspectorconstants.h" QT_FORWARD_DECLARE_CLASS(QActionGroup) diff --git a/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.cpp b/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.cpp index de54329284..33674c0efe 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.cpp @@ -31,16 +31,16 @@ **************************************************************************/ #include "subcomponentmasklayeritem.h" -#include "qmlobserverconstants.h" -#include "qdeclarativeviewobserver.h" +#include "qmlinspectorconstants.h" +#include "qdeclarativeviewinspector.h" #include namespace QmlJSDebugger { -SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer, +SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, QGraphicsItem *parentItem) : QGraphicsPolygonItem(parentItem), - m_observer(observer), + m_inspector(inspector), m_currentItem(0), m_borderRect(new QGraphicsRectItem(this)) { @@ -91,8 +91,8 @@ void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) if (!m_currentItem) return; - QRect viewRect = m_observer->declarativeView()->rect(); - viewRect = m_observer->declarativeView()->mapToScene(viewRect).boundingRect().toRect(); + QRect viewRect = m_inspector->declarativeView()->rect(); + viewRect = m_inspector->declarativeView()->mapToScene(viewRect).boundingRect().toRect(); QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); itemRect = item->mapRectToScene(itemRect); diff --git a/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.h b/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.h index 124e6799f4..02c56a3b19 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/subcomponentmasklayeritem.h @@ -37,12 +37,12 @@ namespace QmlJSDebugger { -class QDeclarativeViewObserver; +class QDeclarativeViewInspector; class SubcomponentMaskLayerItem : public QGraphicsPolygonItem { public: - explicit SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer, + explicit SubcomponentMaskLayerItem(QDeclarativeViewInspector *inspector, QGraphicsItem *parentItem = 0); int type() const; void setCurrentItem(QGraphicsItem *item); @@ -51,7 +51,7 @@ public: QRectF itemRect() const; private: - QDeclarativeViewObserver *m_observer; + QDeclarativeViewInspector *m_inspector; QGraphicsItem *m_currentItem; QGraphicsRectItem *m_borderRect; QRectF m_itemPolyRect; diff --git a/share/qtcreator/qml/qmljsdebugger/editor/toolbarcolorbox.cpp b/share/qtcreator/qml/qmljsdebugger/editor/toolbarcolorbox.cpp index ad76000c74..76c7df7391 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/toolbarcolorbox.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/toolbarcolorbox.cpp @@ -31,7 +31,7 @@ **************************************************************************/ #include "toolbarcolorbox.h" -#include "qmlobserverconstants.h" +#include "qmlinspectorconstants.h" #include #include diff --git a/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.cpp b/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.cpp index 08b67d8377..a2683092b0 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.cpp +++ b/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.cpp @@ -31,7 +31,7 @@ **************************************************************************/ #include "zoomtool.h" -#include "../qdeclarativeviewobserver_p.h" +#include "../qdeclarativeviewinspector_p.h" #include #include @@ -44,7 +44,7 @@ namespace QmlJSDebugger { -ZoomTool::ZoomTool(QDeclarativeViewObserver *view) : +ZoomTool::ZoomTool(QDeclarativeViewInspector *view) : AbstractLiveEditTool(view), m_rubberbandManipulator(), m_smoothZoomMultiplier(0.05f), @@ -57,7 +57,7 @@ ZoomTool::ZoomTool(QDeclarativeViewObserver *view) : m_zoomOutAction->setShortcut(QKeySequence(Qt::Key_Minus)); - LiveLayerItem *layerItem = QDeclarativeViewObserverPrivate::get(view)->manipulatorLayer; + LiveLayerItem *layerItem = QDeclarativeViewInspectorPrivate::get(view)->manipulatorLayer; QGraphicsObject *layerObject = reinterpret_cast(layerItem); m_rubberbandManipulator = new LiveRubberBandSelectionManipulator(layerObject, view); diff --git a/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.h b/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.h index c35ec4aec9..7eb35bdaef 100644 --- a/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.h +++ b/share/qtcreator/qml/qmljsdebugger/editor/zoomtool.h @@ -49,7 +49,7 @@ public: ZoomOut }; - explicit ZoomTool(QDeclarativeViewObserver *view); + explicit ZoomTool(QDeclarativeViewInspector *view); virtual ~ZoomTool(); diff --git a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeinspectorservice.h b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeinspectorservice.h new file mode 100644 index 0000000000..c28f0b50ba --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeinspectorservice.h @@ -0,0 +1,105 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef QDECLARATIVEDESIGNDEBUGSERVER_H +#define QDECLARATIVEDESIGNDEBUGSERVER_H + +#include "qt_private/qdeclarativedebugservice_p.h" +#include "qmlinspectorconstants.h" +#include "qmljsdebugger_global.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QColor) +QT_FORWARD_DECLARE_CLASS(QDeclarativeEngine) +QT_FORWARD_DECLARE_CLASS(QDeclarativeContext) +QT_FORWARD_DECLARE_CLASS(QDeclarativeWatcher) +QT_FORWARD_DECLARE_CLASS(QDataStream) + +namespace QmlJSDebugger { + +class QMLJSDEBUGGER_EXPORT QDeclarativeInspectorService : public QDeclarativeDebugService +{ + Q_OBJECT +public: + QDeclarativeInspectorService(); + static QDeclarativeInspectorService *instance(); + + void setDesignModeBehavior(bool inDesignMode); + void setCurrentObjects(QList items); + void setAnimationSpeed(qreal slowDownFactor); + void setAnimationPaused(bool paused); + void setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId); + void reloaded(); + void setShowAppOnTop(bool showAppOnTop); + + QString idStringForObject(QObject *obj) const; + + void sendMessage(const QByteArray &message); + +public Q_SLOTS: + void selectedColorChanged(const QColor &color); + +Q_SIGNALS: + void debuggingClientChanged(bool hasDebuggingClient); + + void currentObjectsChanged(const QList &objects); + void designModeBehaviorChanged(bool inDesignMode); + void showAppOnTopChanged(bool showAppOnTop); + void reloadRequested(); + void selectToolRequested(); + void selectMarqueeToolRequested(); + void zoomToolRequested(); + void colorPickerToolRequested(); + + void objectCreationRequested(const QString &qml, QObject *parent, + const QStringList &imports, const QString &filename = QString(), int order = -1); + void objectReparentRequested(QObject *object, QObject *newParent); + void objectDeletionRequested(QObject *object); + + // 1 = normal speed, + // 1 < x < 16 = slowdown by some factor + void animationSpeedChangeRequested(qreal speedFactor); + void executionPauseChangeRequested(bool paused); + + void clearComponentCacheRequested(); + +protected: + virtual void statusChanged(Status status); + virtual void messageReceived(const QByteArray &); + +private: + QHash m_stringIdForObjectId; +}; + +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEDESIGNDEBUGSERVER_H diff --git a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h deleted file mode 100644 index 972a362788..0000000000 --- a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeobserverservice.h +++ /dev/null @@ -1,105 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef QDECLARATIVEDESIGNDEBUGSERVER_H -#define QDECLARATIVEDESIGNDEBUGSERVER_H - -#include "qt_private/qdeclarativedebugservice_p.h" -#include "qmlobserverconstants.h" -#include "qmljsdebugger_global.h" - -#include - -QT_FORWARD_DECLARE_CLASS(QColor) -QT_FORWARD_DECLARE_CLASS(QDeclarativeEngine) -QT_FORWARD_DECLARE_CLASS(QDeclarativeContext) -QT_FORWARD_DECLARE_CLASS(QDeclarativeWatcher) -QT_FORWARD_DECLARE_CLASS(QDataStream) - -namespace QmlJSDebugger { - -class QMLJSDEBUGGER_EXPORT QDeclarativeObserverService : public QDeclarativeDebugService -{ - Q_OBJECT -public: - QDeclarativeObserverService(); - static QDeclarativeObserverService *instance(); - - void setDesignModeBehavior(bool inDesignMode); - void setCurrentObjects(QList items); - void setAnimationSpeed(qreal slowDownFactor); - void setAnimationPaused(bool paused); - void setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId); - void reloaded(); - void setShowAppOnTop(bool showAppOnTop); - - QString idStringForObject(QObject *obj) const; - - void sendMessage(const QByteArray &message); - -public Q_SLOTS: - void selectedColorChanged(const QColor &color); - -Q_SIGNALS: - void debuggingClientChanged(bool hasDebuggingClient); - - void currentObjectsChanged(const QList &objects); - void designModeBehaviorChanged(bool inDesignMode); - void showAppOnTopChanged(bool showAppOnTop); - void reloadRequested(); - void selectToolRequested(); - void selectMarqueeToolRequested(); - void zoomToolRequested(); - void colorPickerToolRequested(); - - void objectCreationRequested(const QString &qml, QObject *parent, - const QStringList &imports, const QString &filename = QString(), int order = -1); - void objectReparentRequested(QObject *object, QObject *newParent); - void objectDeletionRequested(QObject *object); - - // 1 = normal speed, - // 1 < x < 16 = slowdown by some factor - void animationSpeedChangeRequested(qreal speedFactor); - void executionPauseChangeRequested(bool paused); - - void clearComponentCacheRequested(); - -protected: - virtual void statusChanged(Status status); - virtual void messageReceived(const QByteArray &); - -private: - QHash m_stringIdForObjectId; -}; - -} // namespace QmlJSDebugger - -#endif // QDECLARATIVEDESIGNDEBUGSERVER_H diff --git a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewinspector.h b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewinspector.h new file mode 100644 index 0000000000..6ba0427187 --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewinspector.h @@ -0,0 +1,120 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef QDECLARATIVEVIEWINSPECTOR_H +#define QDECLARATIVEVIEWINSPECTOR_H + +#include "qmljsdebugger_global.h" +#include "qmlinspectorconstants.h" + +#include +#include + +QT_FORWARD_DECLARE_CLASS(QDeclarativeItem) +QT_FORWARD_DECLARE_CLASS(QMouseEvent) +QT_FORWARD_DECLARE_CLASS(QToolBar) + +namespace QmlJSDebugger { + +class CrumblePath; +class QDeclarativeViewInspectorPrivate; + +class QMLJSDEBUGGER_EXPORT QDeclarativeViewInspector : public QObject +{ + Q_OBJECT +public: + + explicit QDeclarativeViewInspector(QDeclarativeView *view, QObject *parent = 0); + ~QDeclarativeViewInspector(); + + void setSelectedItems(QList items); + QList selectedItems(); + + QDeclarativeView *declarativeView(); + + static QString idStringForObject(QObject *obj); + QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); + + bool showAppOnTop() const; + +public Q_SLOTS: + void setDesignModeBehavior(bool value); + bool designModeBehavior(); + + void setShowAppOnTop(bool appOnTop); + + void setAnimationSpeed(qreal factor); + void setAnimationPaused(bool paused); + +Q_SIGNALS: + void designModeBehaviorChanged(bool inDesignMode); + void showAppOnTopChanged(bool showAppOnTop); + void reloadRequested(); + void marqueeSelectToolActivated(); + void selectToolActivated(); + void zoomToolActivated(); + void colorPickerActivated(); + void selectedColorChanged(const QColor &color); + + void animationSpeedChanged(qreal factor); + void animationPausedChanged(bool paused); + +protected: + bool eventFilter(QObject *obj, QEvent *event); + + bool leaveEvent(QEvent *); + bool mousePressEvent(QMouseEvent *event); + bool mouseMoveEvent(QMouseEvent *event); + bool mouseReleaseEvent(QMouseEvent *event); + bool keyPressEvent(QKeyEvent *event); + bool keyReleaseEvent(QKeyEvent *keyEvent); + bool mouseDoubleClickEvent(QMouseEvent *event); + bool wheelEvent(QWheelEvent *event); + + void setSelectedItemsForTools(QList items); + +private slots: + void animationSpeedChangeRequested(qreal factor); + void animationPausedChangeRequested(bool paused); + +private: + Q_DISABLE_COPY(QDeclarativeViewInspector) + + inline QDeclarativeViewInspectorPrivate *d_func() { return data.data(); } + QScopedPointer data; + friend class QDeclarativeViewInspectorPrivate; + friend class AbstractLiveEditTool; +}; + +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEVIEWINSPECTOR_H diff --git a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewobserver.h b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewobserver.h index 2accbfa700..7621a9e8d7 100644 --- a/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewobserver.h +++ b/share/qtcreator/qml/qmljsdebugger/include/qdeclarativeviewobserver.h @@ -33,86 +33,19 @@ #ifndef QDECLARATIVEVIEWOBSERVER_H #define QDECLARATIVEVIEWOBSERVER_H -#include "qmljsdebugger_global.h" -#include "qmlobserverconstants.h" - -#include -#include - -QT_FORWARD_DECLARE_CLASS(QDeclarativeItem) -QT_FORWARD_DECLARE_CLASS(QMouseEvent) -QT_FORWARD_DECLARE_CLASS(QToolBar) +#include "qdeclarativeviewinspector.h" namespace QmlJSDebugger { -class CrumblePath; -class QDeclarativeViewObserverPrivate; - -class QMLJSDEBUGGER_EXPORT QDeclarativeViewObserver : public QObject +// Provided for compatibility with QmlApplicationViewer +class QMLJSDEBUGGER_EXPORT QDeclarativeViewObserver : public QDeclarativeViewInspector { Q_OBJECT -public: - - explicit QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent = 0); - ~QDeclarativeViewObserver(); - - void setSelectedItems(QList items); - QList selectedItems(); - - QDeclarativeView *declarativeView(); - - static QString idStringForObject(QObject *obj); - QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); - - bool showAppOnTop() const; - -public Q_SLOTS: - void setDesignModeBehavior(bool value); - bool designModeBehavior(); - void setShowAppOnTop(bool appOnTop); - - void setAnimationSpeed(qreal factor); - void setAnimationPaused(bool paused); - -Q_SIGNALS: - void designModeBehaviorChanged(bool inDesignMode); - void showAppOnTopChanged(bool showAppOnTop); - void reloadRequested(); - void marqueeSelectToolActivated(); - void selectToolActivated(); - void zoomToolActivated(); - void colorPickerActivated(); - void selectedColorChanged(const QColor &color); - - void animationSpeedChanged(qreal factor); - void animationPausedChanged(bool paused); - -protected: - bool eventFilter(QObject *obj, QEvent *event); - - bool leaveEvent(QEvent *); - bool mousePressEvent(QMouseEvent *event); - bool mouseMoveEvent(QMouseEvent *event); - bool mouseReleaseEvent(QMouseEvent *event); - bool keyPressEvent(QKeyEvent *event); - bool keyReleaseEvent(QKeyEvent *keyEvent); - bool mouseDoubleClickEvent(QMouseEvent *event); - bool wheelEvent(QWheelEvent *event); - - void setSelectedItemsForTools(QList items); - -private slots: - void animationSpeedChangeRequested(qreal factor); - void animationPausedChangeRequested(bool paused); - -private: - Q_DISABLE_COPY(QDeclarativeViewObserver) - - inline QDeclarativeViewObserverPrivate *d_func() { return data.data(); } - QScopedPointer data; - friend class QDeclarativeViewObserverPrivate; - friend class AbstractLiveEditTool; +public: + explicit QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent = 0) + : QDeclarativeViewInspector(view, parent) + {} }; } // namespace QmlJSDebugger diff --git a/share/qtcreator/qml/qmljsdebugger/include/qmlinspectorconstants.h b/share/qtcreator/qml/qmljsdebugger/include/qmlinspectorconstants.h new file mode 100644 index 0000000000..eb5ac317e8 --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/include/qmlinspectorconstants.h @@ -0,0 +1,71 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef QMLINSPECTORCONSTANTS_H +#define QMLINSPECTORCONSTANTS_H + +namespace QmlJSDebugger { +namespace Constants { + +enum DesignTool { + NoTool = 0, + SelectionToolMode = 1, + MarqueeSelectionToolMode = 2, + MoveToolMode = 3, + ResizeToolMode = 4, + ColorPickerMode = 5, + ZoomMode = 6 +}; + +enum ToolFlags { + NoToolFlags = 0, + UseCursorPos = 1 +}; + +static const int DragStartTime = 50; + +static const int DragStartDistance = 20; + +static const double ZoomSnapDelta = 0.04; + +static const int EditorItemDataKey = 1000; + +enum GraphicsItemTypes { + EditorItemType = 0xEAAA, + ResizeHandleItemType = 0xEAEA +}; + + +} // namespace Constants +} // namespace QmlJSDebugger + +#endif // QMLINSPECTORCONSTANTS_H diff --git a/share/qtcreator/qml/qmljsdebugger/include/qmlobserverconstants.h b/share/qtcreator/qml/qmljsdebugger/include/qmlobserverconstants.h deleted file mode 100644 index 30aefdf1f6..0000000000 --- a/share/qtcreator/qml/qmljsdebugger/include/qmlobserverconstants.h +++ /dev/null @@ -1,71 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef QMLOBSERVERCONSTANTS_H -#define QMLOBSERVERCONSTANTS_H - -namespace QmlJSDebugger { -namespace Constants { - -enum DesignTool { - NoTool = 0, - SelectionToolMode = 1, - MarqueeSelectionToolMode = 2, - MoveToolMode = 3, - ResizeToolMode = 4, - ColorPickerMode = 5, - ZoomMode = 6 -}; - -enum ToolFlags { - NoToolFlags = 0, - UseCursorPos = 1 -}; - -static const int DragStartTime = 50; - -static const int DragStartDistance = 20; - -static const double ZoomSnapDelta = 0.04; - -static const int EditorItemDataKey = 1000; - -enum GraphicsItemTypes { - EditorItemType = 0xEAAA, - ResizeHandleItemType = 0xEAEA -}; - - -} // namespace Constants -} // namespace QmlJSDebugger - -#endif // QMLOBSERVERCONSTANTS_H diff --git a/share/qtcreator/qml/qmljsdebugger/protocol/inspectorprotocol.h b/share/qtcreator/qml/qmljsdebugger/protocol/inspectorprotocol.h new file mode 100644 index 0000000000..b80c5e49d8 --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/protocol/inspectorprotocol.h @@ -0,0 +1,128 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#ifndef INSPECTORPROTOCOL_H +#define INSPECTORPROTOCOL_H + +#include +#include +#include +#include + +namespace QmlJSDebugger { + +class InspectorProtocol : public QObject +{ + Q_OBJECT + Q_ENUMS(Message Tool) + +public: + enum Message { + AnimationSpeedChanged = 0, + AnimationPausedChanged = 19, // highest value + ChangeTool = 1, + ClearComponentCache = 2, + ColorChanged = 3, + CreateObject = 5, + CurrentObjectsChanged = 6, + DestroyObject = 7, + MoveObject = 8, + ObjectIdList = 9, + Reload = 10, + Reloaded = 11, + SetAnimationSpeed = 12, + SetAnimationPaused = 18, + SetCurrentObjects = 14, + SetDesignMode = 15, + ShowAppOnTop = 16, + ToolChanged = 17 + }; + + enum Tool { + ColorPickerTool, + SelectMarqueeTool, + SelectTool, + ZoomTool + }; + + static inline QString toString(Message message) + { + return staticMetaObject.enumerator(0).valueToKey(message); + } + + static inline QString toString(Tool tool) + { + return staticMetaObject.enumerator(1).valueToKey(tool); + } +}; + +inline QDataStream & operator<< (QDataStream &stream, InspectorProtocol::Message message) +{ + return stream << static_cast(message); +} + +inline QDataStream & operator>> (QDataStream &stream, InspectorProtocol::Message &message) +{ + quint32 i; + stream >> i; + message = static_cast(i); + return stream; +} + +inline QDebug operator<< (QDebug dbg, InspectorProtocol::Message message) +{ + dbg << InspectorProtocol::toString(message); + return dbg; +} + +inline QDataStream & operator<< (QDataStream &stream, InspectorProtocol::Tool tool) +{ + return stream << static_cast(tool); +} + +inline QDataStream & operator>> (QDataStream &stream, InspectorProtocol::Tool &tool) +{ + quint32 i; + stream >> i; + tool = static_cast(i); + return stream; +} + +inline QDebug operator<< (QDebug dbg, InspectorProtocol::Tool tool) +{ + dbg << InspectorProtocol::toString(tool); + return dbg; +} + +} // namespace QmlJSDebugger + +#endif // INSPECTORPROTOCOL_H diff --git a/share/qtcreator/qml/qmljsdebugger/protocol/observerprotocol.h b/share/qtcreator/qml/qmljsdebugger/protocol/observerprotocol.h deleted file mode 100644 index 828a3f232c..0000000000 --- a/share/qtcreator/qml/qmljsdebugger/protocol/observerprotocol.h +++ /dev/null @@ -1,128 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#ifndef OBSERVERPROTOCOL_H -#define OBSERVERPROTOCOL_H - -#include -#include -#include -#include - -namespace QmlJSDebugger { - -class ObserverProtocol : public QObject -{ - Q_OBJECT - Q_ENUMS(Message Tool) - -public: - enum Message { - AnimationSpeedChanged = 0, - AnimationPausedChanged = 19, // highest value - ChangeTool = 1, - ClearComponentCache = 2, - ColorChanged = 3, - CreateObject = 5, - CurrentObjectsChanged = 6, - DestroyObject = 7, - MoveObject = 8, - ObjectIdList = 9, - Reload = 10, - Reloaded = 11, - SetAnimationSpeed = 12, - SetAnimationPaused = 18, - SetCurrentObjects = 14, - SetDesignMode = 15, - ShowAppOnTop = 16, - ToolChanged = 17 - }; - - enum Tool { - ColorPickerTool, - SelectMarqueeTool, - SelectTool, - ZoomTool - }; - - static inline QString toString(Message message) - { - return staticMetaObject.enumerator(0).valueToKey(message); - } - - static inline QString toString(Tool tool) - { - return staticMetaObject.enumerator(1).valueToKey(tool); - } -}; - -inline QDataStream & operator<< (QDataStream &stream, ObserverProtocol::Message message) -{ - return stream << static_cast(message); -} - -inline QDataStream & operator>> (QDataStream &stream, ObserverProtocol::Message &message) -{ - quint32 i; - stream >> i; - message = static_cast(i); - return stream; -} - -inline QDebug operator<< (QDebug dbg, ObserverProtocol::Message message) -{ - dbg << ObserverProtocol::toString(message); - return dbg; -} - -inline QDataStream & operator<< (QDataStream &stream, ObserverProtocol::Tool tool) -{ - return stream << static_cast(tool); -} - -inline QDataStream & operator>> (QDataStream &stream, ObserverProtocol::Tool &tool) -{ - quint32 i; - stream >> i; - tool = static_cast(i); - return stream; -} - -inline QDebug operator<< (QDebug dbg, ObserverProtocol::Tool tool) -{ - dbg << ObserverProtocol::toString(tool); - return dbg; -} - -} // namespace QmlJSDebugger - -#endif // OBSERVERPROTOCOL_H diff --git a/share/qtcreator/qml/qmljsdebugger/protocol/protocol.pri b/share/qtcreator/qml/qmljsdebugger/protocol/protocol.pri index 9db20ff863..dfb18fb864 100644 --- a/share/qtcreator/qml/qmljsdebugger/protocol/protocol.pri +++ b/share/qtcreator/qml/qmljsdebugger/protocol/protocol.pri @@ -1,3 +1,3 @@ INCLUDEPATH += $$PWD DEPENDPATH += $$PWD -HEADERS += $$PWD/observerprotocol.h +HEADERS += $$PWD/inspectorprotocol.h diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeinspectorservice.cpp b/share/qtcreator/qml/qmljsdebugger/qdeclarativeinspectorservice.cpp new file mode 100644 index 0000000000..b3c94ec6b0 --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/qdeclarativeinspectorservice.cpp @@ -0,0 +1,286 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "qdeclarativeinspectorservice.h" + +#include + +#include +#include + +namespace QmlJSDebugger { + +Q_GLOBAL_STATIC(QDeclarativeInspectorService, serviceInstance) + +QDeclarativeInspectorService::QDeclarativeInspectorService() + : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode")) +{ +} + +QDeclarativeInspectorService *QDeclarativeInspectorService::instance() +{ + return serviceInstance(); +} + +void QDeclarativeInspectorService::statusChanged(Status status) +{ + emit debuggingClientChanged((status == Enabled)); +} + +void QDeclarativeInspectorService::messageReceived(const QByteArray &message) +{ + QDataStream ds(message); + + InspectorProtocol::Message type; + ds >> type; + + switch (type) { + case InspectorProtocol::SetCurrentObjects: { + int itemCount = 0; + ds >> itemCount; + + QList selectedObjects; + for (int i = 0; i < itemCount; ++i) { + int debugId = -1; + ds >> debugId; + if (QObject *obj = objectForId(debugId)) + selectedObjects << obj; + } + + emit currentObjectsChanged(selectedObjects); + break; + } + case InspectorProtocol::Reload: { + emit reloadRequested(); + break; + } + case InspectorProtocol::SetAnimationSpeed: { + qreal speed; + ds >> speed; + emit animationSpeedChangeRequested(speed); + break; + } + case InspectorProtocol::SetAnimationPaused: { + bool paused; + ds >> paused; + emit executionPauseChangeRequested(paused); + break; + } + case InspectorProtocol::ChangeTool: { + InspectorProtocol::Tool tool; + ds >> tool; + switch (tool) { + case InspectorProtocol::ColorPickerTool: + emit colorPickerToolRequested(); + break; + case InspectorProtocol::SelectTool: + emit selectToolRequested(); + break; + case InspectorProtocol::SelectMarqueeTool: + emit selectMarqueeToolRequested(); + break; + case InspectorProtocol::ZoomTool: + emit zoomToolRequested(); + break; + default: + qWarning() << "Warning: Unhandled tool:" << tool; + } + break; + } + case InspectorProtocol::SetDesignMode: { + bool inDesignMode; + ds >> inDesignMode; + emit designModeBehaviorChanged(inDesignMode); + break; + } + case InspectorProtocol::ShowAppOnTop: { + bool showOnTop; + ds >> showOnTop; + emit showAppOnTopChanged(showOnTop); + break; + } + case InspectorProtocol::CreateObject: { + QString qml; + int parentId; + QString filename; + QStringList imports; + ds >> qml >> parentId >> imports >> filename; + int order = -1; + if (!ds.atEnd()) { + ds >> order; + } + emit objectCreationRequested(qml, objectForId(parentId), imports, filename, order); + break; + } + case InspectorProtocol::DestroyObject: { + int debugId; + ds >> debugId; + if (QObject* obj = objectForId(debugId)) { + emit objectDeletionRequested(obj); + } + break; + } + case InspectorProtocol::MoveObject: { + int debugId, newParent; + ds >> debugId >> newParent; + emit objectReparentRequested(objectForId(debugId), objectForId(newParent)); + break; + } + case InspectorProtocol::ObjectIdList: { + int itemCount; + ds >> itemCount; + m_stringIdForObjectId.clear(); + for (int i = 0; i < itemCount; ++i) { + int itemDebugId; + QString itemIdString; + ds >> itemDebugId + >> itemIdString; + + m_stringIdForObjectId.insert(itemDebugId, itemIdString); + } + break; + } + case InspectorProtocol::ClearComponentCache: { + emit clearComponentCacheRequested(); + break; + } + default: + qWarning() << "Warning: Not handling message:" << type; + } +} + +void QDeclarativeInspectorService::setDesignModeBehavior(bool inDesignMode) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::SetDesignMode + << inDesignMode; + + sendMessage(message); +} + +void QDeclarativeInspectorService::setCurrentObjects(QList objects) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::CurrentObjectsChanged + << objects.length(); + + foreach (QObject *object, objects) { + int id = idForObject(object); + ds << id; + } + + sendMessage(message); +} + +void QDeclarativeInspectorService::setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::ToolChanged + << toolId; + + sendMessage(message); +} + +void QDeclarativeInspectorService::setAnimationSpeed(qreal slowDownFactor) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::AnimationSpeedChanged + << slowDownFactor; + + sendMessage(message); +} + +void QDeclarativeInspectorService::setAnimationPaused(bool paused) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::AnimationPausedChanged + << paused; + + sendMessage(message); +} + +void QDeclarativeInspectorService::reloaded() +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::Reloaded; + + sendMessage(message); +} + +void QDeclarativeInspectorService::setShowAppOnTop(bool showAppOnTop) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::ShowAppOnTop << showAppOnTop; + + sendMessage(message); +} + +void QDeclarativeInspectorService::selectedColorChanged(const QColor &color) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + ds << InspectorProtocol::ColorChanged + << color; + + sendMessage(message); +} + +QString QDeclarativeInspectorService::idStringForObject(QObject *obj) const +{ + int id = idForObject(obj); + QString idString = m_stringIdForObjectId.value(id, QString()); + return idString; +} + +void QDeclarativeInspectorService::sendMessage(const QByteArray &message) +{ + if (status() != Enabled) + return; + + QDeclarativeDebugService::sendMessage(message); +} + +} // namespace QmlJSDebugger diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp b/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp deleted file mode 100644 index 255aa1e407..0000000000 --- a/share/qtcreator/qml/qmljsdebugger/qdeclarativeobserverservice.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#include "qdeclarativeobserverservice.h" - -#include - -#include -#include - -namespace QmlJSDebugger { - -Q_GLOBAL_STATIC(QDeclarativeObserverService, serviceInstance) - -QDeclarativeObserverService::QDeclarativeObserverService() - : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode")) -{ -} - -QDeclarativeObserverService *QDeclarativeObserverService::instance() -{ - return serviceInstance(); -} - -void QDeclarativeObserverService::statusChanged(Status status) -{ - emit debuggingClientChanged((status == Enabled)); -} - -void QDeclarativeObserverService::messageReceived(const QByteArray &message) -{ - QDataStream ds(message); - - ObserverProtocol::Message type; - ds >> type; - - switch (type) { - case ObserverProtocol::SetCurrentObjects: { - int itemCount = 0; - ds >> itemCount; - - QList selectedObjects; - for (int i = 0; i < itemCount; ++i) { - int debugId = -1; - ds >> debugId; - if (QObject *obj = objectForId(debugId)) - selectedObjects << obj; - } - - emit currentObjectsChanged(selectedObjects); - break; - } - case ObserverProtocol::Reload: { - emit reloadRequested(); - break; - } - case ObserverProtocol::SetAnimationSpeed: { - qreal speed; - ds >> speed; - emit animationSpeedChangeRequested(speed); - break; - } - case ObserverProtocol::SetAnimationPaused: { - bool paused; - ds >> paused; - emit executionPauseChangeRequested(paused); - break; - } - case ObserverProtocol::ChangeTool: { - ObserverProtocol::Tool tool; - ds >> tool; - switch (tool) { - case ObserverProtocol::ColorPickerTool: - emit colorPickerToolRequested(); - break; - case ObserverProtocol::SelectTool: - emit selectToolRequested(); - break; - case ObserverProtocol::SelectMarqueeTool: - emit selectMarqueeToolRequested(); - break; - case ObserverProtocol::ZoomTool: - emit zoomToolRequested(); - break; - default: - qWarning() << "Warning: Unhandled tool:" << tool; - } - break; - } - case ObserverProtocol::SetDesignMode: { - bool inDesignMode; - ds >> inDesignMode; - emit designModeBehaviorChanged(inDesignMode); - break; - } - case ObserverProtocol::ShowAppOnTop: { - bool showOnTop; - ds >> showOnTop; - emit showAppOnTopChanged(showOnTop); - break; - } - case ObserverProtocol::CreateObject: { - QString qml; - int parentId; - QString filename; - QStringList imports; - ds >> qml >> parentId >> imports >> filename; - int order = -1; - if (!ds.atEnd()) { - ds >> order; - } - emit objectCreationRequested(qml, objectForId(parentId), imports, filename, order); - break; - } - case ObserverProtocol::DestroyObject: { - int debugId; - ds >> debugId; - if (QObject* obj = objectForId(debugId)) { - emit objectDeletionRequested(obj); - } - break; - } - case ObserverProtocol::MoveObject: { - int debugId, newParent; - ds >> debugId >> newParent; - emit objectReparentRequested(objectForId(debugId), objectForId(newParent)); - break; - } - case ObserverProtocol::ObjectIdList: { - int itemCount; - ds >> itemCount; - m_stringIdForObjectId.clear(); - for (int i = 0; i < itemCount; ++i) { - int itemDebugId; - QString itemIdString; - ds >> itemDebugId - >> itemIdString; - - m_stringIdForObjectId.insert(itemDebugId, itemIdString); - } - break; - } - case ObserverProtocol::ClearComponentCache: { - emit clearComponentCacheRequested(); - break; - } - default: - qWarning() << "Warning: Not handling message:" << type; - } -} - -void QDeclarativeObserverService::setDesignModeBehavior(bool inDesignMode) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::SetDesignMode - << inDesignMode; - - sendMessage(message); -} - -void QDeclarativeObserverService::setCurrentObjects(QList objects) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::CurrentObjectsChanged - << objects.length(); - - foreach (QObject *object, objects) { - int id = idForObject(object); - ds << id; - } - - sendMessage(message); -} - -void QDeclarativeObserverService::setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::ToolChanged - << toolId; - - sendMessage(message); -} - -void QDeclarativeObserverService::setAnimationSpeed(qreal slowDownFactor) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::AnimationSpeedChanged - << slowDownFactor; - - sendMessage(message); -} - -void QDeclarativeObserverService::setAnimationPaused(bool paused) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::AnimationPausedChanged - << paused; - - sendMessage(message); -} - -void QDeclarativeObserverService::reloaded() -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::Reloaded; - - sendMessage(message); -} - -void QDeclarativeObserverService::setShowAppOnTop(bool showAppOnTop) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::ShowAppOnTop << showAppOnTop; - - sendMessage(message); -} - -void QDeclarativeObserverService::selectedColorChanged(const QColor &color) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ds << ObserverProtocol::ColorChanged - << color; - - sendMessage(message); -} - -QString QDeclarativeObserverService::idStringForObject(QObject *obj) const -{ - int id = idForObject(obj); - QString idString = m_stringIdForObjectId.value(id, QString()); - return idString; -} - -void QDeclarativeObserverService::sendMessage(const QByteArray &message) -{ - if (status() != Enabled) - return; - - QDeclarativeDebugService::sendMessage(message); -} - -} // namespace QmlJSDebugger diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector.cpp b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector.cpp new file mode 100644 index 0000000000..f0777e922b --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector.cpp @@ -0,0 +1,950 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "qdeclarativeviewinspector.h" +#include "qdeclarativeviewinspector_p.h" +#include "qdeclarativeinspectorservice.h" +#include "editor/liveselectiontool.h" +#include "editor/zoomtool.h" +#include "editor/colorpickertool.h" +#include "editor/livelayeritem.h" +#include "editor/boundingrecthighlighter.h" +#include "editor/qmltoolbar.h" + +#include "qt_private/qdeclarativedebughelper_p.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qt_private/qdeclarativestate_p.h" + +static inline void initEditorResource() { Q_INIT_RESOURCE(editor); } + +namespace QmlJSDebugger { + +const char * const KEY_TOOLBOX_GEOMETRY = "toolBox/geometry"; + +const int SceneChangeUpdateInterval = 5000; + + +class ToolBox : public QWidget +{ + Q_OBJECT + +public: + ToolBox(QWidget *parent = 0); + ~ToolBox(); + + QmlToolBar *toolBar() const { return m_toolBar; } + +private: + QSettings m_settings; + QmlToolBar *m_toolBar; +}; + +ToolBox::ToolBox(QWidget *parent) + : QWidget(parent, Qt::Tool) + , m_settings(QLatin1String("Nokia"), QLatin1String("QmlInspector"), this) + , m_toolBar(new QmlToolBar) +{ + setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::CustomizeWindowHint); + setWindowTitle(tr("Qt Quick Toolbox")); + + QVBoxLayout *verticalLayout = new QVBoxLayout; + verticalLayout->setMargin(0); + verticalLayout->addWidget(m_toolBar); + setLayout(verticalLayout); + + restoreGeometry(m_settings.value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray()); +} + +ToolBox::~ToolBox() +{ + m_settings.setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY), saveGeometry()); +} + + +QDeclarativeViewInspectorPrivate::QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *q) : + q(q), + designModeBehavior(false), + showAppOnTop(false), + animationPaused(false), + slowDownFactor(1.0f), + toolBox(0) +{ +} + +QDeclarativeViewInspectorPrivate::~QDeclarativeViewInspectorPrivate() +{ +} + +QDeclarativeViewInspector::QDeclarativeViewInspector(QDeclarativeView *view, QObject *parent) : + QObject(parent), data(new QDeclarativeViewInspectorPrivate(this)) +{ + initEditorResource(); + + data->view = view; + data->manipulatorLayer = new LiveLayerItem(view->scene()); + data->selectionTool = new LiveSelectionTool(this); + data->zoomTool = new ZoomTool(this); + data->colorPickerTool = new ColorPickerTool(this); + data->boundingRectHighlighter = new BoundingRectHighlighter(this); + data->currentTool = data->selectionTool; + + // to capture ChildRemoved event when viewport changes + data->view->installEventFilter(this); + + data->setViewport(data->view->viewport()); + + data->debugService = QDeclarativeInspectorService::instance(); + + // tool box is disabled + //connect(data->debugService, SIGNAL(debuggingClientChanged(bool)), + // data.data(), SLOT(_q_setToolBoxVisible(bool))); + + connect(data->debugService, SIGNAL(designModeBehaviorChanged(bool)), + SLOT(setDesignModeBehavior(bool))); + connect(data->debugService, SIGNAL(showAppOnTopChanged(bool)), + SLOT(setShowAppOnTop(bool))); + connect(data->debugService, SIGNAL(reloadRequested()), data.data(), SLOT(_q_reloadView())); + connect(data->debugService, SIGNAL(currentObjectsChanged(QList)), + data.data(), SLOT(_q_onCurrentObjectsChanged(QList))); + connect(data->debugService, SIGNAL(animationSpeedChangeRequested(qreal)), + SLOT(animationSpeedChangeRequested(qreal))); + connect(data->debugService, SIGNAL(executionPauseChangeRequested(bool)), + SLOT(animationPausedChangeRequested(bool))); + connect(data->debugService, SIGNAL(colorPickerToolRequested()), + data.data(), SLOT(_q_changeToColorPickerTool())); + connect(data->debugService, SIGNAL(selectMarqueeToolRequested()), + data.data(), SLOT(_q_changeToMarqueeSelectTool())); + connect(data->debugService, SIGNAL(selectToolRequested()), data.data(), SLOT(_q_changeToSingleSelectTool())); + connect(data->debugService, SIGNAL(zoomToolRequested()), data.data(), SLOT(_q_changeToZoomTool())); + connect(data->debugService, + SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString,int)), + data.data(), SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString,int))); + connect(data->debugService, + SIGNAL(objectDeletionRequested(QObject *)), data.data(), SLOT(_q_deleteQmlObject(QObject *))); + connect(data->debugService, + SIGNAL(objectReparentRequested(QObject *, QObject *)), + data.data(), SLOT(_q_reparentQmlObject(QObject *, QObject *))); + connect(data->debugService, SIGNAL(contextPathIndexChanged(int)), + data.data(), SLOT(_q_changeContextPathIndex(int))); + connect(data->debugService, SIGNAL(clearComponentCacheRequested()), + data.data(), SLOT(_q_clearComponentCache())); + connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), + data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); + + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + SIGNAL(selectedColorChanged(QColor))); + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + data->debugService, SLOT(selectedColorChanged(QColor))); + + data->_q_changeToSingleSelectTool(); +} + +QDeclarativeViewInspector::~QDeclarativeViewInspector() +{ +} + +void QDeclarativeViewInspectorPrivate::_q_setToolBoxVisible(bool visible) +{ +#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) + if (!toolBox && visible) + createToolBox(); + if (toolBox) + toolBox->setVisible(visible); +#else + Q_UNUSED(visible) +#endif +} + +void QDeclarativeViewInspectorPrivate::_q_reloadView() +{ + clearHighlight(); + emit q->reloadRequested(); +} + +void QDeclarativeViewInspectorPrivate::setViewport(QWidget *widget) +{ + if (viewport.data() == widget) + return; + + if (viewport) + viewport.data()->removeEventFilter(q); + + viewport = widget; + if (viewport) { + // make sure we get mouse move events + viewport.data()->setMouseTracking(true); + viewport.data()->installEventFilter(q); + } +} + +void QDeclarativeViewInspectorPrivate::clearEditorItems() +{ + clearHighlight(); + setSelectedItems(QList()); +} + +bool QDeclarativeViewInspector::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == data->view) { + // Event from view + if (event->type() == QEvent::ChildRemoved) { + // Might mean that viewport has changed + if (data->view->viewport() != data->viewport.data()) + data->setViewport(data->view->viewport()); + } + return QObject::eventFilter(obj, event); + } + + // Event from viewport + switch (event->type()) { + case QEvent::Leave: { + if (leaveEvent(event)) + return true; + break; + } + case QEvent::MouseButtonPress: { + if (mousePressEvent(static_cast(event))) + return true; + break; + } + case QEvent::MouseMove: { + if (mouseMoveEvent(static_cast(event))) + return true; + break; + } + case QEvent::MouseButtonRelease: { + if (mouseReleaseEvent(static_cast(event))) + return true; + break; + } + case QEvent::KeyPress: { + if (keyPressEvent(static_cast(event))) + return true; + break; + } + case QEvent::KeyRelease: { + if (keyReleaseEvent(static_cast(event))) + return true; + break; + } + case QEvent::MouseButtonDblClick: { + if (mouseDoubleClickEvent(static_cast(event))) + return true; + break; + } + case QEvent::Wheel: { + if (wheelEvent(static_cast(event))) + return true; + break; + } + default: { + break; + } + } //switch + + // standard event processing + return QObject::eventFilter(obj, event); +} + +bool QDeclarativeViewInspector::leaveEvent(QEvent * /*event*/) +{ + if (!data->designModeBehavior) + return false; + data->clearHighlight(); + return true; +} + +bool QDeclarativeViewInspector::mousePressEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->cursorPos = event->pos(); + data->currentTool->mousePressEvent(event); + return true; +} + +bool QDeclarativeViewInspector::mouseMoveEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) { + data->clearEditorItems(); + return false; + } + data->cursorPos = event->pos(); + + QList selItems = data->selectableItems(event->pos()); + if (!selItems.isEmpty()) { + declarativeView()->setToolTip(AbstractLiveEditTool::titleForItem(selItems.first())); + } else { + declarativeView()->setToolTip(QString()); + } + if (event->buttons()) { + data->currentTool->mouseMoveEvent(event); + } else { + data->currentTool->hoverMoveEvent(event); + } + return true; +} + +bool QDeclarativeViewInspector::mouseReleaseEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + + data->cursorPos = event->pos(); + data->currentTool->mouseReleaseEvent(event); + return true; +} + +bool QDeclarativeViewInspector::keyPressEvent(QKeyEvent *event) +{ + if (!data->designModeBehavior) + return false; + + data->currentTool->keyPressEvent(event); + return true; +} + +bool QDeclarativeViewInspector::keyReleaseEvent(QKeyEvent *event) +{ + if (!data->designModeBehavior) + return false; + + switch(event->key()) { + case Qt::Key_V: + data->_q_changeToSingleSelectTool(); + break; +// disabled because multiselection does not do anything useful without design mode +// case Qt::Key_M: +// data->_q_changeToMarqueeSelectTool(); +// break; + case Qt::Key_I: + data->_q_changeToColorPickerTool(); + break; + case Qt::Key_Z: + data->_q_changeToZoomTool(); + break; + case Qt::Key_Space: + setAnimationPaused(!data->animationPaused); + break; + default: + break; + } + + data->currentTool->keyReleaseEvent(event); + return true; +} + +bool insertObjectInListProperty(QDeclarativeListReference &fromList, int position, QObject *object) +{ + QList tmpList; + int i; + + if (!(fromList.canCount() && fromList.canAt() && fromList.canAppend() && fromList.canClear())) + return false; + + if (position == fromList.count()) { + fromList.append(object); + return true; + } + + for (i=0; i tmpList; + int i; + + if (!(fromList.canCount() && fromList.canAt() && fromList.canAppend() && fromList.canClear())) + return false; + + for (i=0; iengine()->contextForObject(parent); + QDeclarativeComponent component(view->engine(), q); + QByteArray constructedQml = QString(imports + qml).toLatin1(); + + component.setData(constructedQml, filename); + QObject *newObject = component.create(parentContext); + if (newObject) { + newObject->setParent(parent); + do { + // add child item + QDeclarativeItem *parentItem = qobject_cast(parent); + QDeclarativeItem *newItem = qobject_cast(newObject); + if (parentItem && newItem) { + newItem->setParentItem(parentItem); + break; + } + + // add property change + QDeclarativeState *parentState = qobject_cast(parent); + QDeclarativeStateOperation *newPropertyChanges = qobject_cast(newObject); + if (parentState && newPropertyChanges) { + (*parentState) << newPropertyChanges; + break; + } + + // add states + QDeclarativeState *newState = qobject_cast(newObject); + if (parentItem && newState) { + QDeclarativeListReference statesList(parentItem, "states"); + statesList.append(newObject); + break; + } + + // add animation to transition + if (parent->inherits("QDeclarativeTransition") && + newObject->inherits("QDeclarativeAbstractAnimation")) { + QDeclarativeListReference animationsList(parent, "animations"); + animationsList.append(newObject); + break; + } + + // add animation to animation + if (parent->inherits("QDeclarativeAnimationGroup") && + newObject->inherits("QDeclarativeAbstractAnimation")) { + QDeclarativeListReference animationsList(parent, "animations"); + if (order==-1) { + animationsList.append(newObject); + } else { + if (!insertObjectInListProperty(animationsList, order, newObject)) { + animationsList.append(newObject); + } + } + break; + } + + // add transition + if (parentItem && newObject->inherits("QDeclarativeTransition")) { + QDeclarativeListReference transitionsList(parentItem,"transitions"); + if (transitionsList.count() == 1 && transitionsList.at(0) == 0) { + transitionsList.clear(); + } + transitionsList.append(newObject); + break; + } + + } while (false); + } +} + +void QDeclarativeViewInspectorPrivate::_q_reparentQmlObject(QObject *object, QObject *newParent) +{ + if (!newParent) + return; + + object->setParent(newParent); + QDeclarativeItem *newParentItem = qobject_cast(newParent); + QDeclarativeItem *item = qobject_cast(object); + if (newParentItem && item) + item->setParentItem(newParentItem); +} + +void QDeclarativeViewInspectorPrivate::_q_deleteQmlObject(QObject *object) +{ + // special cases for transitions/animations + if (object->inherits("QDeclarativeAbstractAnimation")) { + if (object->parent()) { + QDeclarativeListReference animationsList(object->parent(), "animations"); + if (removeObjectFromListProperty(animationsList, object)) + object->deleteLater(); + return; + } + } + + if (object->inherits("QDeclarativeTransition")) { + QDeclarativeListReference transitionsList(object->parent(), "transitions"); + if (removeObjectFromListProperty(transitionsList, object)) + object->deleteLater(); + return; + } +} + +void QDeclarativeViewInspectorPrivate::_q_clearComponentCache() +{ + view->engine()->clearComponentCache(); +} + +void QDeclarativeViewInspectorPrivate::_q_removeFromSelection(QObject *obj) +{ + QList items = selectedItems(); + if (QGraphicsItem *item = qobject_cast(obj)) + items.removeOne(item); + setSelectedItems(items); +} + +bool QDeclarativeViewInspector::mouseDoubleClickEvent(QMouseEvent * /*event*/) +{ + if (!data->designModeBehavior) + return false; + + return true; +} + +bool QDeclarativeViewInspector::wheelEvent(QWheelEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->currentTool->wheelEvent(event); + return true; +} + +void QDeclarativeViewInspector::setDesignModeBehavior(bool value) +{ + emit designModeBehaviorChanged(value); + + if (data->toolBox) + data->toolBox->toolBar()->setDesignModeBehavior(value); + data->debugService->setDesignModeBehavior(value); + + data->designModeBehavior = value; + + if (!data->designModeBehavior) + data->clearEditorItems(); +} + +bool QDeclarativeViewInspector::designModeBehavior() +{ + return data->designModeBehavior; +} + +bool QDeclarativeViewInspector::showAppOnTop() const +{ + return data->showAppOnTop; +} + +void QDeclarativeViewInspector::setShowAppOnTop(bool appOnTop) +{ + if (data->view) { + QWidget *window = data->view->window(); + Qt::WindowFlags flags = window->windowFlags(); + if (appOnTop) + flags |= Qt::WindowStaysOnTopHint; + else + flags &= ~Qt::WindowStaysOnTopHint; + + window->setWindowFlags(flags); + window->show(); + } + + data->showAppOnTop = appOnTop; + data->debugService->setShowAppOnTop(appOnTop); + + emit showAppOnTopChanged(appOnTop); +} + +void QDeclarativeViewInspectorPrivate::changeTool(Constants::DesignTool tool, + Constants::ToolFlags /*flags*/) +{ + switch(tool) { + case Constants::SelectionToolMode: + _q_changeToSingleSelectTool(); + break; + case Constants::NoTool: + default: + currentTool = 0; + break; + } +} + +void QDeclarativeViewInspectorPrivate::setSelectedItemsForTools(QList items) +{ + foreach (const QWeakPointer &obj, currentSelection) { + if (QGraphicsItem *item = obj.data()) { + if (!items.contains(item)) { + QObject::disconnect(obj.data(), SIGNAL(destroyed(QObject*)), + this, SLOT(_q_removeFromSelection(QObject*))); + currentSelection.removeOne(obj); + } + } + } + + foreach (QGraphicsItem *item, items) { + if (QGraphicsObject *obj = item->toGraphicsObject()) { + if (!currentSelection.contains(obj)) { + QObject::connect(obj, SIGNAL(destroyed(QObject*)), + this, SLOT(_q_removeFromSelection(QObject*))); + currentSelection.append(obj); + } + } + } + + currentTool->updateSelectedItems(); +} + +void QDeclarativeViewInspectorPrivate::setSelectedItems(QList items) +{ + QList > oldList = currentSelection; + setSelectedItemsForTools(items); + if (oldList != currentSelection) { + QList objectList; + foreach (const QWeakPointer &graphicsObject, currentSelection) { + if (graphicsObject) + objectList << graphicsObject.data(); + } + + debugService->setCurrentObjects(objectList); + } +} + +QList QDeclarativeViewInspectorPrivate::selectedItems() +{ + QList selection; + foreach (const QWeakPointer &selectedObject, currentSelection) { + if (selectedObject.data()) + selection << selectedObject.data(); + } + + return selection; +} + +void QDeclarativeViewInspector::setSelectedItems(QList items) +{ + data->setSelectedItems(items); +} + +QList QDeclarativeViewInspector::selectedItems() +{ + return data->selectedItems(); +} + +QDeclarativeView *QDeclarativeViewInspector::declarativeView() +{ + return data->view; +} + +void QDeclarativeViewInspectorPrivate::clearHighlight() +{ + boundingRectHighlighter->clear(); +} + +void QDeclarativeViewInspectorPrivate::highlight(const QList &items) +{ + if (items.isEmpty()) + return; + + QList objectList; + foreach (QGraphicsItem *item, items) { + QGraphicsItem *child = item; + + if (child) { + QGraphicsObject *childObject = child->toGraphicsObject(); + if (childObject) + objectList << childObject; + } + } + + boundingRectHighlighter->highlight(objectList); +} + +QList QDeclarativeViewInspectorPrivate::selectableItems( + const QPointF &scenePos) const +{ + QList itemlist = view->scene()->items(scenePos); + return filterForSelection(itemlist); +} + +QList QDeclarativeViewInspectorPrivate::selectableItems(const QPoint &pos) const +{ + QList itemlist = view->items(pos); + return filterForSelection(itemlist); +} + +QList QDeclarativeViewInspectorPrivate::selectableItems( + const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const +{ + QList itemlist = view->scene()->items(sceneRect, selectionMode); + return filterForSelection(itemlist); +} + +void QDeclarativeViewInspectorPrivate::_q_changeToSingleSelectTool() +{ + currentToolMode = Constants::SelectionToolMode; + selectionTool->setRubberbandSelectionMode(false); + + changeToSelectTool(); + + emit q->selectToolActivated(); + debugService->setCurrentTool(Constants::SelectionToolMode); +} + +void QDeclarativeViewInspectorPrivate::changeToSelectTool() +{ + if (currentTool == selectionTool) + return; + + currentTool->clear(); + currentTool = selectionTool; + currentTool->clear(); + currentTool->updateSelectedItems(); +} + +void QDeclarativeViewInspectorPrivate::_q_changeToMarqueeSelectTool() +{ + changeToSelectTool(); + currentToolMode = Constants::MarqueeSelectionToolMode; + selectionTool->setRubberbandSelectionMode(true); + + emit q->marqueeSelectToolActivated(); + debugService->setCurrentTool(Constants::MarqueeSelectionToolMode); +} + +void QDeclarativeViewInspectorPrivate::_q_changeToZoomTool() +{ + currentToolMode = Constants::ZoomMode; + currentTool->clear(); + currentTool = zoomTool; + currentTool->clear(); + + emit q->zoomToolActivated(); + debugService->setCurrentTool(Constants::ZoomMode); +} + +void QDeclarativeViewInspectorPrivate::_q_changeToColorPickerTool() +{ + if (currentTool == colorPickerTool) + return; + + currentToolMode = Constants::ColorPickerMode; + currentTool->clear(); + currentTool = colorPickerTool; + currentTool->clear(); + + emit q->colorPickerActivated(); + debugService->setCurrentTool(Constants::ColorPickerMode); +} + +void QDeclarativeViewInspector::setAnimationSpeed(qreal slowDownFactor) +{ + Q_ASSERT(slowDownFactor > 0); + if (data->slowDownFactor == slowDownFactor) + return; + + animationSpeedChangeRequested(slowDownFactor); + data->debugService->setAnimationSpeed(slowDownFactor); +} + +void QDeclarativeViewInspector::setAnimationPaused(bool paused) +{ + if (data->animationPaused == paused) + return; + + animationPausedChangeRequested(paused); + data->debugService->setAnimationPaused(paused); +} + +void QDeclarativeViewInspector::animationSpeedChangeRequested(qreal factor) +{ + if (data->slowDownFactor != factor) { + data->slowDownFactor = factor; + emit animationSpeedChanged(factor); + } + + const float effectiveFactor = data->animationPaused ? 0 : factor; + QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor); +} + +void QDeclarativeViewInspector::animationPausedChangeRequested(bool paused) +{ + if (data->animationPaused != paused) { + data->animationPaused = paused; + emit animationPausedChanged(paused); + } + + const float effectiveFactor = paused ? 0 : data->slowDownFactor; + QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor); +} + + +void QDeclarativeViewInspectorPrivate::_q_applyChangesFromClient() +{ +} + + +QList QDeclarativeViewInspectorPrivate::filterForSelection( + QList &itemlist) const +{ + foreach (QGraphicsItem *item, itemlist) { + if (isEditorItem(item)) + itemlist.removeOne(item); + } + + return itemlist; +} + +bool QDeclarativeViewInspectorPrivate::isEditorItem(QGraphicsItem *item) const +{ + return (item->type() == Constants::EditorItemType + || item->type() == Constants::ResizeHandleItemType + || item->data(Constants::EditorItemDataKey).toBool()); +} + +void QDeclarativeViewInspectorPrivate::_q_onStatusChanged(QDeclarativeView::Status status) +{ + if (status == QDeclarativeView::Ready) + debugService->reloaded(); +} + +void QDeclarativeViewInspectorPrivate::_q_onCurrentObjectsChanged(QList objects) +{ + QList items; + QList gfxObjects; + foreach (QObject *obj, objects) { + if (QDeclarativeItem *declarativeItem = qobject_cast(obj)) { + items << declarativeItem; + gfxObjects << declarativeItem; + } + } + if (designModeBehavior) { + setSelectedItemsForTools(items); + clearHighlight(); + highlight(gfxObjects); + } +} + +QString QDeclarativeViewInspector::idStringForObject(QObject *obj) +{ + return QDeclarativeInspectorService::instance()->idStringForObject(obj); +} + +// adjusts bounding boxes on edges of screen to be visible +QRectF QDeclarativeViewInspector::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace) +{ + int marginFromEdge = 1; + QRectF boundingRect(boundingRectInSceneSpace); + if (qAbs(boundingRect.left()) - 1 < 2) + boundingRect.setLeft(marginFromEdge); + + QRect rect = data->view->rect(); + + if (boundingRect.right() >= rect.right()) + boundingRect.setRight(rect.right() - marginFromEdge); + + if (qAbs(boundingRect.top()) - 1 < 2) + boundingRect.setTop(marginFromEdge); + + if (boundingRect.bottom() >= rect.bottom()) + boundingRect.setBottom(rect.bottom() - marginFromEdge); + + return boundingRect; +} + +void QDeclarativeViewInspectorPrivate::createToolBox() +{ + toolBox = new ToolBox(q->declarativeView()); + + QmlToolBar *toolBar = toolBox->toolBar(); + + QObject::connect(q, SIGNAL(selectedColorChanged(QColor)), + toolBar, SLOT(setColorBoxColor(QColor))); + + QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)), + toolBar, SLOT(setDesignModeBehavior(bool))); + + QObject::connect(toolBar, SIGNAL(designModeBehaviorChanged(bool)), + q, SLOT(setDesignModeBehavior(bool))); + QObject::connect(toolBar, SIGNAL(animationSpeedChanged(qreal)), q, SLOT(setAnimationSpeed(qreal))); + QObject::connect(toolBar, SIGNAL(animationPausedChanged(bool)), q, SLOT(setAnimationPaused(bool))); + QObject::connect(toolBar, SIGNAL(colorPickerSelected()), this, SLOT(_q_changeToColorPickerTool())); + QObject::connect(toolBar, SIGNAL(zoomToolSelected()), this, SLOT(_q_changeToZoomTool())); + QObject::connect(toolBar, SIGNAL(selectToolSelected()), this, SLOT(_q_changeToSingleSelectTool())); + QObject::connect(toolBar, SIGNAL(marqueeSelectToolSelected()), + this, SLOT(_q_changeToMarqueeSelectTool())); + + QObject::connect(toolBar, SIGNAL(applyChangesFromQmlFileSelected()), + this, SLOT(_q_applyChangesFromClient())); + + QObject::connect(q, SIGNAL(animationSpeedChanged(qreal)), toolBar, SLOT(setAnimationSpeed(qreal))); + QObject::connect(q, SIGNAL(animationPausedChanged(bool)), toolBar, SLOT(setAnimationPaused(bool))); + + QObject::connect(q, SIGNAL(selectToolActivated()), toolBar, SLOT(activateSelectTool())); + + // disabled features + //connect(d->m_toolBar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient())); + //connect(q, SIGNAL(resizeToolActivated()), d->m_toolBar, SLOT(activateSelectTool())); + //connect(q, SIGNAL(moveToolActivated()), d->m_toolBar, SLOT(activateSelectTool())); + + QObject::connect(q, SIGNAL(colorPickerActivated()), toolBar, SLOT(activateColorPicker())); + QObject::connect(q, SIGNAL(zoomToolActivated()), toolBar, SLOT(activateZoom())); + QObject::connect(q, SIGNAL(marqueeSelectToolActivated()), + toolBar, SLOT(activateMarqueeSelectTool())); +} + +} // namespace QmlJSDebugger + +#include "qdeclarativeviewinspector.moc" diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector_p.h b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector_p.h new file mode 100644 index 0000000000..ed2e007cc2 --- /dev/null +++ b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewinspector_p.h @@ -0,0 +1,138 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef QDECLARATIVEVIEWINSPECTOR_P_H +#define QDECLARATIVEVIEWINSPECTOR_P_H + +#include +#include + +#include "qdeclarativeviewinspector.h" +#include "qdeclarativeinspectorservice.h" + +namespace QmlJSDebugger { + +class JSDebuggerAgent; +class QDeclarativeViewInspector; +class LiveSelectionTool; +class ZoomTool; +class ColorPickerTool; +class LiveLayerItem; +class BoundingRectHighlighter; +class ToolBox; +class CrumblePath; +class AbstractLiveEditTool; + +class QDeclarativeViewInspectorPrivate : public QObject +{ + Q_OBJECT +public: + QDeclarativeViewInspectorPrivate(QDeclarativeViewInspector *); + ~QDeclarativeViewInspectorPrivate(); + + QDeclarativeView *view; + QDeclarativeViewInspector *q; + QDeclarativeInspectorService *debugService; + QWeakPointer viewport; + + QPointF cursorPos; + QList > currentSelection; + + Constants::DesignTool currentToolMode; + AbstractLiveEditTool *currentTool; + + LiveSelectionTool *selectionTool; + ZoomTool *zoomTool; + ColorPickerTool *colorPickerTool; + LiveLayerItem *manipulatorLayer; + + BoundingRectHighlighter *boundingRectHighlighter; + + bool designModeBehavior; + bool showAppOnTop; + + bool animationPaused; + qreal slowDownFactor; + + ToolBox *toolBox; + + void setViewport(QWidget *widget); + + void clearEditorItems(); + void createToolBox(); + void changeToSelectTool(); + QList filterForSelection(QList &itemlist) const; + + QList selectableItems(const QPoint &pos) const; + QList selectableItems(const QPointF &scenePos) const; + QList selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; + + void setSelectedItemsForTools(QList items); + void setSelectedItems(QList items); + QList selectedItems(); + + void changeTool(Constants::DesignTool tool, + Constants::ToolFlags flags = Constants::NoToolFlags); + + void clearHighlight(); + void highlight(const QList &item); + inline void highlight(QGraphicsObject *item) + { highlight(QList() << item); } + + bool isEditorItem(QGraphicsItem *item) const; + +public slots: + void _q_setToolBoxVisible(bool visible); + + void _q_reloadView(); + void _q_onStatusChanged(QDeclarativeView::Status status); + void _q_onCurrentObjectsChanged(QList objects); + void _q_applyChangesFromClient(); + void _q_createQmlObject(const QString &qml, QObject *parent, + const QStringList &imports, const QString &filename = QString(), int order = 0); + void _q_reparentQmlObject(QObject *, QObject *); + void _q_deleteQmlObject(QObject *); + + void _q_changeToSingleSelectTool(); + void _q_changeToMarqueeSelectTool(); + void _q_changeToZoomTool(); + void _q_changeToColorPickerTool(); + void _q_clearComponentCache(); + void _q_removeFromSelection(QObject *); + +public: + static QDeclarativeViewInspectorPrivate *get(QDeclarativeViewInspector *v) { return v->d_func(); } +}; + +} // namespace QmlJSDebugger + +#endif // QDECLARATIVEVIEWINSPECTOR_P_H diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp deleted file mode 100644 index f3524cfb31..0000000000 --- a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver.cpp +++ /dev/null @@ -1,950 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#include "qdeclarativeviewobserver.h" -#include "qdeclarativeviewobserver_p.h" -#include "qdeclarativeobserverservice.h" -#include "editor/liveselectiontool.h" -#include "editor/zoomtool.h" -#include "editor/colorpickertool.h" -#include "editor/livelayeritem.h" -#include "editor/boundingrecthighlighter.h" -#include "editor/qmltoolbar.h" - -#include "qt_private/qdeclarativedebughelper_p.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "qt_private/qdeclarativestate_p.h" - -static inline void initEditorResource() { Q_INIT_RESOURCE(editor); } - -namespace QmlJSDebugger { - -const char * const KEY_TOOLBOX_GEOMETRY = "toolBox/geometry"; - -const int SceneChangeUpdateInterval = 5000; - - -class ToolBox : public QWidget -{ - Q_OBJECT - -public: - ToolBox(QWidget *parent = 0); - ~ToolBox(); - - QmlToolBar *toolBar() const { return m_toolBar; } - -private: - QSettings m_settings; - QmlToolBar *m_toolBar; -}; - -ToolBox::ToolBox(QWidget *parent) - : QWidget(parent, Qt::Tool) - , m_settings(QLatin1String("Nokia"), QLatin1String("QmlObserver"), this) - , m_toolBar(new QmlToolBar) -{ - setWindowFlags((windowFlags() & ~Qt::WindowCloseButtonHint) | Qt::CustomizeWindowHint); - setWindowTitle(tr("Qt Quick Toolbox")); - - QVBoxLayout *verticalLayout = new QVBoxLayout; - verticalLayout->setMargin(0); - verticalLayout->addWidget(m_toolBar); - setLayout(verticalLayout); - - restoreGeometry(m_settings.value(QLatin1String(KEY_TOOLBOX_GEOMETRY)).toByteArray()); -} - -ToolBox::~ToolBox() -{ - m_settings.setValue(QLatin1String(KEY_TOOLBOX_GEOMETRY), saveGeometry()); -} - - -QDeclarativeViewObserverPrivate::QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *q) : - q(q), - designModeBehavior(false), - showAppOnTop(false), - animationPaused(false), - slowDownFactor(1.0f), - toolBox(0) -{ -} - -QDeclarativeViewObserverPrivate::~QDeclarativeViewObserverPrivate() -{ -} - -QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent) : - QObject(parent), data(new QDeclarativeViewObserverPrivate(this)) -{ - initEditorResource(); - - data->view = view; - data->manipulatorLayer = new LiveLayerItem(view->scene()); - data->selectionTool = new LiveSelectionTool(this); - data->zoomTool = new ZoomTool(this); - data->colorPickerTool = new ColorPickerTool(this); - data->boundingRectHighlighter = new BoundingRectHighlighter(this); - data->currentTool = data->selectionTool; - - // to capture ChildRemoved event when viewport changes - data->view->installEventFilter(this); - - data->setViewport(data->view->viewport()); - - data->debugService = QDeclarativeObserverService::instance(); - - // tool box is disabled - //connect(data->debugService, SIGNAL(debuggingClientChanged(bool)), - // data.data(), SLOT(_q_setToolBoxVisible(bool))); - - connect(data->debugService, SIGNAL(designModeBehaviorChanged(bool)), - SLOT(setDesignModeBehavior(bool))); - connect(data->debugService, SIGNAL(showAppOnTopChanged(bool)), - SLOT(setShowAppOnTop(bool))); - connect(data->debugService, SIGNAL(reloadRequested()), data.data(), SLOT(_q_reloadView())); - connect(data->debugService, SIGNAL(currentObjectsChanged(QList)), - data.data(), SLOT(_q_onCurrentObjectsChanged(QList))); - connect(data->debugService, SIGNAL(animationSpeedChangeRequested(qreal)), - SLOT(animationSpeedChangeRequested(qreal))); - connect(data->debugService, SIGNAL(executionPauseChangeRequested(bool)), - SLOT(animationPausedChangeRequested(bool))); - connect(data->debugService, SIGNAL(colorPickerToolRequested()), - data.data(), SLOT(_q_changeToColorPickerTool())); - connect(data->debugService, SIGNAL(selectMarqueeToolRequested()), - data.data(), SLOT(_q_changeToMarqueeSelectTool())); - connect(data->debugService, SIGNAL(selectToolRequested()), data.data(), SLOT(_q_changeToSingleSelectTool())); - connect(data->debugService, SIGNAL(zoomToolRequested()), data.data(), SLOT(_q_changeToZoomTool())); - connect(data->debugService, - SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString,int)), - data.data(), SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString,int))); - connect(data->debugService, - SIGNAL(objectDeletionRequested(QObject *)), data.data(), SLOT(_q_deleteQmlObject(QObject *))); - connect(data->debugService, - SIGNAL(objectReparentRequested(QObject *, QObject *)), - data.data(), SLOT(_q_reparentQmlObject(QObject *, QObject *))); - connect(data->debugService, SIGNAL(contextPathIndexChanged(int)), - data.data(), SLOT(_q_changeContextPathIndex(int))); - connect(data->debugService, SIGNAL(clearComponentCacheRequested()), - data.data(), SLOT(_q_clearComponentCache())); - connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), - data.data(), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); - - connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), - SIGNAL(selectedColorChanged(QColor))); - connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), - data->debugService, SLOT(selectedColorChanged(QColor))); - - data->_q_changeToSingleSelectTool(); -} - -QDeclarativeViewObserver::~QDeclarativeViewObserver() -{ -} - -void QDeclarativeViewObserverPrivate::_q_setToolBoxVisible(bool visible) -{ -#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) - if (!toolBox && visible) - createToolBox(); - if (toolBox) - toolBox->setVisible(visible); -#else - Q_UNUSED(visible) -#endif -} - -void QDeclarativeViewObserverPrivate::_q_reloadView() -{ - clearHighlight(); - emit q->reloadRequested(); -} - -void QDeclarativeViewObserverPrivate::setViewport(QWidget *widget) -{ - if (viewport.data() == widget) - return; - - if (viewport) - viewport.data()->removeEventFilter(q); - - viewport = widget; - if (viewport) { - // make sure we get mouse move events - viewport.data()->setMouseTracking(true); - viewport.data()->installEventFilter(q); - } -} - -void QDeclarativeViewObserverPrivate::clearEditorItems() -{ - clearHighlight(); - setSelectedItems(QList()); -} - -bool QDeclarativeViewObserver::eventFilter(QObject *obj, QEvent *event) -{ - if (obj == data->view) { - // Event from view - if (event->type() == QEvent::ChildRemoved) { - // Might mean that viewport has changed - if (data->view->viewport() != data->viewport.data()) - data->setViewport(data->view->viewport()); - } - return QObject::eventFilter(obj, event); - } - - // Event from viewport - switch (event->type()) { - case QEvent::Leave: { - if (leaveEvent(event)) - return true; - break; - } - case QEvent::MouseButtonPress: { - if (mousePressEvent(static_cast(event))) - return true; - break; - } - case QEvent::MouseMove: { - if (mouseMoveEvent(static_cast(event))) - return true; - break; - } - case QEvent::MouseButtonRelease: { - if (mouseReleaseEvent(static_cast(event))) - return true; - break; - } - case QEvent::KeyPress: { - if (keyPressEvent(static_cast(event))) - return true; - break; - } - case QEvent::KeyRelease: { - if (keyReleaseEvent(static_cast(event))) - return true; - break; - } - case QEvent::MouseButtonDblClick: { - if (mouseDoubleClickEvent(static_cast(event))) - return true; - break; - } - case QEvent::Wheel: { - if (wheelEvent(static_cast(event))) - return true; - break; - } - default: { - break; - } - } //switch - - // standard event processing - return QObject::eventFilter(obj, event); -} - -bool QDeclarativeViewObserver::leaveEvent(QEvent * /*event*/) -{ - if (!data->designModeBehavior) - return false; - data->clearHighlight(); - return true; -} - -bool QDeclarativeViewObserver::mousePressEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) - return false; - data->cursorPos = event->pos(); - data->currentTool->mousePressEvent(event); - return true; -} - -bool QDeclarativeViewObserver::mouseMoveEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) { - data->clearEditorItems(); - return false; - } - data->cursorPos = event->pos(); - - QList selItems = data->selectableItems(event->pos()); - if (!selItems.isEmpty()) { - declarativeView()->setToolTip(AbstractLiveEditTool::titleForItem(selItems.first())); - } else { - declarativeView()->setToolTip(QString()); - } - if (event->buttons()) { - data->currentTool->mouseMoveEvent(event); - } else { - data->currentTool->hoverMoveEvent(event); - } - return true; -} - -bool QDeclarativeViewObserver::mouseReleaseEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) - return false; - - data->cursorPos = event->pos(); - data->currentTool->mouseReleaseEvent(event); - return true; -} - -bool QDeclarativeViewObserver::keyPressEvent(QKeyEvent *event) -{ - if (!data->designModeBehavior) - return false; - - data->currentTool->keyPressEvent(event); - return true; -} - -bool QDeclarativeViewObserver::keyReleaseEvent(QKeyEvent *event) -{ - if (!data->designModeBehavior) - return false; - - switch(event->key()) { - case Qt::Key_V: - data->_q_changeToSingleSelectTool(); - break; -// disabled because multiselection does not do anything useful without design mode -// case Qt::Key_M: -// data->_q_changeToMarqueeSelectTool(); -// break; - case Qt::Key_I: - data->_q_changeToColorPickerTool(); - break; - case Qt::Key_Z: - data->_q_changeToZoomTool(); - break; - case Qt::Key_Space: - setAnimationPaused(!data->animationPaused); - break; - default: - break; - } - - data->currentTool->keyReleaseEvent(event); - return true; -} - -bool insertObjectInListProperty(QDeclarativeListReference &fromList, int position, QObject *object) -{ - QList tmpList; - int i; - - if (!(fromList.canCount() && fromList.canAt() && fromList.canAppend() && fromList.canClear())) - return false; - - if (position == fromList.count()) { - fromList.append(object); - return true; - } - - for (i=0; i tmpList; - int i; - - if (!(fromList.canCount() && fromList.canAt() && fromList.canAppend() && fromList.canClear())) - return false; - - for (i=0; iengine()->contextForObject(parent); - QDeclarativeComponent component(view->engine(), q); - QByteArray constructedQml = QString(imports + qml).toLatin1(); - - component.setData(constructedQml, filename); - QObject *newObject = component.create(parentContext); - if (newObject) { - newObject->setParent(parent); - do { - // add child item - QDeclarativeItem *parentItem = qobject_cast(parent); - QDeclarativeItem *newItem = qobject_cast(newObject); - if (parentItem && newItem) { - newItem->setParentItem(parentItem); - break; - } - - // add property change - QDeclarativeState *parentState = qobject_cast(parent); - QDeclarativeStateOperation *newPropertyChanges = qobject_cast(newObject); - if (parentState && newPropertyChanges) { - (*parentState) << newPropertyChanges; - break; - } - - // add states - QDeclarativeState *newState = qobject_cast(newObject); - if (parentItem && newState) { - QDeclarativeListReference statesList(parentItem, "states"); - statesList.append(newObject); - break; - } - - // add animation to transition - if (parent->inherits("QDeclarativeTransition") && - newObject->inherits("QDeclarativeAbstractAnimation")) { - QDeclarativeListReference animationsList(parent, "animations"); - animationsList.append(newObject); - break; - } - - // add animation to animation - if (parent->inherits("QDeclarativeAnimationGroup") && - newObject->inherits("QDeclarativeAbstractAnimation")) { - QDeclarativeListReference animationsList(parent, "animations"); - if (order==-1) { - animationsList.append(newObject); - } else { - if (!insertObjectInListProperty(animationsList, order, newObject)) { - animationsList.append(newObject); - } - } - break; - } - - // add transition - if (parentItem && newObject->inherits("QDeclarativeTransition")) { - QDeclarativeListReference transitionsList(parentItem,"transitions"); - if (transitionsList.count() == 1 && transitionsList.at(0) == 0) { - transitionsList.clear(); - } - transitionsList.append(newObject); - break; - } - - } while (false); - } -} - -void QDeclarativeViewObserverPrivate::_q_reparentQmlObject(QObject *object, QObject *newParent) -{ - if (!newParent) - return; - - object->setParent(newParent); - QDeclarativeItem *newParentItem = qobject_cast(newParent); - QDeclarativeItem *item = qobject_cast(object); - if (newParentItem && item) - item->setParentItem(newParentItem); -} - -void QDeclarativeViewObserverPrivate::_q_deleteQmlObject(QObject *object) -{ - // special cases for transitions/animations - if (object->inherits("QDeclarativeAbstractAnimation")) { - if (object->parent()) { - QDeclarativeListReference animationsList(object->parent(), "animations"); - if (removeObjectFromListProperty(animationsList, object)) - object->deleteLater(); - return; - } - } - - if (object->inherits("QDeclarativeTransition")) { - QDeclarativeListReference transitionsList(object->parent(), "transitions"); - if (removeObjectFromListProperty(transitionsList, object)) - object->deleteLater(); - return; - } -} - -void QDeclarativeViewObserverPrivate::_q_clearComponentCache() -{ - view->engine()->clearComponentCache(); -} - -void QDeclarativeViewObserverPrivate::_q_removeFromSelection(QObject *obj) -{ - QList items = selectedItems(); - if (QGraphicsItem *item = qobject_cast(obj)) - items.removeOne(item); - setSelectedItems(items); -} - -bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent * /*event*/) -{ - if (!data->designModeBehavior) - return false; - - return true; -} - -bool QDeclarativeViewObserver::wheelEvent(QWheelEvent *event) -{ - if (!data->designModeBehavior) - return false; - data->currentTool->wheelEvent(event); - return true; -} - -void QDeclarativeViewObserver::setDesignModeBehavior(bool value) -{ - emit designModeBehaviorChanged(value); - - if (data->toolBox) - data->toolBox->toolBar()->setDesignModeBehavior(value); - data->debugService->setDesignModeBehavior(value); - - data->designModeBehavior = value; - - if (!data->designModeBehavior) - data->clearEditorItems(); -} - -bool QDeclarativeViewObserver::designModeBehavior() -{ - return data->designModeBehavior; -} - -bool QDeclarativeViewObserver::showAppOnTop() const -{ - return data->showAppOnTop; -} - -void QDeclarativeViewObserver::setShowAppOnTop(bool appOnTop) -{ - if (data->view) { - QWidget *window = data->view->window(); - Qt::WindowFlags flags = window->windowFlags(); - if (appOnTop) - flags |= Qt::WindowStaysOnTopHint; - else - flags &= ~Qt::WindowStaysOnTopHint; - - window->setWindowFlags(flags); - window->show(); - } - - data->showAppOnTop = appOnTop; - data->debugService->setShowAppOnTop(appOnTop); - - emit showAppOnTopChanged(appOnTop); -} - -void QDeclarativeViewObserverPrivate::changeTool(Constants::DesignTool tool, - Constants::ToolFlags /*flags*/) -{ - switch(tool) { - case Constants::SelectionToolMode: - _q_changeToSingleSelectTool(); - break; - case Constants::NoTool: - default: - currentTool = 0; - break; - } -} - -void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QList items) -{ - foreach (const QWeakPointer &obj, currentSelection) { - if (QGraphicsItem *item = obj.data()) { - if (!items.contains(item)) { - QObject::disconnect(obj.data(), SIGNAL(destroyed(QObject*)), - this, SLOT(_q_removeFromSelection(QObject*))); - currentSelection.removeOne(obj); - } - } - } - - foreach (QGraphicsItem *item, items) { - if (QGraphicsObject *obj = item->toGraphicsObject()) { - if (!currentSelection.contains(obj)) { - QObject::connect(obj, SIGNAL(destroyed(QObject*)), - this, SLOT(_q_removeFromSelection(QObject*))); - currentSelection.append(obj); - } - } - } - - currentTool->updateSelectedItems(); -} - -void QDeclarativeViewObserverPrivate::setSelectedItems(QList items) -{ - QList > oldList = currentSelection; - setSelectedItemsForTools(items); - if (oldList != currentSelection) { - QList objectList; - foreach (const QWeakPointer &graphicsObject, currentSelection) { - if (graphicsObject) - objectList << graphicsObject.data(); - } - - debugService->setCurrentObjects(objectList); - } -} - -QList QDeclarativeViewObserverPrivate::selectedItems() -{ - QList selection; - foreach (const QWeakPointer &selectedObject, currentSelection) { - if (selectedObject.data()) - selection << selectedObject.data(); - } - - return selection; -} - -void QDeclarativeViewObserver::setSelectedItems(QList items) -{ - data->setSelectedItems(items); -} - -QList QDeclarativeViewObserver::selectedItems() -{ - return data->selectedItems(); -} - -QDeclarativeView *QDeclarativeViewObserver::declarativeView() -{ - return data->view; -} - -void QDeclarativeViewObserverPrivate::clearHighlight() -{ - boundingRectHighlighter->clear(); -} - -void QDeclarativeViewObserverPrivate::highlight(const QList &items) -{ - if (items.isEmpty()) - return; - - QList objectList; - foreach (QGraphicsItem *item, items) { - QGraphicsItem *child = item; - - if (child) { - QGraphicsObject *childObject = child->toGraphicsObject(); - if (childObject) - objectList << childObject; - } - } - - boundingRectHighlighter->highlight(objectList); -} - -QList QDeclarativeViewObserverPrivate::selectableItems( - const QPointF &scenePos) const -{ - QList itemlist = view->scene()->items(scenePos); - return filterForSelection(itemlist); -} - -QList QDeclarativeViewObserverPrivate::selectableItems(const QPoint &pos) const -{ - QList itemlist = view->items(pos); - return filterForSelection(itemlist); -} - -QList QDeclarativeViewObserverPrivate::selectableItems( - const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const -{ - QList itemlist = view->scene()->items(sceneRect, selectionMode); - return filterForSelection(itemlist); -} - -void QDeclarativeViewObserverPrivate::_q_changeToSingleSelectTool() -{ - currentToolMode = Constants::SelectionToolMode; - selectionTool->setRubberbandSelectionMode(false); - - changeToSelectTool(); - - emit q->selectToolActivated(); - debugService->setCurrentTool(Constants::SelectionToolMode); -} - -void QDeclarativeViewObserverPrivate::changeToSelectTool() -{ - if (currentTool == selectionTool) - return; - - currentTool->clear(); - currentTool = selectionTool; - currentTool->clear(); - currentTool->updateSelectedItems(); -} - -void QDeclarativeViewObserverPrivate::_q_changeToMarqueeSelectTool() -{ - changeToSelectTool(); - currentToolMode = Constants::MarqueeSelectionToolMode; - selectionTool->setRubberbandSelectionMode(true); - - emit q->marqueeSelectToolActivated(); - debugService->setCurrentTool(Constants::MarqueeSelectionToolMode); -} - -void QDeclarativeViewObserverPrivate::_q_changeToZoomTool() -{ - currentToolMode = Constants::ZoomMode; - currentTool->clear(); - currentTool = zoomTool; - currentTool->clear(); - - emit q->zoomToolActivated(); - debugService->setCurrentTool(Constants::ZoomMode); -} - -void QDeclarativeViewObserverPrivate::_q_changeToColorPickerTool() -{ - if (currentTool == colorPickerTool) - return; - - currentToolMode = Constants::ColorPickerMode; - currentTool->clear(); - currentTool = colorPickerTool; - currentTool->clear(); - - emit q->colorPickerActivated(); - debugService->setCurrentTool(Constants::ColorPickerMode); -} - -void QDeclarativeViewObserver::setAnimationSpeed(qreal slowDownFactor) -{ - Q_ASSERT(slowDownFactor > 0); - if (data->slowDownFactor == slowDownFactor) - return; - - animationSpeedChangeRequested(slowDownFactor); - data->debugService->setAnimationSpeed(slowDownFactor); -} - -void QDeclarativeViewObserver::setAnimationPaused(bool paused) -{ - if (data->animationPaused == paused) - return; - - animationPausedChangeRequested(paused); - data->debugService->setAnimationPaused(paused); -} - -void QDeclarativeViewObserver::animationSpeedChangeRequested(qreal factor) -{ - if (data->slowDownFactor != factor) { - data->slowDownFactor = factor; - emit animationSpeedChanged(factor); - } - - const float effectiveFactor = data->animationPaused ? 0 : factor; - QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor); -} - -void QDeclarativeViewObserver::animationPausedChangeRequested(bool paused) -{ - if (data->animationPaused != paused) { - data->animationPaused = paused; - emit animationPausedChanged(paused); - } - - const float effectiveFactor = paused ? 0 : data->slowDownFactor; - QDeclarativeDebugHelper::setAnimationSlowDownFactor(effectiveFactor); -} - - -void QDeclarativeViewObserverPrivate::_q_applyChangesFromClient() -{ -} - - -QList QDeclarativeViewObserverPrivate::filterForSelection( - QList &itemlist) const -{ - foreach (QGraphicsItem *item, itemlist) { - if (isEditorItem(item)) - itemlist.removeOne(item); - } - - return itemlist; -} - -bool QDeclarativeViewObserverPrivate::isEditorItem(QGraphicsItem *item) const -{ - return (item->type() == Constants::EditorItemType - || item->type() == Constants::ResizeHandleItemType - || item->data(Constants::EditorItemDataKey).toBool()); -} - -void QDeclarativeViewObserverPrivate::_q_onStatusChanged(QDeclarativeView::Status status) -{ - if (status == QDeclarativeView::Ready) - debugService->reloaded(); -} - -void QDeclarativeViewObserverPrivate::_q_onCurrentObjectsChanged(QList objects) -{ - QList items; - QList gfxObjects; - foreach (QObject *obj, objects) { - if (QDeclarativeItem *declarativeItem = qobject_cast(obj)) { - items << declarativeItem; - gfxObjects << declarativeItem; - } - } - if (designModeBehavior) { - setSelectedItemsForTools(items); - clearHighlight(); - highlight(gfxObjects); - } -} - -QString QDeclarativeViewObserver::idStringForObject(QObject *obj) -{ - return QDeclarativeObserverService::instance()->idStringForObject(obj); -} - -// adjusts bounding boxes on edges of screen to be visible -QRectF QDeclarativeViewObserver::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace) -{ - int marginFromEdge = 1; - QRectF boundingRect(boundingRectInSceneSpace); - if (qAbs(boundingRect.left()) - 1 < 2) - boundingRect.setLeft(marginFromEdge); - - QRect rect = data->view->rect(); - - if (boundingRect.right() >= rect.right()) - boundingRect.setRight(rect.right() - marginFromEdge); - - if (qAbs(boundingRect.top()) - 1 < 2) - boundingRect.setTop(marginFromEdge); - - if (boundingRect.bottom() >= rect.bottom()) - boundingRect.setBottom(rect.bottom() - marginFromEdge); - - return boundingRect; -} - -void QDeclarativeViewObserverPrivate::createToolBox() -{ - toolBox = new ToolBox(q->declarativeView()); - - QmlToolBar *toolBar = toolBox->toolBar(); - - QObject::connect(q, SIGNAL(selectedColorChanged(QColor)), - toolBar, SLOT(setColorBoxColor(QColor))); - - QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)), - toolBar, SLOT(setDesignModeBehavior(bool))); - - QObject::connect(toolBar, SIGNAL(designModeBehaviorChanged(bool)), - q, SLOT(setDesignModeBehavior(bool))); - QObject::connect(toolBar, SIGNAL(animationSpeedChanged(qreal)), q, SLOT(setAnimationSpeed(qreal))); - QObject::connect(toolBar, SIGNAL(animationPausedChanged(bool)), q, SLOT(setAnimationPaused(bool))); - QObject::connect(toolBar, SIGNAL(colorPickerSelected()), this, SLOT(_q_changeToColorPickerTool())); - QObject::connect(toolBar, SIGNAL(zoomToolSelected()), this, SLOT(_q_changeToZoomTool())); - QObject::connect(toolBar, SIGNAL(selectToolSelected()), this, SLOT(_q_changeToSingleSelectTool())); - QObject::connect(toolBar, SIGNAL(marqueeSelectToolSelected()), - this, SLOT(_q_changeToMarqueeSelectTool())); - - QObject::connect(toolBar, SIGNAL(applyChangesFromQmlFileSelected()), - this, SLOT(_q_applyChangesFromClient())); - - QObject::connect(q, SIGNAL(animationSpeedChanged(qreal)), toolBar, SLOT(setAnimationSpeed(qreal))); - QObject::connect(q, SIGNAL(animationPausedChanged(bool)), toolBar, SLOT(setAnimationPaused(bool))); - - QObject::connect(q, SIGNAL(selectToolActivated()), toolBar, SLOT(activateSelectTool())); - - // disabled features - //connect(d->m_toolBar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient())); - //connect(q, SIGNAL(resizeToolActivated()), d->m_toolBar, SLOT(activateSelectTool())); - //connect(q, SIGNAL(moveToolActivated()), d->m_toolBar, SLOT(activateSelectTool())); - - QObject::connect(q, SIGNAL(colorPickerActivated()), toolBar, SLOT(activateColorPicker())); - QObject::connect(q, SIGNAL(zoomToolActivated()), toolBar, SLOT(activateZoom())); - QObject::connect(q, SIGNAL(marqueeSelectToolActivated()), - toolBar, SLOT(activateMarqueeSelectTool())); -} - -} // namespace QmlJSDebugger - -#include "qdeclarativeviewobserver.moc" diff --git a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h b/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h deleted file mode 100644 index 543fd10786..0000000000 --- a/share/qtcreator/qml/qmljsdebugger/qdeclarativeviewobserver_p.h +++ /dev/null @@ -1,138 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef QDECLARATIVEVIEWOBSERVER_P_H -#define QDECLARATIVEVIEWOBSERVER_P_H - -#include -#include - -#include "qdeclarativeviewobserver.h" -#include "qdeclarativeobserverservice.h" - -namespace QmlJSDebugger { - -class JSDebuggerAgent; -class QDeclarativeViewObserver; -class LiveSelectionTool; -class ZoomTool; -class ColorPickerTool; -class LiveLayerItem; -class BoundingRectHighlighter; -class ToolBox; -class CrumblePath; -class AbstractLiveEditTool; - -class QDeclarativeViewObserverPrivate : public QObject -{ - Q_OBJECT -public: - QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *); - ~QDeclarativeViewObserverPrivate(); - - QDeclarativeView *view; - QDeclarativeViewObserver *q; - QDeclarativeObserverService *debugService; - QWeakPointer viewport; - - QPointF cursorPos; - QList > currentSelection; - - Constants::DesignTool currentToolMode; - AbstractLiveEditTool *currentTool; - - LiveSelectionTool *selectionTool; - ZoomTool *zoomTool; - ColorPickerTool *colorPickerTool; - LiveLayerItem *manipulatorLayer; - - BoundingRectHighlighter *boundingRectHighlighter; - - bool designModeBehavior; - bool showAppOnTop; - - bool animationPaused; - qreal slowDownFactor; - - ToolBox *toolBox; - - void setViewport(QWidget *widget); - - void clearEditorItems(); - void createToolBox(); - void changeToSelectTool(); - QList filterForSelection(QList &itemlist) const; - - QList selectableItems(const QPoint &pos) const; - QList selectableItems(const QPointF &scenePos) const; - QList selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; - - void setSelectedItemsForTools(QList items); - void setSelectedItems(QList items); - QList selectedItems(); - - void changeTool(Constants::DesignTool tool, - Constants::ToolFlags flags = Constants::NoToolFlags); - - void clearHighlight(); - void highlight(const QList &item); - inline void highlight(QGraphicsObject *item) - { highlight(QList() << item); } - - bool isEditorItem(QGraphicsItem *item) const; - -public slots: - void _q_setToolBoxVisible(bool visible); - - void _q_reloadView(); - void _q_onStatusChanged(QDeclarativeView::Status status); - void _q_onCurrentObjectsChanged(QList objects); - void _q_applyChangesFromClient(); - void _q_createQmlObject(const QString &qml, QObject *parent, - const QStringList &imports, const QString &filename = QString(), int order = 0); - void _q_reparentQmlObject(QObject *, QObject *); - void _q_deleteQmlObject(QObject *); - - void _q_changeToSingleSelectTool(); - void _q_changeToMarqueeSelectTool(); - void _q_changeToZoomTool(); - void _q_changeToColorPickerTool(); - void _q_clearComponentCache(); - void _q_removeFromSelection(QObject *); - -public: - static QDeclarativeViewObserverPrivate *get(QDeclarativeViewObserver *v) { return v->d_func(); } -}; - -} // namespace QmlJSDebugger - -#endif // QDECLARATIVEVIEWOBSERVER_P_H diff --git a/share/qtcreator/qml/qmljsdebugger/qmljsdebugger-src.pri b/share/qtcreator/qml/qmljsdebugger/qmljsdebugger-src.pri index 025f758adb..4e93f4339b 100644 --- a/share/qtcreator/qml/qmljsdebugger/qmljsdebugger-src.pri +++ b/share/qtcreator/qml/qmljsdebugger/qmljsdebugger-src.pri @@ -10,9 +10,10 @@ SOURCES += \ $$PWD/jsdebuggeragent.cpp HEADERS += \ + $$PWD/include/qdeclarativeviewinspector.h \ $$PWD/include/qdeclarativeviewobserver.h \ - $$PWD/include/qdeclarativeobserverservice.h \ - $$PWD/include/qmlobserverconstants.h \ + $$PWD/include/qdeclarativeinspectorservice.h \ + $$PWD/include/qmlinspectorconstants.h \ $$PWD/editor/abstractliveedittool.h \ $$PWD/editor/liveselectiontool.h \ $$PWD/editor/livelayeritem.h \ @@ -26,11 +27,11 @@ HEADERS += \ $$PWD/editor/colorpickertool.h \ $$PWD/editor/qmltoolbar.h \ $$PWD/editor/toolbarcolorbox.h \ - $$PWD/qdeclarativeviewobserver_p.h + $$PWD/qdeclarativeviewinspector_p.h SOURCES += \ - $$PWD/qdeclarativeviewobserver.cpp \ - $$PWD/qdeclarativeobserverservice.cpp \ + $$PWD/qdeclarativeviewinspector.cpp \ + $$PWD/qdeclarativeinspectorservice.cpp \ $$PWD/editor/abstractliveedittool.cpp \ $$PWD/editor/liveselectiontool.cpp \ $$PWD/editor/livelayeritem.cpp \ diff --git a/share/qtcreator/qml/qmlobserver/qmlruntime.cpp b/share/qtcreator/qml/qmlobserver/qmlruntime.cpp index ef6542ca24..ae2a34a578 100644 --- a/share/qtcreator/qml/qmlobserver/qmlruntime.cpp +++ b/share/qtcreator/qml/qmlobserver/qmlruntime.cpp @@ -54,8 +54,8 @@ #include #endif -#include -#include +#include +#include #include #include @@ -648,7 +648,7 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) } canvas = new DragAndDropView(this); - observer = new QmlJSDebugger::QDeclarativeViewObserver(canvas, this); + inspector = new QmlJSDebugger::QDeclarativeViewInspector(canvas, this); new QmlJSDebugger::JSDebuggerAgent(canvas->engine()); canvas->setAttribute(Qt::WA_OpaquePaintEvent); @@ -698,7 +698,7 @@ void QDeclarativeViewer::setDesignModeBehavior(bool value) { if (designModeBehaviorAction) designModeBehaviorAction->setChecked(value); - observer->setDesignModeBehavior(value); + inspector->setDesignModeBehavior(value); } void QDeclarativeViewer::enableExperimentalGestures() @@ -777,7 +777,7 @@ void QDeclarativeViewer::createMenu() speedAction->setData(10.0f); playSpeedMenuActions->addAction(speedAction); - pauseAnimationsAction = playSpeedMenu->addAction(tr("Pause"), observer, SLOT(setAnimationPaused(bool))); + pauseAnimationsAction = playSpeedMenu->addAction(tr("Pause"), inspector, SLOT(setAnimationPaused(bool))); pauseAnimationsAction->setCheckable(true); pauseAnimationsAction->setShortcut(QKeySequence("Ctrl+.")); @@ -790,30 +790,30 @@ void QDeclarativeViewer::createMenu() QAction *playSpeedAction = new QAction(tr("Animations"), this); playSpeedAction->setMenu(playSpeedMenu); - connect(observer, SIGNAL(animationSpeedChanged(qreal)), SLOT(animationSpeedChanged(qreal))); - connect(observer, SIGNAL(animationPausedChanged(bool)), pauseAnimationsAction, SLOT(setChecked(bool))); + connect(inspector, SIGNAL(animationSpeedChanged(qreal)), SLOT(animationSpeedChanged(qreal))); + connect(inspector, SIGNAL(animationPausedChanged(bool)), pauseAnimationsAction, SLOT(setChecked(bool))); showWarningsWindow = new QAction(tr("Show Warnings"), this); showWarningsWindow->setCheckable((true)); showWarningsWindow->setChecked(loggerWindow->isVisible()); connect(showWarningsWindow, SIGNAL(triggered(bool)), this, SLOT(showWarnings(bool))); - designModeBehaviorAction = new QAction(tr("&Observer Mode"), this); + designModeBehaviorAction = new QAction(tr("&Inspector Mode"), this); designModeBehaviorAction->setShortcut(QKeySequence("Ctrl+D")); designModeBehaviorAction->setCheckable(true); - designModeBehaviorAction->setChecked(observer->designModeBehavior()); - designModeBehaviorAction->setEnabled(QmlJSDebugger::QDeclarativeObserverService::hasDebuggingClient()); + designModeBehaviorAction->setChecked(inspector->designModeBehavior()); + designModeBehaviorAction->setEnabled(QmlJSDebugger::QDeclarativeInspectorService::hasDebuggingClient()); connect(designModeBehaviorAction, SIGNAL(triggered(bool)), this, SLOT(setDesignModeBehavior(bool))); - connect(observer, SIGNAL(designModeBehaviorChanged(bool)), designModeBehaviorAction, SLOT(setChecked(bool))); - connect(QmlJSDebugger::QDeclarativeObserverService::instance(), SIGNAL(debuggingClientChanged(bool)), + connect(inspector, SIGNAL(designModeBehaviorChanged(bool)), designModeBehaviorAction, SLOT(setChecked(bool))); + connect(QmlJSDebugger::QDeclarativeInspectorService::instance(), SIGNAL(debuggingClientChanged(bool)), designModeBehaviorAction, SLOT(setEnabled(bool))); appOnTopAction = new QAction(tr("Keep Window on Top"), this); appOnTopAction->setCheckable(true); - appOnTopAction->setChecked(observer->showAppOnTop()); + appOnTopAction->setChecked(inspector->showAppOnTop()); - connect(appOnTopAction, SIGNAL(triggered(bool)), observer, SLOT(setShowAppOnTop(bool))); - connect(observer, SIGNAL(showAppOnTopChanged(bool)), appOnTopAction, SLOT(setChecked(bool))); + connect(appOnTopAction, SIGNAL(triggered(bool)), inspector, SLOT(setShowAppOnTop(bool))); + connect(inspector, SIGNAL(showAppOnTopChanged(bool)), appOnTopAction, SLOT(setChecked(bool))); QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this); connect(proxyAction, SIGNAL(triggered()), this, SLOT(showProxySettings())); @@ -1070,12 +1070,12 @@ void QDeclarativeViewer::toggleRecording() void QDeclarativeViewer::pauseAnimations() { - observer->setAnimationPaused(true); + inspector->setAnimationPaused(true); } void QDeclarativeViewer::stepAnimations() { - observer->setAnimationPaused(false); + inspector->setAnimationPaused(false); QTimer::singleShot(m_stepSize, this, SLOT(pauseAnimations())); } @@ -1090,7 +1090,7 @@ void QDeclarativeViewer::setAnimationStep() void QDeclarativeViewer::changeAnimationSpeed() { if (QAction *action = qobject_cast(sender())) - observer->setAnimationSpeed(action->data().toFloat()); + inspector->setAnimationSpeed(action->data().toFloat()); } void QDeclarativeViewer::addLibraryPath(const QString& lib) diff --git a/share/qtcreator/qml/qmlobserver/qmlruntime.h b/share/qtcreator/qml/qmlobserver/qmlruntime.h index 992faa4258..24e9ce76ca 100644 --- a/share/qtcreator/qml/qmlobserver/qmlruntime.h +++ b/share/qtcreator/qml/qmlobserver/qmlruntime.h @@ -40,7 +40,7 @@ #include "loggerwidget.h" namespace QmlJSDebugger { - class QDeclarativeViewObserver; + class QDeclarativeViewInspector; } QT_BEGIN_NAMESPACE @@ -156,7 +156,7 @@ private: LoggerWidget *loggerWindow; QDeclarativeView *canvas; - QmlJSDebugger::QDeclarativeViewObserver *observer; + QmlJSDebugger::QDeclarativeViewInspector *inspector; QSize initialSize; QString currentFileOrUrl; QTimer recordTimer; diff --git a/src/plugins/qmljsinspector/images/inspectormode.png b/src/plugins/qmljsinspector/images/inspectormode.png new file mode 100644 index 0000000000..daed21c944 Binary files /dev/null and b/src/plugins/qmljsinspector/images/inspectormode.png differ diff --git a/src/plugins/qmljsinspector/images/observermode.png b/src/plugins/qmljsinspector/images/observermode.png deleted file mode 100644 index daed21c944..0000000000 Binary files a/src/plugins/qmljsinspector/images/observermode.png and /dev/null differ diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp index f264966b34..5bc1ce6b08 100644 --- a/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp +++ b/src/plugins/qmljsinspector/qmlinspectortoolbar.cpp @@ -66,7 +66,7 @@ static QToolButton *toolButton(QAction *action) QmlInspectorToolBar::QmlInspectorToolBar(QObject *parent) : QObject(parent), m_fromQmlAction(0), - m_observerModeAction(0), + m_inspectorModeAction(0), m_playAction(0), m_selectAction(0), m_zoomAction(0), @@ -88,7 +88,7 @@ void QmlInspectorToolBar::setEnabled(bool value) { m_fromQmlAction->setEnabled(value); m_showAppOnTopAction->setEnabled(value); - m_observerModeAction->setEnabled(value); + m_inspectorModeAction->setEnabled(value); m_playAction->setEnabled(value); m_selectAction->setEnabled(value); m_zoomAction->setEnabled(value); @@ -101,7 +101,7 @@ void QmlInspectorToolBar::enable() setEnabled(true); m_emitSignals = false; m_showAppOnTopAction->setChecked(false); - m_observerModeAction->setChecked(false); + m_inspectorModeAction->setChecked(false); setAnimationSpeed(1.0f); activateDesignModeOnClick(); m_emitSignals = true; @@ -165,7 +165,7 @@ void QmlInspectorToolBar::setAnimationPaused(bool paused) void QmlInspectorToolBar::setDesignModeBehavior(bool inDesignMode) { m_emitSignals = false; - m_observerModeAction->setChecked(inDesignMode); + m_inspectorModeAction->setChecked(inDesignMode); activateDesignModeOnClick(); m_emitSignals = true; } @@ -188,9 +188,9 @@ void QmlInspectorToolBar::createActions(const Core::Context &context) m_showAppOnTopAction = new QAction(QIcon(QLatin1String(":/qml/images/app-on-top.png")), tr("Show application on top"), this); - m_observerModeAction = - new QAction(QIcon(QLatin1String(":/qml/images/observermode.png")), - tr("Observer Mode"), this); + m_inspectorModeAction = + new QAction(QIcon(QLatin1String(":/qml/images/inspectormode.png")), + tr("Inspector Mode"), this); m_playAction = new QAction(m_pauseIcon, tr("Play/Pause Animations"), this); m_selectAction = @@ -207,13 +207,13 @@ void QmlInspectorToolBar::createActions(const Core::Context &context) m_fromQmlAction->setChecked(true); m_showAppOnTopAction->setCheckable(true); m_showAppOnTopAction->setChecked(false); - m_observerModeAction->setCheckable(true); - m_observerModeAction->setChecked(false); + m_inspectorModeAction->setCheckable(true); + m_inspectorModeAction->setChecked(false); m_selectAction->setCheckable(true); m_zoomAction->setCheckable(true); m_colorPickerAction->setCheckable(true); - am->registerAction(m_observerModeAction, Constants::DESIGNMODE_ACTION, context); + am->registerAction(m_inspectorModeAction, Constants::DESIGNMODE_ACTION, context); Core::Command *command = am->registerAction(m_playAction, Constants::PLAY_ACTION, context); command->setAttribute(Core::Command::CA_UpdateIcon); am->registerAction(m_selectAction, Constants::SELECT_ACTION, context); @@ -292,7 +292,7 @@ void QmlInspectorToolBar::createActions(const Core::Context &context) connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml())); connect(m_showAppOnTopAction, SIGNAL(triggered()), SLOT(showAppOnTopClick())); - connect(m_observerModeAction, SIGNAL(triggered()), SLOT(activateDesignModeOnClick())); + connect(m_inspectorModeAction, SIGNAL(triggered()), SLOT(activateDesignModeOnClick())); connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick())); connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick())); connect(m_selectAction, SIGNAL(triggered()), SLOT(activateSelectToolOnClick())); @@ -322,7 +322,7 @@ void QmlInspectorToolBar::changeAnimationSpeed() void QmlInspectorToolBar::activateDesignModeOnClick() { - bool checked = m_observerModeAction->isChecked(); + bool checked = m_inspectorModeAction->isChecked(); m_selectAction->setEnabled(checked); m_zoomAction->setEnabled(checked); diff --git a/src/plugins/qmljsinspector/qmlinspectortoolbar.h b/src/plugins/qmljsinspector/qmlinspectortoolbar.h index ab89a97f2d..d886aacc46 100644 --- a/src/plugins/qmljsinspector/qmlinspectortoolbar.h +++ b/src/plugins/qmljsinspector/qmlinspectortoolbar.h @@ -127,7 +127,7 @@ private: QToolButton *m_operateByInstructionButton; QAction *m_fromQmlAction; - QAction *m_observerModeAction; + QAction *m_inspectorModeAction; QAction *m_playAction; QAction *m_selectAction; QAction *m_zoomAction; diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.cpp b/src/plugins/qmljsinspector/qmljsclientproxy.cpp index 93c8eb60a2..aff9c46e7f 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.cpp +++ b/src/plugins/qmljsinspector/qmljsclientproxy.cpp @@ -32,7 +32,7 @@ #include "qmljsclientproxy.h" #include "qmljsprivateapi.h" -#include "qmljsobserverclient.h" +#include "qmljsinspectorclient.h" #include "qmljsinspector.h" #include @@ -52,7 +52,7 @@ ClientProxy::ClientProxy(Debugger::QmlAdapter *adapter, QObject *parent) : QObject(parent) , m_adapter(adapter) , m_engineClient(0) - , m_observerClient(0) + , m_inspectorClient(0) , m_engineQuery(0) , m_contextQuery(0) , m_isConnected(false) @@ -69,33 +69,33 @@ void ClientProxy::connectToServer() connect(m_engineClient, SIGNAL(newObjects()), this, SLOT(newObjects())); - m_observerClient = new QmlJSObserverClient(m_adapter->connection(), this); + m_inspectorClient = new QmlJSInspectorClient(m_adapter->connection(), this); - connect(m_observerClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)), + connect(m_inspectorClient, SIGNAL(connectedStatusChanged(QDeclarativeDebugClient::Status)), this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); - connect(m_observerClient, SIGNAL(currentObjectsChanged(QList)), + connect(m_inspectorClient, SIGNAL(currentObjectsChanged(QList)), SLOT(onCurrentObjectsChanged(QList))); - connect(m_observerClient, SIGNAL(colorPickerActivated()), + connect(m_inspectorClient, SIGNAL(colorPickerActivated()), SIGNAL(colorPickerActivated())); - connect(m_observerClient, SIGNAL(zoomToolActivated()), + connect(m_inspectorClient, SIGNAL(zoomToolActivated()), SIGNAL(zoomToolActivated())); - connect(m_observerClient, SIGNAL(selectToolActivated()), + connect(m_inspectorClient, SIGNAL(selectToolActivated()), SIGNAL(selectToolActivated())); - connect(m_observerClient, SIGNAL(selectMarqueeToolActivated()), + connect(m_inspectorClient, SIGNAL(selectMarqueeToolActivated()), SIGNAL(selectMarqueeToolActivated())); - connect(m_observerClient, SIGNAL(animationSpeedChanged(qreal)), + connect(m_inspectorClient, SIGNAL(animationSpeedChanged(qreal)), SIGNAL(animationSpeedChanged(qreal))); - connect(m_observerClient, SIGNAL(animationPausedChanged(bool)), + connect(m_inspectorClient, SIGNAL(animationPausedChanged(bool)), SIGNAL(animationPausedChanged(bool))); - connect(m_observerClient, SIGNAL(designModeBehaviorChanged(bool)), + connect(m_inspectorClient, SIGNAL(designModeBehaviorChanged(bool)), SIGNAL(designModeBehaviorChanged(bool))); - connect(m_observerClient, SIGNAL(showAppOnTopChanged(bool)), + connect(m_inspectorClient, SIGNAL(showAppOnTopChanged(bool)), SIGNAL(showAppOnTopChanged(bool))); - connect(m_observerClient, SIGNAL(reloaded()), this, + connect(m_inspectorClient, SIGNAL(reloaded()), this, SIGNAL(serverReloaded())); - connect(m_observerClient, SIGNAL(selectedColorChanged(QColor)), + connect(m_inspectorClient, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); - connect(m_observerClient, SIGNAL(logActivity(QString,QString)), + connect(m_inspectorClient, SIGNAL(logActivity(QString,QString)), m_adapter, SLOT(logServiceActivity(QString,QString))); updateConnected(); @@ -150,7 +150,7 @@ void ClientProxy::setSelectedItemsByDebugId(const QList &debugIds) if (!isConnected()) return; - m_observerClient->setCurrentObjects(debugIds); + m_inspectorClient->setCurrentObjects(debugIds); } void ClientProxy::setSelectedItemsByObjectId(const QList &objectRefs) @@ -162,7 +162,7 @@ void ClientProxy::setSelectedItemsByObjectId(const QListsetCurrentObjects(debugIds); + m_inspectorClient->setCurrentObjects(debugIds); } } @@ -336,7 +336,7 @@ QDeclarativeDebugExpressionQuery *ClientProxy::queryExpressionResult(int objectD void ClientProxy::clearComponentCache() { if (isConnected()) - m_observerClient->clearComponentCache(); + m_inspectorClient->clearComponentCache(); } bool ClientProxy::addObjectWatch(int objectDebugId) @@ -500,10 +500,10 @@ void ClientProxy::objectTreeFetched(QDeclarativeDebugQuery::State state) emit objectTreeUpdated(); if (isConnected()) { - if (!m_observerClient->currentObjects().isEmpty()) - onCurrentObjectsChanged(m_observerClient->currentObjects(), false); + if (!m_inspectorClient->currentObjects().isEmpty()) + onCurrentObjectsChanged(m_inspectorClient->currentObjects(), false); - m_observerClient->setObjectIdList(m_rootObjects); + m_inspectorClient->setObjectIdList(m_rootObjects); } } } @@ -536,78 +536,78 @@ void ClientProxy::buildDebugIdHashRecursive(const QDeclarativeDebugObjectReferen void ClientProxy::reloadQmlViewer() { if (isConnected()) - m_observerClient->reloadViewer(); + m_inspectorClient->reloadViewer(); } void ClientProxy::setDesignModeBehavior(bool inDesignMode) { if (isConnected()) - m_observerClient->setDesignModeBehavior(inDesignMode); + m_inspectorClient->setDesignModeBehavior(inDesignMode); } void ClientProxy::setAnimationSpeed(qreal slowDownFactor) { if (isConnected()) - m_observerClient->setAnimationSpeed(slowDownFactor); + m_inspectorClient->setAnimationSpeed(slowDownFactor); } void ClientProxy::setAnimationPaused(bool paused) { if (isConnected()) - m_observerClient->setAnimationPaused(paused); + m_inspectorClient->setAnimationPaused(paused); } void ClientProxy::changeToColorPickerTool() { if (isConnected()) - m_observerClient->changeToColorPickerTool(); + m_inspectorClient->changeToColorPickerTool(); } void ClientProxy::changeToZoomTool() { if (isConnected()) - m_observerClient->changeToZoomTool(); + m_inspectorClient->changeToZoomTool(); } void ClientProxy::changeToSelectTool() { if (isConnected()) - m_observerClient->changeToSelectTool(); + m_inspectorClient->changeToSelectTool(); } void ClientProxy::changeToSelectMarqueeTool() { if (isConnected()) - m_observerClient->changeToSelectMarqueeTool(); + m_inspectorClient->changeToSelectMarqueeTool(); } void ClientProxy::showAppOnTop(bool showOnTop) { if (isConnected()) - m_observerClient->showAppOnTop(showOnTop); + m_inspectorClient->showAppOnTop(showOnTop); } void ClientProxy::createQmlObject(const QString &qmlText, int parentDebugId, const QStringList &imports, const QString &filename, int order) { if (isConnected()) - m_observerClient->createQmlObject(qmlText, parentDebugId, imports, filename, order); + m_inspectorClient->createQmlObject(qmlText, parentDebugId, imports, filename, order); } void ClientProxy::destroyQmlObject(int debugId) { if (isConnected()) - m_observerClient->destroyQmlObject(debugId); + m_inspectorClient->destroyQmlObject(debugId); } void ClientProxy::reparentQmlObject(int debugId, int newParent) { if (isConnected()) - m_observerClient->reparentQmlObject(debugId, newParent); + m_inspectorClient->reparentQmlObject(debugId, newParent); } void ClientProxy::updateConnected() { - bool isConnected = m_observerClient && m_observerClient->status() == QDeclarativeDebugClient::Enabled + bool isConnected = m_inspectorClient && m_inspectorClient->status() == QDeclarativeDebugClient::Enabled && m_engineClient && m_engineClient->status() == QDeclarativeEngineDebug::Enabled; if (isConnected != m_isConnected) { diff --git a/src/plugins/qmljsinspector/qmljsclientproxy.h b/src/plugins/qmljsinspector/qmljsclientproxy.h index e07483365e..4513cbc52b 100644 --- a/src/plugins/qmljsinspector/qmljsclientproxy.h +++ b/src/plugins/qmljsinspector/qmljsclientproxy.h @@ -50,7 +50,7 @@ typedef QHash, QHash, QList > > DebugId namespace Internal { class InspectorPlugin; -class QmlJSObserverClient; +class QmlJSInspectorClient; class ClientProxy : public QObject { @@ -167,7 +167,7 @@ private: Debugger::QmlAdapter *m_adapter; QDeclarativeEngineDebug *m_engineClient; - QmlJSObserverClient *m_observerClient; + QmlJSInspectorClient *m_inspectorClient; QDeclarativeDebugEnginesQuery *m_engineQuery; QDeclarativeDebugRootContextQuery *m_contextQuery; diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp index 527898e45c..f6e7db1e8d 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.cpp +++ b/src/plugins/qmljsinspector/qmljsinspector.cpp @@ -338,7 +338,7 @@ void InspectorUi::disconnected() m_qmlEngine = 0; resetViews(); - applyChangesToQmlObserverHelper(false); + applyChangesToQmlInspectorHelper(false); QHashIterator iter(m_textPreviews); while (iter.hasNext()) { @@ -417,7 +417,7 @@ void InspectorUi::initializeDocuments() createPreviewForEditor(editor); } - applyChangesToQmlObserverHelper(true); + applyChangesToQmlInspectorHelper(true); } void InspectorUi::serverReloaded() @@ -730,9 +730,9 @@ void InspectorUi::setupDockWidgets() m_propertyInspector = new QmlJSPropertyInspector; - QWidget *observerWidget = new QWidget; - observerWidget->setWindowTitle(tr("QML Observer")); - observerWidget->setObjectName(Debugger::Constants::DOCKWIDGET_QML_INSPECTOR); + QWidget *inspectorWidget = new QWidget; + inspectorWidget->setWindowTitle(tr("QML Inspector")); + inspectorWidget->setObjectName(Debugger::Constants::DOCKWIDGET_QML_INSPECTOR); QWidget *pathAndFilterWidget = new StyledBackground; pathAndFilterWidget->setMaximumHeight(m_crumblePath->height()); @@ -747,14 +747,14 @@ void InspectorUi::setupDockWidgets() pathAndFilterLayout->addWidget(m_crumblePath); pathAndFilterLayout->addWidget(m_filterExp); - QVBoxLayout *wlay = new QVBoxLayout(observerWidget); + QVBoxLayout *wlay = new QVBoxLayout(inspectorWidget); wlay->setMargin(0); wlay->setSpacing(0); - observerWidget->setLayout(wlay); + inspectorWidget->setLayout(wlay); wlay->addWidget(pathAndFilterWidget); wlay->addWidget(m_propertyInspector); - QDockWidget *dock = mw->createDockWidget(Debugger::QmlLanguage, observerWidget); + QDockWidget *dock = mw->createDockWidget(Debugger::QmlLanguage, inspectorWidget); dock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); dock->setTitleBarWidget(new QWidget(dock)); } @@ -793,18 +793,18 @@ QString InspectorUi::findFileInProject(const QString &originalPath) const return m_projectFinder.findFile(originalPath); } -void InspectorUi::setApplyChangesToQmlObserver(bool applyChanges) +void InspectorUi::setApplyChangesToQmlInspector(bool applyChanges) { emit livePreviewActivated(applyChanges); - applyChangesToQmlObserverHelper(applyChanges); + applyChangesToQmlInspectorHelper(applyChanges); } -void InspectorUi::applyChangesToQmlObserverHelper(bool applyChanges) +void InspectorUi::applyChangesToQmlInspectorHelper(bool applyChanges) { QHashIterator iter(m_textPreviews); while (iter.hasNext()) { iter.next(); - iter.value()->setApplyChangesToQmlObserver(applyChanges); + iter.value()->setApplyChangesToQmlInspector(applyChanges); } } @@ -833,7 +833,7 @@ void InspectorUi::updatePendingPreviewDocuments(QmlJS::Document::Ptr doc) void InspectorUi::disableLivePreview() { - setApplyChangesToQmlObserver(false); + setApplyChangesToQmlInspector(false); } void InspectorUi::connectSignals() @@ -875,7 +875,7 @@ void InspectorUi::connectSignals() m_toolBar, SLOT(setAnimationPaused(bool))); connect(m_toolBar, SIGNAL(applyChangesFromQmlFileTriggered(bool)), - this, SLOT(setApplyChangesToQmlObserver(bool))); + this, SLOT(setApplyChangesToQmlInspector(bool))); connect(m_toolBar, SIGNAL(designModeSelected(bool)), m_clientProxy, SLOT(setDesignModeBehavior(bool))); diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h index 3e0077226d..4fce908d6c 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.h +++ b/src/plugins/qmljsinspector/qmljsinspector.h @@ -111,7 +111,7 @@ signals: public slots: void reloadQmlViewer(); void serverReloaded(); - void setApplyChangesToQmlObserver(bool applyChanges); + void setApplyChangesToQmlInspector(bool applyChanges); private slots: void enable(); @@ -141,7 +141,7 @@ private: void resetViews(); void initializeDocuments(); - void applyChangesToQmlObserverHelper(bool applyChanges); + void applyChangesToQmlInspectorHelper(bool applyChanges); void setupDockWidgets(); QString filenameForShadowBuildFile(const QString &filename) const; void populateCrumblePath(const QDeclarativeDebugObjectReference &objRef); diff --git a/src/plugins/qmljsinspector/qmljsinspector.pro b/src/plugins/qmljsinspector/qmljsinspector.pro index a7a47c9d68..50be9aba5d 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.pro +++ b/src/plugins/qmljsinspector/qmljsinspector.pro @@ -16,7 +16,7 @@ qmljsinspector.h \ qmlinspectortoolbar.h \ qmljslivetextpreview.h \ qmljstoolbarcolorbox.h \ -qmljsobserverclient.h \ +qmljsinspectorclient.h \ qmljscontextcrumblepath.h \ qmljsinspectorsettings.h \ qmljspropertyinspector.h @@ -28,7 +28,7 @@ qmljsinspector.cpp \ qmlinspectortoolbar.cpp \ qmljslivetextpreview.cpp \ qmljstoolbarcolorbox.cpp \ -qmljsobserverclient.cpp \ +qmljsinspectorclient.cpp \ qmljscontextcrumblepath.cpp \ qmljsinspectorsettings.cpp \ qmljspropertyinspector.cpp diff --git a/src/plugins/qmljsinspector/qmljsinspector.qrc b/src/plugins/qmljsinspector/qmljsinspector.qrc index f1e4ceb212..8c1ed3975f 100644 --- a/src/plugins/qmljsinspector/qmljsinspector.qrc +++ b/src/plugins/qmljsinspector/qmljsinspector.qrc @@ -18,7 +18,7 @@ images/zoom-small.png images/select-marquee-small.png images/color-picker-small-hicontrast.png - images/observermode.png + images/inspectormode.png images/app-on-top.png diff --git a/src/plugins/qmljsinspector/qmljsinspectorclient.cpp b/src/plugins/qmljsinspector/qmljsinspectorclient.cpp new file mode 100644 index 0000000000..77527d6bb2 --- /dev/null +++ b/src/plugins/qmljsinspector/qmljsinspectorclient.cpp @@ -0,0 +1,479 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#include "qmljsinspectorclient.h" +#include "qmljsclientproxy.h" +#include "qmljsinspectorconstants.h" + +#include + +using namespace QmlJSDebugger; + +namespace QmlJSInspector { +namespace Internal { + +QmlJSInspectorClient::QmlJSInspectorClient(QDeclarativeDebugConnection *client, + QObject * /*parent*/) + : QDeclarativeDebugClient(QLatin1String("QDeclarativeObserverMode"), client) , + m_connection(client) +{ +} + +void QmlJSInspectorClient::statusChanged(Status status) +{ + emit connectedStatusChanged(status); +} + +void QmlJSInspectorClient::messageReceived(const QByteArray &message) +{ + QDataStream ds(message); + + InspectorProtocol::Message type; + ds >> type; + + switch (type) { + case InspectorProtocol::CurrentObjectsChanged: { + int objectCount; + ds >> objectCount; + + log(LogReceive, type, QString("%1 [list of debug ids]").arg(objectCount)); + + m_currentDebugIds.clear(); + + for (int i = 0; i < objectCount; ++i) { + int debugId; + ds >> debugId; + if (debugId != -1) + m_currentDebugIds << debugId; + } + + emit currentObjectsChanged(m_currentDebugIds); + break; + } + case InspectorProtocol::ToolChanged: { + int toolId; + ds >> toolId; + + log(LogReceive, type, QString::number(toolId)); + + if (toolId == Constants::ColorPickerMode) { + emit colorPickerActivated(); + } else if (toolId == Constants::ZoomMode) { + emit zoomToolActivated(); + } else if (toolId == Constants::SelectionToolMode) { + emit selectToolActivated(); + } else if (toolId == Constants::MarqueeSelectionToolMode) { + emit selectMarqueeToolActivated(); + } + break; + } + case InspectorProtocol::AnimationSpeedChanged: { + qreal slowDownFactor; + ds >> slowDownFactor; + + log(LogReceive, type, QString::number(slowDownFactor)); + + emit animationSpeedChanged(slowDownFactor); + break; + } + case InspectorProtocol::AnimationPausedChanged: { + bool paused; + ds >> paused; + + log(LogReceive, type, paused ? QLatin1String("true") : QLatin1String("false")); + + emit animationPausedChanged(paused); + break; + } + case InspectorProtocol::SetDesignMode: { + bool inDesignMode; + ds >> inDesignMode; + + log(LogReceive, type, QLatin1String(inDesignMode ? "true" : "false")); + + emit designModeBehaviorChanged(inDesignMode); + break; + } + case InspectorProtocol::ShowAppOnTop: { + bool showAppOnTop; + ds >> showAppOnTop; + + log(LogReceive, type, QLatin1String(showAppOnTop ? "true" : "false")); + + emit showAppOnTopChanged(showAppOnTop); + break; + } + case InspectorProtocol::Reloaded: { + log(LogReceive, type); + emit reloaded(); + break; + } + case InspectorProtocol::ColorChanged: { + QColor col; + ds >> col; + + log(LogReceive, type, col.name()); + + emit selectedColorChanged(col); + break; + } + default: + qWarning() << "Warning: Not handling message:" << type; + } +} + +QList QmlJSInspectorClient::currentObjects() const +{ + return m_currentDebugIds; +} + +void QmlJSInspectorClient::setCurrentObjects(const QList &debugIds) +{ + if (!m_connection || !m_connection->isConnected()) + return; + + if (debugIds == m_currentDebugIds) + return; + + m_currentDebugIds = debugIds; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::SetCurrentObjects; + ds << cmd + << debugIds.length(); + + foreach (int id, debugIds) { + ds << id; + } + + log(LogSend, cmd, QString("%1 [list of ids]").arg(debugIds.length())); + + sendMessage(message); +} + +void recurseObjectIdList(const QDeclarativeDebugObjectReference &ref, QList &debugIds, QList &objectIds) +{ + debugIds << ref.debugId(); + objectIds << ref.idString(); + foreach (const QDeclarativeDebugObjectReference &child, ref.children()) + recurseObjectIdList(child, debugIds, objectIds); +} + +void QmlJSInspectorClient::setObjectIdList(const QList &objectRoots) +{ + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + QList debugIds; + QList objectIds; + + foreach (const QDeclarativeDebugObjectReference &ref, objectRoots) + recurseObjectIdList(ref, debugIds, objectIds); + + InspectorProtocol::Message cmd = InspectorProtocol::ObjectIdList; + ds << cmd + << debugIds.length(); + + Q_ASSERT(debugIds.length() == objectIds.length()); + + for(int i = 0; i < debugIds.length(); ++i) { + ds << debugIds[i] << objectIds[i]; + } + + log(LogSend, cmd, QString("%1 %2 [list of debug / object ids]").arg(debugIds.length())); + + sendMessage(message); +} + +void QmlJSInspectorClient::clearComponentCache() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::ClearComponentCache; + ds << cmd; + + log(LogSend, cmd); + + sendMessage(message); +} + +void QmlJSInspectorClient::reloadViewer() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::Reload; + ds << cmd; + + log(LogSend, cmd); + + sendMessage(message); +} + +void QmlJSInspectorClient::setDesignModeBehavior(bool inDesignMode) +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::SetDesignMode; + ds << cmd + << inDesignMode; + + log(LogSend, cmd, QLatin1String(inDesignMode ? "true" : "false")); + + sendMessage(message); +} + +void QmlJSInspectorClient::setAnimationSpeed(qreal slowDownFactor) +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::SetAnimationSpeed; + ds << cmd + << slowDownFactor; + + + log(LogSend, cmd, QString::number(slowDownFactor)); + + sendMessage(message); +} + +void QmlJSInspectorClient::setAnimationPaused(bool paused) +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::SetAnimationPaused; + ds << cmd + << paused; + + log(LogSend, cmd, paused ? QLatin1String("true") : QLatin1String("false")); + + sendMessage(message); +} + +void QmlJSInspectorClient::changeToColorPickerTool() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool; + InspectorProtocol::Tool tool = InspectorProtocol::ColorPickerTool; + ds << cmd + << tool; + + log(LogSend, cmd, InspectorProtocol::toString(tool)); + + sendMessage(message); +} + +void QmlJSInspectorClient::changeToSelectTool() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool; + InspectorProtocol::Tool tool = InspectorProtocol::SelectTool; + ds << cmd + << tool; + + log(LogSend, cmd, InspectorProtocol::toString(tool)); + + sendMessage(message); +} + +void QmlJSInspectorClient::changeToSelectMarqueeTool() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool; + InspectorProtocol::Tool tool = InspectorProtocol::SelectMarqueeTool; + ds << cmd + << tool; + + log(LogSend, cmd, InspectorProtocol::toString(tool)); + + sendMessage(message); +} + +void QmlJSInspectorClient::changeToZoomTool() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::ChangeTool; + InspectorProtocol::Tool tool = InspectorProtocol::ZoomTool; + ds << cmd + << tool; + + log(LogSend, cmd, InspectorProtocol::toString(tool)); + + sendMessage(message); +} + +void QmlJSInspectorClient::showAppOnTop(bool showOnTop) +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::ShowAppOnTop; + ds << cmd << showOnTop; + + log(LogSend, cmd, QLatin1String(showOnTop ? "true" : "false")); + + sendMessage(message); +} + +void QmlJSInspectorClient::createQmlObject(const QString &qmlText, int parentDebugId, + const QStringList &imports, const QString &filename, int order) +{ + if (!m_connection || !m_connection->isConnected()) + return; + + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::CreateObject; + ds << cmd + << qmlText + << parentDebugId + << imports + << filename + << order; + + log(LogSend, cmd, QString("%1 %2 [%3] %4").arg(qmlText, QString::number(parentDebugId), + imports.join(","), filename)); + + sendMessage(message); +} + +void QmlJSInspectorClient::destroyQmlObject(int debugId) +{ + if (!m_connection || !m_connection->isConnected()) + return; + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::DestroyObject; + ds << cmd << debugId; + + log(LogSend, cmd, QString::number(debugId)); + + sendMessage(message); +} + +void QmlJSInspectorClient::reparentQmlObject(int debugId, int newParent) +{ + if (!m_connection || !m_connection->isConnected()) + return; + QByteArray message; + QDataStream ds(&message, QIODevice::WriteOnly); + + InspectorProtocol::Message cmd = InspectorProtocol::MoveObject; + ds << cmd + << debugId + << newParent; + + log(LogSend, cmd, QString("%1 %2").arg(QString::number(debugId), + QString::number(newParent))); + + sendMessage(message); +} + + +void QmlJSInspectorClient::applyChangesToQmlFile() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + // TODO +} + +void QmlJSInspectorClient::applyChangesFromQmlFile() +{ + if (!m_connection || !m_connection->isConnected()) + return; + + // TODO +} + +void QmlJSInspectorClient::log(LogDirection direction, InspectorProtocol::Message message, + const QString &extra) +{ + QString msg; + if (direction == LogSend) + msg += QLatin1String(" sending "); + else + msg += QLatin1String(" receiving "); + + msg += InspectorProtocol::toString(message); + msg += QLatin1Char(' '); + msg += extra; + emit logActivity(name(), msg); +} + +} // namespace Internal +} // namespace QmlJSInspector diff --git a/src/plugins/qmljsinspector/qmljsinspectorclient.h b/src/plugins/qmljsinspector/qmljsinspectorclient.h new file mode 100644 index 0000000000..3eb8671ab9 --- /dev/null +++ b/src/plugins/qmljsinspector/qmljsinspectorclient.h @@ -0,0 +1,113 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** 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. +** +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at info@qt.nokia.com. +** +**************************************************************************/ + +#ifndef QMLJSDESIGNDEBUGCLIENT_H +#define QMLJSDESIGNDEBUGCLIENT_H + +#include "qmljsprivateapi.h" + +#include + +namespace QmlJSInspector { +namespace Internal { + +class QmlJSInspectorClient : public QDeclarativeDebugClient +{ + Q_OBJECT +public: + explicit QmlJSInspectorClient(QDeclarativeDebugConnection *client, + QObject *parent = 0); + + void setCurrentObjects(const QList &debugIds); + void reloadViewer(); + void setDesignModeBehavior(bool inDesignMode); + void setAnimationSpeed(qreal slowDownFactor); + void setAnimationPaused(bool paused); + void changeToColorPickerTool(); + void changeToSelectTool(); + void changeToSelectMarqueeTool(); + void changeToZoomTool(); + void showAppOnTop(bool showOnTop); + + void createQmlObject(const QString &qmlText, int parentDebugId, + const QStringList &imports, const QString &filename, int order); + void destroyQmlObject(int debugId); + void reparentQmlObject(int debugId, int newParent); + + void applyChangesToQmlFile(); + void applyChangesFromQmlFile(); + + QList currentObjects() const; + + // ### Qt 4.8: remove if we can have access to qdeclarativecontextdata or id's + void setObjectIdList(const QList &objectRoots); + + void clearComponentCache(); + +signals: + void connectedStatusChanged(QDeclarativeDebugClient::Status status); + + void currentObjectsChanged(const QList &debugIds); + void selectedColorChanged(const QColor &color); + void colorPickerActivated(); + void selectToolActivated(); + void selectMarqueeToolActivated(); + void zoomToolActivated(); + void animationSpeedChanged(qreal slowdownFactor); + void animationPausedChanged(bool paused); + void designModeBehaviorChanged(bool inDesignMode); + void showAppOnTopChanged(bool showAppOnTop); + void reloaded(); // the server has reloadetd he document + + void logActivity(QString client, QString message); + +protected: + void statusChanged(Status); + void messageReceived(const QByteArray &); + +private: + enum LogDirection { + LogSend, + LogReceive + }; + + void log(LogDirection direction, + QmlJSDebugger::InspectorProtocol::Message message, + const QString &extra = QString()); + + QList m_currentDebugIds; + QDeclarativeDebugConnection *m_connection; +}; + +} // namespace Internal +} // namespace QmlJSInspector + +#endif // QMLJSDESIGNDEBUGCLIENT_H diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp index 687edf7f00..2ad761bbbb 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.cpp +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.cpp @@ -176,7 +176,7 @@ QmlJSLiveTextPreview::QmlJSLiveTextPreview(const QmlJS::Document::Ptr &doc, : QObject(parent) , m_previousDoc(doc) , m_initialDoc(initDoc) - , m_applyChangesToQmlObserver(true) + , m_applyChangesToQmlInspector(true) , m_clientProxy(clientProxy) { Q_ASSERT(doc->fileName() == initDoc->fileName()); @@ -341,7 +341,7 @@ void QmlJSLiveTextPreview::updateDebugIds() } -class UpdateObserver : public Delta { +class UpdateInspector : public Delta { private: static inline QString stripQuotes(const QString &str) { @@ -509,7 +509,7 @@ protected: } public: - UpdateObserver(ClientProxy *clientProxy) + UpdateInspector(ClientProxy *clientProxy) : appliedChangesToViewer(false) , referenceRefreshRequired(false) , unsyncronizableChanges(QmlJSLiveTextPreview::NoUnsyncronizableChanges) @@ -534,13 +534,13 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc) bool experimentalWarningShown = false; - if (m_applyChangesToQmlObserver) { + if (m_applyChangesToQmlInspector) { m_docWithUnappliedChanges.clear(); if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName() && doc->qmlProgram() && m_previousDoc->qmlProgram()) { - UpdateObserver delta(m_clientProxy.data()); + UpdateInspector delta(m_clientProxy.data()); m_debugIds = delta(m_previousDoc, doc, m_debugIds); if (delta.referenceRefreshRequired) @@ -622,16 +622,16 @@ void QmlJSLiveTextPreview::disableLivePreview() emit disableLivePreviewRequested(); } -void QmlJSLiveTextPreview::setApplyChangesToQmlObserver(bool applyChanges) +void QmlJSLiveTextPreview::setApplyChangesToQmlInspector(bool applyChanges) { - if (applyChanges && !m_applyChangesToQmlObserver) { + if (applyChanges && !m_applyChangesToQmlInspector) { if (m_docWithUnappliedChanges) { - m_applyChangesToQmlObserver = true; + m_applyChangesToQmlInspector = true; documentChanged(m_docWithUnappliedChanges); } } - m_applyChangesToQmlObserver = applyChanges; + m_applyChangesToQmlInspector = applyChanges; } void QmlJSLiveTextPreview::setClientProxy(ClientProxy *clientProxy) diff --git a/src/plugins/qmljsinspector/qmljslivetextpreview.h b/src/plugins/qmljsinspector/qmljslivetextpreview.h index 685eb6f65d..0c8ffbbd3e 100644 --- a/src/plugins/qmljsinspector/qmljslivetextpreview.h +++ b/src/plugins/qmljsinspector/qmljslivetextpreview.h @@ -90,7 +90,7 @@ signals: void disableLivePreviewRequested(); public slots: - void setApplyChangesToQmlObserver(bool applyChanges); + void setApplyChangesToQmlInspector(bool applyChanges); void updateDebugIds(); private slots: @@ -117,7 +117,7 @@ private: QList > m_editors; - bool m_applyChangesToQmlObserver; + bool m_applyChangesToQmlInspector; QmlJS::Document::Ptr m_docWithUnappliedChanges; QWeakPointer m_clientProxy; diff --git a/src/plugins/qmljsinspector/qmljsobserverclient.cpp b/src/plugins/qmljsinspector/qmljsobserverclient.cpp deleted file mode 100644 index 6eaa7733d8..0000000000 --- a/src/plugins/qmljsinspector/qmljsobserverclient.cpp +++ /dev/null @@ -1,479 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#include "qmljsobserverclient.h" -#include "qmljsclientproxy.h" -#include "qmljsinspectorconstants.h" - -#include - -using namespace QmlJSDebugger; - -namespace QmlJSInspector { -namespace Internal { - -QmlJSObserverClient::QmlJSObserverClient(QDeclarativeDebugConnection *client, - QObject * /*parent*/) - : QDeclarativeDebugClient(QLatin1String("QDeclarativeObserverMode"), client) , - m_connection(client) -{ -} - -void QmlJSObserverClient::statusChanged(Status status) -{ - emit connectedStatusChanged(status); -} - -void QmlJSObserverClient::messageReceived(const QByteArray &message) -{ - QDataStream ds(message); - - ObserverProtocol::Message type; - ds >> type; - - switch (type) { - case ObserverProtocol::CurrentObjectsChanged: { - int objectCount; - ds >> objectCount; - - log(LogReceive, type, QString("%1 [list of debug ids]").arg(objectCount)); - - m_currentDebugIds.clear(); - - for (int i = 0; i < objectCount; ++i) { - int debugId; - ds >> debugId; - if (debugId != -1) - m_currentDebugIds << debugId; - } - - emit currentObjectsChanged(m_currentDebugIds); - break; - } - case ObserverProtocol::ToolChanged: { - int toolId; - ds >> toolId; - - log(LogReceive, type, QString::number(toolId)); - - if (toolId == Constants::ColorPickerMode) { - emit colorPickerActivated(); - } else if (toolId == Constants::ZoomMode) { - emit zoomToolActivated(); - } else if (toolId == Constants::SelectionToolMode) { - emit selectToolActivated(); - } else if (toolId == Constants::MarqueeSelectionToolMode) { - emit selectMarqueeToolActivated(); - } - break; - } - case ObserverProtocol::AnimationSpeedChanged: { - qreal slowDownFactor; - ds >> slowDownFactor; - - log(LogReceive, type, QString::number(slowDownFactor)); - - emit animationSpeedChanged(slowDownFactor); - break; - } - case ObserverProtocol::AnimationPausedChanged: { - bool paused; - ds >> paused; - - log(LogReceive, type, paused ? QLatin1String("true") : QLatin1String("false")); - - emit animationPausedChanged(paused); - break; - } - case ObserverProtocol::SetDesignMode: { - bool inDesignMode; - ds >> inDesignMode; - - log(LogReceive, type, QLatin1String(inDesignMode ? "true" : "false")); - - emit designModeBehaviorChanged(inDesignMode); - break; - } - case ObserverProtocol::ShowAppOnTop: { - bool showAppOnTop; - ds >> showAppOnTop; - - log(LogReceive, type, QLatin1String(showAppOnTop ? "true" : "false")); - - emit showAppOnTopChanged(showAppOnTop); - break; - } - case ObserverProtocol::Reloaded: { - log(LogReceive, type); - emit reloaded(); - break; - } - case ObserverProtocol::ColorChanged: { - QColor col; - ds >> col; - - log(LogReceive, type, col.name()); - - emit selectedColorChanged(col); - break; - } - default: - qWarning() << "Warning: Not handling message:" << type; - } -} - -QList QmlJSObserverClient::currentObjects() const -{ - return m_currentDebugIds; -} - -void QmlJSObserverClient::setCurrentObjects(const QList &debugIds) -{ - if (!m_connection || !m_connection->isConnected()) - return; - - if (debugIds == m_currentDebugIds) - return; - - m_currentDebugIds = debugIds; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::SetCurrentObjects; - ds << cmd - << debugIds.length(); - - foreach (int id, debugIds) { - ds << id; - } - - log(LogSend, cmd, QString("%1 [list of ids]").arg(debugIds.length())); - - sendMessage(message); -} - -void recurseObjectIdList(const QDeclarativeDebugObjectReference &ref, QList &debugIds, QList &objectIds) -{ - debugIds << ref.debugId(); - objectIds << ref.idString(); - foreach (const QDeclarativeDebugObjectReference &child, ref.children()) - recurseObjectIdList(child, debugIds, objectIds); -} - -void QmlJSObserverClient::setObjectIdList(const QList &objectRoots) -{ - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - QList debugIds; - QList objectIds; - - foreach (const QDeclarativeDebugObjectReference &ref, objectRoots) - recurseObjectIdList(ref, debugIds, objectIds); - - ObserverProtocol::Message cmd = ObserverProtocol::ObjectIdList; - ds << cmd - << debugIds.length(); - - Q_ASSERT(debugIds.length() == objectIds.length()); - - for(int i = 0; i < debugIds.length(); ++i) { - ds << debugIds[i] << objectIds[i]; - } - - log(LogSend, cmd, QString("%1 %2 [list of debug / object ids]").arg(debugIds.length())); - - sendMessage(message); -} - -void QmlJSObserverClient::clearComponentCache() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::ClearComponentCache; - ds << cmd; - - log(LogSend, cmd); - - sendMessage(message); -} - -void QmlJSObserverClient::reloadViewer() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::Reload; - ds << cmd; - - log(LogSend, cmd); - - sendMessage(message); -} - -void QmlJSObserverClient::setDesignModeBehavior(bool inDesignMode) -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::SetDesignMode; - ds << cmd - << inDesignMode; - - log(LogSend, cmd, QLatin1String(inDesignMode ? "true" : "false")); - - sendMessage(message); -} - -void QmlJSObserverClient::setAnimationSpeed(qreal slowDownFactor) -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::SetAnimationSpeed; - ds << cmd - << slowDownFactor; - - - log(LogSend, cmd, QString::number(slowDownFactor)); - - sendMessage(message); -} - -void QmlJSObserverClient::setAnimationPaused(bool paused) -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::SetAnimationPaused; - ds << cmd - << paused; - - log(LogSend, cmd, paused ? QLatin1String("true") : QLatin1String("false")); - - sendMessage(message); -} - -void QmlJSObserverClient::changeToColorPickerTool() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::ChangeTool; - ObserverProtocol::Tool tool = ObserverProtocol::ColorPickerTool; - ds << cmd - << tool; - - log(LogSend, cmd, ObserverProtocol::toString(tool)); - - sendMessage(message); -} - -void QmlJSObserverClient::changeToSelectTool() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::ChangeTool; - ObserverProtocol::Tool tool = ObserverProtocol::SelectTool; - ds << cmd - << tool; - - log(LogSend, cmd, ObserverProtocol::toString(tool)); - - sendMessage(message); -} - -void QmlJSObserverClient::changeToSelectMarqueeTool() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::ChangeTool; - ObserverProtocol::Tool tool = ObserverProtocol::SelectMarqueeTool; - ds << cmd - << tool; - - log(LogSend, cmd, ObserverProtocol::toString(tool)); - - sendMessage(message); -} - -void QmlJSObserverClient::changeToZoomTool() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::ChangeTool; - ObserverProtocol::Tool tool = ObserverProtocol::ZoomTool; - ds << cmd - << tool; - - log(LogSend, cmd, ObserverProtocol::toString(tool)); - - sendMessage(message); -} - -void QmlJSObserverClient::showAppOnTop(bool showOnTop) -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::ShowAppOnTop; - ds << cmd << showOnTop; - - log(LogSend, cmd, QLatin1String(showOnTop ? "true" : "false")); - - sendMessage(message); -} - -void QmlJSObserverClient::createQmlObject(const QString &qmlText, int parentDebugId, - const QStringList &imports, const QString &filename, int order) -{ - if (!m_connection || !m_connection->isConnected()) - return; - - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::CreateObject; - ds << cmd - << qmlText - << parentDebugId - << imports - << filename - << order; - - log(LogSend, cmd, QString("%1 %2 [%3] %4").arg(qmlText, QString::number(parentDebugId), - imports.join(","), filename)); - - sendMessage(message); -} - -void QmlJSObserverClient::destroyQmlObject(int debugId) -{ - if (!m_connection || !m_connection->isConnected()) - return; - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::DestroyObject; - ds << cmd << debugId; - - log(LogSend, cmd, QString::number(debugId)); - - sendMessage(message); -} - -void QmlJSObserverClient::reparentQmlObject(int debugId, int newParent) -{ - if (!m_connection || !m_connection->isConnected()) - return; - QByteArray message; - QDataStream ds(&message, QIODevice::WriteOnly); - - ObserverProtocol::Message cmd = ObserverProtocol::MoveObject; - ds << cmd - << debugId - << newParent; - - log(LogSend, cmd, QString("%1 %2").arg(QString::number(debugId), - QString::number(newParent))); - - sendMessage(message); -} - - -void QmlJSObserverClient::applyChangesToQmlFile() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - // TODO -} - -void QmlJSObserverClient::applyChangesFromQmlFile() -{ - if (!m_connection || !m_connection->isConnected()) - return; - - // TODO -} - -void QmlJSObserverClient::log(LogDirection direction, ObserverProtocol::Message message, - const QString &extra) -{ - QString msg; - if (direction == LogSend) - msg += QLatin1String(" sending "); - else - msg += QLatin1String(" receiving "); - - msg += ObserverProtocol::toString(message); - msg += QLatin1Char(' '); - msg += extra; - emit logActivity(name(), msg); -} - -} // namespace Internal -} // namespace QmlJSInspector diff --git a/src/plugins/qmljsinspector/qmljsobserverclient.h b/src/plugins/qmljsinspector/qmljsobserverclient.h deleted file mode 100644 index c9e1e28555..0000000000 --- a/src/plugins/qmljsinspector/qmljsobserverclient.h +++ /dev/null @@ -1,113 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (info@qt.nokia.com) -** -** 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. -** -** 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. -** -** If you have questions regarding the use of this file, please contact -** Nokia at info@qt.nokia.com. -** -**************************************************************************/ - -#ifndef QMLJSDESIGNDEBUGCLIENT_H -#define QMLJSDESIGNDEBUGCLIENT_H - -#include "qmljsprivateapi.h" - -#include - -namespace QmlJSInspector { -namespace Internal { - -class QmlJSObserverClient : public QDeclarativeDebugClient -{ - Q_OBJECT -public: - explicit QmlJSObserverClient(QDeclarativeDebugConnection *client, - QObject *parent = 0); - - void setCurrentObjects(const QList &debugIds); - void reloadViewer(); - void setDesignModeBehavior(bool inDesignMode); - void setAnimationSpeed(qreal slowDownFactor); - void setAnimationPaused(bool paused); - void changeToColorPickerTool(); - void changeToSelectTool(); - void changeToSelectMarqueeTool(); - void changeToZoomTool(); - void showAppOnTop(bool showOnTop); - - void createQmlObject(const QString &qmlText, int parentDebugId, - const QStringList &imports, const QString &filename, int order); - void destroyQmlObject(int debugId); - void reparentQmlObject(int debugId, int newParent); - - void applyChangesToQmlFile(); - void applyChangesFromQmlFile(); - - QList currentObjects() const; - - // ### Qt 4.8: remove if we can have access to qdeclarativecontextdata or id's - void setObjectIdList(const QList &objectRoots); - - void clearComponentCache(); - -signals: - void connectedStatusChanged(QDeclarativeDebugClient::Status status); - - void currentObjectsChanged(const QList &debugIds); - void selectedColorChanged(const QColor &color); - void colorPickerActivated(); - void selectToolActivated(); - void selectMarqueeToolActivated(); - void zoomToolActivated(); - void animationSpeedChanged(qreal slowdownFactor); - void animationPausedChanged(bool paused); - void designModeBehaviorChanged(bool inDesignMode); - void showAppOnTopChanged(bool showAppOnTop); - void reloaded(); // the server has reloadetd he document - - void logActivity(QString client, QString message); - -protected: - void statusChanged(Status); - void messageReceived(const QByteArray &); - -private: - enum LogDirection { - LogSend, - LogReceive - }; - - void log(LogDirection direction, - QmlJSDebugger::ObserverProtocol::Message message, - const QString &extra = QString()); - - QList m_currentDebugIds; - QDeclarativeDebugConnection *m_connection; -}; - -} // namespace Internal -} // namespace QmlJSInspector - -#endif // QMLJSDESIGNDEBUGCLIENT_H -- cgit v1.2.1