2010-07-08 14:00:33 +02:00
|
|
|
#include "qdeclarativedesignview.h"
|
|
|
|
#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)
|
|
|
|
|
|
|
|
QDeclarativeDesignView::QDeclarativeDesignView(QWidget *parent) :
|
|
|
|
QDeclarativeView(parent),
|
|
|
|
m_designModeBehavior(false),
|
|
|
|
m_executionPaused(false),
|
|
|
|
m_slowdownFactor(1.0f),
|
|
|
|
m_toolbar(0)
|
|
|
|
{
|
|
|
|
m_manipulatorLayer = new LayerItem(scene());
|
|
|
|
m_selectionTool = new SelectionTool(this);
|
|
|
|
m_zoomTool = new ZoomTool(this);
|
|
|
|
m_colorPickerTool = new ColorPickerTool(this);
|
|
|
|
m_boundingRectHighlighter = new BoundingRectHighlighter(this);
|
|
|
|
m_subcomponentEditorTool = new SubcomponentEditorTool(this);
|
|
|
|
m_currentTool = m_selectionTool;
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
connect(m_colorPickerTool, SIGNAL(selectedColorChanged(QColor)), SIGNAL(selectedColorChanged(QColor)));
|
2010-07-26 12:47:55 +02:00
|
|
|
connect(m_colorPickerTool, SIGNAL(selectedColorChanged(QColor)),
|
|
|
|
qmlDesignDebugServer(), SLOT(selectedColorChanged(QColor)));
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
createToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDeclarativeDesignView::~QDeclarativeDesignView()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::reloadView()
|
|
|
|
{
|
|
|
|
m_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;
|
|
|
|
}
|
|
|
|
m_cursorPos = event->pos();
|
|
|
|
m_currentTool->mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
m_cursorPos = event->pos();
|
|
|
|
|
|
|
|
QList<QGraphicsItem*> selItems = selectableItems(event->pos());
|
|
|
|
if (!selItems.isEmpty()) {
|
|
|
|
setToolTip(AbstractFormEditorTool::titleForItem(selItems.first()));
|
|
|
|
} else {
|
|
|
|
setToolTip(QString());
|
|
|
|
}
|
|
|
|
if (event->buttons()) {
|
|
|
|
m_subcomponentEditorTool->mouseMoveEvent(event);
|
|
|
|
m_currentTool->mouseMoveEvent(event);
|
|
|
|
} else {
|
|
|
|
m_subcomponentEditorTool->hoverMoveEvent(event);
|
|
|
|
m_currentTool->hoverMoveEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::mouseReleaseEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!designModeBehavior()) {
|
|
|
|
QDeclarativeView::mouseReleaseEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_subcomponentEditorTool->mouseReleaseEvent(event);
|
|
|
|
|
|
|
|
m_cursorPos = event->pos();
|
|
|
|
m_currentTool->mouseReleaseEvent(event);
|
|
|
|
|
2010-07-14 14:21:10 +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;
|
|
|
|
}
|
|
|
|
m_currentTool->keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
m_subcomponentEditorTool->setCurrentItem(selectedItems().first());
|
|
|
|
break;
|
|
|
|
case Qt::Key_Space:
|
|
|
|
if (m_executionPaused) {
|
|
|
|
continueExecution(m_slowdownFactor);
|
|
|
|
} else {
|
|
|
|
pauseExecution();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentTool->keyReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
return m_subcomponentEditorTool->currentRootItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
itemToEnter = m_subcomponentEditorTool->firstChildOfContext(itemToEnter);
|
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
m_subcomponentEditorTool->setCurrentItem(itemToEnter);
|
|
|
|
m_subcomponentEditorTool->mouseDoubleClickEvent(event);
|
|
|
|
|
|
|
|
if ((event->buttons() & Qt::LeftButton) && itemToEnter) {
|
|
|
|
QGraphicsObject *objectToEnter = itemToEnter->toGraphicsObject();
|
|
|
|
if (objectToEnter)
|
|
|
|
qmlDesignDebugServer()->setCurrentObjects(QList<QObject*>() << objectToEnter);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
void QDeclarativeDesignView::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
if (!m_designModeBehavior) {
|
|
|
|
QDeclarativeView::wheelEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_currentTool->wheelEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::setDesignModeBehavior(bool value)
|
|
|
|
{
|
2010-07-12 12:02:35 +02:00
|
|
|
emit designModeBehaviorChanged(value);
|
|
|
|
|
|
|
|
m_toolbar->setDesignModeBehavior(value);
|
2010-07-12 12:08:27 +02:00
|
|
|
qmlDesignDebugServer()->setDesignModeBehavior(value);
|
2010-07-12 12:02:35 +02:00
|
|
|
|
2010-07-08 14:00:33 +02:00
|
|
|
m_designModeBehavior = value;
|
|
|
|
if (m_subcomponentEditorTool) {
|
|
|
|
m_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())
|
|
|
|
m_subcomponentEditorTool->pushContext(rootObject());
|
|
|
|
}
|
2010-07-14 17:47:43 +02:00
|
|
|
|
|
|
|
if (!m_designModeBehavior)
|
|
|
|
clearEditorItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QDeclarativeDesignView::designModeBehavior() const
|
|
|
|
{
|
|
|
|
return m_designModeBehavior;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeTool(Constants::DesignTool tool, Constants::ToolFlags /*flags*/)
|
|
|
|
{
|
|
|
|
switch(tool) {
|
|
|
|
case Constants::SelectionToolMode:
|
|
|
|
changeToSingleSelectTool();
|
|
|
|
break;
|
|
|
|
case Constants::NoTool:
|
|
|
|
default:
|
|
|
|
m_currentTool = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::setSelectedItems(QList<QGraphicsItem *> items)
|
|
|
|
{
|
2010-07-15 13:38:10 +02:00
|
|
|
m_currentSelection.clear();
|
|
|
|
foreach(QGraphicsItem *item, items) {
|
|
|
|
if (item) {
|
|
|
|
QGraphicsObject *obj = item->toGraphicsObject();
|
|
|
|
if (obj)
|
|
|
|
m_currentSelection << obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_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;
|
|
|
|
foreach(const QWeakPointer<QGraphicsObject> &selectedObject, m_currentSelection) {
|
|
|
|
if (selectedObject.isNull()) {
|
|
|
|
m_currentSelection.removeOne(selectedObject);
|
|
|
|
} else {
|
|
|
|
selection << selectedObject.data();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return selection;
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractFormEditorTool *QDeclarativeDesignView::currentTool() const
|
|
|
|
{
|
|
|
|
return m_currentTool;
|
|
|
|
}
|
|
|
|
|
2010-07-13 12:03:21 +02:00
|
|
|
void QDeclarativeDesignView::clearHighlight()
|
2010-07-08 14:00:33 +02:00
|
|
|
{
|
|
|
|
m_boundingRectHighlighter->clear();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
child = m_subcomponentEditorTool->firstChildOfContext(item);
|
|
|
|
|
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
|
|
|
|
|
|
|
m_boundingRectHighlighter->highlight(objectList);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QDeclarativeDesignView::mouseInsideContextItem() const
|
|
|
|
{
|
|
|
|
return m_subcomponentEditorTool->containsCursor(m_cursorPos.toPoint());
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
m_currentToolMode = Constants::SelectionToolMode;
|
|
|
|
m_selectionTool->setRubberbandSelectionMode(false);
|
|
|
|
|
|
|
|
changeToSelectTool();
|
|
|
|
|
|
|
|
emit selectToolActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::SelectionToolMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToSelectTool()
|
|
|
|
{
|
|
|
|
if (m_currentTool == m_selectionTool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentTool->clear();
|
|
|
|
m_currentTool = m_selectionTool;
|
|
|
|
m_currentTool->clear();
|
2010-07-15 13:38:10 +02:00
|
|
|
m_currentTool->updateSelectedItems();
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToMarqueeSelectTool()
|
|
|
|
{
|
|
|
|
changeToSelectTool();
|
|
|
|
m_currentToolMode = Constants::MarqueeSelectionToolMode;
|
|
|
|
m_selectionTool->setRubberbandSelectionMode(true);
|
|
|
|
|
|
|
|
emit marqueeSelectToolActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::MarqueeSelectionToolMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToZoomTool()
|
|
|
|
{
|
|
|
|
m_currentToolMode = Constants::ZoomMode;
|
|
|
|
m_currentTool->clear();
|
|
|
|
m_currentTool = m_zoomTool;
|
|
|
|
m_currentTool->clear();
|
|
|
|
|
|
|
|
emit zoomToolActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::ZoomMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeToColorPickerTool()
|
|
|
|
{
|
|
|
|
if (m_currentTool == m_colorPickerTool)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentToolMode = Constants::ColorPickerMode;
|
|
|
|
m_currentTool->clear();
|
|
|
|
m_currentTool = m_colorPickerTool;
|
|
|
|
m_currentTool->clear();
|
|
|
|
|
|
|
|
emit colorPickerActivated();
|
|
|
|
qmlDesignDebugServer()->setCurrentTool(Constants::ColorPickerMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::changeAnimationSpeed(qreal slowdownFactor)
|
|
|
|
{
|
|
|
|
m_slowdownFactor = slowdownFactor;
|
|
|
|
|
|
|
|
if (m_slowdownFactor != 0) {
|
|
|
|
continueExecution(m_slowdownFactor);
|
|
|
|
} else {
|
|
|
|
pauseExecution();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::continueExecution(qreal slowdownFactor)
|
|
|
|
{
|
|
|
|
Q_ASSERT(slowdownFactor > 0);
|
|
|
|
|
|
|
|
m_slowdownFactor = slowdownFactor;
|
2010-07-12 14:32:54 +02:00
|
|
|
static const qreal animSpeedSnapDelta = 0.01f;
|
|
|
|
bool useStandardSpeed = (qAbs(1.0f - m_slowdownFactor) < animSpeedSnapDelta);
|
2010-07-08 14:00:33 +02:00
|
|
|
|
|
|
|
QUnifiedTimer *timer = QUnifiedTimer::instance();
|
|
|
|
timer->setSlowdownFactor(m_slowdownFactor);
|
2010-07-12 14:32:54 +02:00
|
|
|
timer->setSlowModeEnabled(!useStandardSpeed);
|
2010-07-08 14:00:33 +02:00
|
|
|
m_executionPaused = false;
|
|
|
|
|
|
|
|
emit executionStarted(m_slowdownFactor);
|
|
|
|
qmlDesignDebugServer()->setAnimationSpeed(m_slowdownFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
m_executionPaused = true;
|
|
|
|
|
|
|
|
emit executionPaused();
|
2010-07-09 16:33:09 +02:00
|
|
|
qmlDesignDebugServer()->setAnimationSpeed(0);
|
2010-07-08 14:00:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::applyChangesFromClient()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerItem *QDeclarativeDesignView::manipulatorLayer() const
|
|
|
|
{
|
|
|
|
return m_manipulatorLayer;
|
|
|
|
}
|
|
|
|
|
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-09 16:33:09 +02:00
|
|
|
if (isEditorItem(item) || !m_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) {
|
|
|
|
|
|
|
|
if (isEditorItem(item) || !m_subcomponentEditorTool->isDirectChildOfContext(item)) {
|
|
|
|
|
|
|
|
// if we're a child, but not directly, replace with the parent that is directly in context.
|
|
|
|
if (QGraphicsItem *contextParent = m_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()) {
|
|
|
|
m_subcomponentEditorTool->pushContext(rootObject());
|
|
|
|
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-08 14:00:33 +02:00
|
|
|
QToolBar *QDeclarativeDesignView::toolbar() const
|
|
|
|
{
|
|
|
|
return m_toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QDeclarativeDesignView::createToolbar()
|
|
|
|
{
|
|
|
|
m_toolbar = new QmlToolbar(this);
|
|
|
|
connect(this, SIGNAL(selectedColorChanged(QColor)), m_toolbar, SLOT(setColorBoxColor(QColor)));
|
|
|
|
|
2010-07-12 12:02:35 +02:00
|
|
|
connect(this, SIGNAL(designModeBehaviorChanged(bool)), m_toolbar, SLOT(setDesignModeBehavior(bool)));
|
|
|
|
|
|
|
|
connect(m_toolbar, SIGNAL(designModeBehaviorChanged(bool)), this, SLOT(setDesignModeBehavior(bool)));
|
2010-07-08 14:00:33 +02:00
|
|
|
connect(m_toolbar, SIGNAL(executionStarted()), this, SLOT(continueExecution()));
|
|
|
|
connect(m_toolbar, SIGNAL(executionPaused()), this, SLOT(pauseExecution()));
|
|
|
|
connect(m_toolbar, SIGNAL(colorPickerSelected()), this, SLOT(changeToColorPickerTool()));
|
|
|
|
connect(m_toolbar, SIGNAL(zoomToolSelected()), this, SLOT(changeToZoomTool()));
|
|
|
|
connect(m_toolbar, SIGNAL(selectToolSelected()), this, SLOT(changeToSingleSelectTool()));
|
|
|
|
connect(m_toolbar, SIGNAL(marqueeSelectToolSelected()), this, SLOT(changeToMarqueeSelectTool()));
|
|
|
|
|
|
|
|
connect(m_toolbar, SIGNAL(applyChangesFromQmlFileSelected()), SLOT(applyChangesFromClient()));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(executionStarted(qreal)), m_toolbar, SLOT(startExecution()));
|
|
|
|
connect(this, SIGNAL(executionPaused()), m_toolbar, SLOT(pauseExecution()));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(selectToolActivated()), m_toolbar, SLOT(activateSelectTool()));
|
|
|
|
|
|
|
|
// disabled features
|
|
|
|
//connect(m_toolbar, SIGNAL(applyChangesToQmlFileSelected()), SLOT(applyChangesToClient()));
|
|
|
|
//connect(this, SIGNAL(resizeToolActivated()), m_toolbar, SLOT(activateSelectTool()));
|
|
|
|
//connect(this, SIGNAL(moveToolActivated()), m_toolbar, SLOT(activateSelectTool()));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(colorPickerActivated()), m_toolbar, SLOT(activateColorPicker()));
|
|
|
|
connect(this, SIGNAL(zoomToolActivated()), m_toolbar, SLOT(activateZoom()));
|
|
|
|
connect(this, SIGNAL(marqueeSelectToolActivated()), m_toolbar, SLOT(activateMarqueeSelectTool()));
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace QmlViewer
|