aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--examples/quick/demos/demos.pro4
-rw-r--r--examples/quick/demos/rssnews/content/BusyIndicator.qml73
-rw-r--r--examples/quick/demos/rssnews/content/CategoryDelegate.qml147
-rw-r--r--examples/quick/demos/rssnews/content/NewsDelegate.qml146
-rw-r--r--examples/quick/demos/rssnews/content/RssFeeds.qml91
-rw-r--r--examples/quick/demos/rssnews/content/ScrollBar.qml79
-rw-r--r--examples/quick/demos/rssnews/content/images/Asia.jpgbin0 -> 10578 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Business.jpgbin0 -> 17276 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Entertainment.jpgbin0 -> 15433 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Europe.jpgbin0 -> 15872 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Health.jpgbin0 -> 16015 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Politics.jpgbin0 -> 16401 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Science.jpgbin0 -> 9496 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Sports.jpgbin0 -> 9281 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/Technology.jpgbin0 -> 22290 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/TopStories.jpgbin0 -> 8067 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/USNational.jpgbin0 -> 9635 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/World.jpgbin0 -> 15128 bytes
-rw-r--r--examples/quick/demos/rssnews/content/images/btn_close.pngbin0 -> 1267 bytes
-rw-r--r--examples/quick/demos/rssnews/doc/images/qtquick-demo-rssnews-small.pngbin43372 -> 56864 bytes
-rw-r--r--examples/quick/demos/rssnews/main.cpp41
-rw-r--r--examples/quick/demos/rssnews/rssnews.pro13
-rw-r--r--examples/quick/demos/rssnews/rssnews.qml197
-rw-r--r--examples/quick/demos/rssnews/rssnews.qrc25
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp273
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/fbitem.h136
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/logo.cpp141
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/logo.h65
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/main.cpp56
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp216
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h80
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro17
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.qrc5
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/test.qml210
-rw-r--r--examples/quick/quickwidgets/quickwidgets.pro3
-rw-r--r--examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc113
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.cpp74
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.h32
-rw-r--r--src/qml/doc/src/javascript/expressions.qdoc85
-rw-r--r--src/qml/doc/src/javascript/hostenvironment.qdoc4
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp2
-rw-r--r--src/qml/qml/qqmlcomponent.cpp6
-rw-r--r--src/qml/qml/qqmlcomponent_p.h6
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp26
-rw-r--r--src/qml/qml/qqmlobjectcreator_p.h18
-rw-r--r--src/quick/items/qquickflickable_p_p.h2
-rw-r--r--src/quick/items/qquickitem.cpp2
-rw-r--r--src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp4
-rw-r--r--src/quick/scenegraph/util/qsgpainternode.cpp5
-rw-r--r--src/quickwidgets/qquickwidget.cpp3
-rw-r--r--tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp9
-rw-r--r--tests/auto/quick/qquickitem2/data/keysforward.qml6
53 files changed, 1951 insertions, 466 deletions
diff --git a/.qmake.conf b/.qmake.conf
index d170e6d272..effef04600 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -2,4 +2,4 @@ load(qt_build_config)
CONFIG += qt_example_installs
CONFIG += warning_clean
-MODULE_VERSION = 5.3.1
+MODULE_VERSION = 5.3.2
diff --git a/examples/quick/demos/demos.pro b/examples/quick/demos/demos.pro
index ac15cc3c1f..c1768ce721 100644
--- a/examples/quick/demos/demos.pro
+++ b/examples/quick/demos/demos.pro
@@ -5,8 +5,8 @@ SUBDIRS = samegame \
tweetsearch \
maroon \
photosurface \
+ rssnews \
stocqt
EXAMPLE_FILES = \
- photoviewer \
- rssnews
+ photoviewer
diff --git a/examples/quick/demos/rssnews/content/BusyIndicator.qml b/examples/quick/demos/rssnews/content/BusyIndicator.qml
index c16f582c40..e6cd15847a 100644
--- a/examples/quick/demos/rssnews/content/BusyIndicator.qml
+++ b/examples/quick/demos/rssnews/content/BusyIndicator.qml
@@ -1,53 +1,54 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
+** 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 Digia Plc 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 2.2
Image {
id: container
- property bool on: false
- source: "images/busy.png"; visible: container.on
+ source: "images/busy.png";
NumberAnimation on rotation {
- running: container.on; from: 0; to: 360; loops: Animation.Infinite; duration: 1200
+ running: container.visible
+ from: 0; to: 360;
+ loops: Animation.Infinite;
+ duration: 1200
}
}
diff --git a/examples/quick/demos/rssnews/content/CategoryDelegate.qml b/examples/quick/demos/rssnews/content/CategoryDelegate.qml
index 31dd9c0d3b..cb48715609 100644
--- a/examples/quick/demos/rssnews/content/CategoryDelegate.qml
+++ b/examples/quick/demos/rssnews/content/CategoryDelegate.qml
@@ -1,82 +1,125 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtQml module of the Qt Toolkit.
+** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** "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 Digia Plc 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.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
**
+** 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 2.2
+import QtGraphicalEffects 1.0
-Item {
+Rectangle {
id: delegate
- width: delegate.ListView.view.width; height: 60
+ property bool selected: ListView.isCurrentItem
+ property real itemSize
+ width: itemSize
+ height: itemSize
- Text {
- text: name
- color: delegate.ListView.isCurrentItem ? "white" : "black"
- font { family: "Helvetica"; pixelSize: 16; bold: true }
- anchors {
- left: parent.left; leftMargin: 15
- verticalCenter: parent.verticalCenter
- }
+ Image {
+ anchors.centerIn: parent
+ source: image
}
- BusyIndicator {
- scale: 0.6
- on: delegate.ListView.isCurrentItem && window.loading
- anchors { right: parent.right; rightMargin: 10; verticalCenter: parent.verticalCenter }
- }
+ Item {
+ id: title
+ anchors.fill: parent
+
+ Text {
+ id: titleText
+
+ anchors {
+ left: parent.left; leftMargin: 20
+ right: parent.right; rightMargin: 20
+ top: parent.top; topMargin: 20
+ }
+ font { pixelSize: 18; bold: true }
+ text: name
+ color: selected ? "#ffffff" : "#ebebdd"
+ Behavior on color { ColorAnimation { duration: 150 } }
+ }
- Rectangle {
- width: delegate.width; height: 1; color: "#cccccc"
- anchors.bottom: delegate.bottom
- visible: delegate.ListView.isCurrentItem ? false : true
+ DropShadow {
+ source: titleText
+ anchors.fill: titleText
+ horizontalOffset: selected ? 3 : 1
+ verticalOffset: selected ? 3 : 1
+ radius: 4
+ color: "#2f1000"
+ samples: 8
+
+ Behavior on horizontalOffset { NumberAnimation { duration: 300 } }
+ Behavior on verticalOffset { NumberAnimation { duration: 300 } }
+ }
+
+ states: [
+ State {
+ name: "selected"
+ when: selected
+ PropertyChanges { target: title; scale: "1.1" }
+ }]
+
+ transitions: [
+ Transition {
+ to: "selected"
+ SequentialAnimation {
+ id: titleAnimation
+ PropertyAnimation { target: title; property: "scale"; duration: 300 }
+ }
+ },
+ Transition {
+ to: ""
+ animations: titleAnimation
+ }]
}
- Rectangle {
- width: delegate.width; height: 1; color: "white"
- visible: delegate.ListView.isCurrentItem ? false : true
+
+ BusyIndicator {
+ scale: 0.8
+ visible: delegate.ListView.isCurrentItem && window.loading
+ anchors.centerIn: parent
}
MouseArea {
anchors.fill: delegate
onClicked: {
delegate.ListView.view.currentIndex = index
- window.currentFeed = feed
+ if (window.currentFeed == feed)
+ feedModel.reload()
+ else
+ window.currentFeed = feed
}
}
}
diff --git a/examples/quick/demos/rssnews/content/NewsDelegate.qml b/examples/quick/demos/rssnews/content/NewsDelegate.qml
index ec39510eba..fee1119b08 100644
--- a/examples/quick/demos/rssnews/content/NewsDelegate.qml
+++ b/examples/quick/demos/rssnews/content/NewsDelegate.qml
@@ -1,71 +1,129 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtQml module of the Qt Toolkit.
+** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** "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 Digia Plc 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.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
**
+** 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 2.2
+import QtQuick.Layouts 1.1
-Item {
+ColumnLayout {
id: delegate
- height: column.height + 40
width: delegate.ListView.view.width
- Column {
- id: column
- x: 20; y: 20
- width: parent.width - 40
+ // Returns a string representing how long ago an event occurred
+ function timeSinceEvent(pubDate) {
+ var result = pubDate;
+
+ // We need to modify the pubDate read from the RSS feed
+ // so the JavaScript Date object can interpret it
+ var d = pubDate.replace(',','').split(' ');
+ if (d.length != 6)
+ return result;
+
+ var date = new Date([d[0], d[2], d[1], d[3], d[4], 'GMT' + d[5]].join(' '));
+
+ if (!isNaN(date.getDate())) {
+ var age = new Date() - date;
+ var minutes = Math.floor(Number(age) / 60000);
+ if (minutes < 1440) {
+ if (minutes < 2)
+ result = qsTr("Just now");
+ else if (minutes < 60)
+ result = '' + minutes + ' ' + qsTr("minutes ago")
+ else if (minutes < 120)
+ result = qsTr("1 hour ago");
+ else
+ result = '' + Math.floor(minutes/60) + ' ' + qsTr("hours ago");
+ }
+ else {
+ result = date.toDateString();
+ }
+ }
+ return result;
+ }
+
+ RowLayout {
+ Layout.maximumWidth: parent.width
+
+ ColumnLayout {
+ Layout.alignment: Qt.AlignTop
+
+ Item {
+ height: titleText.font.pixelSize / 4
+ }
+
+ Image {
+ id: titleImage
+ source: image
+ }
+ }
Text {
id: titleText
- text: title; width: parent.width; wrapMode: Text.WordWrap
- font { bold: true; family: "Helvetica"; pointSize: 16 }
+
+ text: title
+ Layout.maximumWidth: delegate.width - titleImage.width
+ wrapMode: Text.WordWrap
+ font.pixelSize: 26
+ font.bold: true
}
+ }
- Text {
- id: descriptionText
- width: parent.width; text: description
- wrapMode: Text.WordWrap; font.family: "Helvetica"
+ Text {
+ Layout.maximumWidth: delegate.width
+ font.pixelSize: 12
+ textFormat: Text.RichText
+ font.italic: true
+ Layout.alignment: Qt.AlignLeft
+ text: timeSinceEvent(pubDate) + " (<a href=\"" + link + "\">Link</a>)"
+ onLinkActivated: {
+ Qt.openUrlExternally(link)
}
}
- Rectangle {
- width: parent.width; height: 1; color: "#cccccc"
- anchors.bottom: parent.bottom
+ Text {
+ id: descriptionText
+
+ text: description
+ Layout.maximumWidth: parent.width
+ wrapMode: Text.WordWrap
+ font.pixelSize: 14
+ textFormat: Text.StyledText
+ horizontalAlignment: Qt.AlignLeft
}
}
diff --git a/examples/quick/demos/rssnews/content/RssFeeds.qml b/examples/quick/demos/rssnews/content/RssFeeds.qml
index 50bc771192..3ae3b23921 100644
--- a/examples/quick/demos/rssnews/content/RssFeeds.qml
+++ b/examples/quick/demos/rssnews/content/RssFeeds.qml
@@ -1,59 +1,56 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
-**
+** 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 Digia Plc 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 2.2
ListModel {
- id: rssFeeds
-
- ListElement { name: "Top Stories"; feed: "rss.news.yahoo.com/rss/topstories" }
- ListElement { name: "World"; feed: "rss.news.yahoo.com/rss/world" }
- ListElement { name: "Europe"; feed: "rss.news.yahoo.com/rss/europe" }
- ListElement { name: "Oceania"; feed: "rss.news.yahoo.com/rss/oceania" }
- ListElement { name: "U.S. National"; feed: "rss.news.yahoo.com/rss/us" }
- ListElement { name: "Politics"; feed: "rss.news.yahoo.com/rss/politics" }
- ListElement { name: "Business"; feed: "rss.news.yahoo.com/rss/business" }
- ListElement { name: "Technology"; feed: "rss.news.yahoo.com/rss/tech" }
- ListElement { name: "Entertainment"; feed: "rss.news.yahoo.com/rss/entertainment" }
- ListElement { name: "Health"; feed: "rss.news.yahoo.com/rss/health" }
- ListElement { name: "Science"; feed: "rss.news.yahoo.com/rss/science" }
- ListElement { name: "Sports"; feed: "rss.news.yahoo.com/rss/sports" }
+ ListElement { name: "Top Stories"; feed: "news.yahoo.com/rss/topstories"; image: "images/TopStories.jpg" }
+ ListElement { name: "World"; feed: "news.yahoo.com/rss/world"; image: "images/World.jpg" }
+ ListElement { name: "Europe"; feed: "news.yahoo.com/rss/europe"; image: "images/Europe.jpg" }
+ ListElement { name: "Asia"; feed: "news.yahoo.com/rss/asia"; image: "images/Asia.jpg" }
+ ListElement { name: "U.S. National"; feed: "news.yahoo.com/rss/us"; image: "images/USNational.jpg" }
+ ListElement { name: "Politics"; feed: "news.yahoo.com/rss/politics"; image: "images/Politics.jpg" }
+ ListElement { name: "Business"; feed: "news.yahoo.com/rss/business"; image: "images/Business.jpg" }
+ ListElement { name: "Technology"; feed: "news.yahoo.com/rss/tech"; image: "images/Technology.jpg" }
+ ListElement { name: "Entertainment"; feed: "news.yahoo.com/rss/entertainment"; image: "images/Entertainment.jpg" }
+ ListElement { name: "Health"; feed: "news.yahoo.com/rss/health"; image: "images/Health.jpg" }
+ ListElement { name: "Science"; feed: "news.yahoo.com/rss/science"; image: "images/Science.jpg" }
+ ListElement { name: "Sports"; feed: "news.yahoo.com/rss/sports"; image: "images/Sports.jpg" }
}
diff --git a/examples/quick/demos/rssnews/content/ScrollBar.qml b/examples/quick/demos/rssnews/content/ScrollBar.qml
index d3cf4a6851..606f2e4259 100644
--- a/examples/quick/demos/rssnews/content/ScrollBar.qml
+++ b/examples/quick/demos/rssnews/content/ScrollBar.qml
@@ -1,51 +1,50 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtQml module of the Qt Toolkit.
+** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** "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 Digia Plc 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.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
**
+** 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 2.2
Item {
id: container
property variant scrollArea
- property variant orientation: Qt.Vertical
+ property int orientation: Qt.Vertical
opacity: 0
@@ -56,7 +55,11 @@ Item {
ny = scrollArea.visibleArea.yPosition * container.height;
else
ny = scrollArea.visibleArea.xPosition * container.width;
- if (ny > 2) return ny; else return 2;
+
+ if (ny > 2)
+ return ny;
+ else
+ return 2;
}
function size()
@@ -79,8 +82,12 @@ Item {
t = Math.ceil(container.height - 3 - ny);
else
t = Math.ceil(container.width - 3 - ny);
- if (nh > t) return t; else return nh;
- } else return nh + ny;
+ if (nh > t)
+ return t;
+ else
+ return nh;
+ } else
+ return nh + ny;
}
Rectangle { anchors.fill: parent; color: "Black"; opacity: 0.3 }
@@ -89,14 +96,16 @@ Item {
source: "images/scrollbar.png"
border { left: 1; right: 1; top: 1; bottom: 1 }
x: container.orientation == Qt.Vertical ? 2 : position()
- width: container.orientation == Qt.Vertical ? container.width - 4 : size()
y: container.orientation == Qt.Vertical ? position() : 2
+ width: container.orientation == Qt.Vertical ? container.width - 4 : size()
height: container.orientation == Qt.Vertical ? size() : container.height - 4
}
states: State {
name: "visible"
- when: container.orientation == Qt.Vertical ? scrollArea.movingVertically : scrollArea.movingHorizontally
+ when: container.orientation == Qt.Vertical ?
+ scrollArea.movingVertically :
+ scrollArea.movingHorizontally
PropertyChanges { target: container; opacity: 1.0 }
}
diff --git a/examples/quick/demos/rssnews/content/images/Asia.jpg b/examples/quick/demos/rssnews/content/images/Asia.jpg
new file mode 100644
index 0000000000..a609557a08
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Asia.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Business.jpg b/examples/quick/demos/rssnews/content/images/Business.jpg
new file mode 100644
index 0000000000..b2c1d92138
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Business.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Entertainment.jpg b/examples/quick/demos/rssnews/content/images/Entertainment.jpg
new file mode 100644
index 0000000000..2c69fc04d7
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Entertainment.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Europe.jpg b/examples/quick/demos/rssnews/content/images/Europe.jpg
new file mode 100644
index 0000000000..bf524e13d0
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Europe.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Health.jpg b/examples/quick/demos/rssnews/content/images/Health.jpg
new file mode 100644
index 0000000000..0e8c71f0c9
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Health.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Politics.jpg b/examples/quick/demos/rssnews/content/images/Politics.jpg
new file mode 100644
index 0000000000..0b1800c97e
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Politics.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Science.jpg b/examples/quick/demos/rssnews/content/images/Science.jpg
new file mode 100644
index 0000000000..7faccbbb97
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Science.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Sports.jpg b/examples/quick/demos/rssnews/content/images/Sports.jpg
new file mode 100644
index 0000000000..0ab3bd3ce7
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Sports.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/Technology.jpg b/examples/quick/demos/rssnews/content/images/Technology.jpg
new file mode 100644
index 0000000000..db553028fb
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/Technology.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/TopStories.jpg b/examples/quick/demos/rssnews/content/images/TopStories.jpg
new file mode 100644
index 0000000000..e35bd67f20
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/TopStories.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/USNational.jpg b/examples/quick/demos/rssnews/content/images/USNational.jpg
new file mode 100644
index 0000000000..82c78228c1
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/USNational.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/World.jpg b/examples/quick/demos/rssnews/content/images/World.jpg
new file mode 100644
index 0000000000..7a0a806fd4
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/World.jpg
Binary files differ
diff --git a/examples/quick/demos/rssnews/content/images/btn_close.png b/examples/quick/demos/rssnews/content/images/btn_close.png
new file mode 100644
index 0000000000..6d635375eb
--- /dev/null
+++ b/examples/quick/demos/rssnews/content/images/btn_close.png
Binary files differ
diff --git a/examples/quick/demos/rssnews/doc/images/qtquick-demo-rssnews-small.png b/examples/quick/demos/rssnews/doc/images/qtquick-demo-rssnews-small.png
index 0ad6c02251..ffef99ee5c 100644
--- a/examples/quick/demos/rssnews/doc/images/qtquick-demo-rssnews-small.png
+++ b/examples/quick/demos/rssnews/doc/images/qtquick-demo-rssnews-small.png
Binary files differ
diff --git a/examples/quick/demos/rssnews/main.cpp b/examples/quick/demos/rssnews/main.cpp
new file mode 100644
index 0000000000..0064412f39
--- /dev/null
+++ b/examples/quick/demos/rssnews/main.cpp
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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 "../../shared/shared.h"
+DECLARATIVE_EXAMPLE_MAIN(demos/rssnews/rssnews)
diff --git a/examples/quick/demos/rssnews/rssnews.pro b/examples/quick/demos/rssnews/rssnews.pro
new file mode 100644
index 0000000000..c67c5a6558
--- /dev/null
+++ b/examples/quick/demos/rssnews/rssnews.pro
@@ -0,0 +1,13 @@
+TEMPLATE = app
+
+QT += quick qml xml xmlpatterns
+SOURCES += main.cpp
+RESOURCES += rssnews.qrc
+
+OTHER_FILES = rssnews.qml \
+ content/*.qml \
+ content/*.js \
+ content/images/*
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/demos/rssnews
+INSTALLS += target
diff --git a/examples/quick/demos/rssnews/rssnews.qml b/examples/quick/demos/rssnews/rssnews.qml
index a367490ef7..cb9734208d 100644
--- a/examples/quick/demos/rssnews/rssnews.qml
+++ b/examples/quick/demos/rssnews/rssnews.qml
@@ -1,112 +1,159 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
-** This file is part of the QtQml module of the Qt Toolkit.
+** This file is part of the examples of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** "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 Digia Plc 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.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia 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.
**
+** 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 2.2
import QtQuick.XmlListModel 2.0
-import "content"
+import QtQuick.Window 2.1
+import "./content"
Rectangle {
id: window
- width: 800; height: 480
- property string currentFeed: "rss.news.yahoo.com/rss/topstories"
- property bool loading: feedModel.status == XmlListModel.Loading
+ width: 800
+ height: 480
+
+ property string currentFeed: rssFeeds.get(0).feed
+ property bool loading: feedModel.status === XmlListModel.Loading
+ property bool isPortrait: Screen.primaryOrientation === Qt.PortraitOrientation
+
+ onLoadingChanged: {
+ if (feedModel.status == XmlListModel.Ready)
+ list.positionViewAtBeginning()
+ }
RssFeeds { id: rssFeeds }
XmlListModel {
id: feedModel
+
source: "http://" + window.currentFeed
- query: "/rss/channel/item"
+ query: "/rss/channel/item[child::media:content]"
+ namespaceDeclarations: "declare namespace media = 'http://search.yahoo.com/mrss/';"
XmlRole { name: "title"; query: "title/string()" }
+ // Remove any links from the description
+ XmlRole { name: "description"; query: "fn:replace(description/string(), '\&lt;a href=.*\/a\&gt;', '')" }
+ XmlRole { name: "image"; query: "media:content/@url/string()" }
XmlRole { name: "link"; query: "link/string()" }
- XmlRole { name: "description"; query: "description/string()" }
+ XmlRole { name: "pubDate"; query: "pubDate/string()" }
}
- Row {
- Rectangle {
- width: 220; height: window.height
- color: "#efefef"
-
- ListView {
- focus: true
- id: categories
- anchors.fill: parent
- model: rssFeeds
- footer: quitButtonDelegate
- delegate: CategoryDelegate {}
- highlight: Rectangle { color: "steelblue" }
- highlightMoveVelocity: 9999999
- }
- ScrollBar {
- scrollArea: categories; height: categories.height; width: 8
- anchors.right: categories.right
- }
- }
- ListView {
- id: list
- width: window.width - 220; height: window.height
- model: feedModel
- delegate: NewsDelegate {}
- }
+ ListView {
+ id: categories
+ property int itemWidth: 190
+
+ width: isPortrait ? parent.width : itemWidth
+ height: isPortrait ? itemWidth : parent.height
+ orientation: isPortrait ? ListView.Horizontal : ListView.Vertical
+ anchors.top: parent.top
+ model: rssFeeds
+ delegate: CategoryDelegate { itemSize: categories.itemWidth }
+ spacing: 3
+ }
+
+ ScrollBar {
+ id: listScrollBar
+
+ orientation: isPortrait ? Qt.Horizontal : Qt.Vertical
+ height: isPortrait ? 8 : categories.height;
+ width: isPortrait ? categories.width : 8
+ scrollArea: categories;
+ anchors.right: categories.right
}
+
+ ListView {
+ id: list
+
+ anchors.left: isPortrait ? window.left : categories.right
+ anchors.right: closeButton.left
+ anchors.top: isPortrait ? categories.bottom : window.top
+ anchors.bottom: window.bottom
+ anchors.leftMargin: 30
+ anchors.rightMargin: 4
+ clip: isPortrait
+ model: feedModel
+ footer: footerText
+ delegate: NewsDelegate {}
+ }
+
+ ScrollBar {
+ scrollArea: list
+ width: 8
+ anchors.right: window.right
+ anchors.top: isPortrait ? categories.bottom : window.top
+ anchors.bottom: window.bottom
+ }
+
Component {
- id: quitButtonDelegate
- Item {
- width: categories.width; height: 60
+ id: footerText
+
+ Rectangle {
+ width: parent.width
+ height: closeButton.height
+ color: "lightgray"
+
Text {
- text: "Quit"
- font { family: "Helvetica"; pixelSize: 16; bold: true }
- anchors {
- left: parent.left; leftMargin: 15
- verticalCenter: parent.verticalCenter
- }
+ text: "RSS Feed from Yahoo News"
+ anchors.centerIn: parent
+ font.pixelSize: 14
}
- MouseArea {
- anchors.fill: parent
- onClicked: Qt.quit()
+ }
+ }
+
+ Image {
+ id: closeButton
+ source: "content/images/btn_close.png"
+ scale: 0.8
+ anchors.top: parent.top
+ anchors.right: parent.right
+ anchors.margins: 4
+ opacity: (isPortrait && categories.moving) ? 0.2 : 1.0
+ Behavior on opacity {
+ NumberAnimation { duration: 300; easing.type: Easing.OutSine }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ Qt.quit()
}
}
}
- ScrollBar { scrollArea: list; height: list.height; width: 8; anchors.right: window.right }
- Rectangle { x: 220; height: window.height; width: 1; color: "#cccccc" }
}
diff --git a/examples/quick/demos/rssnews/rssnews.qrc b/examples/quick/demos/rssnews/rssnews.qrc
new file mode 100644
index 0000000000..1208d44fd7
--- /dev/null
+++ b/examples/quick/demos/rssnews/rssnews.qrc
@@ -0,0 +1,25 @@
+<RCC>
+ <qresource prefix="/demos/rssnews">
+ <file>rssnews.qml</file>
+ <file>content/BusyIndicator.qml</file>
+ <file>content/CategoryDelegate.qml</file>
+ <file>content/NewsDelegate.qml</file>
+ <file>content/RssFeeds.qml</file>
+ <file>content/ScrollBar.qml</file>
+ <file>content/images/btn_close.png</file>
+ <file>content/images/Business.jpg</file>
+ <file>content/images/busy.png</file>
+ <file>content/images/Entertainment.jpg</file>
+ <file>content/images/Europe.jpg</file>
+ <file>content/images/Health.jpg</file>
+ <file>content/images/Asia.jpg</file>
+ <file>content/images/Politics.jpg</file>
+ <file>content/images/Science.jpg</file>
+ <file>content/images/scrollbar.png</file>
+ <file>content/images/Sports.jpg</file>
+ <file>content/images/Technology.jpg</file>
+ <file>content/images/TopStories.jpg</file>
+ <file>content/images/USNational.jpg</file>
+ <file>content/images/World.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp
new file mode 100644
index 0000000000..3b9f2e97f3
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.cpp
@@ -0,0 +1,273 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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 "fbitem.h"
+#include <QOpenGLFramebufferObject>
+#include <QOpenGLFunctions>
+#include <QMatrix4x4>
+
+FbItem::FbItem(QQuickItem *parent)
+ : QQuickFramebufferObject(parent),
+ m_target(0, 0, -1),
+ m_syncState(AllNeedsSync),
+ m_multisample(false)
+{
+}
+
+QQuickFramebufferObject::Renderer *FbItem::createRenderer() const
+{
+ return new FbItemRenderer(m_multisample);
+}
+
+void FbItem::setEye(const QVector3D &v)
+{
+ if (m_eye != v) {
+ m_eye = v;
+ m_syncState |= CameraNeedsSync;
+ update();
+ }
+}
+
+void FbItem::setTarget(const QVector3D &v)
+{
+ if (m_target != v) {
+ m_target = v;
+ m_syncState |= CameraNeedsSync;
+ update();
+ }
+}
+
+void FbItem::setRotation(const QVector3D &v)
+{
+ if (m_rotation != v) {
+ m_rotation = v;
+ m_syncState |= RotationNeedsSync;
+ update();
+ }
+}
+
+int FbItem::swapSyncState()
+{
+ int s = m_syncState;
+ m_syncState = 0;
+ return s;
+}
+
+FbItemRenderer::FbItemRenderer(bool multisample)
+ : m_inited(false),
+ m_multisample(multisample),
+ m_dirty(DirtyAll)
+{
+ m_camera.setToIdentity();
+ m_baseWorld.setToIdentity();
+ m_baseWorld.translate(0, 0, -1);
+ m_world = m_baseWorld;
+}
+
+void FbItemRenderer::synchronize(QQuickFramebufferObject *qfbitem)
+{
+ FbItem *item = static_cast<FbItem *>(qfbitem);
+ int syncState = item->swapSyncState();
+ if (syncState & FbItem::CameraNeedsSync) {
+ m_camera.setToIdentity();
+ m_camera.lookAt(item->eye(), item->eye() + item->target(), QVector3D(0, 1, 0));
+ m_dirty |= DirtyCamera;
+ }
+ if (syncState & FbItem::RotationNeedsSync) {
+ m_rotation = item->rotation();
+ m_dirty |= DirtyWorld;
+ }
+}
+
+struct StateBinder
+{
+ StateBinder(FbItemRenderer *r)
+ : m_r(r) {
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ f->glEnable(GL_DEPTH_TEST);
+ f->glEnable(GL_CULL_FACE);
+ f->glDepthMask(GL_TRUE);
+ f->glDepthFunc(GL_LESS);
+ f->glFrontFace(GL_CCW);
+ f->glCullFace(GL_BACK);
+ m_r->m_program->bind();
+ }
+ ~StateBinder() {
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ m_r->m_program->release();
+ f->glDisable(GL_CULL_FACE);
+ f->glDisable(GL_DEPTH_TEST);
+ }
+ FbItemRenderer *m_r;
+};
+
+void FbItemRenderer::updateDirtyUniforms()
+{
+ if (m_dirty & DirtyProjection)
+ m_program->setUniformValue(m_projMatrixLoc, m_proj);
+
+ if (m_dirty & DirtyCamera)
+ m_program->setUniformValue(m_camMatrixLoc, m_camera);
+
+ if (m_dirty & DirtyWorld) {
+ m_program->setUniformValue(m_worldMatrixLoc, m_world);
+ QMatrix3x3 normalMatrix = m_world.normalMatrix();
+ m_program->setUniformValue(m_normalMatrixLoc, normalMatrix);
+ }
+
+ if (m_dirty & DirtyLight)
+ m_program->setUniformValue(m_lightPosLoc, QVector3D(0, 0, 70));
+
+ m_dirty = 0;
+}
+
+void FbItemRenderer::render()
+{
+ ensureInit();
+
+ QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
+ if (!m_vao.isCreated())
+ setupVertexAttribs();
+
+ StateBinder state(this);
+
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ f->glClearColor(0, 0, 0, 0);
+ f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ if (m_dirty & DirtyWorld) {
+ m_world = m_baseWorld;
+ m_world.rotate(m_rotation.x(), 1, 0, 0);
+ m_world.rotate(m_rotation.y(), 0, 1, 0);
+ m_world.rotate(m_rotation.z(), 0, 0, 1);
+ }
+
+ updateDirtyUniforms();
+
+ f->glDrawArrays(GL_TRIANGLES, 0, m_logo.vertexCount());
+}
+
+QOpenGLFramebufferObject *FbItemRenderer::createFramebufferObject(const QSize &size)
+{
+ m_dirty |= DirtyProjection;
+ m_proj.setToIdentity();
+ m_proj.perspective(45.0f, GLfloat(size.width()) / size.height(), 0.01f, 100.0f);
+
+ QOpenGLFramebufferObjectFormat format;
+ format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
+ format.setSamples(m_multisample ? 4 : 0);
+ return new QOpenGLFramebufferObject(size, format);
+}
+
+void FbItemRenderer::ensureInit()
+{
+ if (m_inited)
+ return;
+
+ m_inited = true;
+
+ initBuf();
+ initProgram();
+}
+
+void FbItemRenderer::initBuf()
+{
+ m_vao.create();
+ QOpenGLVertexArrayObject::Binder vaoBinder(&m_vao);
+
+ m_logoVbo.create();
+ m_logoVbo.bind();
+ m_logoVbo.allocate(m_logo.constData(), m_logo.count() * sizeof(GLfloat));
+
+ setupVertexAttribs();
+}
+
+void FbItemRenderer::setupVertexAttribs()
+{
+ m_logoVbo.bind();
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ f->glEnableVertexAttribArray(0);
+ f->glEnableVertexAttribArray(1);
+ f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), 0);
+ f->glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), reinterpret_cast<void *>(3 * sizeof(GLfloat)));
+ m_logoVbo.release();
+}
+
+static const char *vertexShaderSource =
+ "attribute vec4 vertex;\n"
+ "attribute vec3 normal;\n"
+ "varying vec3 vert;\n"
+ "varying vec3 vertNormal;\n"
+ "uniform mat4 projMatrix;\n"
+ "uniform mat4 camMatrix;\n"
+ "uniform mat4 worldMatrix;\n"
+ "uniform mat3 normalMatrix;\n"
+ "void main() {\n"
+ " vert = vertex.xyz;\n"
+ " vertNormal = normalMatrix * normal;\n"
+ " gl_Position = projMatrix * camMatrix * worldMatrix * vertex;\n"
+ "}\n";
+
+static const char *fragmentShaderSource =
+ "varying highp vec3 vert;\n"
+ "varying highp vec3 vertNormal;\n"
+ "uniform highp vec3 lightPos;\n"
+ "void main() {\n"
+ " highp vec3 L = normalize(lightPos - vert);\n"
+ " highp float NL = max(dot(normalize(vertNormal), L), 0.0);\n"
+ " highp vec3 color = vec3(0.39, 1.0, 0.0);\n"
+ " highp vec3 col = clamp(color * 0.2 + color * 0.8 * NL, 0.0, 1.0);\n"
+ " gl_FragColor = vec4(col, 1.0);\n"
+ "}\n";
+
+void FbItemRenderer::initProgram()
+{
+ m_program.reset(new QOpenGLShaderProgram);
+ m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSource);
+ m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSource);
+ m_program->bindAttributeLocation("vertex", 0);
+ m_program->bindAttributeLocation("normal", 1);
+ m_program->link();
+ m_projMatrixLoc = m_program->uniformLocation("projMatrix");
+ m_camMatrixLoc = m_program->uniformLocation("camMatrix");
+ m_worldMatrixLoc = m_program->uniformLocation("worldMatrix");
+ m_normalMatrixLoc = m_program->uniformLocation("normalMatrix");
+ m_lightPosLoc = m_program->uniformLocation("lightPos");
+}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h
new file mode 100644
index 0000000000..b29998c253
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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$
+**
+****************************************************************************/
+
+#ifndef FBITEM_H
+#define FBITEM_H
+
+#include <QQuickFramebufferObject>
+#include <QOpenGLVertexArrayObject>
+#include <QOpenGLBuffer>
+#include <QOpenGLShaderProgram>
+#include <QVector3D>
+#include "logo.h"
+
+struct StateBinder;
+
+class FbItemRenderer : public QQuickFramebufferObject::Renderer
+{
+public:
+ FbItemRenderer(bool multisample);
+ void synchronize(QQuickFramebufferObject *item) Q_DECL_OVERRIDE;
+ void render() Q_DECL_OVERRIDE;
+ QOpenGLFramebufferObject *createFramebufferObject(const QSize &size) Q_DECL_OVERRIDE;
+
+private:
+ void ensureInit();
+ void initBuf();
+ void setupVertexAttribs();
+ void initProgram();
+ void updateDirtyUniforms();
+
+ bool m_inited;
+ bool m_multisample;
+ QMatrix4x4 m_proj;
+ QMatrix4x4 m_camera;
+ QMatrix4x4 m_baseWorld;
+ QMatrix4x4 m_world;
+ QOpenGLVertexArrayObject m_vao;
+ QOpenGLBuffer m_logoVbo;
+ Logo m_logo;
+ QScopedPointer<QOpenGLShaderProgram> m_program;
+ int m_projMatrixLoc;
+ int m_camMatrixLoc;
+ int m_worldMatrixLoc;
+ int m_normalMatrixLoc;
+ int m_lightPosLoc;
+ QVector3D m_rotation;
+
+ enum Dirty {
+ DirtyProjection = 0x01,
+ DirtyCamera = 0x02,
+ DirtyWorld = 0x04,
+ DirtyLight = 0x08,
+ DirtyAll = 0xFF
+ };
+ int m_dirty;
+
+ friend struct StateBinder;
+};
+
+class FbItem : public QQuickFramebufferObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QVector3D eye READ eye WRITE setEye)
+ Q_PROPERTY(QVector3D target READ target WRITE setTarget)
+ Q_PROPERTY(QVector3D rotation READ rotation WRITE setRotation)
+ Q_PROPERTY(bool multisample READ multisample WRITE setMultisample)
+
+public:
+ explicit FbItem(QQuickItem *parent = 0);
+
+ QQuickFramebufferObject::Renderer *createRenderer() const Q_DECL_OVERRIDE;
+
+ QVector3D eye() const { return m_eye; }
+ void setEye(const QVector3D &v);
+ QVector3D target() const { return m_target; }
+ void setTarget(const QVector3D &v);
+
+ QVector3D rotation() const { return m_rotation; }
+ void setRotation(const QVector3D &v);
+
+ enum SyncState {
+ CameraNeedsSync = 0x01,
+ RotationNeedsSync = 0x02,
+ AllNeedsSync = 0xFF
+ };
+ int swapSyncState();
+
+ bool multisample() const { return m_multisample; }
+ void setMultisample(bool m) { m_multisample = m; }
+
+private:
+ QVector3D m_eye;
+ QVector3D m_target;
+ QVector3D m_rotation;
+ int m_syncState;
+ bool m_multisample;
+};
+
+#endif // FBITEM_H
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/logo.cpp b/examples/quick/quickwidgets/qquickviewcomparison/logo.cpp
new file mode 100644
index 0000000000..1ba47ddfb5
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/logo.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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 "logo.h"
+#include <qmath.h>
+
+Logo::Logo()
+ : m_count(0)
+{
+ m_data.resize(2500 * 6);
+
+ const GLfloat x1 = +0.06f;
+ const GLfloat y1 = -0.14f;
+ const GLfloat x2 = +0.14f;
+ const GLfloat y2 = -0.06f;
+ const GLfloat x3 = +0.08f;
+ const GLfloat y3 = +0.00f;
+ const GLfloat x4 = +0.30f;
+ const GLfloat y4 = +0.22f;
+
+ quad(x1, y1, x2, y2, y2, x2, y1, x1);
+ quad(x3, y3, x4, y4, y4, x4, y3, x3);
+
+ extrude(x1, y1, x2, y2);
+ extrude(x2, y2, y2, x2);
+ extrude(y2, x2, y1, x1);
+ extrude(y1, x1, x1, y1);
+ extrude(x3, y3, x4, y4);
+ extrude(x4, y4, y4, x4);
+ extrude(y4, x4, y3, x3);
+
+ const int NumSectors = 100;
+
+ for (int i = 0; i < NumSectors; ++i) {
+ GLfloat angle = (i * 2 * M_PI) / NumSectors;
+ GLfloat angleSin = qSin(angle);
+ GLfloat angleCos = qCos(angle);
+ const GLfloat x5 = 0.30f * angleSin;
+ const GLfloat y5 = 0.30f * angleCos;
+ const GLfloat x6 = 0.20f * angleSin;
+ const GLfloat y6 = 0.20f * angleCos;
+
+ angle = ((i + 1) * 2 * M_PI) / NumSectors;
+ angleSin = qSin(angle);
+ angleCos = qCos(angle);
+ const GLfloat x7 = 0.20f * angleSin;
+ const GLfloat y7 = 0.20f * angleCos;
+ const GLfloat x8 = 0.30f * angleSin;
+ const GLfloat y8 = 0.30f * angleCos;
+
+ quad(x5, y5, x6, y6, x7, y7, x8, y8);
+
+ extrude(x6, y6, x7, y7);
+ extrude(x8, y8, x5, y5);
+ }
+}
+
+void Logo::add(const QVector3D &v, const QVector3D &n)
+{
+ GLfloat *p = m_data.data() + m_count;
+ *p++ = v.x();
+ *p++ = v.y();
+ *p++ = v.z();
+ *p++ = n.x();
+ *p++ = n.y();
+ *p++ = n.z();
+ m_count += 6;
+}
+
+void Logo::quad(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat x4, GLfloat y4)
+{
+ QVector3D n = QVector3D::normal(QVector3D(x4 - x1, y4 - y1, 0.0f), QVector3D(x2 - x1, y2 - y1, 0.0f));
+
+ add(QVector3D(x1, y1, -0.05f), n);
+ add(QVector3D(x4, y4, -0.05f), n);
+ add(QVector3D(x2, y2, -0.05f), n);
+
+ add(QVector3D(x3, y3, -0.05f), n);
+ add(QVector3D(x2, y2, -0.05f), n);
+ add(QVector3D(x4, y4, -0.05f), n);
+
+ n = QVector3D::normal(QVector3D(x1 - x4, y1 - y4, 0.0f), QVector3D(x2 - x4, y2 - y4, 0.0f));
+
+ add(QVector3D(x4, y4, 0.05f), n);
+ add(QVector3D(x1, y1, 0.05f), n);
+ add(QVector3D(x2, y2, 0.05f), n);
+
+ add(QVector3D(x2, y2, 0.05f), n);
+ add(QVector3D(x3, y3, 0.05f), n);
+ add(QVector3D(x4, y4, 0.05f), n);
+}
+
+void Logo::extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+ QVector3D n = QVector3D::normal(QVector3D(0.0f, 0.0f, -0.1f), QVector3D(x2 - x1, y2 - y1, 0.0f));
+
+ add(QVector3D(x1, y1, +0.05f), n);
+ add(QVector3D(x1, y1, -0.05f), n);
+ add(QVector3D(x2, y2, +0.05f), n);
+
+ add(QVector3D(x2, y2, -0.05f), n);
+ add(QVector3D(x2, y2, +0.05f), n);
+ add(QVector3D(x1, y1, -0.05f), n);
+}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/logo.h b/examples/quick/quickwidgets/qquickviewcomparison/logo.h
new file mode 100644
index 0000000000..29bb7fa241
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/logo.h
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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$
+**
+****************************************************************************/
+
+#ifndef LOGO_H
+#define LOGO_H
+
+#include <qopengl.h>
+#include <QVector>
+#include <QVector3D>
+
+class Logo
+{
+public:
+ Logo();
+ const GLfloat *constData() const { return m_data.constData(); }
+ int count() const { return m_count; }
+ int vertexCount() const { return m_count / 6; }
+
+private:
+ void quad(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat x4, GLfloat y4);
+ void extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
+ void add(const QVector3D &v, const QVector3D &n);
+
+ QVector<GLfloat> m_data;
+ int m_count;
+};
+
+#endif // LOGO_H
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/main.cpp b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp
new file mode 100644
index 0000000000..5f006c3fb6
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/main.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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 <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char **argv)
+{
+ qputenv("QML_BAD_GUI_RENDER_LOOP", "1"); // QTBUG-39507
+
+ QApplication app(argc, argv);
+
+ MainWindow widgetWindow;
+ widgetWindow.resize(1024, 768);
+ widgetWindow.show();
+
+ return app.exec();
+}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
new file mode 100644
index 0000000000..dbf4121518
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
@@ -0,0 +1,216 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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 "mainwindow.h"
+#include "fbitem.h"
+#include <QVBoxLayout>
+#include <QGroupBox>
+#include <QRadioButton>
+#include <QCheckBox>
+#include <QLabel>
+#include <QQuickItem>
+
+MainWindow::MainWindow()
+ : m_currentView(0),
+ m_currentRootObject(0)
+{
+ QVBoxLayout *layout = new QVBoxLayout;
+
+ QGroupBox *groupBox = new QGroupBox(tr("Type"));
+ QVBoxLayout *vbox = new QVBoxLayout;
+ m_radioView = new QRadioButton(tr("QQuickView in a window container (direct)"));
+ m_radioWidget = new QRadioButton(tr("QQuickWidget (indirect through framebuffer objects)"));
+ vbox->addWidget(m_radioView);
+ vbox->addWidget(m_radioWidget);
+ m_radioView->setChecked(true);
+ connect(m_radioView, &QRadioButton::toggled, this, &MainWindow::updateView);
+ connect(m_radioWidget, &QRadioButton::toggled, this, &MainWindow::updateView);
+ groupBox->setLayout(vbox);
+
+ layout->addWidget(groupBox);
+
+ m_checkboxMultiSample = new QCheckBox(tr("Multisample (4x)"));
+ connect(m_checkboxMultiSample, &QCheckBox::toggled, this, &MainWindow::updateView);
+ layout->addWidget(m_checkboxMultiSample);
+
+ m_labelStatus = new QLabel;
+ layout->addWidget(m_labelStatus);
+
+ qmlRegisterType<FbItem>("fbitem", 1, 0, "FbItem");
+
+ QWidget *quickContainer = new QWidget;
+ layout->addWidget(quickContainer);
+ layout->setStretchFactor(quickContainer, 8);
+ m_containerLayout = new QVBoxLayout;
+ quickContainer->setLayout(m_containerLayout);
+
+ // Add an overlay widget to demonstrate that it will _not_ work with
+ // QQuickView, whereas it is perfectly fine with QQuickWidget.
+ QPalette semiTransparent(QColor(255,0,0,128));
+ semiTransparent.setBrush(QPalette::Text, Qt::white);
+ semiTransparent.setBrush(QPalette::WindowText, Qt::white);
+
+ m_overlayLabel = new QLabel("This is a\nsemi-transparent\n overlay widget\nwhich is placed\non top\n of the Quick\ncontent.", this);
+ m_overlayLabel->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
+ m_overlayLabel->setAutoFillBackground(true);
+ m_overlayLabel->setPalette(semiTransparent);
+ QFont f = font();
+ f.setPixelSize(QFontInfo(f).pixelSize()*2);
+ f.setWeight(QFont::Bold);
+ m_overlayLabel->setFont(f);
+ m_overlayLabel->hide();
+
+ m_checkboxOverlayVisible = new QCheckBox(tr("Show widget overlay"));
+ connect(m_checkboxOverlayVisible, &QCheckBox::toggled, m_overlayLabel, &QWidget::setVisible);
+ layout->addWidget(m_checkboxOverlayVisible);
+
+ setLayout(layout);
+
+ updateView();
+}
+
+void MainWindow::resizeEvent(QResizeEvent*)
+{
+ int margin = width() / 10;
+ int top = m_checkboxMultiSample->y();
+ int bottom = m_checkboxOverlayVisible->geometry().bottom();
+ m_overlayLabel->setGeometry(margin, top, width() - 2 * margin, bottom - top);
+}
+
+void MainWindow::switchTo(QWidget *view)
+{
+ if (m_containerLayout->count())
+ m_containerLayout->takeAt(0);
+
+ delete m_currentView;
+ m_currentView = view;
+ m_containerLayout->addWidget(m_currentView);
+ m_currentView->setFocus();
+}
+
+void MainWindow::updateView()
+{
+ QString text = m_currentRootObject
+ ? m_currentRootObject->property("currentText").toString()
+ : QStringLiteral("Hello Qt");
+
+ QUrl source("qrc:qquickviewcomparison/test.qml");
+ QSurfaceFormat format;
+ format.setDepthBufferSize(16);
+ format.setStencilBufferSize(8);
+ if (m_checkboxMultiSample->isChecked())
+ format.setSamples(4);
+
+ if (m_radioView->isChecked()) {
+ QQuickView *quickView = new QQuickView;
+ quickView->setFormat(format);
+ quickView->setResizeMode(QQuickView::SizeRootObjectToView);
+ connect(quickView, &QQuickView::statusChanged, this, &MainWindow::onStatusChangedView);
+ connect(quickView, &QQuickView::sceneGraphError, this, &MainWindow::onSceneGraphError);
+ quickView->setSource(source);
+ m_currentRootObject = quickView->rootObject();
+ switchTo(QWidget::createWindowContainer(quickView));
+ } else {
+ QQuickWidget *quickWidget = new QQuickWidget;
+ quickWidget->setFormat(format);
+ quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
+ connect(quickWidget, &QQuickWidget::statusChanged, this, &MainWindow::onStatusChangedWidget);
+ connect(quickWidget, &QQuickWidget::sceneGraphError, this, &MainWindow::onSceneGraphError);
+ quickWidget->setSource(source);
+ m_currentRootObject = quickWidget->rootObject();
+ switchTo(quickWidget);
+ }
+
+ m_currentRootObject->setProperty("currentText", text);
+ m_currentRootObject->setProperty("multisample", m_checkboxMultiSample->isChecked());
+
+ m_overlayLabel->raise();
+}
+
+void MainWindow::onStatusChangedView(QQuickView::Status status)
+{
+ QString s;
+ switch (status) {
+ case QQuickView::Null:
+ s = tr("Null");
+ break;
+ case QQuickView::Ready:
+ s = tr("Ready");
+ break;
+ case QQuickView::Loading:
+ s = tr("Loading");
+ break;
+ case QQuickView::Error:
+ s = tr("Error");
+ break;
+ default:
+ s = tr("Unknown");
+ break;
+ }
+ m_labelStatus->setText(tr("QQuickView status: %1").arg(s));
+}
+
+void MainWindow::onStatusChangedWidget(QQuickWidget::Status status)
+{
+ QString s;
+ switch (status) {
+ case QQuickWidget::Null:
+ s = tr("Null");
+ break;
+ case QQuickWidget::Ready:
+ s = tr("Ready");
+ break;
+ case QQuickWidget::Loading:
+ s = tr("Loading");
+ break;
+ case QQuickWidget::Error:
+ s = tr("Error");
+ break;
+ default:
+ s = tr("Unknown");
+ break;
+ }
+ m_labelStatus->setText(tr("QQuickWidget status: %1").arg(s));
+}
+
+void MainWindow::onSceneGraphError(QQuickWindow::SceneGraphError error, const QString &message)
+{
+ m_labelStatus->setText(tr("Scenegraph error %1: %2").arg(error).arg(message));
+}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h
new file mode 100644
index 0000000000..c7bd514d81
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QWidget>
+#include <QQuickWidget>
+#include <QQuickView>
+
+QT_FORWARD_DECLARE_CLASS(QRadioButton)
+QT_FORWARD_DECLARE_CLASS(QCheckBox)
+QT_FORWARD_DECLARE_CLASS(QLabel)
+QT_FORWARD_DECLARE_CLASS(QLayout)
+
+class MainWindow : public QWidget
+{
+public:
+ MainWindow();
+
+protected:
+ void resizeEvent(QResizeEvent*);
+private slots:
+ void updateView();
+ void onStatusChangedView(QQuickView::Status status);
+ void onStatusChangedWidget(QQuickWidget::Status status);
+ void onSceneGraphError(QQuickWindow::SceneGraphError error, const QString &message);
+
+private:
+ void switchTo(QWidget *view);
+
+ QRadioButton *m_radioView;
+ QRadioButton *m_radioWidget;
+ QCheckBox *m_checkboxMultiSample;
+ QLabel *m_labelStatus;
+ QLayout *m_containerLayout;
+ QWidget *m_currentView;
+ QObject *m_currentRootObject;
+ QLabel *m_overlayLabel;
+ QCheckBox *m_checkboxOverlayVisible;
+};
+
+#endif
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro
new file mode 100644
index 0000000000..9d70f7aa5a
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro
@@ -0,0 +1,17 @@
+TEMPLATE = app
+TARGET = qquickviewcomparison
+
+QT += quick widgets quickwidgets
+
+SOURCES += main.cpp \
+ mainwindow.cpp \
+ logo.cpp \
+ fbitem.cpp
+
+HEADERS += mainwindow.h \
+ logo.h \
+ fbitem.h
+
+RESOURCES += qquickviewcomparison.qrc
+
+OTHER_FILES += test.qml
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.qrc b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.qrc
new file mode 100644
index 0000000000..2b259fdeec
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/qquickviewcomparison">
+ <file>test.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/test.qml b/examples/quick/quickwidgets/qquickviewcomparison/test.qml
new file mode 100644
index 0000000000..2e8c83024a
--- /dev/null
+++ b/examples/quick/quickwidgets/qquickviewcomparison/test.qml
@@ -0,0 +1,210 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia Plc 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.2
+import QtQuick.Particles 2.0
+import fbitem 1.0
+
+Rectangle {
+ id: root
+ color: "lightBlue"
+ property alias currentText: edit.text
+ property alias multisample: fbitem.multisample
+
+ ParticleSystem {
+ anchors.fill: parent
+ running: true
+
+ ImageParticle {
+ source: "qrc:///particleresources/glowdot.png"
+ alpha: 0
+ colorVariation: 1
+ }
+
+ Emitter {
+ anchors.fill: parent
+ lifeSpan: 3000
+ emitRate: 30
+ size: 50
+ sizeVariation: 10
+ velocity: PointDirection { xVariation: 10; yVariation: 10; }
+ acceleration: PointDirection {
+ y: -10
+ xVariation: 5
+ yVariation: 5
+ }
+ }
+ }
+
+ Rectangle {
+ y: 10
+ width: parent.width / 2
+ height: edit.contentHeight + 4
+ anchors.horizontalCenter: parent.horizontalCenter
+ border.color: "gray"
+ border.width: 2
+ radius: 8
+ color: "lightGray"
+ clip: true
+ TextInput {
+ id: edit
+ anchors.horizontalCenter: parent.horizontalCenter
+ maximumLength: 30
+ focus: true
+ font.pointSize: 20
+ }
+ }
+
+ Rectangle {
+ width: 300
+ height: 300
+ anchors.centerIn: parent
+ color: "red"
+ NumberAnimation on rotation { from: 0; to: 360; duration: 20000; loops: Animation.Infinite; }
+ }
+
+ FbItem {
+ id: fbitem
+ anchors.fill: parent
+ SequentialAnimation on eye.y {
+ loops: Animation.Infinite
+ NumberAnimation {
+ from: 0
+ to: 0.15
+ duration: 1000
+ }
+ NumberAnimation {
+ from: 0.15
+ to: 0
+ duration: 2000
+ }
+ }
+ SequentialAnimation on eye.x {
+ loops: Animation.Infinite
+ NumberAnimation {
+ from: 0
+ to: -0.5
+ duration: 3000
+ }
+ NumberAnimation {
+ from: -0.5
+ to: 0.5
+ duration: 3000
+ easing.type: Easing.OutQuad
+ }
+ NumberAnimation {
+ from: 0.5
+ to: 0
+ duration: 1000
+ }
+ }
+ SequentialAnimation on rotation.y {
+ loops: Animation.Infinite
+ NumberAnimation {
+ from: 0
+ to: 360
+ duration: 5000
+ }
+ NumberAnimation {
+ from: 360
+ to: 0
+ duration: 2500
+ }
+ }
+ SequentialAnimation on rotation.x {
+ loops: Animation.Infinite
+ NumberAnimation {
+ from: 0
+ to: 360
+ duration: 6000
+ }
+ NumberAnimation {
+ from: 360
+ to: 0
+ duration: 3000
+ }
+ }
+ }
+
+ Text {
+ id: effText
+ text: edit.text
+ anchors.centerIn: parent
+ font.pointSize: 60
+ style: Text.Outline
+ styleColor: "green"
+ }
+
+ ShaderEffectSource {
+ id: effSource
+ sourceItem: effText
+ hideSource: true
+ }
+
+ ShaderEffect {
+ SequentialAnimation on scale {
+ loops: Animation.Infinite
+ NumberAnimation { from: 1.0; to: 2.0; duration: 1000; easing.type: Easing.InCirc }
+ PauseAnimation { duration: 1000 }
+ NumberAnimation { from: 2.0; to: 0.5; duration: 1000; easing.type: Easing.OutExpo }
+ NumberAnimation { from: 0.5; to: 1.0; duration: 500 }
+ PauseAnimation { duration: 1000 }
+ }
+ width: effText.width
+ height: effText.height
+ anchors.centerIn: parent
+ property variant source: effSource
+ property real amplitude: 0.002
+ property real frequency: 10
+ property real time: 0
+ NumberAnimation on time { loops: Animation.Infinite; from: 0; to: Math.PI * 2; duration: 1000 }
+ fragmentShader:
+ "uniform lowp float qt_Opacity;" +
+ "uniform highp float amplitude;" +
+ "uniform highp float frequency;" +
+ "uniform highp float time;" +
+ "uniform sampler2D source;" +
+ "varying highp vec2 qt_TexCoord0;" +
+ "void main() {" +
+ " highp vec2 p = sin(time + frequency * qt_TexCoord0);" +
+ " gl_FragColor = texture2D(source, qt_TexCoord0 + amplitude * vec2(p.y, -p.x)) * qt_Opacity;" +
+ "}"
+ }
+}
diff --git a/examples/quick/quickwidgets/quickwidgets.pro b/examples/quick/quickwidgets/quickwidgets.pro
index 07192b6696..be932f33d0 100644
--- a/examples/quick/quickwidgets/quickwidgets.pro
+++ b/examples/quick/quickwidgets/quickwidgets.pro
@@ -1,2 +1,3 @@
TEMPLATE = subdirs
-SUBDIRS = quickwidget
+SUBDIRS = quickwidget \
+ qquickviewcomparison
diff --git a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
index 1f87412aa4..de023ff95c 100644
--- a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
+++ b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
@@ -50,54 +50,40 @@
in the QML file and this value is used by the OpenGL shader
program that draws the squircles.
+ \snippet scenegraph/openglunderqml/squircle.h 2
+
+ First of all, we need an object we can expose to QML. This is a
+ subclass of QQuickItem so we can easily access \l QQuickItem::window().
+
\snippet scenegraph/openglunderqml/squircle.h 1
- First of all, we need a QObject with a slot to connect the signals
- to. We subclass QQuickItem in order to use the \l
- QQuickItem::window() which holds the window instance we want to
- connect to.
-
- We use two values of \c t. The variable \c m_t is the property
- value as it exists in the GUI thread. The \c m_thread_t value is a
- copy of \c m_t for use in the rendering thread. We need an
- explicit copy because the scene graph can render in one thread
- while updating properties on the GUI thread in preparation for the
- next frame. If we had used only one value, the animation could
- have updated the value to that of the next frame before we got a
- chance to render it.
-
- \note In this example, a wrong value for \c t will have minimal
- consequences, but we emphasize that rendering and GUI thread
- objects and values must stay separate to avoid race conditions,
- undesired behavior and in the worst case, crashes.
+ Then we need an object to take care of the rendering. This
+ instance needs to be separated from the QQuickItem because the
+ item lives in the GUI thread and the rendering potentially happens
+ on the render thread. Since we want to connect to \l
+ QQuickWindow::beforeRendering(), we make the renderer a QObject.
+ The renderer contains a copy of all the state it needs,
+ independent of the GUI thread.
+
+ \note Don't be tempted to merge the two objects into
+ one. QQuickItems may be deleted on the GUI thread while the render
+ thread is rendering.
Lets move on to the implementation.
\snippet scenegraph/openglunderqml/squircle.cpp 7
The constructor of the \c Squircle class simply initializes the
- values. The shader program will be initialized during rendering
- later.
-
- \snippet scenegraph/openglunderqml/squircle.cpp 8
-
- The property setter checks that the value has indeed changed
- before updating its internal variable. It then calls \l
- QQuickWindow::update() which will trigger another frame to be
- rendered. Note that the setter might be called during
- initialization, before the object has been entered into the scene
- and before it has a window.
+ values and connects to the window changed signal which we will use
+ to prepare our renderer.
\snippet scenegraph/openglunderqml/squircle.cpp 1
- \snippet scenegraph/openglunderqml/squircle.cpp 2
- For our paint function to be called, we need to connect to the
- window's signals. When Squircle object is populated into the
- scene, the windowChanged signal is emitted. In our handler,
- we connect \l QQuickWindow::beforeRendering() to
- \c paint() to do the rendering, and \l
- QQuickWindow::beforeSynchronizing() to \c sync() to copy the state
- of the \c t property for the upcoming frame.
+ Once we have a window, we attach to the \l
+ QQuickWindow::beforeSynchronizing() signal which we will use to
+ create the renderer and to copy state into it safely. We also
+ connect to the \l QQuickWindow::sceneGraphInvalidated() signal to
+ handle the cleanup of the renderer.
\note Since the Squircle object has affinity to the GUI thread and
the signals are emitted from the rendering thread, it is crucial
@@ -113,18 +99,35 @@
graph, we need to turn this clearing off. This means that we need
to clear ourselves in the \c paint() function.
- \snippet scenegraph/openglunderqml/squircle.cpp 4
+ \snippet scenegraph/openglunderqml/squircle.cpp 9
+
+ We use the \c sync() function to initialize the renderer and to
+ copy the state in our item into the renderer. When the renderer is
+ created, we also connect the \l QQuickWindow::beforeRendering() to
+ the renderer's \c paint() slot.
- The first thing we do in the \c paint() function is to
- initialize the shader program. By initializing the shader program
- here, we make sure that the OpenGL context is bound and that we
- are on the correct thread.
+ \note The \l QQuickWindow::beforeSynchronizing() signal is emitted
+ on the rendering thread while the GUI thread is blocked, so it is
+ safe to simply copy the value without any additional protection.
- We also connect to the QOpenGLContext::aboutToBeDestroyed()
- signal, so that we can clean up the shader program when the
- context is destroyed. Again, this is a \l Qt::DirectConnection as
- all rendering related operations must happen on the rendering
- thread.
+ \snippet scenegraph/openglunderqml/squircle.cpp 6
+
+ In the \c cleanup() function we delete the renderer which in turn
+ cleans up its own resources.
+
+ \snippet scenegraph/openglunderqml/squircle.cpp 8
+
+ When the value of \c t changes, we call \l QQuickWindow::update()
+ rather than \l QQuickItem::update() because the former will force
+ the entire window to be redrawn, even when the scene graph has not
+ changed since the last frame.
+
+ \snippet scenegraph/openglunderqml/squircle.cpp 4
+
+ In the SquircleRenderer's \c paint() function we start by
+ initializing the shader program. By initializing the shader
+ program here, we make sure that the OpenGL context is bound and
+ that we are on the correct thread.
\snippet scenegraph/openglunderqml/squircle.cpp 5
@@ -133,18 +136,10 @@
attributes we used so that the OpenGL context is in a "clean"
state for the scene graph to pick it up.
- \snippet scenegraph/openglunderqml/squircle.cpp 6
-
- In the \c cleanup() function we delete the program.
-
- \snippet scenegraph/openglunderqml/squircle.cpp 9
-
- We use the \c sync() function to copy the state of the
- object in the GUI thread into the rendering thread.
-
- The signal is emitted on the rendering thread while the GUI
- thread is blocked, so it is safe to simply copy the value without
- any additional protection.
+ \note If tracking the changes in the OpenGL context's state is not
+ feasible, one can use the function \l
+ QQuickWindow::resetOpenGLState() which will reset all state that
+ the scene graph relies on.
\snippet scenegraph/openglunderqml/main.cpp 1
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.cpp b/examples/quick/scenegraph/openglunderqml/squircle.cpp
index 91d69c90a4..4b892e3761 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.cpp
+++ b/examples/quick/scenegraph/openglunderqml/squircle.cpp
@@ -47,9 +47,8 @@
//! [7]
Squircle::Squircle()
- : m_program(0)
- , m_t(0)
- , m_thread_t(0)
+ : m_t(0)
+ , m_renderer(0)
{
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
}
@@ -71,24 +70,46 @@ void Squircle::setT(qreal t)
void Squircle::handleWindowChanged(QQuickWindow *win)
{
if (win) {
-//! [1]
- // Connect the beforeRendering signal to our paint function.
- // Since this call is executed on the rendering thread it must be
- // a Qt::DirectConnection
-//! [2]
- connect(win, SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
connect(win, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection);
-//! [2]
-
+ connect(win, SIGNAL(sceneGraphInvalidated()), this, SLOT(cleanup()), Qt::DirectConnection);
+//! [1]
// If we allow QML to do the clearing, they would clear what we paint
// and nothing would show.
//! [3]
win->setClearBeforeRendering(false);
}
}
+//! [3]
+
+//! [6]
+void Squircle::cleanup()
+{
+ if (m_renderer) {
+ delete m_renderer;
+ m_renderer = 0;
+ }
+}
-//! [3] //! [4]
-void Squircle::paint()
+SquircleRenderer::~SquircleRenderer()
+{
+ delete m_program;
+}
+//! [6]
+
+//! [9]
+void Squircle::sync()
+{
+ if (!m_renderer) {
+ m_renderer = new SquircleRenderer();
+ connect(window(), SIGNAL(beforeRendering()), m_renderer, SLOT(paint()), Qt::DirectConnection);
+ }
+ m_renderer->setViewportSize(window()->size() * window()->devicePixelRatio());
+ m_renderer->setT(m_t);
+}
+//! [9]
+
+//! [4]
+void SquircleRenderer::paint()
{
if (!m_program) {
m_program = new QOpenGLShaderProgram();
@@ -112,8 +133,6 @@ void Squircle::paint()
m_program->bindAttributeLocation("vertices", 0);
m_program->link();
- connect(window()->openglContext(), SIGNAL(aboutToBeDestroyed()),
- this, SLOT(cleanup()), Qt::DirectConnection);
}
//! [4] //! [5]
m_program->bind();
@@ -127,12 +146,9 @@ void Squircle::paint()
1, 1
};
m_program->setAttributeArray(0, GL_FLOAT, values, 2);
- m_program->setUniformValue("t", (float) m_thread_t);
+ m_program->setUniformValue("t", (float) m_t);
- qreal ratio = window()->devicePixelRatio();
- int w = int(ratio * window()->width());
- int h = int(ratio * window()->height());
- glViewport(0, 0, w, h);
+ glViewport(0, 0, m_viewportSize.width(), m_viewportSize.height());
glDisable(GL_DEPTH_TEST);
@@ -148,21 +164,3 @@ void Squircle::paint()
m_program->release();
}
//! [5]
-
-//! [6]
-void Squircle::cleanup()
-{
- if (m_program) {
- delete m_program;
- m_program = 0;
- }
-}
-//! [6]
-
-//! [9]
-void Squircle::sync()
-{
- m_thread_t = m_t;
-}
-//! [9]
-
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.h b/examples/quick/scenegraph/openglunderqml/squircle.h
index 449e02bbf1..aa50908242 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.h
+++ b/examples/quick/scenegraph/openglunderqml/squircle.h
@@ -45,11 +45,32 @@
#include <QtQuick/QQuickItem>
#include <QtGui/QOpenGLShaderProgram>
+
+
+//! [1]
+class SquircleRenderer : public QObject {
+ Q_OBJECT
+public:
+ SquircleRenderer() : m_t(0), m_program(0) { }
+ ~SquircleRenderer();
+
+ void setT(qreal t) { m_t = t; }
+ void setViewportSize(const QSize &size) { m_viewportSize = size; }
+
+public slots:
+ void paint();
+
+private:
+ QSize m_viewportSize;
+ qreal m_t;
+ QOpenGLShaderProgram *m_program;
+};
//! [1]
+
+//! [2]
class Squircle : public QQuickItem
{
Q_OBJECT
-
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
public:
@@ -62,19 +83,16 @@ signals:
void tChanged();
public slots:
- void paint();
- void cleanup();
void sync();
+ void cleanup();
private slots:
void handleWindowChanged(QQuickWindow *win);
private:
- QOpenGLShaderProgram *m_program;
-
qreal m_t;
- qreal m_thread_t;
+ SquircleRenderer *m_renderer;
};
-//! [1]
+//! [2]
#endif // SQUIRCLE_H
diff --git a/src/qml/doc/src/javascript/expressions.qdoc b/src/qml/doc/src/javascript/expressions.qdoc
index 79c11b3ac5..37baa49c52 100644
--- a/src/qml/doc/src/javascript/expressions.qdoc
+++ b/src/qml/doc/src/javascript/expressions.qdoc
@@ -37,44 +37,36 @@ Object} includes a number of helper methods that simplify building UIs and
interacting with the QML environment.
The JavaScript environment provided by QML is stricter than that in a web
-browser. For example, in QML you cannot add, or modify, members of the
+browser. For example, in QML you cannot add to, or modify, members of the
JavaScript global object. In regular JavaScript, it is possible to do this
accidentally by using a variable without declaring it. In QML this will throw
-an exception, so all local variables should be explicitly declared. See
+an exception, so all local variables must be explicitly declared. See
\l{JavaScript Environment Restrictions} for a complete description of the
restrictions on JavaScript code executed from QML.
-There are various ways in which JavaScript expressions may be defined and used
-in QML, including property bindings, signal handlers, custom methods and
-JavaScript imports.
-
-
-
-
-\section1 JavaScript Expressions in QML Objects
-
-QML \l{QML Object Types}{object types} defined in \l{QML Documents}
-{QML documents} can make use of JavaScript expressions which implement program
-logic. There are four ways that JavaScript can be used in a QML document:
+Various parts of \l{QML Documents}{QML documents} can contain JavaScript code:
\list 1
- \li Relationships between \l{Property Attributes}{properties} are described
- using JavaScript expressions in \l{Property Binding}{property bindings}.
- When any of a property's \e dependencies change, the property is
- automatically updated too, according to the specified relationship.
- \li \l{Signal Attributes}{Signal handlers} can be defined
- which are automatically evaluated when the object emits the associated
- signal.
- \li \l{Method Attributes}{Custom methods} can be defined
- in QML files as JavaScript functions.
- \li JavaScript files providing functions and variables can be
- \l{Importing JavaScript Resources in QML}{imported} in a QML
- document.
+ \li The body of \l{Property Binding}{property bindings}. These JavaScript
+ expressions describe relationships between QML object \l{Property Attributes}
+ {properties}. When any of a property's \e dependencies change, the property
+ is automatically updated too, according to the specified relationship.
+ \li The body of \l{Signal Attributes}{Signal handlers}. These JavaScript
+ statements are automatically evaluated whenever a QML object emits the
+ associated signal.
+ \li The definition of \l{Method Attributes}{custom methods}. JavaScript functions
+ that are defined within the body of a QML object become methods of that
+ object.
+ \li Standalone \l{Importing JavaScript Resources in QML}{JavaScript resource
+ (.js) files}. These files are actually separate from QML documents, but
+ they can be imported into QML documents. Functions and variables that are
+ defined within the imported files can be used in property bindings, signal
+ handlers, and custom methods.
\endlist
-\section2 Property Bindings
+\section1 JavaScript in Property Bindings
In the following example, the \l Rectangle's \c color depends on the
\l MouseArea's \c pressed property. This relationship is described using a
@@ -136,7 +128,7 @@ bindings differ from value assignments.
-\section2 Signal Handlers
+\section1 JavaScript in Signal Handlers
QML object types can emit signals in reaction to certain events occurring.
Those signals can be handled by signal handler functions, which can be defined
@@ -188,7 +180,7 @@ to define the implementation of signal handlers in QML with JavaScript.
-\section2 JavaScript Expressions in Functions
+\section1 JavaScript in Standalone Functions
Program logic can also be defined in JavaScript functions. These functions can
be defined inline in QML documents (as custom methods) or externally in
@@ -196,12 +188,12 @@ imported JavaScript files.
-\section3 Custom Methods
+\section2 JavaScript in Custom Object Methods
Custom methods can be defined in QML documents and may be called from signal
handlers, property bindings, or functions in other QML objects. Methods
-defined in this way are often referred to as "inline JavaScript functions" as
-their implementation is included in the QML object type definition
+defined in this way are often referred to as \e{inline JavaScript functions}
+because their implementation is included in the QML object type definition
(QML document), as opposed to an external JavaScript file.
An example of an inline custom method is as follows:
@@ -225,7 +217,7 @@ Item {
}
\endqml
-The factorial function will run whenever the MouseArea detects a clicked signal.
+The factorial function will run whenever the MouseArea detects a \c clicked signal.
Importantly, custom methods defined inline in a QML document are exposed to
other objects, and therefore inline functions on the root object in a QML
@@ -238,7 +230,7 @@ to define custom methods in QML with JavaScript code implementations.
-\section3 Functions in Imported JavaScript Files
+\section2 Functions in Imported JavaScript Files
Non-trivial program logic is best separated into external JavaScript files.
These files can be imported into QML files using an \c import statement, in
@@ -263,7 +255,7 @@ the section about \l{Importing JavaScript Resources in QML}.
-\section3 Connecting Signals to JavaScript Functions
+\section2 Connecting Signals to JavaScript Functions
QML object types which emit signals also provide default signal handlers for
their signals, as described in a previous section. Sometimes, however, a
@@ -292,23 +284,26 @@ See \l{qtqml-syntax-signals.html}
-\section1 Running JavaScript at Startup
+\section1 JavaScript in Application Startup Code
It is occasionally necessary to run some imperative code at application (or
component instance) startup. While it is tempting to just include the startup
script as \e {global code} in an external script file, this can have severe
limitations as the QML environment may not have been fully established. For
example, some objects might not have been created or some
-\l {Property Binding}{property bindings} may not have been run.
-\l {JavaScript Environment Restrictions} covers the exact limitations of global
+\l {Property Binding}{property bindings} may not have been established. See
+\l {JavaScript Environment Restrictions} for the exact limitations of global
script code.
-Every QML object has an \e attached \l Component property that references the
-component within which the object was instantiated. Every \l Component
-will emit a \c completed signal, and thus every object can define an
-implementation for the \c onCompleted() handler which can be used to trigger the
-execution of script code at startup after the QML environment has been
-completely established. For example:
+A QML object will emit the \c{Component.completed} \l{Signal and Handler Event
+System#Attached Signal Handlers}{attached signal} when its instantiation is
+complete. JavaScript code in the corresponding \c{Component.onCompleted} handler
+runs after the object is instantiated. Thus, the best place to write application
+startup code is in the \c{Component.onCompleted} handler of the top-level level
+object, because this object emits \c{Component.completed} when the QML environment
+is fully established.
+
+For example:
\qml
import QtQuick 2.0
@@ -346,7 +341,7 @@ signal just before being destroyed.
\section1 Scarce Resources in JavaScript
As described in the documentation for \l{QML Basic Types}, a \c var type
-property may hold a "scarce resource" (image or pixmap). There are several
+property may hold a \e{scarce resource} (image or pixmap). There are several
important semantics of scarce resources which should be noted:
\list
diff --git a/src/qml/doc/src/javascript/hostenvironment.qdoc b/src/qml/doc/src/javascript/hostenvironment.qdoc
index a63ef617c0..bd3ff63bf8 100644
--- a/src/qml/doc/src/javascript/hostenvironment.qdoc
+++ b/src/qml/doc/src/javascript/hostenvironment.qdoc
@@ -135,8 +135,8 @@ var initialPosition = { rootObject.x, rootObject.y }
\endcode
This restriction exists as the QML environment is not yet fully established.
-To run code after the environment setup has completed, refer to
-\l {Running JavaScript at Startup}.
+To run code after the environment setup has completed, see
+\l {JavaScript in Application Startup Code}.
\li The value of \c this is currently undefined in QML in the majority of contexts.
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index a02424a3dc..d64f821a38 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -962,6 +962,8 @@ static void markChildQObjectsRecursively(QObject *parent, QV4::ExecutionEngine *
const QObjectList &children = parent->children();
for (int i = 0; i < children.count(); ++i) {
QObject *child = children.at(i);
+ if (!child)
+ continue;
QQmlData *ddata = QQmlData::get(child, /*create*/false);
if (ddata)
ddata->jsWrapper.markOnce(e);
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index 39a7d8905d..1da2f1c109 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -150,7 +150,7 @@ V8_DEFINE_EXTENSION(QQmlComponentExtension, componentExtension);
// QQmlEngine *engine = qmlContext(this)->engine();
QQmlComponent component(engine, QUrl::fromLocalFile("MyItem.qml"));
QQuickItem *childItem = qobject_cast<QQuickItem*>(component.create());
- childItem->setParent(this);
+ childItem->setParentItem(this);
}
\endcode
@@ -880,7 +880,7 @@ QQmlComponentPrivate::beginCreate(QQmlContextData *context)
enginePriv->referenceScarceResources();
QObject *rv = 0;
- state.creator = new QQmlObjectCreator(context, cc, creationContext);
+ state.creator.reset(new QQmlObjectCreator(context, cc, creationContext));
rv = state.creator->create(start);
if (!rv)
state.errors = state.creator->errors;
@@ -920,7 +920,7 @@ void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
Q_ASSERT(ddata->deferredData);
QQmlData::DeferredData *deferredData = ddata->deferredData;
QQmlContextData *creationContext = 0;
- state->creator = new QQmlObjectCreator(deferredData->context->parent, deferredData->compiledData, creationContext);
+ state->creator.reset(new QQmlObjectCreator(deferredData->context->parent, deferredData->compiledData, creationContext));
if (!state->creator->populateDeferredProperties(object))
state->errors << state->creator->errors;
}
diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h
index e8ae540148..2c70d7b100 100644
--- a/src/qml/qml/qqmlcomponent_p.h
+++ b/src/qml/qml/qqmlcomponent_p.h
@@ -106,15 +106,13 @@ public:
struct ConstructionState {
ConstructionState()
- : creator(0)
- , completePending(false)
+ : completePending(false)
{}
~ConstructionState()
{
- delete creator;
}
- QQmlObjectCreator *creator;
+ QScopedPointer<QQmlObjectCreator> creator;
QList<QQmlError> errors;
bool completePending;
};
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index a8eeeeeddd..36c7dfb0e9 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -91,7 +91,7 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QQmlCompile
init(parentContext);
sharedState = new QQmlObjectCreatorSharedState;
- sharedState.setFlag(); // We own it, so we must delete it
+ topLevelCreator = true;
sharedState->componentAttached = 0;
sharedState->allCreatedBindings.allocate(compiledData->totalBindingsCount);
sharedState->allParserStatusCallbacks.allocate(compiledData->totalParserStatusCount);
@@ -115,6 +115,7 @@ QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, QQmlCompile
init(parentContext);
sharedState = inheritedSharedState;
+ topLevelCreator = false;
}
void QQmlObjectCreator::init(QQmlContextData *providedParentContext)
@@ -139,9 +140,9 @@ void QQmlObjectCreator::init(QQmlContextData *providedParentContext)
QQmlObjectCreator::~QQmlObjectCreator()
{
- if (sharedState.flag()) {
+ if (topLevelCreator) {
{
- QRecursionWatcher<QQmlObjectCreatorSharedState, &QQmlObjectCreatorSharedState::recursionNode> watcher(sharedState.data());
+ QQmlObjectCreatorRecursionWatcher watcher(this);
}
for (int i = 0; i < sharedState->allCreatedBindings.count(); ++i) {
QQmlAbstractBinding *b = sharedState->allCreatedBindings.at(i);
@@ -153,7 +154,10 @@ QQmlObjectCreator::~QQmlObjectCreator()
if (ps)
ps->d = 0;
}
- delete sharedState.data();
+ while (sharedState->componentAttached) {
+ QQmlComponentAttached *a = sharedState->componentAttached;
+ a->rem();
+ }
}
}
@@ -1168,7 +1172,7 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru
Q_ASSERT(phase == ObjectsCreated || phase == Finalizing);
phase = Finalizing;
- QRecursionWatcher<QQmlObjectCreatorSharedState, &QQmlObjectCreatorSharedState::recursionNode> watcher(sharedState.data());
+ QQmlObjectCreatorRecursionWatcher watcher(this);
ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine));
{
@@ -1253,6 +1257,11 @@ void QQmlObjectCreator::clear()
while (!sharedState->allCreatedObjects.isEmpty())
delete sharedState->allCreatedObjects.pop();
+ while (sharedState->componentAttached) {
+ QQmlComponentAttached *a = sharedState->componentAttached;
+ a->rem();
+ }
+
phase = Done;
}
@@ -1325,3 +1334,10 @@ bool QQmlObjectCreator::populateInstance(int index, QObject *instance, QObject *
}
+
+
+QQmlObjectCreatorRecursionWatcher::QQmlObjectCreatorRecursionWatcher(QQmlObjectCreator *creator)
+ : sharedState(creator->sharedState)
+ , watcher(creator->sharedState.data())
+{
+}
diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h
index 379a3b2970..ad2d67624f 100644
--- a/src/qml/qml/qqmlobjectcreator_p.h
+++ b/src/qml/qml/qqmlobjectcreator_p.h
@@ -57,7 +57,7 @@ struct QQmlTypeCompiler;
class QQmlInstantiationInterrupt;
struct QQmlVmeProfiler;
-struct QQmlObjectCreatorSharedState
+struct QQmlObjectCreatorSharedState : public QSharedData
{
QQmlContextData *rootContext;
QQmlContextData *creationContext;
@@ -128,7 +128,8 @@ private:
const QVector<QQmlPropertyCache *> &propertyCaches;
const QVector<QByteArray> &vmeMetaObjectData;
QHash<int, int> objectIndexToId;
- QFlagPointer<QQmlObjectCreatorSharedState> sharedState;
+ QExplicitlySharedDataPointer<QQmlObjectCreatorSharedState> sharedState;
+ bool topLevelCreator;
void *activeVMEDataForRootContext;
QObject *_qobject;
@@ -142,6 +143,19 @@ private:
QQmlVMEMetaObject *_vmeMetaObject;
QQmlListProperty<void> _currentList;
QV4::ExecutionContext *_qmlContext;
+
+ friend struct QQmlObjectCreatorRecursionWatcher;
+};
+
+struct QQmlObjectCreatorRecursionWatcher
+{
+ QQmlObjectCreatorRecursionWatcher(QQmlObjectCreator *creator);
+
+ bool hasRecursed() const { return watcher.hasRecursed(); }
+
+private:
+ QExplicitlySharedDataPointer<QQmlObjectCreatorSharedState> sharedState;
+ QRecursionWatcher<QQmlObjectCreatorSharedState, &QQmlObjectCreatorSharedState::recursionNode> watcher;
};
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickflickable_p_p.h b/src/quick/items/qquickflickable_p_p.h
index 07c434f452..33a642eb69 100644
--- a/src/quick/items/qquickflickable_p_p.h
+++ b/src/quick/items/qquickflickable_p_p.h
@@ -101,7 +101,7 @@ public:
AxisData(QQuickFlickablePrivate *fp, void (QQuickFlickablePrivate::*func)(qreal))
: move(fp, func)
, transitionToBounds(0)
- , viewSize(-1), lastPos(0), startMargin(0), endMargin(0)
+ , viewSize(-1), lastPos(0), velocity(0), startMargin(0), endMargin(0)
, origin(0)
, transitionTo(0)
, continuousFlickVelocity(0), velocityTime(), vTime(0)
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index ef2eac4b61..442080a335 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -1333,6 +1333,7 @@ void QQuickKeysAttached::keyPressed(QKeyEvent *event, bool post)
for (int ii = 0; ii < d->targets.count(); ++ii) {
QQuickItem *i = d->targets.at(ii);
if (i && i->isVisible()) {
+ event->accept();
QCoreApplication::sendEvent(i, event);
if (event->isAccepted()) {
d->inPress = false;
@@ -1375,6 +1376,7 @@ void QQuickKeysAttached::keyReleased(QKeyEvent *event, bool post)
for (int ii = 0; ii < d->targets.count(); ++ii) {
QQuickItem *i = d->targets.at(ii);
if (i && i->isVisible()) {
+ event->accept();
QCoreApplication::sendEvent(i, event);
if (event->isAccepted()) {
d->inRelease = false;
diff --git a/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp b/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp
index 9ff0971774..bffdf40bc1 100644
--- a/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp
+++ b/src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp
@@ -52,7 +52,6 @@ namespace QSGShaderRewriter {
struct Tokenizer {
enum Token {
- Token_Invalid,
Token_Void,
Token_OpenBrace,
Token_CloseBrace,
@@ -75,7 +74,6 @@ struct Tokenizer {
};
const char *Tokenizer::NAMES[] = {
- "Invalid",
"Void",
"OpenBrace",
"CloseBrace",
@@ -167,7 +165,7 @@ Tokenizer::Token Tokenizer::next()
}
}
- return Token_Invalid;
+ return Token_EOF;
}
}
diff --git a/src/quick/scenegraph/util/qsgpainternode.cpp b/src/quick/scenegraph/util/qsgpainternode.cpp
index b454f666ac..8ccb9d2ffb 100644
--- a/src/quick/scenegraph/util/qsgpainternode.cpp
+++ b/src/quick/scenegraph/util/qsgpainternode.cpp
@@ -96,7 +96,6 @@ QSGPainterNode::QSGPainterNode(QQuickPaintedItem *item)
, m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
, m_texture(0)
, m_gl_device(0)
- , m_size(1, 1)
, m_dirtyContents(false)
, m_opaquePainting(false)
, m_linear_filtering(false)
@@ -116,6 +115,10 @@ QSGPainterNode::QSGPainterNode(QQuickPaintedItem *item)
setMaterial(&m_materialO);
setOpaqueMaterial(&m_material);
setGeometry(&m_geometry);
+
+#ifdef QSG_RUNTIME_DESCRIPTION
+ qsgnode_set_description(this, QString::fromLatin1("QQuickPaintedItem(%1):%2").arg(QString::fromLatin1(item->metaObject()->className())).arg(item->objectName()));
+#endif
}
QSGPainterNode::~QSGPainterNode()
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index 3743a8cf1e..5e1502b633 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -310,6 +310,7 @@ QQuickWidget::QQuickWidget(QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, 0)
{
setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
d_func()->init();
}
@@ -322,6 +323,7 @@ QQuickWidget::QQuickWidget(const QUrl &source, QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, 0)
{
setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
d_func()->init();
setSource(source);
}
@@ -339,6 +341,7 @@ QQuickWidget::QQuickWidget(QQmlEngine* engine, QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, 0)
{
setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
Q_ASSERT(engine);
d_func()->init(engine);
}
diff --git a/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp
index 26919af1b6..f91d0135a9 100644
--- a/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp
+++ b/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp
@@ -84,10 +84,15 @@ void tst_QPacketProtocol::init()
QVERIFY(m_server->listen(QHostAddress("127.0.0.1")));
m_client = new QTcpSocket(this);
+
+ QSignalSpy serverSpy(m_server, SIGNAL(newConnection()));
+ QSignalSpy clientSpy(m_client, SIGNAL(connected()));
+
m_client->connectToHost(m_server->serverAddress(), m_server->serverPort());
- QVERIFY(m_client->waitForConnected());
- QVERIFY(m_server->waitForNewConnection(10000));
+ QVERIFY(clientSpy.count() > 0 || clientSpy.wait());
+ QVERIFY(serverSpy.count() > 0 || serverSpy.wait());
+
m_serverConn = m_server->nextPendingConnection();
}
diff --git a/tests/auto/quick/qquickitem2/data/keysforward.qml b/tests/auto/quick/qquickitem2/data/keysforward.qml
index f0cb4d9508..5677aa62f1 100644
--- a/tests/auto/quick/qquickitem2/data/keysforward.qml
+++ b/tests/auto/quick/qquickitem2/data/keysforward.qml
@@ -58,7 +58,7 @@ Item {
objectName: "primary"
property var pressedKeys: []
property var releasedKeys: []
- Keys.forwardTo: secondaryTarget
+ Keys.forwardTo: [ secondaryTarget, extraTarget ]
Keys.onPressed: { event.accepted = event.key === Qt.Key_P; var keys = pressedKeys; keys.push(event.key); pressedKeys = keys }
Keys.onReleased: { event.accepted = event.key === Qt.Key_P; var keys = releasedKeys; keys.push(event.key); releasedKeys = keys }
@@ -81,4 +81,8 @@ Item {
Keys.onPressed: { event.accepted = event.key === Qt.Key_S; var keys = pressedKeys; keys.push(event.key); pressedKeys = keys }
Keys.onReleased: { event.accepted = event.key === Qt.Key_S; var keys = releasedKeys; keys.push(event.key); releasedKeys = keys }
}
+
+ Item {
+ id: extraTarget
+ }
}