Debian Codegraph @

doc/src/snippets/declarative/declarative-feedback.qml

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50
51
52 import QtQuick 2.0
53
54 Rectangle {
55 id: page
56 width: 800
57 height: 350
58 color: "olive"
59
60 //![File Effect]
61 import QtFeedback 5.0
62
63 FileEffect {
64 id: myFileEffect
65 loaded: false
66 source: "file:///myfile.ivs"
67 }
68
69 MouseArea {
70 onClicked: myFileEffect.start();
71 }
72
73 //![File Effect]
74
75 //![Haptics Effect]
76
77 import QtFeedback 5.0
78
79 HapticsEffect {
80 id: rumbleEffect
81 attackIntensity: 0.0
82 attackTime: 250
83 intensity: 1.0
84 duration: 100
85 fadeTime: 250
86 fadeIntensity: 0.0
87 }
88 MouseArea {
89 onClicked: {
90 rumbleEffect.start(); // plays a rumble effect
91 }
92
93 //![Haptics Effect]
94
95 //![Theme]
96 //Example 1: using ThemeEffect declaring element
97
98 import QtFeedback 5.0
99
100 Rectangle {
101 width: 180; height: 20
102 radius:5
103 color: "lightgrey"
104 Text {
105 anchors.centerIn: parent
106 text: "Play Theme: Press"
107 }
108 ThemeEffect {
109 id: myOtherThemeEffect
110 effect: "Press"
111 }
112 MouseArea {
113 anchors.fill: parent
114 onClicked: {
115 myOtherThemeEffect.play();
116 }
117 }
118 }
119
120 //Example 2: using ThemeEffect without declaring element
121
122 import QtFeedback.ThemeEffect 5.0 as Effect
123
124 Rectangle {
125 width: 180; height: 20
126 radius:5
127 color: "lightgrey"
128 Text {
129 anchors.centerIn: parent
130 text: "Play Theme: Press"
131 }
132 MouseArea {
133 anchors.fill: parent
134 onClicked: {
135 Effect.effect = "Press"
136 Effect.play();
137 }
138 }
139 }
140
141 //Example 3: using ThemeEffect without declaring element and calling overloaded play function
142
143 import QtFeedback.ThemeEffect 5.0 as Effect
144
145 Rectangle {
146 width: 180; height: 20
147 radius:5
148 color: "lightgrey"
149 Text {
150 anchors.centerIn: parent
151 text: "Play Theme: Press"
152 }
153 MouseArea {
154 anchors.fill: parent
155 onClicked: {
156 Effect.play(Effect.Press)
157 }
158 }
159 }
160
161 //![Theme]
162
163 //! [Play the system theme button click effect]
164 import QtFeedback.ThemeEffect 5.0 as Effect
165
166 Rectangle {
167 width: 180; height: 20
168 radius:5
169 color: "lightgrey"
170 Text {
171 anchors.centerIn: parent
172 text: "Play Theme: Press"
173 }
174 MouseArea {
175 anchors.fill: parent
176 onClicked: {
177 Effect.play(Effect.Press)
178 }
179 }
180 }
181 //! [Play the system theme button click effect]
182
183 //! [Start playing a custom haptic effect]
184 rumble.start();
185 //! [Start playing a custom haptic effect]
186
187 //! [Pause a custom haptic effect]
188 rumble.pause();
189 //! [Pause a custom haptic effect]
190
191 //! [Stop playing a custom haptic effect]
192 rumble.stop();
193 //! [Stop playing a custom haptic effect]
194
195 //! [Query the state of a custom haptic effect]
196 if (rumble.state === Feedback.Stopped)
197 console.log("The device has stopped rumbling.")
198 //! [Query the state of a custom haptic effect]
199
200 //! [Set the actuator which should play the custom effect]
201 for (var i = 0; rumble.availableActuators[i]; i++) {
202 if (rumble.availableActuators[i].name === "ExampleActuatorName") {
203 rumble.actuator = rumble.availableActuators[i]
204 }
205 }
206 //! [Set the actuator which should play the custom effect]