2010-07-30 12:56:25 +02:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
#include "qdeclarativeviewobserver.h"
|
|
|
|
#include "qdeclarativeviewobserver_p.h"
|
2010-09-16 12:29:06 +02:00
|
|
|
#include "qdeclarativeobserverservice.h"
|
2010-07-08 14:00:33 +02:00
|
|
|
#include "selectiontool.h"
|
|
|
|
#include "zoomtool.h"
|
|
|
|
#include "colorpickertool.h"
|
|
|
|
#include "layeritem.h"
|
|
|
|
#include "boundingrecthighlighter.h"
|
|
|
|
#include "subcomponenteditortool.h"
|
|
|
|
#include "qmltoolbar.h"
|
2010-08-18 13:54:12 +02:00
|
|
|
#include "jsdebuggeragent.h"
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
#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>
|
2010-08-18 13:54:12 +02:00
|
|
|
#include <private/qdeclarativeengine_p.h>
|
2010-07-08 14:00:33 +02:00
|
|
|
#include <private/qabstractanimation_p.h>
|
|
|
|
|
2010-09-16 15:59:52 +02:00
|
|
|
namespace QmlObserver {
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-08-06 14:03:13 +02:00
|
|
|
const int SceneChangeUpdateInterval = 5000;
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QDeclarativeViewObserverPrivate::QDeclarativeViewObserverPrivate(QDeclarativeViewObserver *q) :
|
2010-07-30 12:56:25 +02:00
|
|
|
q(q),
|
2010-07-29 12:15:55 +02:00
|
|
|
designModeBehavior(false),
|
|
|
|
executionPaused(false),
|
|
|
|
slowdownFactor(1.0f),
|
2010-08-18 13:54:12 +02:00
|
|
|
jsDebuggerAgent(0),
|
2010-08-19 12:47:43 +02:00
|
|
|
toolbar(0)
|
2010-07-29 12:15:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QDeclarativeViewObserverPrivate::~QDeclarativeViewObserverPrivate()
|
2010-07-29 12:15:55 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QDeclarativeViewObserver::QDeclarativeViewObserver(QDeclarativeView *view, QObject *parent) :
|
|
|
|
QObject(parent), data(new QDeclarativeViewObserverPrivate(this))
|
2010-07-29 12:15:55 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
data->view = view;
|
|
|
|
data->manipulatorLayer = new LayerItem(view->scene());
|
2010-07-29 12:15:55 +02:00
|
|
|
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
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
data->view->setMouseTracking(true);
|
|
|
|
data->view->viewport()->installEventFilter(this);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-09-16 12:29:06 +02:00
|
|
|
data->debugService = QDeclarativeObserverService::instance();
|
|
|
|
connect(data->debugService, SIGNAL(designModeBehaviorChanged(bool)), SLOT(setDesignModeBehavior(bool)));
|
|
|
|
connect(data->debugService, SIGNAL(reloadRequested()), SLOT(_q_reloadView()));
|
|
|
|
connect(data->debugService,
|
2010-07-08 14:00:33 +02:00
|
|
|
SIGNAL(currentObjectsChanged(QList<QObject*>)),
|
2010-07-30 12:56:25 +02:00
|
|
|
SLOT(_q_onCurrentObjectsChanged(QList<QObject*>)));
|
2010-09-16 12:29:06 +02:00
|
|
|
connect(data->debugService, SIGNAL(animationSpeedChangeRequested(qreal)), SLOT(changeAnimationSpeed(qreal)));
|
|
|
|
connect(data->debugService, SIGNAL(colorPickerToolRequested()), SLOT(_q_changeToColorPickerTool()));
|
|
|
|
connect(data->debugService, SIGNAL(selectMarqueeToolRequested()), SLOT(_q_changeToMarqueeSelectTool()));
|
|
|
|
connect(data->debugService, SIGNAL(selectToolRequested()), SLOT(_q_changeToSingleSelectTool()));
|
|
|
|
connect(data->debugService, SIGNAL(zoomToolRequested()), SLOT(_q_changeToZoomTool()));
|
|
|
|
connect(data->debugService,
|
2010-07-16 09:41:56 +02:00
|
|
|
SIGNAL(objectCreationRequested(QString,QObject*,QStringList,QString)),
|
2010-07-30 12:56:25 +02:00
|
|
|
SLOT(_q_createQmlObject(QString,QObject*,QStringList,QString)));
|
2010-09-16 12:29:06 +02:00
|
|
|
connect(data->debugService,
|
2010-08-26 17:38:31 +02:00
|
|
|
SIGNAL(objectReparentRequested(QObject *, QObject *)),
|
|
|
|
SLOT(_q_reparentQmlObject(QObject *, QObject *)));
|
2010-09-16 12:29:06 +02:00
|
|
|
connect(data->debugService, SIGNAL(contextPathIndexChanged(int)), SLOT(_q_changeContextPathIndex(int)));
|
|
|
|
connect(data->debugService, SIGNAL(clearComponentCacheRequested()), SLOT(_q_clearComponentCache()));
|
2010-09-14 13:39:32 +02:00
|
|
|
connect(data->view, SIGNAL(statusChanged(QDeclarativeView::Status)), SLOT(_q_onStatusChanged(QDeclarativeView::Status)));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor)));
|
|
|
|
connect(data->colorPickerTool, SIGNAL(selectedColorChanged(QColor)),
|
2010-09-16 12:29:06 +02:00
|
|
|
data->debugService, 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-09-16 12:29:06 +02:00
|
|
|
connect(data->subcomponentEditorTool, SIGNAL(contextPathChanged(QStringList)), data->debugService, SLOT(contextPathUpdated(QStringList)));
|
2010-07-30 16:09:17 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
data->createToolbar();
|
2010-08-03 09:45:11 +02:00
|
|
|
|
|
|
|
data->_q_changeToSingleSelectTool();
|
2010-08-18 13:54:12 +02:00
|
|
|
|
|
|
|
// always start debug mode - that's what this design view is for.
|
|
|
|
setDebugMode(true);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QDeclarativeViewObserver::~QDeclarativeViewObserver()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:20:12 +02:00
|
|
|
void QDeclarativeViewObserver::setObserverContext(int contextIndex)
|
2010-07-30 16:09:17 +02:00
|
|
|
{
|
2010-07-30 17:19:28 +02:00
|
|
|
if (data->subcomponentEditorTool->contextIndex() != contextIndex) {
|
|
|
|
QGraphicsObject *object = data->subcomponentEditorTool->setContext(contextIndex);
|
|
|
|
if (object)
|
2010-09-16 12:29:06 +02:00
|
|
|
data->debugService->setCurrentObjects(QList<QObject*>() << object);
|
2010-07-30 17:19:28 +02:00
|
|
|
}
|
2010-07-30 16:09:17 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_reloadView()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
subcomponentEditorTool->clear();
|
2010-07-13 12:03:21 +02:00
|
|
|
clearHighlight();
|
2010-07-30 12:56:25 +02:00
|
|
|
emit q->reloadRequested();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::clearEditorItems()
|
2010-07-14 17:47:43 +02:00
|
|
|
{
|
|
|
|
clearHighlight();
|
|
|
|
setSelectedItems(QList<QGraphicsItem*>());
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::Leave: {
|
|
|
|
if (leaveEvent(event))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::MouseButtonPress: {
|
|
|
|
if (mousePressEvent(static_cast<QMouseEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::MouseMove: {
|
|
|
|
if (mouseMoveEvent(static_cast<QMouseEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::MouseButtonRelease: {
|
|
|
|
if (mouseReleaseEvent(static_cast<QMouseEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::KeyPress: {
|
|
|
|
if (keyPressEvent(static_cast<QKeyEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::KeyRelease: {
|
|
|
|
if (keyReleaseEvent(static_cast<QKeyEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::MouseButtonDblClick: {
|
|
|
|
if (mouseDoubleClickEvent(static_cast<QMouseEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QEvent::Wheel: {
|
|
|
|
if (wheelEvent(static_cast<QWheelEvent*>(event)))
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} //switch
|
|
|
|
|
|
|
|
// standard event processing
|
|
|
|
return QObject::eventFilter(obj, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QDeclarativeViewObserver::leaveEvent(QEvent * /*event*/)
|
2010-07-09 16:33:09 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
if (!data->designModeBehavior)
|
|
|
|
return false;
|
2010-07-30 12:56:25 +02:00
|
|
|
data->clearHighlight();
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::mousePressEvent(QMouseEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
if (!data->designModeBehavior)
|
|
|
|
return false;
|
2010-07-29 12:15:55 +02:00
|
|
|
data->cursorPos = event->pos();
|
|
|
|
data->currentTool->mousePressEvent(event);
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::mouseMoveEvent(QMouseEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
if (!data->designModeBehavior) {
|
|
|
|
data->clearEditorItems();
|
2010-09-14 13:39:32 +02:00
|
|
|
return false;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->cursorPos = event->pos();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
QList<QGraphicsItem*> selItems = data->selectableItems(event->pos());
|
2010-07-08 14:00:33 +02:00
|
|
|
if (!selItems.isEmpty()) {
|
2010-09-14 13:39:32 +02:00
|
|
|
declarativeView()->setToolTip(AbstractFormEditorTool::titleForItem(selItems.first()));
|
2010-07-08 14:00:33 +02:00
|
|
|
} else {
|
2010-09-14 13:39:32 +02:00
|
|
|
declarativeView()->setToolTip(QString());
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::mouseReleaseEvent(QMouseEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
if (!data->designModeBehavior)
|
|
|
|
return false;
|
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-09-16 12:29:06 +02:00
|
|
|
data->debugService->setCurrentObjects(AbstractFormEditorTool::toObjectList(selectedItems()));
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::keyPressEvent(QKeyEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
if (!data->designModeBehavior) {
|
2010-09-14 13:39:32 +02:00
|
|
|
return false;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->keyPressEvent(event);
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::keyReleaseEvent(QKeyEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
if (!data->designModeBehavior) {
|
2010-09-14 13:39:32 +02:00
|
|
|
return false;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(event->key()) {
|
|
|
|
case Qt::Key_V:
|
2010-07-30 12:56:25 +02:00
|
|
|
data->_q_changeToSingleSelectTool();
|
2010-07-08 14:00:33 +02:00
|
|
|
break;
|
2010-08-26 16:31:06 +02:00
|
|
|
// disabled because multiselection does not do anything useful without design mode
|
|
|
|
// case Qt::Key_M:
|
|
|
|
// data->_q_changeToMarqueeSelectTool();
|
|
|
|
// break;
|
2010-07-09 16:33:09 +02:00
|
|
|
case Qt::Key_I:
|
2010-07-30 12:56:25 +02:00
|
|
|
data->_q_changeToColorPickerTool();
|
2010-07-09 16:33:09 +02:00
|
|
|
break;
|
|
|
|
case Qt::Key_Z:
|
2010-07-30 12:56:25 +02:00
|
|
|
data->_q_changeToZoomTool();
|
2010-07-09 16:33:09 +02:00
|
|
|
break;
|
2010-07-08 14:00:33 +02:00
|
|
|
case Qt::Key_Enter:
|
|
|
|
case Qt::Key_Return:
|
2010-07-30 12:56:25 +02:00
|
|
|
if (!data->selectedItems().isEmpty())
|
|
|
|
data->subcomponentEditorTool->setCurrentItem(data->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-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_createQmlObject(const QString &qml, QObject *parent, const QStringList &importList, const QString &filename)
|
2010-07-16 09:41:56 +02:00
|
|
|
{
|
|
|
|
if (!parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString imports;
|
|
|
|
foreach(const QString &s, importList) {
|
|
|
|
imports += s + "\n";
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QDeclarativeContext *parentContext = view->engine()->contextForObject(parent);
|
|
|
|
QDeclarativeComponent component(view->engine(), q);
|
2010-07-16 09:41:56 +02:00
|
|
|
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-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_reparentQmlObject(QObject *object, QObject *newParent)
|
2010-08-26 17:38:31 +02:00
|
|
|
{
|
|
|
|
if (!newParent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
object->setParent(newParent);
|
|
|
|
QDeclarativeItem *newParentItem = qobject_cast<QDeclarativeItem*>(newParent);
|
|
|
|
QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(object);
|
|
|
|
if (newParentItem && item) {
|
|
|
|
item->setParentItem(newParentItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_clearComponentCache()
|
2010-08-03 14:07:30 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
view->engine()->clearComponentCache();
|
2010-08-03 14:07:30 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QGraphicsItem *QDeclarativeViewObserverPrivate::currentRootItem() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
return subcomponentEditorTool->currentRootItem();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::mouseDoubleClickEvent(QMouseEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
if (!data->designModeBehavior)
|
|
|
|
return false;
|
2010-08-03 09:45:11 +02:00
|
|
|
|
|
|
|
if (data->currentToolMode != Constants::SelectionToolMode
|
2010-09-14 13:39:32 +02:00
|
|
|
&& data->currentToolMode != Constants::MarqueeSelectionToolMode)
|
|
|
|
return true;
|
2010-08-03 09:45:11 +02:00
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
QGraphicsItem *itemToEnter = 0;
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> itemList = data->view->items(event->pos());
|
2010-07-30 12:56:25 +02:00
|
|
|
data->filterForSelection(itemList);
|
2010-07-09 16:33:09 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
if (data->selectedItems().isEmpty() && !itemList.isEmpty()) {
|
2010-07-08 14:00:33 +02:00
|
|
|
itemToEnter = itemList.first();
|
2010-07-30 12:56:25 +02:00
|
|
|
} else if (!data->selectedItems().isEmpty() && !itemList.isEmpty()) {
|
2010-07-08 14:00:33 +02:00
|
|
|
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)
|
2010-09-16 12:29:06 +02:00
|
|
|
data->debugService->setCurrentObjects(QList<QObject*>() << objectToEnter);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
2010-08-26 17:11:17 +02:00
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::wheelEvent(QWheelEvent *event)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
if (!data->designModeBehavior)
|
|
|
|
return false;
|
2010-07-29 12:15:55 +02:00
|
|
|
data->currentTool->wheelEvent(event);
|
2010-09-14 13:39:32 +02:00
|
|
|
return true;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::enterContext(QGraphicsItem *itemToEnter)
|
2010-08-26 17:11:17 +02:00
|
|
|
{
|
|
|
|
QGraphicsItem *itemUnderCurrentContext = itemToEnter;
|
|
|
|
if (itemUnderCurrentContext)
|
|
|
|
itemUnderCurrentContext = subcomponentEditorTool->firstChildOfContext(itemToEnter);
|
|
|
|
|
|
|
|
if (itemUnderCurrentContext)
|
|
|
|
subcomponentEditorTool->setCurrentItem(itemToEnter);
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserver::setDesignModeBehavior(bool value)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-12 12:02:35 +02:00
|
|
|
emit designModeBehaviorChanged(value);
|
|
|
|
|
2010-07-29 12:15:55 +02:00
|
|
|
data->toolbar->setDesignModeBehavior(value);
|
2010-09-16 12:29:06 +02:00
|
|
|
data->debugService->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-30 12:56:25 +02:00
|
|
|
data->clearHighlight();
|
|
|
|
data->setSelectedItems(QList<QGraphicsItem*>());
|
2010-07-12 14:32:54 +02:00
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
if (data->view->rootObject())
|
|
|
|
data->subcomponentEditorTool->pushContext(data->view->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-30 12:56:25 +02:00
|
|
|
data->clearEditorItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserver::designModeBehavior()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->designModeBehavior;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
switch(tool) {
|
|
|
|
case Constants::SelectionToolMode:
|
2010-07-30 12:56:25 +02:00
|
|
|
_q_changeToSingleSelectTool();
|
2010-07-08 14:00:33 +02:00
|
|
|
break;
|
|
|
|
case Constants::NoTool:
|
|
|
|
default:
|
2010-07-30 12:56:25 +02:00
|
|
|
currentTool = 0;
|
2010-07-08 14:00:33 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::setSelectedItemsForTools(QList<QGraphicsItem *> items)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
currentSelection.clear();
|
2010-07-15 13:38:10 +02:00
|
|
|
foreach(QGraphicsItem *item, items) {
|
|
|
|
if (item) {
|
|
|
|
QGraphicsObject *obj = item->toGraphicsObject();
|
|
|
|
if (obj)
|
2010-07-30 12:56:25 +02:00
|
|
|
currentSelection << obj;
|
2010-07-15 13:38:10 +02:00
|
|
|
}
|
|
|
|
}
|
2010-07-30 12:56:25 +02:00
|
|
|
currentTool->updateSelectedItems();
|
2010-07-30 17:43:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::setSelectedItems(QList<QGraphicsItem *> items)
|
2010-07-30 17:43:21 +02:00
|
|
|
{
|
|
|
|
setSelectedItemsForTools(items);
|
2010-09-16 12:29:06 +02:00
|
|
|
debugService->setCurrentObjects(AbstractFormEditorTool::toObjectList(items));
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem *> QDeclarativeViewObserverPrivate::selectedItems()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-15 13:38:10 +02:00
|
|
|
QList<QGraphicsItem *> selection;
|
2010-07-30 12:56:25 +02:00
|
|
|
foreach(const QWeakPointer<QGraphicsObject> &selectedObject, currentSelection) {
|
2010-07-15 13:38:10 +02:00
|
|
|
if (selectedObject.isNull()) {
|
2010-07-30 12:56:25 +02:00
|
|
|
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-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserver::setSelectedItems(QList<QGraphicsItem *> items)
|
2010-07-30 12:56:25 +02:00
|
|
|
{
|
|
|
|
data->setSelectedItems(items);
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem *> QDeclarativeViewObserver::selectedItems()
|
2010-07-30 12:56:25 +02:00
|
|
|
{
|
|
|
|
return data->selectedItems();
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QDeclarativeView *QDeclarativeViewObserver::declarativeView()
|
|
|
|
{
|
|
|
|
return data->view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeViewObserverPrivate::clearHighlight()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
boundingRectHighlighter->clear();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::highlight(QGraphicsObject * item, ContextFlags flags)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-08-04 18:53:01 +02:00
|
|
|
highlight(QList<QGraphicsObject*>() << item, flags);
|
2010-07-13 12:03:21 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::highlight(QList<QGraphicsObject *> 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-30 12:56:25 +02:00
|
|
|
child = 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-30 12:56:25 +02:00
|
|
|
boundingRectHighlighter->highlight(objectList);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserverPrivate::mouseInsideContextItem() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
return subcomponentEditorTool->containsCursor(cursorPos.toPoint());
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> QDeclarativeViewObserverPrivate::selectableItems(const QPointF &scenePos) const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> itemlist = view->scene()->items(scenePos);
|
2010-07-09 16:33:09 +02:00
|
|
|
return filterForCurrentContext(itemlist);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> QDeclarativeViewObserverPrivate::selectableItems(const QPoint &pos) const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> itemlist = view->items(pos);
|
2010-07-09 16:33:09 +02:00
|
|
|
return filterForCurrentContext(itemlist);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> QDeclarativeViewObserverPrivate::selectableItems(const QRectF &sceneRect, Qt::ItemSelectionMode selectionMode) const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> itemlist = view->scene()->items(sceneRect, selectionMode);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-09 16:33:09 +02:00
|
|
|
return filterForCurrentContext(itemlist);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_changeToSingleSelectTool()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
currentToolMode = Constants::SelectionToolMode;
|
|
|
|
selectionTool->setRubberbandSelectionMode(false);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
changeToSelectTool();
|
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
emit q->selectToolActivated();
|
2010-09-16 12:29:06 +02:00
|
|
|
debugService->setCurrentTool(Constants::SelectionToolMode);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::changeToSelectTool()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
if (currentTool == selectionTool)
|
2010-07-08 14:00:33 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
currentTool->clear();
|
|
|
|
currentTool = selectionTool;
|
|
|
|
currentTool->clear();
|
|
|
|
currentTool->updateSelectedItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_changeToMarqueeSelectTool()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
changeToSelectTool();
|
2010-07-30 12:56:25 +02:00
|
|
|
currentToolMode = Constants::MarqueeSelectionToolMode;
|
|
|
|
selectionTool->setRubberbandSelectionMode(true);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
emit q->marqueeSelectToolActivated();
|
2010-09-16 12:29:06 +02:00
|
|
|
debugService->setCurrentTool(Constants::MarqueeSelectionToolMode);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_changeToZoomTool()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
currentToolMode = Constants::ZoomMode;
|
|
|
|
currentTool->clear();
|
|
|
|
currentTool = zoomTool;
|
|
|
|
currentTool->clear();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
emit q->zoomToolActivated();
|
2010-09-16 12:29:06 +02:00
|
|
|
debugService->setCurrentTool(Constants::ZoomMode);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_changeToColorPickerTool()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-30 12:56:25 +02:00
|
|
|
if (currentTool == colorPickerTool)
|
2010-07-08 14:00:33 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
currentToolMode = Constants::ColorPickerMode;
|
|
|
|
currentTool->clear();
|
|
|
|
currentTool = colorPickerTool;
|
|
|
|
currentTool->clear();
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
emit q->colorPickerActivated();
|
2010-09-16 12:29:06 +02:00
|
|
|
debugService->setCurrentTool(Constants::ColorPickerMode);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_changeContextPathIndex(int index)
|
2010-08-03 10:17:09 +02:00
|
|
|
{
|
|
|
|
subcomponentEditorTool->setContext(index);
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserver::changeAnimationSpeed(qreal slowdownFactor)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserver::continueExecution(qreal slowdownFactor)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
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);
|
2010-09-16 12:29:06 +02:00
|
|
|
data->debugService->setAnimationSpeed(data->slowdownFactor);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserver::pauseExecution()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
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-09-16 12:29:06 +02:00
|
|
|
data->debugService->setAnimationSpeed(0);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_applyChangesFromClient()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> QDeclarativeViewObserverPrivate::filterForSelection(QList<QGraphicsItem*> &itemlist) const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
foreach(QGraphicsItem *item, itemlist) {
|
2010-07-30 12:56:25 +02:00
|
|
|
if (isEditorItem(item) || !subcomponentEditorTool->isChildOfContext(item))
|
2010-07-08 14:00:33 +02:00
|
|
|
itemlist.removeOne(item);
|
2010-07-09 16:33:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return itemlist;
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QList<QGraphicsItem*> QDeclarativeViewObserverPrivate::filterForCurrentContext(QList<QGraphicsItem*> &itemlist) const
|
2010-07-09 16:33:09 +02:00
|
|
|
{
|
|
|
|
foreach(QGraphicsItem *item, itemlist) {
|
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
if (isEditorItem(item) || !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-30 12:56:25 +02:00
|
|
|
if (QGraphicsItem *contextParent = 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-09-14 13:39:32 +02:00
|
|
|
bool QDeclarativeViewObserverPrivate::isEditorItem(QGraphicsItem *item) const
|
2010-07-09 16:33:09 +02:00
|
|
|
{
|
|
|
|
return (item->type() == Constants::EditorItemType
|
|
|
|
|| item->type() == Constants::ResizeHandleItemType
|
|
|
|
|| item->data(Constants::EditorItemDataKey).toBool());
|
|
|
|
}
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_onStatusChanged(QDeclarativeView::Status status)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
if (status == QDeclarativeView::Ready) {
|
2010-09-14 13:39:32 +02:00
|
|
|
if (view->rootObject()) {
|
2010-07-30 17:43:21 +02:00
|
|
|
if (subcomponentEditorTool->contextIndex() != -1)
|
|
|
|
subcomponentEditorTool->clear();
|
2010-09-14 13:39:32 +02:00
|
|
|
subcomponentEditorTool->pushContext(view->rootObject());
|
2010-07-30 12:56:25 +02:00
|
|
|
emit q->executionStarted(1.0f);
|
2010-07-30 17:25:14 +02:00
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
2010-09-16 12:29:06 +02:00
|
|
|
debugService->reloaded();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::_q_onCurrentObjectsChanged(QList<QObject*> objects)
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
QList<QGraphicsItem*> items;
|
2010-08-04 18:53:01 +02:00
|
|
|
QList<QGraphicsObject*> gfxObjects;
|
2010-07-08 14:00:33 +02:00
|
|
|
foreach(QObject *obj, objects) {
|
|
|
|
QDeclarativeItem* declarativeItem = qobject_cast<QDeclarativeItem*>(obj);
|
2010-08-04 18:53:01 +02:00
|
|
|
if (declarativeItem) {
|
2010-07-08 14:00:33 +02:00
|
|
|
items << declarativeItem;
|
2010-08-04 18:53:01 +02:00
|
|
|
QGraphicsObject *gfxObj = declarativeItem->toGraphicsObject();
|
|
|
|
if (gfxObj)
|
|
|
|
gfxObjects << gfxObj;
|
|
|
|
}
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
2010-07-30 17:43:21 +02:00
|
|
|
setSelectedItemsForTools(items);
|
2010-07-13 12:03:21 +02:00
|
|
|
clearHighlight();
|
2010-09-14 13:39:32 +02:00
|
|
|
highlight(gfxObjects, QDeclarativeViewObserverPrivate::IgnoreContext);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QString QDeclarativeViewObserver::idStringForObject(QObject *obj)
|
2010-07-26 15:31:59 +02:00
|
|
|
{
|
2010-09-16 12:29:06 +02:00
|
|
|
return QDeclarativeObserverService::instance()->idStringForObject(obj);
|
2010-07-26 15:31:59 +02:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:13:12 +02:00
|
|
|
// adjusts bounding boxes on edges of screen to be visible
|
2010-09-14 13:39:32 +02:00
|
|
|
QRectF QDeclarativeViewObserver::adjustToScreenBoundaries(const QRectF &boundingRectInSceneSpace)
|
2010-07-27 13:13:12 +02:00
|
|
|
{
|
|
|
|
int marginFromEdge = 1;
|
|
|
|
QRectF boundingRect(boundingRectInSceneSpace);
|
|
|
|
if (qAbs(boundingRect.left()) - 1 < 2) {
|
|
|
|
boundingRect.setLeft(marginFromEdge);
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QRect rect = data->view->rect();
|
|
|
|
if (boundingRect.right() >= rect.right() ) {
|
|
|
|
boundingRect.setRight(rect.right() - marginFromEdge);
|
2010-07-27 13:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (qAbs(boundingRect.top()) - 1 < 2) {
|
|
|
|
boundingRect.setTop(marginFromEdge);
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
if (boundingRect.bottom() >= rect.bottom() ) {
|
|
|
|
boundingRect.setBottom(rect.bottom() - marginFromEdge);
|
2010-07-27 13:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return boundingRect;
|
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
QToolBar *QDeclarativeViewObserver::toolbar() const
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-07-29 12:15:55 +02:00
|
|
|
return data->toolbar;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserverPrivate::createToolbar()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
2010-09-14 13:39:32 +02:00
|
|
|
toolbar = new QmlToolbar(q->declarativeView());
|
2010-07-30 12:56:25 +02:00
|
|
|
QObject::connect(q, SIGNAL(selectedColorChanged(QColor)), toolbar, SLOT(setColorBoxColor(QColor)));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
QObject::connect(q, SIGNAL(designModeBehaviorChanged(bool)), toolbar, SLOT(setDesignModeBehavior(bool)));
|
2010-07-12 12:02:35 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
QObject::connect(toolbar, SIGNAL(designModeBehaviorChanged(bool)), q, SLOT(setDesignModeBehavior(bool)));
|
2010-08-24 18:40:57 +02:00
|
|
|
QObject::connect(toolbar, SIGNAL(animationSpeedChanged(qreal)), q, SLOT(changeAnimationSpeed(qreal)));
|
2010-07-30 12:56:25 +02:00
|
|
|
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()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
QObject::connect(toolbar, SIGNAL(applyChangesFromQmlFileSelected()), q, SLOT(_q_applyChangesFromClient()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-08-24 18:40:57 +02:00
|
|
|
QObject::connect(q, SIGNAL(executionStarted(qreal)), toolbar, SLOT(setAnimationSpeed(qreal)));
|
|
|
|
QObject::connect(q, SIGNAL(executionPaused()), toolbar, SLOT(setAnimationSpeed()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
QObject::connect(q, SIGNAL(selectToolActivated()), 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()));
|
2010-07-30 12:56:25 +02:00
|
|
|
//connect(q, SIGNAL(resizeToolActivated()), d->m_toolbar, SLOT(activateSelectTool()));
|
|
|
|
//connect(q, SIGNAL(moveToolActivated()), d->m_toolbar, SLOT(activateSelectTool()));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
2010-07-30 12:56:25 +02:00
|
|
|
QObject::connect(q, SIGNAL(colorPickerActivated()), toolbar, SLOT(activateColorPicker()));
|
|
|
|
QObject::connect(q, SIGNAL(zoomToolActivated()), toolbar, SLOT(activateZoom()));
|
|
|
|
QObject::connect(q, SIGNAL(marqueeSelectToolActivated()), toolbar, SLOT(activateMarqueeSelectTool()));
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
void QDeclarativeViewObserver::setDebugMode(bool isDebugMode)
|
2010-08-18 13:54:12 +02:00
|
|
|
{
|
|
|
|
if (isDebugMode && !data->jsDebuggerAgent)
|
2010-09-14 13:39:32 +02:00
|
|
|
data->jsDebuggerAgent = new JSDebuggerAgent(QDeclarativeEnginePrivate::getScriptEngine(data->view->engine()));
|
2010-08-18 13:54:12 +02:00
|
|
|
}
|
|
|
|
|
2010-09-16 15:59:52 +02:00
|
|
|
} //namespace QmlObserver
|
2010-07-30 12:56:25 +02:00
|
|
|
|
2010-09-14 13:39:32 +02:00
|
|
|
#include <moc_qdeclarativeviewobserver.cpp>
|