2010-07-08 14:00:33 +02:00
|
|
|
#include "qdeclarativedesignview.h"
|
2010-07-29 12:15:55 +02:00
|
|
|
#include "qdeclarativedesignview_p.h"
|
2010-07-08 14:00:33 +02:00
|
|
|
#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 <QDeclarativeItem>
|
2010-07-16 09:41:56 +02:00
|
|
|
#include <QDeclarativeEngine>
|
|
|
|
#include <QDeclarativeContext>
|
|
|
|
#include <QDeclarativeExpression>
|
2010-07-08 14:00:33 +02:00
|
|
|
#include <QWidget>
|
2010-07-16 09:41:56 +02:00
|
|
|
#include <QMouseEvent>
|
2010-07-08 14:00:33 +02:00
|
|
|
#include <QGraphicsObject>
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
#include <QAbstractAnimation>
|
|
|
|
#include <private/qabstractanimation_p.h>
|
|
|
|
|
|
|
|
namespace QmlViewer {
|
|
|
|
|
|
|
|
Q_GLOBAL_STATIC(QDeclarativeDesignDebugServer, qmlDesignDebugServer)
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
QDeclarativeDesignViewPrivate::QDeclarativeDesignViewPrivate() :
|
|
|
|
designModeBehavior(false),
|
|
|
|
executionPaused(false),
|
|
|
|
slowdownFactor(1.0f),
|
|
|
|
toolbar(0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QDeclarativeDesignViewPrivate::~QDeclarativeDesignViewPrivate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
|
2010-07-29 12:15:55 +02:00
|
|
|
QDeclarativeView(parent)
|
|
|
|
{
|
|
|
|
data = new QDeclarativeDesignViewPrivate;
|
|
|
|
|
|
|
|
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;
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
setMouseTracking(true);
|
|
|
|
|
2010-07-12 12:02:35 +02:00
|
|
|
connect(qmlDesignDebugServer(), SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool)));
|
2010-07-08 14:00:33 +02:00
|
|
|
connect(qmlDesignDebugServer(), SIGNAL(reloadRequested()), SLOT(reloadView()));
|
|
|
|
connect(qmlDesignDebugServer(),
|
|
|
|
SIGNAL(currentObjectsChanged(QList<QObject*>)),
|
|
|
|
SLOT(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()));
|
2010-07-16 09:41:56 +02:00
|
|
|
connect(qmlDesignDebugServer(),
|
|
|
|
SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)),
|
|
|
|
SLOT(createQmlObject(QString,QObject*,QStringList,QString)));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
connect(this, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(onStatusChanged(QDeclarativeView::Status)));
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor)));
|
|
|
|
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)),
|
2010-07-26 12:47:55 +02:00
|
|
|
qmlDesignDebugServer(), SLOT(selectedColorChanged(QColor)));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 16:09:17 +02:00
|
|
|
connect(data->subcomponentEditorTool, SIGNAL(cleared()), SIGNAL(inspectorContextCleared()));
|
|
|
|
connect(data->subcomponentEditorTool, SIGNAL(contextPushed(QString)), SIGNAL(inspectorContextPushed(QString)));
|
|
|
|
connect(data->subcomponentEditorTool, SIGNAL(contextPopped()), SIGNAL(inspectorContextPopped()));
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
createToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDeclarativeDesignView::~QDeclarativeDesignView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-30 16:09:17 +02:00
|
|
|
void QDeclarativeDesignView::setInspectorContext(int contextIndex)
|
|
|
|
{
|
|
|
|
data->subcomponentEditorTool->setContext(contextIndex);
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
void QDeclarativeDesignView::reloadView()
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->clear();
|
2010-07-13 12:03:21 +02:00
|
|
|
clearHighlight();
|
2010-07-08 14:00:33 +02:00
|
|
|
emit reloadRequested();
|
|
|
|
}
|
|
|
|
|
2010-07-14 17:47:43 +02:00
|
|
|
void QDeclarativeDesignView::clearEditorItems()
|
|
|
|
{
|
|
|
|
clearHighlight();
|
|
|
|
setSelectedItems(QList<QGraphicsItem*>());
|
|
|
|
}
|
|
|
|
|
2010-07-09 16:33:09 +02:00
|
|
|
void QDeclarativeDesignView::leaveEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::leaveEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-13 12:03:21 +02:00
|
|
|
clearHighlight();
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
void QDeclarativeDesignView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::mousePressEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->cursorPos = event->pos();
|
|
|
|
data->currentTool->mousePressEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
2010-07-14 17:47:43 +02:00
|
|
|
clearEditorItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
QDeclarativeView::mouseMoveEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->cursorPos = event->pos();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
QList<QGraphicsItem*> selItems = selectableItems(event->pos());
|
|
|
|
if (!selItems.isEmpty()) {
|
|
|
|
setToolTip(AbstractFormEditorTool::titleForItem(selItems.first()));
|
|
|
|
} else {
|
|
|
|
setToolTip(QString());
|
|
|
|
}
|
|
|
|
if (event->buttons()) {
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->mouseMoveEvent(event);
|
|
|
|
data->currentTool->mouseMoveEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
} else {
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->hoverMoveEvent(event);
|
|
|
|
data->currentTool->hoverMoveEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::mouseReleaseEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->mouseReleaseEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->cursorPos = event->pos();
|
|
|
|
data->currentTool->mouseReleaseEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
//qmlDesignDebugServer()->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::keyPressEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->keyPressEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::keyReleaseEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(event->key()) {
|
|
|
|
case Qt::Key_V:
|
|
|
|
changeToSingleSelectTool();
|
|
|
|
break;
|
|
|
|
case Qt::Key_M:
|
|
|
|
changeToMarqueeSelectTool();
|
|
|
|
break;
|
2010-07-09 16:33:09 +02:00
|
|
|
case Qt::Key_I:
|
|
|
|
changeToColorPickerTool();
|
|
|
|
break;
|
|
|
|
case Qt::Key_Z:
|
|
|
|
changeToZoomTool();
|
|
|
|
break;
|
2010-07-08 14:00:33 +02:00
|
|
|
case Qt::Key_Enter:
|
|
|
|
case Qt::Key_Return:
|
|
|
|
if (!selectedItems().isEmpty())
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->setCurrentItem(selectedItems().first());
|
2010-07-08 14:00:33 +02:00
|
|
|
break;
|
|
|
|
case Qt::Key_Space:
|
2010-07-29 12:15:55 +02:00
|
|
|
if (data->executionPaused) {
|
|
|
|
continueExecution(data->slowdownFactor);
|
2010-07-08 14:00:33 +02:00
|
|
|
} else {
|
|
|
|
pauseExecution();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->keyReleaseEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-16 09:41:56 +02:00
|
|
|
void QDeclarativeDesignView::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 = engine()->contextForObject(parent);
|
|
|
|
QDeclarativeComponent component(engine(), this);
|
|
|
|
QByteArray constructedQml = QString(imports + qml).toLatin1();
|
|
|
|
|
|
|
|
component.setData(constructedQml, filename);
|
|
|
|
QObject *newObject = component.create(parentContext);
|
|
|
|
if (newObject) {
|
|
|
|
newObject->setParent(parent);
|
2010-07-20 12:35:36 +02:00
|
|
|
QDeclarativeItem *parentItem = qobject_cast<QDeclarativeItem*>(parent);
|
|
|
|
QDeclarativeItem *newItem = qobject_cast<QDeclarativeItem*>(newObject);
|
2010-07-16 09:41:56 +02:00
|
|
|
if (parentItem && newItem) {
|
|
|
|
newItem->setParentItem(parentItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
QGraphicsItem *QDeclarativeDesignView::currentRootItem() const
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->subcomponentEditorTool->currentRootItem();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::mouseDoubleClickEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QGraphicsItem *itemToEnter = 0;
|
2010-07-09 16:33:09 +02:00
|
|
|
QList<QGraphicsItem*> itemList = items(event->pos());
|
|
|
|
filterForSelection(itemList);
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
if (selectedItems().isEmpty() && !itemList.isEmpty()) {
|
|
|
|
itemToEnter = itemList.first();
|
|
|
|
} else if (!selectedItems().isEmpty() && !itemList.isEmpty()) {
|
|
|
|
itemToEnter = itemList.first();
|
|
|
|
}
|
|
|
|
|
2010-07-09 16:33:09 +02:00
|
|
|
if (itemToEnter)
|
2010-07-29 12:15:55 +02:00
|
|
|
itemToEnter = data->subcomponentEditorTool->firstChildOfContext(itemToEnter);
|
2010-07-09 16:33:09 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->setCurrentItem(itemToEnter);
|
|
|
|
data->subcomponentEditorTool->mouseDoubleClickEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
if ((event->buttons() & Qt::LeftButton) && itemToEnter) {
|
|
|
|
QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject();
|
|
|
|
if (objectToEnter)
|
|
|
|
qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << objectToEnter);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void QDeclarativeDesignView::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
if (!data->designModeBehavior) {
|
2010-07-08 14:00:33 +02:00
|
|
|
QDeclarativeView::wheelEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->wheelEvent(event);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::setDesignModeBehavior(bool value)
|
|
|
|
{
|
2010-07-12 12:02:35 +02:00
|
|
|
emit designModeBehaviorChanged(value);
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->toolbar->setDesignModeBehavior(value);
|
2010-07-12 12:08:27 +02:00
|
|
|
qmlDesignDebugServer()->setDesignModeBehavior(value);
|
2010-07-12 12:02:35 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->designModeBehavior = value;
|
|
|
|
if (data->subcomponentEditorTool) {
|
|
|
|
data->subcomponentEditorTool->clear();
|
2010-07-13 12:03:21 +02:00
|
|
|
clearHighlight();
|
2010-07-12 14:32:54 +02:00
|
|
|
setSelectedItems(QList<QGraphicsItem*>());
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
if (rootObject())
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->pushContext(rootObject());
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
2010-07-14 17:47:43 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
if (!data->designModeBehavior)
|
2010-07-14 17:47:43 +02:00
|
|
|
clearEditorItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QDeclarativeDesignView::designModeBehavior() const
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->designModeBehavior;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/)
|
|
|
|
{
|
|
|
|
switch(tool) {
|
|
|
|
case Constants::SelectionToolMode:
|
|
|
|
changeToSingleSelectTool();
|
|
|
|
break;
|
|
|
|
case Constants::NoTool:
|
|
|
|
default:
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool = 0;
|
2010-07-08 14:00:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::setSelectedItems(QList<QGraphicsItem *> items)
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentSelection.clear();
|
2010-07-15 13:38:10 +02:00
|
|
|
foreach(QGraphicsItem *item, items) {
|
|
|
|
if (item) {
|
|
|
|
QGraphicsObject *obj = item->toGraphicsObject();
|
|
|
|
if (obj)
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentSelection << obj;
|
2010-07-15 13:38:10 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->updateSelectedItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-15 13:38:10 +02:00
|
|
|
QList<QGraphicsItem *> QDeclarativeDesignView::selectedItems()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-15 13:38:10 +02:00
|
|
|
QList<QGraphicsItem *> selection;
|
2010-07-29 12:15:55 +02:00
|
|
|
foreach(const QWeakPointer<QGraphicsObject> &selectedObject, data->currentSelection) {
|
2010-07-15 13:38:10 +02:00
|
|
|
if (selectedObject.isNull()) {
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentSelection.removeOne(selectedObject);
|
2010-07-15 13:38:10 +02:00
|
|
|
} else {
|
|
|
|
selection << selectedObject.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selection;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 12:03:21 +02:00
|
|
|
void QDeclarativeDesignView::clearHighlight()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->boundingRectHighlighter->clear();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 16:47:22 +02:00
|
|
|
void QDeclarativeDesignView::highlight(QGraphicsItem * item, ContextFlags flags)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-13 16:47:22 +02:00
|
|
|
highlight(QList<QGraphicsItem*>() << item, flags);
|
2010-07-13 12:03:21 +02:00
|
|
|
}
|
|
|
|
|
2010-07-13 16:47:22 +02:00
|
|
|
void QDeclarativeDesignView::highlight(QList<QGraphicsItem *> items, ContextFlags flags)
|
2010-07-13 12:03:21 +02:00
|
|
|
{
|
|
|
|
if (items.isEmpty())
|
2010-07-08 14:00:33 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-13 12:03:21 +02:00
|
|
|
QList<QGraphicsObject*> objectList;
|
|
|
|
foreach(QGraphicsItem *item, items) {
|
2010-07-13 16:47:22 +02:00
|
|
|
QGraphicsItem *child = item;
|
|
|
|
if (flags & ContextSensitive)
|
2010-07-29 12:15:55 +02:00
|
|
|
child = data->subcomponentEditorTool->firstChildOfContext(item);
|
2010-07-13 16:47:22 +02:00
|
|
|
|
2010-07-13 12:03:21 +02:00
|
|
|
if (child) {
|
|
|
|
QGraphicsObject *childObject = child->toGraphicsObject();
|
|
|
|
if (childObject)
|
|
|
|
objectList << childObject;
|
|
|
|
}
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
2010-07-13 12:03:21 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->boundingRectHighlighter->highlight(objectList);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QDeclarativeDesignView::mouseInsideContextItem() const
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->subcomponentEditorTool->containsCursor(data->cursorPos.toPoint());
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QPointF &scenePos) const
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem*> itemlist = scene()->items(scenePos);
|
2010-07-09 16:33:09 +02:00
|
|
|
return filterForCurrentContext(itemlist);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QPoint &pos) const
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem*> itemlist = items(pos);
|
2010-07-09 16:33:09 +02:00
|
|
|
return filterForCurrentContext(itemlist);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<QGraphicsItem*> QDeclarativeDesignView::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem*> itemlist = scene()->items(sceneRect, selectionMode);
|
|
|
|
|
2010-07-09 16:33:09 +02:00
|
|
|
return filterForCurrentContext(itemlist);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToSingleSelectTool()
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentToolMode = Constants::SelectionToolMode;
|
|
|
|
data->selectionTool->setRubberbandSelectionMode(false);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
changeToSelectTool();
|
|
|
|
|
|
|
|
emit selectToolActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::SelectionToolMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToSelectTool()
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
if (data->currentTool == data->selectionTool)
|
2010-07-08 14:00:33 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->clear();
|
|
|
|
data->currentTool = data->selectionTool;
|
|
|
|
data->currentTool->clear();
|
|
|
|
data->currentTool->updateSelectedItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToMarqueeSelectTool()
|
|
|
|
{
|
|
|
|
changeToSelectTool();
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentToolMode = Constants::MarqueeSelectionToolMode;
|
|
|
|
data->selectionTool->setRubberbandSelectionMode(true);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
emit marqueeSelectToolActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::MarqueeSelectionToolMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToZoomTool()
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentToolMode = Constants::ZoomMode;
|
|
|
|
data->currentTool->clear();
|
|
|
|
data->currentTool = data->zoomTool;
|
|
|
|
data->currentTool->clear();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
emit zoomToolActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::ZoomMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToColorPickerTool()
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
if (data->currentTool == data->colorPickerTool)
|
2010-07-08 14:00:33 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentToolMode = Constants::ColorPickerMode;
|
|
|
|
data->currentTool->clear();
|
|
|
|
data->currentTool = data->colorPickerTool;
|
|
|
|
data->currentTool->clear();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
emit colorPickerActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::ColorPickerMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeAnimationSpeed(qreal slowdownFactor)
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->slowdownFactor = slowdownFactor;
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
if (data->slowdownFactor != 0) {
|
|
|
|
continueExecution(data->slowdownFactor);
|
2010-07-08 14:00:33 +02:00
|
|
|
} else {
|
|
|
|
pauseExecution();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::continueExecution(qreal slowdownFactor)
|
|
|
|
{
|
|
|
|
Q_ASSERT(slowdownFactor > 0);
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->slowdownFactor = slowdownFactor;
|
2010-07-12 14:32:54 +02:00
|
|
|
static const qreal animSpeedSnapDelta = 0.01f;
|
2010-07-29 12:15:55 +02:00
|
|
|
bool useStandardSpeed = (qAbs(1.0f - data->slowdownFactor) < animSpeedSnapDelta);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
2010-07-29 12:15:55 +02:00
|
|
|
timer->setSlowdownFactor(data->slowdownFactor);
|
2010-07-12 14:32:54 +02:00
|
|
|
timer->setSlowModeEnabled(!useStandardSpeed);
|
2010-07-29 12:15:55 +02:00
|
|
|
data->executionPaused = false;
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
emit executionStarted(data->slowdownFactor);
|
|
|
|
qmlDesignDebugServer()->setAnimationSpeed(data->slowdownFactor);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::pauseExecution()
|
|
|
|
{
|
|
|
|
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
2010-07-09 16:33:09 +02:00
|
|
|
timer->setSlowdownFactor(0);
|
2010-07-08 14:00:33 +02:00
|
|
|
timer->setSlowModeEnabled(true);
|
2010-07-29 12:15:55 +02:00
|
|
|
data->executionPaused = true;
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
emit executionPaused();
|
2010-07-09 16:33:09 +02:00
|
|
|
qmlDesignDebugServer()->setAnimationSpeed(0);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::applyChangesFromClient()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
QGraphicsObject *QDeclarativeDesignView::manipulatorLayer() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->manipulatorLayer;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-09 16:33:09 +02:00
|
|
|
QList<QGraphicsItem*> QDeclarativeDesignView::filterForSelection(QList<QGraphicsItem*> &itemlist) const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
foreach(QGraphicsItem *item, itemlist) {
|
2010-07-29 12:15:55 +02:00
|
|
|
if (isEditorItem(item) || !data->subcomponentEditorTool->isChildOfContext(item))
|
2010-07-08 14:00:33 +02:00
|
|
|
itemlist.removeOne(item);
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return itemlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QGraphicsItem*> QDeclarativeDesignView::filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const
|
|
|
|
{
|
|
|
|
foreach(QGraphicsItem *item, itemlist) {
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
if (isEditorItem(item) || !data->subcomponentEditorTool->isDirectChildOfContext(item)) {
|
2010-07-09 16:33:09 +02:00
|
|
|
|
|
|
|
// if we're a child, but not directly, replace with the parent that is directly in context.
|
2010-07-29 12:15:55 +02:00
|
|
|
if (QGraphicsItem *contextParent = data->subcomponentEditorTool->firstChildOfContext(item)) {
|
2010-07-14 14:21:10 +02:00
|
|
|
if (contextParent != item) {
|
|
|
|
if (itemlist.contains(contextParent)) {
|
|
|
|
itemlist.removeOne(item);
|
|
|
|
} else {
|
|
|
|
itemlist.replace(itemlist.indexOf(item), contextParent);
|
|
|
|
}
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
|
|
|
} else {
|
2010-07-14 14:21:10 +02:00
|
|
|
itemlist.removeOne(item);
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return itemlist;
|
|
|
|
}
|
|
|
|
|
2010-07-09 16:33:09 +02:00
|
|
|
bool QDeclarativeDesignView::isEditorItem(QGraphicsItem *item) const
|
|
|
|
{
|
|
|
|
return (item->type() == Constants::EditorItemType
|
|
|
|
|| item->type() == Constants::ResizeHandleItemType
|
|
|
|
|| item->data(Constants::EditorItemDataKey).toBool());
|
|
|
|
}
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
void QDeclarativeDesignView::onStatusChanged(QDeclarativeView::Status status)
|
|
|
|
{
|
|
|
|
if (status == QDeclarativeView::Ready) {
|
|
|
|
if (rootObject()) {
|
2010-07-29 12:15:55 +02:00
|
|
|
data->subcomponentEditorTool->pushContext(rootObject());
|
2010-07-08 14:00:33 +02:00
|
|
|
emit executionStarted(1.0f);
|
|
|
|
}
|
2010-07-20 12:35:36 +02:00
|
|
|
qmlDesignDebugServer()->reloaded();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::onCurrentObjectsChanged(QList<QObject*> objects)
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem*> items;
|
|
|
|
foreach(QObject *obj, objects) {
|
|
|
|
QDeclarativeItem* declarativeItem = qobject_cast<QDeclarativeItem*>(obj);
|
|
|
|
if (declarativeItem)
|
|
|
|
items << declarativeItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelectedItems(items);
|
2010-07-13 12:03:21 +02:00
|
|
|
clearHighlight();
|
2010-07-13 16:47:22 +02:00
|
|
|
highlight(items, IgnoreContext);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-07-26 15:31:59 +02:00
|
|
|
QString QDeclarativeDesignView::idStringForObject(QObject *obj)
|
|
|
|
{
|
|
|
|
return qmlDesignDebugServer()->idStringForObject(obj);
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:13:12 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
QToolBar *QDeclarativeDesignView::toolbar() const
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->toolbar;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::createToolbar()
|
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
data->toolbar = new QmlToolbar(this);
|
|
|
|
connect(this, SIGNAL(selectedColorChanged(QColor)), data->toolbar, SLOT(setColorBoxColor(QColor)));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(this, SIGNAL(designModeBehaviorChanged(bool)), data->toolbar, SLOT(setDesignModeBehavior(bool)));
|
2010-07-12 12:02:35 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
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()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(data->toolbar, SIGNAL(applyChangesFromQmlFileSelected()), SLOT(applyChangesFromClient()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(this, SIGNAL(executionStarted(qreal)), data->toolbar, SLOT(startExecution()));
|
|
|
|
connect(this, SIGNAL(executionPaused()), data->toolbar, SLOT(pauseExecution()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(this, SIGNAL(selectToolActivated()), data->toolbar, SLOT(activateSelectTool()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
// disabled features
|
2010-07-29 12:15:55 +02:00
|
|
|
//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()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(this, SIGNAL(colorPickerActivated()), data->toolbar, SLOT(activateColorPicker()));
|
|
|
|
connect(this, SIGNAL(zoomToolActivated()), data->toolbar, SLOT(activateZoom()));
|
|
|
|
connect(this, SIGNAL(marqueeSelectToolActivated()), data->toolbar, SLOT(activateMarqueeSelectTool()));
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace QmlViewer
|