2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2016-01-15 14:59:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:59:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-06-09 15:50:48 +02:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:59:14 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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"
|
|
|
|
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "changepreviewimagesizecommand.h"
|
2011-06-09 15:50:48 +02:00
|
|
|
#include "createscenecommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "nodeinstanceclientinterface.h"
|
2012-09-19 15:57:22 +02:00
|
|
|
#include "removesharedmemorycommand.h"
|
2020-05-07 14:13:21 +02:00
|
|
|
#include "statepreviewimagechangedcommand.h"
|
|
|
|
|
2012-10-10 17:14:31 +02:00
|
|
|
#include <QQuickView>
|
2012-09-19 15:57:22 +02:00
|
|
|
#include <QQuickItem>
|
2015-07-14 12:06:07 +02:00
|
|
|
#include <designersupportdelegate.h>
|
2011-08-31 18:27:41 +02:00
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
|
|
|
Qt5PreviewNodeInstanceServer::Qt5PreviewNodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) :
|
|
|
|
Qt5NodeInstanceServer(nodeInstanceClient)
|
|
|
|
{
|
2014-07-07 14:21:02 +02:00
|
|
|
setSlowRenderTimerInterval(100000000);
|
|
|
|
setRenderTimerInterval(100);
|
2011-06-09 15:50:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Qt5PreviewNodeInstanceServer::createScene(const CreateSceneCommand &command)
|
|
|
|
{
|
2014-09-25 12:57:57 +02:00
|
|
|
initializeView();
|
2021-01-25 17:33:05 +02:00
|
|
|
registerFonts(command.resourceUrl);
|
2020-11-09 16:35:00 +01:00
|
|
|
setTranslationLanguage(command.language);
|
2011-06-09 15:50:48 +02:00
|
|
|
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-18 18:22:15 +02:00
|
|
|
if (!rootNodeInstance().holdsGraphical())
|
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
|
|
|
|
2020-11-23 17:47:07 +02:00
|
|
|
DesignerSupport::polishItems(quickWindow());
|
2012-10-16 16:32:54 +02:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-07-27 18:14:33 +02:00
|
|
|
nodeInstanceClient()->statePreviewImagesChanged(
|
|
|
|
StatePreviewImageChangedCommand(imageContainerVector));
|
2011-06-09 15:50:48 +02:00
|
|
|
|
|
|
|
slowDownRenderTimer();
|
2020-06-17 15:54:41 +03:00
|
|
|
handleExtraRender();
|
2011-06-09 15:50:48 +02:00
|
|
|
inFunction = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Qt5PreviewNodeInstanceServer::changeState(const ChangeStateCommand &/*command*/)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage Qt5PreviewNodeInstanceServer::renderPreviewImage()
|
|
|
|
{
|
2021-10-01 12:27:04 +03:00
|
|
|
// Ensure the state preview image is always clipped properly to root item dimensions
|
|
|
|
if (auto rootItem = qobject_cast<QQuickItem *>(rootNodeInstance().internalObject()))
|
|
|
|
rootItem->setClip(true);
|
|
|
|
|
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();
|
2020-05-07 14:13:21 +02:00
|
|
|
|
2020-07-17 11:17:17 +02:00
|
|
|
if (m_previewSize.isValid() && !m_previewSize.isNull())
|
2020-05-07 14:13:21 +02:00
|
|
|
previewImageSize.scale(m_previewSize, Qt::KeepAspectRatio);
|
2011-08-31 18:21:24 +02:00
|
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-07 14:13:21 +02:00
|
|
|
void Qt5PreviewNodeInstanceServer::changePreviewImageSize(
|
|
|
|
const ChangePreviewImageSizeCommand &command)
|
|
|
|
{
|
|
|
|
m_previewSize = command.size;
|
|
|
|
|
|
|
|
collectItemChangesAndSendChangeCommands();
|
|
|
|
}
|
|
|
|
|
2022-02-02 17:56:16 +02:00
|
|
|
bool Qt5PreviewNodeInstanceServer::isPreviewServer() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-09 15:50:48 +02:00
|
|
|
} // namespace QmlDesigner
|