| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2011-07-06 15:48:52 +00:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2011-07-06 15:48:52 +00:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2011-07-06 15:48:52 +00: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-07-06 15:48:52 +00: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-07-06 15:48:52 +00:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "qt5nodeinstanceserver.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 14:54:00 +02:00
										 |  |  | #include <QSurfaceFormat>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-08 17:02:20 +02:00
										 |  |  | #include <QQmlFileSelector>
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | #include <QQuickItem>
 | 
					
						
							|  |  |  | #include <QQuickView>
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 12:06:07 +02:00
										 |  |  | #include <designersupportdelegate.h>
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | #include <addimportcontainer.h>
 | 
					
						
							|  |  |  | #include <createscenecommand.h>
 | 
					
						
							| 
									
										
										
										
											2013-06-06 16:33:04 +02:00
										 |  |  | #include <reparentinstancescommand.h>
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-27 18:52:06 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include <QOpenGLContext>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Qt5NodeInstanceServer::Qt5NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient) | 
					
						
							| 
									
										
										
										
											2014-10-16 13:56:47 +02:00
										 |  |  |     : NodeInstanceServer(nodeInstanceClient) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-15 11:55:47 +01:00
										 |  |  |     DesignerSupport::activateDesignerMode(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Qt5NodeInstanceServer::~Qt5NodeInstanceServer() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     delete quickView(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QQuickView *Qt5NodeInstanceServer::quickView() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return m_quickView.data(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-25 12:57:57 +02:00
										 |  |  | void Qt5NodeInstanceServer::initializeView() | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     Q_ASSERT(!quickView()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_quickView = new QQuickView; | 
					
						
							| 
									
										
										
										
											2019-06-11 14:54:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QSurfaceFormat surfaceFormat = m_quickView->requestedFormat(); | 
					
						
							|  |  |  |     surfaceFormat.setVersion(4, 1); | 
					
						
							|  |  |  |     surfaceFormat.setProfile(QSurfaceFormat::CoreProfile); | 
					
						
							|  |  |  |     m_quickView->setFormat(surfaceFormat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 17:14:31 +02:00
										 |  |  |     DesignerSupport::createOpenGLContext(m_quickView.data()); | 
					
						
							| 
									
										
										
										
											2019-04-08 17:02:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-14 15:38:00 +02:00
										 |  |  |     if (qEnvironmentVariableIsSet("QMLDESIGNER_QUICK3D_MODE") | 
					
						
							|  |  |  |         && QCoreApplication::arguments().at(2) == "editormode") { | 
					
						
							|  |  |  |         /* In '3d editormode' we do not use the DesignerWindowManager
 | 
					
						
							| 
									
										
										
										
											2019-09-27 18:52:06 +02:00
										 |  |  |          * and since we do not show the QQuickView we have to manually create the OpenGL context */ | 
					
						
							|  |  |  |         auto context = new QOpenGLContext(m_quickView); | 
					
						
							|  |  |  |         context->setFormat(surfaceFormat); | 
					
						
							|  |  |  |         context->create(); | 
					
						
							|  |  |  |         if (!context->makeCurrent(m_quickView)) | 
					
						
							|  |  |  |             qWarning("QOpenGLContext: makeCurrent() failed..."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-08 17:02:20 +02:00
										 |  |  |     if (qEnvironmentVariableIsSet("QML_FILE_SELECTORS")) { | 
					
						
							|  |  |  |         QQmlFileSelector *fileSelector = new QQmlFileSelector(engine(), engine()); | 
					
						
							|  |  |  |         QStringList customSelectors = QString::fromUtf8(qgetenv("QML_FILE_SELECTORS")).split(","); | 
					
						
							|  |  |  |         fileSelector->setExtraSelectors(customSelectors); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QQmlView *Qt5NodeInstanceServer::declarativeView() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-31 17:21:41 +02:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QQmlEngine *Qt5NodeInstanceServer::engine() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (quickView()) | 
					
						
							|  |  |  |         return quickView()->engine(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-31 17:21:41 +02:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Qt5NodeInstanceServer::resizeCanvasSizeToRootItemSize() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Qt5NodeInstanceServer::resetAllItems() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     foreach (QQuickItem *item, allItems()) | 
					
						
							| 
									
										
										
										
											2011-06-21 15:05:15 +02:00
										 |  |  |         DesignerSupport::resetDirty(item); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-09 14:50:13 +01:00
										 |  |  | void Qt5NodeInstanceServer::setupScene(const CreateSceneCommand &command) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-09-29 15:30:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     setupMockupTypes(command.mockupTypes()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     setupFileUrl(command.fileUrl()); | 
					
						
							| 
									
										
										
										
											2015-03-10 11:46:27 +01:00
										 |  |  |     setupImports(command.imports()); | 
					
						
							| 
									
										
										
										
											2011-07-06 14:43:24 +02:00
										 |  |  |     setupDummyData(command.fileUrl()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-09 14:50:13 +01:00
										 |  |  |     setupInstances(command); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     quickView()->resize(rootNodeInstance().boundingRect().size().toSize()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QList<QQuickItem*> subItems(QQuickItem *parentItem) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QList<QQuickItem*> itemList; | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     itemList.append(parentItem->childItems()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     foreach (QQuickItem *childItem, parentItem->childItems()) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         itemList.append(subItems(childItem)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return itemList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QList<QQuickItem*> Qt5NodeInstanceServer::allItems() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-16 12:33:50 +02:00
										 |  |  |     if (rootNodeInstance().isValid()) | 
					
						
							|  |  |  |         return rootNodeInstance().allItemsRecursive(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 12:33:50 +02:00
										 |  |  |     return QList<QQuickItem*>(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Qt5NodeInstanceServer::refreshBindings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DesignerSupport::refreshExpressions(context()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-16 13:56:47 +02:00
										 |  |  | DesignerSupport *Qt5NodeInstanceServer::designerSupport() | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-10-16 13:56:47 +02:00
										 |  |  |     return &m_designerSupport; | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Qt5NodeInstanceServer::createScene(const CreateSceneCommand &command) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     NodeInstanceServer::createScene(command); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void Qt5NodeInstanceServer::clearScene(const ClearSceneCommand &command) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-11 13:32:27 +02:00
										 |  |  |     NodeInstanceServer::clearScene(command); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 16:33:04 +02:00
										 |  |  | void Qt5NodeInstanceServer::reparentInstances(const ReparentInstancesCommand &command) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     NodeInstanceServer::reparentInstances(command.reparentInstances()); | 
					
						
							|  |  |  |     startRenderTimer(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } // QmlDesigner
 |