HapticPage.qml 5,6 КБ
Newer Older
Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
1
// SPDX-FileCopyrightText: 2023 - 2024 Open Mobile Platform LLC <community@omp.ru>
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
2
// SPDX-FileCopyrightText: 2013 Jolla Ltd
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
3
// SPDX-License-Identifier: BSD-3-Clause
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
4
5

import QtQuick 2.0
Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
6
import QtQuick.Layouts 1.0
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
7
8
9
10
11
12
import QtFeedback 5.0
import Sailfish.Silica 1.0

Page {
    id: page

Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
13
    property var effects: [ThemeEffect.Press, ThemeEffect.Release, ThemeEffect.PressWeak, ThemeEffect.ReleaseWeak, ThemeEffect.PressStrong, ThemeEffect.ReleaseStrong, ThemeEffect.DragStart, ThemeEffect.DragDropInZone, ThemeEffect.DragDropOutOfZone, ThemeEffect.DragCrossBoundary, ThemeEffect.Appear, ThemeEffect.Disappear, ThemeEffect.Move]
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
14

Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
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
    property var effectsDescription: [
        //% "Press / Button"
        qsTrId("ui-component-gallery-haptic-press-button"),
        //% "Release"
        qsTrId("ui-component-gallery-haptic-release"),
        //% "PressWeak / Keypad"
        qsTrId("ui-component-gallery-haptic-press-weak-keypad"),
        //% "ReleaseWeak"
        qsTrId("ui-component-gallery-haptic-release-weak"),
        //% "PressStrong / Long"
        qsTrId("ui-component-gallery-haptic-press-strong-long"),
        //% "ReleaseStrong"
        qsTrId("ui-component-gallery-haptic-release-strong"),
        //% "DragStart"
        qsTrId("ui-component-gallery-haptic-drag-start"),
        //% "DragDropInZone"
        qsTrId("ui-component-gallery-haptic-drag-drop-in-zone"),
        //% "DragDropOutOfZone"
        qsTrId("ui-component-gallery-haptic-drag-drop-out-of-zone"),
        //% "DragCrossBoundary"
        qsTrId("ui-component-gallery-haptic-drag-cross-boundary"),
        //% "Appear"
        qsTrId("ui-component-gallery-haptic-appear"),
        //% "Disappear"
        qsTrId("ui-component-gallery-haptic-disappear"),
        //% "Move"
        qsTrId("ui-component-gallery-haptic-move")]
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
42
43

    ThemeEffect {
Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
44
        id: customVibro
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    }

    HapticsEffect {
        id: customBuzz
        intensity: intensitySlider.value
        duration: Math.round(durationSlider.value)
    }

    HapticsEffect {
        id: periodicBuzz
        intensity: 0.9
        duration: 2000
        attackTime: 500
        fadeTime: 1000
        attackIntensity: 0.5
        fadeIntensity: 0.1
        period: 20
    }

    SilicaFlickable {
        anchors.fill: parent
        contentHeight: column.height + Theme.paddingLarge
        contentWidth: parent.width

Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
69
70
        VerticalScrollDecorator {
        }
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
71
72
73
74
75
76
77
        Column {
            id: column

            width: parent.width
            spacing: Theme.paddingLarge

            PageHeader {
Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
78
                title: "Haptics"
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
79
80
81
            }

            SectionHeader {
Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
82
83
                //% "Custom effects"
                text: qsTrId("ui-component-gallery-haptic-custom-effects")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
84
85
            }
            Button {
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
86
87
                //% "Periodic"
                text: qsTrId("ui-component-gallery-haptic-periodic")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
88
89
90
91
92
                anchors.horizontalCenter: parent.horizontalCenter
                onPressed: periodicBuzz.start()
            }
            Label {
                x: Theme.horizontalPageMargin
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
93
94
                //% "Effect duration:"
                text: qsTrId("ui-component-gallery-haptic-effect-duration")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
95
96
97
98
99
100
101
102
103
104
105
            }
            Slider {
                id: durationSlider
                width: page.width
                value: 20
                valueText: Math.round(durationSlider.value)
                minimumValue: 1
                maximumValue: 500
            }
            Label {
                x: Theme.horizontalPageMargin
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
106
107
                //% "Effect intensity:"
                text: qsTrId("ui-component-gallery-haptic-effect-intensity")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
108
109
110
111
112
113
114
115
116
117
            }
            Slider {
                id: intensitySlider
                width: page.width
                value: 0.5
                valueText: Math.round(intensitySlider.value)
                minimumValue: 0.1
                maximumValue: 1.0
            }
            Button {
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
118
119
                //% "onPressed"
                text: qsTrId("ui-component-gallery-haptic-on-pressed")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
120
121
122
123
124
                anchors.horizontalCenter: parent.horizontalCenter
                onPressed: customBuzz.start()
            }
            Button {
                anchors.horizontalCenter: parent.horizontalCenter
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
125
126
                //% "onReleased"
                text: qsTrId("ui-component-gallery-haptic-on-released")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
127
128
129
                onReleased: customBuzz.start()
            }
            Button {
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
130
131
                //% "onClicked"
                text: qsTrId("ui-component-gallery-haptic-on-clicked")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
132
133
134
135
                anchors.horizontalCenter: parent.horizontalCenter
                onClicked: customBuzz.start()
            }
            Button {
Alexey Andreyev's avatar
Alexey Andreyev включено в состав коммита
136
137
                //% "onPressed, onReleased"
                text: qsTrId("ui-component-gallery-haptic-on-pressed-on-released")
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
138
139
140
141
                anchors.horizontalCenter: parent.horizontalCenter
                onPressed: customBuzz.start()
                onReleased: customBuzz.start()
            }
Aleksandr Komakhin's avatar
Aleksandr Komakhin включено в состав коммита
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
            SectionHeader {
                //% "onPressed effects (Qt name / Theme name)"
                text: qsTrId("ui-component-gallery-haptic-on-pressed-effects-qt-name-theme-name")
            }
            GridLayout {
                anchors.horizontalCenter: parent.horizontalCenter
                width: page.width - Theme.paddingMedium * 2
                columns: 2
                rowSpacing: Theme.paddingLarge

                Repeater {
                    model: effects

                    Button {
                        preferredWidth: Theme.buttonWidthExtraSmall
                        text: effectsDescription[index]
                        onPressed: customVibro.play(effects[index])
                    }
                }
            }
Alexey Andreev's avatar
Alexey Andreev включено в состав коммита
162
163
164
        }
    }
}