--- /dev/null
+/****************************************************************************
+**
+** 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 examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.0 as Window
+
+Window.Window {
+ width: 640
+ height: 480
+ visible: true //It's false by default
+ property Component self
+ Component.onCompleted: self = Qt.createComponent("Window.qml")
+ Text{
+ text: "Hello World!"
+ anchors.centerIn: parent
+ }
+ MouseArea{
+ anchors.fill: parent
+ onClicked: self.createObject();
+ }
+}
--- /dev/null
+/****************************************************************************
+**
+** 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 examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Window 2.0 as Window
+
+Item {
+ width: 640
+ height: 480
+ Text {
+ anchors.centerIn: parent
+ text: "First Window"
+ }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: Qt.quit()
+ }
+ Window.Window {
+ width: 640
+ height: 480
+ x: 640
+ y: 480
+ visible: true
+ color: "green"
+ Text {
+ anchors.centerIn: parent
+ text: "Second Window"
+ }
+ MouseArea{
+ anchors.fill: parent
+ onClicked: Qt.quit()
+ }
+ }
+}
--- /dev/null
+/****************************************************************************
+**
+** 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 examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui/QGuiApplication>
+#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeComponent>
+#include <QtCore/QUrl>
+#include <QDebug>
+
+int main(int argc, char* argv[])
+{
+ QGuiApplication app(argc, argv);
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
+ component.loadUrl(QUrl::fromLocalFile("Window.qml"));
+ if ( component.isReady() )
+ component.create();
+ else
+ qWarning() << component.errorString();
+ return app.exec();
+}
--- /dev/null
+TEMPLATE = app
+CONFIG += qt
+QT += declarative
+
+SOURCES += window.cpp
$$PWD/qquickdroparea_p.h \
$$PWD/qquickmultipointtoucharea_p.h \
$$PWD/qquickitemview_p.h \
- $$PWD/qquickitemview_p_p.h
+ $$PWD/qquickitemview_p_p.h \
+ $$PWD/qquickwindowmodule_p.h
SOURCES += \
$$PWD/qquickevents.cpp \
$$PWD/qquickdrag.cpp \
$$PWD/qquickdroparea.cpp \
$$PWD/qquickmultipointtoucharea.cpp \
- $$PWD/qquickitemview.cpp
+ $$PWD/qquickitemview.cpp \
+ $$PWD/qquickwindowmodule.cpp
SOURCES += \
$$PWD/qquickshadereffect.cpp \
q->setFormat(context->defaultSurfaceFormat());
}
+QDeclarativeListProperty<QObject> QQuickCanvasPrivate::data()
+{
+ initRootItem();
+ return QQuickItemPrivate::get(rootItem)->data();
+}
+
+void QQuickCanvasPrivate::initRootItem()
+{
+ Q_Q(QQuickCanvas);
+ q->connect(q, SIGNAL(widthChanged(int)),
+ rootItem, SLOT(setWidth(int)));
+ q->connect(q, SIGNAL(heightChanged(int)),
+ rootItem, SLOT(setHeight(int)));
+ rootItem->setWidth(q->width());
+ rootItem->setHeight(q->height());
+}
+
void QQuickCanvasPrivate::transformTouchPoints(QList<QTouchEvent::TouchPoint> &touchPoints, const QTransform &transform)
{
for (int i=0; i<touchPoints.count(); i++) {
/*!
+ \qmlclass Window QQuickCanvas
+ \inqmlmodule QtQuick.Window 2
+ \brief The Window object creates a new top-level window.
+
+ The Window object creates a new top-level window for a QtQuick scene. It automatically sets up the
+ window for use with QtQuick 2.0 graphical elements.
+*/
+/*!
\class QQuickCanvas
\since QtQuick 2.0
\brief The QQuickCanvas class provides the canvas for displaying a graphical QML scene
}
+/*!
+ \qmlproperty color QtQuick2.Window::Window::color
+
+ The background color for the window.
+
+ Setting this property is more efficient than using a separate Rectangle.
+*/
+
bool QQuickCanvasPrivate::clearHover()
{
if (hoverItems.isEmpty())
void QQuickCanvas::setClearColor(const QColor &color)
{
+ if (color == d_func()->clearColor)
+ return;
d_func()->clearColor = color;
+ emit clearColorChanged(color);
}
class Q_DECLARATIVE_EXPORT QQuickCanvas : public QWindow
{
-Q_OBJECT
-Q_DECLARE_PRIVATE(QQuickCanvas)
+ Q_OBJECT
+ Q_PRIVATE_PROPERTY(QQuickCanvas::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
+ Q_PROPERTY(QColor color READ clearColor WRITE setClearColor NOTIFY clearColorChanged)
+ Q_CLASSINFO("DefaultProperty", "data")
+ Q_DECLARE_PRIVATE(QQuickCanvas)
public:
enum CreateTextureOption {
TextureHasAlphaChannel = 0x0001,
void sceneGraphInitialized();
void beforeRendering();
void afterRendering();
+ void clearColorChanged(const QColor &);
protected:
QQuickCanvas(QQuickCanvasPrivate &dd, QWindow *parent = 0);
QT_BEGIN_NAMESPACE
//Make it easy to identify and customize the root item if needed
+
class QQuickRootItem : public QQuickItem
{
Q_OBJECT
public:
QQuickRootItem();
+public Q_SLOTS:
+ void setWidth(int w) {QQuickItem::setWidth(qreal(w));}
+ void setHeight(int h) {QQuickItem::setHeight(qreal(h));}
};
+class QQuickItemPrivate;
class QQuickCanvasPrivate;
class QTouchEvent;
virtual ~QQuickCanvasPrivate();
void init(QQuickCanvas *);
+ void initRootItem();//Currently only used if items added in QML
QQuickRootItem *rootItem;
+ QDeclarativeListProperty<QObject> data();
QQuickItem *activeFocusItem;
QQuickItem *mouseGrabberItem;
QHash<int, QQuickItem *> itemForTouchPointId;
mutable QQuickCanvasIncubationController *incubationController;
+
private:
static void cleanupNodesOnShutdown(QQuickItem *);
};
--- /dev/null
+/****************************************************************************
+**
+** 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 Declarative 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 "qquickwindowmodule_p.h"
+#include <QQuickCanvas>
+
+QT_BEGIN_NAMESPACE
+
+void QQuickWindowModule::defineModule()
+{
+ const char* uri = "QtQuick.Window";
+
+ qmlRegisterType<QQuickCanvas>(uri, 2, 0, "Window");
+}
+
+QT_END_NAMESPACE
+
--- /dev/null
+/****************************************************************************
+**
+** 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 Declarative 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 QQUICKWINDOWMODULE_H
+#define QQUICKWINDOWMODULE_H
+
+#include <qdeclarative.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QQuickWindowModule
+{
+public:
+ static void defineModule();
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif
#include <private/qdeclarativevaluetype_p.h>
#include <private/qquickitemsmodule_p.h>
#include <private/qquickparticlesmodule_p.h>
+#include <private/qquickwindowmodule_p.h>
#include <private/qdeclarativeenginedebugservice_p.h>
#include <private/qdeclarativedebugstatesdelegate_p.h>
QDeclarativeEnginePrivate::defineModule();
QQuickItemsModule::defineModule();
QQuickParticlesModule::defineModule();
+ QQuickWindowModule::defineModule();
QDeclarativeValueTypeFactory::registerValueTypes();
if (QDeclarativeEngineDebugService::isDebuggingEnabled()) {
--- /dev/null
+import QtQuick 2.0
+import QtQuick.Window 2.0 as Window
+
+Window.Window {
+ color: "#00FF00"
+ Item {
+ objectName: "item"
+ }
+}
#include <QTouchEvent>
#include <QtDeclarative/QQuickItem>
#include <QtDeclarative/QQuickCanvas>
+#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/private/qquickrectangle_p.h>
#include <QtGui/QWindowSystemInterface>
+#include "../shared/util.h"
struct TouchEventData {
QEvent::Type type;
void clearCanvas();
void mouseFiltering();
+
+ void qmlCreation();
+ void clearColor();
};
tst_qquickcanvas::tst_qquickcanvas()
QCOMPARE(topItem->mousePressId, 3);
}
+void tst_qquickcanvas::qmlCreation()
+{
+ QDeclarativeEngine engine;
+ QDeclarativeComponent component(&engine);
+ component.loadUrl(TESTDATA("window.qml"));
+ QObject* created = component.create();
+ QVERIFY(created);
+
+ QQuickCanvas* canvas = qobject_cast<QQuickCanvas*>(created);
+ QVERIFY(canvas);
+ QCOMPARE(canvas->clearColor(), QColor(Qt::green));
+
+ QQuickItem* item = canvas->findChild<QQuickItem*>("item");
+ QVERIFY(item);
+ QCOMPARE(item->canvas(), canvas);
+}
+
+void tst_qquickcanvas::clearColor()
+{
+ //### Can we examine rendering to make sure it is really blue?
+ QQuickCanvas *canvas = new QQuickCanvas;
+ canvas->resize(250, 250);
+ canvas->move(100, 100);
+ canvas->setClearColor(Qt::blue);
+ canvas->show();
+ QTest::qWaitForWindowShown(canvas);
+ QCOMPARE(canvas->clearColor(), QColor(Qt::blue));
+ delete canvas;
+}
QTEST_MAIN(tst_qquickcanvas)