Commit 1972c2f8 authored by Lasse Holmstedt's avatar Lasse Holmstedt

Refactored QmlJS Live Preview into a library

QMLObserver links against the library dynamically. User's apps can also
link to it statically, so that the app can be deployed with debugging
features to a device, without having to worry about library deployment.
parent 36b638d9
......@@ -10,5 +10,6 @@ SUBDIRS = \
utils/process_stub.pro \
cplusplus \
qmljs \
qmljsdebugger \
symbianutils \
3rdparty
......@@ -8,15 +8,13 @@ HEADERS += \
$$PWD/rubberbandselectionmanipulator.h \
$$PWD/selectionrectangle.h \
$$PWD/selectionindicator.h \
$$PWD/qmlviewerconstants.h \
$$PWD/boundingrecthighlighter.h \
$$PWD/subcomponenteditortool.h \
$$PWD/subcomponentmasklayeritem.h \
$$PWD/zoomtool.h \
$$PWD/colorpickertool.h \
$$PWD/qmltoolbar.h \
$$PWD/toolbarcolorbox.h \
$$PWD/crumblepath.h
$$PWD/toolbarcolorbox.h
SOURCES += \
$$PWD/abstractformeditortool.cpp \
......
......@@ -34,7 +34,7 @@
namespace QmlViewer {
RubberBandSelectionManipulator::RubberBandSelectionManipulator(LayerItem *layerItem, QDeclarativeDesignView *editorView)
RubberBandSelectionManipulator::RubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeDesignView *editorView)
: m_selectionRectangleElement(layerItem),
m_editorView(editorView),
m_beginFormEditorItem(0),
......
......@@ -47,7 +47,7 @@ public:
};
RubberBandSelectionManipulator(LayerItem *layerItem, QDeclarativeDesignView *editorView);
RubberBandSelectionManipulator(QGraphicsObject *layerItem, QDeclarativeDesignView *editorView);
void setItems(const QList<QGraphicsItem*> &itemList);
......
......@@ -37,7 +37,7 @@
namespace QmlViewer {
SelectionIndicator::SelectionIndicator(QDeclarativeDesignView *editorView, LayerItem *layerItem)
SelectionIndicator::SelectionIndicator(QDeclarativeDesignView *editorView, QGraphicsObject *layerItem)
: m_layerItem(layerItem), m_view(editorView)
{
}
......
......@@ -32,7 +32,7 @@
#include <QWeakPointer>
#include <QGraphicsPolygonItem>
#include "layeritem.h"
#include <QGraphicsObject>
namespace QmlViewer {
......@@ -41,7 +41,7 @@ class QDeclarativeDesignView;
class SelectionIndicator
{
public:
SelectionIndicator(QDeclarativeDesignView* editorView, LayerItem *layerItem);
SelectionIndicator(QDeclarativeDesignView* editorView, QGraphicsObject *layerItem);
~SelectionIndicator();
void show();
......@@ -57,7 +57,7 @@ private:
private:
QHash<QGraphicsItem*, QGraphicsPolygonItem *> m_indicatorShapeHash;
QWeakPointer<LayerItem> m_layerItem;
QWeakPointer<QGraphicsObject> m_layerItem;
QDeclarativeDesignView *m_view;
};
......
......@@ -45,7 +45,7 @@ public:
int type() const { return Constants::EditorItemType; }
};
SelectionRectangle::SelectionRectangle(LayerItem *layerItem)
SelectionRectangle::SelectionRectangle(QGraphicsObject *layerItem)
: m_controlShape(new SelectionRectShape(layerItem)),
m_layerItem(layerItem)
{
......
......@@ -32,14 +32,14 @@
#include <QWeakPointer>
#include <QGraphicsRectItem>
#include "layeritem.h"
#include <QGraphicsObject>
namespace QmlViewer {
class SelectionRectangle
{
public:
SelectionRectangle(LayerItem *layerItem);
SelectionRectangle(QGraphicsObject *layerItem);
~SelectionRectangle();
void show();
......@@ -54,7 +54,7 @@ public:
private:
QGraphicsRectItem *m_controlShape;
QWeakPointer<LayerItem> m_layerItem;
QWeakPointer<QGraphicsObject> m_layerItem;
};
}
......
......@@ -32,6 +32,7 @@
#include <QWidget>
#include <QList>
#include "qmljsdebugger_global.h"
QT_FORWARD_DECLARE_CLASS(QResizeEvent);
......@@ -39,7 +40,7 @@ namespace QmlViewer {
class CrumblePathButton;
class CrumblePath : public QWidget
class QMLJSDEBUGGER_EXPORT CrumblePath : public QWidget
{
Q_OBJECT
public:
......
......@@ -60,13 +60,14 @@
#include <private/qdeclarativedebugservice_p.h>
#include <QtCore/QStringList>
#include "qmljsdebugger_global.h"
QT_BEGIN_NAMESPACE
class JSAgentWatchData;
class QScriptContext;
class JSDebuggerAgent : public QDeclarativeDebugService , public QScriptEngineAgent
class QMLJSDEBUGGER_EXPORT JSDebuggerAgent : public QDeclarativeDebugService , public QScriptEngineAgent
{ Q_OBJECT
public:
JSDebuggerAgent(QScriptEngine *engine);
......
......@@ -44,6 +44,7 @@
#include <private/qdeclarativedebugservice_p.h>
#include "qmlviewerconstants.h"
#include "qmljsdebugger_global.h"
#include <QHash>
......@@ -55,7 +56,7 @@ class QDeclarativeContext;
class QDeclarativeWatcher;
class QDataStream;
class QDeclarativeDesignDebugServer : public QDeclarativeDebugService
class QMLJSDEBUGGER_EXPORT QDeclarativeDesignDebugServer : public QDeclarativeDebugService
{
Q_OBJECT
public:
......
/**************************************************************************
**
** 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 <qdeclarativeview.h>
#include <QWeakPointer>
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:
enum ContextFlags {
IgnoreContext,
ContextSensitive
};
explicit QDeclarativeDesignView(QWidget *parent = 0);
~QDeclarativeDesignView();
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;
CrumblePath *crumblePathWidget() 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();
void changeAnimationSpeed(qreal slowdownFactor);
void continueExecution(qreal slowdownFactor = 1.0f);
void pauseExecution();
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();
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);
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)
};
} //namespace QmlViewer
#endif // QDECLARATIVEDESIGNVIEW_H
/**************************************************************************
**
** 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 QMLJSDEBUGGER_GLOBAL_H
#define QMLJSDEBUGGER_GLOBAL_H
#include <QtCore/qglobal.h>
# if defined(BUILD_QMLJSDEBUGGER_LIB)
# define QMLJSDEBUGGER_EXPORT Q_DECL_EXPORT
# elif defined(BUILD_QMLJSDEBUGGER_STATIC_LIB)
# define QMLJSDEBUGGER_EXPORT
# else
# define QMLJSDEBUGGER_EXPORT Q_DECL_IMPORT
#endif
#endif // QMLJSDEBUGGER_GLOBAL_H
/**************************************************************************
**
** 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 <QWeakPointer>
#include <QPointF>
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:
QDeclarativeDesignViewPrivate();
~QDeclarativeDesignViewPrivate();
QPointF cursorPos;
QList<QWeakPointer<QGraphicsObject> > currentSelection;
Constants::DesignTool currentToolMode;
AbstractFormEditorTool *currentTool;
SelectionTool *selectionTool;
ZoomTool *zoomTool;
ColorPickerTool *colorPickerTool;
SubcomponentEditorTool *subcomponentEditorTool;
LayerItem *manipulatorLayer;
BoundingRectHighlighter *boundingRectHighlighter;
bool designModeBehavior;
bool executionPaused;
qreal slowdownFactor;
QmlToolbar *toolbar;
CrumblePath *crumblePath;
};
} // namespace QmlViewer
#endif // QDECLARATIVEDESIGNVIEW_P_H
QT += declarative
INCLUDEPATH += $$PWD $$PWD/include editor
DEPENDPATH += $$PWD $$PWD/include editor
contains(CONFIG, dll) {
DEFINES += BUILD_QMLJSDEBUGGER_LIB
} else {
DEFINES += BUILD_QMLJSDEBUGGER_STATIC_LIB
}
## Once is not enough
include($$PWD/../../private_headers.pri)
include($$PWD/../../private_headers.pri)
include($$PWD/editor/editor.pri)
## Input
HEADERS += \
include/jsdebuggeragent.h \
include/qdeclarativedesignview.h \
include/qdeclarativedesigndebugserver.h \
include/crumblepath.h \
include/qmlviewerconstants.h \