| 
									
										
										
										
											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.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-25 17:05:00 +02:00
										 |  |  | #include "quickitemnodeinstance.h"
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "qt5nodeinstanceserver.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | #include <QQmlExpression>
 | 
					
						
							|  |  |  | #include <QQuickView>
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | #include <cmath>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:19:58 +01:00
										 |  |  | #include <private/qquicktextinput_p.h>
 | 
					
						
							|  |  |  | #include <private/qquicktextedit_p.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | #include <QHash>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-06 13:42:46 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2011-06-21 15:05:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::s_createEffectItem = false; | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QuickItemNodeInstance::QuickItemNodeInstance(QQuickItem *item) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |    : ObjectNodeInstance(item), | 
					
						
							|  |  |  |      m_hasHeight(false), | 
					
						
							|  |  |  |      m_hasWidth(false), | 
					
						
							|  |  |  |      m_isResizable(true), | 
					
						
							|  |  |  |      m_hasContent(true), | 
					
						
							|  |  |  |      m_isMovable(true), | 
					
						
							|  |  |  |      m_x(0.0), | 
					
						
							|  |  |  |      m_y(0.0), | 
					
						
							|  |  |  |      m_width(0.0), | 
					
						
							|  |  |  |      m_height(0.0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QuickItemNodeInstance::~QuickItemNodeInstance() | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (quickItem()) | 
					
						
							|  |  |  |         designerSupport()->derefFromEffectItem(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::hasContent() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-22 16:07:17 +02:00
										 |  |  |     if (m_hasContent) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return childItemsHaveContent(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QList<ServerNodeInstance> QuickItemNodeInstance::childItems() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QList<ServerNodeInstance> instanceList; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     foreach (QQuickItem *childItem, quickItem()->childItems()) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) { | 
					
						
							|  |  |  |             instanceList.append(nodeInstanceServer()->instanceForObject(childItem)); | 
					
						
							|  |  |  |         } else { //there might be an item in between the parent instance
 | 
					
						
							|  |  |  |                  //and the child instance.
 | 
					
						
							|  |  |  |                  //Popular example is flickable which has a viewport item between
 | 
					
						
							|  |  |  |                  //the flickable item and the flickable children
 | 
					
						
							|  |  |  |             instanceList.append(childItemsForChild(childItem)); //In such a case we go deeper inside the item and
 | 
					
						
							|  |  |  |                                                            //search for child items with instances.
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return instanceList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QList<ServerNodeInstance> QuickItemNodeInstance::childItemsForChild(QQuickItem *childItem) const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QList<ServerNodeInstance> instanceList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (childItem) { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         foreach (QQuickItem *childItem, childItem->childItems()) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         { | 
					
						
							|  |  |  |             if (childItem && nodeInstanceServer()->hasInstanceForObject(childItem)) { | 
					
						
							|  |  |  |                 instanceList.append(nodeInstanceServer()->instanceForObject(childItem)); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 instanceList.append(childItemsForChild(childItem)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return instanceList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::setHasContent(bool hasContent) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_hasContent = hasContent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 16:07:17 +02:00
										 |  |  | bool QuickItemNodeInstance::anyItemHasContent(QQuickItem *quickItem) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-22 16:07:17 +02:00
										 |  |  |     if (quickItem->flags().testFlag(QQuickItem::ItemHasContents)) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 16:07:17 +02:00
										 |  |  |     foreach (QQuickItem *childItem, quickItem->childItems()) { | 
					
						
							|  |  |  |         if (anyItemHasContent(childItem)) | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool QuickItemNodeInstance::childItemsHaveContent(QQuickItem *quickItem) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     foreach (QQuickItem *childItem, quickItem->childItems()) { | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         if (anyItemHasContent(childItem)) | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QPointF QuickItemNodeInstance::position() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-08 21:26:29 +02:00
										 |  |  |     return quickItem()->position(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 19:18:50 +02:00
										 |  |  | static QTransform transformForItem(QQuickItem *item, NodeInstanceServer *nodeInstanceServer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTransform toParentTransform = DesignerSupport::parentTransform(item); | 
					
						
							|  |  |  |     if (item->parentItem() && !nodeInstanceServer->hasInstanceForObject(item->parentItem())) | 
					
						
							|  |  |  |         return transformForItem(item->parentItem(), nodeInstanceServer) * toParentTransform; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return toParentTransform; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QTransform QuickItemNodeInstance::transform() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-22 19:18:50 +02:00
										 |  |  |     return transformForItem(quickItem(), nodeInstanceServer()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QTransform QuickItemNodeInstance::customTransform() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return QTransform(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QTransform QuickItemNodeInstance::sceneTransform() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-25 14:02:38 +02:00
										 |  |  |     return DesignerSupport::windowTransform(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | double QuickItemNodeInstance::rotation() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return quickItem()->rotation(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | double QuickItemNodeInstance::scale() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return quickItem()->scale(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QPointF QuickItemNodeInstance::transformOriginPoint() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return quickItem()->transformOriginPoint(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | double QuickItemNodeInstance::zValue() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return quickItem()->z(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | double QuickItemNodeInstance::opacity() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return quickItem()->opacity(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QObject *QuickItemNodeInstance::parent() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (!quickItem() || !quickItem()->parentItem()) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return quickItem()->parentItem(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::equalQuickItem(QQuickItem *item) const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return item == quickItem(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::updateDirtyNodeRecursive(QQuickItem *parentItem) const | 
					
						
							| 
									
										
										
										
											2011-08-29 20:55:49 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     foreach (QQuickItem *childItem, parentItem->childItems()) { | 
					
						
							| 
									
										
										
										
											2011-08-29 20:55:49 +02:00
										 |  |  |         if (!nodeInstanceServer()->hasInstanceForObject(childItem)) | 
					
						
							|  |  |  |             updateDirtyNodeRecursive(childItem); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     DesignerSupport::updateDirtyNode(parentItem); | 
					
						
							| 
									
										
										
										
											2011-08-29 20:55:49 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-15 13:28:48 +02:00
										 |  |  | void QuickItemNodeInstance::updateAllDirtyNodeRecursive(QQuickItem *parentItem) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     foreach (QQuickItem *childItem, parentItem->childItems()) | 
					
						
							|  |  |  |             updateDirtyNodeRecursive(childItem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DesignerSupport::updateDirtyNode(parentItem); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QImage QuickItemNodeInstance::renderImage() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     updateDirtyNodeRecursive(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-08-29 20:55:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QRectF boundingRect = boundingRectWithStepChilds(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QImage renderImage = designerSupport()->renderImageForItem(quickItem(), boundingRect, boundingRect.size().toSize()); | 
					
						
							| 
									
										
										
										
											2011-08-25 20:51:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  |     renderImage = renderImage.convertToFormat(QImage::Format_ARGB32_Premultiplied); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return renderImage; | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-15 13:28:48 +02:00
										 |  |  | QImage QuickItemNodeInstance::renderPreviewImage(const QSize &previewImageSize) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QRectF previewItemBoundingRect = boundingRect(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (previewItemBoundingRect.isValid() && quickItem()) | 
					
						
							|  |  |  |         return designerSupport()->renderImageForItem(quickItem(), previewItemBoundingRect, previewImageSize); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QImage(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::isMovable() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-25 20:51:29 +02:00
										 |  |  |     if (isRootNodeInstance()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return m_isMovable && quickItem() && quickItem()->parentItem(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::setMovable(bool movable) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_isMovable = movable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QuickItemNodeInstance::Pointer QuickItemNodeInstance::create(QObject *object) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QQuickItem *quickItem = qobject_cast<QQuickItem*>(object); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     Q_ASSERT(quickItem); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     Pointer instance(new QuickItemNodeInstance(quickItem)); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     instance->setHasContent(anyItemHasContent(quickItem)); | 
					
						
							|  |  |  |     quickItem->setFlag(QQuickItem::ItemHasContents, true); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     static_cast<QQmlParserStatus*>(quickItem)->classBegin(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 20:51:29 +02:00
										 |  |  |     instance->populateResetHashes(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return instance; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-21 15:19:58 +01:00
										 |  |  | static void disableTextCursor(QQuickItem *item) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     foreach (QQuickItem *childItem, item->childItems()) | 
					
						
							|  |  |  |         disableTextCursor(childItem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(item); | 
					
						
							|  |  |  |     if (textInput) | 
					
						
							|  |  |  |         textInput->setCursorVisible(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit*>(item); | 
					
						
							|  |  |  |     if (textEdit) | 
					
						
							|  |  |  |         textEdit->setCursorVisible(false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-21 15:05:15 +02:00
										 |  |  |     if (instanceId() == 0) { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         DesignerSupport::setRootItem(nodeInstanceServer()->quickView(), quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-21 15:05:15 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         quickItem()->setParentItem(qobject_cast<QQuickItem*>(nodeInstanceServer()->quickView()->rootObject())); | 
					
						
							| 
									
										
										
										
											2011-06-21 15:05:15 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  |     if (s_createEffectItem || instanceId() == 0) | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         designerSupport()->refFromEffectItem(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     ObjectNodeInstance::initialize(objectNodeInstance); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     quickItem()->update(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::isQuickItem() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QSizeF QuickItemNodeInstance::size() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-29 19:34:07 +02:00
										 |  |  |     double width; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (DesignerSupport::isValidWidth(quickItem())) { | 
					
						
							|  |  |  |         width = quickItem()->width(); | 
					
						
							| 
									
										
										
										
											2011-06-29 19:34:07 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         width = quickItem()->implicitWidth(); | 
					
						
							| 
									
										
										
										
											2011-06-29 19:34:07 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     double height; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (DesignerSupport::isValidHeight(quickItem())) { | 
					
						
							|  |  |  |         height = quickItem()->height(); | 
					
						
							| 
									
										
										
										
											2011-06-29 19:34:07 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         height = quickItem()->implicitHeight(); | 
					
						
							| 
									
										
										
										
											2011-06-29 19:34:07 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QSizeF(width, height); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 20:51:29 +02:00
										 |  |  | static inline bool isRectangleSane(const QRectF &rect) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return rect.isValid() && (rect.width() < 10000) && (rect.height() < 10000); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-06-28 16:24:53 +02:00
										 |  |  |     QRectF boundingRect = parentItem->boundingRect(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     foreach (QQuickItem *childItem, parentItem->childItems()) { | 
					
						
							| 
									
										
										
										
											2011-08-29 20:54:14 +02:00
										 |  |  |         if (!nodeInstanceServer()->hasInstanceForObject(childItem)) { | 
					
						
							| 
									
										
										
										
											2011-08-25 20:51:29 +02:00
										 |  |  |             QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem)); | 
					
						
							|  |  |  |             if (isRectangleSane(transformedRect)) | 
					
						
							|  |  |  |                 boundingRect = boundingRect.united(transformedRect); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 16:24:53 +02:00
										 |  |  |     return boundingRect; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QRectF QuickItemNodeInstance::boundingRect() const | 
					
						
							| 
									
										
										
										
											2011-06-28 16:24:53 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (quickItem()) { | 
					
						
							|  |  |  |         if (quickItem()->clip()) { | 
					
						
							|  |  |  |             return quickItem()->boundingRect(); | 
					
						
							| 
									
										
										
										
											2011-06-28 16:24:53 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |             return boundingRectWithStepChilds(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QRectF(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void QuickItemNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (name == "state") | 
					
						
							|  |  |  |         return; // states are only set by us
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "height") { | 
					
						
							|  |  |  |         m_height = value.toDouble(); | 
					
						
							|  |  |  |        if (value.isValid()) | 
					
						
							|  |  |  |            m_hasHeight = true; | 
					
						
							|  |  |  |        else | 
					
						
							|  |  |  |            m_hasHeight = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "width") { | 
					
						
							|  |  |  |        m_width = value.toDouble(); | 
					
						
							|  |  |  |        if (value.isValid()) | 
					
						
							|  |  |  |            m_hasWidth = true; | 
					
						
							|  |  |  |        else | 
					
						
							|  |  |  |            m_hasWidth = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "x") | 
					
						
							|  |  |  |         m_x = value.toDouble(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "y") | 
					
						
							|  |  |  |         m_y = value.toDouble(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjectNodeInstance::setPropertyVariant(name, value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 12:49:01 +02:00
										 |  |  |     quickItem()->update(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     refresh(); | 
					
						
							| 
									
										
										
										
											2012-10-04 16:34:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (isInPositioner()) | 
					
						
							|  |  |  |         parentInstance()->refreshPositioner(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void QuickItemNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (name == "state") | 
					
						
							|  |  |  |         return; // states are only set by us
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjectNodeInstance::setPropertyBinding(name, expression); | 
					
						
							| 
									
										
										
										
											2012-10-04 18:56:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 12:49:01 +02:00
										 |  |  |     quickItem()->update(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-04 18:56:24 +02:00
										 |  |  |     refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isInPositioner()) | 
					
						
							|  |  |  |         parentInstance()->refreshPositioner(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QVariant QuickItemNodeInstance::property(const PropertyName &name) const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return ObjectNodeInstance::property(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::resetHorizontal() | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |  { | 
					
						
							|  |  |  |     setPropertyVariant("x", m_x); | 
					
						
							|  |  |  |     if (m_width > 0.0) { | 
					
						
							|  |  |  |         setPropertyVariant("width", m_width); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         setPropertyVariant("width", quickItem()->implicitWidth()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::resetVertical() | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |  { | 
					
						
							|  |  |  |     setPropertyVariant("y", m_y); | 
					
						
							|  |  |  |     if (m_height > 0.0) { | 
					
						
							|  |  |  |         setPropertyVariant("height", m_height); | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |         setPropertyVariant("height", quickItem()->implicitWidth()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | static void repositioning(QQuickItem *item) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (!item) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | //    QQmlBasePositioner *positioner = qobject_cast<QQmlBasePositioner*>(item);
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | //    if (positioner)
 | 
					
						
							|  |  |  | //        positioner->rePositioning();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (item->parentItem()) | 
					
						
							|  |  |  |         repositioning(item->parentItem()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::refresh() | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     repositioning(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-11 12:03:35 +02:00
										 |  |  | static void doComponentCompleteRecursive(QQuickItem *item) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-07 15:45:31 +01:00
										 |  |  |     if (item) { | 
					
						
							|  |  |  |         if (DesignerSupport::isComponentComplete(item)) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |             return; | 
					
						
							| 
									
										
										
										
											2012-11-07 15:45:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         foreach (QQuickItem *childItem, item->childItems()) | 
					
						
							|  |  |  |             doComponentCompleteRecursive(childItem); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         static_cast<QQmlParserStatus*>(item)->componentComplete(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-11-07 15:45:31 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void QuickItemNodeInstance::doComponentComplete() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     doComponentCompleteRecursive(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-11 12:05:00 +02:00
										 |  |  |     disableTextCursor(quickItem()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     quickItem()->update(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::isResizable() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-25 20:51:29 +02:00
										 |  |  |     if (isRootNodeInstance()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return m_isResizable && quickItem() && quickItem()->parentItem(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::setResizable(bool resizeable) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_isResizable = resizeable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | int QuickItemNodeInstance::penWidth() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return DesignerSupport::borderWidth(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void QuickItemNodeInstance::resetProperty(const PropertyName &name) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (name == "height") { | 
					
						
							|  |  |  |         m_hasHeight = false; | 
					
						
							|  |  |  |         m_height = 0.0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "width") { | 
					
						
							|  |  |  |         m_hasWidth = false; | 
					
						
							|  |  |  |         m_width = 0.0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "x") | 
					
						
							|  |  |  |         m_x = 0.0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (name == "y") | 
					
						
							|  |  |  |         m_y = 0.0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     DesignerSupport::resetAnchor(quickItem(), name); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (name == "anchors.fill") { | 
					
						
							|  |  |  |         resetHorizontal(); | 
					
						
							|  |  |  |         resetVertical(); | 
					
						
							|  |  |  |     } else if (name == "anchors.centerIn") { | 
					
						
							|  |  |  |         resetHorizontal(); | 
					
						
							|  |  |  |         resetVertical(); | 
					
						
							|  |  |  |     } else if (name == "anchors.top") { | 
					
						
							|  |  |  |         resetVertical(); | 
					
						
							|  |  |  |     } else if (name == "anchors.left") { | 
					
						
							|  |  |  |         resetHorizontal(); | 
					
						
							|  |  |  |     } else if (name == "anchors.right") { | 
					
						
							|  |  |  |         resetHorizontal(); | 
					
						
							|  |  |  |     } else if (name == "anchors.bottom") { | 
					
						
							|  |  |  |         resetVertical(); | 
					
						
							|  |  |  |     } else if (name == "anchors.horizontalCenter") { | 
					
						
							|  |  |  |         resetHorizontal(); | 
					
						
							|  |  |  |     } else if (name == "anchors.verticalCenter") { | 
					
						
							|  |  |  |         resetVertical(); | 
					
						
							|  |  |  |     } else if (name == "anchors.baseline") { | 
					
						
							|  |  |  |         resetVertical(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjectNodeInstance::resetProperty(name); | 
					
						
							| 
									
										
										
										
											2012-10-04 16:34:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-15 12:49:01 +02:00
										 |  |  |     quickItem()->update(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-04 16:34:25 +02:00
										 |  |  |     if (isInPositioner()) | 
					
						
							|  |  |  |         parentInstance()->refreshPositioner(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | void QuickItemNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const PropertyName &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const PropertyName &newParentProperty) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (oldParentInstance && oldParentInstance->isPositioner()) { | 
					
						
							|  |  |  |         setInPositioner(false); | 
					
						
							|  |  |  |         setMovable(true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ObjectNodeInstance::reparent(oldParentInstance, oldParentProperty, newParentInstance, newParentProperty); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (newParentInstance && newParentInstance->isPositioner()) { | 
					
						
							|  |  |  |         setInPositioner(true); | 
					
						
							|  |  |  |         setMovable(false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (oldParentInstance && oldParentInstance->isPositioner() && !(newParentInstance && newParentInstance->isPositioner())) { | 
					
						
							|  |  |  |         if (!hasBindingForProperty("x")) | 
					
						
							|  |  |  |             setPropertyVariant("x", m_x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!hasBindingForProperty("y")) | 
					
						
							|  |  |  |             setPropertyVariant("y", m_y); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     refresh(); | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     DesignerSupport::updateDirtyNode(quickItem()); | 
					
						
							| 
									
										
										
										
											2012-10-04 16:34:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-12 15:01:27 +02:00
										 |  |  |     if (parentInstance() && isInPositioner()) | 
					
						
							| 
									
										
										
										
											2012-10-04 16:34:25 +02:00
										 |  |  |         parentInstance()->refreshPositioner(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | static bool isValidAnchorName(const PropertyName &name) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     static PropertyNameList anchorNameList(PropertyNameList() << "anchors.top" | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |                                                     << "anchors.left" | 
					
						
							|  |  |  |                                                     << "anchors.right" | 
					
						
							|  |  |  |                                                     << "anchors.bottom" | 
					
						
							|  |  |  |                                                     << "anchors.verticalCenter" | 
					
						
							|  |  |  |                                                     << "anchors.horizontalCenter" | 
					
						
							|  |  |  |                                                     << "anchors.fill" | 
					
						
							|  |  |  |                                                     << "anchors.centerIn" | 
					
						
							|  |  |  |                                                     << "anchors.baseline"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return anchorNameList.contains(name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | bool QuickItemNodeInstance::hasAnchor(const PropertyName &name) const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     return DesignerSupport::hasAnchor(quickItem(), name); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  | QPair<PropertyName, ServerNodeInstance> QuickItemNodeInstance::anchor(const PropertyName &name) const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (!isValidAnchorName(name) || !DesignerSupport::hasAnchor(quickItem(), name)) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         return ObjectNodeInstance::anchor(name); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QPair<QString, QObject*> nameObjectPair = DesignerSupport::anchorLineTarget(quickItem(), name, context()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QObject *targetObject = nameObjectPair.second; | 
					
						
							| 
									
										
										
										
											2013-03-05 12:19:19 +01:00
										 |  |  |     PropertyName targetName = nameObjectPair.first.toUtf8(); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (targetObject && nodeInstanceServer()->hasInstanceForObject(targetObject)) { | 
					
						
							|  |  |  |         return qMakePair(targetName, nodeInstanceServer()->instanceForObject(targetObject)); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return ObjectNodeInstance::anchor(name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QList<ServerNodeInstance> QuickItemNodeInstance::stateInstances() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     QList<ServerNodeInstance> instanceList; | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     QList<QObject*> stateList = DesignerSupport::statesForItem(quickItem()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |     foreach (QObject *state, stateList) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (state && nodeInstanceServer()->hasInstanceForObject(state)) | 
					
						
							|  |  |  |             instanceList.append(nodeInstanceServer()->instanceForObject(state)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return instanceList; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::isAnchoredBySibling() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (quickItem()->parentItem()) { | 
					
						
							|  |  |  |         foreach (QQuickItem *siblingItem, quickItem()->parentItem()->childItems()) { // search in siblings for a anchor to this item
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |             if (siblingItem) { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |                 if (DesignerSupport::isAnchoredTo(siblingItem, quickItem())) | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |                     return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | bool QuickItemNodeInstance::isAnchoredByChildren() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     if (DesignerSupport::areChildrenAnchoredTo(quickItem(), quickItem())) // search in children for a anchor to this item
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | QQuickItem *QuickItemNodeInstance::quickItem() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (object() == 0) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  |     Q_ASSERT(qobject_cast<QQuickItem*>(object())); | 
					
						
							|  |  |  |     return static_cast<QQuickItem*>(object()); | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | DesignerSupport *QuickItemNodeInstance::designerSupport() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return qt5NodeInstanceServer()->designerSupport(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | Qt5NodeInstanceServer *QuickItemNodeInstance::qt5NodeInstanceServer() const | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     return qobject_cast<Qt5NodeInstanceServer*>(nodeInstanceServer()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 15:57:22 +02:00
										 |  |  | void QuickItemNodeInstance::createEffectItem(bool createEffectItem) | 
					
						
							| 
									
										
										
										
											2011-08-31 18:19:45 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     s_createEffectItem = createEffectItem; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-15 15:52:36 +02:00
										 |  |  | void QuickItemNodeInstance::updateDirtyNodeRecursive() | 
					
						
							| 
									
										
										
										
											2013-04-15 13:28:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     updateAllDirtyNodeRecursive(quickItem()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-09 15:50:48 +02:00
										 |  |  | } // namespace Internal
 | 
					
						
							|  |  |  | } // namespace QmlDesigner
 | 
					
						
							|  |  |  | 
 |