From 63cae2981b45b8d6c9334d28e0929d8a29f0c1eb Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 14 Sep 2010 13:39:32 +0200 Subject: QmlJsDebugger: Replace QDDesignView by QDViewObserver Don't force users to inherit from QDeclarativeDesignView. Instead we're using now event filters to let a user attach a QDeclarativeViewObserver object to a QDeclarativeDesignView. --- .../editor/abstractformeditortool.cpp | 25 +- .../qmljsdebugger/editor/abstractformeditortool.h | 11 +- .../editor/boundingrecthighlighter.cpp | 6 +- .../qmljsdebugger/editor/boundingrecthighlighter.h | 6 +- .../qmljsdebugger/editor/colorpickertool.cpp | 4 +- .../qmljsdebugger/editor/colorpickertool.h | 2 +- .../editor/rubberbandselectionmanipulator.cpp | 8 +- .../editor/rubberbandselectionmanipulator.h | 6 +- .../qmljsdebugger/editor/selectionindicator.cpp | 6 +- .../qmljsdebugger/editor/selectionindicator.h | 6 +- .../qmljsdebugger/editor/selectiontool.cpp | 34 +- .../qtcreator/qmljsdebugger/editor/selectiontool.h | 5 +- .../editor/singleselectionmanipulator.cpp | 10 +- .../editor/singleselectionmanipulator.h | 6 +- .../editor/subcomponenteditortool.cpp | 12 +- .../qmljsdebugger/editor/subcomponenteditortool.h | 2 +- .../editor/subcomponentmasklayeritem.cpp | 10 +- .../editor/subcomponentmasklayeritem.h | 6 +- share/qtcreator/qmljsdebugger/editor/zoomtool.cpp | 6 +- share/qtcreator/qmljsdebugger/editor/zoomtool.h | 2 +- .../qmljsdebugger/include/qdeclarativedesignview.h | 125 ---- .../include/qdeclarativeviewobserver.h | 129 ++++ .../qmljsdebugger/qdeclarativedesignview.cpp | 751 ------------------- .../qmljsdebugger/qdeclarativedesignview_p.h | 142 ---- .../qmljsdebugger/qdeclarativeviewobserver.cpp | 804 +++++++++++++++++++++ .../qmljsdebugger/qdeclarativeviewobserver_p.h | 143 ++++ .../qtcreator/qmljsdebugger/qmljsdebugger-lib.pri | 6 +- .../qmlapplicationviewer/qmlapplicationviewer.cpp | 2 +- .../qmlapplicationviewer/qmlapplicationviewer.h | 4 +- src/plugins/debugger/debuggerrunner.cpp | 10 +- src/tools/qml/qmlobserver/qmlruntime.cpp | 29 +- src/tools/qml/qmlobserver/qmlruntime.h | 5 +- 32 files changed, 1194 insertions(+), 1129 deletions(-) delete mode 100644 share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h create mode 100644 share/qtcreator/qmljsdebugger/include/qdeclarativeviewobserver.h delete mode 100644 share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp delete mode 100644 share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h create mode 100644 share/qtcreator/qmljsdebugger/qdeclarativeviewobserver.cpp create mode 100644 share/qtcreator/qmljsdebugger/qdeclarativeviewobserver_p.h diff --git a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp index ece0b49637..179bda9d7f 100644 --- a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp +++ b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.cpp @@ -28,8 +28,8 @@ **************************************************************************/ #include "abstractformeditortool.h" -#include "qdeclarativedesignview.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver.h" +#include "qdeclarativeviewobserver_p.h" #include @@ -39,8 +39,8 @@ namespace QmlViewer { -AbstractFormEditorTool::AbstractFormEditorTool(QDeclarativeDesignView *editorView) - : QObject(editorView), m_view(editorView) +AbstractFormEditorTool::AbstractFormEditorTool(QDeclarativeViewObserver *editorView) + : QObject(editorView), m_observer(editorView) { } @@ -50,9 +50,14 @@ AbstractFormEditorTool::~AbstractFormEditorTool() } -QDeclarativeDesignView* AbstractFormEditorTool::view() const +QDeclarativeViewObserver *AbstractFormEditorTool::observer() const { - return m_view; + return m_observer; +} + +QDeclarativeView *AbstractFormEditorTool::view() const +{ + return m_observer->declarativeView(); } QGraphicsScene* AbstractFormEditorTool::scene() const @@ -67,12 +72,12 @@ void AbstractFormEditorTool::updateSelectedItems() QList AbstractFormEditorTool::items() const { - return view()->selectedItems(); + return observer()->selectedItems(); } void AbstractFormEditorTool::enterContext(QGraphicsItem *itemToEnter) { - view()->data->enterContext(itemToEnter); + observer()->data->enterContext(itemToEnter); } bool AbstractFormEditorTool::topItemIsMovable(const QList & itemList) @@ -92,7 +97,7 @@ bool AbstractFormEditorTool::topItemIsMovable(const QList & item bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList &itemList) { - QList selectedItems = view()->selectedItems(); + QList selectedItems = observer()->selectedItems(); foreach (QGraphicsItem *item, itemList) { QDeclarativeItem *declarativeItem = toQDeclarativeItem(item); @@ -178,7 +183,7 @@ QString AbstractFormEditorTool::titleForItem(QGraphicsItem *item) QDeclarativeItem *declarativeItem = qobject_cast(gfxObject); if (declarativeItem) { - objectStringId = QDeclarativeDesignView::idStringForObject(declarativeItem); + objectStringId = QDeclarativeViewObserver::idStringForObject(declarativeItem); } if (!objectStringId.isEmpty()) { diff --git a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h index 63a3d3eb85..1cecc494bc 100644 --- a/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h +++ b/share/qtcreator/qmljsdebugger/editor/abstractformeditortool.h @@ -42,12 +42,12 @@ class QKeyEvent; class QGraphicsScene; class QGraphicsObject; class QWheelEvent; +class QDeclarativeView; QT_END_NAMESPACE namespace QmlViewer { -class QDeclarativeDesignView; - +class QDeclarativeViewObserver; class FormEditorView; @@ -55,7 +55,7 @@ class AbstractFormEditorTool : public QObject { Q_OBJECT public: - AbstractFormEditorTool(QDeclarativeDesignView* view); + AbstractFormEditorTool(QDeclarativeViewObserver* observer); virtual ~AbstractFormEditorTool(); @@ -92,11 +92,12 @@ public: protected: virtual void selectedItemsChanged(const QList &objectList) = 0; - QDeclarativeDesignView *view() const; + QDeclarativeViewObserver *observer() const; + QDeclarativeView *view() const; QGraphicsScene* scene() const; private: - QDeclarativeDesignView *m_view; + QDeclarativeViewObserver *m_observer; QList m_itemList; }; diff --git a/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.cpp b/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.cpp index 43ebea001b..b889e67bc9 100644 --- a/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.cpp +++ b/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.cpp @@ -1,5 +1,5 @@ #include "boundingrecthighlighter.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativeviewobserver.h" #include "qmlviewerconstants.h" #include @@ -48,8 +48,8 @@ int BoundingBoxPolygonItem::type() const return Constants::EditorItemType; } -BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeDesignView *view) : - LayerItem(view->scene()), +BoundingRectHighlighter::BoundingRectHighlighter(QDeclarativeViewObserver *view) : + LayerItem(view->declarativeView()->scene()), m_view(view), m_animFrame(0) { diff --git a/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.h b/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.h index 139b1ac787..16b1c50699 100644 --- a/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.h +++ b/share/qtcreator/qmljsdebugger/editor/boundingrecthighlighter.h @@ -14,14 +14,14 @@ QT_FORWARD_DECLARE_CLASS(QTimer); namespace QmlViewer { -class QDeclarativeDesignView; +class QDeclarativeViewObserver; class BoundingBox; class BoundingRectHighlighter : public LayerItem { Q_OBJECT public: - explicit BoundingRectHighlighter(QDeclarativeDesignView *view); + explicit BoundingRectHighlighter(QDeclarativeViewObserver *view); ~BoundingRectHighlighter(); void clear(); void highlight(QList items); @@ -42,7 +42,7 @@ private: private: Q_DISABLE_COPY(BoundingRectHighlighter); - QDeclarativeDesignView *m_view; + QDeclarativeViewObserver *m_view; QList m_boxes; QList m_freeBoxes; QTimer *m_animTimer; diff --git a/share/qtcreator/qmljsdebugger/editor/colorpickertool.cpp b/share/qtcreator/qmljsdebugger/editor/colorpickertool.cpp index 5bc349cba9..863ce9b8bc 100644 --- a/share/qtcreator/qmljsdebugger/editor/colorpickertool.cpp +++ b/share/qtcreator/qmljsdebugger/editor/colorpickertool.cpp @@ -1,5 +1,5 @@ #include "colorpickertool.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativeviewobserver.h" #include #include @@ -11,7 +11,7 @@ namespace QmlViewer { -ColorPickerTool::ColorPickerTool(QDeclarativeDesignView *view) : +ColorPickerTool::ColorPickerTool(QDeclarativeViewObserver *view) : AbstractFormEditorTool(view) { m_selectedColor.setRgb(0,0,0); diff --git a/share/qtcreator/qmljsdebugger/editor/colorpickertool.h b/share/qtcreator/qmljsdebugger/editor/colorpickertool.h index f762179c41..b9beec58db 100644 --- a/share/qtcreator/qmljsdebugger/editor/colorpickertool.h +++ b/share/qtcreator/qmljsdebugger/editor/colorpickertool.h @@ -13,7 +13,7 @@ class ColorPickerTool : public AbstractFormEditorTool { Q_OBJECT public: - explicit ColorPickerTool(QDeclarativeDesignView *view); + explicit ColorPickerTool(QDeclarativeViewObserver *view); virtual ~ColorPickerTool(); diff --git a/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp b/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp index 8f24552890..66843e87ae 100644 --- a/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp +++ b/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp @@ -28,13 +28,13 @@ **************************************************************************/ #include "rubberbandselectionmanipulator.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver_p.h" #include namespace QmlViewer { -RubberBandSelectionManipulator::RubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeDesignView *editorView) +RubberBandSelectionManipulator::RubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeViewObserver *editorView) : m_selectionRectangleElement(layerItem), m_editorView(editorView), m_beginFormEditorItem(0), @@ -66,7 +66,7 @@ void RubberBandSelectionManipulator::begin(const QPointF& beginPoint) m_selectionRectangleElement.setRect(m_beginPoint, m_beginPoint); m_selectionRectangleElement.show(); m_isActive = true; - m_beginFormEditorItem = topFormEditorItem(QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(beginPoint)); + m_beginFormEditorItem = topFormEditorItem(QDeclarativeViewObserverPrivate::get(m_editorView)->selectableItems(beginPoint)); m_oldSelectionList = m_editorView->selectedItems(); } @@ -84,7 +84,7 @@ void RubberBandSelectionManipulator::end() void RubberBandSelectionManipulator::select(SelectionType selectionType) { - QList itemList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(m_selectionRectangleElement.rect(), + QList itemList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectableItems(m_selectionRectangleElement.rect(), Qt::IntersectsItemShape); QList newSelectionList; diff --git a/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.h b/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.h index 272d054b65..feacc2d52a 100644 --- a/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.h +++ b/share/qtcreator/qmljsdebugger/editor/rubberbandselectionmanipulator.h @@ -35,7 +35,7 @@ namespace QmlViewer { -class QDeclarativeDesignView; +class QDeclarativeViewObserver; class RubberBandSelectionManipulator { @@ -47,7 +47,7 @@ public: }; - RubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeDesignView *editorView); + RubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeViewObserver *editorView); void setItems(const QList &itemList); @@ -72,7 +72,7 @@ private: QList m_oldSelectionList; SelectionRectangle m_selectionRectangleElement; QPointF m_beginPoint; - QDeclarativeDesignView *m_editorView; + QDeclarativeViewObserver *m_editorView; QGraphicsItem *m_beginFormEditorItem; bool m_isActive; }; diff --git a/share/qtcreator/qmljsdebugger/editor/selectionindicator.cpp b/share/qtcreator/qmljsdebugger/editor/selectionindicator.cpp index 585b54999c..8ebc1d71a9 100644 --- a/share/qtcreator/qmljsdebugger/editor/selectionindicator.cpp +++ b/share/qtcreator/qmljsdebugger/editor/selectionindicator.cpp @@ -28,7 +28,7 @@ **************************************************************************/ #include "selectionindicator.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver_p.h" #include "qmlviewerconstants.h" #include @@ -38,7 +38,7 @@ namespace QmlViewer { -SelectionIndicator::SelectionIndicator(QDeclarativeDesignView *editorView, QGraphicsObject *layerItem) +SelectionIndicator::SelectionIndicator(QDeclarativeViewObserver *editorView, QGraphicsObject *layerItem) : m_layerItem(layerItem), m_view(editorView) { } @@ -85,7 +85,7 @@ QPolygonF SelectionIndicator::addBoundingRectToPolygon(QGraphicsItem *item, QPol } foreach(QGraphicsItem *child, item->childItems()) { - if (!QDeclarativeDesignViewPrivate::get(m_view)->isEditorItem(child)) + if (!QDeclarativeViewObserverPrivate::get(m_view)->isEditorItem(child)) addBoundingRectToPolygon(child, polygon); } return polygon; diff --git a/share/qtcreator/qmljsdebugger/editor/selectionindicator.h b/share/qtcreator/qmljsdebugger/editor/selectionindicator.h index 9880111c6b..61dfa9af62 100644 --- a/share/qtcreator/qmljsdebugger/editor/selectionindicator.h +++ b/share/qtcreator/qmljsdebugger/editor/selectionindicator.h @@ -36,12 +36,12 @@ namespace QmlViewer { -class QDeclarativeDesignView; +class QDeclarativeViewObserver; class SelectionIndicator { public: - SelectionIndicator(QDeclarativeDesignView* editorView, QGraphicsObject *layerItem); + SelectionIndicator(QDeclarativeViewObserver* editorView, QGraphicsObject *layerItem); ~SelectionIndicator(); void show(); @@ -57,7 +57,7 @@ private: private: QHash m_indicatorShapeHash; QWeakPointer m_layerItem; - QDeclarativeDesignView *m_view; + QDeclarativeViewObserver *m_view; }; diff --git a/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp b/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp index dbcadd605b..5e8a01dc1f 100644 --- a/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp +++ b/share/qtcreator/qmljsdebugger/editor/selectiontool.cpp @@ -31,7 +31,7 @@ #include "layeritem.h" //#include "resizehandleitem.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver_p.h" #include @@ -48,12 +48,12 @@ namespace QmlViewer { -SelectionTool::SelectionTool(QDeclarativeDesignView *editorView) +SelectionTool::SelectionTool(QDeclarativeViewObserver *editorView) : AbstractFormEditorTool(editorView), m_rubberbandSelectionMode(false), - m_rubberbandSelectionManipulator(QDeclarativeDesignViewPrivate::get(editorView)->manipulatorLayer, editorView), + m_rubberbandSelectionManipulator(QDeclarativeViewObserverPrivate::get(editorView)->manipulatorLayer, editorView), m_singleSelectionManipulator(editorView), - m_selectionIndicator(editorView, QDeclarativeDesignViewPrivate::get(editorView)->manipulatorLayer), + m_selectionIndicator(editorView, QDeclarativeViewObserverPrivate::get(editorView)->manipulatorLayer), //m_resizeIndicator(editorView->manipulatorLayer()), m_selectOnlyContentItems(true) { @@ -82,7 +82,7 @@ SingleSelectionManipulator::SelectionType SelectionTool::getSelectionType(Qt::Ke bool SelectionTool::alreadySelected(const QList &itemList) const { - const QList selectedItems = QDeclarativeDesignViewPrivate::get(view())->selectedItems(); + const QList selectedItems = QDeclarativeViewObserverPrivate::get(observer())->selectedItems(); if (selectedItems.isEmpty()) return false; @@ -98,7 +98,7 @@ bool SelectionTool::alreadySelected(const QList &itemList) const void SelectionTool::mousePressEvent(QMouseEvent *event) { - QList itemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos()); + QList itemList = QDeclarativeViewObserverPrivate::get(observer())->selectableItems(event->pos()); SingleSelectionManipulator::SelectionType selectionType = getSelectionType(event->modifiers()); if (event->buttons() & Qt::LeftButton) { @@ -109,7 +109,7 @@ void SelectionTool::mousePressEvent(QMouseEvent *event) } else { if (itemList.isEmpty()) { - QDeclarativeDesignViewPrivate::get(view())->setSelectedItems(itemList); + QDeclarativeViewObserverPrivate::get(observer())->setSelectedItems(itemList); return; } @@ -130,7 +130,7 @@ void SelectionTool::mousePressEvent(QMouseEvent *event) m_mousePressTimer.start(); if (itemList.isEmpty()) { - view()->setSelectedItems(itemList); + observer()->setSelectedItems(itemList); return; } @@ -159,7 +159,7 @@ void SelectionTool::mousePressEvent(QMouseEvent *event) void SelectionTool::createContextMenu(QList itemList, QPoint globalPos) { - if (!QDeclarativeDesignViewPrivate::get(view())->mouseInsideContextItem()) + if (!QDeclarativeViewObserverPrivate::get(observer())->mouseInsideContextItem()) return; QMenu contextMenu; @@ -177,7 +177,7 @@ void SelectionTool::createContextMenu(QList itemList, QPoint glo QString itemTitle = titleForItem(item); QAction *elementAction = contextMenu.addAction(itemTitle, this, SLOT(contextMenuElementSelected())); - if (view()->selectedItems().contains(item)) { + if (observer()->selectedItems().contains(item)) { QFont boldFont = elementAction->font(); boldFont.setBold(true); elementAction->setFont(boldFont); @@ -224,7 +224,7 @@ void SelectionTool::contextMenuElementHovered(QAction *action) int itemListIndex = action->data().toInt(); if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { QGraphicsObject *item = m_contextMenuItemList.at(itemListIndex)->toGraphicsObject(); - QDeclarativeDesignViewPrivate::get(view())->highlight(item); + QDeclarativeViewObserverPrivate::get(observer())->highlight(item); } } @@ -274,16 +274,16 @@ void SelectionTool::hoverMoveEvent(QMouseEvent * event) // if (topSelectedItemIsMovable(itemList)) // view()->changeTool(Constants::MoveToolMode); // } - QList selectableItemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos()); + QList selectableItemList = QDeclarativeViewObserverPrivate::get(observer())->selectableItems(event->pos()); if (!selectableItemList.isEmpty()) { QGraphicsObject *item = selectableItemList.first()->toGraphicsObject(); if (item) - QDeclarativeDesignViewPrivate::get(view())->highlight(item); + QDeclarativeViewObserverPrivate::get(observer())->highlight(item); return; } - QDeclarativeDesignViewPrivate::get(view())->clearHighlight(); + QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); } void SelectionTool::mouseReleaseEvent(QMouseEvent *event) @@ -349,11 +349,11 @@ void SelectionTool::wheelEvent(QWheelEvent *event) if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) return; - QList itemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos()); + QList itemList = QDeclarativeViewObserverPrivate::get(observer())->selectableItems(event->pos()); int selectedIdx = 0; - if (!view()->selectedItems().isEmpty()) { - selectedIdx = itemList.indexOf(view()->selectedItems().first()); + if (!observer()->selectedItems().isEmpty()) { + selectedIdx = itemList.indexOf(observer()->selectedItems().first()); if (selectedIdx >= 0) { if (event->delta() > 0) { selectedIdx++; diff --git a/share/qtcreator/qmljsdebugger/editor/selectiontool.h b/share/qtcreator/qmljsdebugger/editor/selectiontool.h index 9fa6e8825e..e535786fe4 100644 --- a/share/qtcreator/qmljsdebugger/editor/selectiontool.h +++ b/share/qtcreator/qmljsdebugger/editor/selectiontool.h @@ -32,15 +32,14 @@ #include "abstractformeditortool.h" -#include "movemanipulator.h" #include "rubberbandselectionmanipulator.h" #include "singleselectionmanipulator.h" #include "selectionindicator.h" -#include "resizeindicator.h" #include #include #include +#include QT_FORWARD_DECLARE_CLASS(QGraphicsItem); QT_FORWARD_DECLARE_CLASS(QMouseEvent); @@ -53,7 +52,7 @@ class SelectionTool : public AbstractFormEditorTool Q_OBJECT public: - SelectionTool(QDeclarativeDesignView* editorView); + SelectionTool(QDeclarativeViewObserver* editorView); ~SelectionTool(); void mousePressEvent(QMouseEvent *event); diff --git a/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.cpp b/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.cpp index 3c5fed7cca..191252ae8b 100644 --- a/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.cpp +++ b/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.cpp @@ -28,13 +28,13 @@ **************************************************************************/ #include "singleselectionmanipulator.h" -#include "qdeclarativedesignview.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver.h" +#include "qdeclarativeviewobserver_p.h" #include namespace QmlViewer { -SingleSelectionManipulator::SingleSelectionManipulator(QDeclarativeDesignView *editorView) +SingleSelectionManipulator::SingleSelectionManipulator(QDeclarativeViewObserver *editorView) : m_editorView(editorView), m_isActive(false) { @@ -45,7 +45,7 @@ void SingleSelectionManipulator::begin(const QPointF &beginPoint) { m_beginPoint = beginPoint; m_isActive = true; - m_oldSelectionList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectedItems(); + m_oldSelectionList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectedItems(); } void SingleSelectionManipulator::update(const QPointF &/*updatePoint*/) @@ -116,7 +116,7 @@ void SingleSelectionManipulator::select(SelectionType selectionType, const QList void SingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) { - QList itemList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(m_beginPoint); + QList itemList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectableItems(m_beginPoint); select(selectionType, itemList, selectOnlyContentItems); } diff --git a/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.h b/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.h index 04f339640f..bde990634d 100644 --- a/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.h +++ b/share/qtcreator/qmljsdebugger/editor/singleselectionmanipulator.h @@ -37,12 +37,12 @@ QT_FORWARD_DECLARE_CLASS(QGraphicsItem); namespace QmlViewer { -class QDeclarativeDesignView; +class QDeclarativeViewObserver; class SingleSelectionManipulator { public: - SingleSelectionManipulator(QDeclarativeDesignView *editorView); + SingleSelectionManipulator(QDeclarativeViewObserver *editorView); enum SelectionType { ReplaceSelection, @@ -67,7 +67,7 @@ public: private: QList m_oldSelectionList; QPointF m_beginPoint; - QDeclarativeDesignView *m_editorView; + QDeclarativeViewObserver *m_editorView; bool m_isActive; }; diff --git a/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.cpp b/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.cpp index 2bd96c80ef..bdb7e61960 100644 --- a/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.cpp +++ b/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.cpp @@ -1,5 +1,5 @@ #include "subcomponenteditortool.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver_p.h" #include "subcomponentmasklayeritem.h" #include "layeritem.h" @@ -16,12 +16,12 @@ namespace QmlViewer { const qreal MaxOpacity = 0.5f; -SubcomponentEditorTool::SubcomponentEditorTool(QDeclarativeDesignView *view) +SubcomponentEditorTool::SubcomponentEditorTool(QDeclarativeViewObserver *view) : AbstractFormEditorTool(view), m_animIncrement(0.05f), m_animTimer(new QTimer(this)) { - m_mask = new SubcomponentMaskLayerItem(view, QDeclarativeDesignViewPrivate::get(view)->manipulatorLayer); + m_mask = new SubcomponentMaskLayerItem(view, QDeclarativeViewObserverPrivate::get(view)->manipulatorLayer); connect(m_animTimer, SIGNAL(timeout()), SLOT(animate())); m_animTimer->setInterval(20); } @@ -71,7 +71,7 @@ void SubcomponentEditorTool::mouseDoubleClickEvent(QMouseEvent *event) void SubcomponentEditorTool::hoverMoveEvent(QMouseEvent *event) { if (!containsCursor(event->pos()) && m_currentContext.size() > 1) { - QDeclarativeDesignViewPrivate::get(view())->clearHighlight(); + QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); } } @@ -164,8 +164,8 @@ void SubcomponentEditorTool::setCurrentItem(QGraphicsItem* contextItem) m_animIncrement = 0.05f; m_animTimer->start(); - QDeclarativeDesignViewPrivate::get(view())->clearHighlight(); - view()->setSelectedItems(QList()); + QDeclarativeViewObserverPrivate::get(observer())->clearHighlight(); + observer()->setSelectedItems(QList()); pushContext(gfxObject); } diff --git a/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.h b/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.h index d54b6a71dc..c8196ed8e5 100644 --- a/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.h +++ b/share/qtcreator/qmljsdebugger/editor/subcomponenteditortool.h @@ -18,7 +18,7 @@ class SubcomponentEditorTool : public AbstractFormEditorTool Q_OBJECT public: - SubcomponentEditorTool(QDeclarativeDesignView *view); + SubcomponentEditorTool(QDeclarativeViewObserver *view); ~SubcomponentEditorTool(); void mousePressEvent(QMouseEvent *event); diff --git a/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.cpp b/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.cpp index ce1b437131..4e6e911163 100644 --- a/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.cpp +++ b/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.cpp @@ -1,13 +1,13 @@ #include "subcomponentmasklayeritem.h" #include "qmlviewerconstants.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativeviewobserver.h" #include namespace QmlViewer { -SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeDesignView *view, QGraphicsItem *parentItem) : +SubcomponentMaskLayerItem::SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer, QGraphicsItem *parentItem) : QGraphicsPolygonItem(parentItem), - m_view(view), + m_observer(observer), m_currentItem(0), m_borderRect(new QGraphicsRectItem(this)) { @@ -51,8 +51,8 @@ void SubcomponentMaskLayerItem::setCurrentItem(QGraphicsItem *item) if (!m_currentItem) return; - QPolygonF viewPoly(QRectF(m_view->rect())); - viewPoly = m_view->mapToScene(viewPoly.toPolygon()); + QPolygonF viewPoly(QRectF(m_observer->declarativeView()->rect())); + viewPoly = m_observer->declarativeView()->mapToScene(viewPoly.toPolygon()); QRectF itemRect = item->boundingRect() | item->childrenBoundingRect(); QPolygonF itemPoly(itemRect); diff --git a/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.h b/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.h index 9a64636461..598cd16195 100644 --- a/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.h +++ b/share/qtcreator/qmljsdebugger/editor/subcomponentmasklayeritem.h @@ -5,12 +5,12 @@ namespace QmlViewer { -class QDeclarativeDesignView; +class QDeclarativeViewObserver; class SubcomponentMaskLayerItem : public QGraphicsPolygonItem { public: - explicit SubcomponentMaskLayerItem(QDeclarativeDesignView *view, QGraphicsItem *parentItem = 0); + explicit SubcomponentMaskLayerItem(QDeclarativeViewObserver *observer, QGraphicsItem *parentItem = 0); int type() const; void setCurrentItem(QGraphicsItem *item); void setBoundingBox(const QRectF &boundingBox); @@ -18,7 +18,7 @@ public: QRectF itemRect() const; private: - QDeclarativeDesignView *m_view; + QDeclarativeViewObserver *m_observer; QGraphicsItem *m_currentItem; QGraphicsRectItem *m_borderRect; QRectF m_itemPolyRect; diff --git a/share/qtcreator/qmljsdebugger/editor/zoomtool.cpp b/share/qtcreator/qmljsdebugger/editor/zoomtool.cpp index 05937eafc2..7a946cf9e8 100644 --- a/share/qtcreator/qmljsdebugger/editor/zoomtool.cpp +++ b/share/qtcreator/qmljsdebugger/editor/zoomtool.cpp @@ -1,5 +1,5 @@ #include "zoomtool.h" -#include "qdeclarativedesignview_p.h" +#include "qdeclarativeviewobserver_p.h" #include #include @@ -12,9 +12,9 @@ namespace QmlViewer { -ZoomTool::ZoomTool(QDeclarativeDesignView *view) : +ZoomTool::ZoomTool(QDeclarativeViewObserver *view) : AbstractFormEditorTool(view), - m_rubberbandManipulator(reinterpret_cast(QDeclarativeDesignViewPrivate::get(view)->manipulatorLayer), view), + m_rubberbandManipulator(reinterpret_cast(QDeclarativeViewObserverPrivate::get(view)->manipulatorLayer), view), m_smoothZoomMultiplier(0.05f), m_currentScale(1.0f) { diff --git a/share/qtcreator/qmljsdebugger/editor/zoomtool.h b/share/qtcreator/qmljsdebugger/editor/zoomtool.h index f3774efa11..31159a1b6d 100644 --- a/share/qtcreator/qmljsdebugger/editor/zoomtool.h +++ b/share/qtcreator/qmljsdebugger/editor/zoomtool.h @@ -17,7 +17,7 @@ public: ZoomOut }; - explicit ZoomTool(QDeclarativeDesignView *view); + explicit ZoomTool(QDeclarativeViewObserver *view); virtual ~ZoomTool(); diff --git a/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h b/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h deleted file mode 100644 index f06002dcd2..0000000000 --- a/share/qtcreator/qmljsdebugger/include/qdeclarativedesignview.h +++ /dev/null @@ -1,125 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef QDECLARATIVEDESIGNVIEW_H -#define QDECLARATIVEDESIGNVIEW_H - -#include "qmljsdebugger_global.h" -#include "qmlviewerconstants.h" -#include -#include - -QT_FORWARD_DECLARE_CLASS(QDeclarativeItem); -QT_FORWARD_DECLARE_CLASS(QMouseEvent); -QT_FORWARD_DECLARE_CLASS(QToolBar); - -namespace QmlViewer { - -class CrumblePath; -class QDeclarativeDesignViewPrivate; - -class QMLJSDEBUGGER_EXPORT QDeclarativeDesignView : public QDeclarativeView -{ - Q_OBJECT -public: - - explicit QDeclarativeDesignView(QWidget *parent = 0); - ~QDeclarativeDesignView(); - - void setSelectedItems(QList items); - QList selectedItems(); - - QToolBar *toolbar() const; - static QString idStringForObject(QObject *obj); - QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); - void setDebugMode(bool isDebugMode); - -public Q_SLOTS: - void setDesignModeBehavior(bool value); - bool designModeBehavior(); - - void changeAnimationSpeed(qreal slowdownFactor); - void continueExecution(qreal slowdownFactor = 1.0f); - void pauseExecution(); - - void setInspectorContext(int contextIndex); - -Q_SIGNALS: - void designModeBehaviorChanged(bool inDesignMode); - void reloadRequested(); - void marqueeSelectToolActivated(); - void selectToolActivated(); - void zoomToolActivated(); - void colorPickerActivated(); - void selectedColorChanged(const QColor &color); - - void executionStarted(qreal slowdownFactor); - void executionPaused(); - - void inspectorContextCleared(); - void inspectorContextPushed(const QString &contextTitle); - void inspectorContextPopped(); - -protected: - void leaveEvent(QEvent *); - void mousePressEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *keyEvent); - void mouseDoubleClickEvent(QMouseEvent *event); - void wheelEvent(QWheelEvent *event); - - void setSelectedItemsForTools(QList items); - -private: - Q_DISABLE_COPY(QDeclarativeDesignView) - Q_PRIVATE_SLOT(d_func(), void _q_reloadView()) - Q_PRIVATE_SLOT(d_func(), void _q_onStatusChanged(QDeclarativeView::Status)) - Q_PRIVATE_SLOT(d_func(), void _q_onCurrentObjectsChanged(QList)) - Q_PRIVATE_SLOT(d_func(), void _q_applyChangesFromClient()) - Q_PRIVATE_SLOT(d_func(), void _q_createQmlObject(const QString &, QObject *, const QStringList &, const QString &)) - Q_PRIVATE_SLOT(d_func(), void _q_reparentQmlObject(QObject *, QObject *)) - Q_PRIVATE_SLOT(d_func(), void _q_changeToSingleSelectTool()) - Q_PRIVATE_SLOT(d_func(), void _q_changeToMarqueeSelectTool()) - Q_PRIVATE_SLOT(d_func(), void _q_changeToZoomTool()) - Q_PRIVATE_SLOT(d_func(), void _q_changeToColorPickerTool()) - Q_PRIVATE_SLOT(d_func(), void _q_changeContextPathIndex(int index)) - Q_PRIVATE_SLOT(d_func(), void _q_clearComponentCache()); - - inline QDeclarativeDesignViewPrivate *d_func() { return data.data(); } - QScopedPointer data; - friend class QDeclarativeDesignViewPrivate; - friend class AbstractFormEditorTool; - -}; - -} //namespace QmlViewer - -#endif // QDECLARATIVEDESIGNVIEW_H diff --git a/share/qtcreator/qmljsdebugger/include/qdeclarativeviewobserver.h b/share/qtcreator/qmljsdebugger/include/qdeclarativeviewobserver.h new file mode 100644 index 0000000000..b6ec2d0e8b --- /dev/null +++ b/share/qtcreator/qmljsdebugger/include/qdeclarativeviewobserver.h @@ -0,0 +1,129 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef QDECLARATIVEVIEWOBSERVER_H +#define QDECLARATIVEVIEWOBSERVER_H + +#include "qmljsdebugger_global.h" +#include "qmlviewerconstants.h" +#include +#include + +QT_FORWARD_DECLARE_CLASS(QDeclarativeItem); +QT_FORWARD_DECLARE_CLASS(QMouseEvent); +QT_FORWARD_DECLARE_CLASS(QToolBar); + +namespace QmlViewer { + +class CrumblePath; +class QDeclarativeViewObserverPrivate; + +class QMLJSDEBUGGER_EXPORT QDeclarativeViewObserver : public QObject +{ + Q_OBJECT +public: + + explicit QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent = 0); + ~QDeclarativeViewObserver(); + + void setSelectedItems(QList items); + QList selectedItems(); + + QDeclarativeView *declarativeView(); + + QToolBar *toolbar() const; + static QString idStringForObject(QObject *obj); + QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); + void setDebugMode(bool isDebugMode); + +public Q_SLOTS: + void setDesignModeBehavior(bool value); + bool designModeBehavior(); + + void changeAnimationSpeed(qreal slowdownFactor); + void continueExecution(qreal slowdownFactor = 1.0f); + void pauseExecution(); + + void setInspectorContext(int contextIndex); + +Q_SIGNALS: + void designModeBehaviorChanged(bool inDesignMode); + void reloadRequested(); + void marqueeSelectToolActivated(); + void selectToolActivated(); + void zoomToolActivated(); + void colorPickerActivated(); + void selectedColorChanged(const QColor &color); + + void executionStarted(qreal slowdownFactor); + void executionPaused(); + + void inspectorContextCleared(); + void inspectorContextPushed(const QString &contextTitle); + void inspectorContextPopped(); + +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: + Q_DISABLE_COPY(QDeclarativeViewObserver) + Q_PRIVATE_SLOT(d_func(), void _q_reloadView()) + Q_PRIVATE_SLOT(d_func(), void _q_onStatusChanged(QDeclarativeView::Status)) + Q_PRIVATE_SLOT(d_func(), void _q_onCurrentObjectsChanged(QList)) + Q_PRIVATE_SLOT(d_func(), void _q_applyChangesFromClient()) + Q_PRIVATE_SLOT(d_func(), void _q_createQmlObject(const QString &, QObject *, const QStringList &, const QString &)) + Q_PRIVATE_SLOT(d_func(), void _q_reparentQmlObject(QObject *, QObject *)) + Q_PRIVATE_SLOT(d_func(), void _q_changeToSingleSelectTool()) + Q_PRIVATE_SLOT(d_func(), void _q_changeToMarqueeSelectTool()) + Q_PRIVATE_SLOT(d_func(), void _q_changeToZoomTool()) + Q_PRIVATE_SLOT(d_func(), void _q_changeToColorPickerTool()) + Q_PRIVATE_SLOT(d_func(), void _q_changeContextPathIndex(int index)) + Q_PRIVATE_SLOT(d_func(), void _q_clearComponentCache()); + + inline QDeclarativeViewObserverPrivate *d_func() { return data.data(); } + QScopedPointer data; + friend class QDeclarativeViewObserverPrivate; + friend class AbstractFormEditorTool; + +}; + +} //namespace QmlViewer + +#endif // QDECLARATIVEVIEWOBSERVER_H diff --git a/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp b/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp deleted file mode 100644 index f9e2a806de..0000000000 --- a/share/qtcreator/qmljsdebugger/qdeclarativedesignview.cpp +++ /dev/null @@ -1,751 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "qdeclarativedesignview.h" -#include "qdeclarativedesignview_p.h" -#include "qdeclarativedesigndebugserver.h" -#include "selectiontool.h" -#include "zoomtool.h" -#include "colorpickertool.h" -#include "layeritem.h" -#include "boundingrecthighlighter.h" -#include "subcomponenteditortool.h" -#include "qmltoolbar.h" -#include "jsdebuggeragent.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -namespace QmlViewer { - -const int SceneChangeUpdateInterval = 5000; - -QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate(QDeclarativeDesignView *q) : - q(q), - designModeBehavior(false), - executionPaused(false), - slowdownFactor(1.0f), - jsDebuggerAgent(0), - toolbar(0) -{ -} - -QDeclarativeDesignViewPrivate::~QDeclarativeDesignViewPrivate() -{ -} - -QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) : - QDeclarativeView(parent), data(new QDeclarativeDesignViewPrivate(this)) -{ - data->manipulatorLayer = new LayerItem(scene()); - data->selectionTool = new SelectionTool(this); - data->zoomTool = new ZoomTool(this); - data->colorPickerTool = new ColorPickerTool(this); - data->boundingRectHighlighter = new BoundingRectHighlighter(this); - data->subcomponentEditorTool = new SubcomponentEditorTool(this); - data->currentTool = data->selectionTool; - - setMouseTracking(true); - - data->debugServer = QDeclarativeDesignDebugServer::instance(); - connect(data->debugServer, SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool))); - connect(data->debugServer, SIGNAL(reloadRequested()), SLOT(_q_reloadView())); - connect(data->debugServer, - SIGNAL(currentObjectsChanged(QList)), - SLOT(_q_onCurrentObjectsChanged(QList))); - connect(data->debugServer, SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal))); - connect(data->debugServer, SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool())); - connect(data->debugServer, SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool())); - connect(data->debugServer, SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool())); - connect(data->debugServer, SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool())); - connect(data->debugServer, - SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)), - SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString))); - connect(data->debugServer, - SIGNAL(objectReparentRequested(QObject *, QObject *)), - SLOT(_q_reparentQmlObject(QObject *, QObject *))); - connect(data->debugServer, SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int))); - connect(data->debugServer, SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache())); - connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); - - connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); - connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), - data->debugServer, SLOT(selectedColorChanged(QColor))); - - connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared())); - connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString))); - connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped())); - connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), data->debugServer, SLOT(contextPathUpdated(QStringList))); - - data->createToolbar(); - - data->_q_changeToSingleSelectTool(); - - // always start debug mode - that's what this design view is for. - setDebugMode(true); -} - -QDeclarativeDesignView::~QDeclarativeDesignView() -{ -} - -void QDeclarativeDesignView::setInspectorContext(int contextIndex) -{ - if (data->subcomponentEditorTool->contextIndex() != contextIndex) { - QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex); - if (object) - data->debugServer->setCurrentObjects(QList() << object); - } -} - -void QDeclarativeDesignViewPrivate::_q_reloadView() -{ - subcomponentEditorTool->clear(); - clearHighlight(); - emit q->reloadRequested(); -} - -void QDeclarativeDesignViewPrivate::clearEditorItems() -{ - clearHighlight(); - setSelectedItems(QList()); -} - -void QDeclarativeDesignView::leaveEvent(QEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::leaveEvent(event); - return; - } - data->clearHighlight(); -} - -void QDeclarativeDesignView::mousePressEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::mousePressEvent(event); - return; - } - data->cursorPos = event->pos(); - data->currentTool->mousePressEvent(event); -} - -void QDeclarativeDesignView::mouseMoveEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) { - data->clearEditorItems(); - QDeclarativeView::mouseMoveEvent(event); - return; - } - data->cursorPos = event->pos(); - - QList selItems = data->selectableItems(event->pos()); - if (!selItems.isEmpty()) { - setToolTip(AbstractFormEditorTool::titleForItem(selItems.first())); - } else { - setToolTip(QString()); - } - if (event->buttons()) { - data->subcomponentEditorTool->mouseMoveEvent(event); - data->currentTool->mouseMoveEvent(event); - } else { - data->subcomponentEditorTool->hoverMoveEvent(event); - data->currentTool->hoverMoveEvent(event); - } -} - -void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::mouseReleaseEvent(event); - return; - } - data->subcomponentEditorTool->mouseReleaseEvent(event); - - data->cursorPos = event->pos(); - data->currentTool->mouseReleaseEvent(event); - - data->debugServer->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems())); -} - -void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::keyPressEvent(event); - return; - } - data->currentTool->keyPressEvent(event); -} - -void QDeclarativeDesignView::keyReleaseEvent(QKeyEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::keyReleaseEvent(event); - return; - } - - 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_Enter: - case Qt::Key_Return: - if (!data->selectedItems().isEmpty()) - data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first()); - break; - case Qt::Key_Space: - if (data->executionPaused) { - continueExecution(data->slowdownFactor); - } else { - pauseExecution(); - } - break; - default: - break; - } - - data->currentTool->keyReleaseEvent(event); -} - -void QDeclarativeDesignViewPrivate::_q_createQmlObject(const QString &qml, QObject *parent, const QStringList &importList, const QString &filename) -{ - if (!parent) - return; - - QString imports; - foreach(const QString &s, importList) { - imports += s + "\n"; - } - - QDeclarativeContext *parentContext = q->engine()->contextForObject(parent); - QDeclarativeComponent component(q->engine(), q); - QByteArray constructedQml = QString(imports + qml).toLatin1(); - - component.setData(constructedQml, filename); - QObject *newObject = component.create(parentContext); - if (newObject) { - newObject->setParent(parent); - QDeclarativeItem *parentItem = qobject_cast(parent); - QDeclarativeItem *newItem = qobject_cast(newObject); - if (parentItem && newItem) { - newItem->setParentItem(parentItem); - } - } -} - -void QDeclarativeDesignViewPrivate::_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 QDeclarativeDesignViewPrivate::_q_clearComponentCache() -{ - q->engine()->clearComponentCache(); -} - -QGraphicsItem *QDeclarativeDesignViewPrivate::currentRootItem() const -{ - return subcomponentEditorTool->currentRootItem(); -} - -void QDeclarativeDesignView::mouseDoubleClickEvent(QMouseEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::mouseDoubleClickEvent(event); - return; - } - - if (data->currentToolMode != Constants::SelectionToolMode - && data->currentToolMode != Constants::MarqueeSelectionToolMode) - { - return; - } - - QGraphicsItem *itemToEnter = 0; - QList itemList = items(event->pos()); - data->filterForSelection(itemList); - - if (data->selectedItems().isEmpty() && !itemList.isEmpty()) { - itemToEnter = itemList.first(); - } else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) { - itemToEnter = itemList.first(); - } - - if (itemToEnter) - itemToEnter = data->subcomponentEditorTool->firstChildOfContext(itemToEnter); - - data->subcomponentEditorTool->setCurrentItem(itemToEnter); - data->subcomponentEditorTool->mouseDoubleClickEvent(event); - - if ((event->buttons() & Qt::LeftButton) && itemToEnter) { - QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject(); - if (objectToEnter) - data->debugServer->setCurrentObjects(QList() << objectToEnter); - } - -} - -void QDeclarativeDesignView::wheelEvent(QWheelEvent *event) -{ - if (!data->designModeBehavior) { - QDeclarativeView::wheelEvent(event); - return; - } - data->currentTool->wheelEvent(event); -} - -void QDeclarativeDesignViewPrivate::enterContext(QGraphicsItem *itemToEnter) -{ - QGraphicsItem *itemUnderCurrentContext = itemToEnter; - if (itemUnderCurrentContext) - itemUnderCurrentContext = subcomponentEditorTool->firstChildOfContext(itemToEnter); - - if (itemUnderCurrentContext) - subcomponentEditorTool->setCurrentItem(itemToEnter); -} - -void QDeclarativeDesignView::setDesignModeBehavior(bool value) -{ - emit designModeBehaviorChanged(value); - - data->toolbar->setDesignModeBehavior(value); - data->debugServer->setDesignModeBehavior(value); - - data->designModeBehavior = value; - if (data->subcomponentEditorTool) { - data->subcomponentEditorTool->clear(); - data->clearHighlight(); - data->setSelectedItems(QList()); - - if (rootObject()) - data->subcomponentEditorTool->pushContext(rootObject()); - } - - if (!data->designModeBehavior) - data->clearEditorItems(); -} - -bool QDeclarativeDesignView::designModeBehavior() -{ - return data->designModeBehavior; -} - -void QDeclarativeDesignViewPrivate::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/) -{ - switch(tool) { - case Constants::SelectionToolMode: - _q_changeToSingleSelectTool(); - break; - case Constants::NoTool: - default: - currentTool = 0; - break; - } -} - -void QDeclarativeDesignViewPrivate::setSelectedItemsForTools(QList items) -{ - currentSelection.clear(); - foreach(QGraphicsItem *item, items) { - if (item) { - QGraphicsObject *obj = item->toGraphicsObject(); - if (obj) - currentSelection << obj; - } - } - currentTool->updateSelectedItems(); -} - -void QDeclarativeDesignViewPrivate::setSelectedItems(QList items) -{ - setSelectedItemsForTools(items); - debugServer->setCurrentObjects(AbstractFormEditorTool::toObjectList(items)); -} - -QList QDeclarativeDesignViewPrivate::selectedItems() -{ - QList selection; - foreach(const QWeakPointer &selectedObject, currentSelection) { - if (selectedObject.isNull()) { - currentSelection.removeOne(selectedObject); - } else { - selection << selectedObject.data(); - } - } - - return selection; -} - -void QDeclarativeDesignView::setSelectedItems(QList items) -{ - data->setSelectedItems(items); -} - -QList QDeclarativeDesignView::selectedItems() -{ - return data->selectedItems(); -} - -void QDeclarativeDesignViewPrivate::clearHighlight() -{ - boundingRectHighlighter->clear(); -} - -void QDeclarativeDesignViewPrivate::highlight(QGraphicsObject * item, ContextFlags flags) -{ - highlight(QList() << item, flags); -} - -void QDeclarativeDesignViewPrivate::highlight(QList items, ContextFlags flags) -{ - if (items.isEmpty()) - return; - - QList objectList; - foreach(QGraphicsItem *item, items) { - QGraphicsItem *child = item; - if (flags & ContextSensitive) - child = subcomponentEditorTool->firstChildOfContext(item); - - if (child) { - QGraphicsObject *childObject = child->toGraphicsObject(); - if (childObject) - objectList << childObject; - } - } - - boundingRectHighlighter->highlight(objectList); -} - -bool QDeclarativeDesignViewPrivate::mouseInsideContextItem() const -{ - return subcomponentEditorTool->containsCursor(cursorPos.toPoint()); -} - -QList QDeclarativeDesignViewPrivate::selectableItems(const QPointF &scenePos) const -{ - QList itemlist = q->scene()->items(scenePos); - return filterForCurrentContext(itemlist); -} - -QList QDeclarativeDesignViewPrivate::selectableItems(const QPoint &pos) const -{ - QList itemlist = q->items(pos); - return filterForCurrentContext(itemlist); -} - -QList QDeclarativeDesignViewPrivate::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const -{ - QList itemlist = q->scene()->items(sceneRect, selectionMode); - - return filterForCurrentContext(itemlist); -} - -void QDeclarativeDesignViewPrivate::_q_changeToSingleSelectTool() -{ - currentToolMode = Constants::SelectionToolMode; - selectionTool->setRubberbandSelectionMode(false); - - changeToSelectTool(); - - emit q->selectToolActivated(); - debugServer->setCurrentTool(Constants::SelectionToolMode); -} - -void QDeclarativeDesignViewPrivate::changeToSelectTool() -{ - if (currentTool == selectionTool) - return; - - currentTool->clear(); - currentTool = selectionTool; - currentTool->clear(); - currentTool->updateSelectedItems(); -} - -void QDeclarativeDesignViewPrivate::_q_changeToMarqueeSelectTool() -{ - changeToSelectTool(); - currentToolMode = Constants::MarqueeSelectionToolMode; - selectionTool->setRubberbandSelectionMode(true); - - emit q->marqueeSelectToolActivated(); - debugServer->setCurrentTool(Constants::MarqueeSelectionToolMode); -} - -void QDeclarativeDesignViewPrivate::_q_changeToZoomTool() -{ - currentToolMode = Constants::ZoomMode; - currentTool->clear(); - currentTool = zoomTool; - currentTool->clear(); - - emit q->zoomToolActivated(); - debugServer->setCurrentTool(Constants::ZoomMode); -} - -void QDeclarativeDesignViewPrivate::_q_changeToColorPickerTool() -{ - if (currentTool == colorPickerTool) - return; - - currentToolMode = Constants::ColorPickerMode; - currentTool->clear(); - currentTool = colorPickerTool; - currentTool->clear(); - - emit q->colorPickerActivated(); - debugServer->setCurrentTool(Constants::ColorPickerMode); -} - -void QDeclarativeDesignViewPrivate::_q_changeContextPathIndex(int index) -{ - subcomponentEditorTool->setContext(index); -} - -void QDeclarativeDesignView::changeAnimationSpeed(qreal slowdownFactor) -{ - data->slowdownFactor = slowdownFactor; - - if (data->slowdownFactor != 0) { - continueExecution(data->slowdownFactor); - } else { - pauseExecution(); - } -} - -void QDeclarativeDesignView::continueExecution(qreal slowdownFactor) -{ - Q_ASSERT(slowdownFactor > 0); - - data->slowdownFactor = slowdownFactor; - static const qreal animSpeedSnapDelta = 0.01f; - bool useStandardSpeed = (qAbs(1.0f - data->slowdownFactor) < animSpeedSnapDelta); - - QUnifiedTimer *timer = QUnifiedTimer::instance(); - timer->setSlowdownFactor(data->slowdownFactor); - timer->setSlowModeEnabled(!useStandardSpeed); - data->executionPaused = false; - - emit executionStarted(data->slowdownFactor); - data->debugServer->setAnimationSpeed(data->slowdownFactor); -} - -void QDeclarativeDesignView::pauseExecution() -{ - QUnifiedTimer *timer = QUnifiedTimer::instance(); - timer->setSlowdownFactor(0); - timer->setSlowModeEnabled(true); - data->executionPaused = true; - - emit executionPaused(); - data->debugServer->setAnimationSpeed(0); -} - -void QDeclarativeDesignViewPrivate::_q_applyChangesFromClient() -{ - -} - - -QList QDeclarativeDesignViewPrivate::filterForSelection(QList &itemlist) const -{ - foreach(QGraphicsItem *item, itemlist) { - if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item)) - itemlist.removeOne(item); - } - - return itemlist; -} - -QList QDeclarativeDesignViewPrivate::filterForCurrentContext(QList &itemlist) const -{ - foreach(QGraphicsItem *item, itemlist) { - - if (isEditorItem(item) || !subcomponentEditorTool->isDirectChildOfContext(item)) { - - // if we're a child, but not directly, replace with the parent that is directly in context. - if (QGraphicsItem *contextParent = subcomponentEditorTool->firstChildOfContext(item)) { - if (contextParent != item) { - if (itemlist.contains(contextParent)) { - itemlist.removeOne(item); - } else { - itemlist.replace(itemlist.indexOf(item), contextParent); - } - } - } else { - itemlist.removeOne(item); - } - } - } - - return itemlist; -} - -bool QDeclarativeDesignViewPrivate::isEditorItem(QGraphicsItem *item) const -{ - return (item->type() == Constants::EditorItemType - || item->type() == Constants::ResizeHandleItemType - || item->data(Constants::EditorItemDataKey).toBool()); -} - -void QDeclarativeDesignViewPrivate::_q_onStatusChanged(QDeclarativeView::Status status) -{ - if (status == QDeclarativeView::Ready) { - if (q->rootObject()) { - if (subcomponentEditorTool->contextIndex() != -1) - subcomponentEditorTool->clear(); - subcomponentEditorTool->pushContext(q->rootObject()); - emit q->executionStarted(1.0f); - - } - debugServer->reloaded(); - } -} - -void QDeclarativeDesignViewPrivate::_q_onCurrentObjectsChanged(QList objects) -{ - QList items; - QList gfxObjects; - foreach(QObject *obj, objects) { - QDeclarativeItem* declarativeItem = qobject_cast(obj); - if (declarativeItem) { - items << declarativeItem; - QGraphicsObject *gfxObj = declarativeItem->toGraphicsObject(); - if (gfxObj) - gfxObjects << gfxObj; - } - } - setSelectedItemsForTools(items); - clearHighlight(); - highlight(gfxObjects, QDeclarativeDesignViewPrivate::IgnoreContext); -} - -QString QDeclarativeDesignView::idStringForObject(QObject *obj) -{ - return QDeclarativeDesignDebugServer::instance()->idStringForObject(obj); -} - -// adjusts bounding boxes on edges of screen to be visible -QRectF QDeclarativeDesignView::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace) -{ - int marginFromEdge = 1; - QRectF boundingRect(boundingRectInSceneSpace); - if (qAbs(boundingRect.left()) - 1 < 2) { - boundingRect.setLeft(marginFromEdge); - } - - 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; -} - -QToolBar *QDeclarativeDesignView::toolbar() const -{ - return data->toolbar; -} - -void QDeclarativeDesignViewPrivate::createToolbar() -{ - toolbar = new QmlToolbar(q); - 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(changeAnimationSpeed(qreal))); - QObject::connect(toolbar, SIGNAL(colorPickerSelected()), q, SLOT(_q_changeToColorPickerTool())); - QObject::connect(toolbar, SIGNAL(zoomToolSelected()), q, SLOT(_q_changeToZoomTool())); - QObject::connect(toolbar, SIGNAL(selectToolSelected()), q, SLOT(_q_changeToSingleSelectTool())); - QObject::connect(toolbar, SIGNAL(marqueeSelectToolSelected()), q, SLOT(_q_changeToMarqueeSelectTool())); - - QObject::connect(toolbar, SIGNAL(applyChangesFromQmlFileSelected()), q, SLOT(_q_applyChangesFromClient())); - - QObject::connect(q, SIGNAL(executionStarted(qreal)), toolbar, SLOT(setAnimationSpeed(qreal))); - QObject::connect(q, SIGNAL(executionPaused()), toolbar, SLOT(setAnimationSpeed())); - - 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())); -} - -void QDeclarativeDesignView::setDebugMode(bool isDebugMode) -{ - if (isDebugMode && !data->jsDebuggerAgent) - data->jsDebuggerAgent = new JSDebuggerAgent(QDeclarativeEnginePrivate::getScriptEngine(engine())); -} - -} //namespace QmlViewer - -#include diff --git a/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h b/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h deleted file mode 100644 index e5a63d9982..0000000000 --- a/share/qtcreator/qmljsdebugger/qdeclarativedesignview_p.h +++ /dev/null @@ -1,142 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef QDECLARATIVEDESIGNVIEW_P_H -#define QDECLARATIVEDESIGNVIEW_P_H - -#include -#include -#include - -#include "qdeclarativedesignview.h" -#include "qdeclarativedesigndebugserver.h" - -QT_FORWARD_DECLARE_CLASS(JSDebuggerAgent) - -namespace QmlViewer { - -class QDeclarativeDesignView; -class SelectionTool; -class ZoomTool; -class ColorPickerTool; -class LayerItem; -class BoundingRectHighlighter; -class SubcomponentEditorTool; -class QmlToolbar; -class CrumblePath; -class AbstractFormEditorTool; - -class QDeclarativeDesignViewPrivate -{ - -public: - - enum ContextFlags { - IgnoreContext, - ContextSensitive - }; - - QDeclarativeDesignViewPrivate(QDeclarativeDesignView *); - ~QDeclarativeDesignViewPrivate(); - - QDeclarativeDesignView *q; - QDeclarativeDesignDebugServer *debugServer; - - QPointF cursorPos; - QList > currentSelection; - - Constants::DesignTool currentToolMode; - AbstractFormEditorTool *currentTool; - - SelectionTool *selectionTool; - ZoomTool *zoomTool; - ColorPickerTool *colorPickerTool; - SubcomponentEditorTool *subcomponentEditorTool; - LayerItem *manipulatorLayer; - - BoundingRectHighlighter *boundingRectHighlighter; - - bool designModeBehavior; - - bool executionPaused; - qreal slowdownFactor; - - JSDebuggerAgent *jsDebuggerAgent; - - QmlToolbar *toolbar; - - void clearEditorItems(); - void createToolbar(); - void changeToSelectTool(); - QList filterForCurrentContext(QList &itemlist) const; - 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(QList item, ContextFlags flags = ContextSensitive); - void highlight(QGraphicsObject *item, ContextFlags flags = ContextSensitive); - - bool mouseInsideContextItem() const; - bool isEditorItem(QGraphicsItem *item) const; - - QGraphicsItem *currentRootItem() const; - - void enterContext(QGraphicsItem *itemToEnter); - - 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()); - void _q_reparentQmlObject(QObject *, QObject *); - - void _q_changeToSingleSelectTool(); - void _q_changeToMarqueeSelectTool(); - void _q_changeToZoomTool(); - void _q_changeToColorPickerTool(); - void _q_changeContextPathIndex(int index); - void _q_clearComponentCache(); - - static QDeclarativeDesignViewPrivate *get(QDeclarativeDesignView *v) { return v->d_func(); } -}; - -} // namespace QmlViewer - -#endif // QDECLARATIVEDESIGNVIEW_P_H diff --git a/share/qtcreator/qmljsdebugger/qdeclarativeviewobserver.cpp b/share/qtcreator/qmljsdebugger/qdeclarativeviewobserver.cpp new file mode 100644 index 0000000000..d94de934b7 --- /dev/null +++ b/share/qtcreator/qmljsdebugger/qdeclarativeviewobserver.cpp @@ -0,0 +1,804 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#include "qdeclarativeviewobserver.h" +#include "qdeclarativeviewobserver_p.h" +#include "qdeclarativedesigndebugserver.h" +#include "selectiontool.h" +#include "zoomtool.h" +#include "colorpickertool.h" +#include "layeritem.h" +#include "boundingrecthighlighter.h" +#include "subcomponenteditortool.h" +#include "qmltoolbar.h" +#include "jsdebuggeragent.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace QmlViewer { + +const int SceneChangeUpdateInterval = 5000; + +QDeclarativeViewObserverPrivate::QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *q) : + q(q), + designModeBehavior(false), + executionPaused(false), + slowdownFactor(1.0f), + jsDebuggerAgent(0), + toolbar(0) +{ +} + +QDeclarativeViewObserverPrivate::~QDeclarativeViewObserverPrivate() +{ +} + +QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent) : + QObject(parent), data(new QDeclarativeViewObserverPrivate(this)) +{ + data->view = view; + data->manipulatorLayer = new LayerItem(view->scene()); + data->selectionTool = new SelectionTool(this); + data->zoomTool = new ZoomTool(this); + data->colorPickerTool = new ColorPickerTool(this); + data->boundingRectHighlighter = new BoundingRectHighlighter(this); + data->subcomponentEditorTool = new SubcomponentEditorTool(this); + data->currentTool = data->selectionTool; + + data->view->setMouseTracking(true); + data->view->viewport()->installEventFilter(this); + + data->debugServer = QDeclarativeDesignDebugServer::instance(); + connect(data->debugServer, SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool))); + connect(data->debugServer, SIGNAL(reloadRequested()), SLOT(_q_reloadView())); + connect(data->debugServer, + SIGNAL(currentObjectsChanged(QList)), + SLOT(_q_onCurrentObjectsChanged(QList))); + connect(data->debugServer, SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal))); + connect(data->debugServer, SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool())); + connect(data->debugServer, SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool())); + connect(data->debugServer, SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool())); + connect(data->debugServer, SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool())); + connect(data->debugServer, + SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)), + SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString))); + connect(data->debugServer, + SIGNAL(objectReparentRequested(QObject *, QObject *)), + SLOT(_q_reparentQmlObject(QObject *, QObject *))); + connect(data->debugServer, SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int))); + connect(data->debugServer, SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache())); + connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status))); + + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor))); + connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), + data->debugServer, SLOT(selectedColorChanged(QColor))); + + connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared())); + connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString))); + connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped())); + connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), data->debugServer, SLOT(contextPathUpdated(QStringList))); + + data->createToolbar(); + + data->_q_changeToSingleSelectTool(); + + // always start debug mode - that's what this design view is for. + setDebugMode(true); +} + +QDeclarativeViewObserver::~QDeclarativeViewObserver() +{ +} + +void QDeclarativeViewObserver::setInspectorContext(int contextIndex) +{ + if (data->subcomponentEditorTool->contextIndex() != contextIndex) { + QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex); + if (object) + data->debugServer->setCurrentObjects(QList() << object); + } +} + +void QDeclarativeViewObserverPrivate::_q_reloadView() +{ + subcomponentEditorTool->clear(); + clearHighlight(); + emit q->reloadRequested(); +} + +void QDeclarativeViewObserverPrivate::clearEditorItems() +{ + clearHighlight(); + setSelectedItems(QList()); +} + +bool QDeclarativeViewObserver::eventFilter(QObject *obj, QEvent *event) + { + 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(AbstractFormEditorTool::titleForItem(selItems.first())); + } else { + declarativeView()->setToolTip(QString()); + } + if (event->buttons()) { + data->subcomponentEditorTool->mouseMoveEvent(event); + data->currentTool->mouseMoveEvent(event); + } else { + data->subcomponentEditorTool->hoverMoveEvent(event); + data->currentTool->hoverMoveEvent(event); + } + return true; +} + +bool QDeclarativeViewObserver::mouseReleaseEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->subcomponentEditorTool->mouseReleaseEvent(event); + + data->cursorPos = event->pos(); + data->currentTool->mouseReleaseEvent(event); + + data->debugServer->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems())); + 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_Enter: + case Qt::Key_Return: + if (!data->selectedItems().isEmpty()) + data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first()); + break; + case Qt::Key_Space: + if (data->executionPaused) { + continueExecution(data->slowdownFactor); + } else { + pauseExecution(); + } + break; + default: + break; + } + + data->currentTool->keyReleaseEvent(event); + return true; +} + +void QDeclarativeViewObserverPrivate::_q_createQmlObject(const QString &qml, QObject *parent, const QStringList &importList, const QString &filename) +{ + if (!parent) + return; + + QString imports; + foreach(const QString &s, importList) { + imports += s + "\n"; + } + + QDeclarativeContext *parentContext = view->engine()->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); + QDeclarativeItem *parentItem = qobject_cast(parent); + QDeclarativeItem *newItem = qobject_cast(newObject); + if (parentItem && newItem) { + newItem->setParentItem(parentItem); + } + } +} + +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_clearComponentCache() +{ + view->engine()->clearComponentCache(); +} + +QGraphicsItem *QDeclarativeViewObserverPrivate::currentRootItem() const +{ + return subcomponentEditorTool->currentRootItem(); +} + +bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (!data->designModeBehavior) + return false; + + if (data->currentToolMode != Constants::SelectionToolMode + && data->currentToolMode != Constants::MarqueeSelectionToolMode) + return true; + + QGraphicsItem *itemToEnter = 0; + QList itemList = data->view->items(event->pos()); + data->filterForSelection(itemList); + + if (data->selectedItems().isEmpty() && !itemList.isEmpty()) { + itemToEnter = itemList.first(); + } else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) { + itemToEnter = itemList.first(); + } + + if (itemToEnter) + itemToEnter = data->subcomponentEditorTool->firstChildOfContext(itemToEnter); + + data->subcomponentEditorTool->setCurrentItem(itemToEnter); + data->subcomponentEditorTool->mouseDoubleClickEvent(event); + + if ((event->buttons() & Qt::LeftButton) && itemToEnter) { + QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject(); + if (objectToEnter) + data->debugServer->setCurrentObjects(QList() << objectToEnter); + } + + return true; +} + +bool QDeclarativeViewObserver::wheelEvent(QWheelEvent *event) +{ + if (!data->designModeBehavior) + return false; + data->currentTool->wheelEvent(event); + return true; +} + +void QDeclarativeViewObserverPrivate::enterContext(QGraphicsItem *itemToEnter) +{ + QGraphicsItem *itemUnderCurrentContext = itemToEnter; + if (itemUnderCurrentContext) + itemUnderCurrentContext = subcomponentEditorTool->firstChildOfContext(itemToEnter); + + if (itemUnderCurrentContext) + subcomponentEditorTool->setCurrentItem(itemToEnter); +} + +void QDeclarativeViewObserver::setDesignModeBehavior(bool value) +{ + emit designModeBehaviorChanged(value); + + data->toolbar->setDesignModeBehavior(value); + data->debugServer->setDesignModeBehavior(value); + + data->designModeBehavior = value; + if (data->subcomponentEditorTool) { + data->subcomponentEditorTool->clear(); + data->clearHighlight(); + data->setSelectedItems(QList()); + + if (data->view->rootObject()) + data->subcomponentEditorTool->pushContext(data->view->rootObject()); + } + + if (!data->designModeBehavior) + data->clearEditorItems(); +} + +bool QDeclarativeViewObserver::designModeBehavior() +{ + return data->designModeBehavior; +} + +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) +{ + currentSelection.clear(); + foreach(QGraphicsItem *item, items) { + if (item) { + QGraphicsObject *obj = item->toGraphicsObject(); + if (obj) + currentSelection << obj; + } + } + currentTool->updateSelectedItems(); +} + +void QDeclarativeViewObserverPrivate::setSelectedItems(QList items) +{ + setSelectedItemsForTools(items); + debugServer->setCurrentObjects(AbstractFormEditorTool::toObjectList(items)); +} + +QList QDeclarativeViewObserverPrivate::selectedItems() +{ + QList selection; + foreach(const QWeakPointer &selectedObject, currentSelection) { + if (selectedObject.isNull()) { + currentSelection.removeOne(selectedObject); + } else { + 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(QGraphicsObject * item, ContextFlags flags) +{ + highlight(QList() << item, flags); +} + +void QDeclarativeViewObserverPrivate::highlight(QList items, ContextFlags flags) +{ + if (items.isEmpty()) + return; + + QList objectList; + foreach(QGraphicsItem *item, items) { + QGraphicsItem *child = item; + if (flags & ContextSensitive) + child = subcomponentEditorTool->firstChildOfContext(item); + + if (child) { + QGraphicsObject *childObject = child->toGraphicsObject(); + if (childObject) + objectList << childObject; + } + } + + boundingRectHighlighter->highlight(objectList); +} + +bool QDeclarativeViewObserverPrivate::mouseInsideContextItem() const +{ + return subcomponentEditorTool->containsCursor(cursorPos.toPoint()); +} + +QList QDeclarativeViewObserverPrivate::selectableItems(const QPointF &scenePos) const +{ + QList itemlist = view->scene()->items(scenePos); + return filterForCurrentContext(itemlist); +} + +QList QDeclarativeViewObserverPrivate::selectableItems(const QPoint &pos) const +{ + QList itemlist = view->items(pos); + return filterForCurrentContext(itemlist); +} + +QList QDeclarativeViewObserverPrivate::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const +{ + QList itemlist = view->scene()->items(sceneRect, selectionMode); + + return filterForCurrentContext(itemlist); +} + +void QDeclarativeViewObserverPrivate::_q_changeToSingleSelectTool() +{ + currentToolMode = Constants::SelectionToolMode; + selectionTool->setRubberbandSelectionMode(false); + + changeToSelectTool(); + + emit q->selectToolActivated(); + debugServer->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(); + debugServer->setCurrentTool(Constants::MarqueeSelectionToolMode); +} + +void QDeclarativeViewObserverPrivate::_q_changeToZoomTool() +{ + currentToolMode = Constants::ZoomMode; + currentTool->clear(); + currentTool = zoomTool; + currentTool->clear(); + + emit q->zoomToolActivated(); + debugServer->setCurrentTool(Constants::ZoomMode); +} + +void QDeclarativeViewObserverPrivate::_q_changeToColorPickerTool() +{ + if (currentTool == colorPickerTool) + return; + + currentToolMode = Constants::ColorPickerMode; + currentTool->clear(); + currentTool = colorPickerTool; + currentTool->clear(); + + emit q->colorPickerActivated(); + debugServer->setCurrentTool(Constants::ColorPickerMode); +} + +void QDeclarativeViewObserverPrivate::_q_changeContextPathIndex(int index) +{ + subcomponentEditorTool->setContext(index); +} + +void QDeclarativeViewObserver::changeAnimationSpeed(qreal slowdownFactor) +{ + data->slowdownFactor = slowdownFactor; + + if (data->slowdownFactor != 0) { + continueExecution(data->slowdownFactor); + } else { + pauseExecution(); + } +} + +void QDeclarativeViewObserver::continueExecution(qreal slowdownFactor) +{ + Q_ASSERT(slowdownFactor > 0); + + data->slowdownFactor = slowdownFactor; + static const qreal animSpeedSnapDelta = 0.01f; + bool useStandardSpeed = (qAbs(1.0f - data->slowdownFactor) < animSpeedSnapDelta); + + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setSlowdownFactor(data->slowdownFactor); + timer->setSlowModeEnabled(!useStandardSpeed); + data->executionPaused = false; + + emit executionStarted(data->slowdownFactor); + data->debugServer->setAnimationSpeed(data->slowdownFactor); +} + +void QDeclarativeViewObserver::pauseExecution() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setSlowdownFactor(0); + timer->setSlowModeEnabled(true); + data->executionPaused = true; + + emit executionPaused(); + data->debugServer->setAnimationSpeed(0); +} + +void QDeclarativeViewObserverPrivate::_q_applyChangesFromClient() +{ + +} + + +QList QDeclarativeViewObserverPrivate::filterForSelection(QList &itemlist) const +{ + foreach(QGraphicsItem *item, itemlist) { + if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item)) + itemlist.removeOne(item); + } + + return itemlist; +} + +QList QDeclarativeViewObserverPrivate::filterForCurrentContext(QList &itemlist) const +{ + foreach(QGraphicsItem *item, itemlist) { + + if (isEditorItem(item) || !subcomponentEditorTool->isDirectChildOfContext(item)) { + + // if we're a child, but not directly, replace with the parent that is directly in context. + if (QGraphicsItem *contextParent = subcomponentEditorTool->firstChildOfContext(item)) { + if (contextParent != item) { + if (itemlist.contains(contextParent)) { + itemlist.removeOne(item); + } else { + itemlist.replace(itemlist.indexOf(item), contextParent); + } + } + } else { + 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) { + if (view->rootObject()) { + if (subcomponentEditorTool->contextIndex() != -1) + subcomponentEditorTool->clear(); + subcomponentEditorTool->pushContext(view->rootObject()); + emit q->executionStarted(1.0f); + + } + debugServer->reloaded(); + } +} + +void QDeclarativeViewObserverPrivate::_q_onCurrentObjectsChanged(QList objects) +{ + QList items; + QList gfxObjects; + foreach(QObject *obj, objects) { + QDeclarativeItem* declarativeItem = qobject_cast(obj); + if (declarativeItem) { + items << declarativeItem; + QGraphicsObject *gfxObj = declarativeItem->toGraphicsObject(); + if (gfxObj) + gfxObjects << gfxObj; + } + } + setSelectedItemsForTools(items); + clearHighlight(); + highlight(gfxObjects, QDeclarativeViewObserverPrivate::IgnoreContext); +} + +QString QDeclarativeViewObserver::idStringForObject(QObject *obj) +{ + return QDeclarativeDesignDebugServer::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; +} + +QToolBar *QDeclarativeViewObserver::toolbar() const +{ + return data->toolbar; +} + +void QDeclarativeViewObserverPrivate::createToolbar() +{ + toolbar = new QmlToolbar(q->declarativeView()); + 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(changeAnimationSpeed(qreal))); + QObject::connect(toolbar, SIGNAL(colorPickerSelected()), q, SLOT(_q_changeToColorPickerTool())); + QObject::connect(toolbar, SIGNAL(zoomToolSelected()), q, SLOT(_q_changeToZoomTool())); + QObject::connect(toolbar, SIGNAL(selectToolSelected()), q, SLOT(_q_changeToSingleSelectTool())); + QObject::connect(toolbar, SIGNAL(marqueeSelectToolSelected()), q, SLOT(_q_changeToMarqueeSelectTool())); + + QObject::connect(toolbar, SIGNAL(applyChangesFromQmlFileSelected()), q, SLOT(_q_applyChangesFromClient())); + + QObject::connect(q, SIGNAL(executionStarted(qreal)), toolbar, SLOT(setAnimationSpeed(qreal))); + QObject::connect(q, SIGNAL(executionPaused()), toolbar, SLOT(setAnimationSpeed())); + + 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())); +} + +void QDeclarativeViewObserver::setDebugMode(bool isDebugMode) +{ + if (isDebugMode && !data->jsDebuggerAgent) + data->jsDebuggerAgent = new JSDebuggerAgent(QDeclarativeEnginePrivate::getScriptEngine(data->view->engine())); +} + +} //namespace QmlViewer + +#include diff --git a/share/qtcreator/qmljsdebugger/qdeclarativeviewobserver_p.h b/share/qtcreator/qmljsdebugger/qdeclarativeviewobserver_p.h new file mode 100644 index 0000000000..85e28b94c2 --- /dev/null +++ b/share/qtcreator/qmljsdebugger/qdeclarativeviewobserver_p.h @@ -0,0 +1,143 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, 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. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ + +#ifndef QDECLARATIVEDESIGNVIEW_P_H +#define QDECLARATIVEDESIGNVIEW_P_H + +#include +#include +#include + +#include "qdeclarativeviewobserver.h" +#include "qdeclarativedesigndebugserver.h" + +QT_FORWARD_DECLARE_CLASS(JSDebuggerAgent) + +namespace QmlViewer { + +class QDeclarativeViewObserver; +class SelectionTool; +class ZoomTool; +class ColorPickerTool; +class LayerItem; +class BoundingRectHighlighter; +class SubcomponentEditorTool; +class QmlToolbar; +class CrumblePath; +class AbstractFormEditorTool; + +class QDeclarativeViewObserverPrivate +{ + +public: + + enum ContextFlags { + IgnoreContext, + ContextSensitive + }; + + QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *); + ~QDeclarativeViewObserverPrivate(); + + QDeclarativeView *view; + QDeclarativeViewObserver *q; + QDeclarativeDesignDebugServer *debugServer; + + QPointF cursorPos; + QList > currentSelection; + + Constants::DesignTool currentToolMode; + AbstractFormEditorTool *currentTool; + + SelectionTool *selectionTool; + ZoomTool *zoomTool; + ColorPickerTool *colorPickerTool; + SubcomponentEditorTool *subcomponentEditorTool; + LayerItem *manipulatorLayer; + + BoundingRectHighlighter *boundingRectHighlighter; + + bool designModeBehavior; + + bool executionPaused; + qreal slowdownFactor; + + JSDebuggerAgent *jsDebuggerAgent; + + QmlToolbar *toolbar; + + void clearEditorItems(); + void createToolbar(); + void changeToSelectTool(); + QList filterForCurrentContext(QList &itemlist) const; + 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(QList item, ContextFlags flags = ContextSensitive); + void highlight(QGraphicsObject *item, ContextFlags flags = ContextSensitive); + + bool mouseInsideContextItem() const; + bool isEditorItem(QGraphicsItem *item) const; + + QGraphicsItem *currentRootItem() const; + + void enterContext(QGraphicsItem *itemToEnter); + + 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()); + void _q_reparentQmlObject(QObject *, QObject *); + + void _q_changeToSingleSelectTool(); + void _q_changeToMarqueeSelectTool(); + void _q_changeToZoomTool(); + void _q_changeToColorPickerTool(); + void _q_changeContextPathIndex(int index); + void _q_clearComponentCache(); + + static QDeclarativeViewObserverPrivate *get(QDeclarativeViewObserver *v) { return v->d_func(); } +}; + +} // namespace QmlViewer + +#endif // QDECLARATIVEDESIGNVIEW_P_H diff --git a/share/qtcreator/qmljsdebugger/qmljsdebugger-lib.pri b/share/qtcreator/qmljsdebugger/qmljsdebugger-lib.pri index 7421f0e9ec..288b3f3542 100644 --- a/share/qtcreator/qmljsdebugger/qmljsdebugger-lib.pri +++ b/share/qtcreator/qmljsdebugger/qmljsdebugger-lib.pri @@ -17,15 +17,15 @@ include($$PWD/editor/editor.pri) ## Input HEADERS += \ include/jsdebuggeragent.h \ - include/qdeclarativedesignview.h \ + include/qdeclarativeviewobserver.h \ include/qdeclarativedesigndebugserver.h \ include/qmlviewerconstants.h \ include/qmljsdebugger_global.h \ - qdeclarativedesignview_p.h + qdeclarativeviewobserver_p.h SOURCES += \ jsdebuggeragent.cpp \ - qdeclarativedesignview.cpp \ + qdeclarativeviewobserver.cpp \ qdeclarativedesigndebugserver.cpp OTHER_FILES += qmljsdebugger.pri diff --git a/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp b/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp index 9af81c9a85..3a85473788 100644 --- a/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp +++ b/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.cpp @@ -42,7 +42,7 @@ QString QmlApplicationViewerPrivate::adjustPath(const QString &path) QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) : #ifdef QMLINSPECTOR - QmlViewer::QDeclarativeDesignView(parent) + QmlViewer::QDeclarativeViewObserver(parent) #else QDeclarativeView(parent) #endif diff --git a/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.h b/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.h index 4327a825ee..1ad160b357 100644 --- a/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.h +++ b/share/qtcreator/templates/qmlapp/qmlapplicationviewer/qmlapplicationviewer.h @@ -2,8 +2,8 @@ #define QMLAPPLICATIONVIEWER_H #ifdef QMLINSPECTOR -#include -class QmlApplicationViewer : public QmlViewer::QDeclarativeDesignView +#include +class QmlApplicationViewer : public QmlViewer::QDeclarativeViewObserver #else // QMLINSPECTOR #include class QmlApplicationViewer : public QDeclarativeView diff --git a/src/plugins/debugger/debuggerrunner.cpp b/src/plugins/debugger/debuggerrunner.cpp index fbebb43aae..d22b393b02 100644 --- a/src/plugins/debugger/debuggerrunner.cpp +++ b/src/plugins/debugger/debuggerrunner.cpp @@ -307,11 +307,11 @@ static DebuggerEngineType engineForToolChain(int toolChainType) // unless the toolchain provides a hint. DebuggerEngineType DebuggerRunControl::engineForExecutable(const QString &executable) { - if (executable.endsWith(_("qmlviewer"))) { + /*if (executable.endsWith(_("qmlviewer"))) { if (d->m_enabledEngines & QmlEngineType) return QmlEngineType; d->m_errorMessage = msgEngineNotAvailable("Qml Engine"); - } + }*/ if (executable.endsWith(_(".js"))) { if (d->m_enabledEngines & ScriptEngineType) @@ -380,13 +380,13 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams // Figure out engine according to toolchain, executable, attach or default. DebuggerEngineType engineType = NoEngineType; DebuggerLanguages activeLangs = DebuggerPlugin::instance()->activeLanguages(); - bool isQmlExecutable = sp.executable.endsWith(_("qmlviewer")) || sp.executable.endsWith(_("qmlobserver")); + /*bool isQmlExecutable = sp.executable.endsWith(_("qmlviewer")) || sp.executable.endsWith(_("qmlobserver")); #ifdef Q_OS_MAC isQmlExecutable = sp.executable.endsWith(_("QMLViewer.app")) || sp.executable.endsWith(_("QMLObserver.app")); #endif - if (isQmlExecutable) + if (isQmlExecutable && sp.startMode != AttachCore) engineType = QmlEngineType; - else if (sp.executable.endsWith(_(".js"))) + else */if (sp.executable.endsWith(_(".js"))) engineType = ScriptEngineType; else if (sp.executable.endsWith(_(".py"))) engineType = PdbEngineType; diff --git a/src/tools/qml/qmlobserver/qmlruntime.cpp b/src/tools/qml/qmlobserver/qmlruntime.cpp index 6e5bdcf335..fbbeda6efe 100644 --- a/src/tools/qml/qmlobserver/qmlruntime.cpp +++ b/src/tools/qml/qmlobserver/qmlruntime.cpp @@ -54,7 +54,7 @@ # include "ui_recopts.h" #endif -#include +#include #include #include @@ -613,13 +613,14 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) recdlg->warning->hide(); } - canvas = new QmlViewer::QDeclarativeDesignView(this); + canvas = new QDeclarativeView(this); + observer = new QmlViewer::QDeclarativeViewObserver(canvas, this); if (!(flags & Qt::FramelessWindowHint)) { m_crumblePathWidget = new Utils::CrumblePath(canvas); #ifndef Q_WS_MAC m_crumblePathWidget->setStyleSheet("QWidget { border-bottom: 1px solid black; }"); #endif - m_crumblePathWidget->setVisible(canvas->designModeBehavior()); + m_crumblePathWidget->setVisible(observer->designModeBehavior()); // CrumblePath is not in a layout, so that it overlays the central widget // The event filter ensures that its width stays in sync nevertheless @@ -641,15 +642,15 @@ QDeclarativeViewer::QDeclarativeViewer(QWidget *parent, Qt::WindowFlags flags) canvas->setFocus(); - QObject::connect(canvas, SIGNAL(reloadRequested()), this, SLOT(reload())); + QObject::connect(observer, SIGNAL(reloadRequested()), this, SLOT(reload())); QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); QObject::connect(canvas, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(statusChanged())); if (m_crumblePathWidget) { - QObject::connect(canvas, SIGNAL(inspectorContextCleared()), m_crumblePathWidget, SLOT(clear())); - QObject::connect(canvas, SIGNAL(inspectorContextPushed(QString)), m_crumblePathWidget, SLOT(pushElement(QString))); - QObject::connect(canvas, SIGNAL(inspectorContextPopped()), m_crumblePathWidget, SLOT(popElement())); - QObject::connect(m_crumblePathWidget, SIGNAL(elementClicked(int)), canvas, SLOT(setInspectorContext(int))); - QObject::connect(canvas, SIGNAL(designModeBehaviorChanged(bool)), m_crumblePathWidget, SLOT(setVisible(bool))); + QObject::connect(observer, SIGNAL(inspectorContextCleared()), m_crumblePathWidget, SLOT(clear())); + QObject::connect(observer, SIGNAL(inspectorContextPushed(QString)), m_crumblePathWidget, SLOT(pushElement(QString))); + QObject::connect(observer, SIGNAL(inspectorContextPopped()), m_crumblePathWidget, SLOT(popElement())); + QObject::connect(m_crumblePathWidget, SIGNAL(elementClicked(int)), observer, SLOT(setInspectorContext(int))); + QObject::connect(observer, SIGNAL(designModeBehaviorChanged(bool)), m_crumblePathWidget, SLOT(setVisible(bool))); } QObject::connect(canvas->engine(), SIGNAL(quit()), QCoreApplication::instance (), SLOT(quit())); @@ -691,12 +692,12 @@ void QDeclarativeViewer::setDesignModeBehavior(bool value) { if (designModeBehaviorAction) designModeBehaviorAction->setChecked(value); - canvas->setDesignModeBehavior(value); + observer->setDesignModeBehavior(value); } void QDeclarativeViewer::setDebugMode(bool on) { - canvas->setDebugMode(on); + observer->setDebugMode(on); } void QDeclarativeViewer::enableExperimentalGestures() @@ -792,10 +793,10 @@ void QDeclarativeViewer::createMenu() designModeBehaviorAction = new QAction(tr("&Observer Mode"), this); designModeBehaviorAction->setShortcut(QKeySequence("Ctrl+D")); designModeBehaviorAction->setCheckable(true); - designModeBehaviorAction->setChecked(canvas->designModeBehavior()); + designModeBehaviorAction->setChecked(observer->designModeBehavior()); designModeBehaviorAction->setEnabled(QDeclarativeDesignDebugServer::hasDebuggingClient()); connect(designModeBehaviorAction, SIGNAL(triggered(bool)), this, SLOT(setDesignModeBehavior(bool))); - connect(canvas, SIGNAL(designModeBehaviorChanged(bool)), designModeBehaviorAction, SLOT(setChecked(bool))); + connect(observer, SIGNAL(designModeBehaviorChanged(bool)), designModeBehaviorAction, SLOT(setChecked(bool))); connect(QDeclarativeDesignDebugServer::instance(), SIGNAL(debuggingClientChanged(bool)), designModeBehaviorAction, SLOT(setEnabled(bool))); QAction *proxyAction = new QAction(tr("HTTP &Proxy..."), this); @@ -1060,7 +1061,7 @@ void QDeclarativeViewer::addPluginPath(const QString& plugin) void QDeclarativeViewer::reload() { - canvas->setDesignModeBehavior(false); + observer->setDesignModeBehavior(false); open(currentFileOrUrl); } diff --git a/src/tools/qml/qmlobserver/qmlruntime.h b/src/tools/qml/qmlobserver/qmlruntime.h index 2c6c5eefbd..1160d91eb5 100644 --- a/src/tools/qml/qmlobserver/qmlruntime.h +++ b/src/tools/qml/qmlobserver/qmlruntime.h @@ -50,7 +50,7 @@ #include "loggerwidget.h" namespace QmlViewer { - class QDeclarativeDesignView; + class QDeclarativeViewObserver; } namespace Utils { class CrumblePath; @@ -167,7 +167,8 @@ private: LoggerWidget *loggerWindow; - QmlViewer::QDeclarativeDesignView *canvas; + QDeclarativeView *canvas; + QmlViewer::QDeclarativeViewObserver *observer; QSize initialSize; QString currentFileOrUrl; QTimer recordTimer; -- cgit v1.2.1