File: QuickActionButton.qml

package info (click to toggle)
plasma-mobile 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,412 kB
  • sloc: xml: 38,474; cpp: 18,529; javascript: 139; sh: 82; makefile: 5
file content (135 lines) | stat: -rw-r--r-- 3,843 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// SPDX-FileCopyrightText: 2025 User8395 <therealuser8395@proton.me>
// SPDX-License-Identifier: GPL-2.0-or-later

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

import org.kde.plasma.quicksetting.flashlight
import org.kde.plasma.private.mobileshell as MobileShell
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
import org.kde.kirigami as Kirigami

AbstractButton {
    id: root

    property int buttonAction

    property bool buttonHeld: false
    property double scale: pressed ? (buttonHeld ? 1.7 : 1.5) : 1
    property real fillAmount: 0.0

    Behavior on scale {
        NumberAnimation {
            duration: Kirigami.Units.longDuration
            easing.type: Easing.OutBack
        }
    }

    MobileShell.HapticsEffect {
        id: haptics
    }

    visible: buttonAction !== ShellSettings.Settings.None
    padding: Math.round(Kirigami.Units.gridUnit * 1.25)

    transform: Scale {
        origin.x: width / 2
        origin.y: height / 2
        xScale: scale
        yScale: scale
    }

    background: Rectangle {
        radius: width
        color: Qt.rgba(255, 255, 255, 0.2)

        Rectangle {
            anchors.centerIn: parent
            width: parent.width * root.fillAmount
            height: parent.height * root.fillAmount
            radius: Math.min(width, height)
            color: Qt.rgba(255, 255, 255, 0.2) // Use the same background rectangle color
        }
    }

    contentItem: Item {
        Kirigami.Icon {
            anchors.centerIn: parent
            width: Kirigami.Units.iconSizes.small
            height: Kirigami.Units.iconSizes.small
            source: {
                switch (buttonAction) {
                    case ShellSettings.Settings.Flashlight:
                        return "flashlight-on-symbolic"
                    case ShellSettings.Settings.Camera:
                        return "camera-photo-symbolic"
                }
            }
            Kirigami.Theme.inherit: false
            Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
        }
    }

    onPressedChanged: {
        if (pressed) {
            pressedTimer.restart();
            buttonHeld = false;

            // Ensure emptyAnimation is not running
            // And fillAnimation use current fillAmount state before start
            // To avoid "reset" glitch
            emptyAnimation.stop();
            fillAnimation.from = root.fillAmount;
            fillAnimation.start();
        } else {
            pressedTimer.stop();

            // Ensure fillAnimation is not running
            // And emptyAnimation use current fillAmount state before start
            // To avoid "reset" glitch
            fillAnimation.stop();
            emptyAnimation.from = root.fillAmount;
            emptyAnimation.start();
        }
    }

    function triggerButtonAction() {
        switch (buttonAction) {
            case ShellSettings.Settings.Flashlight:
                FlashlightUtil.toggleTorch();
                return;
            case ShellSettings.Settings.Camera:
                MobileShell.ShellUtil.launchApp("org.kde.plasma.camera");
                flickable.goToOpenPosition();
                return;
        }
    }

    Timer {
        id: pressedTimer
        interval: Kirigami.Units.longDuration
        repeat: false
        onTriggered: {
            haptics.buttonVibrate();
            buttonHeld = true;
            triggerButtonAction();
        }
    }

    PropertyAnimation {
        id: fillAnimation
        target: root
        property: "fillAmount"
        duration: Kirigami.Units.longDuration
        to: 1.0
    }

    PropertyAnimation {
        id: emptyAnimation
        target: root
        property: "fillAmount"
        duration: Kirigami.Units.longDuration
        to: 0.0
    }
}