diff options
1439 files changed, 107138 insertions, 106954 deletions
diff --git a/doc/src/quick/qtquick.qdoc b/doc/src/quick/qtquick.qdoc new file mode 100644 index 0000000000..358e9f8433 --- /dev/null +++ b/doc/src/quick/qtquick.qdoc @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \module QtQuick + \title Qt Quick Module + \ingroup modules + + \brief The Qt Quick module provides classes for embedding Qt Quick + in Qt/C++ applications. + + To include the definitions of the module's classes, use the + following directive: + + \code + #include <QtQuick> + \endcode + + To link against the module, add this line to your \l qmake \c + .pro file: + + \code + QT += quick + \endcode + + For more information on the Qt Quick module, see the + \l{Qt Quick} documentation. +*/ diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp b/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp index e8ccdb7e36..4a13b7a597 100644 --- a/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp @@ -44,7 +44,7 @@ #include <QDeclarativeEngine> #include <QDeclarativeNetworkAccessManagerFactory> -#include <QQuickView> +#include <QtQuick/QQuickView> /* diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro index 74d8db321d..18d7879900 100644 --- a/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/networkaccessmanagerfactory.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = networkaccessmanagerfactory DEPENDPATH += . INCLUDEPATH += . -QT += declarative network +QT += declarative quick network # Input SOURCES += main.cpp diff --git a/examples/declarative/minehunt/main.cpp b/examples/declarative/minehunt/main.cpp index 205835a9c0..5cc49af684 100644 --- a/examples/declarative/minehunt/main.cpp +++ b/examples/declarative/minehunt/main.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include <QtGui/QGuiApplication> -#include <qquickview.h> +#include <QtQuick/qquickview.h> #include <QtDeclarative/QDeclarativeContext> #include <QtDeclarative/QDeclarativeEngine> diff --git a/examples/declarative/minehunt/minehunt.pro b/examples/declarative/minehunt/minehunt.pro index cf928ce333..82dfc0d5bc 100644 --- a/examples/declarative/minehunt/minehunt.pro +++ b/examples/declarative/minehunt/minehunt.pro @@ -1,6 +1,6 @@ TEMPLATE = app TARGET = minehunt -QT += declarative +QT += declarative quick # Input HEADERS += minehunt.h diff --git a/examples/declarative/modelviews/abstractitemmodel/abstractitemmodel.pro b/examples/declarative/modelviews/abstractitemmodel/abstractitemmodel.pro index 6c51eed9d2..eaf2b30c89 100644 --- a/examples/declarative/modelviews/abstractitemmodel/abstractitemmodel.pro +++ b/examples/declarative/modelviews/abstractitemmodel/abstractitemmodel.pro @@ -2,9 +2,9 @@ TEMPLATE = app TARGET = abstractitemmodel DEPENDPATH += . INCLUDEPATH += . -QT += declarative +QT += declarative quick HEADERS = model.h SOURCES = main.cpp \ model.cpp -RESOURCES += abstractitemmodel.qrc
\ No newline at end of file +RESOURCES += abstractitemmodel.qrc diff --git a/examples/declarative/modelviews/abstractitemmodel/main.cpp b/examples/declarative/modelviews/abstractitemmodel/main.cpp index 7924815879..d8c1abc939 100644 --- a/examples/declarative/modelviews/abstractitemmodel/main.cpp +++ b/examples/declarative/modelviews/abstractitemmodel/main.cpp @@ -43,8 +43,8 @@ #include <qdeclarativeengine.h> #include <qdeclarativecontext.h> #include <qdeclarative.h> -#include <qquickitem.h> -#include <qquickview.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/qquickview.h> //![0] int main(int argc, char ** argv) diff --git a/examples/declarative/modelviews/objectlistmodel/main.cpp b/examples/declarative/modelviews/objectlistmodel/main.cpp index 67ffb946c0..fc7252c864 100644 --- a/examples/declarative/modelviews/objectlistmodel/main.cpp +++ b/examples/declarative/modelviews/objectlistmodel/main.cpp @@ -43,8 +43,8 @@ #include <qdeclarativeengine.h> #include <qdeclarativecontext.h> #include <qdeclarative.h> -#include <qquickitem.h> -#include <qquickview.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/qquickview.h> #include "dataobject.h" diff --git a/examples/declarative/modelviews/objectlistmodel/objectlistmodel.pro b/examples/declarative/modelviews/objectlistmodel/objectlistmodel.pro index 8cc293dbfa..434e6f080b 100644 --- a/examples/declarative/modelviews/objectlistmodel/objectlistmodel.pro +++ b/examples/declarative/modelviews/objectlistmodel/objectlistmodel.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = objectlistmodel DEPENDPATH += . INCLUDEPATH += . -QT += declarative +QT += declarative quick # Input SOURCES += main.cpp \ diff --git a/examples/declarative/modelviews/stringlistmodel/main.cpp b/examples/declarative/modelviews/stringlistmodel/main.cpp index ebd3c59307..d5ddbe8fb8 100644 --- a/examples/declarative/modelviews/stringlistmodel/main.cpp +++ b/examples/declarative/modelviews/stringlistmodel/main.cpp @@ -44,8 +44,8 @@ #include <qdeclarativeengine.h> #include <qdeclarativecontext.h> #include <qdeclarative.h> -#include <qquickitem.h> -#include <qquickview.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/qquickview.h> /* diff --git a/examples/declarative/modelviews/stringlistmodel/stringlistmodel.pro b/examples/declarative/modelviews/stringlistmodel/stringlistmodel.pro index 23dc481f88..d34f7d0b56 100644 --- a/examples/declarative/modelviews/stringlistmodel/stringlistmodel.pro +++ b/examples/declarative/modelviews/stringlistmodel/stringlistmodel.pro @@ -2,7 +2,7 @@ TEMPLATE = app TARGET = stringlistmodel DEPENDPATH += . INCLUDEPATH += . -QT += declarative +QT += declarative quick # Input SOURCES += main.cpp diff --git a/examples/declarative/openglunderqml/main.cpp b/examples/declarative/openglunderqml/main.cpp index 44984c5be3..cb65c3feac 100644 --- a/examples/declarative/openglunderqml/main.cpp +++ b/examples/declarative/openglunderqml/main.cpp @@ -41,7 +41,7 @@ #include <QGuiApplication> -#include <QQuickView> +#include <QtQuick/QQuickView> #include "squircle.h" diff --git a/examples/declarative/openglunderqml/openglunderqml.pro b/examples/declarative/openglunderqml/openglunderqml.pro index 3cd167335b..c93ac791fe 100644 --- a/examples/declarative/openglunderqml/openglunderqml.pro +++ b/examples/declarative/openglunderqml/openglunderqml.pro @@ -1,4 +1,4 @@ -QT += declarative +QT += declarative quick TEMPLATE = app DEPENDPATH += . diff --git a/examples/declarative/openglunderqml/squircle.cpp b/examples/declarative/openglunderqml/squircle.cpp index c2d4c0ac97..55c1dd092c 100644 --- a/examples/declarative/openglunderqml/squircle.cpp +++ b/examples/declarative/openglunderqml/squircle.cpp @@ -41,8 +41,8 @@ #include "squircle.h" -#include <qsgengine.h> -#include <qquickcanvas.h> +#include <QtQuick/qsgengine.h> +#include <QtQuick/qquickcanvas.h> #include <QOpenGLShaderProgram> Squircle::Squircle() diff --git a/examples/declarative/openglunderqml/squircle.h b/examples/declarative/openglunderqml/squircle.h index c92c93e2db..ab33c6a25f 100644 --- a/examples/declarative/openglunderqml/squircle.h +++ b/examples/declarative/openglunderqml/squircle.h @@ -42,7 +42,7 @@ #ifndef SQUIRCLE_H #define SQUIRCLE_H -#include <QtDeclarative/QQuickItem> +#include <QtQuick/QQuickItem> #include <QtGui/QOpenGLShaderProgram> class Squircle : public QQuickItem diff --git a/examples/declarative/painteditem/smile/main.cpp b/examples/declarative/painteditem/smile/main.cpp index dc76e71185..0f69f4c962 100644 --- a/examples/declarative/painteditem/smile/main.cpp +++ b/examples/declarative/painteditem/smile/main.cpp @@ -41,8 +41,8 @@ #include <QGuiApplication> #include <QPainter> #include <QtDeclarative/qdeclarative.h> -#include <QtDeclarative/qquickview.h> -#include <QtDeclarative/qquickpainteditem.h> +#include <QtQuick/qquickview.h> +#include <QtQuick/qquickpainteditem.h> class MyPaintItem : public QQuickPaintedItem { Q_OBJECT diff --git a/examples/declarative/painteditem/smile/smile.pro b/examples/declarative/painteditem/smile/smile.pro index 3b9e4e0f62..780d351fe6 100644 --- a/examples/declarative/painteditem/smile/smile.pro +++ b/examples/declarative/painteditem/smile/smile.pro @@ -1,7 +1,7 @@ TEMPLATE = app TARGET = painteditem -QT += declarative +QT += declarative quick macx: CONFIG -= app_bundle diff --git a/examples/declarative/painteditem/textballoons/textballoon.h b/examples/declarative/painteditem/textballoons/textballoon.h index 064d20bd7e..e35107c1b2 100644 --- a/examples/declarative/painteditem/textballoons/textballoon.h +++ b/examples/declarative/painteditem/textballoons/textballoon.h @@ -42,7 +42,7 @@ #ifndef TEXTBALLOON_H #define TEXTBALLOON_H -#include <QtDeclarative> +#include <QtQuick> //! [0] class TextBalloon : public QQuickPaintedItem diff --git a/examples/declarative/painteditem/textballoons/textballoons.pro b/examples/declarative/painteditem/textballoons/textballoons.pro index 3148fd20e6..453a00336d 100644 --- a/examples/declarative/painteditem/textballoons/textballoons.pro +++ b/examples/declarative/painteditem/textballoons/textballoons.pro @@ -1,6 +1,6 @@ TEMPLATE = lib CONFIG += qt plugin -QT += declarative +QT += declarative quick TARGET = qmltextballoonplugin diff --git a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro index 0f0416718c..affc57ce1f 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro +++ b/examples/declarative/tutorials/extending/chapter1-basics/chapter1-basics.pro @@ -1,4 +1,4 @@ -QT += declarative +QT += declarative quick HEADERS += piechart.h SOURCES += piechart.cpp \ diff --git a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp index 2670871e61..c507b2c30c 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/main.cpp +++ b/examples/declarative/tutorials/extending/chapter1-basics/main.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ //![0] #include "piechart.h" -#include <QQuickView> +#include <QtQuick/QQuickView> #include <QGuiApplication> int main(int argc, char *argv[]) diff --git a/examples/declarative/tutorials/extending/chapter1-basics/piechart.h b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h index d1beb71545..1bd3019f7b 100644 --- a/examples/declarative/tutorials/extending/chapter1-basics/piechart.h +++ b/examples/declarative/tutorials/extending/chapter1-basics/piechart.h @@ -41,7 +41,7 @@ #define PIECHART_H //![0] -#include <QtDeclarative/QQuickPaintedItem> +#include <QtQuick/QQuickPaintedItem> #include <QColor> class PieChart : public QQuickPaintedItem diff --git a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro index 0f0416718c..affc57ce1f 100644 --- a/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro +++ b/examples/declarative/tutorials/extending/chapter2-methods/chapter2-methods.pro @@ -1,4 +1,4 @@ -QT += declarative +QT += declarative quick HEADERS += piechart.h SOURCES += piechart.cpp \ diff --git a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp index 2670871e61..c507b2c30c 100644 --- a/examples/declarative/tutorials/extending/chapter2-methods/main.cpp +++ b/examples/declarative/tutorials/extending/chapter2-methods/main.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ //![0] #include "piechart.h" -#include <QQuickView> +#include <QtQuick/QQuickView> #include <QGuiApplication> int main(int argc, char *argv[]) diff --git a/examples/declarative/tutorials/extending/chapter2-methods/piechart.h b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h index 5205151a0a..4ed9e0665c 100644 --- a/examples/declarative/tutorials/extending/chapter2-methods/piechart.h +++ b/examples/declarative/tutorials/extending/chapter2-methods/piechart.h @@ -40,7 +40,7 @@ #ifndef PIECHART_H #define PIECHART_H -#include <QtDeclarative/QQuickPaintedItem> +#include <QtQuick/QQuickPaintedItem> #include <QColor> //![0] diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro index 0f0416718c..affc57ce1f 100644 --- a/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro +++ b/examples/declarative/tutorials/extending/chapter3-bindings/chapter3-bindings.pro @@ -1,4 +1,4 @@ -QT += declarative +QT += declarative quick HEADERS += piechart.h SOURCES += piechart.cpp \ diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp index 2670871e61..c507b2c30c 100644 --- a/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp +++ b/examples/declarative/tutorials/extending/chapter3-bindings/main.cpp @@ -39,7 +39,7 @@ ****************************************************************************/ //![0] #include "piechart.h" -#include <QQuickView> +#include <QtQuick/QQuickView> #include <QGuiApplication> int main(int argc, char *argv[]) diff --git a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h index 55be2a493f..7c5fda2744 100644 --- a/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h +++ b/examples/declarative/tutorials/extending/chapter3-bindings/piechart.h @@ -41,7 +41,7 @@ #define PIECHART_H #include <QColor> -#include <QtDeclarative/QQuickPaintedItem> +#include <QtQuick/QQuickPaintedItem> //![0] class PieChart : public QQuickPaintedItem diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro index c3f5402aea..6724fa0375 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro @@ -1,4 +1,4 @@ -QT += declarative +QT += declarative quick HEADERS += piechart.h \ pieslice.h diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp index c9b9a0b5aa..5d1c4d6839 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/main.cpp @@ -40,7 +40,7 @@ #include "piechart.h" #include "pieslice.h" -#include <QQuickView> +#include <QtQuick/QQuickView> #include <QGuiApplication> //![0] diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h index c1cdf30805..36a866dfc3 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/piechart.h @@ -40,7 +40,7 @@ #ifndef PIECHART_H #define PIECHART_H -#include <QtDeclarative/QQuickItem> +#include <QtQuick/QQuickItem> class PieSlice; diff --git a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h index 59606486a4..23913adf84 100644 --- a/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h +++ b/examples/declarative/tutorials/extending/chapter4-customPropertyTypes/pieslice.h @@ -40,7 +40,7 @@ #ifndef PIESLICE_H #define PIESLICE_H -#include <QtDeclarative/QQuickPaintedItem> +#include <QtQuick/QQuickPaintedItem> #include <QColor> //![0] diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro index c3f5402aea..6724fa0375 100644 --- a/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/chapter5-listproperties.pro @@ -1,4 +1,4 @@ -QT += declarative +QT += declarative quick HEADERS += piechart.h \ pieslice.h diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp index 78f6f25485..afd34455c8 100644 --- a/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/main.cpp @@ -40,7 +40,7 @@ #include "piechart.h" #include "pieslice.h" -#include <QQuickView> +#include <QtQuick/QQuickView> #include <QGuiApplication> int main(int argc, char *argv[]) diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h index feea3d2789..5ba6b10b7a 100644 --- a/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/piechart.h @@ -40,7 +40,7 @@ #ifndef PIECHART_H #define PIECHART_H -#include <QQuickItem> +#include <QtQuick/QQuickItem> class PieSlice; diff --git a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h index 157e9cda77..a9174fbe0c 100644 --- a/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h +++ b/examples/declarative/tutorials/extending/chapter5-listproperties/pieslice.h @@ -40,7 +40,7 @@ #ifndef PIESLICE_H #define PIESLICE_H -#include <QtDeclarative/QQuickPaintedItem> +#include <QtQuick/QQuickPaintedItem> #include <QColor> //![0] diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro index 47fe0a2fde..c243ec4572 100644 --- a/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro +++ b/examples/declarative/tutorials/extending/chapter6-plugins/chapter6-plugins.pro @@ -1,6 +1,6 @@ TEMPLATE = lib CONFIG += qt plugin -QT += declarative +QT += declarative quick DESTDIR = ChartsPlugin TARGET = chartsplugin diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h index 2d58360245..927dc25e5c 100644 --- a/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h +++ b/examples/declarative/tutorials/extending/chapter6-plugins/piechart.h @@ -40,7 +40,7 @@ #ifndef PIECHART_H #define PIECHART_H -#include <QQuickItem> +#include <QtQuick/QQuickItem> class PieSlice; diff --git a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h index 4251e49396..c09b37d1c8 100644 --- a/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h +++ b/examples/declarative/tutorials/extending/chapter6-plugins/pieslice.h @@ -40,7 +40,7 @@ #ifndef PIESLICE_H #define PIESLICE_H -#include <QtDeclarative/QQuickPaintedItem> +#include <QtQuick/QQuickPaintedItem> #include <QColor> class PieSlice : public QQuickPaintedItem diff --git a/modules/qt_quick.pri b/modules/qt_quick.pri new file mode 100644 index 0000000000..0dc827b732 --- /dev/null +++ b/modules/qt_quick.pri @@ -0,0 +1,17 @@ +QT.quick.VERSION = 5.0.0 +QT.quick.MAJOR_VERSION = 5 +QT.quick.MINOR_VERSION = 0 +QT.quick.PATCH_VERSION = 0 + +QT.quick.name = QtQuick +QT.quick.bins = $$QT_MODULE_BIN_BASE +QT.quick.includes = $$QT_MODULE_INCLUDE_BASE $$QT_MODULE_INCLUDE_BASE/QtQuick +QT.quick.private_includes = $$QT_MODULE_INCLUDE_BASE/QtQuick/$$QT.quick.VERSION +QT.quick.sources = $$QT_MODULE_BASE/src/quick +QT.quick.libs = $$QT_MODULE_LIB_BASE +QT.quick.plugins = $$QT_MODULE_PLUGIN_BASE +QT.quick.imports = $$QT_MODULE_IMPORT_BASE +QT.quick.depends = declarative +QT.quick.DEFINES = QT_QUICK_LIB + +QT_CONFIG += quick diff --git a/src/declarative/debugger/qdeclarativeenginedebugservice_p.h b/src/declarative/debugger/qdeclarativeenginedebugservice_p.h index 7c74c63801..c2ee93b665 100644 --- a/src/declarative/debugger/qdeclarativeenginedebugservice_p.h +++ b/src/declarative/debugger/qdeclarativeenginedebugservice_p.h @@ -66,7 +66,7 @@ class QDeclarativeWatcher; class QDataStream; class QDeclarativeDebugStatesDelegate; -class QDeclarativeEngineDebugService : public QDeclarativeDebugService +class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeEngineDebugService : public QDeclarativeDebugService { Q_OBJECT public: diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro index 265e4eba33..ca81a4a3d3 100644 --- a/src/declarative/declarative.pro +++ b/src/declarative/declarative.pro @@ -31,10 +31,3 @@ HEADERS += qtdeclarativeversion.h include(util/util.pri) include(qml/qml.pri) include(debugger/debugger.pri) -include(scenegraph/scenegraph.pri) -include(items/items.pri) -include(particles/particles.pri) -include(designer/designer.pri) - -HEADERS += qtquick2_p.h -SOURCES += qtquick2.cpp diff --git a/src/declarative/designer/designersupport.cpp b/src/declarative/designer/designersupport.cpp deleted file mode 100644 index 9c565c138c..0000000000 --- a/src/declarative/designer/designersupport.cpp +++ /dev/null @@ -1,408 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "designersupport.h" -#include <private/qquickitem_p.h> - -#include <private/qquickshadereffectsource_p.h> -#include <private/qquickrectangle_p.h> -#include <private/qdeclarativeengine_p.h> -#include <private/qquickview_p.h> -#include <private/qdeclarativestategroup_p.h> -#include <QtGui/QImage> - -QT_BEGIN_NAMESPACE - -DesignerSupport::DesignerSupport() -{ -} - -DesignerSupport::~DesignerSupport() -{ - QHash<QQuickItem*, QQuickShaderEffectTexture*>::iterator iterator; - - for (iterator = m_itemTextureHash.begin(); iterator != m_itemTextureHash.end(); ++iterator) { - QQuickShaderEffectTexture *texture = iterator.value(); - QQuickItem *item = iterator.key(); - QQuickItemPrivate::get(item)->derefFromEffectItem(true); - delete texture; - } -} - -void DesignerSupport::refFromEffectItem(QQuickItem *referencedItem, bool hide) -{ - if (referencedItem == 0) - return; - - QQuickItemPrivate::get(referencedItem)->refFromEffectItem(hide); - QQuickCanvasPrivate::get(referencedItem->canvas())->updateDirtyNode(referencedItem); - - Q_ASSERT(QQuickItemPrivate::get(referencedItem)->rootNode); - - if (!m_itemTextureHash.contains(referencedItem)) { - QQuickShaderEffectTexture *texture = new QQuickShaderEffectTexture(referencedItem); - - texture->setLive(true); - texture->setItem(QQuickItemPrivate::get(referencedItem)->rootNode); - texture->setRect(referencedItem->boundingRect()); - texture->setSize(referencedItem->boundingRect().size().toSize()); - texture->setRecursive(true); -#ifndef QT_OPENGL_ES - texture->setFormat(GL_RGBA8); -#else - texture->setFormat(GL_RGBA); -#endif - texture->setHasMipmaps(false); - - m_itemTextureHash.insert(referencedItem, texture); - } -} - -void DesignerSupport::derefFromEffectItem(QQuickItem *referencedItem, bool unhide) -{ - if (referencedItem == 0) - return; - - delete m_itemTextureHash.take(referencedItem); - QQuickItemPrivate::get(referencedItem)->derefFromEffectItem(unhide); -} - -QImage DesignerSupport::renderImageForItem(QQuickItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize) -{ - if (referencedItem == 0 || referencedItem->parentItem() == 0) { - qDebug() << __FILE__ << __LINE__ << "Warning: Item can be rendered."; - return QImage(); - } - - QQuickShaderEffectTexture *renderTexture = m_itemTextureHash.value(referencedItem); - - Q_ASSERT(renderTexture); - if (renderTexture == 0) - return QImage(); - renderTexture->setRect(boundingRect); - renderTexture->setSize(imageSize); - renderTexture->updateTexture(); - - QImage renderImage = renderTexture->toImage(); - renderImage = renderImage.mirrored(false, true); - - if (renderImage.size().isEmpty()) - qDebug() << __FILE__ << __LINE__ << "Warning: Image is empty."; - - return renderImage; -} - -bool DesignerSupport::isDirty(QQuickItem *referencedItem, DirtyType dirtyType) -{ - if (referencedItem == 0) - return false; - - return QQuickItemPrivate::get(referencedItem)->dirtyAttributes & dirtyType; -} - -void DesignerSupport::resetDirty(QQuickItem *referencedItem) -{ - if (referencedItem == 0) - return; - - QQuickItemPrivate::get(referencedItem)->dirtyAttributes = 0x0; - QQuickItemPrivate::get(referencedItem)->removeFromDirtyList(); -} - -QTransform DesignerSupport::canvasTransform(QQuickItem *referencedItem) -{ - if (referencedItem == 0) - return QTransform(); - - return QQuickItemPrivate::get(referencedItem)->itemToCanvasTransform(); -} - -QTransform DesignerSupport::parentTransform(QQuickItem *referencedItem) -{ - if (referencedItem == 0) - return QTransform(); - - QTransform parentTransform; - - QQuickItemPrivate::get(referencedItem)->itemToParentTransform(parentTransform); - - return parentTransform; -} - -QString propertyNameForAnchorLine(const QQuickAnchorLine::AnchorLine &anchorLine) -{ - switch (anchorLine) { - case QQuickAnchorLine::Left: return QLatin1String("left"); - case QQuickAnchorLine::Right: return QLatin1String("right"); - case QQuickAnchorLine::Top: return QLatin1String("top"); - case QQuickAnchorLine::Bottom: return QLatin1String("bottom"); - case QQuickAnchorLine::HCenter: return QLatin1String("horizontalCenter"); - case QQuickAnchorLine::VCenter: return QLatin1String("verticalCenter"); - case QQuickAnchorLine::Baseline: return QLatin1String("baseline"); - case QQuickAnchorLine::Invalid: - default: return QString(); - } -} - -bool isValidAnchorName(const QString &name) -{ - static QStringList anchorNameList(QStringList() << QLatin1String("anchors.top") - << QLatin1String("anchors.left") - << QLatin1String("anchors.right") - << QLatin1String("anchors.bottom") - << QLatin1String("anchors.verticalCenter") - << QLatin1String("anchors.horizontalCenter") - << QLatin1String("anchors.fill") - << QLatin1String("anchors.centerIn") - << QLatin1String("anchors.baseline")); - - return anchorNameList.contains(name); -} - -bool DesignerSupport::isAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem) -{ - Q_ASSERT(dynamic_cast<QQuickItemPrivate*>(QQuickItemPrivate::get(fromItem))); - QQuickItemPrivate *fromItemPrivate = static_cast<QQuickItemPrivate*>(QQuickItemPrivate::get(fromItem)); - QQuickAnchors *anchors = fromItemPrivate->anchors(); - return anchors->fill() == toItem - || anchors->centerIn() == toItem - || anchors->bottom().item == toItem - || anchors->top().item == toItem - || anchors->left().item == toItem - || anchors->right().item == toItem - || anchors->verticalCenter().item == toItem - || anchors->horizontalCenter().item == toItem - || anchors->baseline().item == toItem; -} - -bool DesignerSupport::areChildrenAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem) -{ - foreach (QQuickItem *childItem, fromItem->childItems()) { - if (childItem) { - if (isAnchoredTo(childItem, toItem)) - return true; - - if (areChildrenAnchoredTo(childItem, toItem)) - return true; - } - } - - return false; -} - -QQuickAnchors *anchors(QQuickItem *item) -{ - QQuickItemPrivate *itemPrivate = static_cast<QQuickItemPrivate*>(QQuickItemPrivate::get(item)); - return itemPrivate->anchors(); -} - -QQuickAnchors::Anchor anchorLineFlagForName(const QString &name) -{ - if (name == QLatin1String("anchors.top")) - return QQuickAnchors::TopAnchor; - - if (name == QLatin1String("anchors.left")) - return QQuickAnchors::LeftAnchor; - - if (name == QLatin1String("anchors.bottom")) - return QQuickAnchors::BottomAnchor; - - if (name == QLatin1String("anchors.right")) - return QQuickAnchors::RightAnchor; - - if (name == QLatin1String("anchors.horizontalCenter")) - return QQuickAnchors::HCenterAnchor; - - if (name == QLatin1String("anchors.verticalCenter")) - return QQuickAnchors::VCenterAnchor; - - if (name == QLatin1String("anchors.baseline")) - return QQuickAnchors::BaselineAnchor; - - - Q_ASSERT_X(false, Q_FUNC_INFO, "wrong anchor name - this should never happen"); - return QQuickAnchors::LeftAnchor; -} - -bool DesignerSupport::hasAnchor(QQuickItem *item, const QString &name) -{ - if (!isValidAnchorName(name)) - return false; - - if (name == QLatin1String("anchors.fill")) - return anchors(item)->fill() != 0; - - if (name == QLatin1String("anchors.centerIn")) - return anchors(item)->centerIn() != 0; - - if (name == QLatin1String("anchors.right")) - return anchors(item)->right().item != 0; - - if (name == QLatin1String("anchors.top")) - return anchors(item)->top().item != 0; - - if (name == QLatin1String("anchors.left")) - return anchors(item)->left().item != 0; - - if (name == QLatin1String("anchors.bottom")) - return anchors(item)->bottom().item != 0; - - if (name == QLatin1String("anchors.horizontalCenter")) - return anchors(item)->horizontalCenter().item != 0; - - if (name == QLatin1String("anchors.verticalCenter")) - return anchors(item)->verticalCenter().item != 0; - - if (name == QLatin1String("anchors.baseline")) - return anchors(item)->baseline().item != 0; - - return anchors(item)->usedAnchors().testFlag(anchorLineFlagForName(name)); -} - -QQuickItem *DesignerSupport::anchorFillTargetItem(QQuickItem *item) -{ - return anchors(item)->fill(); -} - -QQuickItem *DesignerSupport::anchorCenterInTargetItem(QQuickItem *item) -{ - return anchors(item)->centerIn(); -} - - - -QPair<QString, QObject*> DesignerSupport::anchorLineTarget(QQuickItem *item, const QString &name, QDeclarativeContext *context) -{ - QObject *targetObject = 0; - QString targetName; - - if (name == QLatin1String("anchors.fill")) { - targetObject = anchors(item)->fill(); - } else if (name == QLatin1String("anchors.centerIn")) { - targetObject = anchors(item)->centerIn(); - } else { - QDeclarativeProperty metaProperty(item, name, context); - if (!metaProperty.isValid()) - return QPair<QString, QObject*>(); - - QQuickAnchorLine anchorLine = metaProperty.read().value<QQuickAnchorLine>(); - if (anchorLine.anchorLine != QQuickAnchorLine::Invalid) { - targetObject = anchorLine.item; - targetName = propertyNameForAnchorLine(anchorLine.anchorLine); - } - - } - - return QPair<QString, QObject*>(targetName, targetObject); -} - -void DesignerSupport::resetAnchor(QQuickItem *item, const QString &name) -{ - if (name == QLatin1String("anchors.fill")) { - anchors(item)->resetFill(); - } else if (name == QLatin1String("anchors.centerIn")) { - anchors(item)->resetCenterIn(); - } else if (name == QLatin1String("anchors.top")) { - anchors(item)->resetTop(); - } else if (name == QLatin1String("anchors.left")) { - anchors(item)->resetLeft(); - } else if (name == QLatin1String("anchors.right")) { - anchors(item)->resetRight(); - } else if (name == QLatin1String("anchors.bottom")) { - anchors(item)->resetBottom(); - } else if (name == QLatin1String("anchors.horizontalCenter")) { - anchors(item)->resetHorizontalCenter(); - } else if (name == QLatin1String("anchors.verticalCenter")) { - anchors(item)->resetVerticalCenter(); - } else if (name == QLatin1String("anchors.baseline")) { - anchors(item)->resetBaseline(); - } -} - -QList<QObject*> DesignerSupport::statesForItem(QQuickItem *item) -{ - QList<QObject*> objectList; - QList<QDeclarativeState *> stateList = QQuickItemPrivate::get(item)->_states()->states(); - qCopy(stateList.begin(), stateList.end(), objectList.begin()); - - return objectList; -} - -bool DesignerSupport::isComponentComplete(QQuickItem *item) -{ - return static_cast<QQuickItemPrivate*>(QQuickItemPrivate::get(item))->componentComplete; -} - -int DesignerSupport::borderWidth(QQuickItem *item) -{ - QQuickRectangle *rectangle = qobject_cast<QQuickRectangle*>(item); - if (rectangle) - return rectangle->border()->width(); - - return 0; -} - -void DesignerSupport::refreshExpressions(QDeclarativeContext *context) -{ - QDeclarativeContextPrivate::get(context)->data->refreshExpressions(); -} - -void DesignerSupport::setRootItem(QQuickView *view, QQuickItem *item) -{ - QQuickViewPrivate::get(view)->setRootObject(item); -} - -bool DesignerSupport::isValidWidth(QQuickItem *item) -{ - return QQuickItemPrivate::get(item)->heightValid; -} - -bool DesignerSupport::isValidHeight(QQuickItem *item) -{ - return QQuickItemPrivate::get(item)->widthValid; -} - -void DesignerSupport::updateDirtyNode(QQuickItem *item) -{ - QQuickCanvasPrivate::get(item->canvas())->updateDirtyNode(item); -} - -QT_END_NAMESPACE diff --git a/src/declarative/designer/designersupport.h b/src/declarative/designer/designersupport.h deleted file mode 100644 index 7654363276..0000000000 --- a/src/declarative/designer/designersupport.h +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef DESIGNERSUPPORT_H -#define DESIGNERSUPPORT_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - - -#include <QtCore/QtGlobal> -#include <QtCore/QHash> -#include <QtCore/QRectF> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItem; -class QQuickShaderEffectTexture; -class QImage; -class QTransform; -class QDeclarativeContext; -class QQuickView; - - -class Q_DECLARATIVE_EXPORT DesignerSupport -{ -public: - enum DirtyType { - TransformOrigin = 0x00000001, - Transform = 0x00000002, - BasicTransform = 0x00000004, - Position = 0x00000008, - Size = 0x00000010, - - ZValue = 0x00000020, - Content = 0x00000040, - Smooth = 0x00000080, - OpacityValue = 0x00000100, - ChildrenChanged = 0x00000200, - ChildrenStackingChanged = 0x00000400, - ParentChanged = 0x00000800, - - Clip = 0x00001000, - Canvas = 0x00002000, - - EffectReference = 0x00008000, - Visible = 0x00010000, - HideReference = 0x00020000, - - TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas, - ComplexTransformUpdateMask = Transform | Canvas, - ContentUpdateMask = Size | Content | Smooth | Canvas, - ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas - }; - - - DesignerSupport(); - ~DesignerSupport(); - - void refFromEffectItem(QQuickItem *referencedItem, bool hide = true); - void derefFromEffectItem(QQuickItem *referencedItem, bool unhide = true); - - QImage renderImageForItem(QQuickItem *referencedItem, const QRectF &boundingRect, const QSize &imageSize); - - static bool isDirty(QQuickItem *referencedItem, DirtyType dirtyType); - static void resetDirty(QQuickItem *referencedItem); - - static QTransform canvasTransform(QQuickItem *referencedItem); - static QTransform parentTransform(QQuickItem *referencedItem); - - static bool isAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem); - static bool areChildrenAnchoredTo(QQuickItem *fromItem, QQuickItem *toItem); - static bool hasAnchor(QQuickItem *item, const QString &name); - static QQuickItem *anchorFillTargetItem(QQuickItem *item); - static QQuickItem *anchorCenterInTargetItem(QQuickItem *item); - static QPair<QString, QObject*> anchorLineTarget(QQuickItem *item, const QString &name, QDeclarativeContext *context); - static void resetAnchor(QQuickItem *item, const QString &name); - - - static QList<QObject*> statesForItem(QQuickItem *item); - - static bool isComponentComplete(QQuickItem *item); - - static int borderWidth(QQuickItem *item); - - static void refreshExpressions(QDeclarativeContext *context); - - static void setRootItem(QQuickView *view, QQuickItem *item); - - static bool isValidWidth(QQuickItem *item); - static bool isValidHeight(QQuickItem *item); - - static void updateDirtyNode(QQuickItem *item); - -private: - QHash<QQuickItem*, QQuickShaderEffectTexture*> m_itemTextureHash; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // DESIGNERSUPPORT_H diff --git a/src/declarative/items/context2d/qquickcanvasitem.cpp b/src/declarative/items/context2d/qquickcanvasitem.cpp deleted file mode 100644 index 81b7a49722..0000000000 --- a/src/declarative/items/context2d/qquickcanvasitem.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <private/qsgadaptationlayer_p.h> -#include "qquickcanvasitem_p.h" -#include <private/qquickitem_p.h> -#include "qquickcontext2d_p.h" -#include "qquickcontext2dnode_p.h" -#include "qquickcontext2dtexture_p.h" -#include <private/qdeclarativepixmapcache_p.h> - -#include <qdeclarativeinfo.h> -#include <private/qdeclarativeengine_p.h> -#include <QtCore/QBuffer> - -QT_BEGIN_NAMESPACE - -class QQuickCanvasItemPrivate : public QQuickItemPrivate -{ -public: - QQuickCanvasItemPrivate(); - ~QQuickCanvasItemPrivate(); - QQuickContext2D* context; - QQuickContext2DTexture* texture; - QSizeF canvasSize; - QSize tileSize; - QRectF canvasWindow; - QRectF dirtyRect; - uint renderInThread : 1; - uint hasCanvasSize :1; - uint hasTileSize :1; - uint hasCanvasWindow :1; - uint componentCompleted :1; - QQuickCanvasItem::RenderTarget renderTarget; - QHash<QUrl, QDeclarativePixmap*> images; - QUrl baseUrl; -}; - -QQuickCanvasItemPrivate::QQuickCanvasItemPrivate() - : QQuickItemPrivate() - , context(0) - , texture(0) - , canvasSize(1, 1) - , tileSize(1, 1) - , renderInThread(false) - , hasCanvasSize(false) - , hasTileSize(false) - , hasCanvasWindow(false) - , componentCompleted(false) - , renderTarget(QQuickCanvasItem::FramebufferObject) -{ -} - -QQuickCanvasItemPrivate::~QQuickCanvasItemPrivate() -{ - qDeleteAll(images); -} - -/*! - \qmlclass Canvas QQuickCanvasItem - \inqmlmodule QtQuick 2 - \since QtQuick 2.0 - \brief The Canvas item provides a 2D canvas element which enables drawing via Javascript. - \inherits Item - \ingroup qml-basic-visual-elements - - The Canvas item allows drawing of straight and curved lines, simple and - complex shapes, graphs, and referenced graphic images. It can also add text, colors, - shadows, gradients, and patterns, and do low level pixel operations. The Canvas - output may be saved as an image file or serialized to a url. - - To define a drawing area in the Canvas item set the \c width and \c height properties. - For example, the following code creates a Canvas item which has a drawing area with a height of 100 - pixels and width of 200 pixels: - \qml - import QtQuick 2.0 - Canvas { - id:mycanvas - width:100 - height:200 - } - \endqml - - Currently the Canvas item only supports the two-dimensional rendering context. - - \section1 Threaded Rendering and Render Target - - The Canvas item supports two render targets: \c Canvas.Image and \c Canvas.FramebufferObject. - - The \c Canvas.Image render target is a \a QImage object. This render target supports background - thread rendering, allowing complex or long running painting to be executed without blocking the UI. - - The Canvas.FramebufferObject render target utilizes OpenGL hardware accelaration rather than rendering into - system memory, which in many cases results in faster rendering. - - The default render target is Canvas.Image and the default renderInThread property is - false. - - \section1 Tiled Canvas - The Canvas item supports tiled rendering by setting \l canvasSize, \l tileSize - and \l canvasWindow properties. - - Tiling allows efficient display of a very large virtual via a smaller canvas - window. The actual memory consumption is in relatation to the canvas window size. The painting - code can draw within the virtual canvas without handling coordinate system transformations. - - The tiles overlapping with the canvas window may be cached eliminating the need to redraw, - which can lead to significantly improved performance in some situations. - - \section1 Pixel Operations - All HTML5 2D context pixel operations are supported. In order to ensure improved - pixel reading/writing performance the \a Canvas.Image render target should be chosen. The - \a Canvas.FramebufferObject render target requires the pixel data to be exchanged between - the system memory and the graphic card, which is significantly more expensive. Rendering - may also be synchronized with the V-sync signal (to avoid {en.wikipedia.org/wiki/Screen_tearing}{screen tearing}) - which will futher impact pixel operations with \c Canvas.FrambufferObject render target. - - \section1 Tips for Porting Existing HTML5 Canvas applications - - Although the Canvas item is provides a HTML5 like API, HTML5 canvas applications - need to be modified to run in the Canvas item: - \list - \o Replace all DOM API calls with QML property bindings or Canvas item methods. - \o Replace all HTML event handlers with the \a MouseArea item. - \o Change setInterval/setTimeout function calls with the \a Timer item. - \o Place painting code into the \a QtQuick2::Canvas::onPaint handler and trigger - painting by calling the \c markDirty or \c requestPaint methods. - \o To draw images, load them by calling the Canvas's loadImage method and then request to paint - them in the onImageLoaded handler. - \endlist - - \sa QtQuick2::Context2D -*/ - -QQuickCanvasItem::QQuickCanvasItem(QQuickItem *parent) - : QQuickItem(*(new QQuickCanvasItemPrivate), parent) -{ - setFlag(ItemHasContents); -} - -QQuickCanvasItem::~QQuickCanvasItem() -{ - Q_D(QQuickCanvasItem); - delete d->context; -} - -/*! - \qmlproperty size QtQuick2::Canvas::canvasSize - Holds the logical canvas size that the context paints on. - - By default, the canvas size is the same size as the current canvas item size. - By setting the canvasSize, tileSize and canvasWindow, the Canvas - item can act as a large virtual canvas with many seperately rendered tile rectangles - Only those tiles within the current canvas window are painted by - the Canvas render engine. - - \sa QtQuick2::Canvas::tileSize QtQuick2::Canvas::canvasWindow -*/ -QSizeF QQuickCanvasItem::canvasSize() const -{ - Q_D(const QQuickCanvasItem); - return d->canvasSize; -} - -void QQuickCanvasItem::setCanvasSize(const QSizeF & size) -{ - Q_D(QQuickCanvasItem); - if (d->canvasSize != size) { - d->hasCanvasSize = true; - d->canvasSize = size; - emit canvasSizeChanged(); - polish(); - update(); - } -} - -/*! - \qmlproperty size QtQuick2::Canvas::tileSize - Holds the canvas rendering tile size. - - The Canvas item enters tiled mode by setting canvasSize, tileSize and - the canvasWindow. This can improve rendering performance - by rendering and caching tiles instead of rendering the whole canvas every time. - - Memory will be consumed only by those tiles within the current visible region. - - By default the tileSize is the same as the canvasSize. - - \sa QtQuick2::Canvas::canvaasSize QtQuick2::Canvas::canvasWindow -*/ -QSize QQuickCanvasItem::tileSize() const -{ - Q_D(const QQuickCanvasItem); - return d->tileSize; -} - -void QQuickCanvasItem::setTileSize(const QSize & size) -{ - Q_D(QQuickCanvasItem); - if (d->tileSize != size) { - d->hasTileSize = true; - d->tileSize = size; - - emit tileSizeChanged(); - polish(); - update(); - } -} - -/*! - \qmlproperty rect QtQuick2::Canvas::canvasWindow - Holds the current canvas visible window. - - By default the canvasWindow size is the same as the Canvas item - size with the topleft point as (0, 0). - - If the canvasSize is different to the Canvas item size, the Canvas - item can display different visible areas by changing the canvas windowSize - and/or position. - - \sa QtQuick2::Canvas::canvasSize QtQuick2::Canvas::tileSize -*/ -QRectF QQuickCanvasItem::canvasWindow() const -{ - Q_D(const QQuickCanvasItem); - return d->canvasWindow; -} - -void QQuickCanvasItem::setCanvasWindow(const QRectF& rect) -{ - Q_D(QQuickCanvasItem); - if (d->canvasWindow != rect) { - d->canvasWindow = rect; - - d->hasCanvasWindow = true; - emit canvasWindowChanged(); - polish(); - update(); - } -} - - -QQuickContext2D* QQuickCanvasItem::context() const -{ - Q_D(const QQuickCanvasItem); - return d->context; -} -/*! - \qmlproperty bool QtQuick2::Canvas::renderInThread - Holds the current canvas rendering mode. - - Set renderInThread to true to render complex and long - running painting in a dedicated background - thread, avoiding blocking the main UI. - - \note: Not all renderTargets support background rendering. If background rendering - is not supported by the current renderTarget, the renderInThread - property is ignored. - - The default value is false. - \sa QtQuick2::Canvas::renderTarget -*/ -bool QQuickCanvasItem::renderInThread() const -{ - Q_D(const QQuickCanvasItem); - return d->renderInThread; -} -/*! - \qmlproperty bool QtQuick2::Canvas::renderTarget - Holds the current canvas render target. - - \list - \o Canvas.Image - render to an in memory image buffer, the render - target supports background rendering. - \o Canvas.FramebufferObject - render to an OpenGL frame buffer, - this render target will ignore the - renderInThread property. The actual - rendering happens in the main QML rendering - process, which may be in a seperate render thread - or in the main GUI thread depending upon the platform. - \endlist - - The default render target is \c Canvas.Image. - \sa QtQuick2::Canvas::renderInThread -*/ -QQuickCanvasItem::RenderTarget QQuickCanvasItem::renderTarget() const -{ - Q_D(const QQuickCanvasItem); - return d->renderTarget; -} - -void QQuickCanvasItem::setRenderTarget(RenderTarget target) -{ - Q_D(QQuickCanvasItem); - if (d->renderTarget != target) { - d->renderTarget = target; - - if (d->componentCompleted) - createTexture(); - emit renderTargetChanged(); - } -} - -void QQuickCanvasItem::_doPainting(const QRectF& region) -{ - Q_D(QQuickCanvasItem); - emit paint(QDeclarativeV8Handle::fromHandle(d->context->v8value()) - , QQuickContext2DTexture::tiledRect(region, d->tileSize)); - if (d->texture) - d->texture->wake(); -} - -void QQuickCanvasItem::setRenderInThread(bool renderInThread) -{ - Q_D(QQuickCanvasItem); - if (d->renderInThread != renderInThread) { - d->renderInThread = renderInThread; - - if (d->componentCompleted) - createTexture(); - - if (d->renderInThread) - connect(this, SIGNAL(painted()), SLOT(update())); - else - disconnect(this, SIGNAL(painted()), this, SLOT(update())); - emit renderInThreadChanged(); - polish(); - update(); - } -} - -void QQuickCanvasItem::geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry) -{ - Q_D(QQuickCanvasItem); - QQuickItem::geometryChanged(newGeometry, oldGeometry); - - const qreal w = newGeometry.width(); - const qreal h = newGeometry.height(); - - if (!d->hasCanvasSize) { - d->canvasSize = QSizeF(w, h); - emit canvasSizeChanged(); - } - - if (!d->hasTileSize) { - d->tileSize = d->canvasSize.toSize(); - emit tileSizeChanged(); - } - - if (!d->hasCanvasWindow) { - d->canvasWindow = newGeometry; - emit canvasWindowChanged(); - } - - polish(); - update(); -} - -void QQuickCanvasItem::componentComplete() -{ - Q_D(QQuickCanvasItem); - QQuickItem::componentComplete(); - - if (!d->context) - createContext(); - createTexture(); - - d->baseUrl = qmlEngine(this)->contextForObject(this)->baseUrl(); - requestPaint(); - updatePolish(); //force update the canvas sizes to texture for the first time - update(); - d->componentCompleted = true; -} - -void QQuickCanvasItem::updatePolish() -{ - Q_D(QQuickCanvasItem); - QQuickItem::updatePolish(); - if (d->texture) { - if (!d->renderInThread && d->dirtyRect.isValid()) - _doPainting(d->dirtyRect); - - d->texture->canvasChanged(d->canvasSize.toSize() - , d->tileSize - , d->canvasWindow.toAlignedRect() - , d->dirtyRect.toAlignedRect() - , d->smooth); - d->dirtyRect = QRectF(); - } -} - -QSGNode *QQuickCanvasItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - Q_D(QQuickCanvasItem); - QQuickContext2DNode *node = static_cast<QQuickContext2DNode *>(oldNode); - if (!node) - node = new QQuickContext2DNode(this); - - node->setTexture(d->texture); - node->setSize(d->canvasWindow.size()); - node->update(); - return node; -} - -void QQuickCanvasItem::createTexture() -{ - Q_D(QQuickCanvasItem); - - if (!d->texture - || d->texture->threadRendering() != d->renderInThread - || d->texture->renderTarget() != d->renderTarget) { - if (d->texture) { - d->texture->deleteLater(); - d->texture = 0; - } - - if (d->renderTarget == QQuickCanvasItem::Image) { - d->texture = new QQuickContext2DImageTexture(d->renderInThread); - } else if (d->renderTarget == QQuickCanvasItem::FramebufferObject) { - d->texture = new QQuickContext2DFBOTexture(); - } - - if (d->renderInThread && !d->texture->supportThreadRendering()) { - qWarning("Canvas: render target does not support thread rendering, force to non-thread rendering mode."); - d->renderInThread = false; - emit renderInThreadChanged(); - } - - if (d->renderInThread) - connect(d->texture, SIGNAL(textureChanged()), this, SLOT(update())); - - d->texture->setItem(this); - } -} - -void QQuickCanvasItem::createContext() -{ - Q_D(QQuickCanvasItem); - - delete d->context; - - d->context = new QQuickContext2D(this); - - QV8Engine *e = QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this)); - d->context->setV8Engine(e); -} - -/*! - \qmlmethod object QtQuick2::Canvas::getContext(string contextId) - - Currently, the canvas item only supports the 2D context. If the \a contextId - parameter isn't provided or is "2d", then the QtQuick2::Context2D object is - returned, otherwise returns an invalid value. - */ -QDeclarativeV8Handle QQuickCanvasItem::getContext(const QString &contextId) -{ - Q_D(QQuickCanvasItem); - - if (contextId.toLower() != QLatin1String("2d")) - return QDeclarativeV8Handle::fromHandle(v8::Undefined()); - - if (!d->context) - createContext(); - return QDeclarativeV8Handle::fromHandle(d->context->v8value()); -} - -/*! - \qmlmethod void QtQuick2::Canvas::markDirty(rect region) - - Mark the given \a region as dirty, so that when this region is visible - the canvas renderer will redraw it. This will trigger the "onPaint" signal - handler function. - - \sa QtQuick2::Canvas::paint QtQuick2::Canvas::requestPaint - */ -void QQuickCanvasItem::markDirty(const QRectF& region) -{ - Q_D(QQuickCanvasItem); - d->dirtyRect |= region; - if (d->componentCompleted) - polish(); - update(); -} - - -/*! - \qmlmethod bool QtQuick2::Canvas::save(string filename) - - Save the current canvas content into an image file \a filename. - The saved image format is automatically decided by the \a filename's - suffix. - - Note: calling this method will force painting the whole canvas, not just the - current canvas visible window. - - \sa canvasWindow canvasSize toDataURL - */ -bool QQuickCanvasItem::save(const QString &filename) const -{ - Q_D(const QQuickCanvasItem); - QUrl url = d->baseUrl.resolved(QUrl::fromLocalFile(filename)); - return toImage().save(url.toLocalFile()); -} - -QImage QQuickCanvasItem::loadedImage(const QUrl& url) -{ - Q_D(QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - if (!d->images.contains(fullPathUrl)) { - loadImage(url); - } - QDeclarativePixmap* pix = d->images.value(fullPathUrl); - if (pix->isLoading() || pix->isError()) { - return QImage(); - } - return pix->image(); -} - -/*! - \qmlmethod void QtQuick2::Canvas::loadImage(url image) - Loads the given \c image asynchronously. - - When the image is ready, onImageLoaded will be emitted. - The loaded image can be unloaded by the \a QtQuick2::Canvas::unloadImage method. - - Note: Only loaded images can be painted on the Canvas item. - \sa QtQuick2::Canvas::unloadImage QtQuick2::Canvas::imageLoaded QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Context2D::createImageData QtQuick2::Context2D::drawImage - */ -void QQuickCanvasItem::loadImage(const QUrl& url) -{ - Q_D(QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - if (!d->images.contains(fullPathUrl)) { - QDeclarativePixmap* pix = new QDeclarativePixmap(); - d->images.insert(fullPathUrl, pix); - - pix->load(qmlEngine(this) - , fullPathUrl - , QDeclarativePixmap::Cache | QDeclarativePixmap::Asynchronous); - pix->connectFinished(this, SIGNAL(imageLoaded())); - } -} -/*! - \qmlmethod void QtQuick2::Canvas::unloadImage(url image) - Unloads the \c image. - - Once an image is unloaded it cannot be painted by the canvas context - unless it is loaded again. - - \sa QtQuick2::Canvas::loadImage QtQuick2::Canvas::imageLoaded QtQuick2::Canvas::isImageLoaded - \sa QtQuick2::Context2D::createImageData QtQuick2::Context2D::drawImage - */ -void QQuickCanvasItem::unloadImage(const QUrl& url) -{ - Q_D(QQuickCanvasItem); - QUrl removeThis = d->baseUrl.resolved(url); - if (d->images.contains(removeThis)) { - delete d->images.value(removeThis); - d->images.remove(removeThis); - } -} - -/*! - \qmlmethod void QtQuick2::Canvas::isImageError(url image) - Returns true if the \a image failed to load. - - \sa QtQuick2::Canvas::loadImage - */ -bool QQuickCanvasItem::isImageError(const QUrl& url) const -{ - Q_D(const QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - return d->images.contains(fullPathUrl) - && d->images.value(fullPathUrl)->isError(); -} - -/*! - \qmlmethod void QtQuick2::Canvas::isImageLoading(url image) - Returns true if the \a image is currently loading. - - \sa QtQuick2::Canvas::loadImage - */ -bool QQuickCanvasItem::isImageLoading(const QUrl& url) const -{ - Q_D(const QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - return d->images.contains(fullPathUrl) - && d->images.value(fullPathUrl)->isLoading(); -} -/*! - \qmlmethod void QtQuick2::Canvas::isImageLoaded(url image) - Returns true if the \a image is sucessfully loaded and ready to use. - - \sa QtQuick2::Canvas::loadImage - */ -bool QQuickCanvasItem::isImageLoaded(const QUrl& url) const -{ - Q_D(const QQuickCanvasItem); - QUrl fullPathUrl = d->baseUrl.resolved(url); - return d->images.contains(fullPathUrl) - && d->images.value(fullPathUrl)->isReady(); -} - -QImage QQuickCanvasItem::toImage(const QRectF& region) const -{ - Q_D(const QQuickCanvasItem); - if (d->texture) { - if (region.isEmpty()) - return d->texture->toImage(canvasWindow()); - else - return d->texture->toImage(region); - } - return QImage(); -} - -/*! - \qmlmethod string QtQuick2::Canvas::toDataURL(string mimeType) - - Returns a data URL for the image in the canvas. - - The default \a mimeType is "image/png". - - \sa QtQuick2::Canvas::save - */ -QString QQuickCanvasItem::toDataURL(const QString& mimeType) const -{ - QImage image = toImage(); - - if (!image.isNull()) { - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - QString mime = mimeType.toLower(); - QString type; - if (mime == QLatin1Literal("image/png")) { - type = QLatin1Literal("PNG"); - } else if (mime == QLatin1Literal("image/bmp")) - type = QLatin1Literal("BMP"); - else if (mime == QLatin1Literal("image/jpeg")) - type = QLatin1Literal("JPEG"); - else if (mime == QLatin1Literal("image/x-portable-pixmap")) - type = QLatin1Literal("PPM"); - else if (mime == QLatin1Literal("image/tiff")) - type = QLatin1Literal("TIFF"); - else if (mime == QLatin1Literal("image/xpm")) - type = QLatin1Literal("XPM"); - else - return QLatin1Literal("data:,"); - - image.save(&buffer, type.toAscii()); - buffer.close(); - QString dataUrl = QLatin1Literal("data:%1;base64,%2"); - return dataUrl.arg(mime).arg(QLatin1String(ba.toBase64().constData())); - } - return QLatin1Literal("data:,"); -} - -/*! - \qmlsignal QtQuick2::Canvas::onPaint(QtQuick2::Context2D context, rect region) - - This handler is called to render the \a region. - - This signal can be triggered by QtQuick2::Canvas::markdirty, QtQuick2::Canvas::requestPaint - or by changing the current canvas window. -*/ - -/*! - \qmlsignal QtQuick2::Canvas::onPainted() - - This handler is called after all context painting commands are executed and - the Canvas has been rendered. -*/ - -QT_END_NAMESPACE diff --git a/src/declarative/items/context2d/qquickcanvasitem_p.h b/src/declarative/items/context2d/qquickcanvasitem_p.h deleted file mode 100644 index 293434209a..0000000000 --- a/src/declarative/items/context2d/qquickcanvasitem_p.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKCANVASITEM_P_H -#define QQUICKCANVASITEM_P_H - -#include <qquickitem.h> -#include <private/qv8engine_p.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QQuickContext2D; -class QQuickCanvasItemPrivate; -class Q_DECLARATIVE_EXPORT QQuickCanvasItem : public QQuickItem -{ - Q_OBJECT - Q_ENUMS(RenderTarget) - Q_ENUMS(ImageFilterMode) - - Q_PROPERTY(QSizeF canvasSize READ canvasSize WRITE setCanvasSize NOTIFY canvasSizeChanged) - Q_PROPERTY(QSize tileSize READ tileSize WRITE setTileSize NOTIFY tileSizeChanged) - Q_PROPERTY(QRectF canvasWindow READ canvasWindow WRITE setCanvasWindow NOTIFY canvasWindowChanged) - Q_PROPERTY(bool renderInThread READ renderInThread WRITE setRenderInThread NOTIFY renderInThreadChanged) - Q_PROPERTY(RenderTarget renderTarget READ renderTarget WRITE setRenderTarget NOTIFY renderTargetChanged) -public: - enum RenderTarget { - Image, - FramebufferObject - }; - - enum ImageFilterMode { - Threshold, - Mono, - GrayScale, - Brightness, - Invert, - Blur, - Opaque, - Convolute - }; - - QQuickCanvasItem(QQuickItem *parent = 0); - ~QQuickCanvasItem(); - - QSizeF canvasSize() const; - void setCanvasSize(const QSizeF &); - - QSize tileSize() const; - void setTileSize(const QSize &); - - QRectF canvasWindow() const; - void setCanvasWindow(const QRectF& rect); - - bool renderInThread() const; - void setRenderInThread(bool renderInThread); - - RenderTarget renderTarget() const; - void setRenderTarget(RenderTarget target); - - QQuickContext2D* context() const; - QImage toImage(const QRectF& region = QRectF()) const; - - QImage loadedImage(const QUrl& url); - -Q_SIGNALS: - void paint(QDeclarativeV8Handle context, const QRect ®ion); - void painted(); - void canvasSizeChanged(); - void tileSizeChanged(); - void renderInThreadChanged(); - void textureChanged(); - void canvasWindowChanged(); - void renderTargetChanged(); - void imageLoaded(); -public Q_SLOTS: - QString toDataURL(const QString& type = QLatin1String("image/png")) const; - QDeclarativeV8Handle getContext(const QString & = QLatin1String("2d")); - void markDirty(const QRectF& region); - void requestPaint() {markDirty(canvasWindow());} - // Save current canvas to disk - bool save(const QString& filename) const; - void loadImage(const QUrl& url); - void unloadImage(const QUrl& url); - bool isImageLoaded(const QUrl& url) const; - bool isImageLoading(const QUrl& url) const; - bool isImageError(const QUrl& url) const; -private Q_SLOTS: - void _doPainting(const QRectF& region); -protected: - virtual void componentComplete(); - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); - virtual void updatePolish(); -private: - void createContext(); - void createTexture(); - Q_DECLARE_PRIVATE(QQuickCanvasItem) - friend class QQuickContext2D; - friend class QQuickContext2DTexture; -}; -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QQuickCanvasItem) - -QT_END_HEADER - -#endif //QQUICKCANVASITEM_P_H diff --git a/src/declarative/items/context2d/qquickcontext2d.cpp b/src/declarative/items/context2d/qquickcontext2d.cpp deleted file mode 100644 index 1f7a84baa6..0000000000 --- a/src/declarative/items/context2d/qquickcontext2d.cpp +++ /dev/null @@ -1,3540 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquickcontext2d_p.h" -#include "qquickcontext2dcommandbuffer_p.h" -#include "qquickcanvasitem_p.h" -#include <private/qquickitem_p.h> -#include <private/qquickshadereffectsource_p.h> -#include <QtGui/qopenglframebufferobject.h> - -#include <QtCore/qdebug.h> -#include <private/qsgcontext_p.h> -#include <private/qdeclarativesvgparser_p.h> -#include <private/qdeclarativepath_p.h> - -#include <private/qquickimage_p_p.h> - -#include <QtGui/qguiapplication.h> -#include <qdeclarativeinfo.h> -#include <QtCore/qmath.h> -#include <private/qv8engine_p.h> - -#include <qdeclarativeengine.h> -#include <private/qv8domerrors_p.h> -#include <QtCore/qnumeric.h> - -QT_BEGIN_NAMESPACE -/*! - \qmlclass Context2D QQuickContext2D - \inqmlmodule QtQuick 2 - \since QtQuick 2.0 - \brief The Context2D API allows you to draw 2d graphic shapes on the \c Canvas item. - - The Context2D object can be created by \c Canvas item's \c getContext() method: - \code - Canvas { - id:canvas - onPaint:{ - var ctx = canvas.getContext('2d'); - //... - } - } - \endcode - The Context2D API implements the same \l {http://www.w3.org/TR/2dcontext}{W3C Canvas 2D Context API standard} - with some enhanced features. - - The Context2D API provides the rendering \bold{context} which defines the methods and attributes needed to draw - on the \c Canvas item. The following assigns the canvas rendering context to a \c{context} - variable: - \code - var context = mycanvas.getContext("2d") - \endcode - - The Context2D API renders the canvas as a coordinate system whose origin (0,0) is - at the top left corner, as shown in the figure below. Coordinates increase along - the \c{x} axis from left to right and along the \c{y} axis from top to bottom of - the canvas. - \image qml-item-canvas-context.gif -*/ - -Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok); - -static const double Q_PI = 3.14159265358979323846; // pi - -#define DEGREES(t) ((t) * 180.0 / Q_PI) - -#define CHECK_CONTEXT(r) if (!r || !r->context || !r->context->buffer()) \ - V8THROW_ERROR("Not a Context2D object"); - -#define CHECK_CONTEXT_SETTER(r) if (!r || !r->context || !r->context->buffer()) \ - V8THROW_ERROR_SETTER("Not a Context2D object"); -#define qClamp(val, min, max) qMin(qMax(val, min), max) -#define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9)) -QColor qt_color_from_string(v8::Local<v8::Value> name) -{ - v8::String::AsciiValue str(name); - - char *p = *str; - int len = str.length(); - //rgb/hsl color string has at least 7 characters - if (!p || len > 255 || len <= 7) - return QColor(p); - else { - bool isRgb(false), isHsl(false), hasAlpha(false); - Q_UNUSED(isHsl) - - while (isspace(*p)) p++; - if (strncmp(p, "rgb", 3) == 0) - isRgb = true; - else if (strncmp(p, "hsl", 3) == 0) - isHsl = true; - else - return QColor(p); - - p+=3; //skip "rgb" or "hsl" - hasAlpha = (*p == 'a') ? true : false; - - ++p; //skip "(" - - if (hasAlpha) ++p; //skip "a" - - int rh, gs, bl, alpha = 255; - - //red - while (isspace(*p)) p++; - rh = strtol(p, &p, 10); - if (*p == '%') { - rh = qRound(rh/100.0 * 255); - ++p; - } - if (*p++ != ',') return QColor(); - - //green - while (isspace(*p)) p++; - gs = strtol(p, &p, 10); - if (*p == '%') { - gs = qRound(gs/100.0 * 255); - ++p; - } - if (*p++ != ',') return QColor(); - - //blue - while (isspace(*p)) p++; - bl = strtol(p, &p, 10); - if (*p == '%') { - bl = qRound(bl/100.0 * 255); - ++p; - } - - if (hasAlpha) { - if (*p++!= ',') return QColor(); - while (isspace(*p)) p++; - bool ok = false; - alpha = qRound(qstrtod(p, const_cast<const char **>(&p), &ok) * 255); - } - - if (*p != ')') return QColor(); - if (isRgb) - return QColor::fromRgba(qRgba(qClamp(rh, 0, 255), qClamp(gs, 0, 255), qClamp(bl, 0, 255), qClamp(alpha, 0, 255))); - else - return QColor::fromHsl(qClamp(rh, 0, 255), qClamp(gs, 0, 255), qClamp(bl, 0, 255), qClamp(alpha, 0, 255)); - } - return QColor(); -} - -QFont qt_font_from_string(const QString& fontString) { - QFont font; - // ### this is simplified and incomplete - // ### TODO:get code from Qt webkit - QStringList tokens = fontString.split(QLatin1String(" ")); - foreach (const QString &token, tokens) { - if (token == QLatin1String("italic")) - font.setItalic(true); - else if (token == QLatin1String("bold")) - font.setBold(true); - else if (token.endsWith(QLatin1String("px"))) { - QString number = token; - number.remove(QLatin1String("px")); - //font.setPointSizeF(number.trimmed().toFloat()); - font.setPixelSize(number.trimmed().toInt()); - } else - font.setFamily(token); - } - - return font; -} - - - -class QQuickContext2DEngineData : public QV8Engine::Deletable -{ -public: - QQuickContext2DEngineData(QV8Engine *engine); - ~QQuickContext2DEngineData(); - - v8::Persistent<v8::Function> constructorContext; - v8::Persistent<v8::Function> constructorGradient; - v8::Persistent<v8::Function> constructorPattern; - v8::Persistent<v8::Function> constructorPixelArray; - v8::Persistent<v8::Function> constructorImageData; -}; - -V8_DEFINE_EXTENSION(QQuickContext2DEngineData, engineData) - -class QV8Context2DResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(Context2DType) -public: - QV8Context2DResource(QV8Engine *e) : QV8ObjectResource(e) {} - QQuickContext2D* context; -}; - -class QV8Context2DStyleResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(Context2DStyleType) -public: - QV8Context2DStyleResource(QV8Engine *e) - : QV8ObjectResource(e) - , patternRepeatX(false) - , patternRepeatY(false) - {} - QBrush brush; - bool patternRepeatX:1; - bool patternRepeatY:1; -}; - -class QV8Context2DPixelArrayResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(Context2DPixelArrayType) -public: - QV8Context2DPixelArrayResource(QV8Engine *e) : QV8ObjectResource(e) {} - - QImage image; -}; - -QImage qt_image_convolute_filter(const QImage& src, const QVector<qreal>& weights, int radius = 0) -{ - int sides = radius ? radius : qRound(qSqrt(weights.size())); - int half = qFloor(sides/2); - - QImage dst = QImage(src.size(), src.format()); - int w = src.width(); - int h = src.height(); - for (int y = 0; y < dst.height(); ++y) { - QRgb *dr = (QRgb*)dst.scanLine(y); - for (int x = 0; x < dst.width(); ++x) { - unsigned char* dRgb = ((unsigned char*)&dr[x]); - unsigned char red=0, green=0, blue=0, alpha=0; - int sy = y; - int sx = x; - - for (int cy=0; cy<sides; cy++) { - for (int cx=0; cx<sides; cx++) { - int scy = sy + cy - half; - int scx = sx + cx - half; - if (scy >= 0 && scy < w && scx >= 0 && scx < h) { - const QRgb *sr = (const QRgb*)(src.constScanLine(scy)); - const unsigned char* sRgb = ((const unsigned char*)&sr[scx]); - qreal wt = radius ? weights[0] : weights[cy*sides+cx]; - red += sRgb[0] * wt; - green += sRgb[1] * wt; - blue += sRgb[2] * wt; - alpha += sRgb[3] * wt; - } - } - } - dRgb[0] = red; - dRgb[1] = green; - dRgb[2] = blue; - dRgb[3] = alpha; - } - } - return dst; -} - -void qt_image_boxblur(QImage& image, int radius, bool quality) -{ - int passes = quality? 3: 1; - for (int i=0; i < passes; i++) { - image = qt_image_convolute_filter(image, QVector<qreal>() << 1.0/(radius * radius * 1.0), radius); - } -} - -static QPainter::CompositionMode qt_composite_mode_from_string(const QString &compositeOperator) -{ - if (compositeOperator == QLatin1String("source-over")) { - return QPainter::CompositionMode_SourceOver; - } else if (compositeOperator == QLatin1String("source-out")) { - return QPainter::CompositionMode_SourceOut; - } else if (compositeOperator == QLatin1String("source-in")) { - return QPainter::CompositionMode_SourceIn; - } else if (compositeOperator == QLatin1String("source-atop")) { - return QPainter::CompositionMode_SourceAtop; - } else if (compositeOperator == QLatin1String("destination-atop")) { - return QPainter::CompositionMode_DestinationAtop; - } else if (compositeOperator == QLatin1String("destination-in")) { - return QPainter::CompositionMode_DestinationIn; - } else if (compositeOperator == QLatin1String("destination-out")) { - return QPainter::CompositionMode_DestinationOut; - } else if (compositeOperator == QLatin1String("destination-over")) { - return QPainter::CompositionMode_DestinationOver; - } else if (compositeOperator == QLatin1String("lighter")) { - return QPainter::CompositionMode_Lighten; - } else if (compositeOperator == QLatin1String("copy")) { - return QPainter::CompositionMode_Source; - } else if (compositeOperator == QLatin1String("xor")) { - return QPainter::CompositionMode_Xor; - } else if (compositeOperator == QLatin1String("qt-clear")) { - return QPainter::CompositionMode_Clear; - } else if (compositeOperator == QLatin1String("qt-destination")) { - return QPainter::CompositionMode_Destination; - } else if (compositeOperator == QLatin1String("qt-multiply")) { - return QPainter::CompositionMode_Multiply; - } else if (compositeOperator == QLatin1String("qt-screen")) { - return QPainter::CompositionMode_Screen; - } else if (compositeOperator == QLatin1String("qt-overlay")) { - return QPainter::CompositionMode_Overlay; - } else if (compositeOperator == QLatin1String("qt-darken")) { - return QPainter::CompositionMode_Darken; - } else if (compositeOperator == QLatin1String("qt-lighten")) { - return QPainter::CompositionMode_Lighten; - } else if (compositeOperator == QLatin1String("qt-color-dodge")) { - return QPainter::CompositionMode_ColorDodge; - } else if (compositeOperator == QLatin1String("qt-color-burn")) { - return QPainter::CompositionMode_ColorBurn; - } else if (compositeOperator == QLatin1String("qt-hard-light")) { - return QPainter::CompositionMode_HardLight; - } else if (compositeOperator == QLatin1String("qt-soft-light")) { - return QPainter::CompositionMode_SoftLight; - } else if (compositeOperator == QLatin1String("qt-difference")) { - return QPainter::CompositionMode_Difference; - } else if (compositeOperator == QLatin1String("qt-exclusion")) { - return QPainter::CompositionMode_Exclusion; - } - return QPainter::CompositionMode_SourceOver; -} - -static QString qt_composite_mode_to_string(QPainter::CompositionMode op) -{ - switch (op) { - case QPainter::CompositionMode_SourceOver: - return QLatin1String("source-over"); - case QPainter::CompositionMode_DestinationOver: - return QLatin1String("destination-over"); - case QPainter::CompositionMode_Clear: - return QLatin1String("qt-clear"); - case QPainter::CompositionMode_Source: - return QLatin1String("copy"); - case QPainter::CompositionMode_Destination: - return QLatin1String("qt-destination"); - case QPainter::CompositionMode_SourceIn: - return QLatin1String("source-in"); - case QPainter::CompositionMode_DestinationIn: - return QLatin1String("destination-in"); - case QPainter::CompositionMode_SourceOut: - return QLatin1String("source-out"); - case QPainter::CompositionMode_DestinationOut: - return QLatin1String("destination-out"); - case QPainter::CompositionMode_SourceAtop: - return QLatin1String("source-atop"); - case QPainter::CompositionMode_DestinationAtop: - return QLatin1String("destination-atop"); - case QPainter::CompositionMode_Xor: - return QLatin1String("xor"); - case QPainter::CompositionMode_Plus: - return QLatin1String("plus"); - case QPainter::CompositionMode_Multiply: - return QLatin1String("qt-multiply"); - case QPainter::CompositionMode_Screen: - return QLatin1String("qt-screen"); - case QPainter::CompositionMode_Overlay: - return QLatin1String("qt-overlay"); - case QPainter::CompositionMode_Darken: - return QLatin1String("qt-darken"); - case QPainter::CompositionMode_Lighten: - return QLatin1String("lighter"); - case QPainter::CompositionMode_ColorDodge: - return QLatin1String("qt-color-dodge"); - case QPainter::CompositionMode_ColorBurn: - return QLatin1String("qt-color-burn"); - case QPainter::CompositionMode_HardLight: - return QLatin1String("qt-hard-light"); - case QPainter::CompositionMode_SoftLight: - return QLatin1String("qt-soft-light"); - case QPainter::CompositionMode_Difference: - return QLatin1String("qt-difference"); - case QPainter::CompositionMode_Exclusion: - return QLatin1String("qt-exclusion"); - default: - break; - } - return QString(); -} - - -static v8::Local<v8::Object> qt_create_image_data(qreal w, qreal h, QV8Engine* engine, const QImage& image) -{ - QQuickContext2DEngineData *ed = engineData(engine); - v8::Local<v8::Object> imageData = ed->constructorImageData->NewInstance(); - QV8Context2DPixelArrayResource *r = new QV8Context2DPixelArrayResource(engine); - if (image.isNull()) { - r->image = QImage(w, h, QImage::Format_ARGB32); - r->image.fill(0x00000000); - } else { - Q_ASSERT(image.width() == w && image.height() == h); - r->image = image.format() == QImage::Format_ARGB32 ? image : image.convertToFormat(QImage::Format_ARGB32); - } - v8::Local<v8::Object> pixelData = ed->constructorPixelArray->NewInstance(); - pixelData->SetExternalResource(r); - - imageData->SetInternalField(0, pixelData); - return imageData; -} - -//static script functions - -/*! - \qmlproperty QtQuick2::Canvas QtQuick2::Context2D::canvas - Holds the canvas item that the context paints on. - - This property is read only. -*/ -static v8::Handle<v8::Value> ctx2d_canvas(v8::Local<v8::String>, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->newQObject(r->context->canvas()); -} - -/*! - \qmlmethod object QtQuick2::Context2D::restore() - Pops the top state on the stack, restoring the context to that state. - - \sa QtQuick2::Context2D::save() -*/ -static v8::Handle<v8::Value> ctx2d_restore(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - r->context->popState(); - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::reset() - Resets the context state and properties to the default values. -*/ -static v8::Handle<v8::Value> ctx2d_reset(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - r->context->reset(); - r->context->m_path = QPainterPath(); - r->context->m_path.setFillRule(Qt::WindingFill); - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::save() - Pushes the current state onto the state stack. - - Before changing any state attributes, you should save the current state - for future reference. The context maintains a stack of drawing states. - Each state consists of the current transformation matrix, clipping region, - and values of the following attributes: - \list - \o\a QtQuick2::Context2D::strokeStyle - \o\a QtQuick2::Context2D::fillStyle - \o\a QtQuick2::Context2D::fillRule - \o\a QtQuick2::Context2D::globalAlpha - \o\a QtQuick2::Context2D::lineWidth - \o\a QtQuick2::Context2D::lineCap - \o\a QtQuick2::Context2D::lineJoin - \o\a QtQuick2::Context2D::miterLimit - \o\a QtQuick2::Context2D::shadowOffsetX - \o\a QtQuick2::Context2D::shadowOffsetY - \o\a QtQuick2::Context2D::shadowBlur - \o\a QtQuick2::Context2D::shadowColor - \o\a QtQuick2::Context2D::globalCompositeOperation - \o\a QtQuick2::Context2D::font - \o\a QtQuick2::Context2D::textAlign - \o\a QtQuick2::Context2D::textBaseline - \endlist - - The current path is NOT part of the drawing state. The path can be reset by - invoking the \a QtQuick2::Context2D::beginPath() method. -*/ -static v8::Handle<v8::Value> ctx2d_save(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - r->context->pushState(); - - return args.This(); -} - -// transformations -/*! - \qmlmethod object QtQuick2::Context2D::rotate(real angle) - Rotate the canvas around the current origin by \c angle in radians and clockwise direction. - \code - ctx.rotate(Math.PI/2); - \endcode - \image qml-item-canvas-rotate.png - - The rotation transformation matrix is as follows: - - \image qml-item-canvas-math-rotate.png - - where the \c angle of rotation is in radians. - -*/ -static v8::Handle<v8::Value> ctx2d_rotate(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 1) { - qreal angle = args[0]->NumberValue(); - if (!qIsFinite(angle)) - return args.This(); - - r->context->state.matrix.rotate(DEGREES(angle)); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::scale(real x, real y) - Increases or decreases the size of each unit in the canvas grid by multiplying the scale factors - to the current tranform matrix. - Where \c x is the scale factor in the horizontal direction and \c y is the scale factor in the - vertical direction. - The following code doubles the horizontal size of an object drawn on the canvas and half its - vertical size: - \code - ctx.scale(2.0, 0.5); - \endcode - \image qml-item-canvas-scale.png - -*/ -static v8::Handle<v8::Value> ctx2d_scale(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 2) { - qreal x, y; - x = args[0]->NumberValue(); - y = args[1]->NumberValue(); - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->state.matrix.scale(x, y); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::setTransform(real a, real b, real c, real d, real e, real f) - Changes the transformation matrix to the matrix given by the arguments as described below. - - Modifying the transformation matrix directly enables you to perform scaling, - rotating, and translating transformations in a single step. - - Each point on the canvas is multiplied by the matrix before anything is - drawn. The \l{HTML5 Canvas API} defines the transformation matrix as: - - \image qml-item-canvas-math.png - where: - \list - \o \c{a} is the scale factor in the horizontal (x) direction - \image qml-item-canvas-scalex.png - \o \c{c} is the skew factor in the x direction - \image qml-item-canvas-canvas-skewx.png - \o \c{e} is the translation in the x direction - \image qml-item-canvas-canvas-translate.png - \o \c{b} is the skew factor in the y (vertical) direction - \image qml-item-canvas-canvas-skewy.png - \o \c{d} is the scale factor in the y direction - \image qml-item-canvas-canvas-scaley.png - \o \c{f} is the translation in the y direction - \image qml-item-canvas-canvas-translatey.png - \o the last row remains constant - \endlist - The scale factors and skew factors are multiples; \c{e} and \c{f} are - coordinate space units, just like the units in the \a QtQuick2::Context2D::translate(x,y) - method. - - \sa QtQuick2::Context2D::transform() -*/ -static v8::Handle<v8::Value> ctx2d_setTransform(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 6) { - qreal a = args[0]->NumberValue(); - qreal b = args[1]->NumberValue(); - qreal c = args[2]->NumberValue(); - qreal d = args[3]->NumberValue(); - qreal e = args[4]->NumberValue(); - qreal f = args[5]->NumberValue(); - - if (!qIsFinite(a) - || !qIsFinite(b) - || !qIsFinite(c) - || !qIsFinite(d) - || !qIsFinite(e) - || !qIsFinite(f)) - return args.This(); - - r->context->state.matrix = QTransform(a, b, c, d, e, f); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::transform(real a, real b, real c, real d, real e, real f) - This method is very similar to \a QtQuick2::Context2D::setTransform(), but instead of replacing the old - tranform matrix, this method applies the given tranform matrix to the current matrix by mulitplying to it. - - The \a setTransform(a, b, c, d, e, f) method actually resets the current transform to the identity matrix, - and then invokes the transform(a, b, c, d, e, f) method with the same arguments. - - \sa QtQuick2::Context2D::setTransform() -*/ -static v8::Handle<v8::Value> ctx2d_transform(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 6) { - qreal a = args[0]->NumberValue(); - qreal b = args[1]->NumberValue(); - qreal c = args[2]->NumberValue(); - qreal d = args[3]->NumberValue(); - qreal e = args[4]->NumberValue(); - qreal f = args[5]->NumberValue(); - - if (!qIsFinite(a) - || !qIsFinite(b) - || !qIsFinite(c) - || !qIsFinite(d) - || !qIsFinite(e) - || !qIsFinite(f)) - return args.This(); - - r->context->state.matrix *= QTransform(a, b, c, d, e, f); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - -/*! - \qmlmethod object QtQuick2::Context2D::translate(real x, real y) - Translates the origin of the canvas to point (\c x, \c y). - - \c x is the horizontal distance that the origin is translated, in coordinate space units, - \c y is the vertical distance that the origin is translated, in coordinate space units. - Translating the origin enables you to draw patterns of different objects on the canvas - without having to measure the coordinates manually for each shape. -*/ -static v8::Handle<v8::Value> ctx2d_translate(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - - if (args.Length() == 2) { - qreal x = args[0]->NumberValue(); - qreal y = args[1]->NumberValue(); - - if (!qIsFinite(x) || !qIsFinite(y)) - return args.This(); - - r->context->state.matrix.translate(x, y); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - - return args.This(); -} - - -/*! - \qmlmethod object QtQuick2::Context2D::resetTransform() - Reset the transformation matrix to default value. - - \sa QtQuick2::Context2D::transform(), QtQuick2::Context2D::setTransform(), QtQuick2::Context2D::reset() -*/ -static v8::Handle<v8::Value> ctx2d_resetTransform(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - r->context->state.matrix = QTransform(); - r->context->buffer()->updateMatrix(r->context->state.matrix); - - return args.This(); -} - - -/*! - \qmlmethod object QtQuick2::Context2D::shear(real sh, real sv ) - Shear the transformation matrix with \a sh in horizontal direction and \a sv in vertical direction. -*/ -static v8::Handle<v8::Value> ctx2d_shear(const v8::Arguments &args) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(args.This()); - CHECK_CONTEXT(r) - - if (args.Length() == 2) { - qreal sh = args[0]->NumberValue(); - qreal sv = args[1]->NumberValue(); - - if (!qIsFinite(sh) || !qIsFinite(sv)) - return args.This(); - - r->context->state.matrix.shear(sh, sv); - r->context->buffer()->updateMatrix(r->context->state.matrix); - } - return args.This(); -} -// compositing - -/*! - \qmlproperty real QtQuick2::Context2D::globalAlpha - Holds the the current alpha value applied to rendering operations. - The value must be in the range from 0.0 (fully transparent) to 1.0 (fully opque). - The default value is 1.0. -*/ -static v8::Handle<v8::Value> ctx2d_globalAlpha(v8::Local<v8::String>, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT(r) - - return v8::Number::New(r->context->state.globalAlpha); -} - -static void ctx2d_globalAlpha_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT_SETTER(r) - - qreal globalAlpha = value->NumberValue(); - - if (!qIsFinite(globalAlpha)) - return; - - if (globalAlpha >= 0.0 && globalAlpha <= 1.0 && r->context->state.globalAlpha != globalAlpha) { - r->context->state.globalAlpha = globalAlpha; - r->context->buffer()->setGlobalAlpha(r->context->state.globalAlpha); - } -} - -/*! - \qmlproperty string QtQuick2::Context2D::globalCompositeOperation - Holds the the current the current composition operation, from the list below: - \list - \o source-atop - A atop B. Display the source image wherever both images are opaque. - Display the destination image wherever the destination image is opaque but the source image is transparent. - Display transparency elsewhere. - \o source-in - A in B. Display the source image wherever both the source image and destination image are opaque. - Display transparency elsewhere. - \o source-out - A out B. Display the source image wherever the source image is opaque and the destination image is transparent. - Display transparency elsewhere. - \o source-over - (default) A over B. Display the source image wherever the source image is opaque. - Display the destination image elsewhere. - \o destination-atop - B atop A. Same as source-atop but using the destination image instead of the source image and vice versa. - \o destination-in - B in A. Same as source-in but using the destination image instead of the source image and vice versa. - \o destination-out - B out A. Same as source-out but using the destination image instead of the source image and vice versa. - \o destination-over - B over A. Same as source-over but using the destination image instead of the source image and vice versa. - \o lighter - A plus B. Display the sum of the source image and destination image, with color values approaching 255 (100%) as a limit. - \o copy - A (B is ignored). Display the source image instead of the destination image. - \o xor - A xor B. Exclusive OR of the source image and destination image. - \endlist - - Additionally, this property also accepts the compositon modes listed in \a {QPainter::CompositionMode}. According to the W3C standard, these - extension composition modes are provided as "vendorName-operationName" syntax, for example: \c {QPainter::CompositionMode_Exclusion} is porvided as - "qt-exclusion". -*/ -static v8::Handle<v8::Value> ctx2d_globalCompositeOperation(v8::Local<v8::String>, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT(r) - - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->toString(qt_composite_mode_to_string(r->context->state.globalCompositeOperation)); -} - -static void ctx2d_globalCompositeOperation_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - - QString mode = engine->toString(value); - QPainter::CompositionMode cm = qt_composite_mode_from_string(mode); - if (cm == QPainter::CompositionMode_SourceOver && mode != QStringLiteral("source-over")) - return; - - if (cm != r->context->state.globalCompositeOperation) { - r->context->state.globalCompositeOperation = cm; - r->context->buffer()->setGlobalCompositeOperation(cm); - } -} - -// colors and styles -/*! - \qmlproperty variant QtQuick2::Context2D::fillStyle - Holds the current style used for filling shapes. - The style can be either a string containing a CSS color, a CanvasGradient or CanvasPattern object. Invalid values are ignored. - This property accepts several color syntaxes: - \list - \o 'rgb(red, green, blue)' - for example: 'rgb(255, 100, 55)' or 'rgb(100%, 70%, 30%)' - \o 'rgba(red, green, blue, alpha)' - for example: 'rgb(255, 100, 55, 1.0)' or 'rgb(100%, 70%, 30%, 0.5)' - \o 'hsl(hue, saturation, lightness)' - \o 'hsla(hue, saturation, lightness, alpha)' - \o '#RRGGBB' - for example: '#00FFCC' - \o Qt.rgba(red, green, blue, alpha) - for example: Qt.rgba(0.3, 0.7, 1, 1.0) - \endlist - If the \a fillStyle or \a strokeStyle is assigned many times in a loop, the last Qt.rgba() syntax should be chosen, as it has the - best performance, because it's already a valid QColor value, does not need to be parsed everytime. - - The default value is '#000000'. - \sa QtQuick2::Context2D::createLinearGradient - \sa QtQuick2::Context2D::createRadialGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::strokeStyle - */ -static v8::Handle<v8::Value> ctx2d_fillStyle(v8::Local<v8::String>, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QColor color = r->context->state.fillStyle.color(); - if (color.isValid()) { - if (color.alpha() == 255) - return engine->toString(color.name()); - QString alphaString = QString::number(color.alphaF(), 'f'); - while (alphaString.endsWith(QLatin1Char('0'))) - alphaString.chop(1); - if (alphaString.endsWith(QLatin1Char('.'))) - alphaString += QLatin1Char('0'); - return engine->toString(QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(alphaString)); - } - return r->context->m_fillStyle; -} - -static void ctx2d_fillStyle_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - if (value->IsObject()) { - QColor color = engine->toVariant(value, qMetaTypeId<QColor>()).value<QColor>(); - if (color.isValid()) { - r->context->state.fillStyle = color; - r->context->buffer()->setFillStyle(color); - r->context->m_fillStyle = value; - } else { - QV8Context2DStyleResource *style = v8_resource_cast<QV8Context2DStyleResource>(value->ToObject()); - if (style && style->brush != r->context->state.fillStyle) { - r->context->state.fillStyle = style->brush; - r->context->buffer()->setFillStyle(style->brush, style->patternRepeatX, style->patternRepeatY); - r->context->m_fillStyle = value; - r->context->state.fillPatternRepeatX = style->patternRepeatX; - r->context->state.fillPatternRepeatY = style->patternRepeatY; - } - } - } else if (value->IsString()) { - QColor color = qt_color_from_string(value); - if (color.isValid() && r->context->state.fillStyle != QBrush(color)) { - r->context->state.fillStyle = QBrush(color); - r->context->buffer()->setFillStyle(r->context->state.fillStyle); - r->context->m_fillStyle = value; - } - } -} -/*! - \qmlproperty enumeration QtQuick2::Context2D::fillRule - Holds the current fill rule used for filling shapes. The following fill rules supported: - \list - \o Qt.OddEvenFill - \o Qt.WindingFill - \endlist - Note: Unlike the \a QPainterPath, the Canvas API uses the winding fill as the default fill rule. - The fillRule property is part of the context rendering state. - - \sa QtQuick2::Context2D::fillStyle - */ -static v8::Handle<v8::Value> ctx2d_fillRule(v8::Local<v8::String>, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT(r) - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - return engine->fromVariant(r->context->state.fillRule); -} - -static void ctx2d_fillRule_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - if ((value->IsString() && engine->toString(value) == QStringLiteral("WindingFill")) - ||(value->IsNumber() && value->NumberValue() == Qt::WindingFill)) { - r->context->state.fillRule = Qt::WindingFill; - } else if ((value->IsString() && engine->toString(value) == QStringLiteral("OddEvenFill")) - ||(value->IsNumber() && value->NumberValue() == Qt::OddEvenFill)) { - r->context->state.fillRule = Qt::OddEvenFill; - } else { - //error - } - r->context->m_path.setFillRule(r->context->state.fillRule); -} -/*! - \qmlproperty variant QtQuick2::Context2D::strokeStyle - Holds the current color or style to use for the lines around shapes, - The style can be either a string containing a CSS color, a CanvasGradient or CanvasPattern object. - Invalid values are ignored. - - The default value is '#000000'. - - \sa QtQuick2::Context2D::createLinearGradient - \sa QtQuick2::Context2D::createRadialGradient - \sa QtQuick2::Context2D::createPattern - \sa QtQuick2::Context2D::fillStyle - */ -v8::Handle<v8::Value> ctx2d_strokeStyle(v8::Local<v8::String>, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - QColor color = r->context->state.strokeStyle.color(); - if (color.isValid()) { - if (color.alpha() == 255) - return engine->toString(color.name()); - QString alphaString = QString::number(color.alphaF(), 'f'); - while (alphaString.endsWith(QLatin1Char('0'))) - alphaString.chop(1); - if (alphaString.endsWith(QLatin1Char('.'))) - alphaString += QLatin1Char('0'); - return engine->toString(QString::fromLatin1("rgba(%1, %2, %3, %4)").arg(color.red()).arg(color.green()).arg(color.blue()).arg(alphaString)); - } - return r->context->m_strokeStyle; -} - -static void ctx2d_strokeStyle_set(v8::Local<v8::String>, v8::Local<v8::Value> value, const v8::AccessorInfo &info) -{ - QV8Context2DResource *r = v8_resource_cast<QV8Context2DResource>(info.This()); - CHECK_CONTEXT_SETTER(r) - - QV8Engine *engine = V8ENGINE_ACCESSOR(); - - if (value->IsObject()) { - QColor color = engine->toVariant(value, qMetaTypeId<QColor>()).value<QColor>(); - if (color.isValid()) { - r->context->state.fillStyle = color; - r->context->buffer()->setStrokeStyle(color); - r->context->m_strokeStyle = value; - } else { - QV8Context2DStyleResource *style = v8_resource_cast<QV8Context2DStyleResource>(value->ToObject()); - if (style && style->brush != r->context->state.strokeStyle) { - r->context->state.strokeStyle = style->brush; - r->context->buffer()->setStrokeStyle(style->brush, style->patternRepeatX, style->patternRepeatY); - r->context->m_strokeStyle = value; - r->context->state.strokePatternRepeatX = style->patternRepeatX; - r->context->state.strokePatternRepeatY = style->patternRepeatY; - - } - } - } else if (value->IsString()) { - QColor color = qt_color_from_string(value); - if (color.isValid() && r->context->state.strokeStyle != QBrush(color)) { - r->context->state.strokeStyle = QBrush(color); - r->context->buffer()->setStrokeStyle(r->context->state.strokeStyle); - r->context->m_strokeStyle = value; - } - } -} - -/*! - \qmlmethod object QtQuick2::Context2D::createLinearGra |