| 
									
										
										
										
											2010-08-13 15:22:44 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							|  |  |  | ** All rights reserved. | 
					
						
							|  |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of the QtDeclarative module of the Qt Toolkit. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** $QT_BEGIN_LICENSE:LGPL$ | 
					
						
							|  |  |  | ** No Commercial Usage | 
					
						
							|  |  |  | ** This file contains pre-release code and may not be distributed. | 
					
						
							|  |  |  | ** You may use this file in accordance with the terms and conditions | 
					
						
							|  |  |  | ** contained in the Technology Preview License Agreement accompanying | 
					
						
							|  |  |  | ** this package. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** 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, Nokia gives you certain additional | 
					
						
							|  |  |  | ** rights.  These rights are described in the Nokia Qt LGPL Exception | 
					
						
							|  |  |  | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you have questions regarding the use of this file, please contact | 
					
						
							|  |  |  | ** Nokia at qt-info@nokia.com. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** $QT_END_LICENSE$ | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  | #include "qdeclarativedesigndebugserver.h"
 | 
					
						
							| 
									
										
										
										
											2010-07-26 12:47:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-16 09:41:56 +02:00
										 |  |  | #include <QStringList>
 | 
					
						
							| 
									
										
										
										
											2010-07-26 12:47:55 +02:00
										 |  |  | #include <QColor>
 | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-01 13:42:24 +02:00
										 |  |  | Q_GLOBAL_STATIC(QDeclarativeDesignDebugServer, qmlDesignDebugServer) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QDeclarativeDesignDebugServer::QDeclarativeDesignDebugServer() | 
					
						
							|  |  |  |     : QDeclarativeDebugService(QLatin1String("QDeclarativeDesignMode")) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QDeclarativeDesignDebugServer *QDeclarativeDesignDebugServer::instance() | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-09-01 13:42:24 +02:00
										 |  |  |     return qmlDesignDebugServer(); | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 14:40:13 +02:00
										 |  |  | void QDeclarativeDesignDebugServer::enabledChanged(bool enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     emit debuggingClientChanged(enabled); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  | void QDeclarativeDesignDebugServer::messageReceived(const QByteArray &message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QDataStream ds(message); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray type; | 
					
						
							|  |  |  |     ds >> type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type == "SET_CURRENT_OBJECTS") { | 
					
						
							|  |  |  |         int itemCount = 0; | 
					
						
							|  |  |  |         ds >> itemCount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QList<QObject*> selectedObjects; | 
					
						
							|  |  |  |         for(int i = 0; i < itemCount; ++i) { | 
					
						
							|  |  |  |             int debugId = -1; | 
					
						
							|  |  |  |             ds >> debugId; | 
					
						
							|  |  |  |             QObject *obj = objectForId(debugId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (obj) | 
					
						
							|  |  |  |                 selectedObjects << obj; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         emit currentObjectsChanged(selectedObjects); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } else if (type == "RELOAD") { | 
					
						
							|  |  |  |         emit reloadRequested(); | 
					
						
							|  |  |  |     } else if (type == "SET_ANIMATION_SPEED") { | 
					
						
							|  |  |  |         qreal speed; | 
					
						
							|  |  |  |         ds >> speed; | 
					
						
							|  |  |  |         emit animationSpeedChangeRequested(speed); | 
					
						
							|  |  |  |     } else if (type == "CHANGE_TOOL") { | 
					
						
							|  |  |  |         QByteArray toolName; | 
					
						
							|  |  |  |         ds >> toolName; | 
					
						
							|  |  |  |         if (toolName == "COLOR_PICKER") { | 
					
						
							| 
									
										
										
										
											2010-07-12 12:02:35 +02:00
										 |  |  |             emit colorPickerToolRequested(); | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  |         } else if (toolName == "SELECT") { | 
					
						
							| 
									
										
										
										
											2010-07-12 12:02:35 +02:00
										 |  |  |             emit selectToolRequested(); | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  |         } else if (toolName == "SELECT_MARQUEE") { | 
					
						
							| 
									
										
										
										
											2010-07-12 12:02:35 +02:00
										 |  |  |             emit selectMarqueeToolRequested(); | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  |         } else if (toolName == "ZOOM") { | 
					
						
							| 
									
										
										
										
											2010-07-12 12:02:35 +02:00
										 |  |  |             emit zoomToolRequested(); | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-12 12:02:35 +02:00
										 |  |  |     } else if (type == "SET_DESIGN_MODE") { | 
					
						
							|  |  |  |         bool inDesignMode; | 
					
						
							|  |  |  |         ds >> inDesignMode; | 
					
						
							|  |  |  |         emit designModeBehaviorChanged(inDesignMode); | 
					
						
							| 
									
										
										
										
											2010-07-16 09:41:56 +02:00
										 |  |  |     } else if (type == "CREATE_OBJECT") { | 
					
						
							|  |  |  |         QString qml; | 
					
						
							|  |  |  |         int parentId; | 
					
						
							|  |  |  |         QString filename; | 
					
						
							|  |  |  |         QStringList imports; | 
					
						
							|  |  |  |         ds >> qml >> parentId >> imports >> filename; | 
					
						
							|  |  |  |         emit objectCreationRequested(qml, objectForId(parentId), imports, filename); | 
					
						
							| 
									
										
										
										
											2010-07-19 10:42:39 +02:00
										 |  |  |     } else if (type == "DESTROY_OBJECT") { | 
					
						
							|  |  |  |         int debugId; | 
					
						
							|  |  |  |         ds >> debugId; | 
					
						
							|  |  |  |         if (QObject* obj = objectForId(debugId)) | 
					
						
							|  |  |  |             obj->deleteLater(); | 
					
						
							| 
									
										
										
										
											2010-08-26 17:38:31 +02:00
										 |  |  |     } else if (type == "MOVE_OBJECT") { | 
					
						
							|  |  |  |        int debugId, newParent; | 
					
						
							|  |  |  |        ds >> debugId >> newParent; | 
					
						
							|  |  |  |        emit objectReparentRequested(objectForId(debugId), objectForId(newParent)); | 
					
						
							| 
									
										
										
										
											2010-07-26 15:31:59 +02:00
										 |  |  |     } else if (type == "OBJECT_ID_LIST") { | 
					
						
							|  |  |  |         int itemCount; | 
					
						
							|  |  |  |         ds >> itemCount; | 
					
						
							|  |  |  |         m_stringIdForObjectId.clear(); | 
					
						
							|  |  |  |         for(int i = 0; i < itemCount; ++i) { | 
					
						
							|  |  |  |             int itemDebugId; | 
					
						
							|  |  |  |             QString itemIdString; | 
					
						
							|  |  |  |             ds >> itemDebugId | 
					
						
							|  |  |  |                >> itemIdString; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             m_stringIdForObjectId.insert(itemDebugId, itemIdString); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-08-03 10:17:09 +02:00
										 |  |  |     } else if (type == "SET_CONTEXT_PATH_IDX") { | 
					
						
							|  |  |  |         int contextPathIndex; | 
					
						
							|  |  |  |         ds >> contextPathIndex; | 
					
						
							|  |  |  |         emit contextPathIndexChanged(contextPathIndex); | 
					
						
							| 
									
										
										
										
											2010-08-03 14:07:30 +02:00
										 |  |  |     } else if (type == "CLEAR_COMPONENT_CACHE") { | 
					
						
							|  |  |  |         emit clearComponentCacheRequested(); | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-12 12:02:35 +02:00
										 |  |  | void QDeclarativeDesignDebugServer::setDesignModeBehavior(bool inDesignMode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("SET_DESIGN_MODE") | 
					
						
							|  |  |  |        << inDesignMode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-08 14:00:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void QDeclarativeDesignDebugServer::setCurrentObjects(QList<QObject*> objects) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("CURRENT_OBJECTS_CHANGED") | 
					
						
							|  |  |  |        << objects.length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach(QObject *object, objects) { | 
					
						
							|  |  |  |         int id = idForObject(object); | 
					
						
							|  |  |  |         ds << id; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void QDeclarativeDesignDebugServer::setCurrentTool(QmlViewer::Constants::DesignTool toolId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("TOOL_CHANGED") | 
					
						
							|  |  |  |        << toolId; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void QDeclarativeDesignDebugServer::setAnimationSpeed(qreal slowdownFactor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("ANIMATION_SPEED_CHANGED") | 
					
						
							|  |  |  |        << slowdownFactor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-20 12:35:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void QDeclarativeDesignDebugServer::reloaded() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("RELOADED"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-26 12:47:55 +02:00
										 |  |  | void QDeclarativeDesignDebugServer::selectedColorChanged(const QColor &color) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("COLOR_CHANGED") | 
					
						
							|  |  |  |        << color; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-26 15:31:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-02 17:25:29 +02:00
										 |  |  | void QDeclarativeDesignDebugServer::contextPathUpdated(const QStringList &contextPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QByteArray message; | 
					
						
							|  |  |  |     QDataStream ds(&message, QIODevice::WriteOnly); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ds << QByteArray("CONTEXT_PATH_UPDATED") | 
					
						
							|  |  |  |        << contextPath; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sendMessage(message); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-26 15:31:59 +02:00
										 |  |  | QString QDeclarativeDesignDebugServer::idStringForObject(QObject *obj) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int id = idForObject(obj); | 
					
						
							|  |  |  |     QString idString = m_stringIdForObjectId.value(id, QString()); | 
					
						
							|  |  |  |     return idString; | 
					
						
							|  |  |  | } |