diff --git a/src/libs/qmljsdebugclient/qdebugmessageclient.cpp b/src/libs/qmljsdebugclient/qdebugmessageclient.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bc1a11f665df751ed9fa7aa275f54989bbf5612b --- /dev/null +++ b/src/libs/qmljsdebugclient/qdebugmessageclient.cpp @@ -0,0 +1,69 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** 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. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#include "qdebugmessageclient.h" + +namespace QmlJsDebugClient { + +QDebugMessageClient::QDebugMessageClient(QDeclarativeDebugConnection *client) + : QDeclarativeDebugClient(QLatin1String("DebugMessages"), client) +{ +} + +QDebugMessageClient::~QDebugMessageClient() +{ +} + +void QDebugMessageClient::statusChanged(Status status) +{ + emit newStatus(status); +} + +void QDebugMessageClient::messageReceived(const QByteArray &data) +{ + QDataStream ds(data); + QByteArray command; + ds >> command; + + if (command == "MESSAGE") { + QByteArray messagePacket; + ds >> messagePacket; + + QByteArray debugMessage; + int type; + QDataStream ms(messagePacket); + ms >> type >> debugMessage; + emit message(QtMsgType(type), QString::fromUtf8(debugMessage.data())); + } +} + +} // namespace QmlJsDebugClient diff --git a/src/libs/qmljsdebugclient/qdebugmessageclient.h b/src/libs/qmljsdebugclient/qdebugmessageclient.h new file mode 100644 index 0000000000000000000000000000000000000000..59635cdf8b88b90a0c65911e63dcb585421d9161 --- /dev/null +++ b/src/libs/qmljsdebugclient/qdebugmessageclient.h @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** 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. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef QDEBUGMESSAGECLIENT_H +#define QDEBUGMESSAGECLIENT_H + +#include "qdeclarativedebugclient.h" +#include "qmljsdebugclient_global.h" + +namespace QmlJsDebugClient { + +class QDebugMessageClientPrivate; +class QMLJSDEBUGCLIENT_EXPORT QDebugMessageClient : public QDeclarativeDebugClient +{ + Q_OBJECT + +public: + explicit QDebugMessageClient(QDeclarativeDebugConnection *client); + ~QDebugMessageClient(); + +protected: + virtual void statusChanged(Status status); + virtual void messageReceived(const QByteArray &); + +signals: + void newStatus(QDeclarativeDebugClient::Status); + void message(QtMsgType, const QString &); + +private: + class QDebugMessageClientPrivate *d; + Q_DISABLE_COPY(QDebugMessageClient) +}; + +} // namespace QmlJsDebugClient + +#endif // QDEBUGMESSAGECLIENT_H diff --git a/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri b/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri index 6b9fc03fb70ff6570757da31e994512afc78e2de..f15d920bf902f847f9d288a3eac7566601b367cf 100644 --- a/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri +++ b/src/libs/qmljsdebugclient/qmljsdebugclient-lib.pri @@ -16,7 +16,8 @@ HEADERS += \ $$PWD/qmlprofilertraceclient.h \ $$PWD/qpacketprotocol.h \ $$PWD/qv8profilerclient.h \ - $$PWD/qmljsdebugclientconstants.h + $$PWD/qmljsdebugclientconstants.h \ + $$PWD/qdebugmessageclient.h SOURCES += \ $$PWD/qdeclarativedebugclient.cpp \ @@ -25,7 +26,8 @@ SOURCES += \ $$PWD/qmlprofilereventlist.cpp \ $$PWD/qmlprofilertraceclient.cpp \ $$PWD/qpacketprotocol.cpp \ - $$PWD/qv8profilerclient.cpp + $$PWD/qv8profilerclient.cpp \ + $$PWD/qdebugmessageclient.cpp OTHER_FILES += \ $$PWD/qmljsdebugclient.pri \ diff --git a/src/plugins/debugger/qml/qmladapter.cpp b/src/plugins/debugger/qml/qmladapter.cpp index 9997f55581879146f77b6c77ff005065eca5f7ab..dfdcde3cf227961d83c280fe184c2fb1a66d0c1a 100644 --- a/src/plugins/debugger/qml/qmladapter.cpp +++ b/src/plugins/debugger/qml/qmladapter.cpp @@ -42,6 +42,8 @@ #include <extensionsystem/pluginmanager.h> #include <utils/qtcassert.h> +#include <qmljsdebugclient/qdebugmessageclient.h> + #include <QtCore/QTimer> #include <QtCore/QDebug> @@ -57,6 +59,7 @@ public: , m_engineDebugClient(0) , m_conn(0) , m_currentSelectedDebugId(-1) + , m_msgClient(0) { m_connectionTimer.setInterval(4000); m_connectionTimer.setSingleShot(true); @@ -70,6 +73,7 @@ public: QHash<QString, QmlDebuggerClient*> debugClients; int m_currentSelectedDebugId; QString m_currentSelectedDebugName; + QmlJsDebugClient::QDebugMessageClient *m_msgClient; }; } // namespace Internal @@ -89,6 +93,9 @@ QmlAdapter::QmlAdapter(DebuggerEngine *engine, QObject *parent) pluginManager->addObject(this); createDebuggerClients(); + d->m_msgClient = new QmlJsDebugClient::QDebugMessageClient(d->m_conn); + connect(d->m_msgClient, SIGNAL(newStatus(QDeclarativeDebugClient::Status)), + this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); } QmlAdapter::~QmlAdapter() @@ -155,11 +162,15 @@ void QmlAdapter::clientStatusChanged(QDeclarativeDebugClient::Status status) serviceName = client->name(); logServiceStatusChange(serviceName, status); +} - if (status == QDeclarativeDebugClient::Enabled) { - d->m_qmlClient = d->debugClients.value(serviceName); - d->m_qmlClient->startSession(); - } +void QmlAdapter::debugClientStatusChanged(QDeclarativeDebugClient::Status /*status*/) +{ + QDeclarativeDebugClient *client = qobject_cast<QDeclarativeDebugClient*>(sender()); + QTC_ASSERT(client, return); + + d->m_qmlClient = qobject_cast<Internal::QmlDebuggerClient *>(client); + d->m_qmlClient->startSession(); } void QmlAdapter::connectionStateChanged() @@ -211,10 +222,14 @@ void QmlAdapter::createDebuggerClients() Internal::QScriptDebuggerClient *client1 = new Internal::QScriptDebuggerClient(d->m_conn); connect(client1, SIGNAL(newStatus(QDeclarativeDebugClient::Status)), this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); + connect(client1, SIGNAL(newStatus(QDeclarativeDebugClient::Status)), + this, SLOT(debugClientStatusChanged(QDeclarativeDebugClient::Status))); Internal::QmlV8DebuggerClient *client2 = new Internal::QmlV8DebuggerClient(d->m_conn); connect(client2, SIGNAL(newStatus(QDeclarativeDebugClient::Status)), this, SLOT(clientStatusChanged(QDeclarativeDebugClient::Status))); + connect(client2, SIGNAL(newStatus(QDeclarativeDebugClient::Status)), + this, SLOT(debugClientStatusChanged(QDeclarativeDebugClient::Status))); d->debugClients.insert(client1->name(),client1); d->debugClients.insert(client2->name(),client2); @@ -292,6 +307,11 @@ void QmlAdapter::setEngineDebugClient(QmlJsDebugClient::QDeclarativeEngineDebug d->m_engineDebugClient = client; } +QmlJsDebugClient::QDebugMessageClient *QmlAdapter::messageClient() const +{ + return d->m_msgClient; +} + int QmlAdapter::currentSelectedDebugId() const { return d->m_currentSelectedDebugId; diff --git a/src/plugins/debugger/qml/qmladapter.h b/src/plugins/debugger/qml/qmladapter.h index 2618529a5b84270fc9bdca208dc60058463b4888..b0283dd63399ef052222a06415f36539ce93e348 100644 --- a/src/plugins/debugger/qml/qmladapter.h +++ b/src/plugins/debugger/qml/qmladapter.h @@ -42,6 +42,7 @@ namespace QmlJsDebugClient { class QDeclarativeEngineDebug; class QDeclarativeDebugConnection; +class QDebugMessageClient; } namespace Debugger { @@ -77,6 +78,8 @@ public: QmlJsDebugClient::QDeclarativeEngineDebug *engineDebugClient() const; void setEngineDebugClient(QmlJsDebugClient::QDeclarativeEngineDebug *client); + QDebugMessageClient *messageClient() const; + int currentSelectedDebugId() const; QString currentSelectedDisplayName() const; void setCurrentSelectedDebugInfo(int debugId, const QString &displayName = QString()); @@ -96,6 +99,7 @@ signals: private slots: void connectionErrorOccurred(QAbstractSocket::SocketError socketError); void clientStatusChanged(QDeclarativeDebugClient::Status status); + void debugClientStatusChanged(QDeclarativeDebugClient::Status status); void connectionStateChanged(); void checkConnectionState(); diff --git a/src/plugins/debugger/qml/qmljsscriptconsole.cpp b/src/plugins/debugger/qml/qmljsscriptconsole.cpp index 1626f33619df70f6fb50710cc7e1d90322c76ec0..041b78bc727e1507a4b9b5fbacc0683262f3510d 100644 --- a/src/plugins/debugger/qml/qmljsscriptconsole.cpp +++ b/src/plugins/debugger/qml/qmljsscriptconsole.cpp @@ -42,6 +42,8 @@ #include <coreplugin/coreconstants.h> #include <utils/statuslabel.h> +#include <qmljsdebugclient/qdebugmessageclient.h> + #include <QtGui/QMenu> #include <QtGui/QTextBlock> #include <QtGui/QHBoxLayout> @@ -209,8 +211,11 @@ void QmlJSScriptConsole::setInferiorStopped(bool inferiorStopped) void QmlJSScriptConsole::setQmlAdapter(QmlAdapter *adapter) { d->adapter = adapter; - if (adapter) + if (adapter) { connect(adapter, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); + connect(adapter->messageClient(), SIGNAL(message(QtMsgType,QString)), + this, SLOT(insertDebugOutput(QtMsgType,QString))); + } clear(); } @@ -278,6 +283,46 @@ void QmlJSScriptConsole::onSelectionChanged() } } +void QmlJSScriptConsole::insertDebugOutput(QtMsgType type, const QString &debugMsg) +{ + QString msg(debugMsg); + msg.append(_("\n")); + + QTextCursor cursor = textCursor(); + + cursor.setPosition(d->startOfEditableArea - d->prompt.length()); + cursor.insertText(msg); + + QTextEdit::ExtraSelection sel; + + QTextCharFormat resultFormat; + switch (type) { + case QtDebugMsg: + resultFormat.setForeground(QColor(Qt::darkBlue)); + break; + case QtWarningMsg: + resultFormat.setForeground(QColor(Qt::darkYellow)); + break; + case QtCriticalMsg: + resultFormat.setForeground(QColor(Qt::darkRed)); + break; + default: + resultFormat.setForeground(QColor(Qt::black)); + } + + cursor.movePosition(QTextCursor::PreviousBlock); + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + + sel.format = resultFormat; + sel.cursor = cursor; + + d->selections.append(sel); + + setExtraSelections(d->selections); + + d->startOfEditableArea += msg.length(); +} + void QmlJSScriptConsole::keyPressEvent(QKeyEvent *e) { bool keyConsumed = false; diff --git a/src/plugins/debugger/qml/qmljsscriptconsole.h b/src/plugins/debugger/qml/qmljsscriptconsole.h index 7ddc842b5675ba641694b469d6d7653eac810782..2bfcc86d5166681eed65f2f450d5ae15b1b568af 100644 --- a/src/plugins/debugger/qml/qmljsscriptconsole.h +++ b/src/plugins/debugger/qml/qmljsscriptconsole.h @@ -97,6 +97,7 @@ public slots: void clear(); void onStateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State); void onSelectionChanged(); + void insertDebugOutput(QtMsgType type, const QString &debugMsg); protected: void keyPressEvent(QKeyEvent *e);