aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/animation/animation.qrc1
-rw-r--r--examples/quick/animation/basics/property-animation.qml1
-rw-r--r--examples/quick/animation/behaviors/FocusRect.qml115
-rw-r--r--examples/quick/animation/behaviors/SideRect.qml7
-rw-r--r--examples/quick/animation/behaviors/behavior-example.qml43
-rw-r--r--examples/quick/animation/behaviors/tvtennis.qml9
-rw-r--r--examples/quick/animation/behaviors/wigglytext.qml3
-rw-r--r--examples/quick/animation/doc/src/animation.qdoc2
-rw-r--r--examples/quick/animation/easing/easing.qml29
-rw-r--r--examples/quick/animation/pathanimation/pathanimation.qml1
-rw-r--r--examples/quick/animation/pathinterpolator/pathinterpolator.qml1
-rw-r--r--examples/quick/animation/states/states.qml1
-rw-r--r--examples/quick/canvas/smile/smile.qml1
-rw-r--r--examples/quick/customitems/flipable/flipable.pro9
-rw-r--r--examples/quick/customitems/flipable/flipable.qrc9
-rw-r--r--examples/quick/customitems/flipable/main.cpp51
-rw-r--r--examples/quick/customitems/maskedmousearea/main.cpp3
-rw-r--r--examples/quick/customitems/maskedmousearea/maskedmousearea.h1
-rw-r--r--examples/quick/customitems/maskedmousearea/maskedmousearea.pro4
-rw-r--r--examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h11
-rw-r--r--examples/quick/customitems/painteditem/painteditem.pro16
-rw-r--r--examples/quick/customitems/painteditem/textballoon.h1
-rw-r--r--examples/quick/customitems/scrollbar/main.cpp51
-rw-r--r--examples/quick/customitems/scrollbar/scrollbar.pro9
-rw-r--r--examples/quick/customitems/scrollbar/scrollbar.qrc7
-rw-r--r--examples/quick/customitems/searchbox/main.cpp51
-rw-r--r--examples/quick/customitems/searchbox/searchbox.pro9
-rw-r--r--examples/quick/customitems/searchbox/searchbox.qrc9
-rw-r--r--examples/quick/customitems/spinner/main.cpp51
-rw-r--r--examples/quick/customitems/spinner/spinner.pro9
-rw-r--r--examples/quick/customitems/spinner/spinner.qrc8
-rw-r--r--examples/quick/customitems/tabwidget/main.cpp51
-rw-r--r--examples/quick/customitems/tabwidget/tabwidget.pro9
-rw-r--r--examples/quick/customitems/tabwidget/tabwidget.qrc8
-rw-r--r--examples/quick/draganddrop/draganddrop.qrc1
-rw-r--r--examples/quick/draganddrop/tiles/DragTile.qml10
-rw-r--r--examples/quick/draganddrop/tiles/DropTile.qml2
-rw-r--r--examples/quick/draganddrop/views/Icon.qml96
-rw-r--r--examples/quick/draganddrop/views/gridview.qml56
-rw-r--r--examples/quick/externaldraganddrop/DragAndDropTextItem.qml23
-rw-r--r--examples/quick/imageelements/animatedsprite.qml2
-rw-r--r--examples/quick/imageelements/content/BorderImageSelector.qml5
-rw-r--r--examples/quick/imageelements/content/ImageCell.qml2
-rw-r--r--examples/quick/imageelements/content/MyBorderImage.qml1
-rw-r--r--examples/quick/imageelements/image.qml34
-rw-r--r--examples/quick/imageprovider/imageprovider.cpp10
-rw-r--r--examples/quick/imageresponseprovider/imageresponseprovider.cpp9
-rw-r--r--examples/quick/keyinteraction/focus/Core/ContextMenu.qml3
-rw-r--r--examples/quick/keyinteraction/focus/Core/GridMenu.qml21
-rw-r--r--examples/quick/keyinteraction/focus/Core/ListMenu.qml20
-rw-r--r--examples/quick/keyinteraction/focus/Core/ListViewDelegate.qml6
-rw-r--r--examples/quick/keyinteraction/focus/Core/TabMenu.qml11
-rw-r--r--examples/quick/keyinteraction/focus/focus.qml34
-rw-r--r--examples/quick/layouts/layouts.qml13
-rw-r--r--examples/quick/localstorage/localstorage/Header.qml21
-rw-r--r--examples/quick/localstorage/localstorage/MyDelegate.qml19
-rw-r--r--examples/quick/localstorage/localstorage/localstorage.qml33
-rw-r--r--examples/quick/models/abstractitemmodel/main.cpp4
-rw-r--r--examples/quick/models/abstractitemmodel/view.qml10
-rw-r--r--examples/quick/models/objectlistmodel/main.cpp15
-rw-r--r--examples/quick/models/objectlistmodel/view.qml8
-rw-r--r--examples/quick/models/stringlistmodel/main.cpp14
-rw-r--r--examples/quick/models/stringlistmodel/view.qml8
-rw-r--r--examples/quick/mousearea/mousearea-wheel-example.qml2
-rw-r--r--examples/quick/mousearea/mousearea.qml6
-rw-r--r--examples/quick/particles/affectors/content/customaffector.qml4
-rw-r--r--examples/quick/particles/affectors/content/groupgoal.qml4
-rw-r--r--examples/quick/particles/emitters/content/burstandpulse.qml8
-rw-r--r--examples/quick/particles/emitters/content/customemitter.qml6
-rw-r--r--examples/quick/particles/imageparticle/content/sharing.qml90
-rw-r--r--examples/quick/particles/itemparticle/particleview.qml13
-rw-r--r--examples/quick/positioners/positioners-transitions.qml7
-rw-r--r--examples/quick/quick-accessibility/content/Button.qml1
-rw-r--r--examples/quick/quick-accessibility/content/Slider.qml7
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/fbitem.h1
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp2
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro4
-rw-r--r--examples/quick/quickwidgets/quickwidget/fbitem.h1
-rw-r--r--examples/quick/quickwidgets/quickwidget/main.cpp2
-rw-r--r--examples/quick/quickwidgets/quickwidget/quickwidget.pro4
-rw-r--r--examples/quick/righttoleft/layoutdirection/layoutdirection.qml61
-rw-r--r--examples/quick/righttoleft/textalignment/textalignment.qml85
-rw-r--r--examples/quick/scenegraph/customgeometry/beziercurve.h3
-rw-r--r--examples/quick/scenegraph/customgeometry/customgeometry.pro4
-rw-r--r--examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc15
-rw-r--r--examples/quick/scenegraph/customgeometry/main.cpp3
-rw-r--r--examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp1
-rw-r--r--examples/quick/scenegraph/d3d11underqml/d3d11squircle.h1
-rw-r--r--examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro4
-rw-r--r--examples/quick/scenegraph/d3d11underqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/fboitem/fboinsgrenderer.h1
-rw-r--r--examples/quick/scenegraph/fboitem/fboitem.pro4
-rw-r--r--examples/quick/scenegraph/fboitem/fboitem.qrc2
-rw-r--r--examples/quick/scenegraph/fboitem/main.cpp2
-rw-r--r--examples/quick/scenegraph/fboitem/main.qml15
-rw-r--r--examples/quick/scenegraph/fboitem/shaders/+qsb/checker.fragbin0 -> 1615 bytes
-rw-r--r--examples/quick/scenegraph/fboitem/shaders/checker.frag14
-rw-r--r--examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag22
-rw-r--r--examples/quick/scenegraph/graph/graph.h1
-rw-r--r--examples/quick/scenegraph/graph/graph.pro4
-rw-r--r--examples/quick/scenegraph/graph/main.cpp2
-rw-r--r--examples/quick/scenegraph/metaltextureimport/main.cpp4
-rw-r--r--examples/quick/scenegraph/metaltextureimport/metaltextureimport.h1
-rw-r--r--examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro8
-rw-r--r--examples/quick/scenegraph/metalunderqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalsquircle.h1
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalsquircle.mm5
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalunderqml.pro9
-rw-r--r--examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc5
-rw-r--r--examples/quick/scenegraph/openglunderqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/openglunderqml/openglunderqml.pro4
-rw-r--r--examples/quick/scenegraph/openglunderqml/squircle.h1
-rw-r--r--examples/quick/scenegraph/rendernode/customrenderitem.h3
-rw-r--r--examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc2
-rw-r--r--examples/quick/scenegraph/rendernode/main.cpp4
-rw-r--r--examples/quick/scenegraph/rendernode/main.qml2
-rw-r--r--examples/quick/scenegraph/rendernode/rendernode.pro4
-rw-r--r--examples/quick/scenegraph/rendernode/softwarerenderer.cpp3
-rw-r--r--examples/quick/scenegraph/scenegraph.pro6
-rw-r--r--examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc26
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerial.cpp153
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerial.pro10
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerialitem.cpp169
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerialitem.h82
-rw-r--r--examples/quick/scenegraph/textureinthread/main.cpp1
-rw-r--r--examples/quick/scenegraph/textureinthread/textureinthread.pro4
-rw-r--r--examples/quick/scenegraph/textureinthread/threadrenderer.h1
-rw-r--r--examples/quick/scenegraph/threadedanimation/main.cpp2
-rw-r--r--examples/quick/scenegraph/threadedanimation/spinner.h1
-rw-r--r--examples/quick/scenegraph/threadedanimation/threadedanimation.pro4
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.cpp2
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.qml17
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.fragbin0 -> 1824 bytes
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.fragbin0 -> 1941 bytes
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vertbin0 -> 1815 bytes
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/checker.frag14
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag25
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag12
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert12
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag20
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert19
-rw-r--r--examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro4
-rw-r--r--examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc8
-rw-r--r--examples/quick/scenegraph/twotextureproviders/xorblender.cpp220
-rw-r--r--examples/quick/scenegraph/twotextureproviders/xorblender.h1
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpgbin0 -> 28887 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc48
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/main.cpp67
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/main.qml123
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/squircle.frag.spvbin0 -> 1432 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/squircle.vert.spvbin0 -> 644 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp823
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h89
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro13
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc7
-rw-r--r--examples/quick/scenegraph/vulkanunderqml/main.cpp3
-rw-r--r--examples/quick/scenegraph/vulkanunderqml/vulkansquircle.h1
-rw-r--r--examples/quick/scenegraph/vulkanunderqml/vulkanunderqml.pro3
-rw-r--r--examples/quick/shadereffects/content/shaders/+qsb/blur.fragbin2247 -> 1811 bytes
-rw-r--r--examples/quick/shadereffects/content/shaders/+qsb/colorize.fragbin2106 -> 1701 bytes
-rw-r--r--examples/quick/shadereffects/content/shaders/+qsb/genie.vertbin2629 -> 2201 bytes
-rw-r--r--examples/quick/shadereffects/content/shaders/+qsb/outline.fragbin2538 -> 2117 bytes
-rw-r--r--examples/quick/shadereffects/content/shaders/+qsb/shadow.fragbin2151 -> 1745 bytes
-rw-r--r--examples/quick/shadereffects/content/shaders/+qsb/wobble.fragbin2049 -> 1625 bytes
-rw-r--r--examples/quick/shapes/content/item18.qml71
-rw-r--r--examples/quick/shapes/content/shapegallery.qml4
-rw-r--r--examples/quick/shapes/shapes.pro3
-rw-r--r--examples/quick/shapes/shapes.qrc1
-rw-r--r--examples/quick/shared/FlickrRssModel.qml8
-rw-r--r--examples/quick/shared/LauncherList.qml4
-rw-r--r--examples/quick/shared/SimpleLauncherDelegate.qml11
-rw-r--r--examples/quick/shared/TabSet.qml9
-rw-r--r--examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc6
-rw-r--r--examples/quick/tableview/gameoflife/gameoflife.pro5
-rw-r--r--examples/quick/tableview/gameoflife/gameoflifemodel.h2
-rw-r--r--examples/quick/tableview/gameoflife/main.cpp4
-rw-r--r--examples/quick/tableview/gameoflife/main.qml8
-rw-r--r--examples/quick/tableview/pixelator/doc/src/pixelator.qdoc6
-rw-r--r--examples/quick/tableview/pixelator/imagemodel.h2
-rw-r--r--examples/quick/tableview/pixelator/main.cpp4
-rw-r--r--examples/quick/tableview/pixelator/main.qml6
-rw-r--r--examples/quick/tableview/pixelator/pixelator.pro4
-rw-r--r--examples/quick/text/fonts/availableFonts.qml5
-rw-r--r--examples/quick/text/fonts/fonts.qml13
-rw-r--r--examples/quick/text/imgtag/TextWithImage.qml2
-rw-r--r--examples/quick/text/imgtag/imgtag.qml3
-rw-r--r--examples/quick/text/styledtext-layout.qml27
-rw-r--r--examples/quick/threading/threadedlistmodel/timedisplay.qml5
-rw-r--r--examples/quick/threading/workerscript/Spinner.qml1
-rw-r--r--examples/quick/threading/workerscript/workerscript.qml2
-rw-r--r--examples/quick/touchinteraction/flickable/content/Panel.qml168
-rw-r--r--examples/quick/touchinteraction/flickable/corkboards.qml4
-rw-r--r--examples/quick/touchinteraction/multipointtouch/bearwhack.qml12
-rw-r--r--examples/quick/touchinteraction/multipointtouch/content/AugmentedTouchPoint.qml2
-rw-r--r--examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml9
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.pro9
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.qrc6
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview1/main.cpp51
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.pro9
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.qrc6
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview2/main.cpp51
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.pro9
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.qrc6
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview3/main.cpp51
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.pro9
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.qrc6
-rw-r--r--examples/quick/tutorials/dynamicview/dynamicview4/main.cpp51
-rw-r--r--examples/quick/tutorials/samegame/samegame1/main.cpp51
-rw-r--r--examples/quick/tutorials/samegame/samegame1/samegame1.pro11
-rw-r--r--examples/quick/tutorials/samegame/samegame1/samegame1.qrc7
-rw-r--r--examples/quick/tutorials/samegame/samegame2/main.cpp51
-rw-r--r--examples/quick/tutorials/samegame/samegame2/samegame2.pro11
-rw-r--r--examples/quick/tutorials/samegame/samegame2/samegame2.qrc8
-rw-r--r--examples/quick/tutorials/samegame/samegame3/main.cpp51
-rw-r--r--examples/quick/tutorials/samegame/samegame3/samegame3.pro11
-rw-r--r--examples/quick/tutorials/samegame/samegame3/samegame3.qrc8
-rw-r--r--examples/quick/tutorials/samegame/samegame4/main.cpp51
-rw-r--r--examples/quick/tutorials/samegame/samegame4/samegame4.pro11
-rw-r--r--examples/quick/tutorials/samegame/samegame4/samegame4.qrc13
-rw-r--r--examples/quick/tutorials/samegame/shared/pics/shared.qrc13
-rw-r--r--examples/quick/views/delegatemodel/dragselection.qml5
-rw-r--r--examples/quick/views/delegatemodel/flipable.pro9
-rw-r--r--examples/quick/views/delegatemodel/flipable.qrc9
-rw-r--r--examples/quick/views/delegatemodel/main.cpp51
-rw-r--r--examples/quick/views/delegatemodel/slideshow.qml4
-rw-r--r--examples/quick/views/gridview/gridview-example.qml10
-rw-r--r--examples/quick/views/listview/content/PressAndHoldButton.qml4
-rw-r--r--examples/quick/views/listview/content/ToggleButton.qml2
-rw-r--r--examples/quick/views/listview/displaymargin.qml5
-rw-r--r--examples/quick/views/listview/dynamiclist.qml37
-rw-r--r--examples/quick/views/listview/expandingdelegates.qml18
-rw-r--r--examples/quick/views/listview/highlight.qml68
-rw-r--r--examples/quick/views/listview/highlightranges.qml32
-rw-r--r--examples/quick/views/listview/sections.qml10
-rw-r--r--examples/quick/views/objectmodel/objectmodel.qml10
-rw-r--r--examples/quick/views/package/Delegate.qml10
-rw-r--r--examples/quick/views/package/view.qml4
-rw-r--r--examples/quick/views/pathview/pathview-example.qml10
-rw-r--r--examples/quick/window/AllScreens.qml8
-rw-r--r--examples/quick/window/CurrentScreen.qml4
-rw-r--r--examples/quick/window/Splash.qml4
-rw-r--r--examples/quick/window/window.qml63
242 files changed, 3961 insertions, 928 deletions
diff --git a/examples/quick/animation/animation.qrc b/examples/quick/animation/animation.qrc
index d4e78c82f0..2d88c03007 100644
--- a/examples/quick/animation/animation.qrc
+++ b/examples/quick/animation/animation.qrc
@@ -9,6 +9,7 @@
<file>basics/color-animation.qml</file>
<file>basics/property-animation.qml</file>
<file>behaviors/behavior-example.qml</file>
+ <file>behaviors/FocusRect.qml</file>
<file>behaviors/SideRect.qml</file>
<file>behaviors/tvtennis.qml</file>
<file>behaviors/wigglytext.qml</file>
diff --git a/examples/quick/animation/basics/property-animation.qml b/examples/quick/animation/basics/property-animation.qml
index a764c395ee..8d640c9dda 100644
--- a/examples/quick/animation/basics/property-animation.qml
+++ b/examples/quick/animation/basics/property-animation.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Item {
diff --git a/examples/quick/animation/behaviors/FocusRect.qml b/examples/quick/animation/behaviors/FocusRect.qml
new file mode 100644
index 0000000000..5188919606
--- /dev/null
+++ b/examples/quick/animation/behaviors/FocusRect.qml
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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
+
+Rectangle {
+ id: focusRect
+ property string text
+
+ x: 62
+ y: 75
+ width: 75
+ height: 50
+ radius: 6
+ border.width: 4
+ border.color: "white"
+ color: "firebrick"
+
+ // Set an 'elastic' behavior on the focusRect's x property.
+ Behavior on x {
+ NumberAnimation {
+ easing.type: Easing.OutElastic
+ easing.amplitude: 3.0
+ easing.period: 2.0
+ duration: 300
+ }
+ }
+
+ //! [0]
+ // Set an 'elastic' behavior on the focusRect's y property.
+ Behavior on y {
+ NumberAnimation {
+ easing.type: Easing.OutElastic
+ easing.amplitude: 3.0
+ easing.period: 2.0
+ duration: 300
+ }
+ }
+ //! [0]
+
+ Text {
+ id: focusText
+ text: focusRect.text
+ anchors.centerIn: parent
+ color: "white"
+ font.pixelSize: 16
+ font.bold: true
+
+ // Set a behavior on the focusText's x property:
+ // Set the opacity to 0, set the new text value, then set the opacity back to 1.
+ Behavior on text {
+ SequentialAnimation {
+ NumberAnimation {
+ target: focusText
+ property: "opacity"
+ to: 0
+ duration: 150
+ }
+ NumberAnimation {
+ target: focusText
+ property: "opacity"
+ to: 1
+ duration: 150
+ }
+ }
+ }
+ }
+}
diff --git a/examples/quick/animation/behaviors/SideRect.qml b/examples/quick/animation/behaviors/SideRect.qml
index 8b37a6a0ca..19c0528054 100644
--- a/examples/quick/animation/behaviors/SideRect.qml
+++ b/examples/quick/animation/behaviors/SideRect.qml
@@ -53,6 +53,7 @@ import QtQuick 2.0
Rectangle {
id: myRect
+ property FocusRect focusItem
property string text
width: 75; height: 50
@@ -64,9 +65,9 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
onEntered: {
- focusRect.x = myRect.x;
- focusRect.y = myRect.y;
- focusRect.text = myRect.text;
+ myRect.focusItem.x = myRect.x;
+ myRect.focusItem.y = myRect.y;
+ myRect.focusItem.text = myRect.text;
}
}
}
diff --git a/examples/quick/animation/behaviors/behavior-example.qml b/examples/quick/animation/behaviors/behavior-example.qml
index 1d07e6bb90..43ca31f185 100644
--- a/examples/quick/animation/behaviors/behavior-example.qml
+++ b/examples/quick/animation/behaviors/behavior-example.qml
@@ -64,67 +64,34 @@ Rectangle {
SideRect {
id: leftRect
+ focusItem: focusRect
anchors { verticalCenter: parent.verticalCenter; horizontalCenter: parent.left }
text: "Left"
}
SideRect {
id: rightRect
+ focusItem: focusRect
anchors { verticalCenter: parent.verticalCenter; horizontalCenter: parent.right }
text: "Right"
}
SideRect {
id: topRect
+ focusItem: focusRect
anchors { verticalCenter: parent.top; horizontalCenter: parent.horizontalCenter }
text: "Top"
}
SideRect {
id: bottomRect
+ focusItem: focusRect
anchors { verticalCenter: parent.bottom; horizontalCenter: parent.horizontalCenter }
text: "Bottom"
}
-
- Rectangle {
+ FocusRect {
id: focusRect
-
- property string text
-
- x: 62; y: 75; width: 75; height: 50
- radius: 6
- border.width: 4; border.color: "white"
- color: "firebrick"
-
- // Set an 'elastic' behavior on the focusRect's x property.
- Behavior on x {
- NumberAnimation { easing.type: Easing.OutElastic; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 }
- }
-
- //! [0]
- // Set an 'elastic' behavior on the focusRect's y property.
- Behavior on y {
- NumberAnimation { easing.type: Easing.OutElastic; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 }
- }
- //! [0]
-
- Text {
- id: focusText
- text: focusRect.text
- anchors.centerIn: parent
- color: "white"
- font.pixelSize: 16; font.bold: true
-
- // Set a behavior on the focusText's x property:
- // Set the opacity to 0, set the new text value, then set the opacity back to 1.
- Behavior on text {
- SequentialAnimation {
- NumberAnimation { target: focusText; property: "opacity"; to: 0; duration: 150 }
- NumberAnimation { target: focusText; property: "opacity"; to: 1; duration: 150 }
- }
- }
- }
}
}
}
diff --git a/examples/quick/animation/behaviors/tvtennis.qml b/examples/quick/animation/behaviors/tvtennis.qml
index 89d912777a..261f603de6 100644
--- a/examples/quick/animation/behaviors/tvtennis.qml
+++ b/examples/quick/animation/behaviors/tvtennis.qml
@@ -116,6 +116,13 @@ Rectangle {
Rectangle { color: "#1e1b18"; x: page.width/2+50; y: 10; width: 20; height: 40 }
Repeater {
model: page.height / 20
- Rectangle { color: "#328930"; x: page.width/2-5; y: index * 20; width: 10; height: 10 }
+ Rectangle {
+ required property int index
+ color: "#328930"
+ x: page.width / 2 - 5
+ y: index * 20
+ width: 10
+ height: 10
+ }
}
}
diff --git a/examples/quick/animation/behaviors/wigglytext.qml b/examples/quick/animation/behaviors/wigglytext.qml
index cc2e086b51..81d4a8aef9 100644
--- a/examples/quick/animation/behaviors/wigglytext.qml
+++ b/examples/quick/animation/behaviors/wigglytext.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Rectangle {
@@ -58,7 +59,7 @@ Rectangle {
width: 320; height: 480; color: "#474747"; focus: true
- Keys.onPressed: {
+ Keys.onPressed: (event) => {
if (event.key == Qt.Key_Delete || event.key == Qt.Key_Backspace)
container.remove()
else if (event.text != "") {
diff --git a/examples/quick/animation/doc/src/animation.qdoc b/examples/quick/animation/doc/src/animation.qdoc
index 578fb4b849..97a574d768 100644
--- a/examples/quick/animation/doc/src/animation.qdoc
+++ b/examples/quick/animation/doc/src/animation.qdoc
@@ -60,7 +60,7 @@
\section1 Behaviors
\e Behaviors uses behaviors to move a rectangle to where you click.
- \snippet animation/behaviors/behavior-example.qml 0
+ \snippet animation/behaviors/FocusRect.qml 0
\section1 Wiggly Text
diff --git a/examples/quick/animation/easing/easing.qml b/examples/quick/animation/easing/easing.qml
index 6db5599a66..f443486141 100644
--- a/examples/quick/animation/easing/easing.qml
+++ b/examples/quick/animation/easing/easing.qml
@@ -48,6 +48,8 @@
**
****************************************************************************/
+import QtQml 2.15
+import QtQml.Models 2.15
import QtQuick 2.0
Rectangle {
@@ -107,9 +109,14 @@ Rectangle {
id: delegate
Item {
+ id: delegateInstance
+ required property string name;
+ required property int type;
+ required property color ballColor;
+
height: 56; width: window.width
- Text { text: name; anchors.centerIn: parent; color: "White" }
+ Text { text: parent.name; anchors.centerIn: parent; color: "White" }
Rectangle {
id: slot1; color: "#121212"; x: 30; height: 46; width: 46
@@ -137,12 +144,26 @@ Rectangle {
states : State {
name: "right"
- PropertyChanges { target: rect; x: window.width - 76; color: ballColor }
+ PropertyChanges {
+ target: rect;
+ x: window.width - 76;
+ color: delegateInstance.ballColor
+ }
}
transitions: Transition {
- NumberAnimation { properties: "x"; easing.type: type; easing.bezierCurve: getBezierCurve(name); duration: 1000 }
- ColorAnimation { properties: "color"; easing.type: type; easing.bezierCurve: getBezierCurve(name); duration: 1000 }
+ NumberAnimation {
+ properties: "x"
+ easing.type: delegateInstance.type
+ easing.bezierCurve: window.getBezierCurve(delegateInstance.name)
+ duration: 1000
+ }
+ ColorAnimation {
+ properties: "color"
+ easing.type: delegateInstance.type
+ easing.bezierCurve: window.getBezierCurve(delegateInstance.name)
+ duration: 1000
+ }
}
}
}
diff --git a/examples/quick/animation/pathanimation/pathanimation.qml b/examples/quick/animation/pathanimation/pathanimation.qml
index b98fbebefc..ae96b32680 100644
--- a/examples/quick/animation/pathanimation/pathanimation.qml
+++ b/examples/quick/animation/pathanimation/pathanimation.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Rectangle {
diff --git a/examples/quick/animation/pathinterpolator/pathinterpolator.qml b/examples/quick/animation/pathinterpolator/pathinterpolator.qml
index 0c0d7bad46..07a82fc916 100644
--- a/examples/quick/animation/pathinterpolator/pathinterpolator.qml
+++ b/examples/quick/animation/pathinterpolator/pathinterpolator.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Rectangle {
diff --git a/examples/quick/animation/states/states.qml b/examples/quick/animation/states/states.qml
index 498fb6867c..5ff8e5318c 100644
--- a/examples/quick/animation/states/states.qml
+++ b/examples/quick/animation/states/states.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Rectangle {
diff --git a/examples/quick/canvas/smile/smile.qml b/examples/quick/canvas/smile/smile.qml
index 880116726f..cde18d4d38 100644
--- a/examples/quick/canvas/smile/smile.qml
+++ b/examples/quick/canvas/smile/smile.qml
@@ -97,7 +97,6 @@ Item {
ctx.save();
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.translate(originX, originX);
- ctx.globalAlpha = canvas.alpha;
ctx.strokeStyle = canvas.strokeStyle;
ctx.fillStyle = canvas.fillStyle;
ctx.lineWidth = canvas.lineWidth;
diff --git a/examples/quick/customitems/flipable/flipable.pro b/examples/quick/customitems/flipable/flipable.pro
new file mode 100644
index 0000000000..ba00bf792c
--- /dev/null
+++ b/examples/quick/customitems/flipable/flipable.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += flipable.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/flipable
+INSTALLS += target
diff --git a/examples/quick/customitems/flipable/flipable.qrc b/examples/quick/customitems/flipable/flipable.qrc
new file mode 100644
index 0000000000..7918ccf00e
--- /dev/null
+++ b/examples/quick/customitems/flipable/flipable.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/">
+ <file>flipable.qml</file>
+ <file>content/5_heart.png</file>
+ <file>content/9_club.png</file>
+ <file>content/back.png</file>
+ <file>content/Card.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/customitems/flipable/main.cpp b/examples/quick/customitems/flipable/main.cpp
new file mode 100644
index 0000000000..a0f0d67d45
--- /dev/null
+++ b/examples/quick/customitems/flipable/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(flipable)
diff --git a/examples/quick/customitems/maskedmousearea/main.cpp b/examples/quick/customitems/maskedmousearea/main.cpp
index 63558d1b20..5b42516154 100644
--- a/examples/quick/customitems/maskedmousearea/main.cpp
+++ b/examples/quick/customitems/maskedmousearea/main.cpp
@@ -53,14 +53,11 @@
#include "maskedmousearea.h"
-
int main(int argc, char* argv[])
{
QGuiApplication app(argc,argv);
QQuickView view;
- qmlRegisterType<MaskedMouseArea>("Example", 1, 0, "MaskedMouseArea");
-
view.setSource(QUrl("qrc:///customitems/maskedmousearea/maskedmousearea.qml"));
view.show();
return app.exec();
diff --git a/examples/quick/customitems/maskedmousearea/maskedmousearea.h b/examples/quick/customitems/maskedmousearea/maskedmousearea.h
index 28ff6ca9df..39d78a019a 100644
--- a/examples/quick/customitems/maskedmousearea/maskedmousearea.h
+++ b/examples/quick/customitems/maskedmousearea/maskedmousearea.h
@@ -62,6 +62,7 @@ class MaskedMouseArea : public QQuickItem
Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
Q_PROPERTY(QUrl maskSource READ maskSource WRITE setMaskSource NOTIFY maskSourceChanged)
Q_PROPERTY(qreal alphaThreshold READ alphaThreshold WRITE setAlphaThreshold NOTIFY alphaThresholdChanged)
+ QML_ELEMENT
public:
MaskedMouseArea(QQuickItem *parent = 0);
diff --git a/examples/quick/customitems/maskedmousearea/maskedmousearea.pro b/examples/quick/customitems/maskedmousearea/maskedmousearea.pro
index fe5c05ce61..c5cedf4e6e 100644
--- a/examples/quick/customitems/maskedmousearea/maskedmousearea.pro
+++ b/examples/quick/customitems/maskedmousearea/maskedmousearea.pro
@@ -2,6 +2,10 @@ TEMPLATE = app
QT += quick qml
+CONFIG += qmltypes
+QML_IMPORT_NAME = Example
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += maskedmousearea.h
SOURCES += main.cpp \
diff --git a/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h b/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h
index d3a1f4ba91..4abf2cf3dc 100644
--- a/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h
+++ b/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h
@@ -48,17 +48,12 @@
**
****************************************************************************/
-#include <QQmlExtensionPlugin>
+#include <QQmlEngineExtensionPlugin>
#include "../textballoon.h"
-class TextBalloonPlugin : public QQmlExtensionPlugin
+class TextBalloonPlugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
-public:
- void registerTypes(const char *uri)
- {
- qmlRegisterType<TextBalloon>(uri, 1, 0, "TextBalloon");
- }
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
};
diff --git a/examples/quick/customitems/painteditem/painteditem.pro b/examples/quick/customitems/painteditem/painteditem.pro
index bc7480ab9e..641833f3aa 100644
--- a/examples/quick/customitems/painteditem/painteditem.pro
+++ b/examples/quick/customitems/painteditem/painteditem.pro
@@ -1,21 +1,25 @@
TEMPLATE = lib
-CONFIG += plugin
+CONFIG += plugin qmltypes
QT += qml quick
+QML_IMPORT_NAME = TextBalloonPlugin
+QML_IMPORT_MAJOR_VERSION = 1
+
TARGET = qmltextballoonplugin
-HEADERS += TextBalloonPlugin/plugin.h \
+HEADERS += \
+ TextBalloonPlugin/plugin.h \
textballoon.h
SOURCES += textballoon.cpp
RESOURCES += painteditem.qrc
-DESTDIR = TextBalloonPlugin
+DESTDIR = $$QML_IMPORT_NAME
-target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/TextBalloonPlugin
-qmldir.files = TextBalloonPlugin/qmldir
-qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/TextBalloonPlugin
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
+qmldir.files = $$QML_IMPORT_NAME/qmldir
+qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
INSTALLS += qmldir target
diff --git a/examples/quick/customitems/painteditem/textballoon.h b/examples/quick/customitems/painteditem/textballoon.h
index 81b3e2961d..eb72804602 100644
--- a/examples/quick/customitems/painteditem/textballoon.h
+++ b/examples/quick/customitems/painteditem/textballoon.h
@@ -58,6 +58,7 @@ class TextBalloon : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(bool rightAligned READ isRightAligned WRITE setRightAligned NOTIFY rightAlignedChanged)
+ QML_ELEMENT
public:
TextBalloon(QQuickItem *parent = 0);
diff --git a/examples/quick/customitems/scrollbar/main.cpp b/examples/quick/customitems/scrollbar/main.cpp
new file mode 100644
index 0000000000..579db41efd
--- /dev/null
+++ b/examples/quick/customitems/scrollbar/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(main)
diff --git a/examples/quick/customitems/scrollbar/scrollbar.pro b/examples/quick/customitems/scrollbar/scrollbar.pro
new file mode 100644
index 0000000000..7e6ea3c2d6
--- /dev/null
+++ b/examples/quick/customitems/scrollbar/scrollbar.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += scrollbar.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/scrollbar
+INSTALLS += target
diff --git a/examples/quick/customitems/scrollbar/scrollbar.qrc b/examples/quick/customitems/scrollbar/scrollbar.qrc
new file mode 100644
index 0000000000..b1ba5f9211
--- /dev/null
+++ b/examples/quick/customitems/scrollbar/scrollbar.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>ScrollBar.qml</file>
+ <file>pics/niagara_falls.jpg</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/customitems/searchbox/main.cpp b/examples/quick/customitems/searchbox/main.cpp
new file mode 100644
index 0000000000..579db41efd
--- /dev/null
+++ b/examples/quick/customitems/searchbox/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(main)
diff --git a/examples/quick/customitems/searchbox/searchbox.pro b/examples/quick/customitems/searchbox/searchbox.pro
new file mode 100644
index 0000000000..c22fc117aa
--- /dev/null
+++ b/examples/quick/customitems/searchbox/searchbox.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += searchbox.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/searchbox
+INSTALLS += target
diff --git a/examples/quick/customitems/searchbox/searchbox.qrc b/examples/quick/customitems/searchbox/searchbox.qrc
new file mode 100644
index 0000000000..f7a8602c9a
--- /dev/null
+++ b/examples/quick/customitems/searchbox/searchbox.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>SearchBox.qml</file>
+ <file>images/clear.png</file>
+ <file>images/lineedit-bg-focus.png</file>
+ <file>images/lineedit-bg.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/customitems/spinner/main.cpp b/examples/quick/customitems/spinner/main.cpp
new file mode 100644
index 0000000000..579db41efd
--- /dev/null
+++ b/examples/quick/customitems/spinner/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(main)
diff --git a/examples/quick/customitems/spinner/spinner.pro b/examples/quick/customitems/spinner/spinner.pro
new file mode 100644
index 0000000000..b5be6884d2
--- /dev/null
+++ b/examples/quick/customitems/spinner/spinner.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += spinner.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/spinner
+INSTALLS += target
diff --git a/examples/quick/customitems/spinner/spinner.qrc b/examples/quick/customitems/spinner/spinner.qrc
new file mode 100644
index 0000000000..3a8e4b17fd
--- /dev/null
+++ b/examples/quick/customitems/spinner/spinner.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>content/spinner-bg.png</file>
+ <file>content/spinner-select.png</file>
+ <file>content/Spinner.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/customitems/tabwidget/main.cpp b/examples/quick/customitems/tabwidget/main.cpp
new file mode 100644
index 0000000000..579db41efd
--- /dev/null
+++ b/examples/quick/customitems/tabwidget/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(main)
diff --git a/examples/quick/customitems/tabwidget/tabwidget.pro b/examples/quick/customitems/tabwidget/tabwidget.pro
new file mode 100644
index 0000000000..b852bb4075
--- /dev/null
+++ b/examples/quick/customitems/tabwidget/tabwidget.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += tabwidget.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/tabwidget
+INSTALLS += target
diff --git a/examples/quick/customitems/tabwidget/tabwidget.qrc b/examples/quick/customitems/tabwidget/tabwidget.qrc
new file mode 100644
index 0000000000..ee71f677b1
--- /dev/null
+++ b/examples/quick/customitems/tabwidget/tabwidget.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ <file>TabWidget.qml</file>
+ <file>doc/images/qml-tabwidget-example.png</file>
+ <file>doc/images/tab.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/draganddrop/draganddrop.qrc b/examples/quick/draganddrop/draganddrop.qrc
index 6d064f7722..df9fec51d2 100644
--- a/examples/quick/draganddrop/draganddrop.qrc
+++ b/examples/quick/draganddrop/draganddrop.qrc
@@ -5,5 +5,6 @@
<file>tiles/DropTile.qml</file>
<file>tiles/tiles.qml</file>
<file>views/gridview.qml</file>
+ <file>views/Icon.qml</file>
</qresource>
</RCC>
diff --git a/examples/quick/draganddrop/tiles/DragTile.qml b/examples/quick/draganddrop/tiles/DragTile.qml
index 78fe7a483a..47f0ebed5e 100644
--- a/examples/quick/draganddrop/tiles/DragTile.qml
+++ b/examples/quick/draganddrop/tiles/DragTile.qml
@@ -53,7 +53,9 @@ import QtQuick 2.0
//! [0]
Item {
id: root
- property string colorKey
+
+ required property string colorKey
+ required property int modelData
width: 64; height: 64
@@ -74,9 +76,9 @@ Item {
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
- color: colorKey
+ color: root.colorKey
- Drag.keys: [ colorKey ]
+ Drag.keys: [ root.colorKey ]
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 32
Drag.hotSpot.y: 32
@@ -85,7 +87,7 @@ Item {
anchors.fill: parent
color: "white"
font.pixelSize: 48
- text: modelData + 1
+ text: root.modelData + 1
horizontalAlignment:Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
diff --git a/examples/quick/draganddrop/tiles/DropTile.qml b/examples/quick/draganddrop/tiles/DropTile.qml
index de4c0dee44..bf7101f0f6 100644
--- a/examples/quick/draganddrop/tiles/DropTile.qml
+++ b/examples/quick/draganddrop/tiles/DropTile.qml
@@ -64,7 +64,7 @@ DropArea {
id: dropRectangle
anchors.fill: parent
- color: colorKey
+ color: dragTarget.colorKey
states: [
State {
diff --git a/examples/quick/draganddrop/views/Icon.qml b/examples/quick/draganddrop/views/Icon.qml
new file mode 100644
index 0000000000..261d6d146a
--- /dev/null
+++ b/examples/quick/draganddrop/views/Icon.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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.14
+
+Rectangle {
+ id: icon
+ required property Item dragParent
+
+ property int visualIndex: 0
+ width: 72
+ height: 72
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ verticalCenter: parent.verticalCenter
+ }
+ radius: 3
+
+ Text {
+ anchors.centerIn: parent
+ color: "white"
+ text: parent.visualIndex
+ }
+
+ DragHandler {
+ id: dragHandler
+ }
+
+ Drag.active: dragHandler.active
+ Drag.source: icon
+ Drag.hotSpot.x: 36
+ Drag.hotSpot.y: 36
+
+ states: [
+ State {
+ when: dragHandler.active
+ ParentChange {
+ target: icon
+ parent: icon.dragParent
+ }
+
+ AnchorChanges {
+ target: icon
+ anchors.horizontalCenter: undefined
+ anchors.verticalCenter: undefined
+ }
+ }
+ ]
+}
diff --git a/examples/quick/draganddrop/views/gridview.qml b/examples/quick/draganddrop/views/gridview.qml
index 6c5bcef729..05bd48e7fa 100644
--- a/examples/quick/draganddrop/views/gridview.qml
+++ b/examples/quick/draganddrop/views/gridview.qml
@@ -48,8 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.12
-import QtQml.Models 2.1
+import QtQml 2.14
+import QtQuick 2.14
+import QtQml.Models 2.14
GridView {
id: root
@@ -94,54 +95,21 @@ GridView {
//! [1]
delegate: DropArea {
id: delegateRoot
+ required property color color;
width: 80; height: 80
- onEntered: visualModel.items.move(drag.source.visualIndex, icon.visualIndex)
+ onEntered: function(drag) {
+ visualModel.items.move((drag.source as Icon).visualIndex, icon.visualIndex)
+ }
+
property int visualIndex: DelegateModel.itemsIndex
- Binding { target: icon; property: "visualIndex"; value: visualIndex }
- Rectangle {
+ Icon {
id: icon
- property int visualIndex: 0
- width: 72; height: 72
- anchors {
- horizontalCenter: parent.horizontalCenter;
- verticalCenter: parent.verticalCenter
- }
- radius: 3
- color: model.color
-
- Text {
- anchors.centerIn: parent
- color: "white"
- text: parent.visualIndex
- }
-
- DragHandler {
- id: dragHandler
- }
-
- Drag.active: dragHandler.active
- Drag.source: icon
- Drag.hotSpot.x: 36
- Drag.hotSpot.y: 36
-
- states: [
- State {
- when: icon.Drag.active
- ParentChange {
- target: icon
- parent: root
- }
-
- AnchorChanges {
- target: icon
- anchors.horizontalCenter: undefined
- anchors.verticalCenter: undefined
- }
- }
- ]
+ dragParent: root
+ visualIndex: delegateRoot.visualIndex
+ color: delegateRoot.color
}
}
//! [1]
diff --git a/examples/quick/externaldraganddrop/DragAndDropTextItem.qml b/examples/quick/externaldraganddrop/DragAndDropTextItem.qml
index 9858a961c9..605dc07434 100644
--- a/examples/quick/externaldraganddrop/DragAndDropTextItem.qml
+++ b/examples/quick/externaldraganddrop/DragAndDropTextItem.qml
@@ -71,14 +71,18 @@ Rectangle {
id: dropArea
anchors.fill: parent
keys: ["text/plain"]
- onEntered: if (!acceptDropCB.checked) {
- drag.accepted = false
- rejectAnimation.start()
+ onEntered: (drag) => {
+ if (!acceptDropCB.checked) {
+ drag.accepted = false
+ rejectAnimation.start()
+ }
}
- onDropped: if (drop.hasText && acceptDropCB.checked) {
- if (drop.proposedAction == Qt.MoveAction || drop.proposedAction == Qt.CopyAction) {
- item.display = drop.text
- drop.acceptProposedAction()
+ onDropped: (drop) => {
+ if (drop.hasText && acceptDropCB.checked) {
+ if (drop.proposedAction == Qt.MoveAction || drop.proposedAction == Qt.CopyAction) {
+ item.display = drop.text
+ drop.acceptProposedAction()
+ }
}
}
}
@@ -95,7 +99,10 @@ Rectangle {
Drag.hotSpot.y: 0
Drag.mimeData: { "text/plain": item.display }
Drag.dragType: Drag.Automatic
- Drag.onDragFinished: if (dropAction == Qt.MoveAction) item.display = ""
+ Drag.onDragFinished: (dropAction) => {
+ if (dropAction == Qt.MoveAction)
+ item.display = ""
+ }
}
Examples.CheckBox {
id: acceptDropCB
diff --git a/examples/quick/imageelements/animatedsprite.qml b/examples/quick/imageelements/animatedsprite.qml
index 0c6bf5e28d..cc5226882a 100644
--- a/examples/quick/imageelements/animatedsprite.qml
+++ b/examples/quick/imageelements/animatedsprite.qml
@@ -73,7 +73,7 @@ Item {
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
- onClicked: {
+ onClicked: (mouse) => {
if (!sprite.running)
sprite.start();
if (!sprite.paused)
diff --git a/examples/quick/imageelements/content/BorderImageSelector.qml b/examples/quick/imageelements/content/BorderImageSelector.qml
index 93ff5136bc..d8c2101be7 100644
--- a/examples/quick/imageelements/content/BorderImageSelector.qml
+++ b/examples/quick/imageelements/content/BorderImageSelector.qml
@@ -93,7 +93,10 @@ Item {
Repeater {
model: [ "Scale", "Repeat", "Scale/Repeat", "Round" ]
delegate: Text {
- text: model.modelData
+ required property string modelData
+ required property int index
+
+ text: modelData
anchors.verticalCenter: parent.verticalCenter
x: (index - selector.curIdx) * 80 + 140
diff --git a/examples/quick/imageelements/content/ImageCell.qml b/examples/quick/imageelements/content/ImageCell.qml
index 4b147633c3..7804346bd4 100644
--- a/examples/quick/imageelements/content/ImageCell.qml
+++ b/examples/quick/imageelements/content/ImageCell.qml
@@ -53,8 +53,6 @@ Item {
property alias mode: image.fillMode
property alias caption: captionItem.text
- width: parent.cellWidth; height: parent.cellHeight
-
Image {
id: image
width: parent.width; height: parent.height - captionItem.height
diff --git a/examples/quick/imageelements/content/MyBorderImage.qml b/examples/quick/imageelements/content/MyBorderImage.qml
index 01d26a9630..3198de3bf1 100644
--- a/examples/quick/imageelements/content/MyBorderImage.qml
+++ b/examples/quick/imageelements/content/MyBorderImage.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Item {
diff --git a/examples/quick/imageelements/image.qml b/examples/quick/imageelements/image.qml
index d414f59629..0750ea3b79 100644
--- a/examples/quick/imageelements/image.qml
+++ b/examples/quick/imageelements/image.qml
@@ -65,12 +65,34 @@ Rectangle {
rows: 3
spacing: 30
- ImageCell { mode: Image.Stretch; caption: "Stretch" }
- ImageCell { mode: Image.PreserveAspectFit; caption: "PreserveAspectFit" }
- ImageCell { mode: Image.PreserveAspectCrop; caption: "PreserveAspectCrop" }
+ component SizedImageCell: ImageCell {
+ width: parent.cellWidth
+ height: parent.cellHeight
+ }
- ImageCell { mode: Image.Tile; caption: "Tile" }
- ImageCell { mode: Image.TileHorizontally; caption: "TileHorizontally" }
- ImageCell { mode: Image.TileVertically; caption: "TileVertically" }
+ SizedImageCell {
+ mode: Image.Stretch
+ caption: "Stretch"
+ }
+ SizedImageCell {
+ mode: Image.PreserveAspectFit
+ caption: "PreserveAspectFit"
+ }
+ SizedImageCell {
+ mode: Image.PreserveAspectCrop
+ caption: "PreserveAspectCrop"
+ }
+ SizedImageCell {
+ mode: Image.Tile
+ caption: "Tile"
+ }
+ SizedImageCell {
+ mode: Image.TileHorizontally
+ caption: "TileHorizontally"
+ }
+ SizedImageCell {
+ mode: Image.TileVertically
+ caption: "TileVertically"
+ }
}
}
diff --git a/examples/quick/imageprovider/imageprovider.cpp b/examples/quick/imageprovider/imageprovider.cpp
index 2d927ea79a..a606352cce 100644
--- a/examples/quick/imageprovider/imageprovider.cpp
+++ b/examples/quick/imageprovider/imageprovider.cpp
@@ -90,22 +90,16 @@ public:
};
-class ImageProviderExtensionPlugin : public QQmlExtensionPlugin
+class ImageProviderExtensionPlugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
public:
- void registerTypes(const char *uri) override
- {
- Q_UNUSED(uri);
- }
-
void initializeEngine(QQmlEngine *engine, const char *uri) override
{
Q_UNUSED(uri);
engine->addImageProvider("colors", new ColorImageProvider);
}
-
};
diff --git a/examples/quick/imageresponseprovider/imageresponseprovider.cpp b/examples/quick/imageresponseprovider/imageresponseprovider.cpp
index 32510dbec8..4ab1090361 100644
--- a/examples/quick/imageresponseprovider/imageresponseprovider.cpp
+++ b/examples/quick/imageresponseprovider/imageresponseprovider.cpp
@@ -128,16 +128,11 @@ private:
};
-class ImageProviderExtensionPlugin : public QQmlExtensionPlugin
+class ImageProviderExtensionPlugin : public QQmlEngineExtensionPlugin
{
Q_OBJECT
- Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
+ Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
public:
- void registerTypes(const char *uri) override
- {
- Q_UNUSED(uri);
- }
-
void initializeEngine(QQmlEngine *engine, const char *uri) override
{
Q_UNUSED(uri);
diff --git a/examples/quick/keyinteraction/focus/Core/ContextMenu.qml b/examples/quick/keyinteraction/focus/Core/ContextMenu.qml
index c5430aa650..31b5e1b83d 100644
--- a/examples/quick/keyinteraction/focus/Core/ContextMenu.qml
+++ b/examples/quick/keyinteraction/focus/Core/ContextMenu.qml
@@ -52,6 +52,7 @@ import QtQuick 2.1
FocusScope {
id: container
+ required property Item keyRightTarget
property bool open: false
@@ -62,7 +63,7 @@ FocusScope {
anchors.fill: parent
color: "#D1DBBD"
focus: true
- Keys.onRightPressed: mainView.focus = true
+ Keys.onRightPressed: container.keyRightTarget.focus = true
Text {
anchors { top: parent.top; horizontalCenter: parent.horizontalCenter; margins: 30 }
diff --git a/examples/quick/keyinteraction/focus/Core/GridMenu.qml b/examples/quick/keyinteraction/focus/Core/GridMenu.qml
index 3f62adc792..78d6654957 100644
--- a/examples/quick/keyinteraction/focus/Core/GridMenu.qml
+++ b/examples/quick/keyinteraction/focus/Core/GridMenu.qml
@@ -51,12 +51,11 @@
import QtQuick 2.1
FocusScope {
+ id: menu
property alias interactive: gridView.interactive
-
- onActiveFocusChanged: {
- if (activeFocus)
- mainView.state = "showGridViews"
- }
+ required property Item keyUpTarget
+ required property Item keyDownTarget
+ required property Item keyLeftTarget
Rectangle {
anchors.fill: parent
@@ -73,13 +72,15 @@ FocusScope {
focus: true
model: 12
- KeyNavigation.up: tabMenu
- KeyNavigation.down: listMenu
- KeyNavigation.left: contextMenu
+ KeyNavigation.up: menu.keyUpTarget
+ KeyNavigation.down: menu.keyDownTarget
+ KeyNavigation.left: menu.keyLeftTarget
delegate: Item {
id: container
- width: GridView.view.cellWidth; height: GridView.view.cellHeight
+ width: GridView.view.cellWidth
+ height: GridView.view.cellHeight
+ required property int index
Rectangle {
id: content
@@ -97,7 +98,7 @@ FocusScope {
hoverEnabled: true
onClicked: {
- container.GridView.view.currentIndex = index
+ container.GridView.view.currentIndex = container.index
container.forceActiveFocus()
}
}
diff --git a/examples/quick/keyinteraction/focus/Core/ListMenu.qml b/examples/quick/keyinteraction/focus/Core/ListMenu.qml
index d8e9daba78..694ae3cac6 100644
--- a/examples/quick/keyinteraction/focus/Core/ListMenu.qml
+++ b/examples/quick/keyinteraction/focus/Core/ListMenu.qml
@@ -48,21 +48,22 @@
**
****************************************************************************/
+import QtQml 2.1
import QtQuick 2.1
FocusScope {
+ id: menu
clip: true
-
- onActiveFocusChanged: {
- if (activeFocus)
- mainView.state = "showListViews"
- }
+ required property Item keyUpTarget
+ required property Item keyLeftTarget
ListView {
id: list1
y: activeFocus ? 10 : 40; width: parent.width / 3; height: parent.height - 20
focus: true
- KeyNavigation.up: gridMenu; KeyNavigation.left: contextMenu; KeyNavigation.right: list2
+ KeyNavigation.up: menu.keyUpTarget
+ KeyNavigation.left: menu.keyLeftTarget
+ KeyNavigation.right: list2
model: 10; cacheBuffer: 200
delegate: ListViewDelegate {}
@@ -74,7 +75,9 @@ FocusScope {
ListView {
id: list2
y: activeFocus ? 10 : 40; x: parseInt(parent.width / 3); width: parent.width / 3; height: parent.height - 20
- KeyNavigation.up: gridMenu; KeyNavigation.left: list1; KeyNavigation.right: list3
+ KeyNavigation.up: menu.keyUpTarget
+ KeyNavigation.left: list1
+ KeyNavigation.right: list3
model: 10; cacheBuffer: 200
delegate: ListViewDelegate {}
@@ -86,7 +89,8 @@ FocusScope {
ListView {
id: list3
y: activeFocus ? 10 : 40; x: parseInt(2 * parent.width / 3); width: parent.width / 3; height: parent.height - 20
- KeyNavigation.up: gridMenu; KeyNavigation.left: list2
+ KeyNavigation.up: menu.keyUpTarget
+ KeyNavigation.left: list2
model: 10; cacheBuffer: 200
delegate: ListViewDelegate {}
diff --git a/examples/quick/keyinteraction/focus/Core/ListViewDelegate.qml b/examples/quick/keyinteraction/focus/Core/ListViewDelegate.qml
index b1dde9ddc5..5a2957eab0 100644
--- a/examples/quick/keyinteraction/focus/Core/ListViewDelegate.qml
+++ b/examples/quick/keyinteraction/focus/Core/ListViewDelegate.qml
@@ -52,6 +52,8 @@ import QtQuick 2.1
Item {
id: container
+ required property int index
+
width: ListView.view.width; height: 60; anchors.leftMargin: 10; anchors.rightMargin: 10
Rectangle {
@@ -67,7 +69,7 @@ Item {
Text {
id: label
anchors.centerIn: content
- text: "List element " + (index + 1)
+ text: "List element " + (container.index + 1)
color: "#193441"
font.pixelSize: 14
}
@@ -78,7 +80,7 @@ Item {
hoverEnabled: true
onClicked: {
- container.ListView.view.currentIndex = index
+ container.ListView.view.currentIndex = container.index
container.forceActiveFocus()
}
}
diff --git a/examples/quick/keyinteraction/focus/Core/TabMenu.qml b/examples/quick/keyinteraction/focus/Core/TabMenu.qml
index a40e070b2c..11b3d005c3 100644
--- a/examples/quick/keyinteraction/focus/Core/TabMenu.qml
+++ b/examples/quick/keyinteraction/focus/Core/TabMenu.qml
@@ -51,10 +51,9 @@
import QtQuick 2.1
FocusScope {
- onActiveFocusChanged: {
- if (activeFocus)
- mainView.state = "showTabViews"
- }
+ id: menu
+ required property Item keyUpTarget
+ required property Item keyDownTarget
Rectangle {
anchors.fill: parent
@@ -76,8 +75,8 @@ FocusScope {
activeFocusOnTab: true
focus: true
- KeyNavigation.up: listMenu
- KeyNavigation.down: gridMenu
+ KeyNavigation.up: menu.keyUpTarget
+ KeyNavigation.down: menu.keyDownTarget
Rectangle {
id: content
diff --git a/examples/quick/keyinteraction/focus/focus.qml b/examples/quick/keyinteraction/focus/focus.qml
index e07df57697..9db9ab48bc 100644
--- a/examples/quick/keyinteraction/focus/focus.qml
+++ b/examples/quick/keyinteraction/focus/focus.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.1
import QtQuick 2.1
import "Core"
@@ -67,20 +68,45 @@ Rectangle {
id: tabMenu
y: 160; width: parent.width; height: 160
+ keyUpTarget: listMenu
+ keyDownTarget: gridMenu
+
focus: true
activeFocusOnTab: true
+
+ onActiveFocusChanged: {
+ if (activeFocus)
+ mainView.state = "showTabViews"
+ }
}
GridMenu {
id: gridMenu
y: 320; width: parent.width; height: 320
activeFocusOnTab: true
+
+ keyUpTarget: tabMenu
+ keyDownTarget: listMenu
+ keyLeftTarget: contextMenu
+
+ onActiveFocusChanged: {
+ if (activeFocus)
+ mainView.state = "showGridViews"
+ }
}
ListMenu {
id: listMenu
y: 640; width: parent.width; height: 320
activeFocusOnTab: true
+
+ keyUpTarget: gridMenu
+ keyLeftTarget: contextMenu
+
+ onActiveFocusChanged: {
+ if (activeFocus)
+ mainView.state = "showListViews"
+ }
}
Rectangle {
@@ -129,7 +155,13 @@ Rectangle {
}
}
- ContextMenu { id: contextMenu; x: -265; width: 260; height: parent.height }
+ ContextMenu {
+ keyRightTarget: mainView
+ id: contextMenu
+ x: -265
+ width: 260
+ height: parent.height
+ }
states: State {
name: "contextMenuOpen"
diff --git a/examples/quick/layouts/layouts.qml b/examples/quick/layouts/layouts.qml
index 48299f36aa..e56fecade9 100644
--- a/examples/quick/layouts/layouts.qml
+++ b/examples/quick/layouts/layouts.qml
@@ -53,6 +53,8 @@ import QtQuick.Controls 1.2
import QtQuick.Layouts 1.3
ApplicationWindow {
+ id: appWindow
+
visible: true
title: "Basic layouts"
property int margin: 11
@@ -64,7 +66,7 @@ ApplicationWindow {
ColumnLayout {
id: mainLayout
anchors.fill: parent
- anchors.margins: margin
+ anchors.margins: appWindow.margin
GroupBox {
id: rowBox
title: "Row layout"
@@ -135,8 +137,13 @@ ApplicationWindow {
id: stackRepeater
model: 5
Rectangle {
- color: Qt.hsla((0.5 + index)/stackRepeater.count, 0.3, 0.7, 1)
- Button { anchors.centerIn: parent; text: "Page " + (index + 1); onClicked: { stackLayout.advance() } }
+ required property int index
+ color: Qt.hsla((0.5 + index) / stackRepeater.count, 0.3, 0.7, 1)
+ Button {
+ anchors.centerIn: parent
+ text: "Page " + (parent.index + 1)
+ onClicked: { stackLayout.advance() }
+ }
}
}
}
diff --git a/examples/quick/localstorage/localstorage/Header.qml b/examples/quick/localstorage/localstorage/Header.qml
index b3807f6e40..47879500a7 100644
--- a/examples/quick/localstorage/localstorage/Header.qml
+++ b/examples/quick/localstorage/localstorage/Header.qml
@@ -59,6 +59,9 @@ Item {
width: Screen.width / 2
height: Screen.height / 7
+ required property ListView listView
+ required property Text statusText
+
function insertrec() {
var rowid = parseInt(JS.dbInsert(dateInput.text, descInput.text, distInput.text), 10)
if (rowid) {
@@ -148,7 +151,7 @@ Item {
}
onEditingFinished: {
if (dateInput.text == "") {
- statustext.text = "Please fill in the date"
+ root.statusText.text = "Please fill in the date"
dateInput.forceActiveFocus()
}
}
@@ -161,10 +164,10 @@ Item {
activeFocusOnTab: true
onEditingFinished: {
if (descInput.text.length < 8) {
- statustext.text = "Enter a description of minimum 8 characters"
+ root.statusText.text = "Enter a description of minimum 8 characters"
descInput.forceActiveFocus()
} else {
- statustext.text = ""
+ root.statusText.text = ""
}
}
}
@@ -179,18 +182,18 @@ Item {
}
onEditingFinished: {
if (distInput.text == "") {
- statustext.text = "Please fill in the distance"
+ root.statusText.text = "Please fill in the distance"
distInput.forceActiveFocus()
}
}
}
}
}
-
- MouseArea {
- anchors.fill: parent
- onClicked: dateInput.forceActiveFocus()
- }
}
}
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: dateInput.forceActiveFocus()
+ }
}
diff --git a/examples/quick/localstorage/localstorage/MyDelegate.qml b/examples/quick/localstorage/localstorage/MyDelegate.qml
index 63a83bfbae..e8575d4f7a 100644
--- a/examples/quick/localstorage/localstorage/MyDelegate.qml
+++ b/examples/quick/localstorage/localstorage/MyDelegate.qml
@@ -54,18 +54,27 @@ import QtQuick.Layouts 1.1
import "Database.js" as JS
Item {
+ id: delegate
+
width: parent.width
height: rDate.implicitHeight
+ required property int index
+ required property int distance
+ required property string trip_desc
+ required property string date
+
+ signal clicked()
+
Rectangle {
id: baseRec
anchors.fill: parent
opacity: 0.8
- color: index % 2 ? "lightgrey" : "grey"
+ color: delegate.index % 2 ? "lightgrey" : "grey"
MouseArea {
anchors.fill: parent
- onClicked: listView.currentIndex = index
+ onClicked: delegate.clicked()
}
GridLayout {
anchors.fill:parent
@@ -73,21 +82,21 @@ Item {
Text {
id: rDate
- text: date
+ text: delegate.date
font.pixelSize: 22
Layout.preferredWidth: parent.width / 4
color: "black"
}
Text {
id: rDesc
- text: trip_desc
+ text: delegate.trip_desc
Layout.fillWidth: true
font.pixelSize: 22
color: "black"
}
Text {
id: rDistance
- text: distance
+ text: delegate.distance
font.pixelSize: 22
Layout.alignment: Qt.AlignRight
color: "black"
diff --git a/examples/quick/localstorage/localstorage/localstorage.qml b/examples/quick/localstorage/localstorage/localstorage.qml
index 434639db54..418aab838e 100644
--- a/examples/quick/localstorage/localstorage/localstorage.qml
+++ b/examples/quick/localstorage/localstorage/localstorage.qml
@@ -55,6 +55,7 @@ import QtQuick.LocalStorage 2.0
import "Database.js" as JS
Window {
+ id: window
visible: true
width: Screen.width / 2
height: Screen.height / 1.8
@@ -72,19 +73,21 @@ Window {
Header {
id: input
Layout.fillWidth: true
+ listView: listView
+ statusText: statustext
}
RowLayout {
MyButton {
text: "New"
onClicked: {
input.initrec_new()
- creatingNewEntry = true
+ window.creatingNewEntry = true
listView.model.setProperty(listView.currentIndex, "id", 0)
}
}
MyButton {
id: saveButton
- enabled: (creatingNewEntry || editingEntry) && listView.currentIndex != -1
+ enabled: (window.creatingNewEntry || window.editingEntry) && listView.currentIndex != -1
text: "Save"
onClicked: {
var insertedRow = false;
@@ -109,8 +112,8 @@ Window {
if (insertedRow) {
input.initrec()
- creatingNewEntry = false
- editingEntry = false
+ window.creatingNewEntry = false
+ window.editingEntry = false
listView.forceLayout()
}
}
@@ -118,20 +121,20 @@ Window {
MyButton {
id: editButton
text: "Edit"
- enabled: !creatingNewEntry && !editingEntry && listView.currentIndex != -1
+ enabled: !window.creatingNewEntry && !window.editingEntry && listView.currentIndex != -1
onClicked: {
input.editrec(listView.model.get(listView.currentIndex).date,
listView.model.get(listView.currentIndex).trip_desc,
listView.model.get(listView.currentIndex).distance,
listView.model.get(listView.currentIndex).id)
- editingEntry = true
+ window.editingEntry = true
}
}
MyButton {
id: deleteButton
text: "Delete"
- enabled: !creatingNewEntry && listView.currentIndex != -1
+ enabled: !window.creatingNewEntry && listView.currentIndex != -1
onClicked: {
JS.dbDeleteRow(listView.model.get(listView.currentIndex).id)
listView.model.remove(listView.currentIndex, 1)
@@ -145,7 +148,7 @@ Window {
MyButton {
id: cancelButton
text: "Cancel"
- enabled: (creatingNewEntry || editingEntry) && listView.currentIndex != -1
+ enabled: (window.creatingNewEntry || window.editingEntry) && listView.currentIndex != -1
onClicked: {
if (listView.model.get(listView.currentIndex).id === 0) {
// This entry had an id of 0, which means it was being created and hadn't
@@ -153,8 +156,8 @@ Window {
listView.model.remove(listView.currentIndex, 1)
}
listView.forceLayout()
- creatingNewEntry = false
- editingEntry = false
+ window.creatingNewEntry = false
+ window.editingEntry = false
input.initrec()
}
}
@@ -166,8 +169,8 @@ Window {
Component {
id: highlightBar
Rectangle {
- width: listView.currentItem.width
- height: listView.currentItem.height
+ width: listView.currentItem !== null ? listView.currentItem.width : implicitWidth
+ height: listView.currentItem !== null ? listView.currentItem.height : implicitHeight
color: "lightgreen"
}
}
@@ -176,9 +179,11 @@ Window {
Layout.fillWidth: true
Layout.fillHeight: true
model: MyModel {}
- delegate: MyDelegate {}
+ delegate: MyDelegate {
+ onClicked: listView.currentIndex = index
+ }
// Don't allow changing the currentIndex while the user is creating/editing values.
- enabled: !creatingNewEntry && !editingEntry
+ enabled: !window.creatingNewEntry && !window.editingEntry
highlight: highlightBar
highlightFollowsCurrentItem: true
diff --git a/examples/quick/models/abstractitemmodel/main.cpp b/examples/quick/models/abstractitemmodel/main.cpp
index 515f47ec30..dd5b368c6b 100644
--- a/examples/quick/models/abstractitemmodel/main.cpp
+++ b/examples/quick/models/abstractitemmodel/main.cpp
@@ -68,10 +68,8 @@ int main(int argc, char ** argv)
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- QQmlContext *ctxt = view.rootContext();
- ctxt->setContextProperty("myModel", &model);
+ view.setInitialProperties({{"model", QVariant::fromValue(&model)}});
//![0]
-
view.setSource(QUrl("qrc:view.qml"));
view.show();
diff --git a/examples/quick/models/abstractitemmodel/view.qml b/examples/quick/models/abstractitemmodel/view.qml
index f699aa40c8..2b9f87df92 100644
--- a/examples/quick/models/abstractitemmodel/view.qml
+++ b/examples/quick/models/abstractitemmodel/view.qml
@@ -53,8 +53,14 @@ import QtQuick 2.0
ListView {
width: 200; height: 250
- model: myModel
- delegate: Text { text: "Animal: " + type + ", " + size }
+ required model
+
+ delegate: Text {
+ required property string type
+ required property string size
+
+ text: "Animal: " + type + ", " + size
+ }
}
//![0]
diff --git a/examples/quick/models/objectlistmodel/main.cpp b/examples/quick/models/objectlistmodel/main.cpp
index 977bbfb93b..1418af90ca 100644
--- a/examples/quick/models/objectlistmodel/main.cpp
+++ b/examples/quick/models/objectlistmodel/main.cpp
@@ -66,18 +66,19 @@
//![0]
int main(int argc, char ** argv)
{
+ QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
- QList<QObject*> dataList;
- dataList.append(new DataObject("Item 1", "red"));
- dataList.append(new DataObject("Item 2", "green"));
- dataList.append(new DataObject("Item 3", "blue"));
- dataList.append(new DataObject("Item 4", "yellow"));
+ QList<QObject *> dataList = {
+ new DataObject("Item 1", "red"),
+ new DataObject("Item 2", "green"),
+ new DataObject("Item 3", "blue"),
+ new DataObject("Item 4", "yellow")
+ };
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
- QQmlContext *ctxt = view.rootContext();
- ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
+ view.setInitialProperties({{ "model", QVariant::fromValue(dataList) }});
//![0]
view.setSource(QUrl("qrc:view.qml"));
diff --git a/examples/quick/models/objectlistmodel/view.qml b/examples/quick/models/objectlistmodel/view.qml
index d9a32aff14..ba0c905e1e 100644
--- a/examples/quick/models/objectlistmodel/view.qml
+++ b/examples/quick/models/objectlistmodel/view.qml
@@ -53,13 +53,15 @@ import QtQuick 2.0
//![0]
ListView {
width: 100; height: 100
+ required model
- model: myModel
delegate: Rectangle {
+ required color
+ required property string name
+
height: 25
width: 100
- color: model.modelData.color
- Text { text: name }
+ Text { text: parent.name }
}
}
//![0]
diff --git a/examples/quick/models/stringlistmodel/main.cpp b/examples/quick/models/stringlistmodel/main.cpp
index 6b4db422a6..d9de69b3aa 100644
--- a/examples/quick/models/stringlistmodel/main.cpp
+++ b/examples/quick/models/stringlistmodel/main.cpp
@@ -68,15 +68,15 @@ int main(int argc, char ** argv)
QGuiApplication app(argc, argv);
//![0]
- QStringList dataList;
- dataList.append("Item 1");
- dataList.append("Item 2");
- dataList.append("Item 3");
- dataList.append("Item 4");
+ QStringList dataList = {
+ "Item 1",
+ "Item 2",
+ "Item 3",
+ "Item 4"
+ };
QQuickView view;
- QQmlContext *ctxt = view.rootContext();
- ctxt->setContextProperty("myModel", QVariant::fromValue(dataList));
+ view.setInitialProperties({{ "model", QVariant::fromValue(dataList) }});
//![0]
view.setSource(QUrl("qrc:view.qml"));
diff --git a/examples/quick/models/stringlistmodel/view.qml b/examples/quick/models/stringlistmodel/view.qml
index f74b7db1c1..e392284d0f 100644
--- a/examples/quick/models/stringlistmodel/view.qml
+++ b/examples/quick/models/stringlistmodel/view.qml
@@ -52,13 +52,15 @@ import QtQuick 2.0
//![0]
ListView {
- width: 100; height: 100
+ width: 100
+ height: 100
+ required model
- model: myModel
delegate: Rectangle {
+ required property string modelData
height: 25
width: 100
- Text { text: modelData }
+ Text { text: parent.modelData }
}
}
//![0]
diff --git a/examples/quick/mousearea/mousearea-wheel-example.qml b/examples/quick/mousearea/mousearea-wheel-example.qml
index 44b9216285..5e8fba3ac3 100644
--- a/examples/quick/mousearea/mousearea-wheel-example.qml
+++ b/examples/quick/mousearea/mousearea-wheel-example.qml
@@ -63,6 +63,8 @@ Rectangle {
model: ["#9ACD32", "#EEEEEE", "#FFD700", "#87CEEB"]
Rectangle {
+ required property color modelData
+
property real scaleFactor: 1
height: 40 * scaleFactor
diff --git a/examples/quick/mousearea/mousearea.qml b/examples/quick/mousearea/mousearea.qml
index 1540d85fdd..cecbc2cfc8 100644
--- a/examples/quick/mousearea/mousearea.qml
+++ b/examples/quick/mousearea/mousearea.qml
@@ -76,7 +76,7 @@ Rectangle {
onEntered: info.text = 'Entered'
onExited: info.text = 'Exited (pressed=' + pressed + ')'
- onPressed: {
+ onPressed: (mouse) => {
if (mouse.button == Qt.LeftButton)
buttonID = 'LeftButton'
else if (mouse.button == Qt.RightButton)
@@ -139,14 +139,14 @@ Rectangle {
+ ' (' + posInBox.x + ',' + posInBox.y + ' in window)'
}
- onReleased: {
+ onReleased: (mouse) => {
btn.text = 'Released (isClick=' + mouse.isClick + ' wasHeld=' + mouse.wasHeld + ')'
posInfo.text = ''
}
//! [clicks]
onPressAndHold: btn.text = 'Press and hold'
- onClicked: btn.text = 'Clicked (wasHeld=' + mouse.wasHeld + ')'
+ onClicked: (mouse) => { btn.text = 'Clicked (wasHeld=' + mouse.wasHeld + ')' }
onDoubleClicked: btn.text = 'Double clicked'
//! [clicks]
}
diff --git a/examples/quick/particles/affectors/content/customaffector.qml b/examples/quick/particles/affectors/content/customaffector.qml
index 71646bcf39..6fabfb3ab2 100644
--- a/examples/quick/particles/affectors/content/customaffector.qml
+++ b/examples/quick/particles/affectors/content/customaffector.qml
@@ -81,7 +81,7 @@ Item {
property real velocity: 1.5
width: parent.width
height: parent.height - 100
- onAffectParticles: {
+ onAffectParticles: (particles, dt) => {
/* //Linear movement
if (particle.r == 0) {
particle.r = Math.random() > 0.5 ? -1 : 1;
@@ -117,7 +117,7 @@ Item {
width: parent.width + 120
height: 100
anchors.bottom: parent.bottom
- onAffectParticles: {
+ onAffectParticles: (particles, dt) => {
for (var i=0; i<particles.length; i++) {
var particle = particles[i];
var pseudoRand = (Math.floor(particle.t*1327) % 10) + 1;
diff --git a/examples/quick/particles/affectors/content/groupgoal.qml b/examples/quick/particles/affectors/content/groupgoal.qml
index 6472a3b450..9910531a98 100644
--- a/examples/quick/particles/affectors/content/groupgoal.qml
+++ b/examples/quick/particles/affectors/content/groupgoal.qml
@@ -62,7 +62,7 @@ Rectangle {
Text {
color: "white"
anchors.right: parent.right
- text: score
+ text: root.score
}
ParticleSystem {
@@ -96,7 +96,7 @@ Rectangle {
ParticleGroup {
name: "lit"
duration: 10000
- onEntered: score++;
+ onEntered: root.score++
TrailEmitter {
id: fireballFlame
group: "flame"
diff --git a/examples/quick/particles/emitters/content/burstandpulse.qml b/examples/quick/particles/emitters/content/burstandpulse.qml
index 8bd19ed8ed..d3c38c2360 100644
--- a/examples/quick/particles/emitters/content/burstandpulse.qml
+++ b/examples/quick/particles/emitters/content/burstandpulse.qml
@@ -52,6 +52,8 @@ import QtQuick 2.0
import QtQuick.Particles 2.0
Rectangle {
+ id: root
+
width: 320
height: 480
color: "black"
@@ -63,12 +65,12 @@ Rectangle {
repeat: true
onTriggered: {
//! [0]
- if (lastWasPulse) {
+ if (root.lastWasPulse) {
burstEmitter.burst(500);
- lastWasPulse = false;
+ root.lastWasPulse = false;
} else {
pulseEmitter.pulse(500);
- lastWasPulse = true;
+ root.lastWasPulse = true;
}
//! [0]
}
diff --git a/examples/quick/particles/emitters/content/customemitter.qml b/examples/quick/particles/emitters/content/customemitter.qml
index aa8ca6b2f9..f6aea13d08 100644
--- a/examples/quick/particles/emitters/content/customemitter.qml
+++ b/examples/quick/particles/emitters/content/customemitter.qml
@@ -79,7 +79,7 @@ ParticleSystem {
size: 12
anchors.centerIn: parent
//! [0]
- onEmitParticles: {
+ onEmitParticles: (particles) => {
for (var i=0; i<particles.length; i++) {
var particle = particles[i];
particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24));
@@ -90,8 +90,8 @@ ParticleSystem {
theta /= 6.0;
theta *= 2.0*Math.PI;
theta += sys.convert(sys.petalRotation);//Convert from degrees to radians
- particle.initialVX = petalLength * Math.cos(theta);
- particle.initialVY = petalLength * Math.sin(theta);
+ particle.initialVX = sys.petalLength * Math.cos(theta);
+ particle.initialVY = sys.petalLength * Math.sin(theta);
particle.initialAX = particle.initialVX * -0.5;
particle.initialAY = particle.initialVY * -0.5;
}
diff --git a/examples/quick/particles/imageparticle/content/sharing.qml b/examples/quick/particles/imageparticle/content/sharing.qml
index 1018a8e8ba..13b0dadf85 100644
--- a/examples/quick/particles/imageparticle/content/sharing.qml
+++ b/examples/quick/particles/imageparticle/content/sharing.qml
@@ -56,6 +56,8 @@ import QtQuick 2.0
import QtQuick.Particles 2.0
Rectangle {
+ id: root
+
property real delegateHeight: 65
width: 200; height: 300
gradient: Gradient {
@@ -65,53 +67,53 @@ Rectangle {
// Define a delegate component. A component will be
// instantiated for each visible item in the list.
- Component {
- id: petDelegate
- Item {
- id: wrapper
- width: 200; height: delegateHeight
- z: 10
- Column {
- Text {color: "white"; text: name; font.pixelSize: 18 }
- Text {color: "white"; text: 'Type: ' + type; font.pixelSize: 14 }
- Text {color: "white"; text: 'Age: ' + age; font.pixelSize: 14 }
- }
- MouseArea { anchors.fill: parent; onClicked: listView.currentIndex = index; }
- // indent the item if it is the current item
- states: State {
- name: "Current"
- when: wrapper.ListView.isCurrentItem
- PropertyChanges { target: wrapper; x: 20 }
- }
- transitions: Transition {
- NumberAnimation { properties: "x"; duration: 200 }
- }
+ component PetDelegate: Item {
+ id: pet
+ width: 200; height: root.delegateHeight
+ z: 10
+
+ required property int index
+ required property string name
+ required property string type
+ required property int age
+
+ Column {
+ Text {color: "white"; text: pet.name; font.pixelSize: 18 }
+ Text {color: "white"; text: 'Type: ' + pet.type; font.pixelSize: 14 }
+ Text {color: "white"; text: 'Age: ' + pet.age; font.pixelSize: 14 }
+ }
+ MouseArea { anchors.fill: parent; onClicked: listView.currentIndex = pet.index; }
+ // indent the item if it is the current item
+ states: State {
+ name: "Current"
+ when: pet.ListView.isCurrentItem
+ PropertyChanges { target: pet; x: 20 }
+ }
+ transitions: Transition {
+ NumberAnimation { properties: "x"; duration: 200 }
}
}
// Define a highlight with customized movement between items.
- Component {
- id: highlightBar
- Rectangle {
- z: 0
- width: 200; height: delegateHeight
- gradient: Gradient {
- GradientStop { position: 0.0; color: "#99FF99" }
- GradientStop { position: 1.0; color: "#88FF88" }
- }
- y: listView.currentItem.y;
- Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }
- //! [1]
- ImageParticle {
- anchors.fill: parent
- system: particles
- source: "../../images/flower.png"
- color: "red"
- clip: true
- alpha: 1.0
- }
- //! [1]
+ component HighlightBar : Rectangle {
+ z: 0
+ width: 200; height: root.delegateHeight
+ gradient: Gradient {
+ GradientStop { position: 0.0; color: "#99FF99" }
+ GradientStop { position: 1.0; color: "#88FF88" }
+ }
+ y: listView.currentItem.y;
+ Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }
+ //! [1]
+ ImageParticle {
+ anchors.fill: parent
+ system: particles
+ source: "../../images/flower.png"
+ color: "red"
+ clip: true
+ alpha: 1.0
}
+ //! [1]
}
ListView {
@@ -119,12 +121,12 @@ Rectangle {
width: 200; height: parent.height
model: petsModel
- delegate: petDelegate
+ delegate: PetDelegate {}
focus: true
// Set the highlight delegate. Note we must also set highlightFollowsCurrentItem
// to false so the highlight delegate can control how the highlight is moved.
- highlight: highlightBar
+ highlight: HighlightBar {}
highlightFollowsCurrentItem: false
ParticleSystem { id: particles }
diff --git a/examples/quick/particles/itemparticle/particleview.qml b/examples/quick/particles/itemparticle/particleview.qml
index 3b412e37e5..8eb18dc283 100644
--- a/examples/quick/particles/itemparticle/particleview.qml
+++ b/examples/quick/particles/itemparticle/particleview.qml
@@ -156,7 +156,7 @@ Item {
interval: 800
onTriggered: {
force.enabled = false;
- mp.take(alertItem, true);
+ mp.take(root.alertItem, true);
centerEmitter.burst(1);
}
}
@@ -216,6 +216,11 @@ Item {
Component {
id: theDelegate
Image {
+ required property int index
+ required property string title
+ required property string media
+ required property string thumbnail
+
id: image
antialiasing: true;
source: thumbnail
@@ -237,7 +242,7 @@ Item {
width: parent.paintedWidth + 1
height: parent.paintedHeight + 1
color: "black"
- opacity: darken * (1 - depth)
+ opacity: image.darken * (1 - image.depth)
antialiasing: true;
}
Text {
@@ -247,7 +252,7 @@ Item {
width: parent.paintedWidth - 4
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
- text: title
+ text: image.title
color: "black"
}
ItemParticle.onDetached: mp.take(image); // respawns
@@ -277,7 +282,7 @@ Item {
}
PropertyChanges {
target: image
- source: media
+ source: image.media
x: 0
y: 0
width: root.width
diff --git a/examples/quick/positioners/positioners-transitions.qml b/examples/quick/positioners/positioners-transitions.qml
index fbaa05c81c..d4f3772c4e 100644
--- a/examples/quick/positioners/positioners-transitions.qml
+++ b/examples/quick/positioners/positioners-transitions.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
Item {
@@ -215,9 +216,9 @@ Item {
opacity: page.effectiveOpacity
}
- Rectangle { color: "#80c342"; width:page. smallSize; height: page.smallSize }
- Rectangle { color: "#14aaff"; width: smallSize; height: page.smallSize }
- Rectangle { color: "#6400aa"; width: page.page.smallSize; height: page.smallSize }
+ Rectangle { color: "#80c342"; width: page.smallSize; height: page.smallSize }
+ Rectangle { color: "#14aaff"; width: page.smallSize; height: page.smallSize }
+ Rectangle { color: "#6400aa"; width: page.smallSize; height: page.smallSize }
}
Flow {
diff --git a/examples/quick/quick-accessibility/content/Button.qml b/examples/quick/quick-accessibility/content/Button.qml
index fc9c19b789..7a86e31588 100644
--- a/examples/quick/quick-accessibility/content/Button.qml
+++ b/examples/quick/quick-accessibility/content/Button.qml
@@ -79,7 +79,6 @@ Rectangle {
Text {
id: buttonText
- text: parent.description
anchors.centerIn: parent
font.pixelSize: parent.height * .5
style: Text.Sunken
diff --git a/examples/quick/quick-accessibility/content/Slider.qml b/examples/quick/quick-accessibility/content/Slider.qml
index aa425797a7..241e5d804e 100644
--- a/examples/quick/quick-accessibility/content/Slider.qml
+++ b/examples/quick/quick-accessibility/content/Slider.qml
@@ -72,7 +72,7 @@ Rectangle {
x: 1
y: 1
height: parent.height - 2
- width: ((parent.width - 2) / maximumValue) * value
+ width: ((parent.width - 2) / slider.maximumValue) * slider.value
color: "lightgrey"
Behavior on width {
NumberAnimation { duration: 50 }
@@ -88,8 +88,9 @@ Rectangle {
MouseArea {
anchors.fill: parent
- onClicked: {
- var pos = mouse.x / slider.width * (maximumValue - minimumValue) + minimumValue
+ onClicked: (mouse) => {
+ var pos = mouse.x / slider.width * (slider.maximumValue - slider.minimumValue)
+ + slider.minimumValue
slider.value = pos
}
}
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h
index 3a4c5a13c2..6270e7adff 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h
+++ b/examples/quick/quickwidgets/qquickviewcomparison/fbitem.h
@@ -111,6 +111,7 @@ class FbItem : public QQuickFramebufferObject
Q_PROPERTY(QVector3D target READ target WRITE setTarget)
Q_PROPERTY(QVector3D rotation READ rotation WRITE setRotation)
Q_PROPERTY(bool multisample READ multisample WRITE setMultisample)
+ QML_ELEMENT
public:
explicit FbItem(QQuickItem *parent = 0);
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
index 84e116dce6..850ecd147b 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
+++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp
@@ -86,8 +86,6 @@ MainWindow::MainWindow(bool transparency, bool noRenderAlpha)
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);
diff --git a/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro
index 80216da346..7809c20b3a 100644
--- a/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro
+++ b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro
@@ -1,6 +1,10 @@
TEMPLATE = app
TARGET = qquickviewcomparison
+CONFIG += qmltypes
+QML_IMPORT_NAME = fbitem
+QML_IMPORT_MAJOR_VERSION = 1
+
QT += quick widgets quickwidgets
SOURCES += main.cpp \
diff --git a/examples/quick/quickwidgets/quickwidget/fbitem.h b/examples/quick/quickwidgets/quickwidget/fbitem.h
index 7beb9874a5..c1fb866c9a 100644
--- a/examples/quick/quickwidgets/quickwidget/fbitem.h
+++ b/examples/quick/quickwidgets/quickwidget/fbitem.h
@@ -56,6 +56,7 @@
class FbItem : public QQuickFramebufferObject
{
Q_OBJECT
+ QML_ELEMENT
public:
Renderer *createRenderer() const;
};
diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp
index c54586c5de..f28b2f1443 100644
--- a/examples/quick/quickwidgets/quickwidget/main.cpp
+++ b/examples/quick/quickwidgets/quickwidget/main.cpp
@@ -214,8 +214,6 @@ int main(int argc, char **argv)
optMultipleSample = parser.isSet(multipleSampleOption);
optCoreProfile = parser.isSet(coreProfileOption);
- qmlRegisterType<FbItem>("QuickWidgetExample", 1, 0, "FbItem");
-
MainWindow mainWindow;
mainWindow.show();
diff --git a/examples/quick/quickwidgets/quickwidget/quickwidget.pro b/examples/quick/quickwidgets/quickwidget/quickwidget.pro
index 5be006f7fa..b824c520f5 100644
--- a/examples/quick/quickwidgets/quickwidget/quickwidget.pro
+++ b/examples/quick/quickwidgets/quickwidget/quickwidget.pro
@@ -3,6 +3,10 @@ QT += core gui quick widgets quickwidgets
TARGET = quickwidget
TEMPLATE = app
+CONFIG += qmltypes
+QML_IMPORT_NAME = QuickWidgetExample
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += main.cpp fbitem.cpp
HEADERS += fbitem.h
diff --git a/examples/quick/righttoleft/layoutdirection/layoutdirection.qml b/examples/quick/righttoleft/layoutdirection/layoutdirection.qml
index 4e3e93852c..de111ea025 100644
--- a/examples/quick/righttoleft/layoutdirection/layoutdirection.qml
+++ b/examples/quick/righttoleft/layoutdirection/layoutdirection.qml
@@ -84,8 +84,8 @@ Rectangle {
Repeater {
model: 3
Loader {
- property int value: index
- sourceComponent: positionerDelegate
+ required property int index
+ sourceComponent: PositionerDelegate {}
}
}
}
@@ -106,8 +106,8 @@ Rectangle {
Repeater {
model: 8
Loader {
- property int value: index
- sourceComponent: positionerDelegate
+ required property int index
+ sourceComponent: PositionerDelegate {}
}
}
}
@@ -128,8 +128,8 @@ Rectangle {
Repeater {
model: 8
Loader {
- property int value: index
- sourceComponent: positionerDelegate
+ required property int index
+ sourceComponent: PositionerDelegate {}
}
}
}
@@ -152,7 +152,7 @@ Rectangle {
layoutDirection: root.direction
orientation: Qt.Horizontal
model: 48
- delegate: viewDelegate
+ delegate: ViewDelegate {}
}
Text {
@@ -166,7 +166,7 @@ Rectangle {
cellWidth: 50; cellHeight: 50
layoutDirection: root.direction
model: 48
- delegate: viewDelegate
+ delegate: ViewDelegate {}
}
Rectangle {
@@ -230,37 +230,36 @@ Rectangle {
}
}
- Component {
- id: positionerDelegate
+ component PositionerDelegate : Rectangle {
+ width: 40
+ height: 40
+ property int lightness: parent.index + 1;
+ color: Qt.rgba(0.8 / lightness, 0.8 / lightness, 0.8 / lightness, 1.0)
+ Text {
+ text: parent.lightness
+ color: "white"
+ font.pixelSize: 18
+ anchors.centerIn: parent
+ }
+ }
+
+ component ViewDelegate : Item {
+ id: delegateItem
+ required property int index
+ width: (listView.effectiveLayoutDirection == Qt.LeftToRight ? (index == 48 - 1) : (index == 0)) ? 40 : 50
Rectangle {
width: 40; height: 40
- color: Qt.rgba(0.8/(parent.value+1),0.8/(parent.value+1),0.8/(parent.value+1),1.0)
+ color: Qt.rgba(0.5 + (48 - delegateItem.index) * Math.random() / 48,
+ 0.3 + delegateItem.index * Math.random() / 48,
+ 0.3 * Math.random(),
+ 1.0)
Text {
- text: parent.parent.value+1
+ text: delegateItem.index + 1
color: "white"
font.pixelSize: 18
anchors.centerIn: parent
}
}
}
- Component {
- id: viewDelegate
- Item {
- width: (listView.effectiveLayoutDirection == Qt.LeftToRight ? (index == 48 - 1) : (index == 0)) ? 40 : 50
- Rectangle {
- width: 40; height: 40
- color: Qt.rgba(0.5+(48 - index)*Math.random()/48,
- 0.3+index*Math.random()/48,
- 0.3*Math.random(),
- 1.0)
- Text {
- text: index+1
- color: "white"
- font.pixelSize: 18
- anchors.centerIn: parent
- }
- }
- }
- }
}
diff --git a/examples/quick/righttoleft/textalignment/textalignment.qml b/examples/quick/righttoleft/textalignment/textalignment.qml
index c5790027f2..698917a3c0 100644
--- a/examples/quick/righttoleft/textalignment/textalignment.qml
+++ b/examples/quick/righttoleft/textalignment/textalignment.qml
@@ -93,18 +93,23 @@ Rectangle {
width: 320
height: 320
id: editorTypeRow
- model: editorType.length
+ model: root.editorType.length
orientation: ListView.Horizontal
cacheBuffer: 1000//Load the really expensive ones async if possible
delegate: Item {
+ id: delegate
+
width: editorColumn.width
height: editorColumn.height
+
+ required property int index
+
Column {
id: editorColumn
spacing: 5
width: textColumn.width+10
Text {
- text: root.editorType[index]
+ text: root.editorType[delegate.index]
font.pixelSize: 16
anchors.horizontalCenter: parent.horizontalCenter
}
@@ -113,8 +118,8 @@ Rectangle {
spacing: 5
anchors.horizontalCenter: parent.horizontalCenter
Repeater {
- model: textComponents.length
- delegate: textComponents[index]
+ model: root.textComponents.length
+ delegate: root.textComponents[delegate.index]
}
}
}
@@ -203,9 +208,11 @@ Rectangle {
Component {
id: plainTextComponent
Text {
+ required property int index
+
width: 180
text: root.text[index]
- font.pixelSize: pxSz
+ font.pixelSize: root.pxSz
wrapMode: Text.WordWrap
horizontalAlignment: root.horizontalAlignment
LayoutMirroring.enabled: root.mirror
@@ -216,10 +223,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[parent.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -228,7 +235,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
@@ -237,9 +244,11 @@ Rectangle {
Component {
id: styledTextComponent
Text {
+ required property int index
+
width: 180
text: root.text[index]
- font.pixelSize: pxSz
+ font.pixelSize: root.pxSz
wrapMode: Text.WordWrap
horizontalAlignment: root.horizontalAlignment
LayoutMirroring.enabled: root.mirror
@@ -252,10 +261,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[parent.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -264,7 +273,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
@@ -273,9 +282,11 @@ Rectangle {
Component {
id: richTextComponent
Text {
+ required property int index
+
width: 180
text: root.text[index]
- font.pixelSize: pxSz
+ font.pixelSize: root.pxSz
wrapMode: Text.WordWrap
horizontalAlignment: root.horizontalAlignment
LayoutMirroring.enabled: root.mirror
@@ -286,10 +297,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[parent.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -298,7 +309,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
@@ -307,9 +318,11 @@ Rectangle {
Component {
id: italicRichTextComponent
Text {
+ required property int index
+
width: 180
text: "<i>" + root.text[index] + "</i>"
- font.pixelSize: pxSz
+ font.pixelSize: root.pxSz
wrapMode: Text.WordWrap
horizontalAlignment: root.horizontalAlignment
LayoutMirroring.enabled: root.mirror
@@ -321,10 +334,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[parent.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -333,7 +346,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
@@ -342,9 +355,11 @@ Rectangle {
Component {
id: plainTextEdit
TextEdit {
+ required property int index
+
width: 180
text: root.text[index]
- font.pixelSize: pxSz
+ font.pixelSize: root.pxSz
cursorVisible: true
wrapMode: TextEdit.WordWrap
horizontalAlignment: root.horizontalAlignment
@@ -355,10 +370,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[parent.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -367,7 +382,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
@@ -376,9 +391,11 @@ Rectangle {
Component {
id: italicTextEdit
TextEdit {
+ required property int index
+
width: 180
text: "<i>" + root.text[index] + "<i>"
- font.pixelSize: pxSz
+ font.pixelSize: root.pxSz
cursorVisible: true
wrapMode: TextEdit.WordWrap
textFormat: TextEdit.RichText
@@ -390,10 +407,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[parent.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -402,7 +419,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
@@ -411,13 +428,15 @@ Rectangle {
Component {
id: textInput
Item {
+ id: textDelegate
+ required property int index
width: 180
height: textInput.text.length > 20 ? 3*textInput.height : textInput.height
TextInput {
id: textInput
width: 180
- text: root.text[index]
- font.pixelSize: pxSz
+ text: root.text[textDelegate.index]
+ font.pixelSize: root.pxSz
cursorVisible: true
horizontalAlignment: root.horizontalAlignment
LayoutMirroring.enabled: root.mirror
@@ -427,10 +446,10 @@ Rectangle {
anchors.fill: parent
}
Text {
- text: root.description[index]
+ text: root.description[textDelegate.index]
color: Qt.rgba(1,1,1,1.0)
anchors.centerIn: parent
- font.pixelSize: pxSz - 2
+ font.pixelSize: root.pxSz - 2
Rectangle {
z: -1
color: Qt.rgba(0.3, 0, 0, 0.3)
@@ -439,7 +458,7 @@ Rectangle {
}
Text {
color: "white"
- text: shortText(parent.horizontalAlignment)
+ text: root.shortText(parent.horizontalAlignment)
anchors { top: parent.top; right: parent.right; margins: 2 }
}
}
diff --git a/examples/quick/scenegraph/customgeometry/beziercurve.h b/examples/quick/scenegraph/customgeometry/beziercurve.h
index f2f7832e6d..fd0085a08e 100644
--- a/examples/quick/scenegraph/customgeometry/beziercurve.h
+++ b/examples/quick/scenegraph/customgeometry/beziercurve.h
@@ -64,6 +64,9 @@ class BezierCurve : public QQuickItem
Q_PROPERTY(QPointF p4 READ p4 WRITE setP4 NOTIFY p4Changed)
Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
+//! [3]
+ QML_ELEMENT
+//! [3]
public:
BezierCurve(QQuickItem *parent = 0);
diff --git a/examples/quick/scenegraph/customgeometry/customgeometry.pro b/examples/quick/scenegraph/customgeometry/customgeometry.pro
index 17c30fc560..3785f88c7e 100644
--- a/examples/quick/scenegraph/customgeometry/customgeometry.pro
+++ b/examples/quick/scenegraph/customgeometry/customgeometry.pro
@@ -1,6 +1,10 @@
TARGET = customgeometry
QT += quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = CustomGeometry
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += \
main.cpp \
beziercurve.cpp
diff --git a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
index 959114b424..bd235e5dfb 100644
--- a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
+++ b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc
@@ -169,11 +169,16 @@
\snippet scenegraph/customgeometry/main.cpp 1
The application is a straightforward QML application, with a
- QGuiApplication and a QQuickView that we pass a .qml file. To make
- use of the BezierCurve item, we need to register it in the QML
- engine, using the qmlRegisterType() function. We give it the name
- BezierCurve and make it part of the \c {CustomGeometry 1.0}
- module.
+ QGuiApplication and a QQuickView that we pass a .qml file.
+
+ \snippet scenegraph/customgeometry/beziercurve.h 3
+
+ To make use of the BezierCurve item, we need to register it in the QML
+ engine, using the QML_ELEMENT macro. This gives it the name
+ BezierCurve and makes it part of the \c {CustomGeometry 1.0}
+ module as defined in the customgeometry.pro file:
+
+ \quotefile scenegraph/customgeometry/customgeometry.pro
As the bezier curve is drawn using GL_LINE_STRIP, we specify that
the view should be multisampled to get antialiasing. This is not
diff --git a/examples/quick/scenegraph/customgeometry/main.cpp b/examples/quick/scenegraph/customgeometry/main.cpp
index 6f3c24e87b..0b9b2eb3f9 100644
--- a/examples/quick/scenegraph/customgeometry/main.cpp
+++ b/examples/quick/scenegraph/customgeometry/main.cpp
@@ -56,10 +56,9 @@
//! [1]
int main(int argc, char **argv)
{
+ QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
- qmlRegisterType<BezierCurve>("CustomGeometry", 1, 0, "BezierCurve");
-
QQuickView view;
QSurfaceFormat format = view.format();
format.setSamples(16);
diff --git a/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp b/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp
index f05bf2f843..5737e419b0 100644
--- a/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp
+++ b/examples/quick/scenegraph/d3d11underqml/d3d11squircle.cpp
@@ -49,6 +49,7 @@
****************************************************************************/
#include "d3d11squircle.h"
+#include <QtCore/QFile>
#include <QtCore/QRunnable>
#include <QtQuick/QQuickWindow>
diff --git a/examples/quick/scenegraph/d3d11underqml/d3d11squircle.h b/examples/quick/scenegraph/d3d11underqml/d3d11squircle.h
index be9aadc43b..4be3671d1c 100644
--- a/examples/quick/scenegraph/d3d11underqml/d3d11squircle.h
+++ b/examples/quick/scenegraph/d3d11underqml/d3d11squircle.h
@@ -59,6 +59,7 @@ class D3D11Squircle : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+ QML_ELEMENT
public:
D3D11Squircle();
diff --git a/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro b/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro
index 7658a9a813..4f052cf388 100644
--- a/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro
+++ b/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro
@@ -2,6 +2,10 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = D3D11UnderQML
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += d3d11squircle.h
SOURCES += d3d11squircle.cpp main.cpp
RESOURCES += d3d11underqml.qrc
diff --git a/examples/quick/scenegraph/d3d11underqml/main.cpp b/examples/quick/scenegraph/d3d11underqml/main.cpp
index d26de1144a..bcefae6cb5 100644
--- a/examples/quick/scenegraph/d3d11underqml/main.cpp
+++ b/examples/quick/scenegraph/d3d11underqml/main.cpp
@@ -56,8 +56,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<D3D11Squircle>("D3D11UnderQML", 1, 0, "D3D11Squircle");
-
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi);
QQuickView view;
diff --git a/examples/quick/scenegraph/fboitem/fboinsgrenderer.h b/examples/quick/scenegraph/fboitem/fboinsgrenderer.h
index e1a9ce22c8..1b92b56851 100644
--- a/examples/quick/scenegraph/fboitem/fboinsgrenderer.h
+++ b/examples/quick/scenegraph/fboitem/fboinsgrenderer.h
@@ -58,6 +58,7 @@ class LogoRenderer;
class FboInSGRenderer : public QQuickFramebufferObject
{
Q_OBJECT
+ QML_NAMED_ELEMENT(Renderer)
public:
Renderer *createRenderer() const;
};
diff --git a/examples/quick/scenegraph/fboitem/fboitem.pro b/examples/quick/scenegraph/fboitem/fboitem.pro
index e40e5f4cf8..180c2288e2 100644
--- a/examples/quick/scenegraph/fboitem/fboitem.pro
+++ b/examples/quick/scenegraph/fboitem/fboitem.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += fboinsgrenderer.h
SOURCES += fboinsgrenderer.cpp main.cpp
diff --git a/examples/quick/scenegraph/fboitem/fboitem.qrc b/examples/quick/scenegraph/fboitem/fboitem.qrc
index 9d9db70654..eeb5c36afd 100644
--- a/examples/quick/scenegraph/fboitem/fboitem.qrc
+++ b/examples/quick/scenegraph/fboitem/fboitem.qrc
@@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/scenegraph/fboitem">
<file>main.qml</file>
+ <file>shaders/checker.frag</file>
+ <file>shaders/+qsb/checker.frag</file>
</qresource>
</RCC>
diff --git a/examples/quick/scenegraph/fboitem/main.cpp b/examples/quick/scenegraph/fboitem/main.cpp
index 429224ba95..153bd931ec 100644
--- a/examples/quick/scenegraph/fboitem/main.cpp
+++ b/examples/quick/scenegraph/fboitem/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<FboInSGRenderer>("SceneGraphRendering", 1, 0, "Renderer");
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/fboitem/main.qml"));
diff --git a/examples/quick/scenegraph/fboitem/main.qml b/examples/quick/scenegraph/fboitem/main.qml
index 92fa99e847..1f1829deda 100644
--- a/examples/quick/scenegraph/fboitem/main.qml
+++ b/examples/quick/scenegraph/fboitem/main.qml
@@ -67,20 +67,7 @@ Item {
property size pixelSize: Qt.size(width / tileSize, height / tileSize);
- fragmentShader:
- "
- uniform lowp vec4 color1;
- uniform lowp vec4 color2;
- uniform highp vec2 pixelSize;
- varying highp vec2 qt_TexCoord0;
- void main() {
- highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
- if (tc.x != tc.y)
- gl_FragColor = color1;
- else
- gl_FragColor = color2;
- }
- "
+ fragmentShader: "qrc:/scenegraph/fboitem/shaders/checker.frag"
}
Renderer {
diff --git a/examples/quick/scenegraph/fboitem/shaders/+qsb/checker.frag b/examples/quick/scenegraph/fboitem/shaders/+qsb/checker.frag
new file mode 100644
index 0000000000..5037899d19
--- /dev/null
+++ b/examples/quick/scenegraph/fboitem/shaders/+qsb/checker.frag
Binary files differ
diff --git a/examples/quick/scenegraph/fboitem/shaders/checker.frag b/examples/quick/scenegraph/fboitem/shaders/checker.frag
new file mode 100644
index 0000000000..044b3bad58
--- /dev/null
+++ b/examples/quick/scenegraph/fboitem/shaders/checker.frag
@@ -0,0 +1,14 @@
+uniform lowp vec4 color1;
+uniform lowp vec4 color2;
+uniform highp vec2 pixelSize;
+
+varying highp vec2 qt_TexCoord0;
+
+void main()
+{
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
+ if (tc.x != tc.y)
+ gl_FragColor = color1;
+ else
+ gl_FragColor = color2;
+}
diff --git a/examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag b/examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag
new file mode 100644
index 0000000000..1e4131d026
--- /dev/null
+++ b/examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag
@@ -0,0 +1,22 @@
+#version 440
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+
+ vec4 color1;
+ vec4 color2;
+ vec2 pixelSize;
+} ubuf;
+
+layout(location = 0) in vec2 qt_TexCoord0;
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * ubuf.pixelSize));
+ if (tc.x != tc.y)
+ fragColor = ubuf.color1;
+ else
+ fragColor = ubuf.color2;
+}
diff --git a/examples/quick/scenegraph/graph/graph.h b/examples/quick/scenegraph/graph/graph.h
index a1a00cb6dc..e32e657e0e 100644
--- a/examples/quick/scenegraph/graph/graph.h
+++ b/examples/quick/scenegraph/graph/graph.h
@@ -56,6 +56,7 @@
class Graph : public QQuickItem
{
Q_OBJECT
+ QML_ELEMENT
public:
Graph();
diff --git a/examples/quick/scenegraph/graph/graph.pro b/examples/quick/scenegraph/graph/graph.pro
index 1a880b61f1..fe36585d77 100644
--- a/examples/quick/scenegraph/graph/graph.pro
+++ b/examples/quick/scenegraph/graph/graph.pro
@@ -4,6 +4,10 @@ TARGET = graph
TEMPLATE = app
+CONFIG += qmltypes
+QML_IMPORT_NAME = Graph
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += main.cpp \
graph.cpp \
noisynode.cpp \
diff --git a/examples/quick/scenegraph/graph/main.cpp b/examples/quick/scenegraph/graph/main.cpp
index 2406457ab5..854fad84e3 100644
--- a/examples/quick/scenegraph/graph/main.cpp
+++ b/examples/quick/scenegraph/graph/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
- qmlRegisterType<Graph>("Graph", 1, 0, "Graph");
-
QQuickView view;
view.resize(800, 400);
view.setResizeMode(QQuickView::SizeRootObjectToView);
diff --git a/examples/quick/scenegraph/metaltextureimport/main.cpp b/examples/quick/scenegraph/metaltextureimport/main.cpp
index c969817e8f..4fc010e710 100644
--- a/examples/quick/scenegraph/metaltextureimport/main.cpp
+++ b/examples/quick/scenegraph/metaltextureimport/main.cpp
@@ -50,14 +50,10 @@
#include <QGuiApplication>
#include <QtQuick/QQuickView>
-#include "metaltextureimport.h"
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
-
- qmlRegisterType<CustomTextureItem>("MetalTextureImport", 1, 0, "CustomTextureItem");
-
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
QQuickView view;
diff --git a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.h b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.h
index afc5aced97..49a29565a7 100644
--- a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.h
+++ b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.h
@@ -60,6 +60,7 @@ class CustomTextureItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+ QML_ELEMENT
public:
CustomTextureItem();
diff --git a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
index 5b11606946..9e88c50dc6 100644
--- a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
+++ b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
@@ -1,12 +1,16 @@
-!macos: error("This example requires macOS")
+!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = MetalTextureImport
+QML_IMPORT_MAJOR_VERSION = 1
HEADERS += metaltextureimport.h
SOURCES += metaltextureimport.mm main.cpp
RESOURCES += metaltextureimport.qrc
-LIBS += -framework Metal -framework AppKit
+LIBS += -framework Metal
+macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metaltextureimport
INSTALLS += target
diff --git a/examples/quick/scenegraph/metalunderqml/main.cpp b/examples/quick/scenegraph/metalunderqml/main.cpp
index 5ad337abb1..cefb1c10a9 100644
--- a/examples/quick/scenegraph/metalunderqml/main.cpp
+++ b/examples/quick/scenegraph/metalunderqml/main.cpp
@@ -56,8 +56,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<MetalSquircle>("MetalUnderQML", 1, 0, "MetalSquircle");
-
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
QQuickView view;
diff --git a/examples/quick/scenegraph/metalunderqml/metalsquircle.h b/examples/quick/scenegraph/metalunderqml/metalsquircle.h
index 43c4afad21..18db7d45f3 100644
--- a/examples/quick/scenegraph/metalunderqml/metalsquircle.h
+++ b/examples/quick/scenegraph/metalunderqml/metalsquircle.h
@@ -59,6 +59,7 @@ class MetalSquircle : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+ QML_ELEMENT
public:
MetalSquircle();
diff --git a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
index 5ca6daa01a..4844df0c70 100644
--- a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
+++ b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
@@ -349,10 +349,13 @@ void SquircleRenderer::init(int framesInFlight)
rpDesc.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne;
rpDesc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;
+#ifdef Q_OS_MACOS
if (m_device.depth24Stencil8PixelFormatSupported) {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
- } else {
+ } else
+#endif
+ {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}
diff --git a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
index 9fd131fe1b..3b0489ecdf 100644
--- a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
+++ b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
@@ -1,12 +1,17 @@
-!macos: error("This example requires macOS")
+!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = MetalUnderQML
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += metalsquircle.h
SOURCES += metalsquircle.mm main.cpp
RESOURCES += metalunderqml.qrc
-LIBS += -framework Metal -framework AppKit
+LIBS += -framework Metal
+macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metalunderqml
INSTALLS += target
diff --git a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
index 9676815c44..c2944970a5 100644
--- a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
+++ b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc
@@ -60,6 +60,7 @@
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().
+ We expose it to QML using the QML_ELEMENT macro.
\snippet scenegraph/openglunderqml/squircle.h 1
@@ -145,9 +146,7 @@
\snippet scenegraph/openglunderqml/main.cpp 1
The application's \c main() function instantiates a QQuickView and
- launches the \c main.qml file. The only thing worth noting is that
- we export the \c Squircle class to QML using the \l
- qmlRegisterType() macro.
+ launches the \c main.qml file.
\snippet scenegraph/openglunderqml/main.qml 1
diff --git a/examples/quick/scenegraph/openglunderqml/main.cpp b/examples/quick/scenegraph/openglunderqml/main.cpp
index 022d6a75bb..4ca8d05f1c 100644
--- a/examples/quick/scenegraph/openglunderqml/main.cpp
+++ b/examples/quick/scenegraph/openglunderqml/main.cpp
@@ -59,8 +59,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<Squircle>("OpenGLUnderQML", 1, 0, "Squircle");
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml"));
diff --git a/examples/quick/scenegraph/openglunderqml/openglunderqml.pro b/examples/quick/scenegraph/openglunderqml/openglunderqml.pro
index 54558ce9e9..7eaace1133 100644
--- a/examples/quick/scenegraph/openglunderqml/openglunderqml.pro
+++ b/examples/quick/scenegraph/openglunderqml/openglunderqml.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = OpenGLUnderQML
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += squircle.h
SOURCES += squircle.cpp main.cpp
RESOURCES += openglunderqml.qrc
diff --git a/examples/quick/scenegraph/openglunderqml/squircle.h b/examples/quick/scenegraph/openglunderqml/squircle.h
index 1b9995bc1e..c24fdd50c2 100644
--- a/examples/quick/scenegraph/openglunderqml/squircle.h
+++ b/examples/quick/scenegraph/openglunderqml/squircle.h
@@ -86,6 +86,7 @@ class Squircle : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+ QML_ELEMENT
public:
Squircle();
diff --git a/examples/quick/scenegraph/rendernode/customrenderitem.h b/examples/quick/scenegraph/rendernode/customrenderitem.h
index a0ac3468e4..28be54925b 100644
--- a/examples/quick/scenegraph/rendernode/customrenderitem.h
+++ b/examples/quick/scenegraph/rendernode/customrenderitem.h
@@ -53,13 +53,16 @@
#include <QQuickItem>
+//! [0]
class CustomRenderItem : public QQuickItem
{
Q_OBJECT
+ QML_ELEMENT
public:
CustomRenderItem(QQuickItem *parent = nullptr);
QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
};
+//! [0]
#endif
diff --git a/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc b/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc
index ba6551fddf..87e3c8b506 100644
--- a/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc
+++ b/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc
@@ -69,7 +69,7 @@
Let's go through the most important parts of the code:
- \snippet scenegraph/rendernode/main.cpp 1
+ \snippet scenegraph/rendernode/customrenderitem.h 0
Our custom QML type is implemented in the class CustomRenderItem.
diff --git a/examples/quick/scenegraph/rendernode/main.cpp b/examples/quick/scenegraph/rendernode/main.cpp
index 146d787e50..645360eaba 100644
--- a/examples/quick/scenegraph/rendernode/main.cpp
+++ b/examples/quick/scenegraph/rendernode/main.cpp
@@ -58,10 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
-//! [1]
- qmlRegisterType<CustomRenderItem>("SceneGraphRendering", 2, 0, "CustomRenderItem");
-//! [1]
-
QQuickView view;
QCoreApplication::setApplicationName("Qt Scene Graph Render Node Example");
diff --git a/examples/quick/scenegraph/rendernode/main.qml b/examples/quick/scenegraph/rendernode/main.qml
index 153a71e097..5631df317c 100644
--- a/examples/quick/scenegraph/rendernode/main.qml
+++ b/examples/quick/scenegraph/rendernode/main.qml
@@ -66,7 +66,7 @@ Item {
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
- onClicked: {
+ onClicked: (mouse) => {
if (mouse.button === Qt.LeftButton) {
clipper.clip = !clipper.clip
} else if (mouse.button === Qt.RightButton) {
diff --git a/examples/quick/scenegraph/rendernode/rendernode.pro b/examples/quick/scenegraph/rendernode/rendernode.pro
index 897b0b1f08..cfec905764 100644
--- a/examples/quick/scenegraph/rendernode/rendernode.pro
+++ b/examples/quick/scenegraph/rendernode/rendernode.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 2
+
HEADERS += customrenderitem.h \
openglrenderer.h \
softwarerenderer.h
diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
index bba364ac97..d6d97a8151 100644
--- a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
+++ b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
@@ -53,6 +53,7 @@
#include <QQuickWindow>
#include <QSGRendererInterface>
#include <QPainter>
+#include <QPainterPath>
SoftwareRenderNode::~SoftwareRenderNode()
{
@@ -95,7 +96,7 @@ void SoftwareRenderNode::render(const RenderState *renderState)
QSGRenderNode::StateFlags SoftwareRenderNode::changedStates() const
{
- return nullptr;
+ return {};
}
QSGRenderNode::RenderingFlags SoftwareRenderNode::flags() const
diff --git a/examples/quick/scenegraph/scenegraph.pro b/examples/quick/scenegraph/scenegraph.pro
index 5fea3b974a..08ca18fa0c 100644
--- a/examples/quick/scenegraph/scenegraph.pro
+++ b/examples/quick/scenegraph/scenegraph.pro
@@ -16,7 +16,7 @@ SUBDIRS += \
rendernode \
threadedanimation
-macos {
+macos|ios {
SUBDIRS += \
metalunderqml \
metaltextureimport
@@ -27,7 +27,9 @@ win32 {
}
qtConfig(vulkan) {
- SUBDIRS += vulkanunderqml
+ SUBDIRS += \
+ vulkanunderqml \
+ vulkantextureimport
}
EXAMPLE_FILES += \
diff --git a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
index 67ca2d8dbd..d7de1613e4 100644
--- a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
+++ b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc
@@ -47,7 +47,7 @@
material state is what we assign to each individual node; in this
case to give them different colors.
- \snippet scenegraph/simplematerial/simplematerial.cpp 1
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 1
The first thing we do when creating custom materials with the
simplified scheme is to create a state class. In this case the
@@ -55,7 +55,7 @@
compare function which the scene graph can use to reorder the node
rendering.
- \snippet scenegraph/simplematerial/simplematerial.cpp 2
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 2
Next we define the material shader, by subclassing a template
instantiation of \l QSGSimpleMaterialShader with our \c State.
@@ -74,21 +74,21 @@
classes. Using the same \c State class in multiple shaders will
will lead to undefined behavior.
- \snippet scenegraph/simplematerial/simplematerial.cpp 3
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 3
Next comes the declaration of the shader source code, where we
define a vertex and fragment shader. The simple material assumes
the presence of \c qt_Matrix in the vertex shader and \c
qt_Opacity in the fragment shader.
- \snippet scenegraph/simplematerial/simplematerial.cpp 4
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 4
We reimplement the \c attributes function to return the name of
the \c aVertex and \c aTexCoord attributes. These attributes
will be mapped to attribute indices 0 and 1 in the node's
geometry.
- \snippet scenegraph/simplematerial/simplematerial.cpp 6
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 6
Uniforms can be accessed either by name or by index, where index
is faster than name. We reimplement the \c resolveUniforms()
@@ -96,7 +96,7 @@
to worry about resolving \c qt_Opacity or \c qt_Matrix as these
are handled by the baseclass.
- \snippet scenegraph/simplematerial/simplematerial.cpp 5
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 5
The \c updateState() function is called once for every unique
state and we use it to update the shader program with the current
@@ -105,7 +105,7 @@
use case, where all the colors are different, the updateState()
function will be called once for every node.
- \snippet scenegraph/simplematerial/simplematerial.cpp 7
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 7
The \c ColorNode class is supposed to draw something, so it needs
to be a subclass of \l QSGGeometryNode.
@@ -129,12 +129,13 @@
Finally, we tell the node to take ownership of the material, so we
do not have to explicitly memory-manage it.
- \snippet scenegraph/simplematerial/simplematerial.cpp 8
+ \snippet scenegraph/simplematerial/simplematerialitem.h 8
Since the Item is providing its own graphics to the scene graph,
- we set the flag \l QQuickItem::ItemHasContents.
+ we set the flag \l QQuickItem::ItemHasContents. We also make sure
+ the item is exposed to QML by adding the QML_ELEMENT macro.
- \snippet scenegraph/simplematerial/simplematerial.cpp 9
+ \snippet scenegraph/simplematerial/simplematerialitem.cpp 9
Whenever the Item has changed graphically, the \l
QQuickItem::updatePaintNode() function is called.
@@ -159,9 +160,8 @@
\snippet scenegraph/simplematerial/simplematerial.cpp 11
- The \c main() function of the application adds the custom QML type
- using \l qmlRegisterType() and opens up a \l QQuickView with our
- QML file.
+ The \c main() function of the application opens up a \l QQuickView
+ with our QML file.
\snippet scenegraph/simplematerial/main.qml 1
diff --git a/examples/quick/scenegraph/simplematerial/simplematerial.cpp b/examples/quick/scenegraph/simplematerial/simplematerial.cpp
index 6773b6fb5a..35866bd6d0 100644
--- a/examples/quick/scenegraph/simplematerial/simplematerial.cpp
+++ b/examples/quick/scenegraph/simplematerial/simplematerial.cpp
@@ -49,162 +49,13 @@
****************************************************************************/
#include <qguiapplication.h>
-
-#include <qsgmaterial.h>
-#include <qsgnode.h>
-
-#include <qquickitem.h>
#include <qquickview.h>
-#include <qsgsimplerectnode.h>
-
-#include <qsgsimplematerial.h>
-
-//! [1]
-struct State
-{
- QColor color;
-
- int compare(const State *other) const {
- uint rgb = color.rgba();
- uint otherRgb = other->color.rgba();
-
- if (rgb == otherRgb) {
- return 0;
- } else if (rgb < otherRgb) {
- return -1;
- } else {
- return 1;
- }
- }
-};
-//! [1]
-
-//! [2]
-class Shader : public QSGSimpleMaterialShader<State>
-{
- QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State);
-//! [2] //! [3]
-public:
-
- const char *vertexShader() const override {
- return
- "attribute highp vec4 aVertex; \n"
- "attribute highp vec2 aTexCoord; \n"
- "uniform highp mat4 qt_Matrix; \n"
- "varying highp vec2 texCoord; \n"
- "void main() { \n"
- " gl_Position = qt_Matrix * aVertex; \n"
- " texCoord = aTexCoord; \n"
- "}";
- }
-
- const char *fragmentShader() const override {
- return
- "uniform lowp float qt_Opacity; \n"
- "uniform lowp vec4 color; \n"
- "varying highp vec2 texCoord; \n"
- "void main () \n"
- "{ \n"
- " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n"
- "}";
- }
-//! [3] //! [4]
- QList<QByteArray> attributes() const override
- {
- return QList<QByteArray>() << "aVertex" << "aTexCoord";
- }
-//! [4] //! [5]
- void updateState(const State *state, const State *) override
- {
- program()->setUniformValue(id_color, state->color);
- }
-//! [5] //! [6]
- void resolveUniforms() override
- {
- id_color = program()->uniformLocation("color");
- }
-
-private:
- int id_color;
-//! [6]
-};
-
-
-//! [7]
-class ColorNode : public QSGGeometryNode
-{
-public:
- ColorNode()
- : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
- {
- setGeometry(&m_geometry);
-
- QSGSimpleMaterial<State> *material = Shader::createMaterial();
- material->setFlag(QSGMaterial::Blending);
- setMaterial(material);
- setFlag(OwnsMaterial);
- }
-
- QSGGeometry m_geometry;
-};
-//! [7]
-
-
-//! [8]
-class Item : public QQuickItem
-{
- Q_OBJECT
-
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
-
-public:
-
- Item()
- {
- setFlag(ItemHasContents, true);
- }
-
- void setColor(const QColor &color) {
- if (m_color != color) {
- m_color = color;
- emit colorChanged();
- update();
- }
- }
- QColor color() const {
- return m_color;
- }
-
-signals:
- void colorChanged();
-
-private:
- QColor m_color;
-
-//! [8] //! [9]
-public:
- QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override
- {
- ColorNode *n = static_cast<ColorNode *>(node);
- if (!node)
- n = new ColorNode();
-
- QSGGeometry::updateTexturedRectGeometry(n->geometry(), boundingRect(), QRectF(0, 0, 1, 1));
- static_cast<QSGSimpleMaterial<State>*>(n->material())->state()->color = m_color;
-
- n->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
-
- return n;
- }
-};
-//! [9] //! [11]
+//! [11]
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<Item>("SimpleMaterial", 1, 0, "SimpleMaterialItem");
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/simplematerial/main.qml"));
@@ -212,6 +63,4 @@ int main(int argc, char **argv)
return app.exec();
}
-
-#include "simplematerial.moc"
//! [11]
diff --git a/examples/quick/scenegraph/simplematerial/simplematerial.pro b/examples/quick/scenegraph/simplematerial/simplematerial.pro
index 6ae935f357..131af45974 100644
--- a/examples/quick/scenegraph/simplematerial/simplematerial.pro
+++ b/examples/quick/scenegraph/simplematerial/simplematerial.pro
@@ -1,8 +1,13 @@
QT += quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SimpleMaterial
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += \
- simplematerial.cpp
+ simplematerial.cpp \
+ simplematerialitem.cpp
RESOURCES += simplematerial.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
@@ -10,3 +15,6 @@ qml.files = main.qml
qml.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
INSTALLS += target qml
+
+HEADERS += \
+ simplematerialitem.h
diff --git a/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp b/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp
new file mode 100644
index 0000000000..c4c7b2e07e
--- /dev/null
+++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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 "simplematerialitem.h"
+
+#include <QtQuick/qsgsimplematerial.h>
+#include <QtQuick/qsggeometry.h>
+#include <QtQuick/qsgnode.h>
+
+//! [1]
+struct State
+{
+ QColor color;
+
+ int compare(const State *other) const {
+ uint rgb = color.rgba();
+ uint otherRgb = other->color.rgba();
+
+ if (rgb == otherRgb) {
+ return 0;
+ } else if (rgb < otherRgb) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+};
+//! [1]
+
+//! [2]
+class Shader : public QSGSimpleMaterialShader<State>
+{
+ QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State);
+//! [2] //! [3]
+public:
+
+ const char *vertexShader() const override {
+ return
+ "attribute highp vec4 aVertex; \n"
+ "attribute highp vec2 aTexCoord; \n"
+ "uniform highp mat4 qt_Matrix; \n"
+ "varying highp vec2 texCoord; \n"
+ "void main() { \n"
+ " gl_Position = qt_Matrix * aVertex; \n"
+ " texCoord = aTexCoord; \n"
+ "}";
+ }
+
+ const char *fragmentShader() const override {
+ return
+ "uniform lowp float qt_Opacity; \n"
+ "uniform lowp vec4 color; \n"
+ "varying highp vec2 texCoord; \n"
+ "void main () \n"
+ "{ \n"
+ " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n"
+ "}";
+ }
+//! [3] //! [4]
+ QList<QByteArray> attributes() const override
+ {
+ return QList<QByteArray>() << "aVertex" << "aTexCoord";
+ }
+//! [4] //! [5]
+ void updateState(const State *state, const State *) override
+ {
+ program()->setUniformValue(id_color, state->color);
+ }
+//! [5] //! [6]
+ void resolveUniforms() override
+ {
+ id_color = program()->uniformLocation("color");
+ }
+
+private:
+ int id_color;
+//! [6]
+};
+
+
+//! [7]
+class ColorNode : public QSGGeometryNode
+{
+public:
+ ColorNode()
+ : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
+ {
+ setGeometry(&m_geometry);
+
+ QSGSimpleMaterial<State> *material = Shader::createMaterial();
+ material->setFlag(QSGMaterial::Blending);
+ setMaterial(material);
+ setFlag(OwnsMaterial);
+ }
+
+ QSGGeometry m_geometry;
+};
+//! [7]
+
+void SimpleMaterialItem::setColor(const QColor &color) {
+ if (m_color != color) {
+ m_color = color;
+ emit colorChanged();
+ update();
+ }
+}
+
+//! [9]
+QSGNode *SimpleMaterialItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *)
+{
+ ColorNode *n = static_cast<ColorNode *>(node);
+ if (!node)
+ n = new ColorNode();
+
+ QSGGeometry::updateTexturedRectGeometry(n->geometry(), boundingRect(), QRectF(0, 0, 1, 1));
+ static_cast<QSGSimpleMaterial<State>*>(n->material())->state()->color = m_color;
+
+ n->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
+
+ return n;
+}
+//! [9]
diff --git a/examples/quick/scenegraph/simplematerial/simplematerialitem.h b/examples/quick/scenegraph/simplematerial/simplematerialitem.h
new file mode 100644
index 0000000000..5775ad097b
--- /dev/null
+++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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 SIMPLEMATERIALITEM_H
+#define SIMPLEMATERIALITEM_H
+
+#include <QtQuick/qquickitem.h>
+
+//! [8]
+class SimpleMaterialItem : public QQuickItem
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ QML_ELEMENT
+
+public:
+
+ SimpleMaterialItem() { setFlag(ItemHasContents, true); }
+
+ void setColor(const QColor &color);
+ QColor color() const { return m_color; }
+
+signals:
+ void colorChanged();
+
+private:
+ QColor m_color;
+
+public:
+ QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
+};
+//! [8]
+
+#endif // SIMPLEMATERIALITEM_H
diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp
index 7a46f25390..cb00946bf7 100644
--- a/examples/quick/scenegraph/textureinthread/main.cpp
+++ b/examples/quick/scenegraph/textureinthread/main.cpp
@@ -70,7 +70,6 @@ int main(int argc, char **argv)
return app.exec();
}
- qmlRegisterType<ThreadRenderer>("SceneGraphRendering", 1, 0, "Renderer");
int execReturn = 0;
{
diff --git a/examples/quick/scenegraph/textureinthread/textureinthread.pro b/examples/quick/scenegraph/textureinthread/textureinthread.pro
index 7f5fbb76e9..4d41daa7bf 100644
--- a/examples/quick/scenegraph/textureinthread/textureinthread.pro
+++ b/examples/quick/scenegraph/textureinthread/textureinthread.pro
@@ -3,6 +3,10 @@ QT += quick
# To make threaded gl check...
QT += core-private gui-private
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += threadrenderer.h
SOURCES += threadrenderer.cpp main.cpp
diff --git a/examples/quick/scenegraph/textureinthread/threadrenderer.h b/examples/quick/scenegraph/textureinthread/threadrenderer.h
index 8442041bf8..96c00e7b2e 100644
--- a/examples/quick/scenegraph/textureinthread/threadrenderer.h
+++ b/examples/quick/scenegraph/textureinthread/threadrenderer.h
@@ -58,6 +58,7 @@ class RenderThread;
class ThreadRenderer : public QQuickItem
{
Q_OBJECT
+ QML_NAMED_ELEMENT(Renderer)
public:
ThreadRenderer();
diff --git a/examples/quick/scenegraph/threadedanimation/main.cpp b/examples/quick/scenegraph/threadedanimation/main.cpp
index b1b0c05085..85ff486b16 100644
--- a/examples/quick/scenegraph/threadedanimation/main.cpp
+++ b/examples/quick/scenegraph/threadedanimation/main.cpp
@@ -57,8 +57,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<Spinner>("Spinner", 1, 0, "Spinner");
-
QQuickView view;
view.setSource(QUrl("qrc:///scenegraph/threadedanimation/main.qml"));
view.show();
diff --git a/examples/quick/scenegraph/threadedanimation/spinner.h b/examples/quick/scenegraph/threadedanimation/spinner.h
index c3f3394c93..fd3eaa7751 100644
--- a/examples/quick/scenegraph/threadedanimation/spinner.h
+++ b/examples/quick/scenegraph/threadedanimation/spinner.h
@@ -58,6 +58,7 @@ class Spinner : public QQuickItem
Q_OBJECT
Q_PROPERTY(bool spinning READ spinning WRITE setSpinning NOTIFY spinningChanged)
+ QML_ELEMENT
public:
Spinner();
diff --git a/examples/quick/scenegraph/threadedanimation/threadedanimation.pro b/examples/quick/scenegraph/threadedanimation/threadedanimation.pro
index 419ee97e2e..3caf3fa94b 100644
--- a/examples/quick/scenegraph/threadedanimation/threadedanimation.pro
+++ b/examples/quick/scenegraph/threadedanimation/threadedanimation.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = Spinner
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += spinner.h
SOURCES += spinner.cpp main.cpp
RESOURCES += threadedanimation.qrc
diff --git a/examples/quick/scenegraph/twotextureproviders/main.cpp b/examples/quick/scenegraph/twotextureproviders/main.cpp
index a5d23b6adc..df0454ce40 100644
--- a/examples/quick/scenegraph/twotextureproviders/main.cpp
+++ b/examples/quick/scenegraph/twotextureproviders/main.cpp
@@ -58,8 +58,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<XorBlender>("SceneGraphRendering", 1, 0, "XorBlender");
-
QQuickView view;
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///scenegraph/twotextureproviders/main.qml"));
diff --git a/examples/quick/scenegraph/twotextureproviders/main.qml b/examples/quick/scenegraph/twotextureproviders/main.qml
index 296df766a1..b9e516f4b7 100644
--- a/examples/quick/scenegraph/twotextureproviders/main.qml
+++ b/examples/quick/scenegraph/twotextureproviders/main.qml
@@ -64,20 +64,9 @@ Item {
property size pixelSize: Qt.size(width / tileSize, height / tileSize);
- fragmentShader:
- "
- uniform lowp vec4 color1;
- uniform lowp vec4 color2;
- uniform highp vec2 pixelSize;
- varying highp vec2 qt_TexCoord0;
- void main() {
- highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
- if (tc.x != tc.y)
- gl_FragColor = color1;
- else
- gl_FragColor = color2;
- }
- "
+ // Will automatically pick either checker.frag or +qsb/checker.frag
+ // thanks to file selectors.
+ fragmentShader: "qrc:/scenegraph/twotextureproviders/shaders/checker.frag"
}
width: 320
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.frag b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.frag
new file mode 100644
index 0000000000..edcfad488b
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.frag
Binary files differ
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag
new file mode 100644
index 0000000000..7a5280ba08
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag
Binary files differ
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert
new file mode 100644
index 0000000000..d643c7be6a
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert
Binary files differ
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/checker.frag b/examples/quick/scenegraph/twotextureproviders/shaders/checker.frag
new file mode 100644
index 0000000000..044b3bad58
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/checker.frag
@@ -0,0 +1,14 @@
+uniform lowp vec4 color1;
+uniform lowp vec4 color2;
+uniform highp vec2 pixelSize;
+
+varying highp vec2 qt_TexCoord0;
+
+void main()
+{
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
+ if (tc.x != tc.y)
+ gl_FragColor = color1;
+ else
+ gl_FragColor = color2;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag b/examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag
new file mode 100644
index 0000000000..0932bc8c37
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag
@@ -0,0 +1,25 @@
+#version 440
+
+layout(location = 0) in vec2 qt_TexCoord0;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ // preamble as required by ShaderEffect
+ mat4 qt_Matrix;
+ float qt_Opacity;
+
+ // our custom members, connected automatically to QML object properties
+ vec4 color1;
+ vec4 color2;
+ vec2 pixelSize;
+} ubuf;
+
+void main()
+{
+ vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * ubuf.pixelSize));
+ if (tc.x != tc.y)
+ fragColor = ubuf.color1;
+ else
+ fragColor = ubuf.color2;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag
new file mode 100644
index 0000000000..f67735312d
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag
@@ -0,0 +1,12 @@
+uniform lowp float qt_Opacity;
+uniform lowp sampler2D uSource1;
+uniform lowp sampler2D uSource2;
+
+varying highp vec2 vTexCoord;
+
+void main()
+{
+ lowp vec4 p1 = texture2D(uSource1, vTexCoord);
+ lowp vec4 p2 = texture2D(uSource2, vTexCoord);
+ gl_FragColor = (p1 * (1.0 - p2.a) + p2 * (1.0 - p1.a)) * qt_Opacity;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert
new file mode 100644
index 0000000000..ac9f1364d6
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert
@@ -0,0 +1,12 @@
+attribute highp vec4 aVertex;
+attribute highp vec2 aTexCoord;
+
+uniform highp mat4 qt_Matrix;
+
+varying highp vec2 vTexCoord;
+
+void main()
+{
+ gl_Position = qt_Matrix * aVertex;
+ vTexCoord = aTexCoord;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag
new file mode 100644
index 0000000000..bc68160c1f
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag
@@ -0,0 +1,20 @@
+#version 440
+
+layout(location = 0) in vec2 vTexCoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+} ubuf;
+
+layout(binding = 1) uniform sampler2D uSource1;
+layout(binding = 2) uniform sampler2D uSource2;
+
+void main()
+{
+ lowp vec4 p1 = texture(uSource1, vTexCoord);
+ lowp vec4 p2 = texture(uSource2, vTexCoord);
+ fragColor = (p1 * (1.0 - p2.a) + p2 * (1.0 - p1.a)) * ubuf.qt_Opacity;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert
new file mode 100644
index 0000000000..41000bde04
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec4 aVertex;
+layout(location = 1) in vec2 aTexCoord;
+
+layout(location = 0) out vec2 vTexCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ gl_Position = ubuf.qt_Matrix * aVertex;
+ vTexCoord = aTexCoord;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro
index 7b7c093b48..b87a0a2611 100644
--- a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro
+++ b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro
@@ -1,5 +1,9 @@
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = SceneGraphRendering
+QML_IMPORT_MAJOR_VERSION = 1
+
HEADERS += xorblender.h
SOURCES += xorblender.cpp main.cpp
diff --git a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc
index 1424333ce5..8022a77a1e 100644
--- a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc
+++ b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc
@@ -1,5 +1,13 @@
<RCC>
<qresource prefix="/scenegraph/twotextureproviders">
<file>main.qml</file>
+
+ <file>shaders/checker.frag</file>
+ <file>shaders/xorblender.vert</file>
+ <file>shaders/xorblender.frag</file>
+
+ <file>shaders/+qsb/checker.frag</file>
+ <file>shaders/+qsb/xorblender.vert</file>
+ <file>shaders/+qsb/xorblender.frag</file>
</qresource>
</RCC>
diff --git a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
index 8d7597addf..d5881b9adc 100644
--- a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
+++ b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
@@ -55,7 +55,7 @@
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFunctions>
-#include <QtQuick/QSGSimpleMaterial>
+#include <QtQuick/QSGMaterial>
#include <QtQuick/QSGTexture>
#include <QtQuick/QSGGeometryNode>
#include <QtQuick/QSGTextureProvider>
@@ -67,64 +67,170 @@
* a custom material.
*/
-struct XorBlendState {
- QSGTexture *texture1;
- QSGTexture *texture2;
+class XorBlendMaterial : public QSGMaterial
+{
+public:
+ XorBlendMaterial();
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ int compare(const QSGMaterial *other) const override;
+
+ struct {
+ QSGTexture *texture1 = nullptr;
+ QSGTexture *texture2 = nullptr;
+ } state;
};
-class XorBlendShader : public QSGSimpleMaterialShader<XorBlendState>
+class XorBlendShader : public QSGMaterialShader // for when the scenegraph is using OpenGL directly
{
- QSG_DECLARE_SIMPLE_SHADER(XorBlendShader, XorBlendState)
public:
+ XorBlendShader();
+ void initialize() override;
+ char const *const *attributeNames() const override;
+ void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
- const char *vertexShader() const override {
- return
- "attribute highp vec4 aVertex; \n"
- "attribute highp vec2 aTexCoord; \n"
- "uniform highp mat4 qt_Matrix; \n"
- "varying highp vec2 vTexCoord; \n"
- "void main() { \n"
- " gl_Position = qt_Matrix * aVertex; \n"
- " vTexCoord = aTexCoord; \n"
- "}";
- }
+private:
+ int m_matrix_id;
+ int m_opacity_id;
+};
- const char *fragmentShader() const override {
- return
- "uniform lowp float qt_Opacity; \n"
- "uniform lowp sampler2D uSource1; \n"
- "uniform lowp sampler2D uSource2; \n"
- "varying highp vec2 vTexCoord; \n"
- "void main() { \n"
- " lowp vec4 p1 = texture2D(uSource1, vTexCoord); \n"
- " lowp vec4 p2 = texture2D(uSource2, vTexCoord); \n"
- " gl_FragColor = (p1 * (1.0 - p2.a) + p2 * (1.0 - p1.a)) * qt_Opacity; \n"
- "}";
- }
+class XorBlendRhiShader : public QSGMaterialRhiShader // for when the scenegraph is using QRhi
+{
+public:
+ XorBlendRhiShader();
+ bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+XorBlendMaterial::XorBlendMaterial()
+{
+ setFlag(SupportsRhiShader);
+ setFlag(Blending);
+}
+
+QSGMaterialShader *XorBlendMaterial::createShader() const
+{
+ if (flags().testFlag(RhiShaderWanted))
+ return new XorBlendRhiShader;
+ else
+ return new XorBlendShader;
+}
+
+QSGMaterialType *XorBlendMaterial::type() const
+{
+ static QSGMaterialType type;
+ return &type;
+}
+
+int XorBlendMaterial::compare(const QSGMaterial *o) const
+{
+ Q_ASSERT(o && type() == o->type());
+ const XorBlendMaterial *other = static_cast<const XorBlendMaterial *>(o);
+
+ if (!state.texture1 || !other->state.texture1)
+ return state.texture1 ? 1 : -1;
+
+ if (!state.texture2 || !other->state.texture2)
+ return state.texture2 ? -1 : 1;
+
+ if (int diff = state.texture1->comparisonKey() - other->state.texture1->comparisonKey())
+ return diff;
+
+ if (int diff = state.texture2->comparisonKey() - other->state.texture2->comparisonKey())
+ return diff;
- QList<QByteArray> attributes() const override {
- return QList<QByteArray>() << "aVertex" << "aTexCoord";
+ return 0;
+}
+
+XorBlendShader::XorBlendShader()
+{
+ setShaderSourceFile(QOpenGLShader::Vertex, QLatin1String(":/scenegraph/twotextureproviders/shaders/xorblender.vert"));
+ setShaderSourceFile(QOpenGLShader::Fragment, QLatin1String(":/scenegraph/twotextureproviders/shaders/xorblender.frag"));
+}
+
+void XorBlendShader::initialize()
+{
+ m_matrix_id = program()->uniformLocation("qt_Matrix");
+ m_opacity_id = program()->uniformLocation("qt_Opacity");
+ // The texture units never change, only the textures we bind to them so
+ // we set these once and for all here.
+ program()->setUniformValue("uSource1", 0); // GL_TEXTURE0
+ program()->setUniformValue("uSource2", 1); // GL_TEXTURE1
+}
+
+char const *const *XorBlendShader::attributeNames() const
+{
+ static char const *const attr[] = { "aVertex", "aTexCoord", nullptr };
+ return attr;
+}
+
+void XorBlendShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
+{
+ XorBlendMaterial *material = static_cast<XorBlendMaterial *>(newEffect);
+
+ if (state.isMatrixDirty())
+ program()->setUniformValue(m_matrix_id, state.combinedMatrix());
+
+ if (state.isOpacityDirty())
+ program()->setUniformValue(m_opacity_id, state.opacity());
+
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ // We bind the textures in inverse order so that we leave the updateState
+ // function with GL_TEXTURE0 as the active texture unit. This is maintain
+ // the "contract" that updateState should not mess up the GL state beyond
+ // what is needed for this material.
+ f->glActiveTexture(GL_TEXTURE1);
+ material->state.texture2->bind();
+ f->glActiveTexture(GL_TEXTURE0);
+ material->state.texture1->bind();
+}
+
+XorBlendRhiShader::XorBlendRhiShader()
+{
+ setShaderFileName(VertexStage, QLatin1String(":/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert"));
+ setShaderFileName(FragmentStage, QLatin1String(":/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag"));
+}
+
+bool XorBlendRhiShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 68);
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
}
- void updateState(const XorBlendState *state, const XorBlendState *) override {
- QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- // We bind the textures in inverse order so that we leave the updateState
- // function with GL_TEXTURE0 as the active texture unit. This is maintain
- // the "contract" that updateState should not mess up the GL state beyond
- // what is needed for this material.
- f->glActiveTexture(GL_TEXTURE1);
- state->texture2->bind();
- f->glActiveTexture(GL_TEXTURE0);
- state->texture1->bind();
+ if (state.isOpacityDirty()) {
+ const float opacity = state.opacity();
+ memcpy(buf->data() + 64, &opacity, 4);
+ changed = true;
}
- void resolveUniforms() override {
- // The texture units never change, only the texturess we bind to them so
- // we set these once and for all here.
- program()->setUniformValue("uSource1", 0); // GL_TEXTURE0
- program()->setUniformValue("uSource2", 1); // GL_TEXTURE1
+ return changed;
+}
+
+void XorBlendRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *)
+{
+ Q_UNUSED(state);
+
+ XorBlendMaterial *mat = static_cast<XorBlendMaterial *>(newMaterial);
+ switch (binding) { // the binding for the sampler2Ds in the fragment shader
+ case 1:
+ *texture = mat->state.texture1;
+ break;
+ case 2:
+ *texture = mat->state.texture2;
+ break;
+ default:
+ return;
}
-};
+}
/* The rendering is split into two nodes. The top-most node is not actually
* rendering anything, but is responsible for managing the texture providers.
@@ -148,10 +254,7 @@ public:
setFlag(QSGNode::UsePreprocess, true);
// Set up material so it is all set for later..
- m_material = XorBlendShader::createMaterial();
- m_material->state()->texture1 = nullptr;
- m_material->state()->texture2 = nullptr;
- m_material->setFlag(QSGMaterial::Blending);
+ m_material = new XorBlendMaterial;
m_node.setMaterial(m_material);
m_node.setFlag(QSGNode::OwnsMaterial);
@@ -166,25 +269,24 @@ public:
}
void preprocess() override {
- XorBlendState *state = m_material->state();
// Update the textures from the providers, calling into QSGDynamicTexture if required
if (m_provider1) {
- state->texture1 = m_provider1->texture();
- if (QSGDynamicTexture *dt1 = qobject_cast<QSGDynamicTexture *>(state->texture1))
+ m_material->state.texture1 = m_provider1->texture();
+ if (QSGDynamicTexture *dt1 = qobject_cast<QSGDynamicTexture *>(m_material->state.texture1))
dt1->updateTexture();
}
if (m_provider2) {
- state->texture2 = m_provider2->texture();
- if (QSGDynamicTexture *dt2 = qobject_cast<QSGDynamicTexture *>(state->texture2))
+ m_material->state.texture2 = m_provider2->texture();
+ if (QSGDynamicTexture *dt2 = qobject_cast<QSGDynamicTexture *>(m_material->state.texture2))
dt2->updateTexture();
}
// Remove node from the scene graph if it is there and either texture is missing...
- if (m_node.parent() && (!state->texture1 || !state->texture2))
+ if (m_node.parent() && (!m_material->state.texture1 || !m_material->state.texture2))
removeChildNode(&m_node);
// Add it if it is not already there and both textures are present..
- else if (!m_node.parent() && state->texture1 && state->texture2)
+ else if (!m_node.parent() && m_material->state.texture1 && m_material->state.texture2)
appendChildNode(&m_node);
}
@@ -206,7 +308,7 @@ public slots:
private:
QRectF m_rect;
- QSGSimpleMaterial<XorBlendState> *m_material;
+ XorBlendMaterial *m_material;
QSGGeometryNode m_node;
QPointer<QSGTextureProvider> m_provider1;
QPointer<QSGTextureProvider> m_provider2;
diff --git a/examples/quick/scenegraph/twotextureproviders/xorblender.h b/examples/quick/scenegraph/twotextureproviders/xorblender.h
index 94132f09fb..17557b8efd 100644
--- a/examples/quick/scenegraph/twotextureproviders/xorblender.h
+++ b/examples/quick/scenegraph/twotextureproviders/xorblender.h
@@ -58,6 +58,7 @@ class XorBlender : public QQuickItem
Q_OBJECT
Q_PROPERTY(QQuickItem *source1 READ source1 WRITE setSource1 NOTIFY source1Changed)
Q_PROPERTY(QQuickItem *source2 READ source2 WRITE setSource2 NOTIFY source2Changed)
+ QML_ELEMENT
public:
explicit XorBlender(QQuickItem *parent = 0);
diff --git a/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg b/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg
new file mode 100644
index 0000000000..e7bbe62bf3
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc b/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc
new file mode 100644
index 0000000000..334291f990
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example scenegraph/vulkantextureimport
+ \title Scene Graph - Vulkan Texture Import
+ \ingroup qtquickexamples
+ \brief Shows how to use a texture created directly with use a texture created directly withulkan.
+
+ \image vulkantextureimport-example.jpg
+
+
+ The Vulkan Texture Import example shows how an application can import and
+ use a
+ \l{https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkImage.html}
+ {VkImage} in the Qt Quick scene. This provides an alternative to the \l{Scene Graph -
+ Vulkan Under QML}{underlay}, overlay, or \l{Scene Graph - Custom Rendering
+ with QSGRenderNode}{render node} approaches when it comes to integrating
+ native Vulkan rendering.
+
+ This example is equivalent in most ways to the \l{Scene Graph - Metal Texture Import}{Metal Texture Import}
+ example. The Vulkan rendering code is taken from the \l{Scene Graph - Vulkan Under QML}{Vulkan Under QML} example.
+
+ */
diff --git a/examples/quick/scenegraph/vulkantextureimport/main.cpp b/examples/quick/scenegraph/vulkantextureimport/main.cpp
new file mode 100644
index 0000000000..5dc28eb8a3
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/main.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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 <QGuiApplication>
+#include <QtQuick/QQuickView>
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
+
+ QQuickView view;
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:///scenegraph/vulkantextureimport/main.qml"));
+ view.resize(400, 400);
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/quick/scenegraph/vulkantextureimport/main.qml b/examples/quick/scenegraph/vulkantextureimport/main.qml
new file mode 100644
index 0000000000..91adf4c394
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/main.qml
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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
+//! [1]
+import VulkanTextureImport 1.0
+//! [1]
+
+Rectangle {
+ gradient: Gradient {
+ GradientStop { position: 0; color: "firebrick" }
+ GradientStop { position: 1; color: "black" }
+ }
+
+ //! [2]
+ CustomTextureItem {
+ id: renderer
+ anchors.fill: parent
+ anchors.margins: 10
+
+ SequentialAnimation on t {
+ NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
+ NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
+ loops: Animation.Infinite
+ running: true
+ }
+ //! [2]
+
+ transform: [
+ Rotation { id: rotation; axis.x: 0; axis.z: 0; axis.y: 1; angle: 0; origin.x: renderer.width / 2; origin.y: renderer.height / 2; },
+ Translate { id: txOut; x: -renderer.width / 2; y: -renderer.height / 2 },
+ Scale { id: scale; },
+ Translate { id: txIn; x: renderer.width / 2; y: renderer.height / 2 }
+ ]
+ }
+
+ SequentialAnimation {
+ PauseAnimation { duration: 5000 }
+ ParallelAnimation {
+ NumberAnimation { target: scale; property: "xScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack }
+ NumberAnimation { target: scale; property: "yScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack }
+ }
+ NumberAnimation { target: rotation; property: "angle"; to: 80; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: rotation; property: "angle"; to: -80; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: rotation; property: "angle"; to: 0; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: renderer; property: "opacity"; to: 0.1; duration: 1000; easing.type: Easing.InOutCubic }
+ PauseAnimation { duration: 1000 }
+ NumberAnimation { target: renderer; property: "opacity"; to: 1.0; duration: 1000; easing.type: Easing.InOutCubic }
+ ParallelAnimation {
+ NumberAnimation { target: scale; property: "xScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack }
+ NumberAnimation { target: scale; property: "yScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack }
+ }
+ running: true
+ loops: Animation.Infinite
+ }
+
+ Rectangle {
+ id: labelFrame
+ anchors.margins: -10
+ radius: 5
+ color: "white"
+ border.color: "black"
+ opacity: 0.5
+ anchors.fill: label
+ }
+
+ Text {
+ id: label
+ anchors.bottom: renderer.bottom
+ anchors.left: renderer.left
+ anchors.right: renderer.right
+ anchors.margins: 20
+ wrapMode: Text.WordWrap
+ text: "The squircle, using rendering code borrowed from the vulkanunderqml example, is rendered into a texture directly with Vulkan. The VkImage is then imported and used in a custom Qt Quick item."
+ }
+}
diff --git a/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv b/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv
new file mode 100644
index 0000000000..e4d13a871d
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv b/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv
new file mode 100644
index 0000000000..5df94a47e4
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp
new file mode 100644
index 0000000000..a4201c1dfa
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp
@@ -0,0 +1,823 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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 "vulkantextureimport.h"
+
+#include <QtGui/QScreen>
+#include <QtQuick/QQuickWindow>
+#include <QtQuick/QSGTextureProvider>
+#include <QtQuick/QSGSimpleTextureNode>
+
+#include <QVulkanInstance>
+#include <QVulkanFunctions>
+
+class CustomTextureNode : public QSGTextureProvider, public QSGSimpleTextureNode
+{
+ Q_OBJECT
+
+public:
+ CustomTextureNode(QQuickItem *item);
+ ~CustomTextureNode() override;
+
+ QSGTexture *texture() const override;
+
+ void sync();
+
+private slots:
+ void render();
+
+private:
+ enum Stage {
+ VertexStage,
+ FragmentStage
+ };
+ void prepareShader(Stage stage);
+ bool buildTexture(const QSize &size);
+ void freeTexture();
+ bool createRenderPass();
+ bool initialize();
+
+ QQuickItem *m_item;
+ QQuickWindow *m_window;
+ QSize m_size;
+ qreal m_dpr;
+
+ QByteArray m_vert;
+ QByteArray m_frag;
+
+ VkImage m_texture = VK_NULL_HANDLE;
+ VkDeviceMemory m_textureMemory = VK_NULL_HANDLE;
+ VkFramebuffer m_textureFramebuffer = VK_NULL_HANDLE;
+ VkImageView m_textureView = VK_NULL_HANDLE;
+
+ bool m_initialized = false;
+
+ float m_t;
+
+ VkPhysicalDevice m_physDev = VK_NULL_HANDLE;
+ VkDevice m_dev = VK_NULL_HANDLE;
+ QVulkanDeviceFunctions *m_devFuncs = nullptr;
+ QVulkanFunctions *m_funcs = nullptr;
+
+ VkBuffer m_vbuf = VK_NULL_HANDLE;
+ VkDeviceMemory m_vbufMem = VK_NULL_HANDLE;
+ VkBuffer m_ubuf = VK_NULL_HANDLE;
+ VkDeviceMemory m_ubufMem = VK_NULL_HANDLE;
+ VkDeviceSize m_allocPerUbuf = 0;
+
+ VkPipelineCache m_pipelineCache = VK_NULL_HANDLE;
+
+ VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
+ VkDescriptorSetLayout m_resLayout = VK_NULL_HANDLE;
+ VkPipeline m_pipeline = VK_NULL_HANDLE;
+
+ VkDescriptorPool m_descriptorPool = VK_NULL_HANDLE;
+ VkDescriptorSet m_ubufDescriptor = VK_NULL_HANDLE;
+
+ VkRenderPass m_renderPass = VK_NULL_HANDLE;
+};
+
+CustomTextureItem::CustomTextureItem()
+{
+ setFlag(ItemHasContents, true);
+}
+
+void CustomTextureItem::invalidateSceneGraph() // called on the render thread when the scenegraph is invalidated
+{
+ m_node = nullptr;
+}
+
+void CustomTextureItem::releaseResources() // called on the gui thread if the item is removed from scene
+{
+ m_node = nullptr;
+}
+
+QSGNode *CustomTextureItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
+{
+ CustomTextureNode *n = static_cast<CustomTextureNode *>(node);
+
+ if (!n && (width() <= 0 || height() <= 0))
+ return nullptr;
+
+ if (!n) {
+ m_node = new CustomTextureNode(this);
+ n = m_node;
+ }
+
+ m_node->sync();
+
+ n->setTextureCoordinatesTransform(QSGSimpleTextureNode::NoTransform);
+ n->setFiltering(QSGTexture::Linear);
+ n->setRect(0, 0, width(), height());
+
+ window()->update(); // ensure getting to beforeRendering() at some point
+
+ return n;
+}
+
+void CustomTextureItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+
+ if (newGeometry.size() != oldGeometry.size())
+ update();
+}
+
+void CustomTextureItem::setT(qreal t)
+{
+ if (t == m_t)
+ return;
+
+ m_t = t;
+ emit tChanged();
+
+ update();
+}
+
+CustomTextureNode::CustomTextureNode(QQuickItem *item)
+ : m_item(item)
+{
+ m_window = m_item->window();
+ connect(m_window, &QQuickWindow::beforeRendering, this, &CustomTextureNode::render);
+ connect(m_window, &QQuickWindow::screenChanged, this, [this]() {
+ if (m_window->effectiveDevicePixelRatio() != m_dpr)
+ m_item->update();
+ });
+}
+
+CustomTextureNode::~CustomTextureNode()
+{
+ m_devFuncs->vkDestroyBuffer(m_dev, m_vbuf, nullptr);
+ m_devFuncs->vkDestroyBuffer(m_dev, m_ubuf, nullptr);
+ m_devFuncs->vkFreeMemory(m_dev, m_vbufMem, nullptr);
+ m_devFuncs->vkFreeMemory(m_dev, m_ubufMem, nullptr);
+
+ m_devFuncs->vkDestroyPipelineCache(m_dev, m_pipelineCache, nullptr);
+ m_devFuncs->vkDestroyPipelineLayout(m_dev, m_pipelineLayout, nullptr);
+ m_devFuncs->vkDestroyPipeline(m_dev, m_pipeline, nullptr);
+
+ m_devFuncs->vkDestroyRenderPass(m_dev, m_renderPass, nullptr);
+
+ m_devFuncs->vkDestroyDescriptorSetLayout(m_dev, m_resLayout, nullptr);
+ m_devFuncs->vkDestroyDescriptorPool(m_dev, m_descriptorPool, nullptr);
+
+ delete texture();
+ freeTexture();
+}
+
+QSGTexture *CustomTextureNode::texture() const
+{
+ return QSGSimpleTextureNode::texture();
+}
+
+static const float vertices[] = {
+ -1, -1,
+ 1, -1,
+ -1, 1,
+ 1, 1
+};
+
+const int UBUF_SIZE = 4;
+
+
+bool CustomTextureNode::buildTexture(const QSize &size)
+{
+ VkImageCreateInfo imageInfo;
+ memset(&imageInfo, 0, sizeof(imageInfo));
+ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
+ imageInfo.flags = 0;
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
+ imageInfo.extent.width = uint32_t(size.width());
+ imageInfo.extent.height = uint32_t(size.height());
+ imageInfo.extent.depth = 1;
+ imageInfo.mipLevels = 1;
+ imageInfo.arrayLayers = 1;
+ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
+ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
+ imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
+
+ imageInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+ imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+
+ VkImage image = VK_NULL_HANDLE;
+ if (m_devFuncs->vkCreateImage(m_dev, &imageInfo, nullptr, &image) != VK_SUCCESS) {
+ qCritical("VulkanWrapper: failed to create image!");
+ return false;
+ }
+
+ m_texture = image;
+
+ VkMemoryRequirements memReq;
+ m_devFuncs->vkGetImageMemoryRequirements(m_dev, image, &memReq);
+
+ quint32 memIndex = 0;
+ VkPhysicalDeviceMemoryProperties physDevMemProps;
+ m_window->vulkanInstance()->functions()->vkGetPhysicalDeviceMemoryProperties(m_physDev, &physDevMemProps);
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (!(memReq.memoryTypeBits & (1 << i)))
+ continue;
+ memIndex = i;
+ }
+
+ VkMemoryAllocateInfo allocInfo = {
+ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ nullptr,
+ memReq.size,
+ memIndex
+ };
+
+ VkResult err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_textureMemory);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to allocate memory for linear image: %d", err);
+ return false;
+ }
+
+ err = m_devFuncs->vkBindImageMemory(m_dev, image, m_textureMemory, 0);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to bind linear image memory: %d", err);
+ return false;
+ }
+
+ VkImageViewCreateInfo viewInfo;
+ memset(&viewInfo, 0, sizeof(viewInfo));
+ viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+ viewInfo.image = image;
+ viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
+ viewInfo.format = imageInfo.format;
+ viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
+ viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
+ viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
+ viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
+ viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ viewInfo.subresourceRange.baseMipLevel = 0;
+ viewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
+ viewInfo.subresourceRange.baseArrayLayer = 0;
+ viewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
+
+ err = m_devFuncs->vkCreateImageView(m_dev, &viewInfo, nullptr, &m_textureView);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create render target image view: %d", err);
+ return false;
+ }
+
+ VkFramebufferCreateInfo fbInfo;
+ memset(&fbInfo, 0, sizeof(fbInfo));
+ fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ fbInfo.renderPass = m_renderPass;
+ fbInfo.attachmentCount = 1;
+ fbInfo.pAttachments = &m_textureView;
+ fbInfo.width = uint32_t(size.width());
+ fbInfo.height = uint32_t(size.height());
+ fbInfo.layers = 1;
+
+ err = m_devFuncs->vkCreateFramebuffer(m_dev, &fbInfo, nullptr, &m_textureFramebuffer);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create framebuffer: %d", err);
+ return false;
+ }
+ return true;
+}
+
+void CustomTextureNode::freeTexture()
+{
+ if (m_texture) {
+ m_devFuncs->vkDestroyFramebuffer(m_dev, m_textureFramebuffer, nullptr);
+ m_textureFramebuffer = VK_NULL_HANDLE;
+ m_devFuncs->vkFreeMemory(m_dev, m_textureMemory, nullptr);
+ m_textureMemory = VK_NULL_HANDLE;
+ m_devFuncs->vkDestroyImageView(m_dev, m_textureView, nullptr);
+ m_textureView = VK_NULL_HANDLE;
+ m_devFuncs->vkDestroyImage(m_dev, m_texture, nullptr);
+ m_texture = VK_NULL_HANDLE;
+ }
+}
+
+
+
+static inline VkDeviceSize aligned(VkDeviceSize v, VkDeviceSize byteAlign)
+{
+ return (v + byteAlign - 1) & ~(byteAlign - 1);
+}
+
+bool CustomTextureNode::createRenderPass()
+{
+ const VkFormat vkformat = VK_FORMAT_R8G8B8A8_UNORM;
+ const VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
+ VkAttachmentDescription colorAttDesc;
+ memset(&colorAttDesc, 0, sizeof(colorAttDesc));
+ colorAttDesc.format = vkformat;
+ colorAttDesc.samples = samples;
+ colorAttDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ colorAttDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ colorAttDesc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ colorAttDesc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ colorAttDesc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ colorAttDesc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ const VkAttachmentReference colorRef = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
+
+ VkSubpassDescription subpassDesc;
+ memset(&subpassDesc, 0, sizeof(subpassDesc));
+ subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
+ subpassDesc.colorAttachmentCount = 1;
+ subpassDesc.pColorAttachments = &colorRef;
+ subpassDesc.pDepthStencilAttachment = nullptr;
+ subpassDesc.pResolveAttachments = nullptr;
+
+ VkRenderPassCreateInfo rpInfo;
+ memset(&rpInfo, 0, sizeof(rpInfo));
+ rpInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
+ rpInfo.attachmentCount = 1;
+ rpInfo.pAttachments = &colorAttDesc;
+ rpInfo.subpassCount = 1;
+ rpInfo.pSubpasses = &subpassDesc;
+
+ VkResult err = m_devFuncs->vkCreateRenderPass(m_dev, &rpInfo, nullptr, &m_renderPass);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create renderpass: %d", err);
+ return false;
+ }
+
+ return true;
+}
+
+bool CustomTextureNode::initialize()
+{
+ const int framesInFlight = m_window->graphicsStateInfo().framesInFlight;
+ m_initialized = true;
+
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ QVulkanInstance *inst = reinterpret_cast<QVulkanInstance *>(
+ rif->getResource(m_window, QSGRendererInterface::VulkanInstanceResource));
+ Q_ASSERT(inst && inst->isValid());
+
+ m_physDev = *static_cast<VkPhysicalDevice *>(rif->getResource(m_window, QSGRendererInterface::PhysicalDeviceResource));
+ m_dev = *static_cast<VkDevice *>(rif->getResource(m_window, QSGRendererInterface::DeviceResource));
+ Q_ASSERT(m_physDev && m_dev);
+
+ m_devFuncs = inst->deviceFunctions(m_dev);
+ m_funcs = inst->functions();
+ Q_ASSERT(m_devFuncs && m_funcs);
+
+ createRenderPass();
+
+ VkPhysicalDeviceProperties physDevProps;
+ m_funcs->vkGetPhysicalDeviceProperties(m_physDev, &physDevProps);
+
+ VkPhysicalDeviceMemoryProperties physDevMemProps;
+ m_funcs->vkGetPhysicalDeviceMemoryProperties(m_physDev, &physDevMemProps);
+
+ VkBufferCreateInfo bufferInfo;
+ memset(&bufferInfo, 0, sizeof(bufferInfo));
+ bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
+ bufferInfo.size = sizeof(vertices);
+ bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
+ VkResult err = m_devFuncs->vkCreateBuffer(m_dev, &bufferInfo, nullptr, &m_vbuf);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create vertex buffer: %d", err);
+
+ VkMemoryRequirements memReq;
+ m_devFuncs->vkGetBufferMemoryRequirements(m_dev, m_vbuf, &memReq);
+ VkMemoryAllocateInfo allocInfo;
+ memset(&allocInfo, 0, sizeof(allocInfo));
+ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ allocInfo.allocationSize = memReq.size;
+
+ uint32_t memTypeIndex = uint32_t(-1);
+ const VkMemoryType *memType = physDevMemProps.memoryTypes;
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (memReq.memoryTypeBits & (1 << i)) {
+ if ((memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ && (memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ {
+ memTypeIndex = i;
+ break;
+ }
+ }
+ }
+ if (memTypeIndex == uint32_t(-1))
+ qFatal("Failed to find host visible and coherent memory type");
+
+ allocInfo.memoryTypeIndex = memTypeIndex;
+ err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_vbufMem);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate vertex buffer memory of size %u: %d", uint(allocInfo.allocationSize), err);
+
+ void *p = nullptr;
+ err = m_devFuncs->vkMapMemory(m_dev, m_vbufMem, 0, allocInfo.allocationSize, 0, &p);
+ if (err != VK_SUCCESS || !p)
+ qFatal("Failed to map vertex buffer memory: %d", err);
+ memcpy(p, vertices, sizeof(vertices));
+ m_devFuncs->vkUnmapMemory(m_dev, m_vbufMem);
+ err = m_devFuncs->vkBindBufferMemory(m_dev, m_vbuf, m_vbufMem, 0);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to bind vertex buffer memory: %d", err);
+
+ m_allocPerUbuf = aligned(UBUF_SIZE, physDevProps.limits.minUniformBufferOffsetAlignment);
+
+ bufferInfo.size = framesInFlight * m_allocPerUbuf;
+ bufferInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
+ err = m_devFuncs->vkCreateBuffer(m_dev, &bufferInfo, nullptr, &m_ubuf);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create uniform buffer: %d", err);
+ m_devFuncs->vkGetBufferMemoryRequirements(m_dev, m_ubuf, &memReq);
+ memTypeIndex = -1;
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (memReq.memoryTypeBits & (1 << i)) {
+ if ((memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ && (memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ {
+ memTypeIndex = i;
+ break;
+ }
+ }
+ }
+ if (memTypeIndex == uint32_t(-1))
+ qFatal("Failed to find host visible and coherent memory type");
+
+ allocInfo.allocationSize = qMax(memReq.size, framesInFlight * m_allocPerUbuf);
+ allocInfo.memoryTypeIndex = memTypeIndex;
+ err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_ubufMem);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate uniform buffer memory of size %u: %d", uint(allocInfo.allocationSize), err);
+
+ err = m_devFuncs->vkBindBufferMemory(m_dev, m_ubuf, m_ubufMem, 0);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to bind uniform buffer memory: %d", err);
+
+ // Now onto the pipeline.
+
+ VkPipelineCacheCreateInfo pipelineCacheInfo;
+ memset(&pipelineCacheInfo, 0, sizeof(pipelineCacheInfo));
+ pipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
+ err = m_devFuncs->vkCreatePipelineCache(m_dev, &pipelineCacheInfo, nullptr, &m_pipelineCache);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create pipeline cache: %d", err);
+
+ VkDescriptorSetLayoutBinding descLayoutBinding;
+ memset(&descLayoutBinding, 0, sizeof(descLayoutBinding));
+ descLayoutBinding.binding = 0;
+ descLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
+ descLayoutBinding.descriptorCount = 1;
+ descLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
+ VkDescriptorSetLayoutCreateInfo layoutInfo;
+ memset(&layoutInfo, 0, sizeof(layoutInfo));
+ layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
+ layoutInfo.bindingCount = 1;
+ layoutInfo.pBindings = &descLayoutBinding;
+ err = m_devFuncs->vkCreateDescriptorSetLayout(m_dev, &layoutInfo, nullptr, &m_resLayout);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create descriptor set layout: %d", err);
+
+ VkPipelineLayoutCreateInfo pipelineLayoutInfo;
+ memset(&pipelineLayoutInfo, 0, sizeof(pipelineLayoutInfo));
+ pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
+ pipelineLayoutInfo.setLayoutCount = 1;
+ pipelineLayoutInfo.pSetLayouts = &m_resLayout;
+ err = m_devFuncs->vkCreatePipelineLayout(m_dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
+ if (err != VK_SUCCESS)
+ qWarning("Failed to create pipeline layout: %d", err);
+
+ VkGraphicsPipelineCreateInfo pipelineInfo;
+ memset(&pipelineInfo, 0, sizeof(pipelineInfo));
+ pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
+
+ VkShaderModuleCreateInfo shaderInfo;
+ memset(&shaderInfo, 0, sizeof(shaderInfo));
+ shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
+ shaderInfo.codeSize = m_vert.size();
+ shaderInfo.pCode = reinterpret_cast<const quint32 *>(m_vert.constData());
+ VkShaderModule vertShaderModule;
+ err = m_devFuncs->vkCreateShaderModule(m_dev, &shaderInfo, nullptr, &vertShaderModule);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create vertex shader module: %d", err);
+
+ shaderInfo.codeSize = m_frag.size();
+ shaderInfo.pCode = reinterpret_cast<const quint32 *>(m_frag.constData());
+ VkShaderModule fragShaderModule;
+ err = m_devFuncs->vkCreateShaderModule(m_dev, &shaderInfo, nullptr, &fragShaderModule);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create fragment shader module: %d", err);
+
+ VkPipelineShaderStageCreateInfo stageInfo[2];
+ memset(&stageInfo, 0, sizeof(stageInfo));
+ stageInfo[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ stageInfo[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
+ stageInfo[0].module = vertShaderModule;
+ stageInfo[0].pName = "main";
+ stageInfo[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ stageInfo[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
+ stageInfo[1].module = fragShaderModule;
+ stageInfo[1].pName = "main";
+ pipelineInfo.stageCount = 2;
+ pipelineInfo.pStages = stageInfo;
+
+ VkVertexInputBindingDescription vertexBinding = {
+ 0, // binding
+ 2 * sizeof(float), // stride
+ VK_VERTEX_INPUT_RATE_VERTEX
+ };
+ VkVertexInputAttributeDescription vertexAttr = {
+ 0, // location
+ 0, // binding
+ VK_FORMAT_R32G32_SFLOAT, // 'vertices' only has 2 floats per vertex
+ 0 // offset
+ };
+ VkPipelineVertexInputStateCreateInfo vertexInputInfo;
+ memset(&vertexInputInfo, 0, sizeof(vertexInputInfo));
+ vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+ vertexInputInfo.vertexBindingDescriptionCount = 1;
+ vertexInputInfo.pVertexBindingDescriptions = &vertexBinding;
+ vertexInputInfo.vertexAttributeDescriptionCount = 1;
+ vertexInputInfo.pVertexAttributeDescriptions = &vertexAttr;
+ pipelineInfo.pVertexInputState = &vertexInputInfo;
+
+ VkDynamicState dynStates[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
+ VkPipelineDynamicStateCreateInfo dynamicInfo;
+ memset(&dynamicInfo, 0, sizeof(dynamicInfo));
+ dynamicInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
+ dynamicInfo.dynamicStateCount = 2;
+ dynamicInfo.pDynamicStates = dynStates;
+ pipelineInfo.pDynamicState = &dynamicInfo;
+
+ VkPipelineViewportStateCreateInfo viewportInfo;
+ memset(&viewportInfo, 0, sizeof(viewportInfo));
+ viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
+ viewportInfo.viewportCount = viewportInfo.scissorCount = 1;
+ pipelineInfo.pViewportState = &viewportInfo;
+
+ VkPipelineInputAssemblyStateCreateInfo iaInfo;
+ memset(&iaInfo, 0, sizeof(iaInfo));
+ iaInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
+ iaInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
+ pipelineInfo.pInputAssemblyState = &iaInfo;
+
+ VkPipelineRasterizationStateCreateInfo rsInfo;
+ memset(&rsInfo, 0, sizeof(rsInfo));
+ rsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
+ rsInfo.lineWidth = 1.0f;
+ pipelineInfo.pRasterizationState = &rsInfo;
+
+ VkPipelineMultisampleStateCreateInfo msInfo;
+ memset(&msInfo, 0, sizeof(msInfo));
+ msInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
+ msInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ pipelineInfo.pMultisampleState = &msInfo;
+
+ VkPipelineDepthStencilStateCreateInfo dsInfo;
+ memset(&dsInfo, 0, sizeof(dsInfo));
+ dsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
+ pipelineInfo.pDepthStencilState = &dsInfo;
+
+ // SrcAlpha, One
+ VkPipelineColorBlendStateCreateInfo blendInfo;
+ memset(&blendInfo, 0, sizeof(blendInfo));
+ blendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
+ VkPipelineColorBlendAttachmentState blend;
+ memset(&blend, 0, sizeof(blend));
+ blend.blendEnable = true;
+ blend.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ blend.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
+ blend.colorBlendOp = VK_BLEND_OP_ADD;
+ blend.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ blend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
+ blend.alphaBlendOp = VK_BLEND_OP_ADD;
+ blend.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT
+ | VK_COLOR_COMPONENT_A_BIT;
+ blendInfo.attachmentCount = 1;
+ blendInfo.pAttachments = &blend;
+ pipelineInfo.pColorBlendState = &blendInfo;
+
+ pipelineInfo.layout = m_pipelineLayout;
+
+ pipelineInfo.renderPass = m_renderPass;
+
+ err = m_devFuncs->vkCreateGraphicsPipelines(m_dev, m_pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline);
+
+ m_devFuncs->vkDestroyShaderModule(m_dev, vertShaderModule, nullptr);
+ m_devFuncs->vkDestroyShaderModule(m_dev, fragShaderModule, nullptr);
+
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create graphics pipeline: %d", err);
+
+ // Now just need some descriptors.
+ VkDescriptorPoolSize descPoolSizes[] = {
+ { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1 }
+ };
+ VkDescriptorPoolCreateInfo descPoolInfo;
+ memset(&descPoolInfo, 0, sizeof(descPoolInfo));
+ descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+ descPoolInfo.flags = 0; // won't use vkFreeDescriptorSets
+ descPoolInfo.maxSets = 1;
+ descPoolInfo.poolSizeCount = sizeof(descPoolSizes) / sizeof(descPoolSizes[0]);
+ descPoolInfo.pPoolSizes = descPoolSizes;
+ err = m_devFuncs->vkCreateDescriptorPool(m_dev, &descPoolInfo, nullptr, &m_descriptorPool);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create descriptor pool: %d", err);
+
+ VkDescriptorSetAllocateInfo descAllocInfo;
+ memset(&descAllocInfo, 0, sizeof(descAllocInfo));
+ descAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
+ descAllocInfo.descriptorPool = m_descriptorPool;
+ descAllocInfo.descriptorSetCount = 1;
+ descAllocInfo.pSetLayouts = &m_resLayout;
+ err = m_devFuncs->vkAllocateDescriptorSets(m_dev, &descAllocInfo, &m_ubufDescriptor);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate descriptor set");
+
+ VkWriteDescriptorSet writeInfo;
+ memset(&writeInfo, 0, sizeof(writeInfo));
+ writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ writeInfo.dstSet = m_ubufDescriptor;
+ writeInfo.dstBinding = 0;
+ writeInfo.descriptorCount = 1;
+ writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
+ VkDescriptorBufferInfo bufInfo;
+ bufInfo.buffer = m_ubuf;
+ bufInfo.offset = 0; // dynamic offset is used so this is ignored
+ bufInfo.range = UBUF_SIZE;
+ writeInfo.pBufferInfo = &bufInfo;
+
+ m_devFuncs->vkUpdateDescriptorSets(m_dev, 1, &writeInfo, 0, nullptr);
+ return true;
+}
+
+void CustomTextureNode::sync()
+{
+ m_dpr = m_window->effectiveDevicePixelRatio();
+ const QSize newSize = m_window->size() * m_dpr;
+ bool needsNew = false;
+
+ if (!m_initialized) {
+ prepareShader(VertexStage);
+ prepareShader(FragmentStage);
+ initialize();
+ m_initialized = true;
+ }
+
+ if (!texture())
+ needsNew = true;
+
+ if (newSize != m_size) {
+ needsNew = true;
+ m_size = newSize;
+ }
+
+ if (needsNew) {
+ delete texture();
+ freeTexture();
+ buildTexture(m_size);
+ QSGTexture *wrapper = m_window->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture,
+ &m_texture,
+ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
+ m_size);
+ setTexture(wrapper);
+ }
+
+ m_t = float(static_cast<CustomTextureItem *>(m_item)->t());
+}
+
+void CustomTextureNode::render()
+{
+ if (!m_initialized)
+ return;
+
+ VkResult err = VK_SUCCESS;
+
+ uint currentFrameSlot = m_window->graphicsStateInfo().currentFrameSlot;
+ VkDeviceSize ubufOffset = currentFrameSlot * m_allocPerUbuf;
+ void *p = nullptr;
+ err = m_devFuncs->vkMapMemory(m_dev, m_ubufMem, ubufOffset, m_allocPerUbuf, 0, &p);
+ if (err != VK_SUCCESS || !p)
+ qFatal("Failed to map uniform buffer memory: %d", err);
+ float t = m_t;
+ memcpy(p, &t, 4);
+ m_devFuncs->vkUnmapMemory(m_dev, m_ubufMem);
+
+ VkClearValue clearColor = {{ {0, 0, 0, 1} }};
+
+ VkRenderPassBeginInfo rpBeginInfo = {};
+ rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+ rpBeginInfo.renderPass = m_renderPass;
+ rpBeginInfo.framebuffer = m_textureFramebuffer;
+ rpBeginInfo.renderArea.extent.width = m_size.width();
+ rpBeginInfo.renderArea.extent.height = m_size.height();
+ rpBeginInfo.clearValueCount = 1;
+ rpBeginInfo.pClearValues = &clearColor;
+
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ VkCommandBuffer cmdBuf = *reinterpret_cast<VkCommandBuffer *>(
+ rif->getResource(m_window, QSGRendererInterface::CommandListResource));
+
+ m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
+
+ m_devFuncs->vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline);
+
+ VkDeviceSize vbufOffset = 0;
+ m_devFuncs->vkCmdBindVertexBuffers(cmdBuf, 0, 1, &m_vbuf, &vbufOffset);
+
+ uint32_t dynamicOffset = m_allocPerUbuf * currentFrameSlot;
+ m_devFuncs->vkCmdBindDescriptorSets(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1,
+ &m_ubufDescriptor, 1, &dynamicOffset);
+
+ VkViewport vp = { 0, 0, float(m_size.width()), float(m_size.height()), 0.0f, 1.0f };
+ m_devFuncs->vkCmdSetViewport(cmdBuf, 0, 1, &vp);
+ VkRect2D scissor = { { 0, 0 }, { uint32_t(m_size.width()), uint32_t(m_size.height()) } };
+ m_devFuncs->vkCmdSetScissor(cmdBuf, 0, 1, &scissor);
+
+ m_devFuncs->vkCmdDraw(cmdBuf, 4, 1, 0, 0);
+ m_devFuncs->vkCmdEndRenderPass(cmdBuf);
+
+ // Memory barrier before the texture can be used as a source.
+ // Since we are not using a sub-pass, we have to do this explicitly.
+
+ VkImageMemoryBarrier imageTransitionBarrier = {};
+ imageTransitionBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ imageTransitionBarrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
+ imageTransitionBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
+ imageTransitionBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ imageTransitionBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ imageTransitionBarrier.image = m_texture;
+ imageTransitionBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ imageTransitionBarrier.subresourceRange.levelCount = imageTransitionBarrier.subresourceRange.layerCount = 1;
+
+ m_devFuncs->vkCmdPipelineBarrier(cmdBuf,
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+ 0, 0, nullptr, 0, nullptr,
+ 1, &imageTransitionBarrier);
+}
+
+void CustomTextureNode::prepareShader(Stage stage)
+{
+ QString filename;
+ if (stage == VertexStage) {
+ filename = QLatin1String(":/scenegraph/vulkantextureimport/squircle.vert.spv");
+ } else {
+ Q_ASSERT(stage == FragmentStage);
+ filename = QLatin1String(":/scenegraph/vulkantextureimport/squircle.frag.spv");
+ }
+ QFile f(filename);
+ if (!f.open(QIODevice::ReadOnly))
+ qFatal("Failed to read shader %s", qPrintable(filename));
+
+ const QByteArray contents = f.readAll();
+
+ if (stage == VertexStage) {
+ m_vert = contents;
+ Q_ASSERT(!m_vert.isEmpty());
+ } else {
+ m_frag = contents;
+ Q_ASSERT(!m_frag.isEmpty());
+ }
+}
+
+#include "vulkantextureimport.moc"
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h
new file mode 100644
index 0000000000..b8c13b44f6
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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 VULKANTEXTUREIMPORT_H
+#define VULKANTEXTUREIMPORT_H
+
+#include <QtQuick/QQuickItem>
+
+class CustomTextureNode;
+
+//! [1]
+class CustomTextureItem : public QQuickItem
+{
+ Q_OBJECT
+ Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+ QML_ELEMENT
+
+public:
+ CustomTextureItem();
+
+ qreal t() const { return m_t; }
+ void setT(qreal t);
+
+signals:
+ void tChanged();
+
+protected:
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
+
+private slots:
+ void invalidateSceneGraph();
+
+private:
+ void releaseResources() override;
+
+ CustomTextureNode *m_node = nullptr;
+ qreal m_t = 0;
+};
+//! [1]
+
+#endif // VULKANTEXTUREIMPORT_H
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro
new file mode 100644
index 0000000000..11e422ecad
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro
@@ -0,0 +1,13 @@
+!qtConfig(vulkan): error("This example requires Qt built with Vulkan support")
+
+QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = VulkanTextureImport
+QML_IMPORT_MAJOR_VERSION = 1
+
+HEADERS += vulkantextureimport.h
+SOURCES += vulkantextureimport.cpp main.cpp
+RESOURCES += vulkantextureimport.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/vulkantextureimport
+INSTALLS += target
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc
new file mode 100644
index 0000000000..a1aec6c950
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/scenegraph/vulkantextureimport">
+ <file>main.qml</file>
+ <file>squircle.vert.spv</file>
+ <file>squircle.frag.spv</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/scenegraph/vulkanunderqml/main.cpp b/examples/quick/scenegraph/vulkanunderqml/main.cpp
index a04497b1d6..6ed0efacdd 100644
--- a/examples/quick/scenegraph/vulkanunderqml/main.cpp
+++ b/examples/quick/scenegraph/vulkanunderqml/main.cpp
@@ -50,14 +50,11 @@
#include <QGuiApplication>
#include <QtQuick/QQuickView>
-#include "vulkansquircle.h"
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- qmlRegisterType<VulkanSquircle>("VulkanUnderQML", 1, 0, "VulkanSquircle");
-
// This example needs Vulkan. It will not run otherwise.
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
diff --git a/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.h b/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.h
index 7e65d01a15..16feeacb5b 100644
--- a/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.h
+++ b/examples/quick/scenegraph/vulkanunderqml/vulkansquircle.h
@@ -59,6 +59,7 @@ class VulkanSquircle : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+ QML_ELEMENT
public:
VulkanSquircle();
diff --git a/examples/quick/scenegraph/vulkanunderqml/vulkanunderqml.pro b/examples/quick/scenegraph/vulkanunderqml/vulkanunderqml.pro
index 9ea57b91c3..8f7ea5861d 100644
--- a/examples/quick/scenegraph/vulkanunderqml/vulkanunderqml.pro
+++ b/examples/quick/scenegraph/vulkanunderqml/vulkanunderqml.pro
@@ -1,6 +1,9 @@
!qtConfig(vulkan): error("This example requires Qt built with Vulkan support")
QT += qml quick
+CONFIG += qmltypes
+QML_IMPORT_NAME = VulkanUnderQML
+QML_IMPORT_MAJOR_VERSION = 1
HEADERS += vulkansquircle.h
SOURCES += vulkansquircle.cpp main.cpp
diff --git a/examples/quick/shadereffects/content/shaders/+qsb/blur.frag b/examples/quick/shadereffects/content/shaders/+qsb/blur.frag
index 1c79359297..d29b2d4365 100644
--- a/examples/quick/shadereffects/content/shaders/+qsb/blur.frag
+++ b/examples/quick/shadereffects/content/shaders/+qsb/blur.frag
Binary files differ
diff --git a/examples/quick/shadereffects/content/shaders/+qsb/colorize.frag b/examples/quick/shadereffects/content/shaders/+qsb/colorize.frag
index 45c5301f31..58bb5aaa8e 100644
--- a/examples/quick/shadereffects/content/shaders/+qsb/colorize.frag
+++ b/examples/quick/shadereffects/content/shaders/+qsb/colorize.frag
Binary files differ
diff --git a/examples/quick/shadereffects/content/shaders/+qsb/genie.vert b/examples/quick/shadereffects/content/shaders/+qsb/genie.vert
index dd94129cf7..540cb6a85b 100644
--- a/examples/quick/shadereffects/content/shaders/+qsb/genie.vert
+++ b/examples/quick/shadereffects/content/shaders/+qsb/genie.vert
Binary files differ
diff --git a/examples/quick/shadereffects/content/shaders/+qsb/outline.frag b/examples/quick/shadereffects/content/shaders/+qsb/outline.frag
index 470e2bd6e6..633fe0f926 100644
--- a/examples/quick/shadereffects/content/shaders/+qsb/outline.frag
+++ b/examples/quick/shadereffects/content/shaders/+qsb/outline.frag
Binary files differ
diff --git a/examples/quick/shadereffects/content/shaders/+qsb/shadow.frag b/examples/quick/shadereffects/content/shaders/+qsb/shadow.frag
index 128af21daa..8059fab6ac 100644
--- a/examples/quick/shadereffects/content/shaders/+qsb/shadow.frag
+++ b/examples/quick/shadereffects/content/shaders/+qsb/shadow.frag
Binary files differ
diff --git a/examples/quick/shadereffects/content/shaders/+qsb/wobble.frag b/examples/quick/shadereffects/content/shaders/+qsb/wobble.frag
index 9b27ae87cb..85fb453659 100644
--- a/examples/quick/shadereffects/content/shaders/+qsb/wobble.frag
+++ b/examples/quick/shadereffects/content/shaders/+qsb/wobble.frag
Binary files differ
diff --git a/examples/quick/shapes/content/item18.qml b/examples/quick/shapes/content/item18.qml
new file mode 100644
index 0000000000..192438408d
--- /dev/null
+++ b/examples/quick/shapes/content/item18.qml
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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.15
+import QtQuick.Shapes 1.0
+
+Rectangle {
+ color: "lightGray"
+
+ Shape {
+ anchors.centerIn: parent
+ width: 200
+ height: 100
+
+ ShapePath {
+ id: capTest
+ strokeColor: "black"
+ strokeWidth: 1
+ fillColor: "black"
+
+ PathText { x: 0; y: 0; font.family: "Arial"; font.pixelSize: 150; text: "Qt!" }
+ }
+ }
+}
diff --git a/examples/quick/shapes/content/shapegallery.qml b/examples/quick/shapes/content/shapegallery.qml
index 86445e25c2..e5a7c51483 100644
--- a/examples/quick/shapes/content/shapegallery.qml
+++ b/examples/quick/shapes/content/shapegallery.qml
@@ -130,6 +130,10 @@ Rectangle {
name: "Tiger"
shapeUrl: "item17.qml"
}
+ ListElement {
+ name: "Text"
+ shapeUrl: "item18.qml"
+ }
}
property int gridSpacing: 10
diff --git a/examples/quick/shapes/shapes.pro b/examples/quick/shapes/shapes.pro
index ff6fa422fb..f99d941804 100644
--- a/examples/quick/shapes/shapes.pro
+++ b/examples/quick/shapes/shapes.pro
@@ -24,7 +24,8 @@ OTHER_FILES += content/main.qml \
content/item13.qml \
content/item14.qml \
content/item15.qml \
- content/item17.qml
+ content/item17.qml \
+ content/item18.qml
target.path = $$[QT_INSTALL_EXAMPLES]/quick/shapes
INSTALLS += target
diff --git a/examples/quick/shapes/shapes.qrc b/examples/quick/shapes/shapes.qrc
index e03c0e8a0a..6de463dd33 100644
--- a/examples/quick/shapes/shapes.qrc
+++ b/examples/quick/shapes/shapes.qrc
@@ -28,5 +28,6 @@
<file alias="item14.qml">content/item14.qml</file>
<file alias="item15.qml">content/item15.qml</file>
<file alias="item17.qml">content/item17.qml</file>
+ <file alias="item18.qml">content/item18.qml</file>
</qresource>
</RCC>
diff --git a/examples/quick/shared/FlickrRssModel.qml b/examples/quick/shared/FlickrRssModel.qml
index cee4022bf0..2fb4412ba1 100644
--- a/examples/quick/shared/FlickrRssModel.qml
+++ b/examples/quick/shared/FlickrRssModel.qml
@@ -63,10 +63,16 @@ ListModel {
var xhr = new XMLHttpRequest;
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
+
+ if (xhr.status !== 200) {
+ console.log("Failed to get images from flickr. status code: " + xhr.status);
+ return;
+ }
+
var jsonText = xhr.responseText;
var objArray = JSON.parse(jsonText.replace(/\'/g,"'"))
if (objArray.errors !== undefined)
- console.log(lCategory, "Error fetching tweets: " + imageItems.errors[0].message)
+ console.log("Error fetching tweets: " + objArray.errors[0].message)
else {
for (var key in objArray.items) {
var rssItem = objArray.items[key];
diff --git a/examples/quick/shared/LauncherList.qml b/examples/quick/shared/LauncherList.qml
index 9859b5b635..cb13ec4372 100644
--- a/examples/quick/shared/LauncherList.qml
+++ b/examples/quick/shared/LauncherList.qml
@@ -48,6 +48,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
+import QtQml 2.12
+import QtQml.Models 2.12
import QtQuick 2.12
Rectangle {
@@ -75,6 +78,7 @@ Rectangle {
id: launcherList
clip: true
delegate: SimpleLauncherDelegate{
+ required property url url
onClicked: root.showExample(url)
}
model: ListModel {id:myModel}
diff --git a/examples/quick/shared/SimpleLauncherDelegate.qml b/examples/quick/shared/SimpleLauncherDelegate.qml
index 75aecf262c..dd29b8b821 100644
--- a/examples/quick/shared/SimpleLauncherDelegate.qml
+++ b/examples/quick/shared/SimpleLauncherDelegate.qml
@@ -55,18 +55,21 @@ Rectangle {
width: ListView.view.width
height: button.implicitHeight + 22
+ required property string name
+ required property string description
+
signal clicked()
gradient: Gradient {
GradientStop {
position: 0
Behavior on color {ColorAnimation { duration: 100 }}
- color: button.pressed ? "#e0e0e0" : "#fff"
+ color: tapHandler.pressed ? "#e0e0e0" : "#fff"
}
GradientStop {
position: 1
Behavior on color {ColorAnimation { duration: 100 }}
- color: button.pressed ? "#e0e0e0" : button.containsMouse ? "#f5f5f5" : "#eee"
+ color: tapHandler.pressed ? "#e0e0e0" : button.containsMouse ? "#f5f5f5" : "#eee"
}
}
@@ -110,7 +113,7 @@ Rectangle {
anchors.leftMargin: 10
anchors.right: parent.right
anchors.rightMargin: 10
- text: name
+ text: container.name
color: "black"
font.pixelSize: 22
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
@@ -122,7 +125,7 @@ Rectangle {
id: buttonLabel2
anchors.left: parent.left
anchors.leftMargin: 10
- text: description
+ text: container.description
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
color: "#666"
font.pixelSize: 12
diff --git a/examples/quick/shared/TabSet.qml b/examples/quick/shared/TabSet.qml
index 9e2759c3ec..ab8476ad44 100644
--- a/examples/quick/shared/TabSet.qml
+++ b/examples/quick/shared/TabSet.qml
@@ -78,6 +78,7 @@ Item {
Repeater {
model: stack.children.length
delegate: Rectangle {
+ required property int index
width: tabWidget.width / stack.children.length
height: Math.max(Screen.pixelDensity * 7, label.implicitHeight * 1.2)
@@ -90,18 +91,18 @@ Item {
anchors { fill: parent; leftMargin: 2; topMargin: 5; rightMargin: 1 }
border { left: 7; right: 7 }
source: "images/tab.png"
- visible: tabWidget.current == index
+ visible: tabWidget.current == parent.index
}
Text {
id: label
horizontalAlignment: Qt.AlignHCenter; verticalAlignment: Qt.AlignVCenter
anchors.fill: parent
- text: stack.children[index].title
+ text: stack.children[parent.index].title
elide: Text.ElideRight
- font.bold: tabWidget.current == index
+ font.bold: tabWidget.current == parent.index
}
TapHandler {
- onTapped: tabWidget.current = index
+ onTapped: tabWidget.current = parent.index
}
}
}
diff --git a/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc b/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc
index 069513636a..b61ba90a58 100644
--- a/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc
+++ b/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc
@@ -50,9 +50,6 @@
the view should be scrolled to.
\snippet tableview/gameoflife/main.qml model
- The model that we use is a custom C++ class that we register
- in the QML system:
- \snippet tableview/gameoflife/main.cpp registertype
\section1 The C++ Model
@@ -61,7 +58,8 @@
used as the model of our TableView component. Therefore, it needs to
implement some functions so the TableView component can interact with
the model. As you can see in the \c private part of the class, the model
- uses a fixed-size array to store the current state of all the cells.
+ uses a fixed-size array to store the current state of all the cells. We
+ also use the QML_ELEMENT macro in order to expose the class to QML.
\snippet tableview/gameoflife/gameoflifemodel.cpp modelsize
Here, the \c rowCount and \c columnCount methods are implemented so
diff --git a/examples/quick/tableview/gameoflife/gameoflife.pro b/examples/quick/tableview/gameoflife/gameoflife.pro
index 98050b0d79..9c47a9b530 100644
--- a/examples/quick/tableview/gameoflife/gameoflife.pro
+++ b/examples/quick/tableview/gameoflife/gameoflife.pro
@@ -1,6 +1,11 @@
TEMPLATE = app
QT += quick qml
+
+CONFIG += qmltypes
+QML_IMPORT_NAME = GameOfLifeModel
+QML_IMPORT_MAJOR_VERSION = 1
+
SOURCES += \
main.cpp \
gameoflifemodel.cpp
diff --git a/examples/quick/tableview/gameoflife/gameoflifemodel.h b/examples/quick/tableview/gameoflife/gameoflifemodel.h
index 3ea1469861..161e0b2cfc 100644
--- a/examples/quick/tableview/gameoflife/gameoflifemodel.h
+++ b/examples/quick/tableview/gameoflife/gameoflifemodel.h
@@ -54,11 +54,13 @@
#include <array>
#include <QAbstractTableModel>
#include <QPoint>
+#include <QtQml/qqml.h>
//! [modelclass]
class GameOfLifeModel : public QAbstractTableModel
{
Q_OBJECT
+ QML_ELEMENT
Q_ENUMS(Roles)
public:
diff --git a/examples/quick/tableview/gameoflife/main.cpp b/examples/quick/tableview/gameoflife/main.cpp
index 5101880b06..1500efdcca 100644
--- a/examples/quick/tableview/gameoflife/main.cpp
+++ b/examples/quick/tableview/gameoflife/main.cpp
@@ -58,10 +58,6 @@ int main(int argc, char *argv[])
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
- //! [registertype]
- qmlRegisterType<GameOfLifeModel>("GameOfLifeModel", 1, 0, "GameOfLifeModel");
- //! [registertype]
-
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
diff --git a/examples/quick/tableview/gameoflife/main.qml b/examples/quick/tableview/gameoflife/main.qml
index 90be69b9c0..fb3195892f 100644
--- a/examples/quick/tableview/gameoflife/main.qml
+++ b/examples/quick/tableview/gameoflife/main.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.12
import QtQuick 2.12
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
@@ -81,11 +82,14 @@ ApplicationWindow {
implicitWidth: 15
implicitHeight: 15
- color: model.value ? "#f3f3f4" : "#b5b7bf"
+ required property var model
+ required property bool value
+
+ color: value ? "#f3f3f4" : "#b5b7bf"
MouseArea {
anchors.fill: parent
- onClicked: model.value = !model.value
+ onClicked: parent.model.value = !parent.value
}
}
//! [tableview]
diff --git a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc
index 9e199a5347..88b28769cd 100644
--- a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc
+++ b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc
@@ -42,6 +42,7 @@
TableView.
We use the \l{The Property System}{Qt Property System} and a source property
as \c QString to set the path of the image.
+ We also add the QML_ELEMENT macro to expose the model to QML.
\snippet tableview/pixelator/imagemodel.cpp setsource
@@ -59,11 +60,6 @@
When we call this function with the display role, we return the pixel's
gray value.
- \snippet tableview/pixelator/main.cpp registertype
-
- We need to register our model in the QML type system to be able to use it
- from the QML side.
-
\snippet tableview/pixelator/main.qml pixelcomponent
Each pixel in the \c TableView is displayed via a delegate component.
diff --git a/examples/quick/tableview/pixelator/imagemodel.h b/examples/quick/tableview/pixelator/imagemodel.h
index bf0ec90da4..de8ad7cd8d 100644
--- a/examples/quick/tableview/pixelator/imagemodel.h
+++ b/examples/quick/tableview/pixelator/imagemodel.h
@@ -53,12 +53,14 @@
#include <QAbstractTableModel>
#include <QImage>
+#include <QtQml/qqml.h>
//! [model]
class ImageModel : public QAbstractTableModel
{
Q_OBJECT
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
+ QML_ELEMENT
public:
ImageModel(QObject *parent = nullptr);
diff --git a/examples/quick/tableview/pixelator/main.cpp b/examples/quick/tableview/pixelator/main.cpp
index c57039556a..c07f43dc27 100644
--- a/examples/quick/tableview/pixelator/main.cpp
+++ b/examples/quick/tableview/pixelator/main.cpp
@@ -59,10 +59,6 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
- //! [registertype]
- qmlRegisterType<ImageModel>("ImageModel", 1, 0, "ImageModel");
- //! [registertype]
-
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
diff --git a/examples/quick/tableview/pixelator/main.qml b/examples/quick/tableview/pixelator/main.qml
index 38a25f439f..a5edefae90 100644
--- a/examples/quick/tableview/pixelator/main.qml
+++ b/examples/quick/tableview/pixelator/main.qml
@@ -65,7 +65,9 @@ Window {
id: pixelDelegate
Item {
- readonly property real gray: model.display / 255.0
+ required property real display
+
+ readonly property real gray: display / 255.0
readonly property real size: 16
implicitWidth: size
@@ -77,7 +79,7 @@ Window {
id: rect
anchors.centerIn: parent
color: "#09102b"
- radius: size - gray * size
+ radius: parent.size - parent.gray * parent.size
implicitWidth: radius
implicitHeight: radius
//! [rectshape]
diff --git a/examples/quick/tableview/pixelator/pixelator.pro b/examples/quick/tableview/pixelator/pixelator.pro
index 6c863cb304..f27303b56b 100644
--- a/examples/quick/tableview/pixelator/pixelator.pro
+++ b/examples/quick/tableview/pixelator/pixelator.pro
@@ -5,6 +5,10 @@ HEADERS += imagemodel.h
SOURCES += main.cpp \
imagemodel.cpp
+CONFIG += qmltypes
+QML_IMPORT_NAME = ImageModel
+QML_IMPORT_MAJOR_VERSION = 1
+
RESOURCES += qt.png main.qml
target.path = $$[QT_INSTALL_EXAMPLES]/quick/tableview/pixelator
diff --git a/examples/quick/text/fonts/availableFonts.qml b/examples/quick/text/fonts/availableFonts.qml
index ea3bff22b8..41dbae0021 100644
--- a/examples/quick/text/fonts/availableFonts.qml
+++ b/examples/quick/text/fonts/availableFonts.qml
@@ -61,11 +61,12 @@ Rectangle {
delegate: Item {
height: 40; width: ListView.view.width
+ required property string modelData
Text {
anchors.centerIn: parent
- text: modelData
+ text: parent.modelData
//! [delegate]
- font.family: modelData
+ font.family: parent.modelData
//! [delegate]
font.pixelSize: 20
color: "white"
diff --git a/examples/quick/text/fonts/fonts.qml b/examples/quick/text/fonts/fonts.qml
index d356e00417..4478db0135 100644
--- a/examples/quick/text/fonts/fonts.qml
+++ b/examples/quick/text/fonts/fonts.qml
@@ -51,6 +51,7 @@
import QtQuick 2.0
Rectangle {
+ id: root
property string myText: "The quick brown fox jumps over the lazy dog."
width: 320; height: 480
@@ -71,7 +72,7 @@ Rectangle {
spacing: 15
Text {
- text: myText
+ text: root.myText
color: "lightsteelblue"
width: parent.width
wrapMode: Text.WordWrap
@@ -81,7 +82,7 @@ Rectangle {
font.pixelSize: 20
}
Text {
- text: myText
+ text: root.myText
color: "lightsteelblue"
width: parent.width
wrapMode: Text.WordWrap
@@ -89,7 +90,7 @@ Rectangle {
font { family: "Times"; pixelSize: 20; capitalization: Font.AllUppercase }
}
Text {
- text: myText
+ text: root.myText
color: "lightsteelblue"
width: parent.width
horizontalAlignment: Text.AlignRight
@@ -97,14 +98,14 @@ Rectangle {
font { family: fixedFont.name; pixelSize: 20; weight: Font.Bold; capitalization: Font.AllLowercase }
}
Text {
- text: myText
+ text: root.myText
color: "lightsteelblue"
width: parent.width
wrapMode: Text.WordWrap
font { family: fixedFont.name; pixelSize: 20; italic: true; capitalization: Font.SmallCaps }
}
Text {
- text: myText
+ text: root.myText
color: "lightsteelblue"
width: parent.width
wrapMode: Text.WordWrap
@@ -112,7 +113,7 @@ Rectangle {
}
Text {
text: {
- if (webFont.status == FontLoader.Ready) myText
+ if (webFont.status == FontLoader.Ready) root.myText
else if (webFont.status == FontLoader.Loading) "Loading..."
else if (webFont.status == FontLoader.Error) "Error loading font"
}
diff --git a/examples/quick/text/imgtag/TextWithImage.qml b/examples/quick/text/imgtag/TextWithImage.qml
index 1cb65e739d..d22e93146d 100644
--- a/examples/quick/text/imgtag/TextWithImage.qml
+++ b/examples/quick/text/imgtag/TextWithImage.qml
@@ -55,5 +55,5 @@ Text {
font.pointSize: 14
wrapMode: Text.WordWrap
textFormat: Text.StyledText
- horizontalAlignment: main.hAlign
+ horizontalAlignment: parent.hAlign
}
diff --git a/examples/quick/text/imgtag/imgtag.qml b/examples/quick/text/imgtag/imgtag.qml
index 1790853de2..177008940a 100644
--- a/examples/quick/text/imgtag/imgtag.qml
+++ b/examples/quick/text/imgtag/imgtag.qml
@@ -56,7 +56,7 @@ Rectangle {
focus: true
color: "#dedede"
- property var hAlign: Text.AlignLeft
+ property int hAlign: Text.AlignLeft
Flickable {
anchors.fill: parent
@@ -68,6 +68,7 @@ Rectangle {
x: 10; y: 10
spacing: 20
width: parent.width - 20
+ property int hAlign: main.hAlign
TextWithImage {
text: "This is a <b>happy</b> face<img src=\"images/face-smile.png\">"
diff --git a/examples/quick/text/styledtext-layout.qml b/examples/quick/text/styledtext-layout.qml
index fe7b40b89b..b399b638dc 100644
--- a/examples/quick/text/styledtext-layout.qml
+++ b/examples/quick/text/styledtext-layout.qml
@@ -71,15 +71,34 @@ Rectangle {
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at ante dui <a href=\"http://www.digia.com\">www.digia.com</a>.<br/>Curabitur ante est, pulvinar quis adipiscing a, iaculis id ipsum. Nunc blandit condimentum odio vel egestas.<br><ul type=\"bullet\"><li>Coffee<ol type=\"a\"><li>Espresso<li>Cappuccino<li>Latte</ol><li>Juice<ol type=\"1\"><li>Orange</li><li>Apple</li><li>Pineapple</li><li>Tomato</li></ol></li></ul><p><font color=\"#434343\"><i>Proin consectetur <b>sapien</b> in ipsum lacinia sit amet mattis orci interdum. Quisque vitae accumsan lectus. Ut nisi turpis, sollicitudin ut dignissim id, fermentum ac est. Maecenas nec libero leo. Sed ac leo eget ipsum ultricies viverra sit amet eu orci. Praesent et tortor risus, viverra accumsan sapien. Sed faucibus eleifend lectus, sed euismod urna porta eu. Quisque vitae accumsan lectus. Ut nisi turpis, sollicitudin ut dignissim id, fermentum ac est. Maecenas nec libero leo. Sed ac leo eget ipsum ultricies viverra sit amet eu orci."
//! [layout]
- onLineLaidOut: {
- line.width = width / 2 - (margin)
+ onLineLaidOut: (line) => {
+ line.width = width / 2 - main.margin
if (line.y + line.height >= height) {
- line.y -= height - margin
- line.x = width / 2 + margin
+ line.y -= height - main.margin
+ line.x = width / 2 + main.activeFocusmargin
+ }
+
+ if (line.isLast) {
+ lastLineMarker.x = line.x + line.implicitWidth
+ lastLineMarker.y = line.y + (line.height - lastLineMarker.height) / 2
}
}
//! [layout]
+
+ Rectangle {
+ id: lastLineMarker
+ color: "#44cccccc"
+ width: theEndText.width + margin
+ height: theEndText.height + margin
+
+ Text {
+ id: theEndText
+ text: "THE\nEND"
+ anchors.centerIn: parent
+ font.pixelSize: myText.font.pixelSize / 2
+ }
+ }
}
}
diff --git a/examples/quick/threading/threadedlistmodel/timedisplay.qml b/examples/quick/threading/threadedlistmodel/timedisplay.qml
index 5ad901c676..c4e6e7b249 100644
--- a/examples/quick/threading/threadedlistmodel/timedisplay.qml
+++ b/examples/quick/threading/threadedlistmodel/timedisplay.qml
@@ -59,7 +59,10 @@ Rectangle {
anchors.fill: parent
model: listModel
delegate: Component {
- Text { text: time }
+ Text {
+ required property string time
+ text: time
+ }
}
ListModel { id: listModel }
diff --git a/examples/quick/threading/workerscript/Spinner.qml b/examples/quick/threading/workerscript/Spinner.qml
index 9c70090dba..a2257f8639 100644
--- a/examples/quick/threading/workerscript/Spinner.qml
+++ b/examples/quick/threading/workerscript/Spinner.qml
@@ -78,6 +78,7 @@ Rectangle {
clip: true
model: 64
delegate: Text {
+ required property int index
font.pixelSize: 18;
color: "white";
text: index;
diff --git a/examples/quick/threading/workerscript/workerscript.qml b/examples/quick/threading/workerscript/workerscript.qml
index 735cc8d1f1..eb8ad43d01 100644
--- a/examples/quick/threading/workerscript/workerscript.qml
+++ b/examples/quick/threading/workerscript/workerscript.qml
@@ -58,7 +58,7 @@ Rectangle {
id: myWorker
source: "workerscript.mjs"
- onMessage: {
+ onMessage: (messageObject) => {
if (messageObject.row == rowSpinner.value && messageObject.column == columnSpinner.value){ //Not an old result
if (messageObject.result == -1)
resultText.text = "Column must be <= Row";
diff --git a/examples/quick/touchinteraction/flickable/content/Panel.qml b/examples/quick/touchinteraction/flickable/content/Panel.qml
index 21f8fc8afd..0aae0635b2 100644
--- a/examples/quick/touchinteraction/flickable/content/Panel.qml
+++ b/examples/quick/touchinteraction/flickable/content/Panel.qml
@@ -50,112 +50,106 @@
import QtQuick 2.0
-Component {
- Item {
- property variant stickies
+Item {
+ required property string name
+ required property var notes
- id: page
- width: ListView.view.width+40; height: ListView.view.height
+ property real horizontalVelocity: 0
+ id: page
+ width: ListView.view.width+40; height: ListView.view.height
- Image {
- source: "cork.jpg"
- width: page.ListView.view.width
- height: page.ListView.view.height
- fillMode: Image.PreserveAspectCrop
- clip: true
- }
-
- MouseArea {
- anchors.fill: parent
- onClicked: page.focus = false;
- }
- Text {
- text: name; x: 15; y: 8; height: 40; width: 370
- font.pixelSize: 18; font.bold: true; color: "white"
- style: Text.Outline; styleColor: "black"
- }
+ Image {
+ source: "cork.jpg"
+ width: page.ListView.view.width
+ height: page.ListView.view.height
+ fillMode: Image.PreserveAspectCrop
+ clip: true
+ }
- Repeater {
- model: notes
- Item {
- id: stickyPage
+ MouseArea {
+ anchors.fill: parent
+ onClicked: page.focus = false;
+ }
- property int randomX: Math.random() * (page.ListView.view.width-0.5*stickyImage.width) +100
- property int randomY: Math.random() * (page.ListView.view.height-0.5*stickyImage.height) +50
+ Text {
+ text: page.name; x: 15; y: 8; height: 40; width: 370
+ font.pixelSize: 18; font.bold: true; color: "white"
+ style: Text.Outline; styleColor: "black"
+ }
- x: randomX; y: randomY
+ Repeater {
+ model: page.notes
+ Item {
+ id: stickyPage
+ required property string noteText
- rotation: -flickable.horizontalVelocity / 100;
- Behavior on rotation {
- SpringAnimation { spring: 2.0; damping: 0.15 }
- }
+ property int randomX: Math.random() * (page.ListView.view.width-0.5*stickyImage.width) +100
+ property int randomY: Math.random() * (page.ListView.view.height-0.5*stickyImage.height) +50
- Item {
- id: sticky
- scale: 0.7
-
- Image {
- id: stickyImage
- x: 8 + -width * 0.6 / 2; y: -20
- source: "note-yellow.png"
- scale: 0.6; transformOrigin: Item.TopLeft
- }
+ x: randomX; y: randomY
- TextEdit {
- id: myText
- x: -104; y: 36; width: 215; height: 200
- font.pixelSize: 24
- readOnly: false
- rotation: -8
- text: noteText
- }
+ rotation: -page.horizontalVelocity / 100
+ Behavior on rotation {
+ SpringAnimation { spring: 2.0; damping: 0.15 }
+ }
- Item {
- x: stickyImage.x; y: -20
- width: stickyImage.width * stickyImage.scale
- height: stickyImage.height * stickyImage.scale
-
- MouseArea {
- id: mouse
- anchors.fill: parent
- drag.target: stickyPage
- drag.axis: Drag.XAndYAxis
- drag.minimumY: 0
- drag.maximumY: page.height - 80
- drag.minimumX: 100
- drag.maximumX: page.width - 140
- onClicked: myText.forceActiveFocus()
- }
- }
- }
+ Item {
+ id: sticky
+ scale: 0.7
Image {
- x: -width / 2; y: -height * 0.5 / 2
- source: "tack.png"
- scale: 0.7; transformOrigin: Item.TopLeft
+ id: stickyImage
+ x: 8 + -width * 0.6 / 2; y: -20
+ source: "note-yellow.png"
+ scale: 0.6; transformOrigin: Item.TopLeft
}
- states: State {
- name: "pressed"
- when: mouse.pressed
- PropertyChanges { target: sticky; rotation: 8; scale: 1 }
- PropertyChanges { target: page; z: 8 }
+ TextEdit {
+ id: myText
+ x: -104; y: 36; width: 215; height: 200
+ font.pixelSize: 24
+ readOnly: false
+ rotation: -8
+ text: stickyPage.noteText
}
- transitions: Transition {
- NumberAnimation { properties: "rotation,scale"; duration: 200 }
+ Item {
+ x: stickyImage.x; y: -20
+ width: stickyImage.width * stickyImage.scale
+ height: stickyImage.height * stickyImage.scale
+
+ MouseArea {
+ id: mouse
+ anchors.fill: parent
+ drag.target: stickyPage
+ drag.axis: Drag.XAndYAxis
+ drag.minimumY: 0
+ drag.maximumY: page.height - 80
+ drag.minimumX: 100
+ drag.maximumX: page.width - 140
+ onClicked: myText.forceActiveFocus()
+ }
}
}
- }
- }
-}
-
-
-
-
-
+ Image {
+ x: -width / 2; y: -height * 0.5 / 2
+ source: "tack.png"
+ scale: 0.7; transformOrigin: Item.TopLeft
+ }
+ states: State {
+ name: "pressed"
+ when: mouse.pressed
+ PropertyChanges { target: sticky; rotation: 8; scale: 1 }
+ PropertyChanges { target: page; z: 8 }
+ }
+ transitions: Transition {
+ NumberAnimation { properties: "rotation,scale"; duration: 200 }
+ }
+ }
+ }
+}
diff --git a/examples/quick/touchinteraction/flickable/corkboards.qml b/examples/quick/touchinteraction/flickable/corkboards.qml
index afb5dd309c..4825053f3f 100644
--- a/examples/quick/touchinteraction/flickable/corkboards.qml
+++ b/examples/quick/touchinteraction/flickable/corkboards.qml
@@ -92,6 +92,8 @@ Rectangle {
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem
model: list
- delegate: Panel { }
+ delegate: Panel {
+ horizontalVelocity: flickable.horizontalVelocity
+ }
}
}
diff --git a/examples/quick/touchinteraction/multipointtouch/bearwhack.qml b/examples/quick/touchinteraction/multipointtouch/bearwhack.qml
index 49bd0b9db8..90c1a66891 100644
--- a/examples/quick/touchinteraction/multipointtouch/bearwhack.qml
+++ b/examples/quick/touchinteraction/multipointtouch/bearwhack.qml
@@ -87,7 +87,7 @@ Item {
running: !startScreen.visible
}
- property int score: 0
+ property int score: particleSystem.score
Text {
anchors.right: parent.right
@@ -96,11 +96,13 @@ Item {
color: "white"
function padded(num) {
var ret = num.toString();
- while (ret.length < 6)
- ret = "0" + ret;
- return ret;
+
+ if (ret >= 0)
+ return ret.padStart(6, "0");
+ else
+ return "-" + ret.substr(1).padStart(6, "0");
}
- text: "Score: " + padded(score)
+ text: "Score: " + padded(root.score)
}
MultiPointTouchArea {
anchors.fill: parent
diff --git a/examples/quick/touchinteraction/multipointtouch/content/AugmentedTouchPoint.qml b/examples/quick/touchinteraction/multipointtouch/content/AugmentedTouchPoint.qml
index 5750ffcad1..56f287666f 100644
--- a/examples/quick/touchinteraction/multipointtouch/content/AugmentedTouchPoint.qml
+++ b/examples/quick/touchinteraction/multipointtouch/content/AugmentedTouchPoint.qml
@@ -66,7 +66,7 @@ TouchPoint {
interval: 100
running: false
repeat: false
- onTriggered: child.enabled = false
+ onTriggered: container.child.enabled = false
}
property Item child: SpriteGoal {
enabled: false
diff --git a/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml b/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml
index 3db9eaf1e5..8da5949a1b 100644
--- a/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml
+++ b/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml
@@ -52,6 +52,9 @@ import QtQuick.Particles 2.0
ParticleSystem {
id: particleSystem
+
+ property int score
+
function explode(x,y) {
fireEmitter.burst(100,x,y);
}
@@ -116,13 +119,13 @@ ParticleSystem {
once: true
y: parent.height - 32
groups: "bears"
- onAffectParticles: {
+ onAffectParticles: function(particles) {
for (var i=0;i<particles.length; i++) {
if (particles[i].animationIndex != 0) {
- score++;
+ particleSystem.score++;
bloodEmitter.burst(100, particles[i].x, particles[i].y);
} else {
- score--;
+ particleSystem.score--;
heartEmitter.burst(100, particles[i].x, particles[i].y);
}
particles[i].update = 1.0;
diff --git a/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.pro b/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.pro
new file mode 100644
index 0000000000..8ca003b6b4
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += dynamicview1.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/dynamicview/dynamicview1
+INSTALLS += target
diff --git a/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.qrc b/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.qrc
new file mode 100644
index 0000000000..c89a5e3a97
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview1/dynamicview1.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>dynamicview.qml</file>
+ <file>PetsModel.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/dynamicview/dynamicview1/main.cpp b/examples/quick/tutorials/dynamicview/dynamicview1/main.cpp
new file mode 100644
index 0000000000..72b8b667f5
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview1/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(dynamicview)
diff --git a/examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.pro b/examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.pro
new file mode 100644
index 0000000000..a2b058c528
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += dynamicview2.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/dynamicview/dynamicview2
+INSTALLS += target
diff --git a/examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.qrc b/examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.qrc
new file mode 100644
index 0000000000..c89a5e3a97
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview2/dynamicview2.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>dynamicview.qml</file>
+ <file>PetsModel.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/dynamicview/dynamicview2/main.cpp b/examples/quick/tutorials/dynamicview/dynamicview2/main.cpp
new file mode 100644
index 0000000000..72b8b667f5
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview2/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(dynamicview)
diff --git a/examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.pro b/examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.pro
new file mode 100644
index 0000000000..ebc753f2a7
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += dynamicview3.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/dynamicview/dynamicview3
+INSTALLS += target
diff --git a/examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.qrc b/examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.qrc
new file mode 100644
index 0000000000..c89a5e3a97
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview3/dynamicview3.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>dynamicview.qml</file>
+ <file>PetsModel.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/dynamicview/dynamicview3/main.cpp b/examples/quick/tutorials/dynamicview/dynamicview3/main.cpp
new file mode 100644
index 0000000000..72b8b667f5
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview3/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(dynamicview)
diff --git a/examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.pro b/examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.pro
new file mode 100644
index 0000000000..a5cb99f665
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += dynamicview4.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/dynamicview/dynamicview4
+INSTALLS += target
diff --git a/examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.qrc b/examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.qrc
new file mode 100644
index 0000000000..c89a5e3a97
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview4/dynamicview4.qrc
@@ -0,0 +1,6 @@
+<RCC>
+ <qresource prefix="/">
+ <file>dynamicview.qml</file>
+ <file>PetsModel.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/dynamicview/dynamicview4/main.cpp b/examples/quick/tutorials/dynamicview/dynamicview4/main.cpp
new file mode 100644
index 0000000000..72b8b667f5
--- /dev/null
+++ b/examples/quick/tutorials/dynamicview/dynamicview4/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(dynamicview)
diff --git a/examples/quick/tutorials/samegame/samegame1/main.cpp b/examples/quick/tutorials/samegame/samegame1/main.cpp
new file mode 100644
index 0000000000..7589b92906
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame1/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(samegame)
diff --git a/examples/quick/tutorials/samegame/samegame1/samegame1.pro b/examples/quick/tutorials/samegame/samegame1/samegame1.pro
new file mode 100644
index 0000000000..9f316b6868
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame1/samegame1.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += \
+ samegame1.qrc \
+ ../shared/pics/shared.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/samegame/samegame1
+INSTALLS += target
diff --git a/examples/quick/tutorials/samegame/samegame1/samegame1.qrc b/examples/quick/tutorials/samegame/samegame1/samegame1.qrc
new file mode 100644
index 0000000000..866cf899bf
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame1/samegame1.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>Button.qml</file>
+ <file>Block.qml</file>
+ <file>samegame.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/samegame/samegame2/main.cpp b/examples/quick/tutorials/samegame/samegame2/main.cpp
new file mode 100644
index 0000000000..7589b92906
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame2/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(samegame)
diff --git a/examples/quick/tutorials/samegame/samegame2/samegame2.pro b/examples/quick/tutorials/samegame/samegame2/samegame2.pro
new file mode 100644
index 0000000000..5ede9042cc
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame2/samegame2.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += \
+ samegame2.qrc \
+ ../shared/pics/shared.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/samegame/samegame2
+INSTALLS += target
diff --git a/examples/quick/tutorials/samegame/samegame2/samegame2.qrc b/examples/quick/tutorials/samegame/samegame2/samegame2.qrc
new file mode 100644
index 0000000000..0f95174d83
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame2/samegame2.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>Button.qml</file>
+ <file>Block.qml</file>
+ <file>samegame.qml</file>
+ <file>samegame.js</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/samegame/samegame3/main.cpp b/examples/quick/tutorials/samegame/samegame3/main.cpp
new file mode 100644
index 0000000000..7589b92906
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame3/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(samegame)
diff --git a/examples/quick/tutorials/samegame/samegame3/samegame3.pro b/examples/quick/tutorials/samegame/samegame3/samegame3.pro
new file mode 100644
index 0000000000..7b99673e57
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame3/samegame3.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += \
+ samegame3.qrc \
+ ../shared/pics/shared.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/samegame/samegame3
+INSTALLS += target
diff --git a/examples/quick/tutorials/samegame/samegame3/samegame3.qrc b/examples/quick/tutorials/samegame/samegame3/samegame3.qrc
new file mode 100644
index 0000000000..0f95174d83
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame3/samegame3.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>Button.qml</file>
+ <file>Block.qml</file>
+ <file>samegame.qml</file>
+ <file>samegame.js</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/samegame/samegame4/main.cpp b/examples/quick/tutorials/samegame/samegame4/main.cpp
new file mode 100644
index 0000000000..7589b92906
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame4/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(samegame)
diff --git a/examples/quick/tutorials/samegame/samegame4/samegame4.pro b/examples/quick/tutorials/samegame/samegame4/samegame4.pro
new file mode 100644
index 0000000000..5da0d46e19
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame4/samegame4.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += \
+ samegame4.qrc \
+ ../shared/pics/shared.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/tutorials/samegame/samegame4
+INSTALLS += target
diff --git a/examples/quick/tutorials/samegame/samegame4/samegame4.qrc b/examples/quick/tutorials/samegame/samegame4/samegame4.qrc
new file mode 100644
index 0000000000..8b130721f5
--- /dev/null
+++ b/examples/quick/tutorials/samegame/samegame4/samegame4.qrc
@@ -0,0 +1,13 @@
+<RCC>
+ <qresource prefix="/">
+ <file>samegame.qml</file>
+ <file>content/BoomBlock.qml</file>
+ <file>content/Button.qml</file>
+ <file>content/Dialog.qml</file>
+ <file>content/samegame.js</file>
+ <file>highscores/README</file>
+ <file>highscores/score_data.xml</file>
+ <file>highscores/score_style.xsl</file>
+ <file>highscores/scores.php</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/tutorials/samegame/shared/pics/shared.qrc b/examples/quick/tutorials/samegame/shared/pics/shared.qrc
new file mode 100644
index 0000000000..8982a9face
--- /dev/null
+++ b/examples/quick/tutorials/samegame/shared/pics/shared.qrc
@@ -0,0 +1,13 @@
+<RCC>
+ <qresource prefix="/shared/pics">
+ <file>background.jpg</file>
+ <file>blueStar.png</file>
+ <file>blueStone.png</file>
+ <file>greenStar.png</file>
+ <file>greenStone.png</file>
+ <file>redStar.png</file>
+ <file>redStone.png</file>
+ <file>star.png</file>
+ <file>yellowStone.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/views/delegatemodel/dragselection.qml b/examples/quick/views/delegatemodel/dragselection.qml
index 15fd2654c2..f9a0d37311 100644
--- a/examples/quick/views/delegatemodel/dragselection.qml
+++ b/examples/quick/views/delegatemodel/dragselection.qml
@@ -48,6 +48,7 @@
**
****************************************************************************/
+import QtQml 2.0
import QtQuick 2.0
import QtQml.Models 2.1
@@ -64,6 +65,8 @@ Item {
Package {
id: packageRoot
+ required property var modelData
+
MouseArea {
id: visibleContainer
Package.name: "visible"
@@ -130,7 +133,7 @@ Item {
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
color: "white"
- text: modelData
+ text: packageRoot.modelData
font.pixelSize: 18
}
diff --git a/examples/quick/views/delegatemodel/flipable.pro b/examples/quick/views/delegatemodel/flipable.pro
new file mode 100644
index 0000000000..ba00bf792c
--- /dev/null
+++ b/examples/quick/views/delegatemodel/flipable.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+
+QT += quick qml
+SOURCES += main.cpp
+
+RESOURCES += flipable.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/flipable
+INSTALLS += target
diff --git a/examples/quick/views/delegatemodel/flipable.qrc b/examples/quick/views/delegatemodel/flipable.qrc
new file mode 100644
index 0000000000..7918ccf00e
--- /dev/null
+++ b/examples/quick/views/delegatemodel/flipable.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/">
+ <file>flipable.qml</file>
+ <file>content/5_heart.png</file>
+ <file>content/9_club.png</file>
+ <file>content/back.png</file>
+ <file>content/Card.qml</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/views/delegatemodel/main.cpp b/examples/quick/views/delegatemodel/main.cpp
new file mode 100644
index 0000000000..a0f0d67d45
--- /dev/null
+++ b/examples/quick/views/delegatemodel/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, 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 The Qt Company Ltd 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(flipable)
diff --git a/examples/quick/views/delegatemodel/slideshow.qml b/examples/quick/views/delegatemodel/slideshow.qml
index b252519bbf..638c8bf10f 100644
--- a/examples/quick/views/delegatemodel/slideshow.qml
+++ b/examples/quick/views/delegatemodel/slideshow.qml
@@ -74,6 +74,8 @@ Rectangle {
width: 76; height: 76
+ required property string thumbnail
+
Rectangle {
id: image
x: 0; y: 0; width: 76; height: 76
@@ -86,7 +88,7 @@ Rectangle {
anchors.leftMargin: 1
anchors.topMargin: 1
- source: thumbnail
+ source: delegateItem.thumbnail
fillMode: Image.PreserveAspectFit
}
diff --git a/examples/quick/views/gridview/gridview-example.qml b/examples/quick/views/gridview/gridview-example.qml
index 76a1d8dd37..4cc30d3736 100644
--- a/examples/quick/views/gridview/gridview-example.qml
+++ b/examples/quick/views/gridview/gridview-example.qml
@@ -74,20 +74,24 @@ Rectangle {
highlight: Rectangle { width: 80; height: 80; color: "lightsteelblue" }
delegate: Item {
+ required property string icon
+ required property string name
+ required property int index
+
width: 100; height: 100
Image {
id: myIcon
y: 20; anchors.horizontalCenter: parent.horizontalCenter
- source: icon
+ source: parent.icon
}
Text {
anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
- text: name
+ text: parent.name
}
MouseArea {
anchors.fill: parent
- onClicked: parent.GridView.view.currentIndex = index
+ onClicked: parent.GridView.view.currentIndex = parent.index
}
}
}
diff --git a/examples/quick/views/listview/content/PressAndHoldButton.qml b/examples/quick/views/listview/content/PressAndHoldButton.qml
index 527394eb4d..6d633c0264 100644
--- a/examples/quick/views/listview/content/PressAndHoldButton.qml
+++ b/examples/quick/views/listview/content/PressAndHoldButton.qml
@@ -72,12 +72,12 @@ Image {
PropertyAction { target: container; property: "pressed"; value: true }
ScriptAction { script: container.clicked() }
- PauseAnimation { duration: repeatDelay }
+ PauseAnimation { duration: container.repeatDelay }
SequentialAnimation {
loops: Animation.Infinite
ScriptAction { script: container.clicked() }
- PauseAnimation { duration: repeatDuration }
+ PauseAnimation { duration: container.repeatDuration }
}
}
diff --git a/examples/quick/views/listview/content/ToggleButton.qml b/examples/quick/views/listview/content/ToggleButton.qml
index 0a2747a683..890a94570b 100644
--- a/examples/quick/views/listview/content/ToggleButton.qml
+++ b/examples/quick/views/listview/content/ToggleButton.qml
@@ -63,6 +63,6 @@ Rectangle {
Text { id: text; anchors.centerIn: parent; font.pixelSize: 14 }
MouseArea {
anchors.fill: parent
- onClicked: { active = !active; root.toggled() }
+ onClicked: { root.active = !root.active; root.toggled() }
}
}
diff --git a/examples/quick/views/listview/displaymargin.qml b/examples/quick/views/listview/displaymargin.qml
index e0024e72a9..19261caaa6 100644
--- a/examples/quick/views/listview/displaymargin.qml
+++ b/examples/quick/views/listview/displaymargin.qml
@@ -68,10 +68,13 @@ Item {
width: parent.width
height: 25
color: index % 2 ? "steelblue" : "lightsteelblue"
+
+ required property int index
+
Text {
anchors.centerIn: parent
color: "white"
- text: "Item " + (index + 1)
+ text: "Item " + (parent.index + 1)
}
}
}
diff --git a/examples/quick/views/listview/dynamiclist.qml b/examples/quick/views/listview/dynamiclist.qml
index bfc697d094..f37aab98e2 100644
--- a/examples/quick/views/listview/dynamiclist.qml
+++ b/examples/quick/views/listview/dynamiclist.qml
@@ -101,6 +101,11 @@ Rectangle {
width: listView.width; height: 80
clip: true
+ required property int index
+ required property string name
+ required property real cost
+ required property var attributes
+
Column {
id: arrows
anchors {
@@ -109,10 +114,16 @@ Rectangle {
}
Image {
source: "content/pics/arrow-up.png"
- MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index, index-1, 1) }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: fruitModel.move(delegateItem.index, delegateItem.index - 1, 1)
+ }
}
Image { source: "content/pics/arrow-down.png"
- MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index, index+1, 1) }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: fruitModel.move(delegateItem.index, delegateItem.index + 1, 1)
+ }
}
}
@@ -125,7 +136,7 @@ Rectangle {
Text {
anchors.horizontalCenter: parent.horizontalCenter
- text: name
+ text: delegateItem.name
font.pixelSize: 15
color: "white"
}
@@ -133,8 +144,12 @@ Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
spacing: 5
Repeater {
- model: attributes
- Text { text: description; color: "White" }
+ model: delegateItem.attributes
+ Text {
+ required property string description
+ text: description
+ color: "White"
+ }
}
}
}
@@ -154,13 +169,13 @@ Rectangle {
PressAndHoldButton {
anchors.verticalCenter: parent.verticalCenter
source: "content/pics/plus-sign.png"
- onClicked: fruitModel.setProperty(index, "cost", cost + 0.25)
+ onClicked: fruitModel.setProperty(delegateItem.index, "cost", delegateItem.cost + 0.25)
}
Text {
id: costText
anchors.verticalCenter: parent.verticalCenter
- text: '$' + Number(cost).toFixed(2)
+ text: '$' + Number(delegateItem.cost).toFixed(2)
font.pixelSize: 15
color: "white"
font.bold: true
@@ -169,12 +184,16 @@ Rectangle {
PressAndHoldButton {
anchors.verticalCenter: parent.verticalCenter
source: "content/pics/minus-sign.png"
- onClicked: fruitModel.setProperty(index, "cost", Math.max(0,cost-0.25))
+ onClicked: fruitModel.setProperty(delegateItem.index, "cost",
+ Math.max(0, delegateItem.cost - 0.25))
}
Image {
source: "content/pics/list-delete.png"
- MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: fruitModel.remove(delegateItem.index)
+ }
}
}
}
diff --git a/examples/quick/views/listview/expandingdelegates.qml b/examples/quick/views/listview/expandingdelegates.qml
index 1308e8441d..6ed1d8c341 100644
--- a/examples/quick/views/listview/expandingdelegates.qml
+++ b/examples/quick/views/listview/expandingdelegates.qml
@@ -67,6 +67,11 @@ Rectangle {
Item {
id: recipe
+ required property string title
+ required property string picture
+ required property string ingredients
+ required property string method
+
// Create a property to contain the visibility of the details.
// We can bind multiple element's opacity to this one property,
// rather than having a "PropertyChanges" line for each element we
@@ -106,7 +111,7 @@ Rectangle {
Image {
id: recipeImage
width: 50; height: 50
- source: picture
+ source: recipe.picture
}
//! [1]
Column {
@@ -114,7 +119,7 @@ Rectangle {
spacing: 5
Text {
- text: title
+ text: recipe.title
font.bold: true; font.pointSize: 16
}
@@ -125,7 +130,7 @@ Rectangle {
}
SmallText {
- text: ingredients
+ text: recipe.ingredients
wrapMode: Text.WordWrap
width: parent.width
opacity: recipe.detailsOpacity
@@ -155,7 +160,12 @@ Rectangle {
contentHeight: methodText.height
clip: true
- Text { id: methodText; text: method; wrapMode: Text.WordWrap; width: details.width }
+ Text {
+ id: methodText
+ text: recipe.method
+ wrapMode: Text.WordWrap
+ width: details.width
+ }
}
Image {
diff --git a/examples/quick/views/listview/highlight.qml b/examples/quick/views/listview/highlight.qml
index 5b03d30f25..092b4d59bd 100644
--- a/examples/quick/views/listview/highlight.qml
+++ b/examples/quick/views/listview/highlight.qml
@@ -58,44 +58,44 @@ import "content"
Rectangle {
width: 200; height: 300
- // Define a delegate component. A component will be
+ // Define a delegate component. The component will be
// instantiated for each visible item in the list.
- Component {
- id: petDelegate
- Item {
- id: wrapper
- width: 200; height: 55
- Column {
- SmallText { text: 'Name: ' + name }
- SmallText { text: 'Type: ' + type }
- SmallText { text: 'Age: ' + age }
- }
- // indent the item if it is the current item
- states: State {
- name: "Current"
- when: wrapper.ListView.isCurrentItem
- PropertyChanges { target: wrapper; x: 20 }
- }
- transitions: Transition {
- NumberAnimation { properties: "x"; duration: 200 }
- }
- MouseArea {
- anchors.fill: parent
- onClicked: wrapper.ListView.view.currentIndex = index
- }
+ component PetDelegate: Item {
+ id: pet
+ width: 200; height: 55
+
+ required property int index
+ required property string name
+ required property string type
+ required property int age
+
+ Column {
+ SmallText { text: 'Name: ' + pet.name }
+ SmallText { text: 'Type: ' + pet.type }
+ SmallText { text: 'Age: ' + pet.age }
+ }
+ // indent the item if it is the current item
+ states: State {
+ name: "Current"
+ when: pet.ListView.isCurrentItem
+ PropertyChanges { target: pet; x: 20 }
+ }
+ transitions: Transition {
+ NumberAnimation { properties: "x"; duration: 200 }
+ }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: pet.ListView.view.currentIndex = pet.index
}
}
//! [0]
// Define a highlight with customized movement between items.
- Component {
- id: highlightBar
- Rectangle {
- width: 200; height: 50
- color: "#FFFF88"
- y: listView.currentItem.y;
- Behavior on y { SpringAnimation { spring: 2; damping: 0.1 } }
- }
+ component HighlightBar : Rectangle {
+ width: 200; height: 50
+ color: "#FFFF88"
+ y: listView.currentItem.y
+ Behavior on y { SpringAnimation { spring: 2; damping: 0.1 } }
}
ListView {
@@ -104,12 +104,12 @@ Rectangle {
x: 30
model: PetsModel {}
- delegate: petDelegate
+ delegate: PetDelegate {}
focus: true
// Set the highlight delegate. Note we must also set highlightFollowsCurrentItem
// to false so the highlight delegate can control how the highlight is moved.
- highlight: highlightBar
+ highlight: HighlightBar {}
highlightFollowsCurrentItem: false
}
//! [0]
diff --git a/examples/quick/views/listview/highlightranges.qml b/examples/quick/views/listview/highlightranges.qml
index 7bc9ab7fe1..dafd064332 100644
--- a/examples/quick/views/listview/highlightranges.qml
+++ b/examples/quick/views/listview/highlightranges.qml
@@ -62,17 +62,17 @@ Rectangle {
loops: -1
running: true
ScriptAction {
- script: if (increasing) {
- current++;
- if (current >= aModel.count -1) {
- current = aModel.count - 1;
- increasing = !increasing;
+ script: if (root.increasing) {
+ root.current++;
+ if (root.current >= aModel.count -1) {
+ root.current = aModel.count - 1;
+ root.increasing = !root.increasing;
}
} else {
- current--;
- if (current <= 0) {
- current = 0;
- increasing = !increasing;
+ root.current--;
+ if (root.current <= 0) {
+ root.current = 0;
+ root.increasing = !root.increasing;
}
}
}
@@ -161,16 +161,22 @@ Rectangle {
Item {
width: 160
height: column.height
+
+ required property int index
+ required property string name
+ required property string type
+ required property int age
+
Column {
id: column
- Text { text: 'Name: ' + name }
- Text { text: 'Type: ' + type }
- Text { text: 'Age: ' + age }
+ Text { text: 'Name: ' + parent.name }
+ Text { text: 'Type: ' + parent.type }
+ Text { text: 'Age: ' + parent.age }
}
MouseArea {
anchors.fill: parent
- onClicked: root.current = index
+ onClicked: root.current = parent.index
}
}
}
diff --git a/examples/quick/views/listview/sections.qml b/examples/quick/views/listview/sections.qml
index 75b0f5c6d9..d51ed89789 100644
--- a/examples/quick/views/listview/sections.qml
+++ b/examples/quick/views/listview/sections.qml
@@ -87,8 +87,10 @@ Rectangle {
height: childrenRect.height
color: "lightsteelblue"
+ required property string section
+
Text {
- text: section
+ text: parent.section
font.bold: true
font.pixelSize: 20
}
@@ -101,7 +103,11 @@ Rectangle {
anchors.bottom: buttonBar.top
width: parent.width
model: animalsModel
- delegate: Text { text: name; font.pixelSize: 18 }
+ delegate: Text {
+ required property string name
+ text: name
+ font.pixelSize: 18
+ }
section.property: "size"
section.criteria: ViewSection.FullString
diff --git a/examples/quick/views/objectmodel/objectmodel.qml b/examples/quick/views/objectmodel/objectmodel.qml
index 8fc2f7c386..c9e4b8a5cd 100644
--- a/examples/quick/views/objectmodel/objectmodel.qml
+++ b/examples/quick/views/objectmodel/objectmodel.qml
@@ -70,21 +70,21 @@ Rectangle {
color: "#FFFEF0"
Text { text: "Page 1"; font.bold: true; anchors.centerIn: parent }
- Component.onDestruction: if (printDestruction) print("destroyed 1")
+ Component.onDestruction: if (root.printDestruction) print("destroyed 1")
}
Rectangle {
width: view.width; height: view.height
color: "#F0FFF7"
Text { text: "Page 2"; font.bold: true; anchors.centerIn: parent }
- Component.onDestruction: if (printDestruction) print("destroyed 2")
+ Component.onDestruction: if (root.printDestruction) print("destroyed 2")
}
Rectangle {
width: view.width; height: view.height
color: "#F4F0FF"
Text { text: "Page 3"; font.bold: true; anchors.centerIn: parent }
- Component.onDestruction: if (printDestruction) print("destroyed 3")
+ Component.onDestruction: if (root.activeFocusprintDestruction) print("destroyed 3")
}
}
@@ -112,6 +112,8 @@ Rectangle {
model: itemModel.count
Rectangle {
+ required property int index
+
width: 5; height: 5
radius: 3
color: view.currentIndex == index ? "blue" : "white"
@@ -119,7 +121,7 @@ Rectangle {
MouseArea {
width: 20; height: 20
anchors.centerIn: parent
- onClicked: view.currentIndex = index
+ onClicked: view.currentIndex = parent.index
}
}
}
diff --git a/examples/quick/views/package/Delegate.qml b/examples/quick/views/package/Delegate.qml
index 7c73f35c3d..9f4f1946d8 100644
--- a/examples/quick/views/package/Delegate.qml
+++ b/examples/quick/views/package/Delegate.qml
@@ -52,6 +52,12 @@ import QtQuick 2.0
//! [0]
Package {
+ id: delegate
+
+ required property int upTo
+ required property int index
+ required property string display
+
Text { id: listDelegate; width: parent.width; height: 25; text: 'Empty'; Package.name: 'list' }
Text { id: gridDelegate; width: parent.width / 2; height: 50; text: 'Empty'; Package.name: 'grid' }
@@ -60,8 +66,8 @@ Package {
width: parent.width; height: 25
color: 'lightsteelblue'
- Text { text: display; anchors.centerIn: parent }
- state: root.upTo > index ? 'inGrid' : 'inList'
+ Text { text: delegate.display; anchors.centerIn: parent }
+ state: delegate.upTo > delegate.index ? 'inGrid' : 'inList'
states: [
State {
name: 'inList'
diff --git a/examples/quick/views/package/view.qml b/examples/quick/views/package/view.qml
index 311cc3be8e..632d27c724 100644
--- a/examples/quick/views/package/view.qml
+++ b/examples/quick/views/package/view.qml
@@ -77,7 +77,9 @@ Rectangle {
//![0]
DelegateModel {
id: visualModel
- delegate: Delegate {}
+ delegate: Delegate {
+ upTo: root.upTo
+ }
model: myModel
}
diff --git a/examples/quick/views/pathview/pathview-example.qml b/examples/quick/views/pathview/pathview-example.qml
index a70bf1b656..e42117dfae 100644
--- a/examples/quick/views/pathview/pathview-example.qml
+++ b/examples/quick/views/pathview/pathview-example.qml
@@ -71,19 +71,23 @@ Rectangle {
width: 100; height: 100
scale: PathView.iconScale
+ required property string name
+ required property string icon
+ required property int index
+
Image {
id: myIcon
y: 20; anchors.horizontalCenter: parent.horizontalCenter
- source: icon
+ source: parent.icon
}
Text {
anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
- text: name
+ text: parent.name
}
MouseArea {
anchors.fill: parent
- onClicked: view.currentIndex = index
+ onClicked: view.currentIndex = parent.index
}
}
}
diff --git a/examples/quick/window/AllScreens.qml b/examples/quick/window/AllScreens.qml
index a5da380025..ac0e1cb821 100644
--- a/examples/quick/window/AllScreens.qml
+++ b/examples/quick/window/AllScreens.qml
@@ -69,8 +69,14 @@ Column {
id: screenInfo
model: Qt.application.screens
Shared.Label {
+ required property string name
+ required property int virtualX
+ required property int virtualY
+ required property int width
+ required property int height
+
lineHeight: 1.5
- text: name + "\n" + virtualX + ", " + virtualY + " " + modelData.width + "x" + modelData.height
+ text: name + "\n" + virtualX + ", " + virtualY + " " + width + "x" + height
}
}
}
diff --git a/examples/quick/window/CurrentScreen.qml b/examples/quick/window/CurrentScreen.qml
index 2703582399..563cca32a5 100644
--- a/examples/quick/window/CurrentScreen.qml
+++ b/examples/quick/window/CurrentScreen.qml
@@ -115,10 +115,10 @@ Item {
Shared.Label { text: Screen.virtualX + ", " + Screen.virtualY }
Shared.Label { text: "orientation" }
- Shared.Label { text: orientationToString(Screen.orientation) + " (" + Screen.orientation + ")" }
+ Shared.Label { text: root.orientationToString(Screen.orientation) + " (" + Screen.orientation + ")" }
Shared.Label { text: "primary orientation" }
- Shared.Label { text: orientationToString(Screen.primaryOrientation) + " (" + Screen.primaryOrientation + ")" }
+ Shared.Label { text: root.orientationToString(Screen.primaryOrientation) + " (" + Screen.primaryOrientation + ")" }
//! [screen]
Shared.Label { text: "10mm rectangle" }
diff --git a/examples/quick/window/Splash.qml b/examples/quick/window/Splash.qml
index c3e36d9b3b..b33ad6c168 100644
--- a/examples/quick/window/Splash.qml
+++ b/examples/quick/window/Splash.qml
@@ -78,9 +78,9 @@ Window {
}
//! [timer]
Timer {
- interval: timeoutInterval; running: true; repeat: false
+ interval: splash.timeoutInterval; running: true; repeat: false
onTriggered: {
- visible = false
+ splash.visible = false
splash.timeout()
}
}
diff --git a/examples/quick/window/window.qml b/examples/quick/window/window.qml
index 2ee7fb6e09..4280b6a4c0 100644
--- a/examples/quick/window/window.qml
+++ b/examples/quick/window/window.qml
@@ -53,65 +53,66 @@ import QtQuick.Window 2.3
import "../shared" as Shared
QtObject {
+ id: root
property real defaultSpacing: 10
property SystemPalette palette: SystemPalette { }
property var controlWindow: Window {
- width: col.implicitWidth + defaultSpacing * 2
- height: col.implicitHeight + defaultSpacing * 2
- color: palette.window
+ width: col.implicitWidth + root.defaultSpacing * 2
+ height: col.implicitHeight + root.defaultSpacing * 2
+ color: root.palette.window
title: "Control Window"
Column {
id: col
anchors.fill: parent
- anchors.margins: defaultSpacing
- spacing: defaultSpacing
+ anchors.margins: root.defaultSpacing
+ spacing: root.defaultSpacing
property real cellWidth: col.width / 3 - spacing
Shared.Label { text: "Control the second window:" }
Grid {
id: grid
columns: 3
- spacing: defaultSpacing
+ spacing: root.defaultSpacing
width: parent.width
Shared.Button {
id: showButton
width: col.cellWidth
- text: testWindow.visible ? "Hide" : "Show"
- onClicked: testWindow.visible = !testWindow.visible
+ text: root.testWindow.visible ? "Hide" : "Show"
+ onClicked: root.testWindow.visible = !root.testWindow.visible
}
//! [windowedCheckbox]
Shared.CheckBox {
text: "Windowed"
height: showButton.height
width: col.cellWidth
- Binding on checked { value: testWindow.visibility === Window.Windowed }
- onClicked: testWindow.visibility = Window.Windowed
+ Binding on checked { value: root.testWindow.visibility === Window.Windowed }
+ onClicked: root.testWindow.visibility = Window.Windowed
}
//! [windowedCheckbox]
Shared.CheckBox {
height: showButton.height
width: col.cellWidth
text: "Full Screen"
- Binding on checked { value: testWindow.visibility === Window.FullScreen }
- onClicked: testWindow.visibility = Window.FullScreen
+ Binding on checked { value: root.testWindow.visibility === Window.FullScreen }
+ onClicked: root.testWindow.visibility = Window.FullScreen
}
Shared.Button {
id: autoButton
width: col.cellWidth
text: "Automatic"
- onClicked: testWindow.visibility = Window.AutomaticVisibility
+ onClicked: root.testWindow.visibility = Window.AutomaticVisibility
}
Shared.CheckBox {
height: autoButton.height
text: "Minimized"
- Binding on checked { value: testWindow.visibility === Window.Minimized }
- onClicked: testWindow.visibility = Window.Minimized
+ Binding on checked { value: root.testWindow.visibility === Window.Minimized }
+ onClicked: root.testWindow.visibility = Window.Minimized
}
Shared.CheckBox {
height: autoButton.height
text: "Maximized"
- Binding on checked { value: testWindow.visibility === Window.Maximized }
- onClicked: testWindow.visibility = Window.Maximized
+ Binding on checked { value: root.testWindow.visibility === Window.Maximized }
+ onClicked: root.testWindow.visibility = Window.Maximized
}
}
function visibilityToString(v) {
@@ -133,17 +134,17 @@ QtObject {
}
Shared.Label {
id: visibilityLabel
- text: "second window is " + (testWindow.visible ? "visible" : "invisible") +
- " and has visibility " + parent.visibilityToString(testWindow.visibility)
+ text: "second window is " + (root.testWindow.visible ? "visible" : "invisible") +
+ " and has visibility " + parent.visibilityToString(root.testWindow.visibility)
}
Rectangle {
- color: palette.text
+ color: root.palette.text
width: parent.width
height: 1
}
CurrentScreen { }
Rectangle {
- color: palette.text
+ color: root.palette.text
width: parent.width
height: 1
}
@@ -159,40 +160,40 @@ QtObject {
flags: Qt.Window | Qt.WindowFullscreenButtonHint
Rectangle {
anchors.fill: parent
- anchors.margins: defaultSpacing
+ anchors.margins: root.defaultSpacing
Shared.Label {
anchors.centerIn: parent
text: "Second Window"
}
MouseArea {
anchors.fill: parent
- onClicked: testWindow.color = "#e0c31e"
+ onClicked: root.testWindow.color = "#e0c31e"
}
Shared.Button {
anchors.right: parent.right
anchors.top: parent.top
- anchors.margins: defaultSpacing
- text: testWindow.visibility === Window.FullScreen ? "exit fullscreen" : "go fullscreen"
+ anchors.margins: root.defaultSpacing
+ text: root.testWindow.visibility === Window.FullScreen ? "exit fullscreen" : "go fullscreen"
width: 150
onClicked: {
- if (testWindow.visibility === Window.FullScreen)
- testWindow.visibility = Window.AutomaticVisibility
+ if (root.testWindow.visibility === Window.FullScreen)
+ root.testWindow.visibility = Window.AutomaticVisibility
else
- testWindow.visibility = Window.FullScreen
+ root.testWindow.visibility = Window.FullScreen
}
}
Shared.Button {
anchors.left: parent.left
anchors.top: parent.top
- anchors.margins: defaultSpacing
+ anchors.margins: root.defaultSpacing
text: "X"
width: 30
- onClicked: testWindow.close()
+ onClicked: root.testWindow.close()
}
}
}
property var splashWindow: Splash {
- onTimeout: controlWindow.visible = true
+ onTimeout: root.controlWindow.visible = true
}
}