From ba0d63fd220ff215150e827a21a42c8de3372dd4 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 18 Nov 2011 19:32:56 +1000 Subject: Initial window implementation Includes adding a color property on QQuickCanvas. Note that most Window related properties come from the QWindow inheritance. Task-number: QTBUG-19799 Change-Id: I00f6c90a1e2a5c85d787793d6edac2cd7d5309ab Reviewed-by: Alan Alpert --- examples/declarative/window/Window.qml | 58 ++++++++++++++++++ examples/declarative/window/standalone.qml | 71 ++++++++++++++++++++++ examples/declarative/window/window.cpp | 58 ++++++++++++++++++ examples/declarative/window/window.pro | 5 ++ src/declarative/items/items.pri | 6 +- src/declarative/items/qquickcanvas.cpp | 36 +++++++++++ src/declarative/items/qquickcanvas.h | 8 ++- src/declarative/items/qquickcanvas_p.h | 8 +++ src/declarative/items/qquickwindowmodule.cpp | 55 +++++++++++++++++ src/declarative/items/qquickwindowmodule_p.h | 63 +++++++++++++++++++ src/declarative/qtquick2.cpp | 2 + .../auto/declarative/qquickcanvas/data/window.qml | 9 +++ .../declarative/qquickcanvas/tst_qquickcanvas.cpp | 35 +++++++++++ 13 files changed, 410 insertions(+), 4 deletions(-) create mode 100644 examples/declarative/window/Window.qml create mode 100644 examples/declarative/window/standalone.qml create mode 100644 examples/declarative/window/window.cpp create mode 100644 examples/declarative/window/window.pro create mode 100644 src/declarative/items/qquickwindowmodule.cpp create mode 100644 src/declarative/items/qquickwindowmodule_p.h create mode 100644 tests/auto/declarative/qquickcanvas/data/window.qml diff --git a/examples/declarative/window/Window.qml b/examples/declarative/window/Window.qml new file mode 100644 index 0000000000..33efd96b0e --- /dev/null +++ b/examples/declarative/window/Window.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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(); + } +} diff --git a/examples/declarative/window/standalone.qml b/examples/declarative/window/standalone.qml new file mode 100644 index 0000000000..d49e9ae788 --- /dev/null +++ b/examples/declarative/window/standalone.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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() + } + } +} diff --git a/examples/declarative/window/window.cpp b/examples/declarative/window/window.cpp new file mode 100644 index 0000000000..56f1c09987 --- /dev/null +++ b/examples/declarative/window/window.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include + +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(); +} diff --git a/examples/declarative/window/window.pro b/examples/declarative/window/window.pro new file mode 100644 index 0000000000..74804bd776 --- /dev/null +++ b/examples/declarative/window/window.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +CONFIG += qt +QT += declarative + +SOURCES += window.cpp diff --git a/src/declarative/items/items.pri b/src/declarative/items/items.pri index f83c65c203..308706f0b9 100644 --- a/src/declarative/items/items.pri +++ b/src/declarative/items/items.pri @@ -66,7 +66,8 @@ HEADERS += \ $$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 \ @@ -112,7 +113,8 @@ SOURCES += \ $$PWD/qquickdrag.cpp \ $$PWD/qquickdroparea.cpp \ $$PWD/qquickmultipointtoucharea.cpp \ - $$PWD/qquickitemview.cpp + $$PWD/qquickitemview.cpp \ + $$PWD/qquickwindowmodule.cpp SOURCES += \ $$PWD/qquickshadereffect.cpp \ diff --git a/src/declarative/items/qquickcanvas.cpp b/src/declarative/items/qquickcanvas.cpp index c6969b5cda..8022af98f4 100644 --- a/src/declarative/items/qquickcanvas.cpp +++ b/src/declarative/items/qquickcanvas.cpp @@ -532,6 +532,23 @@ void QQuickCanvasPrivate::init(QQuickCanvas *c) q->setFormat(context->defaultSurfaceFormat()); } +QDeclarativeListProperty 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 &touchPoints, const QTransform &transform) { for (int i=0; iclearColor) + return; d_func()->clearColor = color; + emit clearColorChanged(color); } diff --git a/src/declarative/items/qquickcanvas.h b/src/declarative/items/qquickcanvas.h index a480439574..6f9d40da48 100644 --- a/src/declarative/items/qquickcanvas.h +++ b/src/declarative/items/qquickcanvas.h @@ -63,8 +63,11 @@ class QInputMethodEvent; class Q_DECLARATIVE_EXPORT QQuickCanvas : public QWindow { -Q_OBJECT -Q_DECLARE_PRIVATE(QQuickCanvas) + Q_OBJECT + Q_PRIVATE_PROPERTY(QQuickCanvas::d_func(), QDeclarativeListProperty 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, @@ -114,6 +117,7 @@ Q_SIGNALS: void sceneGraphInitialized(); void beforeRendering(); void afterRendering(); + void clearColorChanged(const QColor &); protected: QQuickCanvas(QQuickCanvasPrivate &dd, QWindow *parent = 0); diff --git a/src/declarative/items/qquickcanvas_p.h b/src/declarative/items/qquickcanvas_p.h index fdfe0911f5..13ca288cb1 100644 --- a/src/declarative/items/qquickcanvas_p.h +++ b/src/declarative/items/qquickcanvas_p.h @@ -73,13 +73,18 @@ 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; @@ -97,8 +102,10 @@ public: virtual ~QQuickCanvasPrivate(); void init(QQuickCanvas *); + void initRootItem();//Currently only used if items added in QML QQuickRootItem *rootItem; + QDeclarativeListProperty data(); QQuickItem *activeFocusItem; QQuickItem *mouseGrabberItem; @@ -175,6 +182,7 @@ public: QHash itemForTouchPointId; mutable QQuickCanvasIncubationController *incubationController; + private: static void cleanupNodesOnShutdown(QQuickItem *); }; diff --git a/src/declarative/items/qquickwindowmodule.cpp b/src/declarative/items/qquickwindowmodule.cpp new file mode 100644 index 0000000000..7a7f28cb43 --- /dev/null +++ b/src/declarative/items/qquickwindowmodule.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** 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 + +QT_BEGIN_NAMESPACE + +void QQuickWindowModule::defineModule() +{ + const char* uri = "QtQuick.Window"; + + qmlRegisterType(uri, 2, 0, "Window"); +} + +QT_END_NAMESPACE + diff --git a/src/declarative/items/qquickwindowmodule_p.h b/src/declarative/items/qquickwindowmodule_p.h new file mode 100644 index 0000000000..ead15942b9 --- /dev/null +++ b/src/declarative/items/qquickwindowmodule_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickWindowModule +{ +public: + static void defineModule(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/declarative/qtquick2.cpp b/src/declarative/qtquick2.cpp index 72e3251dd8..ff49641865 100644 --- a/src/declarative/qtquick2.cpp +++ b/src/declarative/qtquick2.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -179,6 +180,7 @@ void QDeclarativeQtQuick2Module::defineModule() QDeclarativeEnginePrivate::defineModule(); QQuickItemsModule::defineModule(); QQuickParticlesModule::defineModule(); + QQuickWindowModule::defineModule(); QDeclarativeValueTypeFactory::registerValueTypes(); if (QDeclarativeEngineDebugService::isDebuggingEnabled()) { diff --git a/tests/auto/declarative/qquickcanvas/data/window.qml b/tests/auto/declarative/qquickcanvas/data/window.qml new file mode 100644 index 0000000000..d79d5161b5 --- /dev/null +++ b/tests/auto/declarative/qquickcanvas/data/window.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 +import QtQuick.Window 2.0 as Window + +Window.Window { + color: "#00FF00" + Item { + objectName: "item" + } +} diff --git a/tests/auto/declarative/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/declarative/qquickcanvas/tst_qquickcanvas.cpp index 95fcd82dfa..829d666b7e 100644 --- a/tests/auto/declarative/qquickcanvas/tst_qquickcanvas.cpp +++ b/tests/auto/declarative/qquickcanvas/tst_qquickcanvas.cpp @@ -44,8 +44,11 @@ #include #include #include +#include +#include #include #include +#include "../shared/util.h" struct TouchEventData { QEvent::Type type; @@ -197,6 +200,9 @@ private slots: void clearCanvas(); void mouseFiltering(); + + void qmlCreation(); + void clearColor(); }; tst_qquickcanvas::tst_qquickcanvas() @@ -516,6 +522,35 @@ void tst_qquickcanvas::mouseFiltering() 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(created); + QVERIFY(canvas); + QCOMPARE(canvas->clearColor(), QColor(Qt::green)); + + QQuickItem* item = canvas->findChild("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) -- cgit v1.2.3