import QtQuick import "../theme" // Hold-to-confirm overlay: accent liquid fills the parent shape while // `holding` is true and emits completed() once full. Let go early and it // drains. The glyph (or `inkSource`) turns the accent text colour where the // liquid covers it, so the overlay sits on top of the button's own glyph. Item { id: root property bool holding: false property int duration: 800 property real radius: Math.min(width, height) / 2 property color color: Theme.accent property color inkColor: Theme.accentText // The default ink is a centred glyph matching the button's own. property string glyph property string fallback property int glyphSize: Math.round(Math.min(width, height) * 0.5) property int glyphWeight: Font.Normal // Any transparent item the size of this one, e.g. a row of labels. property Item inkSource: defaultInk property real progress: 0 property real time: 0 // Stays full for a moment after completing, in case the action fails. property bool latched: false readonly property bool active: progress > 0 signal completed // Let go before full. signal cancelled onHoldingChanged: { if (latched) return; if (holding) { drain.stop(); rise.from = progress; rise.duration = Math.max(1, (1 - progress) * duration); rise.start(); } else if (rise.running || progress > 0) { rise.stop(); if (progress < 1) cancelled(); root.empty(); } } function empty() { drain.from = progress; drain.duration = Theme.duration * 2.2 * progress; drain.start(); } NumberAnimation { id: rise target: root property: "progress" to: 1 easing.type: Easing.InOutSine onFinished: if (root.progress >= 1) { root.latched = true; hold.restart(); root.completed(); } } NumberAnimation { id: drain target: root property: "progress" to: 0 easing.type: Easing.OutCubic } Timer { id: hold interval: 900 onTriggered: { root.latched = false; if (!root.holding) root.empty(); } } FrameAnimation { running: root.active && Theme.intensity > 0 onTriggered: root.time += frameTime } Text { id: defaultInk width: root.width height: root.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: Icons.available && root.glyph ? root.glyph : root.fallback font.family: Icons.available && root.glyph ? Icons.family : "" font.pixelSize: root.glyphSize font.weight: root.glyphWeight color: "white" } ShaderEffectSource { id: inkTexture sourceItem: root.inkSource hideSource: root.inkSource === defaultInk live: true visible: false } ShaderEffect { anchors.fill: parent visible: root.active property point size: Qt.point(width, height) property real radius: root.radius property real level: root.progress property real time: root.time // Sloshes more while draining than while filling. property real slosh: Math.max(1.2, root.height * 0.06) * Math.min(1, Theme.intensity) * (root.holding ? 1 : 1.6) property vector4d fill: Qt.vector4d(root.color.r * root.color.a, root.color.g * root.color.a, root.color.b * root.color.a, root.color.a) property vector4d ink: Qt.vector4d(root.inkColor.r * root.inkColor.a, root.inkColor.g * root.inkColor.a, root.inkColor.b * root.inkColor.a, root.inkColor.a) property var glyph: inkTexture fragmentShader: Qt.resolvedUrl("shaders/holdfill.frag.qsb") Behavior on slosh { NumberAnimation { duration: Theme.duration } } } }