Debian Codegraph @

src/imports/Components/2.0/Internal__Haptics.qml

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import org.kde.tactilefeedback
19 import Lomiri.Components
20
21 Item {
22 readonly property bool enabled: true
23 property alias effect: effect
24
25 function play(customEffect) {
26 if (effectData.data) {
27 // we have a custom effect playing, stop it
28 effect.stop();
29 }
30 if (effect.state === Feedback.Running) {
31 // this is a global effect, leave
32 return;
33 }
34 if (customEffect) {
35 effectData.backup(customEffect);
36 }
37 effect.start();
38 }
39
40 QtObject {
41 id: effectData
42 property var data
43
44 function backup(customEffect) {
45 data = customEffect;
46 for (var p in data) {
47 var value = data[p];
48 data[p] = effect[p];
49 effect[p] = value;
50 }
51 }
52 function restore() {
53 for (var p in data) {
54 effect[p] = data[p];
55 }
56 data = undefined;
57 }
58 }
59
60 //
61 // local feedback component used to play feedback
62 HapticsEffect {
63 id: effect
64 attackIntensity: 0.0
65 attackTime: 50
66 intensity: 1.0
67 duration: 10
68 fadeTime: 50
69 fadeIntensity: 0.0
70
71 onStateChanged: {
72 if (state === HapticsEffect.Stopped) {
73 effectData.restore();
74 }
75 }
76 }
77 }