1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "qdeclarativeobserverservice.h"
44 #include <QStringList>
49 namespace QmlJSDebugger {
51 Q_GLOBAL_STATIC(QDeclarativeObserverService, serviceInstance)
53 QDeclarativeObserverService::QDeclarativeObserverService()
54 : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode"))
58 QDeclarativeObserverService *QDeclarativeObserverService::instance()
60 return serviceInstance();
63 void QDeclarativeObserverService::statusChanged(Status status)
65 emit debuggingClientChanged((status == Enabled));
68 void QDeclarativeObserverService::messageReceived(const QByteArray &message)
70 QDataStream ds(message);
75 if (type == "SET_CURRENT_OBJECTS") {
79 QList<QObject*> selectedObjects;
80 for(int i = 0; i < itemCount; ++i) {
83 QObject *obj = objectForId(debugId);
86 selectedObjects << obj;
89 emit currentObjectsChanged(selectedObjects);
91 } else if (type == "RELOAD") {
92 emit reloadRequested();
93 } else if (type == "SET_ANIMATION_SPEED") {
96 emit animationSpeedChangeRequested(speed);
97 } else if (type == "CHANGE_TOOL") {
100 if (toolName == "COLOR_PICKER") {
101 emit colorPickerToolRequested();
102 } else if (toolName == "SELECT") {
103 emit selectToolRequested();
104 } else if (toolName == "SELECT_MARQUEE") {
105 emit selectMarqueeToolRequested();
106 } else if (toolName == "ZOOM") {
107 emit zoomToolRequested();
109 } else if (type == "SET_DESIGN_MODE") {
112 emit designModeBehaviorChanged(inDesignMode);
113 } else if (type == "SHOW_APP_ON_TOP") {
116 emit showAppOnTopChanged(showOnTop);
117 } else if (type == "CREATE_OBJECT") {
122 ds >> qml >> parentId >> imports >> filename;
123 emit objectCreationRequested(qml, objectForId(parentId), imports, filename);
124 } else if (type == "DESTROY_OBJECT") {
127 if (QObject* obj = objectForId(debugId))
129 } else if (type == "MOVE_OBJECT") {
130 int debugId, newParent;
131 ds >> debugId >> newParent;
132 emit objectReparentRequested(objectForId(debugId), objectForId(newParent));
133 } else if (type == "OBJECT_ID_LIST") {
136 m_stringIdForObjectId.clear();
137 for(int i = 0; i < itemCount; ++i) {
139 QString itemIdString;
143 m_stringIdForObjectId.insert(itemDebugId, itemIdString);
145 } else if (type == "SET_CONTEXT_PATH_IDX") {
146 int contextPathIndex;
147 ds >> contextPathIndex;
148 emit contextPathIndexChanged(contextPathIndex);
149 } else if (type == "CLEAR_COMPONENT_CACHE") {
150 emit clearComponentCacheRequested();
154 void QDeclarativeObserverService::setDesignModeBehavior(bool inDesignMode)
157 QDataStream ds(&message, QIODevice::WriteOnly);
159 ds << QByteArray("SET_DESIGN_MODE")
162 sendMessage(message);
165 void QDeclarativeObserverService::setCurrentObjects(QList<QObject*> objects)
168 QDataStream ds(&message, QIODevice::WriteOnly);
170 ds << QByteArray("CURRENT_OBJECTS_CHANGED")
173 foreach(QObject *object, objects) {
174 int id = idForObject(object);
178 sendMessage(message);
181 void QDeclarativeObserverService::setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId)
184 QDataStream ds(&message, QIODevice::WriteOnly);
186 ds << QByteArray("TOOL_CHANGED")
189 sendMessage(message);
192 void QDeclarativeObserverService::setAnimationSpeed(qreal slowdownFactor)
196 QDataStream ds(&message, QIODevice::WriteOnly);
198 ds << QByteArray("ANIMATION_SPEED_CHANGED")
201 sendMessage(message);
204 void QDeclarativeObserverService::reloaded()
207 QDataStream ds(&message, QIODevice::WriteOnly);
209 ds << QByteArray("RELOADED");
211 sendMessage(message);
214 void QDeclarativeObserverService::setShowAppOnTop(bool showAppOnTop)
217 QDataStream ds(&message, QIODevice::WriteOnly);
219 ds << QByteArray("SHOW_APP_ON_TOP") << showAppOnTop;
221 sendMessage(message);
224 void QDeclarativeObserverService::selectedColorChanged(const QColor &color)
227 QDataStream ds(&message, QIODevice::WriteOnly);
229 ds << QByteArray("COLOR_CHANGED")
232 sendMessage(message);
235 void QDeclarativeObserverService::contextPathUpdated(const QStringList &contextPath)
238 QDataStream ds(&message, QIODevice::WriteOnly);
240 ds << QByteArray("CONTEXT_PATH_UPDATED")
243 sendMessage(message);
246 QString QDeclarativeObserverService::idStringForObject(QObject *obj) const
248 int id = idForObject(obj);
249 QString idString = m_stringIdForObjectId.value(id, QString());
253 void QDeclarativeObserverService::sendMessage(const QByteArray &message)
255 if (status() != Enabled)
258 QDeclarativeDebugService::sendMessage(message);
261 } // namespace QmlJSDebugger