Commit 63cae298 authored by Kai Koehne's avatar Kai Koehne

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.
parent 0fa0d00f
......@@ -28,8 +28,8 @@
**************************************************************************/
#include "abstractformeditortool.h"
#include "qdeclarativedesignview.h"
#include "qdeclarativedesignview_p.h"
#include "qdeclarativeviewobserver.h"
#include "qdeclarativeviewobserver_p.h"
#include <QDeclarativeEngine>
......@@ -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<QGraphicsItem*> 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<QGraphicsItem*> & itemList)
......@@ -92,7 +97,7 @@ bool AbstractFormEditorTool::topItemIsMovable(const QList<QGraphicsItem*> & item
bool AbstractFormEditorTool::topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList)
{
QList<QGraphicsItem*> selectedItems = view()->selectedItems();
QList<QGraphicsItem*> selectedItems = observer()->selectedItems();
foreach (QGraphicsItem *item, itemList) {
QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
......@@ -178,7 +183,7 @@ QString AbstractFormEditorTool::titleForItem(QGraphicsItem *item)
QDeclarativeItem *declarativeItem = qobject_cast<QDeclarativeItem*>(gfxObject);
if (declarativeItem) {
objectStringId = QDeclarativeDesignView::idStringForObject(declarativeItem);
objectStringId = QDeclarativeViewObserver::idStringForObject(declarativeItem);
}
if (!objectStringId.isEmpty()) {
......
......@@ -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<QGraphicsItem*> &objectList) = 0;
QDeclarativeDesignView *view() const;
QDeclarativeViewObserver *observer() const;
QDeclarativeView *view() const;
QGraphicsScene* scene() const;
private:
QDeclarativeDesignView *m_view;
QDeclarativeViewObserver *m_observer;
QList<QGraphicsItem*> m_itemList;
};
......
#include "boundingrecthighlighter.h"
#include "qdeclarativedesignview.h"
#include "qdeclarativeviewobserver.h"
#include "qmlviewerconstants.h"
#include <QGraphicsPolygonItem>
......@@ -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)
{
......
......@@ -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<QGraphicsObject*> items);
......@@ -42,7 +42,7 @@ private:
private:
Q_DISABLE_COPY(BoundingRectHighlighter);
QDeclarativeDesignView *m_view;
QDeclarativeViewObserver *m_view;
QList<BoundingBox* > m_boxes;
QList<BoundingBox* > m_freeBoxes;
QTimer *m_animTimer;
......
#include "colorpickertool.h"
#include "qdeclarativedesignview.h"
#include "qdeclarativeviewobserver.h"
#include <QMouseEvent>
#include <QKeyEvent>
......@@ -11,7 +11,7 @@
namespace QmlViewer {
ColorPickerTool::ColorPickerTool(QDeclarativeDesignView *view) :
ColorPickerTool::ColorPickerTool(QDeclarativeViewObserver *view) :
AbstractFormEditorTool(view)
{
m_selectedColor.setRgb(0,0,0);
......
......@@ -13,7 +13,7 @@ class ColorPickerTool : public AbstractFormEditorTool
{
Q_OBJECT
public:
explicit ColorPickerTool(QDeclarativeDesignView *view);
explicit ColorPickerTool(QDeclarativeViewObserver *view);
virtual ~ColorPickerTool();
......
......@@ -28,13 +28,13 @@
**************************************************************************/
#include "rubberbandselectionmanipulator.h"
#include "qdeclarativedesignview_p.h"
#include "qdeclarativeviewobserver_p.h"
#include <QDebug>
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<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(m_selectionRectangleElement.rect(),
QList<QGraphicsItem*> itemList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectableItems(m_selectionRectangleElement.rect(),
Qt::IntersectsItemShape);
QList<QGraphicsItem*> newSelectionList;
......
......@@ -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<QGraphicsItem*> &itemList);
......@@ -72,7 +72,7 @@ private:
QList<QGraphicsItem*> m_oldSelectionList;
SelectionRectangle m_selectionRectangleElement;
QPointF m_beginPoint;
QDeclarativeDesignView *m_editorView;
QDeclarativeViewObserver *m_editorView;
QGraphicsItem *m_beginFormEditorItem;
bool m_isActive;
};
......
......@@ -28,7 +28,7 @@
**************************************************************************/
#include "selectionindicator.h"
#include "qdeclarativedesignview_p.h"
#include "qdeclarativeviewobserver_p.h"
#include "qmlviewerconstants.h"
#include <QPen>
......@@ -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;
......
......@@ -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<QGraphicsItem*, QGraphicsPolygonItem *> m_indicatorShapeHash;
QWeakPointer<QGraphicsObject> m_layerItem;
QDeclarativeDesignView *m_view;
QDeclarativeViewObserver *m_view;
};
......
......@@ -31,7 +31,7 @@
#include "layeritem.h"
//#include "resizehandleitem.h"
#include "qdeclarativedesignview_p.h"
#include "qdeclarativeviewobserver_p.h"
#include <QDeclarativeEngine>
......@@ -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<QGraphicsItem*> &itemList) const
{
const QList<QGraphicsItem*> selectedItems = QDeclarativeDesignViewPrivate::get(view())->selectedItems();
const QList<QGraphicsItem*> selectedItems = QDeclarativeViewObserverPrivate::get(observer())->selectedItems();
if (selectedItems.isEmpty())
return false;
......@@ -98,7 +98,7 @@ bool SelectionTool::alreadySelected(const QList<QGraphicsItem*> &itemList) const
void SelectionTool::mousePressEvent(QMouseEvent *event)
{
QList<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos());
QList<QGraphicsItem*> 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<QGraphicsItem*> itemList, QPoint globalPos)
{
if (!QDeclarativeDesignViewPrivate::get(view())->mouseInsideContextItem())
if (!QDeclarativeViewObserverPrivate::get(observer())->mouseInsideContextItem())
return;
QMenu contextMenu;
......@@ -177,7 +177,7 @@ void SelectionTool::createContextMenu(QList<QGraphicsItem*> 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<QGraphicsItem*> selectableItemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos());
QList<QGraphicsItem*> 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<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(view())->selectableItems(event->pos());
QList<QGraphicsItem*> 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++;
......
......@@ -32,15 +32,14 @@
#include "abstractformeditortool.h"
#include "movemanipulator.h"
#include "rubberbandselectionmanipulator.h"
#include "singleselectionmanipulator.h"
#include "selectionindicator.h"
#include "resizeindicator.h"
#include <QHash>
#include <QList>
#include <QTime>
#include <QAction>
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);
......
......@@ -28,13 +28,13 @@
**************************************************************************/
#include "singleselectionmanipulator.h"
#include "qdeclarativedesignview.h"
#include "qdeclarativedesignview_p.h"
#include "qdeclarativeviewobserver.h"
#include "qdeclarativeviewobserver_p.h"
#include <QtDebug>
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<QGraphicsItem*> itemList = QDeclarativeDesignViewPrivate::get(m_editorView)->selectableItems(m_beginPoint);
QList<QGraphicsItem*> itemList = QDeclarativeViewObserverPrivate::get(m_editorView)->selectableItems(m_beginPoint);
select(selectionType, itemList, selectOnlyContentItems);
}
......
......@@ -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<QGraphicsItem*> m_oldSelectionList;
QPointF m_beginPoint;
QDeclarativeDesignView *m_editorView;
QDeclarativeViewObserver *m_editorView;
bool m_isActive;
};
......
#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<QGraphicsItem*>());
QDeclarativeViewObserverPrivate::get(observer())->clearHighlight();
observer()->setSelectedItems(QList<QGraphicsItem*>());
pushContext(gfxObject);
}
......
......@@ -18,7 +18,7 @@ class SubcomponentEditorTool : public AbstractFormEditorTool
Q_OBJECT
public:
SubcomponentEditorTool(QDeclarativeDesignView *view);
SubcomponentEditorTool(QDeclarativeViewObserver *view);
~SubcomponentEditorTool();
void mousePressEvent(QMouseEvent *event);
......
#include "subcomponentmasklayeritem.h"
#include "qmlviewerconstants.h"
#include "qdeclarativedesignview.h"
#include "qdeclarativeviewobserver.h"
#include <QPolygonF>
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);
......
......@@ -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: