From abb9a3b5031e86bdd89a9338c4f12d703e6f385b Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 26 May 2009 10:03:08 +1000 Subject: Move canvas scene snapshot out of in-process debugger --- src/declarative/canvas/qsimplecanvas.cpp | 4 +- .../canvas/qsimplecanvasdebugplugin.cpp | 56 +++++ .../canvas/qsimplecanvasdebugplugin_p.h | 17 ++ src/declarative/debugger/debugger.pri | 2 - src/declarative/debugger/qmlcanvasdebugger.cpp | 240 -------------------- src/declarative/debugger/qmlcanvasdebugger_p.h | 89 -------- src/declarative/debugger/qmldebugclient.cpp | 4 +- src/declarative/debugger/qmldebugclient.h | 1 - src/declarative/debugger/qmldebugger.cpp | 9 +- src/declarative/debugger/qmldebugger.h | 2 - src/declarative/debugger/qmldebugserver.cpp | 15 ++ src/declarative/debugger/qmldebugserver.h | 1 + tools/qmldebugger/canvasframerate.cpp | 45 ++-- tools/qmldebugger/canvasframerate.h | 1 + tools/qmldebugger/canvasscene.cpp | 245 +++++++++++++++++++++ tools/qmldebugger/canvasscene.h | 39 ++++ tools/qmldebugger/main.cpp | 56 ++++- tools/qmldebugger/qmldebugger.pro | 4 +- 18 files changed, 449 insertions(+), 381 deletions(-) delete mode 100644 src/declarative/debugger/qmlcanvasdebugger.cpp delete mode 100644 src/declarative/debugger/qmlcanvasdebugger_p.h create mode 100644 tools/qmldebugger/canvasscene.cpp create mode 100644 tools/qmldebugger/canvasscene.h diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp index 7d2c9c5..e582226 100644 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ b/src/declarative/canvas/qsimplecanvas.cpp @@ -573,8 +573,10 @@ void QSimpleCanvasPrivate::init(QSimpleCanvas::CanvasMode mode) if (continuousUpdate()) qWarning("QSimpleCanvas: Continuous update enabled"); - if (QmlDebugServerPlugin::isDebuggingEnabled()) + if (QmlDebugServerPlugin::isDebuggingEnabled()) { debugPlugin = new QSimpleCanvasDebugPlugin(q); + new QSimpleCanvasSceneDebugPlugin(q); + } root = new QSimpleCanvasRootLayer(q); root->setActiveFocusPanel(true); diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp index 0ce5378..f5f4f53 100644 --- a/src/declarative/canvas/qsimplecanvasdebugplugin.cpp +++ b/src/declarative/canvas/qsimplecanvasdebugplugin.cpp @@ -42,6 +42,8 @@ #include "qsimplecanvasdebugplugin_p.h" #include "qdebug.h" #include +#include +#include QT_BEGIN_NAMESPACE @@ -74,6 +76,9 @@ void QSimpleCanvasDebugPlugin::addTiming(quint32 paint, quint32 repaint, quint32 timeBetweenFrames) { + if (!isEnabled()) + return; + bool isFrameBreak = _breaks > 1; _breaks = 0; int e = _time.elapsed(); @@ -89,5 +94,56 @@ void QSimpleCanvasDebugPlugin::frameBreak() _breaks++; } +QSimpleCanvasSceneDebugPlugin::QSimpleCanvasSceneDebugPlugin(QSimpleCanvas *parent) +: QmlDebugServerPlugin("CanvasScene", parent), m_canvas(parent) +{ +} + +void QSimpleCanvasSceneDebugPlugin::messageReceived(const QByteArray &) +{ + refresh(); +} + +void QSimpleCanvasSceneDebugPlugin::refresh() +{ + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + const QList &children = m_canvas->root()->children(); + ds << children.count(); + for (int ii = 0; ii < children.count(); ++ii) + refresh(ds, children.at(ii)); + + sendMessage(data); +} + +void QSimpleCanvasSceneDebugPlugin::refresh(QDataStream &ds, + QSimpleCanvasItem *item) +{ + ds << QmlDebugServerPlugin::objectToString(item) << item->x() << item->y() + << item->z() << item->width() << item->height() + << (int)item->transformOrigin() << item->scale() << (int)item->flip() + << item->transform() << item->hasActiveFocus() << (int)item->options(); + + QPixmap pix; + + if(item->options() & QSimpleCanvasItem::HasContents && + item->width() > 0 && item->height() > 0) { + + pix = QPixmap(item->width(), item->height()); + pix.fill(QColor(0,0,0,0)); + QPainter p(&pix); + item->paintContents(p); + + } + + ds << pix; + + const QList &children = item->children(); + ds << children.count(); + + for(int ii = 0; ii < children.count(); ++ii) + refresh(ds, children.at(ii)); +} + QT_END_NAMESPACE diff --git a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h index 0c76f38..270b78c 100644 --- a/src/declarative/canvas/qsimplecanvasdebugplugin_p.h +++ b/src/declarative/canvas/qsimplecanvasdebugplugin_p.h @@ -62,6 +62,23 @@ private: int _breaks; QTime _time; }; + +class QSimpleCanvas; +class QSimpleCanvasItem; +class QSimpleCanvasSceneDebugPlugin : public QmlDebugServerPlugin +{ +public: + QSimpleCanvasSceneDebugPlugin(QSimpleCanvas *parent = 0); + + virtual void messageReceived(const QByteArray &); + +private: + void refresh(); + void refresh(QDataStream &, QSimpleCanvasItem *); + QSimpleCanvas *m_canvas; +}; + + QT_END_NAMESPACE #endif // QSIMPLECANVASDEBUGPLUGIN_P_H diff --git a/src/declarative/debugger/debugger.pri b/src/declarative/debugger/debugger.pri index 121cb98..aa36675 100644 --- a/src/declarative/debugger/debugger.pri +++ b/src/declarative/debugger/debugger.pri @@ -3,7 +3,6 @@ SOURCES += debugger/qmldebugger.cpp \ debugger/qmlpropertyview.cpp \ debugger/qmlwatches.cpp \ debugger/qmlobjecttree.cpp \ - debugger/qmlcanvasdebugger.cpp \ debugger/qpacketprotocol.cpp \ debugger/qmldebugserver.cpp \ debugger/qmldebugclient.cpp @@ -13,7 +12,6 @@ HEADERS += debugger/qmldebugger.h \ debugger/qmlpropertyview_p.h \ debugger/qmlwatches_p.h \ debugger/qmlobjecttree_p.h \ - debugger/qmlcanvasdebugger_p.h \ debugger/qpacketprotocol.h \ debugger/qmldebugserver.h \ debugger/qmldebugclient.h diff --git a/src/declarative/debugger/qmlcanvasdebugger.cpp b/src/declarative/debugger/qmlcanvasdebugger.cpp deleted file mode 100644 index 21abd2d..0000000 --- a/src/declarative/debugger/qmlcanvasdebugger.cpp +++ /dev/null @@ -1,240 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -QmlCanvasDebugger::QmlCanvasDebugger(QmlWatches *w, QWidget *parent) -: QWidget(parent), m_watches(w), m_tree(0), m_canvas(0), m_canvasRoot(0), m_debugCanvas(0), - m_selected(0) -{ - QVBoxLayout *layout = new QVBoxLayout; - layout->setContentsMargins(0,0,0,0); - layout->setSpacing(0); - setLayout(layout); - QHBoxLayout *hlayout = new QHBoxLayout; - hlayout->setContentsMargins(0,0,0,0); - hlayout->addStretch(2); - hlayout->setSpacing(0); - layout->addLayout(hlayout); - QSpinBox *x = new QSpinBox(this); - x->setSingleStep(50); - x->setMaximum(10000); - x->setMinimum(-10000); - QObject::connect(x, SIGNAL(valueChanged(int)), this, SLOT(setX(int))); - QSpinBox *y = new QSpinBox(this); - y->setSingleStep(50); - y->setMaximum(10000); - y->setMinimum(-10000); - QObject::connect(y, SIGNAL(valueChanged(int)), this, SLOT(setY(int))); - hlayout->addWidget(x); - hlayout->addWidget(y); - QPushButton *pb = new QPushButton(tr("Refresh"), this); - QObject::connect(pb, SIGNAL(clicked()), this, SLOT(refresh())); - hlayout->addWidget(pb); - - QSplitter *splitter = new QSplitter(this); - - m_tree = new QTreeWidget(this); - QObject::connect(m_tree, SIGNAL(itemExpanded(QTreeWidgetItem*)), - this, SLOT(itemExpanded(QTreeWidgetItem*))); - QObject::connect(m_tree, SIGNAL(itemCollapsed(QTreeWidgetItem*)), - this, SLOT(itemCollapsed(QTreeWidgetItem*))); - QObject::connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), - this, SLOT(itemClicked(QTreeWidgetItem*))); - m_canvas = new QSimpleCanvas(QSimpleCanvas::SimpleCanvas, this); - m_canvasRoot = new QSimpleCanvasItem; - m_canvasRoot->setParent(m_canvas->root()); - splitter->addWidget(m_tree); - splitter->addWidget(m_canvas); - splitter->setStretchFactor(1, 2); - layout->addWidget(splitter); -} - -void QmlCanvasDebugger::refresh() -{ - setCanvas(m_debugCanvas); -} - -class QmlCanvasDebuggerItem : public QTreeWidgetItem -{ -public: - QmlCanvasDebuggerItem(QTreeWidget *tree) - : QTreeWidgetItem(tree), me(0), img(0) - { - } - - QmlCanvasDebuggerItem(QTreeWidgetItem *item) - : QTreeWidgetItem(item), me(0), img(0) - { - } - - QPointer them; - QFxRect *me; - QFxImage *img; -}; - -void QmlCanvasDebugger::itemExpanded(QTreeWidgetItem *i) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->me) - item->me->setOpacity(1); -} - -void QmlCanvasDebugger::setOpacityRecur(QTreeWidgetItem *i, qreal op) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->img) - item->img->setOpacity(op); - - for(int ii = 0; ii < item->childCount(); ++ii) - setOpacityRecur(item->child(ii), op); -} - -void QmlCanvasDebugger::itemClicked(QTreeWidgetItem *i) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->them) - emit objectClicked(m_watches->objectId(item->them)); - - if(m_selected) { - setOpacityRecur(m_selected, 0); - m_selected = 0; - } - - m_selected = item; - setOpacityRecur(m_selected, 1); -} - -void QmlCanvasDebugger::itemCollapsed(QTreeWidgetItem *i) -{ - QmlCanvasDebuggerItem *item = static_cast(i); - if(item->me) - item->me->setOpacity(0); -} - -void QmlCanvasDebugger::clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, QSimpleCanvasItem *them) -{ - const QList &children = them->children(); - - foreach(QSimpleCanvasItem *child, children) { - QmlCanvasDebuggerItem *childItem = new QmlCanvasDebuggerItem(item); - childItem->setText(0, QmlWatches::objectToString(child)); - childItem->setExpanded(true); - - QFxRect *rect = new QFxRect; - rect->setParent(me); - rect->setX(child->x()); - rect->setY(child->y()); - rect->setZ(child->z()); - rect->setWidth(child->width()); - rect->setHeight(child->height()); - rect->setTransformOrigin(child->transformOrigin()); - rect->setScale(child->scale()); - rect->setFlip(child->flip()); - rect->setTransform(child->transform()); - - if(child->hasActiveFocus()) - rect->setColor(QColor(0, 0, 0, 10)); - else if(child->options() & QSimpleCanvasItem::IsFocusPanel) - rect->setColor(QColor(0, 255, 0, 10)); - else if(child->options() & QSimpleCanvasItem::IsFocusRealm) - rect->setColor(QColor(0, 0, 255, 10)); - else - rect->setColor(QColor(255, 0, 0, 10)); - - if(child->width() > 0 && child->height() > 0) { - QPixmap pix(child->width(), child->height()); - pix.fill(QColor(0,0,0,0)); - QPainter p(&pix); - child->paintContents(p); - QFxImage *img = new QFxImage; - img->setParent(rect); - img->setWidth(child->width()); - img->setHeight(child->height()); - img->setPixmap(pix); - img->setOpacity(0); - childItem->img = img; - } - - childItem->them = child; - childItem->me = rect; - - clone(childItem, rect, child); - } -} - -void QmlCanvasDebugger::setX(int x) -{ - m_canvasRoot->setX(x); -} - -void QmlCanvasDebugger::setY(int y) -{ - m_canvasRoot->setY(y); -} - -void QmlCanvasDebugger::setCanvas(QSimpleCanvas *canvas) -{ - QList children = m_canvasRoot->children(); - qDeleteAll(children); - m_tree->clear(); - m_selected = 0; - - m_debugCanvas = canvas; - if(!m_debugCanvas) - return; - - QTreeWidgetItem *root = new QmlCanvasDebuggerItem(m_tree); - root->setText(0, tr("Root")); - root->setExpanded(true); - clone(root, m_canvasRoot, m_debugCanvas->root()); -} - diff --git a/src/declarative/debugger/qmlcanvasdebugger_p.h b/src/declarative/debugger/qmlcanvasdebugger_p.h deleted file mode 100644 index 80a2322..0000000 --- a/src/declarative/debugger/qmlcanvasdebugger_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMLCANVASDEBUGGER_P_H -#define QMLCANVASDEBUGGER_P_H - -#include -#include - -QT_BEGIN_NAMESPACE - -class QSimpleCanvas; -class QSimpleCanvasItem; -class QTreeWidget; -class QTreeWidgetItem; -class QmlWatches; -class QmlCanvasDebugger : public QWidget -{ - Q_OBJECT -public: - QmlCanvasDebugger(QmlWatches *, QWidget *parent = 0); - - void setCanvas(QSimpleCanvas *); - -signals: - void objectClicked(quint32); - -private slots: - void refresh(); - void itemClicked(QTreeWidgetItem *); - void itemExpanded(QTreeWidgetItem *); - void itemCollapsed(QTreeWidgetItem *); - void setX(int); - void setY(int); - -private: - void setOpacityRecur(QTreeWidgetItem *, qreal); - void clone(QTreeWidgetItem *, QSimpleCanvasItem *me, QSimpleCanvasItem *them); - - QmlWatches *m_watches; - QTreeWidget *m_tree; - QSimpleCanvas *m_canvas; - QSimpleCanvasItem *m_canvasRoot; - QPointer m_debugCanvas; - QTreeWidgetItem *m_selected; -}; - -QT_END_NAMESPACE - -#endif // QMLCANVASDEBUGGER_P_H - diff --git a/src/declarative/debugger/qmldebugclient.cpp b/src/declarative/debugger/qmldebugclient.cpp index 7a304ef..85ccf0b 100644 --- a/src/declarative/debugger/qmldebugclient.cpp +++ b/src/declarative/debugger/qmldebugclient.cpp @@ -73,7 +73,7 @@ QmlDebugClientPrivate::QmlDebugClientPrivate(QmlDebugClient *c) void QmlDebugClientPrivate::connected() { QPacket pack; - pack << QString(QLatin1String("QmlDebugServer")) << QStringList(); + pack << QString(QLatin1String("QmlDebugServer")) << enabled; protocol->send(pack); } @@ -178,7 +178,7 @@ void QmlDebugClientPlugin::sendMessage(const QByteArray &message) QPacket pack; pack << d->name << message; - d->client->d_func()->protocol->send(pack); + d->client->d->protocol->send(pack); } void QmlDebugClientPlugin::messageReceived(const QByteArray &) diff --git a/src/declarative/debugger/qmldebugclient.h b/src/declarative/debugger/qmldebugclient.h index d765822..3fbf534 100644 --- a/src/declarative/debugger/qmldebugclient.h +++ b/src/declarative/debugger/qmldebugclient.h @@ -54,7 +54,6 @@ class QmlDebugClientPrivate; class Q_DECLARATIVE_EXPORT QmlDebugClient : public QTcpSocket { Q_OBJECT - Q_DECLARE_PRIVATE(QmlDebugClient) Q_DISABLE_COPY(QmlDebugClient) public: QmlDebugClient(QObject * = 0); diff --git a/src/declarative/debugger/qmldebugger.cpp b/src/declarative/debugger/qmldebugger.cpp index 0bbcb2c..c925148 100644 --- a/src/declarative/debugger/qmldebugger.cpp +++ b/src/declarative/debugger/qmldebugger.cpp @@ -61,11 +61,10 @@ #include #include #include -#include QmlDebugger::QmlDebugger(QWidget *parent) : QWidget(parent), m_tree(0), m_warnings(0), m_watchTable(0), m_watches(0), - m_canvas(0), m_properties(0), m_text(0), m_highlightedItem(0) + m_properties(0), m_text(0), m_highlightedItem(0) { QHBoxLayout *layout = new QHBoxLayout; setLayout(layout); @@ -111,11 +110,6 @@ QmlDebugger::QmlDebugger(QWidget *parent) tabs->addTab(m_properties, tr("Properties")); tabs->setCurrentWidget(m_properties); - m_canvas = new QmlCanvasDebugger(m_watches, this); - QObject::connect(m_canvas, SIGNAL(objectClicked(quint32)), - this, SLOT(highlightObject(quint32))); - tabs->addTab(m_canvas, tr("Canvas")); - splitter->addWidget(tabs); splitter->setStretchFactor(1, 2); @@ -339,7 +333,6 @@ bool operator<(const QPair > &lhs, void QmlDebugger::setCanvas(QSimpleCanvas *c) { - m_canvas->setCanvas(c); } void QmlDebugger::setDebugObject(QObject *obj) diff --git a/src/declarative/debugger/qmldebugger.h b/src/declarative/debugger/qmldebugger.h index 4641bce..10b2f9a 100644 --- a/src/declarative/debugger/qmldebugger.h +++ b/src/declarative/debugger/qmldebugger.h @@ -61,7 +61,6 @@ class QmlPropertyView; class QmlWatches; class QmlObjectTree; class QmlContext; -class QmlCanvasDebugger; class QSimpleCanvas; class QmlDebugger : public QWidget { @@ -88,7 +87,6 @@ private: QTreeWidget *m_warnings; QTableView *m_watchTable; QmlWatches *m_watches; - QmlCanvasDebugger *m_canvas; QmlPropertyView *m_properties; QPlainTextEdit *m_text; QPointer m_object; diff --git a/src/declarative/debugger/qmldebugserver.cpp b/src/declarative/debugger/qmldebugserver.cpp index bce7e6d..a253e8c 100644 --- a/src/declarative/debugger/qmldebugserver.cpp +++ b/src/declarative/debugger/qmldebugserver.cpp @@ -258,6 +258,21 @@ bool QmlDebugServerPlugin::isDebuggingEnabled() return QmlDebugServer::instance() != 0; } +QString QmlDebugServerPlugin::objectToString(QObject *obj) +{ + if(!obj) + return QLatin1String("NULL"); + + QString objectName = obj->objectName(); + if(objectName.isEmpty()) + objectName = QLatin1String(""); + + QString rv = QLatin1String(obj->metaObject()->className()) + + QLatin1String(": ") + objectName; + + return rv; +} + void QmlDebugServerPlugin::sendMessage(const QByteArray &message) { Q_D(QmlDebugServerPlugin); diff --git a/src/declarative/debugger/qmldebugserver.h b/src/declarative/debugger/qmldebugserver.h index 8ee2cfb..02fe7d1 100644 --- a/src/declarative/debugger/qmldebugserver.h +++ b/src/declarative/debugger/qmldebugserver.h @@ -64,6 +64,7 @@ public: void sendMessage(const QByteArray &); static bool isDebuggingEnabled(); + static QString objectToString(QObject *obj); protected: virtual void enabledChanged(bool); diff --git a/tools/qmldebugger/canvasframerate.cpp b/tools/qmldebugger/canvasframerate.cpp index b1f412e..022aed5 100644 --- a/tools/qmldebugger/canvasframerate.cpp +++ b/tools/qmldebugger/canvasframerate.cpp @@ -12,6 +12,7 @@ #include #include #include +#include class QLineGraph : public QWidget { @@ -26,9 +27,7 @@ public slots: protected: virtual void paintEvent(QPaintEvent *); - virtual void mousePressEvent(QMouseEvent *); - virtual void resizeEvent(QResizeEvent *); - virtual void showEvent(QShowEvent *); + virtual QSize sizeHint() const; private slots: void scrollbarChanged(int); @@ -64,32 +63,20 @@ QLineGraph::QLineGraph(QWidget *parent) QObject::connect(&sb, SIGNAL(valueChanged(int)), this, SLOT(scrollbarChanged(int))); } -void QLineGraph::scrollbarChanged(int v) +QSize QLineGraph::sizeHint() const { - if(ignoreScroll) - return; - - position = v; - update(); + return QSize(800, 600); } -void QLineGraph::resizeEvent(QResizeEvent *e) -{ - QWidget::resizeEvent(e); -} - -void QLineGraph::showEvent(QShowEvent *e) +void QLineGraph::scrollbarChanged(int v) { - QWidget::showEvent(e); -} + if(ignoreScroll) + return; -void QLineGraph::mousePressEvent(QMouseEvent *) -{ - if(position == -1) { - position = qMax(0, _samples.count() - samplesPerWidth - 1); - } else { + if (v == sb.maximum()) position = -1; - } + else + position = v; update(); } @@ -276,6 +263,11 @@ CanvasFrameRate::CanvasFrameRate(QmlDebugClient *client, QWidget *parent) layout->addLayout(bottom); bottom->addStretch(2); + QCheckBox *check = new QCheckBox("Enable", this); + bottom->addWidget(check); + QObject::connect(check, SIGNAL(stateChanged(int)), + this, SLOT(stateChanged(int))); + QPushButton *pb = new QPushButton(tr("New Tab"), this); QObject::connect(pb, SIGNAL(clicked()), this, SLOT(newTab())); bottom->addWidget(pb); @@ -302,4 +294,11 @@ void CanvasFrameRate::newTab() m_tabs->setCurrentIndex(id); } +void CanvasFrameRate::stateChanged(int s) +{ + bool checked = s != 0; + + static_cast(m_plugin)->setEnabled(checked); +} + #include "canvasframerate.moc" diff --git a/tools/qmldebugger/canvasframerate.h b/tools/qmldebugger/canvasframerate.h index c3e88ef..543f233 100644 --- a/tools/qmldebugger/canvasframerate.h +++ b/tools/qmldebugger/canvasframerate.h @@ -13,6 +13,7 @@ public: private slots: void newTab(); + void stateChanged(int); private: QTabWidget *m_tabs; diff --git a/tools/qmldebugger/canvasscene.cpp b/tools/qmldebugger/canvasscene.cpp new file mode 100644 index 0000000..2d5b764 --- /dev/null +++ b/tools/qmldebugger/canvasscene.cpp @@ -0,0 +1,245 @@ +#include "canvasscene.h" +#include +#include +#include +#include +#include +#include +#include +#include + +class CanvasSceneClientPlugin : public QmlDebugClientPlugin +{ +public: + CanvasSceneClientPlugin(QmlDebugClient *, CanvasScene *s); + +protected: + void messageReceived(const QByteArray &); + +private: + void dump(QDataStream &, int indent); + CanvasScene *scene; +}; + +class QmlCanvasDebuggerItem : public QTreeWidgetItem +{ +public: + QmlCanvasDebuggerItem(QTreeWidget *tree) + : QTreeWidgetItem(tree), me(0), img(0) + { + } + + QmlCanvasDebuggerItem(QTreeWidgetItem *item) + : QTreeWidgetItem(item), me(0), img(0) + { + } + + QFxRect *me; + QFxImage *img; +}; + +CanvasSceneClientPlugin::CanvasSceneClientPlugin(QmlDebugClient *c, + CanvasScene *s) +: QmlDebugClientPlugin(QLatin1String("CanvasScene"), c), scene(s) +{ +} + +void CanvasSceneClientPlugin::messageReceived(const QByteArray &data) +{ + QByteArray d = data; + QDataStream ds(&d, QIODevice::ReadOnly); + + scene->message(ds); +} + +void CanvasScene::message(QDataStream &ds) +{ + QList children = m_canvasRoot->children(); + qDeleteAll(children); + m_tree->clear(); + m_selected = 0; + + QTreeWidgetItem *root = new QmlCanvasDebuggerItem(m_tree); + root->setText(0, tr("Root")); + root->setExpanded(true); + clone(root, m_canvasRoot, ds); +} + +void CanvasScene::clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, + QDataStream &ds) +{ + int children; + ds >> children; + + for (int ii = 0; ii < children; ++ii) { + QString name; + qreal x, y, z, width, height, scale; + QTransform transform; + bool activeFocus; + int transformOrigin, flip, options; + QPixmap pix; + + ds >> name >> x >> y >> z >> width >> height >> transformOrigin >> scale + >> flip >> transform >> activeFocus >> options >> pix; + + QmlCanvasDebuggerItem *childItem = new QmlCanvasDebuggerItem(item); + childItem->setText(0, name); + childItem->setExpanded(true); + + QFxRect *rect = new QFxRect; + rect->setParent(me); + rect->setX(x); + rect->setY(y); + rect->setZ(z); + rect->setWidth(width); + rect->setHeight(height); + rect->setTransformOrigin((QSimpleCanvasItem::TransformOrigin)transformOrigin); + rect->setScale(scale); + rect->setFlip((QSimpleCanvasItem::Flip)flip); + rect->setTransform(transform); + + if (activeFocus) + rect->setColor(QColor(0, 0, 0, 10)); + else if(options & QSimpleCanvasItem::IsFocusPanel) + rect->setColor(QColor(0, 255, 0, 10)); + else if(options & QSimpleCanvasItem::IsFocusRealm) + rect->setColor(QColor(0, 0, 255, 10)); + else + rect->setColor(QColor(255, 0, 0, 10)); + + if (pix.width() > 0 || pix.height() > 0) { + QFxImage *img = new QFxImage; + img->setParent(rect); + img->setWidth(width); + img->setHeight(height); + img->setPixmap(pix); + img->setOpacity(0); + childItem->img = img; + } + + childItem->me = rect; + + clone(childItem, rect, ds); + } +} + +void CanvasSceneClientPlugin::dump(QDataStream &ds, int indent) +{ + QString name; + qreal x, y, z, width, height, scale; + QTransform transform; + bool activeFocus; + int transformOrigin, flip, options, count; + QPixmap pix; + + ds >> name >> x >> y >> z >> width >> height >> transformOrigin >> scale + >> flip >> transform >> activeFocus >> options >> pix >> count; + + QByteArray ba(indent * 4, ' '); + qWarning() << ba.constData() << name << x << y; + + for(int ii = 0; ii < count; ++ii) + dump(ds, indent + 1); +} + +CanvasScene::CanvasScene(QmlDebugClient *c, QWidget *parent) +: QWidget(parent) +{ + client = new CanvasSceneClientPlugin(c, this); + + QVBoxLayout *layout = new QVBoxLayout; + layout->setContentsMargins(0,0,0,0); + layout->setSpacing(0); + setLayout(layout); + QSplitter *splitter = new QSplitter(this); + + m_tree = new QTreeWidget(this); + m_tree->setHeaderHidden(true); + QObject::connect(m_tree, SIGNAL(itemExpanded(QTreeWidgetItem*)), + this, SLOT(itemExpanded(QTreeWidgetItem*))); + QObject::connect(m_tree, SIGNAL(itemCollapsed(QTreeWidgetItem*)), + this, SLOT(itemCollapsed(QTreeWidgetItem*))); + QObject::connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), + this, SLOT(itemClicked(QTreeWidgetItem*))); + m_canvas = new QSimpleCanvas(QSimpleCanvas::SimpleCanvas, this); + m_canvasRoot = new QSimpleCanvasItem; + m_canvasRoot->setParent(m_canvas->root()); + splitter->addWidget(m_tree); + splitter->addWidget(m_canvas); + splitter->setStretchFactor(1, 2); + layout->addWidget(splitter); + + QHBoxLayout *hlayout = new QHBoxLayout; + hlayout->setContentsMargins(0,0,0,0); + hlayout->addStretch(2); + hlayout->setSpacing(0); + layout->addLayout(hlayout); + QSpinBox *x = new QSpinBox(this); + x->setSingleStep(50); + x->setMaximum(10000); + x->setMinimum(-10000); + QObject::connect(x, SIGNAL(valueChanged(int)), this, SLOT(setX(int))); + QSpinBox *y = new QSpinBox(this); + y->setSingleStep(50); + y->setMaximum(10000); + y->setMinimum(-10000); + QObject::connect(y, SIGNAL(valueChanged(int)), this, SLOT(setY(int))); + hlayout->addWidget(x); + hlayout->addWidget(y); + QPushButton *pb = new QPushButton(tr("Refresh"), this); + QObject::connect(pb, SIGNAL(clicked()), this, SLOT(refresh())); + hlayout->addWidget(pb); +} + +void CanvasScene::refresh() +{ + client->sendMessage(QByteArray()); +} + +void CanvasScene::itemExpanded(QTreeWidgetItem *i) +{ + QmlCanvasDebuggerItem *item = static_cast(i); + if(item->me) + item->me->setOpacity(1); +} + +void CanvasScene::setOpacityRecur(QTreeWidgetItem *i, qreal op) +{ + QmlCanvasDebuggerItem *item = static_cast(i); + if(item->img) + item->img->setOpacity(op); + + for(int ii = 0; ii < item->childCount(); ++ii) + setOpacityRecur(item->child(ii), op); +} + +void CanvasScene::itemClicked(QTreeWidgetItem *i) +{ + QmlCanvasDebuggerItem *item = static_cast(i); + + if(m_selected) { + setOpacityRecur(m_selected, 0); + m_selected = 0; + } + + m_selected = item; + setOpacityRecur(m_selected, 1); +} + +void CanvasScene::itemCollapsed(QTreeWidgetItem *i) +{ + QmlCanvasDebuggerItem *item = static_cast(i); + if(item->me) + item->me->setOpacity(0); +} + +void CanvasScene::setX(int x) +{ + m_canvasRoot->setX(x); +} + +void CanvasScene::setY(int y) +{ + m_canvasRoot->setY(y); +} + diff --git a/tools/qmldebugger/canvasscene.h b/tools/qmldebugger/canvasscene.h new file mode 100644 index 0000000..d980241 --- /dev/null +++ b/tools/qmldebugger/canvasscene.h @@ -0,0 +1,39 @@ +#ifndef CANVASSCENE_H +#define CANVASSCENE_H + +#include +#include +#include +#include + +class QmlDebugClient; +class CanvasSceneClient; +class QmlDebugClientPlugin; +class CanvasScene : public QWidget +{ +Q_OBJECT +public: + CanvasScene(QmlDebugClient *, QWidget *parent = 0); + + void message(QDataStream &); +private slots: + void refresh(); + void itemClicked(QTreeWidgetItem *); + void itemExpanded(QTreeWidgetItem *); + void itemCollapsed(QTreeWidgetItem *); + void setX(int); + void setY(int); + +private: + void setOpacityRecur(QTreeWidgetItem *, qreal); + void clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, QDataStream &); + QmlDebugClientPlugin *client; + + QTreeWidget *m_tree; + QSimpleCanvas *m_canvas; + QSimpleCanvasItem *m_canvasRoot; + QTreeWidgetItem *m_selected; +}; + +#endif // CANVASSCENE_H + diff --git a/tools/qmldebugger/main.cpp b/tools/qmldebugger/main.cpp index 2c5be6c..5b94cbb 100644 --- a/tools/qmldebugger/main.cpp +++ b/tools/qmldebugger/main.cpp @@ -8,11 +8,13 @@ #include #include #include "canvasframerate.h" +#include "canvasscene.h" #include #include #include #include #include +#include class Shell : public QWidget { @@ -23,10 +25,12 @@ public: private slots: void connectToHost(); void disconnectFromHost(); + void connectionStateChanged(); private: QmlDebugClient client; + QLabel *m_connectionState; QLineEdit *m_host; QSpinBox *m_port; QPushButton *m_connectButton; @@ -44,8 +48,10 @@ Shell::Shell(QWidget *parent) layout->addLayout(connectLayout); connectLayout->addStretch(2); + m_connectionState = new QLabel(this); + connectLayout->addWidget(m_connectionState); m_host = new QLineEdit(this); - m_host->setText("localhost"); + m_host->setText("127.0.0.1"); connectLayout->addWidget(m_host); m_port = new QSpinBox(this); m_port->setMinimum(1024); @@ -67,33 +73,61 @@ Shell::Shell(QWidget *parent) CanvasFrameRate *cfr = new CanvasFrameRate(&client, this); tabs->addTab(cfr, tr("Frame Rate")); + + CanvasScene *cs = new CanvasScene(&client, this); + tabs->addTab(cs, tr("Scene")); + + QObject::connect(&client, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(connectionStateChanged())); + connectionStateChanged(); +} + +void Shell::connectionStateChanged() +{ + switch (client.state()) { + default: + case QAbstractSocket::UnconnectedState: + m_connectionState->setText(tr("Disconnected")); + m_connectButton->setEnabled(true); + m_disconnectButton->setEnabled(false); + break; + case QAbstractSocket::HostLookupState: + m_connectionState->setText(tr("Resolving")); + m_connectButton->setEnabled(false); + m_disconnectButton->setEnabled(true); + break; + case QAbstractSocket::ConnectingState: + m_connectionState->setText(tr("Connecting")); + m_connectButton->setEnabled(false); + m_disconnectButton->setEnabled(true); + break; + case QAbstractSocket::ConnectedState: + m_connectionState->setText(tr("Connected")); + m_connectButton->setEnabled(false); + m_disconnectButton->setEnabled(true); + break; + case QAbstractSocket::ClosingState: + m_connectionState->setText(tr("Closing")); + m_connectButton->setEnabled(false); + m_disconnectButton->setEnabled(false); + break; + } } void Shell::connectToHost() { - m_connectButton->setEnabled(false); - m_disconnectButton->setEnabled(true); client.connectToHost(m_host->text(), m_port->value()); } void Shell::disconnectFromHost() { - m_connectButton->setEnabled(true); - m_disconnectButton->setEnabled(false); client.disconnectFromHost(); } int main(int argc, char ** argv) { - if(argc != 3) { - qWarning() << "Usage:" << argv[0] << "host port"; - return -1; - } - QApplication app(argc, argv); Shell shell; -// shell.setFixedSize(1024, 768); shell.show(); diff --git a/tools/qmldebugger/qmldebugger.pro b/tools/qmldebugger/qmldebugger.pro index 6af2909..757ba12 100644 --- a/tools/qmldebugger/qmldebugger.pro +++ b/tools/qmldebugger/qmldebugger.pro @@ -1,8 +1,8 @@ DESTDIR = ../../bin QT += network declarative # Input -HEADERS += canvasframerate.h -SOURCES += main.cpp canvasframerate.cpp +HEADERS += canvasframerate.h canvasscene.h +SOURCES += main.cpp canvasframerate.cpp canvasscene.cpp target.path=$$[QT_INSTALL_BINS] INSTALLS += target -- cgit v0.12