From d107f39df40990d4cbd1fc5983c5de7ae46bb374 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 30 Apr 2009 14:09:20 +1000 Subject: More work on transform elements. AxisRotation/AxisTranslation have been renamed Rotation3D/Translation3D. Squish has gained a raster implementation and basic docs. --- doc/src/declarative/pics/squish.png | Bin 0 -> 8590 bytes src/declarative/fx/qfxflipable.cpp | 2 +- src/declarative/fx/qfxtransform.cpp | 202 +++++++++++++++++++++++------------- src/declarative/fx/qfxtransform.h | 22 ++-- 4 files changed, 137 insertions(+), 89 deletions(-) create mode 100644 doc/src/declarative/pics/squish.png diff --git a/doc/src/declarative/pics/squish.png b/doc/src/declarative/pics/squish.png new file mode 100644 index 0000000..73bf292 Binary files /dev/null and b/doc/src/declarative/pics/squish.png differ diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp index 1d15827..81ed750 100644 --- a/src/declarative/fx/qfxflipable.cpp +++ b/src/declarative/fx/qfxflipable.cpp @@ -58,7 +58,7 @@ public: QFxItem *front; QFxItem *back; QFxAxis *axis; - QFxRotation axisRotation; + QFxRotation3D axisRotation; qreal rotation; }; diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp index c355158..2bed170 100644 --- a/src/declarative/fx/qfxtransform.cpp +++ b/src/declarative/fx/qfxtransform.cpp @@ -178,8 +178,8 @@ void QFxAxis::setEndZ(qreal z) } /*! - \qmlclass AxisRotation - \brief The AxisRotation element provides a way to rotate an Item around an axis. + \qmlclass Rotation3D + \brief The Rotation3D element provides a way to rotate an Item around an axis. Here is an example of various rotations applied to an \l Image. \code @@ -187,22 +187,22 @@ void QFxAxis::setEndZ(qreal z) - + - + - + - + @@ -211,58 +211,58 @@ void QFxAxis::setEndZ(qreal z) \image axisrotation.png */ -QML_DEFINE_TYPE(QFxRotation,AxisRotation); +QML_DEFINE_TYPE(QFxRotation3D,Rotation3D); -QFxRotation::QFxRotation(QObject *parent) -: QFxTransform(parent), _angle(0), _distanceToPlane(1024.), _dirty(true) +QFxRotation3D::QFxRotation3D(QObject *parent) +: QFxTransform(parent), _angle(0), _dirty(true) { connect(&_axis, SIGNAL(updated()), this, SLOT(update())); } -QFxRotation::~QFxRotation() +QFxRotation3D::~QFxRotation3D() { } /*! - \qmlproperty real AxisRotation::axis.startX - \qmlproperty real AxisRotation::axis.startY - \qmlproperty real AxisRotation::axis.endX - \qmlproperty real AxisRotation::axis.endY - \qmlproperty real AxisRotation::axis.endZ + \qmlproperty real Rotation3D::axis.startX + \qmlproperty real Rotation3D::axis.startY + \qmlproperty real Rotation3D::axis.endX + \qmlproperty real Rotation3D::axis.endY + \qmlproperty real Rotation3D::axis.endZ A rotation axis is specified by 2 points in 3D space: a start point and an end point. The z-position of the start point is assumed to be 0, and cannot be changed. */ -QFxAxis *QFxRotation::axis() +QFxAxis *QFxRotation3D::axis() { return &_axis; } /*! - \qmlproperty real AxisRotation::angle + \qmlproperty real Rotation3D::angle The angle, in degrees, to rotate around the specified axis. */ -qreal QFxRotation::angle() const +qreal QFxRotation3D::angle() const { return _angle; } -void QFxRotation::setAngle(qreal angle) +void QFxRotation3D::setAngle(qreal angle) { _angle = angle; update(); } -bool QFxRotation::isIdentity() const +bool QFxRotation3D::isIdentity() const { return (_angle == 0.) || (_axis.endZ() == 0. && _axis.endY() == _axis.startY() && _axis.endX() == _axis.startX()); } #if defined(QFX_RENDER_QPAINTER) const qreal inv_dist_to_plane = 1. / 1024.; -QTransform QFxRotation::transform() const +QTransform QFxRotation3D::transform() const { if (_dirty) { _transform = QTransform(); @@ -282,10 +282,6 @@ QTransform QFxRotation::transform() const qreal y = _axis.endY() - _axis.startY(); qreal z = _axis.endZ(); - qreal idtp = inv_dist_to_plane; - if (distanceToPlane() != 1024.) - idtp = 1. / distanceToPlane(); - qreal len = x * x + y * y + z * z; if (len != 1.) { len = ::sqrt(len); @@ -294,8 +290,8 @@ QTransform QFxRotation::transform() const z /= len; } - QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*idtp, - y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*idtp, + QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane, + y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane, 0, 0, 1); _transform *= rotTrans; @@ -310,7 +306,7 @@ QTransform QFxRotation::transform() const return _transform; } #elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxRotation::transform() const +QMatrix4x4 QFxRotation3D::transform() const { if (_dirty) { _dirty = false; @@ -333,21 +329,7 @@ QMatrix4x4 QFxRotation::transform() const } #endif -/*! - \qmlproperty real AxisRotation::distanceToPlane -*/ -qreal QFxRotation::distanceToPlane() const -{ - return _distanceToPlane; -} - -void QFxRotation::setDistanceToPlane(qreal d) -{ - _distanceToPlane = d; - update(); -} - -void QFxRotation::update() +void QFxRotation3D::update() { _dirty = true; QFxItem *item = qobject_cast(parent()); @@ -356,77 +338,77 @@ void QFxRotation::update() } /*! - \qmlclass AxisTranslation - \brief The AxisTranslation element provides a way to move an Item along an axis. + \qmlclass Translation3D + \brief The Translation3D element provides a way to move an Item along an axis. The following example translates the image to 10, 3. \code - + \endcode */ -QML_DEFINE_TYPE(QFxTranslation,AxisTranslation); +QML_DEFINE_TYPE(QFxTranslation3D,Translation3D); -QFxTranslation::QFxTranslation(QObject *parent) +QFxTranslation3D::QFxTranslation3D(QObject *parent) : QFxTransform(parent), _distance(0), _dirty(true) { connect(&_axis, SIGNAL(updated()), this, SLOT(update())); } -QFxTranslation::~QFxTranslation() +QFxTranslation3D::~QFxTranslation3D() { } /*! - \qmlproperty real AxisTranslation::axis.startX - \qmlproperty real AxisTranslation::axis.startY - \qmlproperty real AxisTranslation::axis.endX - \qmlproperty real AxisTranslation::axis.endY - \qmlproperty real AxisTranslation::axis.endZ + \qmlproperty real Translation3D::axis.startX + \qmlproperty real Translation3D::axis.startY + \qmlproperty real Translation3D::axis.endX + \qmlproperty real Translation3D::axis.endY + \qmlproperty real Translation3D::axis.endZ A translation axis is specified by 2 points in 3D space: a start point and an end point. The z-position of the start point is assumed to be 0, and cannot be changed. Changing the z-position of the end point is only valid when running under OpenGL. */ -QFxAxis *QFxTranslation::axis() +QFxAxis *QFxTranslation3D::axis() { return &_axis; } /*! - \qmlproperty real AxisTranslation::distance + \qmlproperty real Translation3D::distance The distance to translate along the specified axis. distance is a multiplier; in the example below, a distance of 1 would translate to 100, 50, while a distance of 0.5 would translate to 50, 25. \code - + \endcode */ -qreal QFxTranslation::distance() const +qreal QFxTranslation3D::distance() const { return _distance; } -void QFxTranslation::setDistance(qreal distance) +void QFxTranslation3D::setDistance(qreal distance) { _distance = distance; update(); } -bool QFxTranslation::isIdentity() const +bool QFxTranslation3D::isIdentity() const { return (_distance == 0.) || (_axis.endZ() == 0. && _axis.endY() == _axis.startY() && _axis.endX() == _axis.startX()); } #if defined(QFX_RENDER_QPAINTER) -QTransform QFxTranslation::transform() const +QTransform QFxTranslation3D::transform() const { if (_dirty) { _transform = QTransform(); @@ -446,7 +428,7 @@ QTransform QFxTranslation::transform() const return _transform; } #elif defined(QFX_RENDER_OPENGL) -QMatrix4x4 QFxRotation::transform() const +QMatrix4x4 QFxTranslation3D::transform() const { if (_dirty) { _dirty = false; @@ -465,7 +447,7 @@ QMatrix4x4 QFxRotation::transform() const } #endif -void QFxTranslation::update() +void QFxTranslation3D::update() { _dirty = true; @@ -541,8 +523,62 @@ QMatrix4x4 QFxPerspective::transform() const \qmlclass Squish \brief The Squish element allows you to distort an items appearance by 'squishing' it. - A Squish transform only affects an item when running under OpenGL; when running under software - rasterization it has no effect. + Here is an example of various \l Image squishes. + \code + Rect { + id: Screen + width: 360; height: 80 + color: "white" + + HorizontalLayout { + margin: 10 + spacing: 10 + Image { src: "qt.png" } + Image { + src: "qt.png" + transform: Squish { + x:0; y:0; width:60; height:60 + topLeftX:0; topLeftY:0 + topRightX:50; topRightY:10 + bottomLeftX:0; bottomLeftY:60 + bottomRightX: 60; bottomRightY:60 + } + } + Image { + src: "qt.png" + transform: Squish { + x:0; y:0; width:60; height:60 + topLeftX:0; topLeftY:0 + topRightX:50; topRightY:0 + bottomLeftX:10; bottomLeftY:50 + bottomRightX: 60; bottomRightY:60 + } + } + Image { + src: "qt.png" + transform: Squish { + x:0; y:0; width:60; height:60 + topLeftX:0; topLeftY:10 + topRightX:60; topRightY:10 + bottomLeftX:0; bottomLeftY:50 + bottomRightX: 60; bottomRightY:50 + } + } + Image { + src: "qt.png" + transform: Squish { + x:0; y:0; width:60; height:60 + topLeftX:10; topLeftY:0 + topRightX:50; topRightY:0 + bottomLeftX:10; bottomLeftY:60 + bottomRightX: 50; bottomRightY:60 + } + } + } + } + \endcode + + \image squish.png */ QML_DEFINE_TYPE(QFxSquish,Squish); @@ -557,6 +593,11 @@ QFxSquish::~QFxSquish() /*! \qmlproperty real Squish::x + \qmlproperty real Squish::y + \qmlproperty real Squish::width + \qmlproperty real Squish::height + + This is usually set to the original geometry of the item being squished. */ qreal QFxSquish::x() const { @@ -569,9 +610,6 @@ void QFxSquish::setX(qreal v) update(); } -/*! - \qmlproperty real Squish::y -*/ qreal QFxSquish::y() const { return p.y(); @@ -583,9 +621,6 @@ void QFxSquish::setY(qreal v) update(); } -/*! - \qmlproperty real Squish::width -*/ qreal QFxSquish::width() const { return s.width(); @@ -597,9 +632,6 @@ void QFxSquish::setWidth(qreal v) update(); } -/*! - \qmlproperty real Squish::height -*/ qreal QFxSquish::height() const { return s.height(); @@ -614,6 +646,8 @@ void QFxSquish::setHeight(qreal v) /*! \qmlproperty real Squish::topLeftX \qmlproperty real Squish::topLeftY + + The top left point for the squish. */ qreal QFxSquish::topLeft_x() const { @@ -640,6 +674,8 @@ void QFxSquish::settopLeft_y(qreal v) /*! \qmlproperty real Squish::topRightX \qmlproperty real Squish::topRightY + + The top right point for the squish. */ qreal QFxSquish::topRight_x() const { @@ -666,6 +702,8 @@ void QFxSquish::settopRight_y(qreal v) /*! \qmlproperty real Squish::bottomLeftX \qmlproperty real Squish::bottomLeftY + + The bottom left point for the squish. */ qreal QFxSquish::bottomLeft_x() const { @@ -692,6 +730,8 @@ void QFxSquish::setbottomLeft_y(qreal v) /*! \qmlproperty real Squish::bottomRightX \qmlproperty real Squish::bottomRightY + + The bottom right point for the squish. */ qreal QFxSquish::bottomRight_x() const { @@ -722,12 +762,24 @@ void QFxSquish::update() item->updateTransform(); } -#if defined(QFX_RENDER_OPENGL) bool QFxSquish::isIdentity() const { return false; } +#if defined(QFX_RENDER_QPAINTER) +QTransform QFxSquish::transform() const +{ + QPolygonF poly; + poly << p << QPointF(p.x() + s.width(), p.y()) << QPointF(p.x() + s.width(), p.y() + s.height()) << QPointF(p.x(), p.y() + s.height()); + QPolygonF poly2; + poly2 << p1 << p2 << p4 << p3; + + QTransform t; + QTransform::quadToQuad(poly, poly2, t); + return t; +} +#elif defined(QFX_RENDER_OPENGL) QMatrix4x4 QFxSquish::transform() const { QPolygonF poly; diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h index 8a4eab1..14bce9b 100644 --- a/src/declarative/fx/qfxtransform.h +++ b/src/declarative/fx/qfxtransform.h @@ -109,16 +109,15 @@ private: }; QML_DECLARE_TYPE(QFxAxis); -class Q_DECLARATIVE_EXPORT QFxRotation : public QFxTransform +class Q_DECLARATIVE_EXPORT QFxRotation3D : public QFxTransform { Q_OBJECT Q_PROPERTY(QFxAxis *axis READ axis) Q_PROPERTY(qreal angle READ angle WRITE setAngle) - Q_PROPERTY(qreal distanceToPlane READ distanceToPlane WRITE setDistanceToPlane) public: - QFxRotation(QObject *parent=0); - ~QFxRotation(); + QFxRotation3D(QObject *parent=0); + ~QFxRotation3D(); QFxAxis *axis(); @@ -136,22 +135,21 @@ private Q_SLOTS: private: QFxAxis _axis; qreal _angle; - qreal _distanceToPlane; mutable bool _dirty; mutable QSimpleCanvas::Matrix _transform; }; -QML_DECLARE_TYPE(QFxRotation); +QML_DECLARE_TYPE(QFxRotation3D); -class Q_DECLARATIVE_EXPORT QFxTranslation : public QFxTransform +class Q_DECLARATIVE_EXPORT QFxTranslation3D : public QFxTransform { Q_OBJECT Q_PROPERTY(QFxAxis *axis READ axis) Q_PROPERTY(qreal distance READ distance WRITE setDistance) public: - QFxTranslation(QObject *parent=0); - ~QFxTranslation(); + QFxTranslation3D(QObject *parent=0); + ~QFxTranslation3D(); QFxAxis *axis(); @@ -170,7 +168,7 @@ private: mutable bool _dirty; mutable QSimpleCanvas::Matrix _transform; }; -QML_DECLARE_TYPE(QFxTranslation); +QML_DECLARE_TYPE(QFxTranslation3D); class Q_DECLARATIVE_EXPORT QFxPerspective : public QFxTransform { @@ -269,10 +267,8 @@ public: qreal bottomRight_x() const; void setbottomRight_x(qreal); -#if defined(QFX_RENDER_OPENGL) virtual bool isIdentity() const; - virtual QMatrix4x4 transform() const; -#endif + virtual QSimpleCanvas::Matrix transform() const; private: void update(); -- cgit v0.12 From 72afedd7fad133b390cc63fd04e3cf0cee757e2e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 30 Apr 2009 14:58:56 +1000 Subject: Rename duiviewer to qmlviewer. --- doc/src/declarative/examples.qdoc | 9 +- doc/src/declarative/focus.qdoc | 2 +- doc/src/declarative/tutorial1.qdoc | 4 +- doc/src/duiviewer.qdoc | 80 -------- doc/src/qmlviewer.qdoc | 79 ++++++++ doc/src/tutorials/declarative.qdoc | 2 +- tools/duiviewer/duiviewer.pro | 12 -- tools/duiviewer/main.cpp | 135 -------------- tools/duiviewer/qfxviewer.cpp | 367 ------------------------------------- tools/duiviewer/qfxviewer.h | 72 -------- tools/qmlviewer/main.cpp | 135 ++++++++++++++ tools/qmlviewer/qmlviewer.cpp | 366 ++++++++++++++++++++++++++++++++++++ tools/qmlviewer/qmlviewer.h | 72 ++++++++ tools/qmlviewer/qmlviewer.pro | 12 ++ tools/tools.pro | 2 +- 15 files changed, 673 insertions(+), 676 deletions(-) delete mode 100644 doc/src/duiviewer.qdoc create mode 100644 doc/src/qmlviewer.qdoc delete mode 100644 tools/duiviewer/duiviewer.pro delete mode 100644 tools/duiviewer/main.cpp delete mode 100644 tools/duiviewer/qfxviewer.cpp delete mode 100644 tools/duiviewer/qfxviewer.h create mode 100644 tools/qmlviewer/main.cpp create mode 100644 tools/qmlviewer/qmlviewer.cpp create mode 100644 tools/qmlviewer/qmlviewer.h create mode 100644 tools/qmlviewer/qmlviewer.pro diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index e65808f..fa9f05b 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -3,18 +3,18 @@ \target qmlexamples \title QML Examples -A viewer application is included that allows you to quickly explore many of the +A \l {qmlviewer}{viewer} application is included that allows you to quickly explore many of the examples. It has some useful options, revealed by: \code - bin/duiviewer -help + bin/qmlviewer -help \endcode -There are several illustrative XML examples available. From your build +There are several illustrative QML examples available. From your build directory, \code - bin/duiviewer $QT_SOURCE_DIR/examples/declarative/mediabrowser/mediabrowser.qml + bin/qmlviewer $QT_SOURCE_DIR/demos/declarative/phonebrowser/phonebrowser.qml \endcode Many other simple examples can be found under the \c examples/declarative sub @@ -32,5 +32,4 @@ own QML-based applications. software rasterizer, a simple canvas backend is used by default. To use Graphics View instead, set \c QML_USE_GRAPHICSVIEW=1. - */ diff --git a/doc/src/declarative/focus.qdoc b/doc/src/declarative/focus.qdoc index e0d4ca3..fc747a9 100644 --- a/doc/src/declarative/focus.qdoc +++ b/doc/src/declarative/focus.qdoc @@ -48,7 +48,7 @@ element whose text is determined by whether or not it has \e {active focus}. An \l Item requests focus by setting the \c {Item::focus} property to true. For very simple cases simply setting the \c {Item::focus} property is sometimes -sufficient. If we run the following example in the \c duiviewer, we see that +sufficient. If we run the following example in the \c qmlviewer, we see that the \c {} element has \e {active focus} and pressing the \e A, \e B, or \e C keys modifies the text appropriately. diff --git a/doc/src/declarative/tutorial1.qdoc b/doc/src/declarative/tutorial1.qdoc index caadbf5..aa94c06 100644 --- a/doc/src/declarative/tutorial1.qdoc +++ b/doc/src/declarative/tutorial1.qdoc @@ -43,10 +43,10 @@ The \c anchors.horizontalCenter property refers to the horizontal center of an e \section2 Viewing the example -To view what you have created, run the duiviewer (located in the \c bin directory) with your filename as the first argument. For example, to run the provided completed Tutorial 1 example from the install location, you would type: +To view what you have created, run the qmlviewer (located in the \c bin directory) with your filename as the first argument. For example, to run the provided completed Tutorial 1 example from the install location, you would type: \code -bin/duiviewer examples/tutorials/t1/tutorial1.qml +bin/qmlviewer examples/tutorials/t1/tutorial1.qml \endcode [\l tutorial] [Next: \l tutorial2] diff --git a/doc/src/duiviewer.qdoc b/doc/src/duiviewer.qdoc deleted file mode 100644 index f967f87..0000000 --- a/doc/src/duiviewer.qdoc +++ /dev/null @@ -1,80 +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 documentation 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$ -** -****************************************************************************/ - -/*! - \page duiviewer.html - \title Declarative UI Viewer (duiviewer) - \ingroup qttools - \keyword duiviewer - - This page documents the \e{Declarative UI Viewer} for the Qt GUI - toolkit. The \c duiviewer reads an XML format declarative user interface definition - (\c .qml) file - and displays the user interface it describes. - - \section1 Options - - When run with the \c -help option, duiviewer shows available options. - - \section1 Dummy Data - - One use of duiviewer is to allow QML files to be viewed stand-alone, - rather than being loaded from within a Qt program. Qt applications will - usually bind objects and properties into the execution context before - running the QML. To stand-in for such bindings, you can provide dummy - data: create a directory called "dummydata" in the same directory as - the target QML file and create files there with the "qml" extension. - All such files will be loaded as QML objects and bound to the root - context as a property with the name of the file (without ".qml"). - - For example, if the Qt application has a "clock.time" property - that is a qreal from 0 to 86400 representing the number of seconds since - midnight, dummy data for this could be provided by \c dummydata/clock.qml: - \code - - - - - - \endcode - Any QML can be used in the dummy data files. You could even animate the - fictional data! -*/ diff --git a/doc/src/qmlviewer.qdoc b/doc/src/qmlviewer.qdoc new file mode 100644 index 0000000..e8fdec4 --- /dev/null +++ b/doc/src/qmlviewer.qdoc @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation 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$ +** +****************************************************************************/ + +/*! + \page qmlviewer.html + \title Qt Declarative UI Viewer (qmlviewer) + \ingroup qttools + \keyword qmlviewer + + This page documents the \e{Declarative UI Viewer} for the Qt GUI + toolkit. The \c qmlviewer reads a declarative user interface definition + (\c .qml) file and displays the user interface it describes. + + \section1 Options + + When run with the \c -help option, qmlviewer shows available options. + + \section1 Dummy Data + + One use of qmlviewer is to allow QML files to be viewed stand-alone, + rather than being loaded from within a Qt program. Qt applications will + usually bind objects and properties into the execution context before + running the QML. To stand-in for such bindings, you can provide dummy + data: create a directory called "dummydata" in the same directory as + the target QML file and create files there with the "qml" extension. + All such files will be loaded as QML objects and bound to the root + context as a property with the name of the file (without ".qml"). + + For example, if the Qt application has a "clock.time" property + that is a qreal from 0 to 86400 representing the number of seconds since + midnight, dummy data for this could be provided by \c dummydata/clock.qml: + \code + + + + + + \endcode + Any QML can be used in the dummy data files. You could even animate the + fictional data! +*/ diff --git a/doc/src/tutorials/declarative.qdoc b/doc/src/tutorials/declarative.qdoc index 3724b10..16dad6e 100644 --- a/doc/src/tutorials/declarative.qdoc +++ b/doc/src/tutorials/declarative.qdoc @@ -77,7 +77,7 @@ sub directory the files are numbered in an order of increasing features. The code in this example is not compiled, but interpreted at run time. - This means you should use the duiviewer application provided with + This means you should use the qmlviewer application provided with Qt to run the examples. \list diff --git a/tools/duiviewer/duiviewer.pro b/tools/duiviewer/duiviewer.pro deleted file mode 100644 index eae313e..0000000 --- a/tools/duiviewer/duiviewer.pro +++ /dev/null @@ -1,12 +0,0 @@ -DESTDIR = ../../bin -QT += declarative script network sql -# Input -HEADERS += qfxviewer.h -SOURCES += main.cpp qfxviewer.cpp - -include($$QT_SOURCE_TREE/tools/shared/deviceskin/deviceskin.pri) - -target.path=$$[QT_INSTALL_BINS] -INSTALLS += target - -CONFIG += console diff --git a/tools/duiviewer/main.cpp b/tools/duiviewer/main.cpp deleted file mode 100644 index cb4ba05..0000000 --- a/tools/duiviewer/main.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#include "qml.h" -#include "qfxviewer.h" -#include -#include -#include "qfxtestengine.h" -#include - - -void usage() -{ - qWarning("Usage: duiviewer [options] "); - qWarning(" "); - qWarning(" options:"); - qWarning(" -v, -version ............................. display version"); - qWarning(" -frameless ............................... run with no window frame"); - qWarning(" -skin ...................... run with a skin window frame"); - qWarning(" -recorddither ordered|threshold|floyd .... set dither mode used for recording"); - qWarning(" -recordperiod ............. set time between recording frames"); - qWarning(" -autorecord [from-] ...... set recording to start and stop automatically"); - qWarning(" -devicekeys .............................. use numeric keys (see F1)"); - qWarning(" -cache ................................... enable a disk cache of remote content"); - qWarning(" -recordtest .................. record an autotest"); - qWarning(" -runtest ..................... run a previously recorded test"); - qWarning(" "); - qWarning(" Press F1 for interactive help"); - exit(1); -} - -int main(int argc, char ** argv) -{ - //### default to using raster graphics backend for now - int newargc = argc + 2; - char **newargv; - newargv = new char * [newargc]; - for (int i = 0; i < argc; ++i) { - newargv[i] = argv[i]; - if (!qstrcmp(argv[i], "-graphicssystem")) { - newargc -= 2; - break; - } - } - char system[] = "-graphicssystem"; - newargv[argc] = system; - char raster[] = "raster"; - newargv[argc+1] = raster; - - - QApplication app(newargc, newargv); - app.setApplicationName("viewer"); - - bool frameless = false; - QString fileName; - int period = 0; - int autorecord_from = 0; - int autorecord_to = 0; - QString dither = "threshold"; - QString skin; - bool devkeys = false; - bool cache = false; - QFxTestEngine::TestMode testMode = QFxTestEngine::NoTest; - QString testDir; - - for (int i = 1; i < newargc; ++i) { - QString arg = newargv[i]; - if (arg == "-frameless") { - frameless = true; - } else if (arg == "-skin") { - skin = QString(argv[++i]); - } else if (arg == "-cache") { - cache = true; - } else if (arg == "-recordperiod") { - period = QString(argv[++i]).toInt(); - } else if (arg == "-autorecord") { - QString range = QString(argv[++i]); - int dash = range.indexOf('-'); - if (dash > 0) - autorecord_from = range.left(dash).toInt(); - autorecord_to = range.mid(dash+1).toInt(); - } else if (arg == "-devicekeys") { - devkeys = true; - } else if (arg == "-recordtest") { - testMode = QFxTestEngine::RecordTest; - if(i + 1 >= newargc) - usage(); - testDir = newargv[i + 1]; - ++i; - } else if (arg == "-runtest") { - testMode = QFxTestEngine::PlaybackTest; - if(i + 1 >= newargc) - usage(); - testDir = newargv[i + 1]; - ++i; - } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { - fprintf(stderr, "Qt Declarative UI Viewer version %s\n", QT_VERSION_STR); - return 0; - } else if (arg[0] != '-') { - fileName = arg; - } else if (1 || arg == "-help") { - usage(); - } - } - - if (fileName.isEmpty()) - usage(); - - QFxViewer viewer(testMode, testDir, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget); - viewer.setCacheEnabled(cache); - viewer.openXml(fileName); - if (period>0) - viewer.setRecordPeriod(period); - if (autorecord_to) - viewer.setAutoRecord(autorecord_from,autorecord_to); - if (QDir(skin).exists()) - viewer.setSkin(skin); - if (devkeys) - viewer.setDeviceKeys(true); - viewer.setRecordDither(dither); - viewer.show(); - - return app.exec(); -} - diff --git a/tools/duiviewer/qfxviewer.cpp b/tools/duiviewer/qfxviewer.cpp deleted file mode 100644 index b15a8bf..0000000 --- a/tools/duiviewer/qfxviewer.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#include - -#include "qmlbindablevalue.h" -#include "qfxviewer.h" -#include -#include -#include "qml.h" -#include "qperformancelog.h" -#include "qfxtestengine.h" -#include "deviceskin.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QFxViewer::QFxViewer(QFxTestEngine::TestMode testMode, const QString &testDir, QWidget *parent, Qt::WindowFlags flags) - : QWidget(parent, flags) -{ - testEngine = 0; - devicemode = false; - skin = 0; - canvas = 0; - record_autotime = 0; - record_period = 20; - - int width=240; - int height=320; - setAttribute(Qt::WA_OpaquePaintEvent); - setAttribute(Qt::WA_NoSystemBackground); - - canvas = new QFxView(this); - if(testMode != QFxTestEngine::NoTest) - testEngine = new QFxTestEngine(testMode, testDir, canvas, this); - - QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); - canvas->setFixedSize(width, height); - resize(width, height); -} - -void QFxViewer::reload() -{ - openXml(currentFileName); -} - -void QFxViewer::openXml(const QString& fileName) -{ - setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName)); - - canvas->reset(); - - currentFileName = fileName; - QUrl url(fileName); - QFileInfo fi(fileName); - if (fi.exists()) { - url = QUrl::fromLocalFile(fi.absoluteFilePath()); - QmlContext *ctxt = canvas->rootContext(); - QDir dir(fi.path()+"/dummydata", "*.qml"); - QStringList list = dir.entryList(); - for (int i = 0; i < list.size(); ++i) { - QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QmlComponent comp(canvas->engine()); - comp.setData(data, QUrl()); - QObject *dummyData = comp.create(); - if (dummyData) { - qWarning() << "Loaded dummy data:" << dir.filePath(qml); - qml.truncate(qml.length()-4); - ctxt->setContextProperty(qml, dummyData); - dummyData->setParent(this); - } - } - } - - canvas->setUrl(url); - - QTime t; - t.start(); - canvas->execute(); - qWarning() << "Wall startup time:" << t.elapsed(); -#ifdef QTOPIA - show(); -#endif -} - -class PreviewDeviceSkin : public DeviceSkin -{ - Q_OBJECT -public: - explicit PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent); - - void setPreview(QWidget *formWidget); - void setScreenSize(const QSize& size) - { - QMatrix fit; - fit = fit.scale(qreal(size.width())/m_screenSize.width(), - qreal(size.height())/m_screenSize.height()); - setTransform(fit); - } - -private slots: - void slotSkinKeyPressEvent(int code, const QString& text, bool autorep); - void slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep); - void slotPopupMenu(); - -private: - void populateContextMenu(QMenu *menu); - const QSize m_screenSize; -}; - - -PreviewDeviceSkin::PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent) : - DeviceSkin(parameters, parent), - m_screenSize(parameters.screenSize()) -{ - connect(this, SIGNAL(skinKeyPressEvent(int,QString,bool)), - this, SLOT(slotSkinKeyPressEvent(int,QString,bool))); - connect(this, SIGNAL(skinKeyReleaseEvent(int,QString,bool)), - this, SLOT(slotSkinKeyReleaseEvent(int,QString,bool))); - connect(this, SIGNAL(popupMenu()), this, SLOT(slotPopupMenu())); -} - -void PreviewDeviceSkin::setPreview(QWidget *formWidget) -{ - formWidget->setFixedSize(m_screenSize); - formWidget->setParent(this, Qt::SubWindow); - formWidget->setAutoFillBackground(true); - setView(formWidget); -} - -void PreviewDeviceSkin::slotSkinKeyPressEvent(int code, const QString& text, bool autorep) -{ - if (QWidget *focusWidget = QApplication::focusWidget()) { - QKeyEvent e(QEvent::KeyPress,code,0,text,autorep); - QApplication::sendEvent(focusWidget, &e); - } - -} - -void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep) -{ - if (QWidget *focusWidget = QApplication::focusWidget()) { - QKeyEvent e(QEvent::KeyRelease,code,0,text,autorep); - QApplication::sendEvent(focusWidget, &e); - } -} - -void PreviewDeviceSkin::slotPopupMenu() -{ - QMenu menu(this); - populateContextMenu(&menu); - menu.exec(QCursor::pos()); -} - -void PreviewDeviceSkin::populateContextMenu(QMenu *menu) -{ - connect(menu->addAction(tr("&Close")), SIGNAL(triggered()), parentWidget(), SLOT(close())); -} - - -void QFxViewer::setSkin(const QString& skinDirectory) -{ - DeviceSkinParameters parameters; - QString err; - if (parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { - delete skin; - if (!err.isEmpty()) - qWarning() << err; - skin = new PreviewDeviceSkin(parameters,this); - skin->setScreenSize(canvas->size()); - canvas->setParent(skin, Qt::SubWindow); - canvas->setAutoFillBackground(true); - skin->setView(canvas); - delete layout(); - - canvas->show(); - } -} - -void QFxViewer::setAutoRecord(int from, int to) -{ - record_autotime = to-from; - if (from) { - autoStartTimer.start(from,this); - } else { - autoTimer.start(); - setRecording(true); - } -} - -void QFxViewer::setRecordPeriod(int ms) -{ - record_period = ms; -} - -void QFxViewer::sceneResized(QSize size) -{ - if (size.width() > 0 && size.height() > 0) { - canvas->setFixedSize(size.width(), size.height()); - if (skin) - skin->setScreenSize(size); - else - resize(size); - } -} - -void QFxViewer::resizeEvent(QResizeEvent *) -{ - if (!skin) - canvas->setFixedSize(width(),height()); -} - -void QFxViewer::keyPressEvent(QKeyEvent *event) -{ - if (event->key() == Qt::Key_0 && devicemode) - exit(0); - else if (event->key() == Qt::Key_F1 || (event->key() == Qt::Key_1 && devicemode)) { - qDebug() << "F1 - help\n" - << "F2 - toggle GIF recording\n" - << "F3 - take PNG snapshot\n" - << "F4 - show items and state\n" - << "F5 - reload XML\n" - << "F6 - show object tree\n" - << "F7 - show timing\n" - << "F8 - show performance (if available)\n" - << "device keys: 0=quit, 1..8=F1..F8" - ; - } else if (event->key() == Qt::Key_F2 || (event->key() == Qt::Key_2 && devicemode)) { - setRecording(!recordTimer.isActive()); - } else if (event->key() == Qt::Key_F3 || (event->key() == Qt::Key_3 && devicemode)) { - setRecording(!recordTimer.isActive()); - canvas->asImage().save("snapshot.png"); - qDebug() << "Wrote snapshot.png"; - } else if (event->key() == Qt::Key_F4 || (event->key() == Qt::Key_4 && devicemode)) { - canvas->dumpItems(); - canvas->checkState(); - } else if (event->key() == Qt::Key_F5 || (event->key() == Qt::Key_5 && devicemode)) { - reload(); - } else if (event->key() == Qt::Key_F6 || (event->key() == Qt::Key_6 && devicemode)) { - canvas->dumpRoot(); - } else if (event->key() == Qt::Key_F7 || (event->key() == Qt::Key_7 && devicemode)) { - canvas->dumpTiming(); - } else if (event->key() == Qt::Key_F8 || (event->key() == Qt::Key_8 && devicemode)) { - QPerformanceLog::displayData(); - QPerformanceLog::clear(); - } else if (event->key() == Qt::Key_F9) { - if(testEngine) testEngine->save(); - } else if (event->key() == Qt::Key_F10) { - if(testEngine) testEngine->captureFullFrame(); - } - - QWidget::keyPressEvent(event); -} - -void QFxViewer::setRecording(bool on) -{ - if (on == recordTimer.isActive()) - return; - - if (on) { - recordTimer.start(record_period,this); - } else { - recordTimer.stop(); - int frame=0; - QStringList inputs; - qDebug() << "Saving frames..."; - - foreach (QImage* img, frames) { - QString name; - name.sprintf("tmp-frame%04d.png",frame++); - if (record_dither=="ordered") - img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::OrderedDither).save(name); - else if (record_dither=="threshold") - img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::ThresholdDither).save(name); - else if (record_dither=="floyd") - img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither).save(name); - else - img->convertToFormat(QImage::Format_Indexed8).save(name); - inputs << name; - delete img; - } - QString output="animation.gif"; - - QStringList args; - - args << "-delay" << QString::number(record_period/10); - args << inputs; - args << output; - qDebug() << "Converting..." << output; - if (0!=QProcess::execute("convert", args)) { - qWarning() << "Cannot run ImageMagick 'convert' - not converted to gif"; - inputs.clear(); // don't remove them - qDebug() << "Wrote frames tmp-frame*.png"; - } else { - qDebug() << "Compressing..." << output; - if (0!=QProcess::execute("gifsicle", QStringList() << "-O2" << "-o" << output << output)) - qWarning() << "Cannot run 'gifsicle' - not compressed"; - qDebug() << "Wrote" << output; - } - - foreach (QString name, inputs) - QFile::remove(name); - - frames.clear(); - } - qDebug() << "Recording: " << (recordTimer.isActive()?"ON":"OFF"); -} - -void QFxViewer::timerEvent(QTimerEvent *event) -{ - if (event->timerId() == recordTimer.timerId()) { - frames.append(new QImage(canvas->asImage())); - if (record_autotime && autoTimer.elapsed() >= record_autotime) - setRecording(false); - } else if (event->timerId() == autoStartTimer.timerId()) { - autoTimer.start(); - autoStartTimer.stop(); - setRecording(true); - } else { - QWidget::timerEvent(event); - } -} - -void QFxViewer::setDeviceKeys(bool on) -{ - devicemode = on; -} - -void QFxViewer::setCacheEnabled(bool on) -{ - QNetworkAccessManager * nam = canvas->engine()->networkAccessManager(); - if (on == !!nam->cache()) - return; - if (on) { - // Setup a caching network manager - QNetworkDiskCache *cache = new QNetworkDiskCache; - cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-duiviewer-network-cache")); - cache->setMaximumCacheSize(8000000); - nam->setCache(cache); - } else { - nam->setCache(0); - } -} - -#include "qfxviewer.moc" diff --git a/tools/duiviewer/qfxviewer.h b/tools/duiviewer/qfxviewer.h deleted file mode 100644 index 7a190c5..0000000 --- a/tools/duiviewer/qfxviewer.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $TROLLTECH_DUAL_LICENSE$ -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -****************************************************************************/ - -#ifndef QFXVIEWER_H -#define QFXVIEWER_H - -#include -#include -#include -#include -#include - - -class QFxView; -class PreviewDeviceSkin; -class QFxTestEngine; - -class QFxViewer : public QWidget -{ -Q_OBJECT -public: - QFxViewer(QFxTestEngine::TestMode = QFxTestEngine::NoTest, const QString &testDir = QString(), QWidget *parent=0, Qt::WindowFlags flags=0); - - void setRecordDither(const QString& s) { record_dither = s; } - void setRecordPeriod(int ms); - int recordPeriod() const { return record_period; } - void setRecording(bool on); - bool isRecording() const { return recordTimer.isActive(); } - void setAutoRecord(int from, int to); - void setSkin(const QString& skinDirectory); - void setDeviceKeys(bool); - void setCacheEnabled(bool); - -public slots: - void sceneResized(QSize size); - void openXml(const QString& fileName); - void reload(); - -protected: - virtual void keyPressEvent(QKeyEvent *); - virtual void timerEvent(QTimerEvent *); - virtual void resizeEvent(QResizeEvent *); - -private: - QString currentFileName; - PreviewDeviceSkin *skin; - QSize skinscreensize; - QFxView *canvas; - void init(QFxTestEngine::TestMode, const QString &, const QString& fileName); - QBasicTimer recordTimer; - QList frames; - QBasicTimer autoStartTimer; - QTime autoTimer; - QString record_dither; - int record_period; - int record_autotime; - bool devicemode; - - QFxTestEngine *testEngine; -}; - -#endif diff --git a/tools/qmlviewer/main.cpp b/tools/qmlviewer/main.cpp new file mode 100644 index 0000000..c5676ab --- /dev/null +++ b/tools/qmlviewer/main.cpp @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "qml.h" +#include "qmlviewer.h" +#include +#include +#include "qfxtestengine.h" +#include + + +void usage() +{ + qWarning("Usage: qmlviewer [options] "); + qWarning(" "); + qWarning(" options:"); + qWarning(" -v, -version ............................. display version"); + qWarning(" -frameless ............................... run with no window frame"); + qWarning(" -skin ...................... run with a skin window frame"); + qWarning(" -recorddither ordered|threshold|floyd .... set dither mode used for recording"); + qWarning(" -recordperiod ............. set time between recording frames"); + qWarning(" -autorecord [from-] ...... set recording to start and stop automatically"); + qWarning(" -devicekeys .............................. use numeric keys (see F1)"); + qWarning(" -cache ................................... enable a disk cache of remote content"); + qWarning(" -recordtest .................. record an autotest"); + qWarning(" -runtest ..................... run a previously recorded test"); + qWarning(" "); + qWarning(" Press F1 for interactive help"); + exit(1); +} + +int main(int argc, char ** argv) +{ + //### default to using raster graphics backend for now + int newargc = argc + 2; + char **newargv; + newargv = new char * [newargc]; + for (int i = 0; i < argc; ++i) { + newargv[i] = argv[i]; + if (!qstrcmp(argv[i], "-graphicssystem")) { + newargc -= 2; + break; + } + } + char system[] = "-graphicssystem"; + newargv[argc] = system; + char raster[] = "raster"; + newargv[argc+1] = raster; + + + QApplication app(newargc, newargv); + app.setApplicationName("viewer"); + + bool frameless = false; + QString fileName; + int period = 0; + int autorecord_from = 0; + int autorecord_to = 0; + QString dither = "threshold"; + QString skin; + bool devkeys = false; + bool cache = false; + QFxTestEngine::TestMode testMode = QFxTestEngine::NoTest; + QString testDir; + + for (int i = 1; i < newargc; ++i) { + QString arg = newargv[i]; + if (arg == "-frameless") { + frameless = true; + } else if (arg == "-skin") { + skin = QString(argv[++i]); + } else if (arg == "-cache") { + cache = true; + } else if (arg == "-recordperiod") { + period = QString(argv[++i]).toInt(); + } else if (arg == "-autorecord") { + QString range = QString(argv[++i]); + int dash = range.indexOf('-'); + if (dash > 0) + autorecord_from = range.left(dash).toInt(); + autorecord_to = range.mid(dash+1).toInt(); + } else if (arg == "-devicekeys") { + devkeys = true; + } else if (arg == "-recordtest") { + testMode = QFxTestEngine::RecordTest; + if(i + 1 >= newargc) + usage(); + testDir = newargv[i + 1]; + ++i; + } else if (arg == "-runtest") { + testMode = QFxTestEngine::PlaybackTest; + if(i + 1 >= newargc) + usage(); + testDir = newargv[i + 1]; + ++i; + } else if (arg == QLatin1String("-v") || arg == QLatin1String("-version")) { + fprintf(stderr, "Qt Declarative UI Viewer version %s\n", QT_VERSION_STR); + return 0; + } else if (arg[0] != '-') { + fileName = arg; + } else if (1 || arg == "-help") { + usage(); + } + } + + if (fileName.isEmpty()) + usage(); + + QmlViewer viewer(testMode, testDir, 0, frameless ? Qt::FramelessWindowHint : Qt::Widget); + viewer.setCacheEnabled(cache); + viewer.openQml(fileName); + if (period>0) + viewer.setRecordPeriod(period); + if (autorecord_to) + viewer.setAutoRecord(autorecord_from,autorecord_to); + if (QDir(skin).exists()) + viewer.setSkin(skin); + if (devkeys) + viewer.setDeviceKeys(true); + viewer.setRecordDither(dither); + viewer.show(); + + return app.exec(); +} + diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp new file mode 100644 index 0000000..87bebfa --- /dev/null +++ b/tools/qmlviewer/qmlviewer.cpp @@ -0,0 +1,366 @@ +/**************************************************************************** +** +** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include + +#include "qmlbindablevalue.h" +#include "qmlviewer.h" +#include +#include +#include "qml.h" +#include "qperformancelog.h" +#include "qfxtestengine.h" +#include "deviceskin.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QmlViewer::QmlViewer(QFxTestEngine::TestMode testMode, const QString &testDir, QWidget *parent, Qt::WindowFlags flags) + : QWidget(parent, flags) +{ + testEngine = 0; + devicemode = false; + skin = 0; + canvas = 0; + record_autotime = 0; + record_period = 20; + + int width=240; + int height=320; + setAttribute(Qt::WA_OpaquePaintEvent); + setAttribute(Qt::WA_NoSystemBackground); + + canvas = new QFxView(this); + if(testMode != QFxTestEngine::NoTest) + testEngine = new QFxTestEngine(testMode, testDir, canvas, this); + + QObject::connect(canvas, SIGNAL(sceneResized(QSize)), this, SLOT(sceneResized(QSize))); + canvas->setFixedSize(width, height); + resize(width, height); +} + +void QmlViewer::reload() +{ + openQml(currentFileName); +} + +void QmlViewer::openQml(const QString& fileName) +{ + setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(fileName)); + + canvas->reset(); + + currentFileName = fileName; + QUrl url(fileName); + QFileInfo fi(fileName); + if (fi.exists()) { + url = QUrl::fromLocalFile(fi.absoluteFilePath()); + QmlContext *ctxt = canvas->rootContext(); + QDir dir(fi.path()+"/dummydata", "*.qml"); + QStringList list = dir.entryList(); + for (int i = 0; i < list.size(); ++i) { + QString qml = list.at(i); + QFile f(dir.filePath(qml)); + f.open(QIODevice::ReadOnly); + QByteArray data = f.readAll(); + QmlComponent comp(canvas->engine()); + comp.setData(data, QUrl()); + QObject *dummyData = comp.create(); + if (dummyData) { + qWarning() << "Loaded dummy data:" << dir.filePath(qml); + qml.truncate(qml.length()-4); + ctxt->setContextProperty(qml, dummyData); + dummyData->setParent(this); + } + } + } + + canvas->setUrl(url); + + QTime t; + t.start(); + canvas->execute(); + qWarning() << "Wall startup time:" << t.elapsed(); +#ifdef QTOPIA + show(); +#endif +} + +class PreviewDeviceSkin : public DeviceSkin +{ + Q_OBJECT +public: + explicit PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent); + + void setPreview(QWidget *formWidget); + void setScreenSize(const QSize& size) + { + QMatrix fit; + fit = fit.scale(qreal(size.width())/m_screenSize.width(), + qreal(size.height())/m_screenSize.height()); + setTransform(fit); + } + +private slots: + void slotSkinKeyPressEvent(int code, const QString& text, bool autorep); + void slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep); + void slotPopupMenu(); + +private: + void populateContextMenu(QMenu *menu); + const QSize m_screenSize; +}; + + +PreviewDeviceSkin::PreviewDeviceSkin(const DeviceSkinParameters ¶meters, QWidget *parent) : + DeviceSkin(parameters, parent), + m_screenSize(parameters.screenSize()) +{ + connect(this, SIGNAL(skinKeyPressEvent(int,QString,bool)), + this, SLOT(slotSkinKeyPressEvent(int,QString,bool))); + connect(this, SIGNAL(skinKeyReleaseEvent(int,QString,bool)), + this, SLOT(slotSkinKeyReleaseEvent(int,QString,bool))); + connect(this, SIGNAL(popupMenu()), this, SLOT(slotPopupMenu())); +} + +void PreviewDeviceSkin::setPreview(QWidget *formWidget) +{ + formWidget->setFixedSize(m_screenSize); + formWidget->setParent(this, Qt::SubWindow); + formWidget->setAutoFillBackground(true); + setView(formWidget); +} + +void PreviewDeviceSkin::slotSkinKeyPressEvent(int code, const QString& text, bool autorep) +{ + if (QWidget *focusWidget = QApplication::focusWidget()) { + QKeyEvent e(QEvent::KeyPress,code,0,text,autorep); + QApplication::sendEvent(focusWidget, &e); + } + +} + +void PreviewDeviceSkin::slotSkinKeyReleaseEvent(int code, const QString& text, bool autorep) +{ + if (QWidget *focusWidget = QApplication::focusWidget()) { + QKeyEvent e(QEvent::KeyRelease,code,0,text,autorep); + QApplication::sendEvent(focusWidget, &e); + } +} + +void PreviewDeviceSkin::slotPopupMenu() +{ + QMenu menu(this); + populateContextMenu(&menu); + menu.exec(QCursor::pos()); +} + +void PreviewDeviceSkin::populateContextMenu(QMenu *menu) +{ + connect(menu->addAction(tr("&Close")), SIGNAL(triggered()), parentWidget(), SLOT(close())); +} + + +void QmlViewer::setSkin(const QString& skinDirectory) +{ + DeviceSkinParameters parameters; + QString err; + if (parameters.read(skinDirectory,DeviceSkinParameters::ReadAll,&err)) { + delete skin; + if (!err.isEmpty()) + qWarning() << err; + skin = new PreviewDeviceSkin(parameters,this); + skin->setScreenSize(canvas->size()); + canvas->setParent(skin, Qt::SubWindow); + canvas->setAutoFillBackground(true); + skin->setView(canvas); + delete layout(); + + canvas->show(); + } +} + +void QmlViewer::setAutoRecord(int from, int to) +{ + record_autotime = to-from; + if (from) { + autoStartTimer.start(from,this); + } else { + autoTimer.start(); + setRecording(true); + } +} + +void QmlViewer::setRecordPeriod(int ms) +{ + record_period = ms; +} + +void QmlViewer::sceneResized(QSize size) +{ + if (size.width() > 0 && size.height() > 0) { + canvas->setFixedSize(size.width(), size.height()); + if (skin) + skin->setScreenSize(size); + else + resize(size); + } +} + +void QmlViewer::resizeEvent(QResizeEvent *) +{ + if (!skin) + canvas->setFixedSize(width(),height()); +} + +void QmlViewer::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_0 && devicemode) + exit(0); + else if (event->key() == Qt::Key_F1 || (event->key() == Qt::Key_1 && devicemode)) { + qDebug() << "F1 - help\n" + << "F2 - toggle GIF recording\n" + << "F3 - take PNG snapshot\n" + << "F4 - show items and state\n" + << "F5 - reload XML\n" + << "F6 - show object tree\n" + << "F7 - show timing\n" + << "F8 - show performance (if available)\n" + << "device keys: 0=quit, 1..8=F1..F8" + ; + } else if (event->key() == Qt::Key_F2 || (event->key() == Qt::Key_2 && devicemode)) { + setRecording(!recordTimer.isActive()); + } else if (event->key() == Qt::Key_F3 || (event->key() == Qt::Key_3 && devicemode)) { + canvas->asImage().save("snapshot.png"); + qDebug() << "Wrote snapshot.png"; + } else if (event->key() == Qt::Key_F4 || (event->key() == Qt::Key_4 && devicemode)) { + canvas->dumpItems(); + canvas->checkState(); + } else if (event->key() == Qt::Key_F5 || (event->key() == Qt::Key_5 && devicemode)) { + reload(); + } else if (event->key() == Qt::Key_F6 || (event->key() == Qt::Key_6 && devicemode)) { + canvas->dumpRoot(); + } else if (event->key() == Qt::Key_F7 || (event->key() == Qt::Key_7 && devicemode)) { + canvas->dumpTiming(); + } else if (event->key() == Qt::Key_F8 || (event->key() == Qt::Key_8 && devicemode)) { + QPerformanceLog::displayData(); + QPerformanceLog::clear(); + } else if (event->key() == Qt::Key_F9) { + if(testEngine) testEngine->save(); + } else if (event->key() == Qt::Key_F10) { + if(testEngine) testEngine->captureFullFrame(); + } + + QWidget::keyPressEvent(event); +} + +void QmlViewer::setRecording(bool on) +{ + if (on == recordTimer.isActive()) + return; + + if (on) { + recordTimer.start(record_period,this); + } else { + recordTimer.stop(); + int frame=0; + QStringList inputs; + qDebug() << "Saving frames..."; + + foreach (QImage* img, frames) { + QString name; + name.sprintf("tmp-frame%04d.png",frame++); + if (record_dither=="ordered") + img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::OrderedDither).save(name); + else if (record_dither=="threshold") + img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither|Qt::ThresholdDither).save(name); + else if (record_dither=="floyd") + img->convertToFormat(QImage::Format_Indexed8,Qt::PreferDither).save(name); + else + img->convertToFormat(QImage::Format_Indexed8).save(name); + inputs << name; + delete img; + } + QString output="animation.gif"; + + QStringList args; + + args << "-delay" << QString::number(record_period/10); + args << inputs; + args << output; + qDebug() << "Converting..." << output; + if (0!=QProcess::execute("convert", args)) { + qWarning() << "Cannot run ImageMagick 'convert' - not converted to gif"; + inputs.clear(); // don't remove them + qDebug() << "Wrote frames tmp-frame*.png"; + } else { + qDebug() << "Compressing..." << output; + if (0!=QProcess::execute("gifsicle", QStringList() << "-O2" << "-o" << output << output)) + qWarning() << "Cannot run 'gifsicle' - not compressed"; + qDebug() << "Wrote" << output; + } + + foreach (QString name, inputs) + QFile::remove(name); + + frames.clear(); + } + qDebug() << "Recording: " << (recordTimer.isActive()?"ON":"OFF"); +} + +void QmlViewer::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == recordTimer.timerId()) { + frames.append(new QImage(canvas->asImage())); + if (record_autotime && autoTimer.elapsed() >= record_autotime) + setRecording(false); + } else if (event->timerId() == autoStartTimer.timerId()) { + autoTimer.start(); + autoStartTimer.stop(); + setRecording(true); + } else { + QWidget::timerEvent(event); + } +} + +void QmlViewer::setDeviceKeys(bool on) +{ + devicemode = on; +} + +void QmlViewer::setCacheEnabled(bool on) +{ + QNetworkAccessManager * nam = canvas->engine()->networkAccessManager(); + if (on == !!nam->cache()) + return; + if (on) { + // Setup a caching network manager + QNetworkDiskCache *cache = new QNetworkDiskCache; + cache->setCacheDirectory(QDir::tempPath()+QLatin1String("/qml-duiviewer-network-cache")); + cache->setMaximumCacheSize(8000000); + nam->setCache(cache); + } else { + nam->setCache(0); + } +} + +#include "qmlviewer.moc" diff --git a/tools/qmlviewer/qmlviewer.h b/tools/qmlviewer/qmlviewer.h new file mode 100644 index 0000000..0fa879d --- /dev/null +++ b/tools/qmlviewer/qmlviewer.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved. +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef QMLVIEWER_H +#define QMLVIEWER_H + +#include +#include +#include +#include +#include + + +class QFxView; +class PreviewDeviceSkin; +class QFxTestEngine; + +class QmlViewer : public QWidget +{ +Q_OBJECT +public: + QmlViewer(QFxTestEngine::TestMode = QFxTestEngine::NoTest, const QString &testDir = QString(), QWidget *parent=0, Qt::WindowFlags flags=0); + + void setRecordDither(const QString& s) { record_dither = s; } + void setRecordPeriod(int ms); + int recordPeriod() const { return record_period; } + void setRecording(bool on); + bool isRecording() const { return recordTimer.isActive(); } + void setAutoRecord(int from, int to); + void setSkin(const QString& skinDirectory); + void setDeviceKeys(bool); + void setCacheEnabled(bool); + +public slots: + void sceneResized(QSize size); + void openQml(const QString& fileName); + void reload(); + +protected: + virtual void keyPressEvent(QKeyEvent *); + virtual void timerEvent(QTimerEvent *); + virtual void resizeEvent(QResizeEvent *); + +private: + QString currentFileName; + PreviewDeviceSkin *skin; + QSize skinscreensize; + QFxView *canvas; + void init(QFxTestEngine::TestMode, const QString &, const QString& fileName); + QBasicTimer recordTimer; + QList frames; + QBasicTimer autoStartTimer; + QTime autoTimer; + QString record_dither; + int record_period; + int record_autotime; + bool devicemode; + + QFxTestEngine *testEngine; +}; + +#endif diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro new file mode 100644 index 0000000..08d2d2b --- /dev/null +++ b/tools/qmlviewer/qmlviewer.pro @@ -0,0 +1,12 @@ +DESTDIR = ../../bin +QT += declarative script network sql +# Input +HEADERS += qmlviewer.h +SOURCES += main.cpp qmlviewer.cpp + +include($$QT_SOURCE_TREE/tools/shared/deviceskin/deviceskin.pri) + +target.path=$$[QT_INSTALL_BINS] +INSTALLS += target + +CONFIG += console diff --git a/tools/tools.pro b/tools/tools.pro index 12da18c..2c83580 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -24,7 +24,7 @@ mac { SUBDIRS += kmap2qmap -contains(QT_CONFIG, declarative):SUBDIRS += duiviewer qmlconv +contains(QT_CONFIG, declarative):SUBDIRS += qmlviewer qmlconv contains(QT_CONFIG, dbus):SUBDIRS += qdbus !wince*:contains(QT_CONFIG, xmlpatterns): SUBDIRS += xmlpatterns embedded: SUBDIRS += makeqpf -- cgit v0.12