2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2011-07-06 15:48:52 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-07-06 15:48:52 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-06-09 15:50:48 +02:00
|
|
|
|
|
|
|
#include "qt5previewnodeinstanceserver.h"
|
|
|
|
|
|
|
|
#include "nodeinstanceclientinterface.h"
|
|
|
|
#include "statepreviewimagechangedcommand.h"
|
|
|
|
#include "createscenecommand.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "removesharedmemorycommand.h"
|
2012-10-10 17:14:31 +02:00
|
|
|
#include <QQuickView>
|
2012-09-19 15:57:22 +02:00
|
|
|
#include <QQuickItem>
|
2011-08-31 18:27:41 +02:00
|
|
|
#include <designersupport.h>
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
Qt5PreviewNodeInstanceServer::Qt5PreviewNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) :
|
|
|
|
Qt5NodeInstanceServer(nodeInstanceClient)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Qt5PreviewNodeInstanceServer::createScene(const CreateSceneCommand &command)
|
|
|
|
{
|
|
|
|
initializeView(command.imports());
|
|
|
|
setupScene(command);
|
|
|
|
|
|
|
|
startRenderTimer();
|
|
|
|
}
|
|
|
|
void Qt5PreviewNodeInstanceServer::startRenderTimer()
|
|
|
|
{
|
|
|
|
if (timerId() != 0)
|
|
|
|
killTimer(timerId());
|
|
|
|
|
|
|
|
int timerId = startTimer(renderTimerInterval());
|
|
|
|
|
|
|
|
setTimerId(timerId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Qt5PreviewNodeInstanceServer::collectItemChangesAndSendChangeCommands()
|
|
|
|
{
|
|
|
|
static bool inFunction = false;
|
|
|
|
|
2013-04-15 13:28:48 +02:00
|
|
|
if (!rootNodeInstance().holdsQuickItem())
|
2012-10-15 14:53:43 +02:00
|
|
|
return;
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
if (!inFunction && nodeInstanceClient()->bytesToWrite() < 10000) {
|
|
|
|
inFunction = true;
|
2012-10-16 16:32:54 +02:00
|
|
|
|
|
|
|
DesignerSupport::polishItems(quickView());
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
QVector<ImageContainer> imageContainerVector;
|
2012-09-19 15:57:22 +02:00
|
|
|
imageContainerVector.append(ImageContainer(0, renderPreviewImage(), -1));
|
2011-06-09 15:50:48 +02:00
|
|
|
|
|
|
|
foreach (ServerNodeInstance instance, rootNodeInstance().stateInstances()) {
|
|
|
|
instance.activateState();
|
2012-10-15 14:56:53 +02:00
|
|
|
QImage previewImage = renderPreviewImage();
|
|
|
|
if (!previewImage.isNull())
|
|
|
|
imageContainerVector.append(ImageContainer(instance.instanceId(), renderPreviewImage(), instance.instanceId()));
|
2011-06-09 15:50:48 +02:00
|
|
|
instance.deactivateState();
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeInstanceClient()->statePreviewImagesChanged(StatePreviewImageChangedCommand(imageContainerVector));
|
|
|
|
|
|
|
|
slowDownRenderTimer();
|
|
|
|
inFunction = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Qt5PreviewNodeInstanceServer::changeState(const ChangeStateCommand &/*command*/)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
static void updateDirtyNodeRecursive(QQuickItem *parentItem)
|
2011-08-31 18:21:24 +02:00
|
|
|
{
|
2012-09-19 15:57:22 +02:00
|
|
|
foreach (QQuickItem *childItem, parentItem->childItems())
|
2011-08-31 18:21:24 +02:00
|
|
|
updateDirtyNodeRecursive(childItem);
|
|
|
|
|
|
|
|
DesignerSupport::updateDirtyNode(parentItem);
|
|
|
|
}
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
QImage Qt5PreviewNodeInstanceServer::renderPreviewImage()
|
|
|
|
{
|
2013-04-15 13:28:48 +02:00
|
|
|
rootNodeInstance().updateDirtyNodeRecursive();
|
2011-08-31 18:21:24 +02:00
|
|
|
|
|
|
|
QRectF boundingRect = rootNodeInstance().boundingRect();
|
|
|
|
|
|
|
|
QSize previewImageSize = boundingRect.size().toSize();
|
|
|
|
previewImageSize.scale(QSize(100, 100), Qt::KeepAspectRatio);
|
|
|
|
|
2013-04-15 13:28:48 +02:00
|
|
|
QImage previewImage = rootNodeInstance().renderPreviewImage(previewImageSize);
|
2011-06-09 15:50:48 +02:00
|
|
|
|
2011-08-31 18:21:24 +02:00
|
|
|
previewImage = previewImage.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
2011-06-09 15:50:48 +02:00
|
|
|
|
2011-08-31 18:21:24 +02:00
|
|
|
return previewImage;
|
2011-06-09 15:50:48 +02:00
|
|
|
}
|
|
|
|
|
2012-09-11 15:11:34 +02:00
|
|
|
void QmlDesigner::Qt5PreviewNodeInstanceServer::removeSharedMemory(const QmlDesigner::RemoveSharedMemoryCommand &command)
|
|
|
|
{
|
|
|
|
if (command.typeName() == "Image")
|
2012-09-19 15:57:22 +02:00
|
|
|
ImageContainer::removeSharedMemorys(command.keyNumbers());
|
2012-09-11 15:11:34 +02:00
|
|
|
}
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
} // namespace QmlDesigner
|