diff options
author | Marco Bubke <marco.bubke@nokia.com> | 2011-01-12 16:07:31 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@nokia.com> | 2011-01-12 16:08:17 +0100 |
commit | 2228fb14e81c0149dab7f9680a400e55a0636313 (patch) | |
tree | 8fde3b65fcb24082a2ffeae6b6344e11c8523179 | |
parent | 8bf142fbc3f84fffda557eb5f80568bfcd727dc5 (diff) |
QmlDesigner: States preview are functional again
But still slow.
20 files changed, 254 insertions, 67 deletions
diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp index b5cba61ea7..f212f7ae51 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.cpp @@ -32,6 +32,7 @@ **************************************************************************/ #include "stateseditorimageprovider.h" #include "stateseditorview.h" +#include "nodeinstanceview.h" #include <QtDebug> @@ -39,34 +40,45 @@ namespace QmlDesigner { namespace Internal { -StatesEditorImageProvider::StatesEditorImageProvider() : - QDeclarativeImageProvider(QDeclarativeImageProvider::Image) +StatesEditorImageProvider::StatesEditorImageProvider() + : QDeclarativeImageProvider(QDeclarativeImageProvider::Image) { } QImage StatesEditorImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { + if (m_nodeInstanceView.isNull()) + return QImage(); + QSize newSize = requestedSize; if (newSize.isEmpty()) newSize = QSize (100, 100); - QImage image = m_imageHash.value(id, QImage(newSize, QImage::Format_ARGB32)); - image.fill(0xFFFFFFFF); + QString imageId = id.split("-").first(); + QImage image; + + if (imageId == "baseState") { + image = m_nodeInstanceView->statePreviewImage(m_nodeInstanceView->rootModelNode()); + } else { + bool canBeConverted; + int instanceId = imageId.toInt(&canBeConverted); + if (canBeConverted && m_nodeInstanceView->hasModelNodeForInternalId(instanceId)) { + image = m_nodeInstanceView->statePreviewImage(m_nodeInstanceView->modelNodeForInternalId(instanceId)); + } else { + image = QImage(newSize, QImage::Format_ARGB32); + image.fill(0xFFFFFFFF); + } + } *size = image.size(); return image; } -void StatesEditorImageProvider::setImage(const QString &id, const QImage &image) -{ - m_imageHash.insert(id, image); -} - -void StatesEditorImageProvider::removeImage(const QString &id) +void StatesEditorImageProvider::setNodeInstanceView(NodeInstanceView *nodeInstanceView) { - m_imageHash.remove(id); + m_nodeInstanceView = nodeInstanceView; } } diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h index 3b60d28964..8c8d2d6e00 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorimageprovider.h @@ -35,7 +35,8 @@ #define STATESEDITORIMAGEPROVIDER_H #include <QDeclarativeImageProvider> -#include <QHash> +#include <QWeakPointer> +#include"abstractview.h" namespace QmlDesigner { @@ -50,11 +51,10 @@ public: QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize); - void setImage(const QString &id, const QImage &image); - void removeImage(const QString &id); + void setNodeInstanceView(NodeInstanceView *nodeInstanceView); private: - QHash<QString, QImage> m_imageHash; + QWeakPointer<NodeInstanceView> m_nodeInstanceView; }; } diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp index 91eb6f8175..a85837b146 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp @@ -118,7 +118,15 @@ QVariant StatesEditorModel::data(const QModelIndex &index, int role) const } } - case StateImageSourceRole: return QString("image://qmldesigner_stateseditor/%1").arg(index.internalId()); + case StateImageSourceRole: { + static int randomNumber = 0; + randomNumber++; + if (index.row() == 0) { + return QString("image://qmldesigner_stateseditor/baseState-%1").arg(randomNumber); + } else { + return QString("image://qmldesigner_stateseditor/%1-%2").arg(index.internalId()).arg(randomNumber); + } + } case NodeId : return index.internalId(); } @@ -130,35 +138,34 @@ void StatesEditorModel::insertState(int stateIndex) { if (stateIndex >= 0) { - const int index = stateIndex + 1; - beginInsertRows(QModelIndex(), index, index); + const int updateIndex = stateIndex + 1; + beginInsertRows(QModelIndex(), updateIndex, updateIndex); endInsertRows(); - emit dataChanged(createIndex(index, 0), createIndex(index, 0)); + emit dataChanged(index(updateIndex, 0), index(updateIndex, 0)); emit countChanged(); } } -void StatesEditorModel::updateState(int stateIndex) +void StatesEditorModel::updateState(int updateIndex) { - if (stateIndex >= 0) { - const int index = stateIndex + 1; - - emit dataChanged(createIndex(index, 0), createIndex(index, 0)); + if (updateIndex >= 0) { + QModelIndex modelIndex = index(updateIndex, 0); + emit dataChanged(modelIndex, modelIndex); } } void StatesEditorModel::removeState(int stateIndex) { if (stateIndex >= 0) { - const int index = stateIndex + 1; - beginRemoveRows(QModelIndex(), index, index); + const int updateIndex = stateIndex + 1; + beginRemoveRows(QModelIndex(), updateIndex, updateIndex); endRemoveRows(); - emit dataChanged(createIndex(index, 0), createIndex(index, 0)); + emit dataChanged(index(updateIndex, 0), index(updateIndex, 0)); emit countChanged(); } } diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp index d1dc945388..b53c60b7ea 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorview.cpp @@ -48,10 +48,6 @@ #include <variantproperty.h> #include <nodelistproperty.h> -enum { - debug = false -}; - namespace QmlDesigner { /** @@ -228,6 +224,9 @@ void StatesEditorView::modelAttached(Model *model) Q_ASSERT(model); QmlModelView::modelAttached(model); + if (m_statesEditorWidget) + m_statesEditorWidget->setNodeInstanceView(nodeInstanceView()); + resetModel(); } @@ -252,7 +251,7 @@ void StatesEditorView::variantPropertiesChanged(const QList<VariantProperty> &pr if (property.name() == "name" && property.parentModelNode().hasParentProperty()) { NodeAbstractProperty parentProperty = property.parentModelNode().parentProperty(); if (parentProperty.name() == "states" && parentProperty.parentModelNode().isRootNode()) { - m_statesEditorModel->updateState(parentProperty.indexOf(property.parentModelNode())); + m_statesEditorModel->updateState(parentProperty.indexOf(property.parentModelNode()) + 1); } } } @@ -337,22 +336,17 @@ void StatesEditorView::otherPropertyChanged(const QmlObjectNode &qmlObjectNode, void StatesEditorView::customNotification(const AbstractView * view, const QString & identifier, const QList<ModelNode> & nodeList, const QList<QVariant> &imageList) { - if (debug) - qDebug() << __FUNCTION__; - - if (identifier == "__state preview updated__") { - if (nodeList.size() != imageList.size()) - return; - -// if (++m_updateCounter == INT_MAX) -// m_updateCounter = 0; - for (int i = 0; i < nodeList.size(); i++) { - QmlModelState modelState(nodeList.at(i)); + if (identifier == "__instance preview image changed__") { + foreach(const ModelNode &node, nodeList) { + if (node.isRootNode()) { + m_statesEditorModel->updateState(0); + } else { + int index = rootStateGroup().allStates().indexOf(QmlModelState(node)) + 1; + if (index > 0) + m_statesEditorModel->updateState(index); + } } - - // emit dataChanged(createIndex(i, 0), createIndex(i, 0)); - } else { QmlModelView::customNotification(view, identifier, nodeList, imageList); } @@ -360,8 +354,6 @@ void StatesEditorView::customNotification(const AbstractView * view, const QStri void StatesEditorView::scriptFunctionsChanged(const ModelNode &node, const QStringList &scriptFunctionList) { - if (debug) - qDebug() << __FUNCTION__; QmlModelView::scriptFunctionsChanged(node, scriptFunctionList); } diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp index 024f451180..e1e663c300 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.cpp @@ -72,14 +72,21 @@ void StatesEditorWidget::setCurrentStateInternalId(int internalId) m_declarativeView->rootObject()->setProperty("currentStateInternalId", internalId); } -StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel): - QWidget() +void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView) { - m_declarativeView = new QDeclarativeView(this); + m_imageProvider->setNodeInstanceView(nodeInstanceView); +} +StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel): + QWidget(), + m_declarativeView(new QDeclarativeView(this)), + m_statesEditorView(statesEditorView), + m_imageProvider(0) +{ + m_imageProvider = new Internal::StatesEditorImageProvider; + m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView()); m_declarativeView->engine()->addImageProvider( - QLatin1String("qmldesigner_stateseditor"), new Internal::StatesEditorImageProvider); - + QLatin1String("qmldesigner_stateseditor"), m_imageProvider); m_declarativeView->setAcceptDrops(false); diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h index 3562efe0c7..18e2ad5069 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditorwidget.h @@ -47,7 +47,11 @@ class Model; class ModelState; class StatesEditorModel; class StatesEditorView; +class NodeInstanceView; +namespace Internal { +class StatesEditorImageProvider; +} class StatesEditorWidget : public QWidget { @@ -61,10 +65,12 @@ public: int currentStateInternalId() const; void setCurrentStateInternalId(int internalId); + void setNodeInstanceView(NodeInstanceView *nodeInstanceView); private: QWeakPointer<QDeclarativeView> m_declarativeView; QWeakPointer<StatesEditorView> m_statesEditorView; + Internal::StatesEditorImageProvider *m_imageProvider; }; } diff --git a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h index 90f887d13f..a0b5d944fd 100644 --- a/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h +++ b/src/plugins/qmldesigner/designercore/include/nodeinstanceview.h @@ -43,6 +43,7 @@ #include <QHash> #include <QSet> +#include <QImage> #include <QWeakPointer> #include <QRectF> @@ -124,6 +125,8 @@ public: void statePreviewImagesChanged(const StatePreviewImageChangedCommand &command); void componentCompleted(const ComponentCompletedCommand &command); + QImage statePreviewImage(const ModelNode &stateNode) const; + private: // functions NodeInstance rootNodeInstance() const; @@ -170,9 +173,11 @@ private: //variables NodeInstance m_activeStateInstance; QHash<ModelNode, NodeInstance> m_nodeInstanceHash; + QHash<ModelNode, QImage> m_statePreviewImage; uint m_blockUpdates; QWeakPointer<NodeInstanceServerInterface> m_nodeInstanceServer; + QImage m_baseStatePreviewImage; }; } // namespace ProxyNodeInstanceView diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp index b3bdefa45a..5ab93591fc 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.cpp @@ -39,7 +39,7 @@ namespace QmlDesigner { NodeInstanceClientProxy::NodeInstanceClientProxy(QObject *parent) : QObject(parent), m_nodeInstanceServer(new NodeInstanceServer(this)), - m_baseStateNodeInstancePreview(new PreviewNodeInstanceServer(this)), + m_stateNodeInstancePreview(new PreviewNodeInstanceServer(this)), m_blockSize(0) { m_socket = new QLocalSocket(this); @@ -132,6 +132,11 @@ void NodeInstanceClientProxy::readDataStream() } } +NodeInstanceServerInterface *NodeInstanceClientProxy::stateNodeInstancePreview() const +{ + return m_stateNodeInstancePreview; +} + NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const { return m_nodeInstanceServer; @@ -140,51 +145,61 @@ NodeInstanceServerInterface *NodeInstanceClientProxy::nodeInstanceServer() const void NodeInstanceClientProxy::createInstances(const CreateInstancesCommand &command) { nodeInstanceServer()->createInstances(command); + stateNodeInstancePreview()->createInstances(command); } void NodeInstanceClientProxy::changeFileUrl(const ChangeFileUrlCommand &command) { nodeInstanceServer()->changeFileUrl(command); + stateNodeInstancePreview()->changeFileUrl(command); } void NodeInstanceClientProxy::createScene(const CreateSceneCommand &command) { nodeInstanceServer()->createScene(command); + stateNodeInstancePreview()->createScene(command); } void NodeInstanceClientProxy::clearScene(const ClearSceneCommand &command) { nodeInstanceServer()->clearScene(command); + stateNodeInstancePreview()->clearScene(command); } void NodeInstanceClientProxy::removeInstances(const RemoveInstancesCommand &command) { nodeInstanceServer()->removeInstances(command); + stateNodeInstancePreview()->removeInstances(command); } void NodeInstanceClientProxy::removeProperties(const RemovePropertiesCommand &command) { nodeInstanceServer()->removeProperties(command); + stateNodeInstancePreview()->removeProperties(command); } void NodeInstanceClientProxy::changePropertyBindings(const ChangeBindingsCommand &command) { nodeInstanceServer()->changePropertyBindings(command); + stateNodeInstancePreview()->changePropertyBindings(command); } void NodeInstanceClientProxy::changePropertyValues(const ChangeValuesCommand &command) { nodeInstanceServer()->changePropertyValues(command); + stateNodeInstancePreview()->changePropertyValues(command); } void NodeInstanceClientProxy::reparentInstances(const ReparentInstancesCommand &command) { nodeInstanceServer()->reparentInstances(command); + stateNodeInstancePreview()->reparentInstances(command); } void NodeInstanceClientProxy::changeIds(const ChangeIdsCommand &command) { nodeInstanceServer()->changeIds(command); + stateNodeInstancePreview()->changeIds(command); } void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command) @@ -195,11 +210,13 @@ void NodeInstanceClientProxy::changeState(const ChangeStateCommand &command) void NodeInstanceClientProxy::addImport(const AddImportCommand &command) { nodeInstanceServer()->addImport(command); + stateNodeInstancePreview()->addImport(command); } void NodeInstanceClientProxy::completeComponent(const CompleteComponentCommand &command) { nodeInstanceServer()->completeComponent(command); + stateNodeInstancePreview()->completeComponent(command); } void NodeInstanceClientProxy::dispatchCommand(const QVariant &command) diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h index a570dc4e39..a23e511517 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceclientproxy.h @@ -49,7 +49,7 @@ protected: void writeCommand(const QVariant &command); void dispatchCommand(const QVariant &command); NodeInstanceServerInterface *nodeInstanceServer() const; - NodeInstanceServerInterface *baseStateNodeInstancePreview() const; + NodeInstanceServerInterface *stateNodeInstancePreview() const; void createInstances(const CreateInstancesCommand &command); void changeFileUrl(const ChangeFileUrlCommand &command); @@ -71,8 +71,7 @@ private slots: private: QLocalSocket *m_socket; NodeInstanceServerInterface *m_nodeInstanceServer; - NodeInstanceServerInterface *m_baseStateNodeInstancePreview; - QHash<qint32, QWeakPointer<NodeInstanceServerInterface> > m_nodeInstancePreviewVector; + NodeInstanceServerInterface *m_stateNodeInstancePreview; quint32 m_blockSize; }; diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp index c85e0232bd..655736525b 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.cpp @@ -51,7 +51,9 @@ NodeInstanceServer::NodeInstanceServer(NodeInstanceClientInterface *nodeInstance m_childrenChangeEventFilter(new Internal::ChildrenChangeEventFilter(this)), m_nodeInstanceClient(nodeInstanceClient), m_timer(0), - m_slowRenderTimer(false) + m_renderTimerInterval(16), + m_slowRenderTimer(false), + m_slowRenderTimerInterval(1000) { m_importList.append("import Qt 4.7"); connect(m_childrenChangeEventFilter.data(), SIGNAL(childrenChanged(QObject*)), this, SLOT(emitParentChanged(QObject*))); @@ -123,13 +125,23 @@ bool NodeInstanceServer::hasInstanceForObject(QObject *object) const return m_objectInstanceHash.contains(object); } +void NodeInstanceServer::setRenderTimerInterval(int timerInterval) +{ + m_renderTimerInterval = timerInterval; +} + +void NodeInstanceServer::setSlowRenderTimerInterval(int timerInterval) +{ + m_slowRenderTimerInterval = timerInterval; +} + void NodeInstanceServer::startRenderTimer() { if (m_slowRenderTimer) stopRenderTimer(); if (m_timer == 0) - m_timer = startTimer(16); + m_timer = startTimer(m_renderTimerInterval); m_slowRenderTimer = false; } @@ -140,7 +152,7 @@ void NodeInstanceServer::slowDownRenderTimer() stopRenderTimer(); if (m_timer == 0) - m_timer = startTimer(1000); + m_timer = startTimer(m_slowRenderTimerInterval); m_slowRenderTimer = true; } @@ -789,6 +801,28 @@ void NodeInstanceServer::initializeDeclarativeView() #endif } +QImage NodeInstanceServer::renderPreviewImage() +{ + QSize size = rootNodeInstance().boundingRect().size().toSize(); + size.scale(100, 100, Qt::KeepAspectRatio); + + QImage image(size, QImage::Format_ARGB32); + image.fill(0xFFFFFFFF); + + if (m_declarativeView) { + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setRenderHint(QPainter::TextAntialiasing, true); + painter.setRenderHint(QPainter::SmoothPixmapTransform, true); + painter.setRenderHint(QPainter::HighQualityAntialiasing, true); + painter.setRenderHint(QPainter::NonCosmeticDefaultPen, true); + + m_declarativeView->scene()->render(&painter, image.rect(), rootNodeInstance().boundingRect().toRect(), Qt::IgnoreAspectRatio); + } + + return image; +} + QList<ServerNodeInstance> NodeInstanceServer::setupScene(const CreateSceneCommand &command) { if (!command.fileUrl().isEmpty()) diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h index c209a915a7..b75ceaa653 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceserver.h @@ -105,7 +105,7 @@ protected: void timerEvent(QTimerEvent *); bool nonInstanceChildIsDirty(QGraphicsObject *graphicsObject) const; - void findItemChangesAndSendChangeCommands(); + virtual void findItemChangesAndSendChangeCommands(); void resetAllItems(); ValuesChangedCommand createValuesChangedCommand(const QList<ServerNodeInstance> &instanceList) const; @@ -121,9 +121,14 @@ protected: void startRenderTimer(); void slowDownRenderTimer(); void stopRenderTimer(); + void setRenderTimerInterval(int timerInterval); + void setSlowRenderTimerInterval(int timerInterval); + void initializeDeclarativeView(); QList<ServerNodeInstance> setupScene(const CreateSceneCommand &command); + QImage renderPreviewImage(); + private: ServerNodeInstance m_rootNodeInstance; ServerNodeInstance m_activeStateInstance; @@ -136,7 +141,9 @@ private: QUrl m_fileUrl; NodeInstanceClientInterface *m_nodeInstanceClient; int m_timer; + int m_renderTimerInterval; bool m_slowRenderTimer; + int m_slowRenderTimerInterval; QVector<InstancePropertyPair> m_changedPropertyList; QStringList m_importList; QSet<ServerNodeInstance> m_dirtyInstanceSet; diff --git a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp index 0430cf46f7..016599ad89 100644 --- a/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp +++ b/src/plugins/qmldesigner/designercore/instances/nodeinstanceview.cpp @@ -113,8 +113,10 @@ d too. \see ~NodeInstanceView setRenderOffScreen */ NodeInstanceView::NodeInstanceView(QObject *parent) - : AbstractView(parent) + : AbstractView(parent), + m_baseStatePreviewImage(QSize(100, 100), QImage::Format_ARGB32) { + m_baseStatePreviewImage.fill(0xFFFFFF); } @@ -891,7 +893,7 @@ void NodeInstanceView::valuesChanged(const ValuesChangedCommand &command) void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command) { - if (!model()) + if (!model()) return; QSet<ModelNode> renderImageChangeSet; @@ -907,7 +909,7 @@ void NodeInstanceView::pixmapChanged(const PixmapChangedCommand &command) } if (!renderImageChangeSet.isEmpty()) - emitCustomNotification("__instance render pixmap changed__", renderImageChangeSet.toList()); + emitCustomNotification("__instance render pixmap changed__", renderImageChangeSet.toList()); } void NodeInstanceView::informationChanged(const InformationChangedCommand &command) @@ -931,9 +933,34 @@ void NodeInstanceView::informationChanged(const InformationChangedCommand &comma emitCustomNotification("__instance information changed__", informationChangedList); } -void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedCommand &/*command*/) +QImage NodeInstanceView::statePreviewImage(const ModelNode &stateNode) const { + if (stateNode == rootModelNode()) + return m_baseStatePreviewImage; + + return m_statePreviewImage.value(stateNode); +} +void NodeInstanceView::statePreviewImagesChanged(const StatePreviewImageChangedCommand &command) +{ + if (!model()) + return; + + QList<ModelNode> previewImageChangeList; + + foreach (const ImageContainer &container, command.previews()) { + if (container.instanceId() == 0) { + m_baseStatePreviewImage = container.image(); + previewImageChangeList.append(rootModelNode()); + } else if (hasInstanceForId(container.instanceId())) { + ModelNode node = modelNodeForInternalId(container.instanceId()); + m_statePreviewImage.insert(node, container.image()); + previewImageChangeList.append(node); + } + } + + if (!previewImageChangeList.isEmpty()) + emitCustomNotification("__instance preview image changed__", previewImageChangeList); } void NodeInstanceView::componentCompleted(const ComponentCompletedCommand &command) diff --git a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp index 162a1bf37c..bb4000d658 100644 --- a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.cpp @@ -616,6 +616,11 @@ QList<ServerNodeInstance> ObjectNodeInstance::childItems() const return QList<ServerNodeInstance>(); } +QList<ServerNodeInstance> ObjectNodeInstance::stateInstances() const +{ + return QList<ServerNodeInstance>(); +} + void ObjectNodeInstance::setDeleteHeldInstance(bool deleteInstance) { m_deleteHeldInstance = deleteInstance; diff --git a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h index 262e0ca8e6..090643e53c 100644 --- a/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/objectnodeinstance.h @@ -174,6 +174,7 @@ public: virtual void doComponentComplete(); + virtual QList<ServerNodeInstance> stateInstances() const; protected: void doResetProperty(const QString &propertyName); diff --git a/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.cpp b/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.cpp index ea258bca41..a247cc8721 100644 --- a/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.cpp +++ b/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.cpp @@ -1,10 +1,48 @@ #include "previewnodeinstanceserver.h" +#include "nodeinstanceclientinterface.h" +#include "statepreviewimagechangedcommand.h" namespace QmlDesigner { PreviewNodeInstanceServer::PreviewNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) : NodeInstanceServer(nodeInstanceClient) { + setRenderTimerInterval(200); + setSlowRenderTimerInterval(10000); } +void PreviewNodeInstanceServer::createScene(const CreateSceneCommand &command) +{ + initializeDeclarativeView(); + setupScene(command); + + startRenderTimer(); +} + +void PreviewNodeInstanceServer::findItemChangesAndSendChangeCommands() +{ + static bool inFunction = false; + + if (!inFunction && nodeInstanceClient()->bytesToWrite() < 10000) { + inFunction = true; + QVector<ImageContainer> imageContainerVector; + imageContainerVector.append(ImageContainer(0, renderPreviewImage())); + + foreach (ServerNodeInstance instance, rootNodeInstance().stateInstances()) { + instance.activateState(); + imageContainerVector.append(ImageContainer(instance.instanceId(), renderPreviewImage())); + instance.deactivateState(); + } + + nodeInstanceClient()->statePreviewImagesChanged(StatePreviewImageChangedCommand(imageContainerVector)); + + slowDownRenderTimer(); + inFunction = false; + } +} + +void PreviewNodeInstanceServer::changeState(const ChangeStateCommand &/*command*/) +{ + +} } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.h b/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.h index d5eba79629..11c05595e5 100644 --- a/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.h +++ b/src/plugins/qmldesigner/designercore/instances/previewnodeinstanceserver.h @@ -10,10 +10,14 @@ class PreviewNodeInstanceServer : public NodeInstanceServer Q_OBJECT public: explicit PreviewNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient); + void createScene(const CreateSceneCommand &command); + void changeState(const ChangeStateCommand &command); -signals: +protected: + void findItemChangesAndSendChangeCommands(); -public slots: +private: + ServerNodeInstance m_actualState; }; diff --git a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp index 72f8e0e395..6cb732c639 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.cpp @@ -46,6 +46,7 @@ #include <private/qdeclarativeproperty_p.h> #include <private/qdeclarativerectangle_p.h> #include <private/qdeclarativepositioners_p.h> +#include <private/qdeclarativestategroup_p.h> #include <cmath> @@ -493,6 +494,19 @@ QPair<QString, ServerNodeInstance> QmlGraphicsItemNodeInstance::anchor(const QSt } } +QList<ServerNodeInstance> QmlGraphicsItemNodeInstance::stateInstances() const +{ + QList<ServerNodeInstance> instanceList; + QList<QDeclarativeState *> stateList = QDeclarativeItemPrivate::get(qmlGraphicsItem())->_states()->states(); + foreach(QDeclarativeState *state, stateList) + { + if (state && nodeInstanceServer()->hasInstanceForObject(state)) + instanceList.append(nodeInstanceServer()->instanceForObject(state)); + } + + return instanceList; +} + bool QmlGraphicsItemNodeInstance::hasAnchor(const QString &name) const { if (!isValidAnchorName(name)) diff --git a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h index 19c2809a03..07dba86037 100644 --- a/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/qmlgraphicsitemnodeinstance.h @@ -77,6 +77,9 @@ public: bool isResizable() const; void setResizable(bool resizeable); + + QList<ServerNodeInstance> stateInstances() const; + protected: QmlGraphicsItemNodeInstance(QDeclarativeItem *item); QDeclarativeItem *qmlGraphicsItem() const; diff --git a/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp index 496b87d2b8..f08987dea9 100644 --- a/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp +++ b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.cpp @@ -592,6 +592,11 @@ QObject* ServerNodeInstance::testHandle() const return internalObject(); } +QList<ServerNodeInstance> ServerNodeInstance::stateInstances() const +{ + return m_nodeInstance->stateInstances(); +} + Internal::ObjectNodeInstance::Pointer ServerNodeInstance::internalInstance() const { return m_nodeInstance; diff --git a/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h index 802e30f01c..675ee94a24 100644 --- a/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h +++ b/src/plugins/qmldesigner/designercore/instances/servernodeinstance.h @@ -53,6 +53,7 @@ QT_END_NAMESPACE namespace QmlDesigner { class NodeInstanceServer; +class PreviewNodeInstanceServer; class InstanceContainer; namespace Internal { @@ -66,6 +67,7 @@ namespace Internal { class CORESHARED_EXPORT ServerNodeInstance { friend CORESHARED_EXPORT class NodeInstanceServer; + friend CORESHARED_EXPORT class PreviewNodeInstanceServer; friend class QHash<qint32, ServerNodeInstance>; friend CORESHARED_EXPORT uint qHash(const ServerNodeInstance &instance); friend CORESHARED_EXPORT bool operator==(const ServerNodeInstance &first, const ServerNodeInstance &second); @@ -145,6 +147,8 @@ public: QObject* testHandle() const; QSharedPointer<Internal::ObjectNodeInstance> internalInstance() const; + QList<ServerNodeInstance> stateInstances() const; + private: // functions ServerNodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance); |