diff options
Diffstat (limited to 'src/qml/doc/snippets')
| -rw-r--r-- | src/qml/doc/snippets/qml/Easing.qml | 35 | ||||
| -rw-r--r-- | src/qml/doc/snippets/qml/easingCurve.qml | 49 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/qml/doc/snippets/qml/Easing.qml b/src/qml/doc/snippets/qml/Easing.qml new file mode 100644 index 0000000000..b7a93a1e19 --- /dev/null +++ b/src/qml/doc/snippets/qml/Easing.qml @@ -0,0 +1,35 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick + +Item { +//! [0] + Rectangle { + id: rect + width: 100 + height: 100 + anchors.centerIn: parent + color: "red" + opacity: 0 + } + + FrameAnimation { + id: frameAnimation + running: true + + property real elapsed // In seconds. + readonly property real duration: 2 // Two seconds. + + onTriggered: { + elapsed += frameTime + // Loop once we reach the duration. + if (elapsed > duration) + elapsed = 0 + + // Increase the opacity from 0 slowly at first, then quickly. + rect.opacity = Easing.valueForProgress(Easing.InQuart, elapsed / duration) + } + } +//! [0] +} diff --git a/src/qml/doc/snippets/qml/easingCurve.qml b/src/qml/doc/snippets/qml/easingCurve.qml new file mode 100644 index 0000000000..3300383be7 --- /dev/null +++ b/src/qml/doc/snippets/qml/easingCurve.qml @@ -0,0 +1,49 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +//! [import QtQml] +import QtQml as QtQml +//! [import QtQml] +import QtQuick + +Item { +//! [children] + Rectangle { + id: rect + width: 100 + height: 100 + anchors.centerIn: parent + color: "red" + opacity: 0 + } + + FrameAnimation { + id: frameAnimation + running: true + + property real elapsed // In seconds. + readonly property real duration: 2 // Two seconds. +//! [easingCurve new declaration] + readonly property easingCurve easingCurve: Easing.InQuart +//! [easingCurve new declaration] + + onTriggered: { + elapsed += frameTime + // Loop once we reach the duration. + if (elapsed > duration) + elapsed = 0 + + // Increase the opacity from 0 slowly at first, then quickly. + rect.opacity = inQuartCurve.valueForProgress(elapsed / duration) + } + } +//! [children] + +//! [easingCurve structed value type declaration] + readonly property easingCurve inElasticCurve: ({ + type: Easing.InElastic, + amplitude: 4, + period: 3 + }) +//! [easingCurve structed value type declaration] +} |
