summaryrefslogtreecommitdiffstats
path: root/src/declarative/debugger
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-05-08 09:10:41 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-05-08 09:10:41 (GMT)
commit80c80005c74776a930ec4a1a8fb8af5330073a71 (patch)
tree7689ae517747342394193dffc04624e3b1dd34d5 /src/declarative/debugger
parent5eada373217c4935257a20769ff16b3986cca417 (diff)
downloadQt-80c80005c74776a930ec4a1a8fb8af5330073a71.zip
Qt-80c80005c74776a930ec4a1a8fb8af5330073a71.tar.gz
Qt-80c80005c74776a930ec4a1a8fb8af5330073a71.tar.bz2
Add canvas image capture
Diffstat (limited to 'src/declarative/debugger')
-rw-r--r--src/declarative/debugger/qmlcanvasdebugger.cpp94
-rw-r--r--src/declarative/debugger/qmlcanvasdebugger_p.h5
2 files changed, 90 insertions, 9 deletions
diff --git a/src/declarative/debugger/qmlcanvasdebugger.cpp b/src/declarative/debugger/qmlcanvasdebugger.cpp
index 90ec742..fe57bf4 100644
--- a/src/declarative/debugger/qmlcanvasdebugger.cpp
+++ b/src/declarative/debugger/qmlcanvasdebugger.cpp
@@ -44,27 +44,54 @@
#include <QtDeclarative/qsimplecanvas.h>
#include <QtGui/qboxlayout.h>
#include <QtGui/qpushbutton.h>
+#include <QtGui/qspinbox.h>
#include <QtGui/qsplitter.h>
#include <QtGui/qtreewidget.h>
#include <QtDeclarative/qfxrect.h>
+#include <QtDeclarative/qfximage.h>
QmlCanvasDebugger::QmlCanvasDebugger(QmlWatches *w, QWidget *parent)
-: QWidget(parent), m_watches(w), m_tree(0), m_canvas(0), m_debugCanvas(0)
+: 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("Refresh", this);
QObject::connect(pb, SIGNAL(clicked()), this, SLOT(refresh()));
- layout->addWidget(pb);
+ 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*)));
+ 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);
@@ -80,17 +107,18 @@ class QmlCanvasDebuggerItem : public QTreeWidgetItem
{
public:
QmlCanvasDebuggerItem(QTreeWidget *tree)
- : QTreeWidgetItem(tree), me(0)
+ : QTreeWidgetItem(tree), me(0), img(0)
{
}
QmlCanvasDebuggerItem(QTreeWidgetItem *item)
- : QTreeWidgetItem(item), me(0)
+ : QTreeWidgetItem(item), me(0), img(0)
{
}
QPointer<QObject> them;
QFxRect *me;
+ QFxImage *img;
};
void QmlCanvasDebugger::itemExpanded(QTreeWidgetItem *i)
@@ -100,11 +128,29 @@ void QmlCanvasDebugger::itemExpanded(QTreeWidgetItem *i)
item->me->setOpacity(1);
}
+void QmlCanvasDebugger::setOpacityRecur(QTreeWidgetItem *i, qreal op)
+{
+ QmlCanvasDebuggerItem *item = static_cast<QmlCanvasDebuggerItem *>(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<QmlCanvasDebuggerItem *>(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)
@@ -127,8 +173,13 @@ void QmlCanvasDebugger::clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, QSim
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));
@@ -139,6 +190,20 @@ void QmlCanvasDebugger::clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, QSim
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;
@@ -146,11 +211,22 @@ void QmlCanvasDebugger::clone(QTreeWidgetItem *item, QSimpleCanvasItem *me, QSim
}
}
+void QmlCanvasDebugger::setX(int x)
+{
+ m_canvasRoot->setX(x);
+}
+
+void QmlCanvasDebugger::setY(int y)
+{
+ m_canvasRoot->setY(y);
+}
+
void QmlCanvasDebugger::setCanvas(QSimpleCanvas *canvas)
{
- QList<QSimpleCanvasItem *> children = m_canvas->root()->children();
+ QList<QSimpleCanvasItem *> children = m_canvasRoot->children();
qDeleteAll(children);
m_tree->clear();
+ m_selected = 0;
m_debugCanvas = canvas;
if(!m_debugCanvas)
@@ -159,6 +235,6 @@ void QmlCanvasDebugger::setCanvas(QSimpleCanvas *canvas)
QTreeWidgetItem *root = new QmlCanvasDebuggerItem(m_tree);
root->setText(0, "Root");
root->setExpanded(true);
- clone(root, m_canvas->root(), m_debugCanvas->root());
+ clone(root, m_canvasRoot, m_debugCanvas->root());
}
diff --git a/src/declarative/debugger/qmlcanvasdebugger_p.h b/src/declarative/debugger/qmlcanvasdebugger_p.h
index 24240ee..80a2322 100644
--- a/src/declarative/debugger/qmlcanvasdebugger_p.h
+++ b/src/declarative/debugger/qmlcanvasdebugger_p.h
@@ -68,14 +68,19 @@ private slots:
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<QSimpleCanvas> m_debugCanvas;
+ QTreeWidgetItem *m_selected;
};
QT_END_NAMESPACE