aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/canvas
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2021-02-04 11:46:07 +0100
committerOliver Eftevaag <oliver.eftevaag@qt.io>2021-03-10 17:53:22 +0100
commit1d3cdac6e448479127d3077c6e011d75fa77e6d6 (patch)
tree15d60db3bb5116159ab795aac0765bde07c60138 /examples/quick/canvas
parentea8f8e09007f4acb5530b1966bc5b2afab609064 (diff)
Update canvas example to use QtQuickControls2
The QtQuick examples should ideally have a more native look and feel. Making them use controls from QtQuickControl will cause them to adapt to the desktop style. This patch replaces the previous Sliders from the 'shared' directory, with Sliders from QtQuickControls2 Task-number: QTBUG-90880 Change-Id: I90521abf7059950521bc3d1a54994d2cca07259d Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'examples/quick/canvas')
-rw-r--r--examples/quick/canvas/CMakeLists.txt1
-rw-r--r--examples/quick/canvas/LabeledSlider.qml85
-rw-r--r--examples/quick/canvas/bezierCurve/bezierCurve.qml25
-rw-r--r--examples/quick/canvas/canvas.qml4
-rw-r--r--examples/quick/canvas/canvas.qrc1
-rw-r--r--examples/quick/canvas/clip/clip.qml16
-rw-r--r--examples/quick/canvas/quadraticCurveTo/quadraticCurveTo.qml17
-rw-r--r--examples/quick/canvas/roundedrect/roundedrect.qml16
-rw-r--r--examples/quick/canvas/smile/smile.qml17
-rw-r--r--examples/quick/canvas/squircle/squircle.qml16
-rw-r--r--examples/quick/canvas/tiger/tiger.qml15
11 files changed, 159 insertions, 54 deletions
diff --git a/examples/quick/canvas/CMakeLists.txt b/examples/quick/canvas/CMakeLists.txt
index ef978ee80b..f7fd901238 100644
--- a/examples/quick/canvas/CMakeLists.txt
+++ b/examples/quick/canvas/CMakeLists.txt
@@ -38,6 +38,7 @@ target_link_libraries(canvas PUBLIC
# Resources:
set(canvas_resource_files
"bezierCurve/bezierCurve.qml"
+ "LabeledSlider.qml"
"canvas.qml"
"clip/clip.qml"
"contents/qt-logo.png"
diff --git a/examples/quick/canvas/LabeledSlider.qml b/examples/quick/canvas/LabeledSlider.qml
new file mode 100644
index 0000000000..0faae7f0c8
--- /dev/null
+++ b/examples/quick/canvas/LabeledSlider.qml
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+
+Item {
+ id: labeledSlider
+ property alias name: label.text
+ implicitHeight: Math.max(label.implicitHeight, quickControlsSlider.implicitHeight)
+ property real min: 0.0
+ property real max: 1.0
+ property real init: 0.0
+ readonly property alias value: quickControlsSlider.value
+
+ Label {
+ id: label
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.verticalCenter: parent.verticalCenter
+ color: "#333"
+ font: Qt.font({pointSize: 13})
+ }
+
+ Slider {
+ id: quickControlsSlider
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.right: parent.right
+ anchors.rightMargin: 10
+ anchors.left: label.right
+ anchors.leftMargin: 20
+ from: labeledSlider.min
+ to: labeledSlider.max
+ width: labeledSlider.width - label.implicitWidth - (label.anchors.leftMargin + anchors.rightMargin + anchors.leftMargin)
+
+ Component.onCompleted: ()=> value = labeledSlider.init;
+ }
+}
diff --git a/examples/quick/canvas/bezierCurve/bezierCurve.qml b/examples/quick/canvas/bezierCurve/bezierCurve.qml
index 4f573ed64e..b284a40f4a 100644
--- a/examples/quick/canvas/bezierCurve/bezierCurve.qml
+++ b/examples/quick/canvas/bezierCurve/bezierCurve.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
Item {
id:container
@@ -62,7 +62,7 @@ Item {
anchors.fill: parent
anchors.topMargin: 12
- Text {
+ Label {
font.pointSize: 24
font.bold: true
text: "Bezier Curve"
@@ -130,8 +130,17 @@ Item {
id: controls
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id: lineWidthCtrl; min: 1; max: 10; init: 2; name: "Outline"}
- Slider {id: scaleCtrl; min: 0.1; max: 10; init: 1; name: "Scale"}
- Slider {id: rotateCtrl; min: 0; max: Math.PI*2; init: 0; name: "Rotate"}
+
+ LabeledSlider {
+ id: lineWidthCtrl; name: "Outline"; min: 1; max: 10; init: 2; width: container.width
+ }
+
+ LabeledSlider {
+ id: scaleCtrl; name: "Scale"; min: 0.1; max: 10; init: 1; width: container.width
+ }
+
+ LabeledSlider {
+ id: rotateCtrl; name: "Rotate"; min: 0; max: Math.PI*2; init: 0; width: container.width
+ }
}
}
diff --git a/examples/quick/canvas/canvas.qml b/examples/quick/canvas/canvas.qml
index 7768e1092b..34e4f5a07b 100644
--- a/examples/quick/canvas/canvas.qml
+++ b/examples/quick/canvas/canvas.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
import "../shared" as Examples
Item {
diff --git a/examples/quick/canvas/canvas.qrc b/examples/quick/canvas/canvas.qrc
index cfdfc844b9..7904309811 100644
--- a/examples/quick/canvas/canvas.qrc
+++ b/examples/quick/canvas/canvas.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/canvas">
<file>canvas.qml</file>
+ <file>LabeledSlider.qml</file>
<file>bezierCurve/bezierCurve.qml</file>
<file>clip/clip.qml</file>
<file>contents/qt-logo.png</file>
diff --git a/examples/quick/canvas/clip/clip.qml b/examples/quick/canvas/clip/clip.qml
index 1771121cd6..1c77657873 100644
--- a/examples/quick/canvas/clip/clip.qml
+++ b/examples/quick/canvas/clip/clip.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
Item {
id:container
@@ -61,7 +61,8 @@ Item {
spacing:5
anchors.fill: parent
anchors.topMargin: 12
- Text {
+
+ Label {
font.pointSize: 24
font.bold: true
text: "Squircle with Clip"
@@ -152,7 +153,8 @@ Item {
id: controls
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id: nCtrl; min: 1; max: 10; init: 4; name:"N"}
- Slider {id: rCtrl; min: 30; max: 180; init: 80; name:"Radius"}
+
+ LabeledSlider {id: nCtrl; min: 1; max: 10; init: 4; name: "N"; width: container.width}
+ LabeledSlider {id: rCtrl; min: 30; max: 180; init: 80; name: "Radius"; width: container.width}
}
}
diff --git a/examples/quick/canvas/quadraticCurveTo/quadraticCurveTo.qml b/examples/quick/canvas/quadraticCurveTo/quadraticCurveTo.qml
index cd93205995..ca83b3989c 100644
--- a/examples/quick/canvas/quadraticCurveTo/quadraticCurveTo.qml
+++ b/examples/quick/canvas/quadraticCurveTo/quadraticCurveTo.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
Item {
id:container
@@ -62,7 +62,7 @@ Item {
anchors.fill: parent
anchors.topMargin: 12
- Text {
+ Label {
font.pointSize: 24
font.bold: true
text: "Quadratic Curve"
@@ -138,8 +138,9 @@ Item {
Column {
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id:lineWidthCtrl; min:1; max:10; init:2; name:"Outline"}
- Slider {id:scaleCtrl; min:0.1; max:10; init:1; name:"Scale"}
- Slider {id:rotateCtrl; min:0; max:Math.PI*2; init:0; name:"Rotate"}
+
+ LabeledSlider {id:lineWidthCtrl; min:1; max:10; init:2; name: "Outline"; width: container.width}
+ LabeledSlider {id:scaleCtrl; min:0.1; max:10; init:1; name: "Scale"; width: container.width}
+ LabeledSlider {id:rotateCtrl; min:0; max:Math.PI*2; init:0; name: "Rotate"; width: container.width}
}
}
diff --git a/examples/quick/canvas/roundedrect/roundedrect.qml b/examples/quick/canvas/roundedrect/roundedrect.qml
index 08ede9b1e7..a4d6571cf8 100644
--- a/examples/quick/canvas/roundedrect/roundedrect.qml
+++ b/examples/quick/canvas/roundedrect/roundedrect.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
Item {
id:container
@@ -61,7 +61,8 @@ Item {
spacing: 6
anchors.fill: parent
anchors.topMargin: 12
- Text {
+
+ Label {
font.pointSize: 24
font.bold: true
text: "Rounded rectangle"
@@ -125,7 +126,8 @@ Item {
Column {
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id: lineWidthCtrl ; min: 1 ; max: 10; init: 2 ; name: "Outline"}
- Slider {id: rCtrl ; min: 10 ; max: 80 ; init: 40 ; name: "Radius"}
+
+ LabeledSlider {id: lineWidthCtrl ; min: 1 ; max: 10; init: 2 ; name: "Outline"; width: container.width}
+ LabeledSlider {id: rCtrl ; min: 10 ; max: 80 ; init: 40 ; name: "Radius"; width: container.width}
}
}
diff --git a/examples/quick/canvas/smile/smile.qml b/examples/quick/canvas/smile/smile.qml
index cde18d4d38..ddcf42d4d0 100644
--- a/examples/quick/canvas/smile/smile.qml
+++ b/examples/quick/canvas/smile/smile.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
Item {
id: container
@@ -62,7 +62,7 @@ Item {
anchors.fill: parent
anchors.topMargin: 12
- Text {
+ Label {
font.pointSize: 24
font.bold: true
text: "Smile with arcs"
@@ -131,8 +131,9 @@ Item {
id: controls
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id: lineWidthCtrl ; min: 1 ; max: 10 ; init: 2 ; name: "Outline"}
- Slider {id: scaleCtrl ; min: 0.1 ; max: 10 ; init: 1 ; name: "Scale"}
- Slider {id: rotateCtrl ; min: 0 ; max: Math.PI*2 ; init: 0 ; name: "Rotate"}
+
+ LabeledSlider {id: lineWidthCtrl ; min: 1 ; max: 10 ; init: 2 ; name: "Outline"; width: container.width}
+ LabeledSlider {id: scaleCtrl ; min: 0.1 ; max: 10 ; init: 1 ; name: "Scale"; width: container.width}
+ LabeledSlider {id: rotateCtrl ; min: 0 ; max: Math.PI*2 ; init: 0 ; name: "Rotate"; width: container.width}
}
}
diff --git a/examples/quick/canvas/squircle/squircle.qml b/examples/quick/canvas/squircle/squircle.qml
index 5416bfa1c7..f337c6adad 100644
--- a/examples/quick/canvas/squircle/squircle.qml
+++ b/examples/quick/canvas/squircle/squircle.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
Item {
id: container
@@ -61,7 +61,8 @@ Item {
spacing: 6
anchors.fill: parent
anchors.topMargin: 12
- Text {
+
+ Label {
font.pointSize: 24
font.bold: true
text: "Squircles"
@@ -154,7 +155,8 @@ Item {
Column {
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id: nCtrl ; min: 1 ; max: 10 ; init: 2 ; name: "N"}
- Slider {id: rCtrl ; min: 30 ; max: 180 ; init: 60 ; name: "Radius"}
+
+ LabeledSlider {id: nCtrl ; min: 1 ; max: 10 ; init: 2 ; name: "N"; width: container.width}
+ LabeledSlider {id: rCtrl ; min: 30 ; max: 180 ; init: 60 ; name: "Radius"; width: container.width}
}
}
diff --git a/examples/quick/canvas/tiger/tiger.qml b/examples/quick/canvas/tiger/tiger.qml
index 71367d560a..abd823d40e 100644
--- a/examples/quick/canvas/tiger/tiger.qml
+++ b/examples/quick/canvas/tiger/tiger.qml
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import "../contents"
-import "../../shared"
+import QtQuick
+import QtQuick.Controls
+import "../"
import "tiger.js" as Tiger
Item {
@@ -63,7 +63,7 @@ Item {
anchors.fill: parent
anchors.topMargin: 12
- Text {
+ Label {
font.pointSize: 24
font.bold: true
text: "Tiger with SVG path"
@@ -137,8 +137,9 @@ Item {
id: controls
anchors.bottom: parent.bottom
anchors.bottomMargin: 12
- Slider {id: scaleCtrl ; min: 0.1 ; max: 1 ; init: 0.3 ; name: "Scale"}
- Slider {id: rotateCtrl ; min: 0 ; max: Math.PI*2 ; init: 0 ; name: "Rotate"}
- Slider {id: alphaCtrl ; min: 0 ; max: 1 ; init: 1 ; name: "Alpha"}
+
+ LabeledSlider {id: scaleCtrl ; min: 0.1 ; max: 1 ; init: 0.3 ; name: "Scale"; width: container.width}
+ LabeledSlider {id: rotateCtrl ; min: 0 ; max: Math.PI*2 ; init: 0 ; name: "Rotate"; width: container.width}
+ LabeledSlider {id: alphaCtrl ; min: 0 ; max: 1 ; init: 1 ; name: "Alpha"; width: container.width}
}
}