diff --git a/src/libs/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp b/src/libs/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp index ec703c014ddd3b8f0e4eeeb37ec9c521bbdf4263..8f24552890d439c9d9bb9340a51e51a650c2fa9b 100644 --- a/src/libs/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp +++ b/src/libs/qmljsdebugger/editor/rubberbandselectionmanipulator.cpp @@ -28,7 +28,7 @@ **************************************************************************/ #include "rubberbandselectionmanipulator.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativedesignview_p.h" #include <QDebug> @@ -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(m_editorView->selectableItems(beginPoint)); + m_beginFormEditorItem = topFormEditorItem(QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(beginPoint)); m_oldSelectionList = m_editorView->selectedItems(); } @@ -84,7 +84,7 @@ void RubberBandSelectionManipulator::end() void RubberBandSelectionManipulator::select(SelectionType selectionType) { - QList<QGraphicsItem*> itemList = m_editorView->selectableItems(m_selectionRectangleElement.rect(), + QList<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(m_selectionRectangleElement.rect(), Qt::IntersectsItemShape); QList<QGraphicsItem*> newSelectionList; diff --git a/src/libs/qmljsdebugger/editor/selectionindicator.cpp b/src/libs/qmljsdebugger/editor/selectionindicator.cpp index 49b96ea1ee80dd86e5421029db3f3aaf75bbb328..fdf0104e0e68d06849a1f101c343d677aaf3654c 100644 --- a/src/libs/qmljsdebugger/editor/selectionindicator.cpp +++ b/src/libs/qmljsdebugger/editor/selectionindicator.cpp @@ -28,7 +28,7 @@ **************************************************************************/ #include "selectionindicator.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativedesignview_p.h" #include "qmlviewerconstants.h" #include <QPen> @@ -75,7 +75,7 @@ QPolygonF SelectionIndicator::addBoundingRectToPolygon(QGraphicsItem *item, QPol polygon = polygon.united(item->mapToScene(item->boundingRect())); foreach(QGraphicsItem *child, item->childItems()) { - if (!m_view->isEditorItem(child)) + if (!QDeclarativeDesignViewPrivate::get(m_view)->isEditorItem(child)) addBoundingRectToPolygon(child, polygon); } return polygon; diff --git a/src/libs/qmljsdebugger/editor/selectiontool.cpp b/src/libs/qmljsdebugger/editor/selectiontool.cpp index bbeebad6e35dd5319e725d96c07ebb5164588eca..6c76ec1bc171ff0529f453949c0a4b3029107a9b 100644 --- a/src/libs/qmljsdebugger/editor/selectiontool.cpp +++ b/src/libs/qmljsdebugger/editor/selectiontool.cpp @@ -28,9 +28,10 @@ **************************************************************************/ #include "selectiontool.h" +#include "layeritem.h" //#include "resizehandleitem.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativedesignview_p.h" #include <private/qdeclarativeitem_p.h> #include <private/qdeclarativecontext_p.h> @@ -52,9 +53,9 @@ namespace QmlViewer { SelectionTool::SelectionTool(QDeclarativeDesignView *editorView) : AbstractFormEditorTool(editorView), m_rubberbandSelectionMode(false), - m_rubberbandSelectionManipulator(editorView->manipulatorLayer(), editorView), + m_rubberbandSelectionManipulator(QDeclarativeDesignViewPrivate::get(editorView)->manipulatorLayer, editorView), m_singleSelectionManipulator(editorView), - m_selectionIndicator(editorView, editorView->manipulatorLayer()), + m_selectionIndicator(editorView, QDeclarativeDesignViewPrivate::get(editorView)->manipulatorLayer), //m_resizeIndicator(editorView->manipulatorLayer()), m_selectOnlyContentItems(true) { @@ -83,7 +84,7 @@ SingleSelectionManipulator::SelectionType SelectionTool::getSelectionType(Qt::Ke bool SelectionTool::alreadySelected(const QList<QGraphicsItem*> &itemList) const { - const QList<QGraphicsItem*> selectedItems = view()->selectedItems(); + const QList<QGraphicsItem*> selectedItems = QDeclarativeDesignViewPrivate::get(view())->selectedItems(); if (selectedItems.isEmpty()) return false; @@ -99,7 +100,7 @@ bool SelectionTool::alreadySelected(const QList<QGraphicsItem*> &itemList) const void SelectionTool::mousePressEvent(QMouseEvent *event) { - QList<QGraphicsItem*> itemList = view()->selectableItems(event->pos()); + QList<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos()); SingleSelectionManipulator::SelectionType selectionType = getSelectionType(event->modifiers()); if (event->buttons() & Qt::LeftButton) { @@ -110,7 +111,7 @@ void SelectionTool::mousePressEvent(QMouseEvent *event) } else { if (itemList.isEmpty()) { - view()->setSelectedItems(itemList); + QDeclarativeDesignViewPrivate::get(view())->setSelectedItems(itemList); return; } @@ -160,7 +161,7 @@ void SelectionTool::mousePressEvent(QMouseEvent *event) void SelectionTool::createContextMenu(QList<QGraphicsItem*> itemList, QPoint globalPos) { - if (!view()->mouseInsideContextItem()) + if (!QDeclarativeDesignViewPrivate::get(view())->mouseInsideContextItem()) return; QMenu contextMenu; @@ -222,7 +223,7 @@ void SelectionTool::contextMenuElementHovered(QAction *action) { int itemListIndex = action->data().toInt(); if (itemListIndex >= 0 && itemListIndex < m_contextMenuItemList.length()) { - view()->highlight(m_contextMenuItemList.at(itemListIndex)); + QDeclarativeDesignViewPrivate::get(view())->highlight(m_contextMenuItemList.at(itemListIndex)); } } @@ -277,7 +278,7 @@ void SelectionTool::hoverMoveEvent(QMouseEvent * event) QGraphicsItem *topSelectableItem = 0; foreach(QGraphicsItem* item, selectableItemList) { - if (!view()->isEditorItem(item) + if (!QDeclarativeDesignViewPrivate::get(view())->isEditorItem(item) /*&& !item->qmlItemNode().isRootNode() && (QGraphicsItem->qmlItemNode().hasShowContent() || !m_selectOnlyContentItems)*/) { @@ -286,9 +287,9 @@ void SelectionTool::hoverMoveEvent(QMouseEvent * event) } } - view()->highlight(topSelectableItem); + QDeclarativeDesignViewPrivate::get(view())->highlight(topSelectableItem); } else { - view()->clearHighlight(); + QDeclarativeDesignViewPrivate::get(view())->clearHighlight(); } } @@ -356,7 +357,7 @@ void SelectionTool::wheelEvent(QWheelEvent *event) if (event->orientation() == Qt::Horizontal || m_rubberbandSelectionMode) return; - QList<QGraphicsItem*> itemList = view()->selectableItems(event->pos()); + QList<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos()); int selectedIdx = 0; if (!view()->selectedItems().isEmpty()) { diff --git a/src/libs/qmljsdebugger/editor/singleselectionmanipulator.cpp b/src/libs/qmljsdebugger/editor/singleselectionmanipulator.cpp index c585618c76fd683b7a6e7bb4d7105e9c2c718c88..3c5fed7cca358d647c02a74c0029db8ae7f326e1 100644 --- a/src/libs/qmljsdebugger/editor/singleselectionmanipulator.cpp +++ b/src/libs/qmljsdebugger/editor/singleselectionmanipulator.cpp @@ -29,6 +29,7 @@ #include "singleselectionmanipulator.h" #include "qdeclarativedesignview.h" +#include "qdeclarativedesignview_p.h" #include <QtDebug> namespace QmlViewer { @@ -44,7 +45,7 @@ void SingleSelectionManipulator::begin(const QPointF &beginPoint) { m_beginPoint = beginPoint; m_isActive = true; - m_oldSelectionList = m_editorView->selectedItems(); + m_oldSelectionList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectedItems(); } void SingleSelectionManipulator::update(const QPointF &/*updatePoint*/) @@ -115,7 +116,7 @@ void SingleSelectionManipulator::select(SelectionType selectionType, const QList void SingleSelectionManipulator::select(SelectionType selectionType, bool selectOnlyContentItems) { - QList<QGraphicsItem*> itemList = m_editorView->selectableItems(m_beginPoint); + QList<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(m_beginPoint); select(selectionType, itemList, selectOnlyContentItems); } diff --git a/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp b/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp index 03ffbff20db7deeab352c3d7fdb0453e7c1a16b7..6911e11cd497346e71313096e58dbbd3829fff52 100644 --- a/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp +++ b/src/libs/qmljsdebugger/editor/subcomponenteditortool.cpp @@ -1,5 +1,5 @@ #include "subcomponenteditortool.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativedesignview_p.h" #include "subcomponentmasklayeritem.h" #include "layeritem.h" @@ -21,7 +21,7 @@ SubcomponentEditorTool::SubcomponentEditorTool(QDeclarativeDesignView *view) m_animIncrement(0.05f), m_animTimer(new QTimer(this)) { - m_mask = new SubcomponentMaskLayerItem(view, view->manipulatorLayer()); + m_mask = new SubcomponentMaskLayerItem(view, QDeclarativeDesignViewPrivate::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) { - view()->clearHighlight(); + QDeclarativeDesignViewPrivate::get(view())->clearHighlight(); } } @@ -172,7 +172,7 @@ void SubcomponentEditorTool::setCurrentItem(QGraphicsItem* contextItem) m_animIncrement = 0.05f; m_animTimer->start(); - view()->clearHighlight(); + QDeclarativeDesignViewPrivate::get(view())->clearHighlight(); view()->setSelectedItems(QList<QGraphicsItem*>()); pushContext(gfxObject); diff --git a/src/libs/qmljsdebugger/editor/zoomtool.cpp b/src/libs/qmljsdebugger/editor/zoomtool.cpp index 35686499e05857971d9f4cbdcd394ada06ded45f..542b51e6c2aab03b3991595553bdaa05074ca55e 100644 --- a/src/libs/qmljsdebugger/editor/zoomtool.cpp +++ b/src/libs/qmljsdebugger/editor/zoomtool.cpp @@ -1,5 +1,5 @@ #include "zoomtool.h" -#include "qdeclarativedesignview.h" +#include "qdeclarativedesignview_p.h" #include <QMouseEvent> #include <QWheelEvent> @@ -14,7 +14,7 @@ namespace QmlViewer { ZoomTool::ZoomTool(QDeclarativeDesignView *view) : AbstractFormEditorTool(view), - m_rubberbandManipulator(view->manipulatorLayer(), view), + m_rubberbandManipulator(reinterpret_cast<QGraphicsObject *>(QDeclarativeDesignViewPrivate::get(view)->manipulatorLayer), view), m_smoothZoomMultiplier(0.05f), m_currentScale(1.0f) { diff --git a/src/libs/qmljsdebugger/include/qdeclarativedesignview.h b/src/libs/qmljsdebugger/include/qdeclarativedesignview.h index e6a12643fcf6ec684ecab2bde80b293ed8b3c79d..4e4a9c7c4649419d478479728cbce67d980bc228 100644 --- a/src/libs/qmljsdebugger/include/qdeclarativedesignview.h +++ b/src/libs/qmljsdebugger/include/qdeclarativedesignview.h @@ -48,10 +48,6 @@ class QMLJSDEBUGGER_EXPORT QDeclarativeDesignView : public QDeclarativeView { Q_OBJECT public: - enum ContextFlags { - IgnoreContext, - ContextSensitive - }; explicit QDeclarativeDesignView(QWidget *parent = 0); ~QDeclarativeDesignView(); @@ -59,33 +55,13 @@ public: void setSelectedItems(QList<QGraphicsItem *> items); QList<QGraphicsItem *> selectedItems(); - QGraphicsObject *manipulatorLayer() const; - void changeTool(Constants::DesignTool tool, - Constants::ToolFlags flags = Constants::NoToolFlags); - - void clearHighlight(); - void highlight(QList<QGraphicsItem *> item, ContextFlags flags = ContextSensitive); - void highlight(QGraphicsItem *item, ContextFlags flags = ContextSensitive); - - bool mouseInsideContextItem() const; - bool isEditorItem(QGraphicsItem *item) const; - - QList<QGraphicsItem*> selectableItems(const QPoint &pos) const; - QList<QGraphicsItem*> selectableItems(const QPointF &scenePos) const; - QList<QGraphicsItem*> selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; - QGraphicsItem *currentRootItem() const; - QToolBar *toolbar() const; static QString idStringForObject(QObject *obj); QRectF adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace); public Q_SLOTS: void setDesignModeBehavior(bool value); - bool designModeBehavior() const; - void changeToSingleSelectTool(); - void changeToMarqueeSelectTool(); - void changeToZoomTool(); - void changeToColorPickerTool(); + bool designModeBehavior(); void changeAnimationSpeed(qreal slowdownFactor); void continueExecution(qreal slowdownFactor = 1.0f); @@ -119,25 +95,21 @@ protected: void mouseDoubleClickEvent(QMouseEvent *event); void wheelEvent(QWheelEvent *event); -private Q_SLOTS: - void reloadView(); - void onStatusChanged(QDeclarativeView::Status status); - void onCurrentObjectsChanged(QList<QObject*> objects); - void applyChangesFromClient(); - void createQmlObject(const QString &qml, QObject *parent, - const QStringList &imports, const QString &filename = QString()); - -private: - void clearEditorItems(); - void createToolbar(); - void changeToSelectTool(); - QList<QGraphicsItem*> filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const; - QList<QGraphicsItem*> filterForSelection(QList<QGraphicsItem*> &itemlist) const; - - QDeclarativeDesignViewPrivate *data; - 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<QObject*>)) + 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_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()) + + inline QDeclarativeDesignViewPrivate *d_func() { return data.data(); } + QScopedPointer<QDeclarativeDesignViewPrivate> data; + friend class QDeclarativeDesignViewPrivate; }; diff --git a/src/libs/qmljsdebugger/qdeclarativedesignview.cpp b/src/libs/qmljsdebugger/qdeclarativedesignview.cpp index efba89596bf0f3b70e382f9ce9d44849db46271e..9284ca396d3b896fbb478af8ef498d37c0615441 100644 --- a/src/libs/qmljsdebugger/qdeclarativedesignview.cpp +++ b/src/libs/qmljsdebugger/qdeclarativedesignview.cpp @@ -1,3 +1,32 @@ +/************************************************************************** +** +** 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" @@ -25,7 +54,8 @@ namespace QmlViewer { Q_GLOBAL_STATIC(QDeclarativeDesignDebugServer, qmlDesignDebugServer) -QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate() : +QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate(QDeclarativeDesignView *q) : + q(q), designModeBehavior(false), executionPaused(false), slowdownFactor(1.0f), @@ -39,10 +69,8 @@ QDeclarativeDesignViewPrivate::~QDeclarativeDesignViewPrivate() } QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) : - QDeclarativeView(parent) + QDeclarativeView(parent), data(new QDeclarativeDesignViewPrivate(this)) { - data = new QDeclarativeDesignViewPrivate; - data->manipulatorLayer = new LayerItem(scene()); data->selectionTool = new SelectionTool(this); data->zoomTool = new ZoomTool(this); @@ -54,20 +82,20 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) : setMouseTracking(true); connect(qmlDesignDebugServer(), SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool))); - connect(qmlDesignDebugServer(), SIGNAL(reloadRequested()), SLOT(reloadView())); + connect(qmlDesignDebugServer(), SIGNAL(reloadRequested()), SLOT(_q_reloadView())); connect(qmlDesignDebugServer(), SIGNAL(currentObjectsChanged(QList<QObject*>)), - SLOT(onCurrentObjectsChanged(QList<QObject*>))); + SLOT(_q_onCurrentObjectsChanged(QList<QObject*>))); connect(qmlDesignDebugServer(), SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal))); - connect(qmlDesignDebugServer(), SIGNAL(colorPickerToolRequested()), SLOT(changeToColorPickerTool())); - connect(qmlDesignDebugServer(), SIGNAL(selectMarqueeToolRequested()), SLOT(changeToMarqueeSelectTool())); - connect(qmlDesignDebugServer(), SIGNAL(selectToolRequested()), SLOT(changeToSingleSelectTool())); - connect(qmlDesignDebugServer(), SIGNAL(zoomToolRequested()), SLOT(changeToZoomTool())); + connect(qmlDesignDebugServer(), SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool())); + connect(qmlDesignDebugServer(), SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool())); + connect(qmlDesignDebugServer(), SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool())); + connect(qmlDesignDebugServer(), SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool())); connect(qmlDesignDebugServer(), SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)), - SLOT(createQmlObject(QString,QObject*,QStringList,QString))); + SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString))); - connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(onStatusChanged(QDeclarativeView::Status))); + 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)), @@ -77,7 +105,7 @@ QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) : connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString))); connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped())); - createToolbar(); + data->createToolbar(); } QDeclarativeDesignView::~QDeclarativeDesignView() @@ -89,14 +117,14 @@ void QDeclarativeDesignView::setInspectorContext(int contextIndex) data->subcomponentEditorTool->setContext(contextIndex); } -void QDeclarativeDesignView::reloadView() +void QDeclarativeDesignViewPrivate::_q_reloadView() { - data->subcomponentEditorTool->clear(); + subcomponentEditorTool->clear(); clearHighlight(); - emit reloadRequested(); + emit q->reloadRequested(); } -void QDeclarativeDesignView::clearEditorItems() +void QDeclarativeDesignViewPrivate::clearEditorItems() { clearHighlight(); setSelectedItems(QList<QGraphicsItem*>()); @@ -104,16 +132,16 @@ void QDeclarativeDesignView::clearEditorItems() void QDeclarativeDesignView::leaveEvent(QEvent *event) { - if (!designModeBehavior()) { + if (!data->designModeBehavior) { QDeclarativeView::leaveEvent(event); return; } - clearHighlight(); + data->clearHighlight(); } void QDeclarativeDesignView::mousePressEvent(QMouseEvent *event) { - if (!designModeBehavior()) { + if (!data->designModeBehavior) { QDeclarativeView::mousePressEvent(event); return; } @@ -123,14 +151,14 @@ void QDeclarativeDesignView::mousePressEvent(QMouseEvent *event) void QDeclarativeDesignView::mouseMoveEvent(QMouseEvent *event) { - if (!designModeBehavior()) { - clearEditorItems(); + if (!data->designModeBehavior) { + data->clearEditorItems(); QDeclarativeView::mouseMoveEvent(event); return; } data->cursorPos = event->pos(); - QList<QGraphicsItem*> selItems = selectableItems(event->pos()); + QList<QGraphicsItem*> selItems = data->selectableItems(event->pos()); if (!selItems.isEmpty()) { setToolTip(AbstractFormEditorTool::titleForItem(selItems.first())); } else { @@ -147,7 +175,7 @@ void QDeclarativeDesignView::mouseMoveEvent(QMouseEvent *event) void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event) { - if (!designModeBehavior()) { + if (!data->designModeBehavior) { QDeclarativeView::mouseReleaseEvent(event); return; } @@ -161,7 +189,7 @@ void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event) void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event) { - if (!designModeBehavior()) { + if (!data->designModeBehavior) { QDeclarativeView::keyPressEvent(event); return; } @@ -170,28 +198,28 @@ void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event) void QDeclarativeDesignView::keyReleaseEvent(QKeyEvent *event) { - if (!designModeBehavior()) { + if (!data->designModeBehavior) { QDeclarativeView::keyReleaseEvent(event); return; } switch(event->key()) { case Qt::Key_V: - changeToSingleSelectTool(); + data->_q_changeToSingleSelectTool(); break; case Qt::Key_M: - changeToMarqueeSelectTool(); + data->_q_changeToMarqueeSelectTool(); break; case Qt::Key_I: - changeToColorPickerTool(); + data->_q_changeToColorPickerTool(); break; case Qt::Key_Z: - changeToZoomTool(); + data->_q_changeToZoomTool(); break; case Qt::Key_Enter: case Qt::Key_Return: - if (!selectedItems().isEmpty()) - data->subcomponentEditorTool->setCurrentItem(selectedItems().first()); + if (!data->selectedItems().isEmpty()) + data->subcomponentEditorTool->setCurrentItem(data->selectedItems().first()); break; case Qt::Key_Space: if (data->executionPaused) { @@ -207,7 +235,7 @@ void QDeclarativeDesignView::keyReleaseEvent(QKeyEvent *event) data->currentTool->keyReleaseEvent(event); } -void QDeclarativeDesignView::createQmlObject(const QString &qml, QObject *parent, const QStringList &importList, const QString &filename) +void QDeclarativeDesignViewPrivate::_q_createQmlObject(const QString &qml, QObject *parent, const QStringList &importList, const QString &filename) { if (!parent) return; @@ -217,8 +245,8 @@ void QDeclarativeDesignView::createQmlObject(const QString &qml, QObject *parent imports += s + "\n"; } - QDeclarativeContext *parentContext = engine()->contextForObject(parent); - QDeclarativeComponent component(engine(), this); + QDeclarativeContext *parentContext = q->engine()->contextForObject(parent); + QDeclarativeComponent component(q->engine(), q); QByteArray constructedQml = QString(imports + qml).toLatin1(); component.setData(constructedQml, filename); @@ -233,24 +261,24 @@ void QDeclarativeDesignView::createQmlObject(const QString &qml, QObject *parent } } -QGraphicsItem *QDeclarativeDesignView::currentRootItem() const +QGraphicsItem *QDeclarativeDesignViewPrivate::currentRootItem() const { - return data->subcomponentEditorTool->currentRootItem(); + return subcomponentEditorTool->currentRootItem(); } void QDeclarativeDesignView::mouseDoubleClickEvent(QMouseEvent *event) { - if (!designModeBehavior()) { + if (!data->designModeBehavior) { QDeclarativeView::mouseDoubleClickEvent(event); return; } QGraphicsItem *itemToEnter = 0; QList<QGraphicsItem*> itemList = items(event->pos()); - filterForSelection(itemList); + data->filterForSelection(itemList); - if (selectedItems().isEmpty() && !itemList.isEmpty()) { + if (data->selectedItems().isEmpty() && !itemList.isEmpty()) { itemToEnter = itemList.first(); - } else if (!selectedItems().isEmpty() && !itemList.isEmpty()) { + } else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) { itemToEnter = itemList.first(); } @@ -286,54 +314,57 @@ void QDeclarativeDesignView::setDesignModeBehavior(bool value) data->designModeBehavior = value; if (data->subcomponentEditorTool) { data->subcomponentEditorTool->clear(); - clearHighlight(); - setSelectedItems(QList<QGraphicsItem*>()); + data->clearHighlight(); + data->setSelectedItems(QList<QGraphicsItem*>()); if (rootObject()) data->subcomponentEditorTool->pushContext(rootObject()); } if (!data->designModeBehavior) - clearEditorItems(); + data->clearEditorItems(); } -bool QDeclarativeDesignView::designModeBehavior() const +bool QDeclarativeDesignView::designModeBehavior() { return data->designModeBehavior; } -void QDeclarativeDesignView::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/) + + + +void QDeclarativeDesignViewPrivate::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/) { switch(tool) { case Constants::SelectionToolMode: - changeToSingleSelectTool(); + _q_changeToSingleSelectTool(); break; case Constants::NoTool: default: - data->currentTool = 0; + currentTool = 0; break; } } -void QDeclarativeDesignView::setSelectedItems(QList<QGraphicsItem *> items) +void QDeclarativeDesignViewPrivate::setSelectedItems(QList<QGraphicsItem *> items) { - data->currentSelection.clear(); + currentSelection.clear(); foreach(QGraphicsItem *item, items) { if (item) { QGraphicsObject *obj = item->toGraphicsObject(); if (obj) - data->currentSelection << obj; + currentSelection << obj; } } - data->currentTool->updateSelectedItems(); + currentTool->updateSelectedItems(); } -QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems() +QList<QGraphicsItem *> QDeclarativeDesignViewPrivate::selectedItems() { QList<QGraphicsItem *> selection; - foreach(const QWeakPointer<QGraphicsObject> &selectedObject, data->currentSelection) { + foreach(const QWeakPointer<QGraphicsObject> &selectedObject, currentSelection) { if (selectedObject.isNull()) { - data->currentSelection.removeOne(selectedObject); + currentSelection.removeOne(selectedObject); } else { selection << selectedObject.data(); } @@ -342,17 +373,28 @@ QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems() return selection; } -void QDeclarativeDesignView::clearHighlight() +void QDeclarativeDesignView::setSelectedItems(QList<QGraphicsItem *> items) +{ + data->setSelectedItems(items); +} + +QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems() +{ + return data->selectedItems(); +} + + +void QDeclarativeDesignViewPrivate::clearHighlight() { - data->boundingRectHighlighter->clear(); + boundingRectHighlighter->clear(); } -void QDeclarativeDesignView::highlight(QGraphicsItem * item, ContextFlags flags) +void QDeclarativeDesignViewPrivate::highlight(QGraphicsItem * item, ContextFlags flags) { highlight(QList<QGraphicsItem*>() << item, flags); } -void QDeclarativeDesignView::highlight(QList<QGraphicsItem *> items, ContextFlags flags) +void QDeclarativeDesignViewPrivate::highlight(QList<QGraphicsItem *> items, ContextFlags flags) { if (items.isEmpty()) return; @@ -361,7 +403,7 @@ void QDeclarativeDesignView::highlight(QList<QGraphicsItem *> items, ContextFlag foreach(QGraphicsItem *item, items) { QGraphicsItem *child = item; if (flags & ContextSensitive) - child = data->subcomponentEditorTool->firstChildOfContext(item); + child = subcomponentEditorTool->firstChildOfContext(item); if (child) { QGraphicsObject *childObject = child->toGraphicsObject(); @@ -370,87 +412,87 @@ void QDeclarativeDesignView::highlight(QList<QGraphicsItem *> items, ContextFlag } } - data->boundingRectHighlighter->highlight(objectList); + boundingRectHighlighter->highlight(objectList); } -bool QDeclarativeDesignView::mouseInsideContextItem() const +bool QDeclarativeDesignViewPrivate::mouseInsideContextItem() const { - return data->subcomponentEditorTool->containsCursor(data->cursorPos.toPoint()); + return subcomponentEditorTool->containsCursor(cursorPos.toPoint()); } -QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QPointF &scenePos) const +QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::selectableItems(const QPointF &scenePos) const { - QList<QGraphicsItem*> itemlist = scene()->items(scenePos); + QList<QGraphicsItem*> itemlist = q->scene()->items(scenePos); return filterForCurrentContext(itemlist); } -QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QPoint &pos) const +QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::selectableItems(const QPoint &pos) const { - QList<QGraphicsItem*> itemlist = items(pos); + QList<QGraphicsItem*> itemlist = q->items(pos); return filterForCurrentContext(itemlist); } -QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const +QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const { - QList<QGraphicsItem*> itemlist = scene()->items(sceneRect, selectionMode); + QList<QGraphicsItem*> itemlist = q->scene()->items(sceneRect, selectionMode); return filterForCurrentContext(itemlist); } -void QDeclarativeDesignView::changeToSingleSelectTool() +void QDeclarativeDesignViewPrivate::_q_changeToSingleSelectTool() { - data->currentToolMode = Constants::SelectionToolMode; - data->selectionTool->setRubberbandSelectionMode(false); + currentToolMode = Constants::SelectionToolMode; + selectionTool->setRubberbandSelectionMode(false); changeToSelectTool(); - emit selectToolActivated(); + emit q->selectToolActivated(); qmlDesignDebugServer()->setCurrentTool(Constants::SelectionToolMode); } -void QDeclarativeDesignView::changeToSelectTool() +void QDeclarativeDesignViewPrivate::changeToSelectTool() { - if (data->currentTool == data->selectionTool) + if (currentTool == selectionTool) return; - data->currentTool->clear(); - data->currentTool = data->selectionTool; - data->currentTool->clear(); - data->currentTool->updateSelectedItems(); + currentTool->clear(); + currentTool = selectionTool; + currentTool->clear(); + currentTool->updateSelectedItems(); } -void QDeclarativeDesignView::changeToMarqueeSelectTool() +void QDeclarativeDesignViewPrivate::_q_changeToMarqueeSelectTool() { changeToSelectTool(); - data->currentToolMode = Constants::MarqueeSelectionToolMode; - data->selectionTool->setRubberbandSelectionMode(true); + currentToolMode = Constants::MarqueeSelectionToolMode; + selectionTool->setRubberbandSelectionMode(true); - emit marqueeSelectToolActivated(); + emit q->marqueeSelectToolActivated(); qmlDesignDebugServer()->setCurrentTool(Constants::MarqueeSelectionToolMode); } -void QDeclarativeDesignView::changeToZoomTool() +void QDeclarativeDesignViewPrivate::_q_changeToZoomTool() { - data->currentToolMode = Constants::ZoomMode; - data->currentTool->clear(); - data->currentTool = data->zoomTool; - data->currentTool->clear(); + currentToolMode = Constants::ZoomMode; + currentTool->clear(); + currentTool = zoomTool; + currentTool->clear(); - emit zoomToolActivated(); + emit q->zoomToolActivated(); qmlDesignDebugServer()->setCurrentTool(Constants::ZoomMode); } -void QDeclarativeDesignView::changeToColorPickerTool() +void QDeclarativeDesignViewPrivate::_q_changeToColorPickerTool() { - if (data->currentTool == data->colorPickerTool) + if (currentTool == colorPickerTool) return; - data->currentToolMode = Constants::ColorPickerMode; - data->currentTool->clear(); - data->currentTool = data->colorPickerTool; - data->currentTool->clear(); + currentToolMode = Constants::ColorPickerMode; + currentTool->clear(); + currentTool = colorPickerTool; + currentTool->clear(); - emit colorPickerActivated(); + emit q->colorPickerActivated(); qmlDesignDebugServer()->setCurrentTool(Constants::ColorPickerMode); } @@ -493,34 +535,30 @@ void QDeclarativeDesignView::pauseExecution() qmlDesignDebugServer()->setAnimationSpeed(0); } -void QDeclarativeDesignView::applyChangesFromClient() +void QDeclarativeDesignViewPrivate::_q_applyChangesFromClient() { } -QGraphicsObject *QDeclarativeDesignView::manipulatorLayer() const -{ - return data->manipulatorLayer; -} -QList<QGraphicsItem*> QDeclarativeDesignView::filterForSelection(QList<QGraphicsItem*> &itemlist) const +QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::filterForSelection(QList<QGraphicsItem*> &itemlist) const { foreach(QGraphicsItem *item, itemlist) { - if (isEditorItem(item) || !data->subcomponentEditorTool->isChildOfContext(item)) + if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item)) itemlist.removeOne(item); } return itemlist; } -QList<QGraphicsItem*> QDeclarativeDesignView::filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const +QList<QGraphicsItem*> QDeclarativeDesignViewPrivate::filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const { foreach(QGraphicsItem *item, itemlist) { - if (isEditorItem(item) || !data->subcomponentEditorTool->isDirectChildOfContext(item)) { + 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 = data->subcomponentEditorTool->firstChildOfContext(item)) { + if (QGraphicsItem *contextParent = subcomponentEditorTool->firstChildOfContext(item)) { if (contextParent != item) { if (itemlist.contains(contextParent)) { itemlist.removeOne(item); @@ -537,25 +575,25 @@ QList<QGraphicsItem*> QDeclarativeDesignView::filterForCurrentContext(QList<QGra return itemlist; } -bool QDeclarativeDesignView::isEditorItem(QGraphicsItem *item) const +bool QDeclarativeDesignViewPrivate::isEditorItem(QGraphicsItem *item) const { return (item->type() == Constants::EditorItemType || item->type() == Constants::ResizeHandleItemType || item->data(Constants::EditorItemDataKey).toBool()); } -void QDeclarativeDesignView::onStatusChanged(QDeclarativeView::Status status) +void QDeclarativeDesignViewPrivate::_q_onStatusChanged(QDeclarativeView::Status status) { if (status == QDeclarativeView::Ready) { - if (rootObject()) { - data->subcomponentEditorTool->pushContext(rootObject()); - emit executionStarted(1.0f); + if (q->rootObject()) { + subcomponentEditorTool->pushContext(q->rootObject()); + emit q->executionStarted(1.0f); } qmlDesignDebugServer()->reloaded(); } } -void QDeclarativeDesignView::onCurrentObjectsChanged(QList<QObject*> objects) +void QDeclarativeDesignViewPrivate::_q_onCurrentObjectsChanged(QList<QObject*> objects) { QList<QGraphicsItem*> items; foreach(QObject *obj, objects) { @@ -566,7 +604,7 @@ void QDeclarativeDesignView::onCurrentObjectsChanged(QList<QObject*> objects) setSelectedItems(items); clearHighlight(); - highlight(items, IgnoreContext); + highlight(items, QDeclarativeDesignViewPrivate::IgnoreContext); } QString QDeclarativeDesignView::idStringForObject(QObject *obj) @@ -603,36 +641,38 @@ QToolBar *QDeclarativeDesignView::toolbar() const return data->toolbar; } -void QDeclarativeDesignView::createToolbar() +void QDeclarativeDesignViewPrivate::createToolbar() { - data->toolbar = new QmlToolbar(this); - connect(this, SIGNAL(selectedColorChanged(QColor)), data->toolbar, SLOT(setColorBoxColor(QColor))); + toolbar = new QmlToolbar(q); + QObject::connect(q, SIGNAL(selectedColorChanged(QColor)), toolbar, SLOT(setColorBoxColor(QColor))); - connect(this, SIGNAL(designModeBehaviorChanged(bool)), data->toolbar, SLOT(setDesignModeBehavior(bool))); + QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)), toolbar, SLOT(setDesignModeBehavior(bool))); - connect(data->toolbar, SIGNAL(designModeBehaviorChanged(bool)), this, SLOT(setDesignModeBehavior(bool))); - connect(data->toolbar, SIGNAL(executionStarted()), this, SLOT(continueExecution())); - connect(data->toolbar, SIGNAL(executionPaused()), this, SLOT(pauseExecution())); - connect(data->toolbar, SIGNAL(colorPickerSelected()), this, SLOT(changeToColorPickerTool())); - connect(data->toolbar, SIGNAL(zoomToolSelected()), this, SLOT(changeToZoomTool())); - connect(data->toolbar, SIGNAL(selectToolSelected()), this, SLOT(changeToSingleSelectTool())); - connect(data->toolbar, SIGNAL(marqueeSelectToolSelected()), this, SLOT(changeToMarqueeSelectTool())); + QObject::connect(toolbar, SIGNAL(designModeBehaviorChanged(bool)), q, SLOT(setDesignModeBehavior(bool))); + QObject::connect(toolbar, SIGNAL(executionStarted()), q, SLOT(continueExecution())); + QObject::connect(toolbar, SIGNAL(executionPaused()), q, SLOT(pauseExecution())); + 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())); - connect(data->toolbar, SIGNAL(applyChangesFromQmlFileSelected()), SLOT(applyChangesFromClient())); + QObject::connect(toolbar, SIGNAL(applyChangesFromQmlFileSelected()), q, SLOT(_q_applyChangesFromClient())); - connect(this, SIGNAL(executionStarted(qreal)), data->toolbar, SLOT(startExecution())); - connect(this, SIGNAL(executionPaused()), data->toolbar, SLOT(pauseExecution())); + QObject::connect(q, SIGNAL(executionStarted(qreal)), toolbar, SLOT(startExecution())); + QObject::connect(q, SIGNAL(executionPaused()), toolbar, SLOT(pauseExecution())); - connect(this, SIGNAL(selectToolActivated()), data->toolbar, SLOT(activateSelectTool())); + QObject::connect(q, SIGNAL(selectToolActivated()), toolbar, SLOT(activateSelectTool())); // disabled features //connect(d->m_toolbar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient())); - //connect(this, SIGNAL(resizeToolActivated()), d->m_toolbar, SLOT(activateSelectTool())); - //connect(this, SIGNAL(moveToolActivated()), d->m_toolbar, SLOT(activateSelectTool())); + //connect(q, SIGNAL(resizeToolActivated()), d->m_toolbar, SLOT(activateSelectTool())); + //connect(q, SIGNAL(moveToolActivated()), d->m_toolbar, SLOT(activateSelectTool())); - connect(this, SIGNAL(colorPickerActivated()), data->toolbar, SLOT(activateColorPicker())); - connect(this, SIGNAL(zoomToolActivated()), data->toolbar, SLOT(activateZoom())); - connect(this, SIGNAL(marqueeSelectToolActivated()), data->toolbar, SLOT(activateMarqueeSelectTool())); + QObject::connect(q, SIGNAL(colorPickerActivated()), toolbar, SLOT(activateColorPicker())); + QObject::connect(q, SIGNAL(zoomToolActivated()), toolbar, SLOT(activateZoom())); + QObject::connect(q, SIGNAL(marqueeSelectToolActivated()), toolbar, SLOT(activateMarqueeSelectTool())); } } //namespace QmlViewer + +#include <moc_qdeclarativedesignview.cpp> diff --git a/src/libs/qmljsdebugger/qdeclarativedesignview_p.h b/src/libs/qmljsdebugger/qdeclarativedesignview_p.h index 2a4095fbc4f047f547c3f46b3a1932c19e34873e..39ad149093a19ad39b0dd6b267b0da759256ee53 100644 --- a/src/libs/qmljsdebugger/qdeclarativedesignview_p.h +++ b/src/libs/qmljsdebugger/qdeclarativedesignview_p.h @@ -33,6 +33,8 @@ #include <QWeakPointer> #include <QPointF> +#include "qdeclarativedesignview.h" + namespace QmlViewer { class QDeclarativeDesignView; @@ -50,9 +52,16 @@ class QDeclarativeDesignViewPrivate { public: - QDeclarativeDesignViewPrivate(); + + enum ContextFlags { + IgnoreContext, + ContextSensitive + }; + + QDeclarativeDesignViewPrivate(QDeclarativeDesignView *); ~QDeclarativeDesignViewPrivate(); + QDeclarativeDesignView *q; QPointF cursorPos; QList<QWeakPointer<QGraphicsObject> > currentSelection; @@ -74,6 +83,45 @@ public: QmlToolbar *toolbar; + void clearEditorItems(); + void createToolbar(); + void changeToSelectTool(); + QList<QGraphicsItem*> filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const; + QList<QGraphicsItem*> filterForSelection(QList<QGraphicsItem*> &itemlist) const; + + QList<QGraphicsItem*> selectableItems(const QPoint &pos) const; + QList<QGraphicsItem*> selectableItems(const QPointF &scenePos) const; + QList<QGraphicsItem*> selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const; + + void setSelectedItems(QList<QGraphicsItem *> items); + QList<QGraphicsItem *> selectedItems(); + + void changeTool(Constants::DesignTool tool, + Constants::ToolFlags flags = Constants::NoToolFlags); + + void clearHighlight(); + void highlight(QList<QGraphicsItem *> item, ContextFlags flags = ContextSensitive); + void highlight(QGraphicsItem *item, ContextFlags flags = ContextSensitive); + + bool mouseInsideContextItem() const; + bool isEditorItem(QGraphicsItem *item) const; + + QGraphicsItem *currentRootItem() const; + + + void _q_reloadView(); + void _q_onStatusChanged(QDeclarativeView::Status status); + void _q_onCurrentObjectsChanged(QList<QObject*> objects); + void _q_applyChangesFromClient(); + void _q_createQmlObject(const QString &qml, QObject *parent, + const QStringList &imports, const QString &filename = QString()); + + void _q_changeToSingleSelectTool(); + void _q_changeToMarqueeSelectTool(); + void _q_changeToZoomTool(); + void _q_changeToColorPickerTool(); + + static QDeclarativeDesignViewPrivate *get(QDeclarativeDesignView *v) { return v->d_func(); } }; } // namespace QmlViewer