1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
9 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
14 ** Please review the following information to ensure the GNU Lesser General
15 ** Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
24 ** Alternatively, this file may be used in accordance with the terms and
25 ** conditions contained in a signed written agreement between you and Nokia.
27 ** If you have questions regarding the use of this file, please contact
28 ** Nokia at qt-info@nokia.com.
30 **************************************************************************/
32 #include "qdeclarativeobserverservice.h"
34 #include <observerprotocol.h>
36 #include <QStringList>
39 namespace QmlJSDebugger {
41 Q_GLOBAL_STATIC(QDeclarativeObserverService, serviceInstance)
43 QDeclarativeObserverService::QDeclarativeObserverService()
44 : QDeclarativeDebugService(QLatin1String("QDeclarativeObserverMode"))
48 QDeclarativeObserverService *QDeclarativeObserverService::instance()
50 return serviceInstance();
53 void QDeclarativeObserverService::statusChanged(Status status)
55 emit debuggingClientChanged((status == Enabled));
58 void QDeclarativeObserverService::messageReceived(const QByteArray &message)
60 QDataStream ds(message);
62 ObserverProtocol::Message type;
66 case ObserverProtocol::SetCurrentObjects: {
70 QList<QObject*> selectedObjects;
71 for (int i = 0; i < itemCount; ++i) {
74 QObject *obj = objectForId(debugId);
77 selectedObjects << obj;
80 emit currentObjectsChanged(selectedObjects);
83 case ObserverProtocol::Reload: {
84 emit reloadRequested();
87 case ObserverProtocol::SetAnimationSpeed: {
90 emit animationSpeedChangeRequested(speed);
93 case ObserverProtocol::SetAnimationPaused: {
96 emit executionPauseChangeRequested(paused);
99 case ObserverProtocol::ChangeTool: {
100 ObserverProtocol::Tool tool;
103 case ObserverProtocol::ColorPickerTool:
104 emit colorPickerToolRequested();
106 case ObserverProtocol::SelectTool:
107 emit selectToolRequested();
109 case ObserverProtocol::SelectMarqueeTool:
110 emit selectMarqueeToolRequested();
112 case ObserverProtocol::ZoomTool:
113 emit zoomToolRequested();
116 qWarning() << "Warning: Unhandled tool:" << tool;
120 case ObserverProtocol::SetDesignMode: {
123 emit designModeBehaviorChanged(inDesignMode);
126 case ObserverProtocol::ShowAppOnTop: {
129 emit showAppOnTopChanged(showOnTop);
132 case ObserverProtocol::CreateObject: {
137 ds >> qml >> parentId >> imports >> filename;
138 emit objectCreationRequested(qml, objectForId(parentId), imports, filename);
141 case ObserverProtocol::DestroyObject: {
144 if (QObject* obj = objectForId(debugId))
148 case ObserverProtocol::MoveObject: {
149 int debugId, newParent;
150 ds >> debugId >> newParent;
151 emit objectReparentRequested(objectForId(debugId), objectForId(newParent));
154 case ObserverProtocol::ObjectIdList: {
157 m_stringIdForObjectId.clear();
158 for (int i = 0; i < itemCount; ++i) {
160 QString itemIdString;
164 m_stringIdForObjectId.insert(itemDebugId, itemIdString);
168 case ObserverProtocol::SetContextPathIdx: {
169 int contextPathIndex;
170 ds >> contextPathIndex;
171 emit contextPathIndexChanged(contextPathIndex);
174 case ObserverProtocol::ClearComponentCache: {
175 emit clearComponentCacheRequested();
179 qWarning() << "Warning: Not handling message:" << type;
183 void QDeclarativeObserverService::setDesignModeBehavior(bool inDesignMode)
186 QDataStream ds(&message, QIODevice::WriteOnly);
188 ds << ObserverProtocol::SetDesignMode
191 sendMessage(message);
194 void QDeclarativeObserverService::setCurrentObjects(QList<QObject*> objects)
197 QDataStream ds(&message, QIODevice::WriteOnly);
199 ds << ObserverProtocol::CurrentObjectsChanged
202 foreach (QObject *object, objects) {
203 int id = idForObject(object);
207 sendMessage(message);
210 void QDeclarativeObserverService::setCurrentTool(QmlJSDebugger::Constants::DesignTool toolId)
213 QDataStream ds(&message, QIODevice::WriteOnly);
215 ds << ObserverProtocol::ToolChanged
218 sendMessage(message);
221 void QDeclarativeObserverService::setAnimationSpeed(qreal slowDownFactor)
224 QDataStream ds(&message, QIODevice::WriteOnly);
226 ds << ObserverProtocol::AnimationSpeedChanged
229 sendMessage(message);
232 void QDeclarativeObserverService::setAnimationPaused(bool paused)
235 QDataStream ds(&message, QIODevice::WriteOnly);
237 ds << ObserverProtocol::AnimationPausedChanged
240 sendMessage(message);
243 void QDeclarativeObserverService::reloaded()
246 QDataStream ds(&message, QIODevice::WriteOnly);
248 ds << ObserverProtocol::Reloaded;
250 sendMessage(message);
253 void QDeclarativeObserverService::setShowAppOnTop(bool showAppOnTop)
256 QDataStream ds(&message, QIODevice::WriteOnly);
258 ds << ObserverProtocol::ShowAppOnTop << showAppOnTop;
260 sendMessage(message);
263 void QDeclarativeObserverService::selectedColorChanged(const QColor &color)
266 QDataStream ds(&message, QIODevice::WriteOnly);
268 ds << ObserverProtocol::ColorChanged
271 sendMessage(message);
274 void QDeclarativeObserverService::contextPathUpdated(const QStringList &contextPath)
277 QDataStream ds(&message, QIODevice::WriteOnly);
279 ds << ObserverProtocol::ContextPathUpdated
282 sendMessage(message);
285 QString QDeclarativeObserverService::idStringForObject(QObject *obj) const
287 int id = idForObject(obj);
288 QString idString = m_stringIdForObjectId.value(id, QString());
292 void QDeclarativeObserverService::sendMessage(const QByteArray &message)
294 if (status() != Enabled)
297 QDeclarativeDebugService::sendMessage(message);
300 } // namespace QmlJSDebugger