qtdoc/examples/demos/coffee/Progress.qml

274 lines
9.3 KiB
QML
Raw Normal View History

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Effects
Item {
// Height, width and any other size related properties containing odd looking float or other dividers
// that do not seem to have any logical origin are just arbitrary and based on original design
// and/or personal preference on what looks nice.
id: root
property alias timer: timer
property alias greenBar: greenBar
property alias cup: cup
property int brewTime
property int maxCoffee
property int maxmilk
property int maxFoam
property int coffeeAmount
property int milkAmount
property int foamAmount
property double sugarAmount
property double progressBarValue: 0
states: [
State {
name: "portrait"
PropertyChanges {
target: cup
Layout.alignment: Qt.AlignCenter | Qt.AlignTop
Layout.preferredWidth: height / 1.16
Layout.preferredHeight: root.height / 3
}
PropertyChanges {
target: dialog
Layout.preferredWidth: root.width / 1.12
Layout.preferredHeight: root.height / 7
}
},
State {
name: "landscape"
PropertyChanges {
target: grid
rowSpacing: 10
}
PropertyChanges {
target: cup
Layout.alignment: Qt.AlignCenter | Qt.AlignTop
Layout.preferredWidth: height / 1.16
Layout.preferredHeight: root.height / 2.5
}
PropertyChanges {
target: dialog
Layout.preferredWidth: root.width / 2.5
Layout.preferredHeight: root.height / 5
}
PropertyChanges {
target: control
Layout.bottomMargin: 10
}
}
]
//! [Timer]
Timer {
id: timer
interval: brewTime
running: true
onTriggered: {
applicationFlow.onFinished()
}
}
//! [Timer]
//! [Behavior]
Behavior on greenBar.width {
SmoothedAnimation {
easing.type: Easing.Linear
velocity: (contentItem.width / brewTime) * 1000
}
}
//! [Behavior]
GridLayout {
id: grid
rowSpacing: 20
anchors.horizontalCenter: parent.horizontalCenter
flow: GridLayout.TopToBottom
//! [Cup]
Cup {
id: cup
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
state: "0"
states: [
State {
name: "0"
PropertyChanges {
target: cup
coffeeAmount: 0
}
PropertyChanges {
target: cup
milkAmount: 0
}
PropertyChanges {
target: cup
foamAmount: 0
}
PropertyChanges {
target: cup
sugarAmount: 0
}
},
State {
name: "1"
PropertyChanges {
target: cup
coffeeAmount: root.coffeeAmount
}
PropertyChanges {
target: cup
milkAmount: root.milkAmount
}
PropertyChanges {
target: cup
foamAmount: root.foamAmount
}
PropertyChanges {
target: cup
sugarAmount: root.sugarAmount
}
}
]
transitions: Transition {
from: "0"
to: "1"
SmoothedAnimation {
target: cup
property: "coffeeAmount"
velocity: (coffeeAmount / brewTime) * 1200
}
SmoothedAnimation {
target: cup
property: "milkAmount"
velocity: (milkAmount / brewTime) * 1200
}
SmoothedAnimation {
target: cup
property: "foamAmount"
velocity: (foamAmount / brewTime) * 1200
}
SmoothedAnimation {
target: cup
property: "sugarAmount"
velocity: (sugarAmount / brewTime) * 1200
}
}
}
//! [Cup]
Rectangle {
id: dialog
radius: 8
Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
gradient: Colors.greyBorder
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
Layout.minimumHeight: 30
Layout.minimumWidth: 350
Rectangle {
id: rectangle
width: parent.width - 2
height: parent.height - 2
radius: 8
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
color: Colors.currentTheme.cardColor
Text {
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
id: caption
text: "Your Coffee is preparing, Please Wait!"
color: Colors.currentTheme.textColor
font.pixelSize: 18
font.weight: 600
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
states: [
State {
name: "small"
when: ((Screen.height * Screen.devicePixelRatio) + (Screen.width * Screen.devicePixelRatio)) < 2000
PropertyChanges {
target: caption
font.pixelSize: 16
}
}
]
}
}
MultiEffect {
source: rectangle
anchors.fill: rectangle
shadowEnabled: true
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
shadowColor: Colors.shadow
shadowOpacity: 0.5
}
}
ProgressBar {
id: control
Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
value: progressBarValue
Layout.topMargin: 20
background: Rectangle {
implicitHeight: 2
color: "#e6e6e6"
}
contentItem: Item {
id: contentItem
implicitWidth: dialog.width / 1.5
implicitHeight: 2
Rectangle {
id: greenBar
width: control.visualPosition * parent.width
height: parent.height
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
color: Colors.green
}
Image {
id: circle
source: (Colors.currentTheme == Colors.dark) ? "./images/icons/ellipse_dark.svg" : "./images/icons/ellipse_light.svg"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.left
}
Image {
id: circle2
source: (Colors.currentTheme == Colors.dark) ? "./images/icons/ellipse_dark.svg" : "./images/icons/ellipse_light.svg"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
}
Image {
id: circle3
source: (Colors.currentTheme == Colors.dark) ? "./images/icons/ellipse_dark.svg" : "./images/icons/ellipse_light.svg"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.right
}
Text {
text: "0%"
font.pixelSize: 12
anchors.horizontalCenter: circle.horizontalCenter
anchors.verticalCenter: circle.verticalCenter
color: Colors.currentTheme.textColor
}
Text {
text: "50%"
font.pixelSize: 12
anchors.horizontalCenter: circle2.horizontalCenter
anchors.verticalCenter: circle2.verticalCenter
color: Colors.currentTheme.textColor
}
Text {
text: "100%"
font.pixelSize: 12
anchors.horizontalCenter: circle3.horizontalCenter
anchors.verticalCenter: circle3.verticalCenter
color: Colors.currentTheme.textColor
}
}
}
Text {
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
color: Colors.green
text: qsTr("Brewing...")
Layout.alignment: Qt.AlignHCenter
font.pixelSize: 12
font.weight: 600
}
}
}