X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fqmltest%2Fquicktestresult.cpp;h=ff2cf05102b8e98be38d87c14b2708b868e9668c;hb=feb996e3ab44e68082c97102556ea396f5df3f44;hp=d33eab4943f1bb4b1831254e782857396446e865;hpb=784555f3032194a8923d804a8ce84957f113caf6;p=profile%2Fivi%2Fqtdeclarative.git diff --git a/src/qmltest/quicktestresult.cpp b/src/qmltest/quicktestresult.cpp index d33eab4..ff2cf05 100644 --- a/src/qmltest/quicktestresult.cpp +++ b/src/qmltest/quicktestresult.cpp @@ -55,6 +55,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -62,6 +63,57 @@ static const char *globalProgramName = 0; static bool loggingStarted = false; static QBenchmarkGlobalData globalBenchmarkData; +class Q_QUICK_TEST_EXPORT QuickTestImageObject : public QObject +{ + Q_OBJECT +public: + QuickTestImageObject(const QImage& img, QObject *parent = 0) + : QObject(parent) + , m_image(img) + { + } + + ~QuickTestImageObject() {} + +public Q_SLOTS: + int red(int x, int y) const + { + return pixel(x, y).value().red(); + } + + int green(int x, int y) const + { + return pixel(x, y).value().green(); + } + + int blue(int x, int y) const + { + return pixel(x, y).value().blue(); + } + + int alpha(int x, int y) const + { + return pixel(x, y).value().alpha(); + } + + QVariant pixel(int x, int y) const + { + if (m_image.isNull() + || x >= m_image.width() + || y >= m_image.height() + || x < 0 + || y < 0 + || x * y >= m_image.width() * m_image.height()) + return QVariant(); + + const QRgb* pixel = reinterpret_cast(m_image.constScanLine(y)); + pixel += x; + return QColor::fromRgba(*pixel); + } +private: + QImage m_image; +}; + class QuickTestResultPrivate { public: @@ -534,6 +586,17 @@ void QuickTestResult::stopBenchmark() d->benchmarkIter = 0; } +QObject *QuickTestResult::grabImage(QQuickItem *item) +{ + if (item) { + QQuickWindow *window = item->window(); + QImage grabbed = window->grabWindow(); + QRectF rf(item->x(), item->y(), item->width(), item->height()); + rf = rf.intersected(QRectF(0, 0, grabbed.width(), grabbed.height())); + return new QuickTestImageObject(grabbed.copy(rf.toAlignedRect())); + } + return 0; +} namespace QTest { void qtest_qParseArgs(int argc, char *argv[], bool qml); }; @@ -574,4 +637,6 @@ int QuickTestResult::exitCode() #endif } +#include "quicktestresult.moc" + QT_END_NAMESPACE