Debian Codegraph @

src/imports/feedback/qdeclarativehapticseffect.cpp

raw symbols SCIP
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 QtFeedback module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qdeclarativehapticseffect_p.h"
41 /*!
42 \qmltype HapticsEffect
43 \brief The HapticsEffect element represents a custom haptic feedback effect.
44 \ingroup qml-feedback-api
45 \inherits FeedbackEffect
46
47 This class closely corresponds to the C++ \l QFeedbackHapticsEffect class.
48
49 \snippet doc/src/snippets/declarative/declarative-feedback.qml Haptics Effect
50
51 \sa Actuator, {QFeedbackHapticsEffect}
52 */
53 QDeclarativeHapticsEffect::QDeclarativeHapticsEffect(QObject *parent)
54 : QDeclarativeFeedbackEffect(parent), m_actuator(0)
55 {
56 d = new QFeedbackHapticsEffect(this);
57 setFeedbackEffect(d);
58
59 QFeedbackActuator* fa = d->actuator();
60
61 QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators();
62 foreach (QFeedbackActuator* actuator, actuators) {
63 QDeclarativeFeedbackActuator* dfa;
64 dfa = new QDeclarativeFeedbackActuator(this, actuator);
65 if (fa && *fa == *actuator) {
66 m_actuator = dfa;
67 }
68 m_actuators.push_back(dfa);
69 }
70 }
71
72 void QDeclarativeHapticsEffect::setDuration(int msecs)
73 {
74 if (msecs != d->duration()) {
75 d->setDuration(msecs);
76 emit durationChanged();
77 }
78 }
79
80 int QDeclarativeHapticsEffect::duration() const
81 {
82 return d->duration();
83 }
84 /*!
85 \qmlproperty double HapticsEffect::intensity
86
87 The intensity of the main part of the haptics effect, from 0.0 to 1.0.
88 */
89 void QDeclarativeHapticsEffect::setIntensity(qreal intensity)
90 {
91 if (!qFuzzyCompare(intensity, d->intensity())) {
92 d->setIntensity(intensity);
93 emit intensityChanged();
94 }
95 }
96
97 qreal QDeclarativeHapticsEffect::intensity() const
98 {
99 return d->intensity();
100 }
101
102 /*!
103 \qmlproperty int HapticsEffect::attackTime
104
105 The duration of the attack (fade-in) part of the haptics effect.
106 */
107
108 void QDeclarativeHapticsEffect::setAttackTime(int msecs)
109 {
110 if (msecs != d->attackTime()) {
111 d->setAttackTime(msecs);
112 emit attackTimeChanged();
113 }
114 }
115
116 int QDeclarativeHapticsEffect::attackTime() const
117 {
118 return d->attackTime();
119 }
120 /*!
121 \qmlproperty double HapticsEffect::attackIntensity
122
123 The intensity of the attack (fade-in) part of the haptics effect, from 0.0 to 1.0.
124 */
125 void QDeclarativeHapticsEffect::setAttackIntensity(qreal intensity)
126 {
127 if (!qFuzzyCompare(intensity, d->attackIntensity())) {
128 d->setAttackIntensity(intensity);
129 emit intensityChanged();
130 }
131 }
132
133 qreal QDeclarativeHapticsEffect::attackIntensity() const
134 {
135 return d->attackIntensity();
136 }
137 /*!
138 \qmlproperty int HapticsEffect::fadeTime
139
140 The duration of the fade-out part of the haptics effect.
141 */
142
143 void QDeclarativeHapticsEffect::setFadeTime(int msecs)
144 {
145 if (msecs != d->fadeTime()) {
146 d->setFadeTime(msecs);
147 emit fadeTimeChanged();
148 }
149 }
150
151 int QDeclarativeHapticsEffect::fadeTime() const
152 {
153 return d->fadeTime();
154 }
155
156 void QDeclarativeHapticsEffect::setFadeIntensity(qreal intensity)
157 {
158 if (!qFuzzyCompare(intensity, d->fadeIntensity())) {
159 d->setFadeIntensity(intensity);
160 emit fadeIntensityChanged();
161 }
162 }
163 /*!
164 \qmlproperty double HapticsEffect::fadeIntensity
165
166 The intensity of the fade-out part of the haptics effect, from 0.0 to 1.0.
167 */
168 qreal QDeclarativeHapticsEffect::fadeIntensity() const
169 {
170 return d->fadeIntensity();
171 }
172 /*!
173 \qmlproperty int HapticsEffect::period
174
175 The period of the haptics effect. If the period is zero, the effect will
176 not repeat. If it is non-zero, the effect will repeat every period milliseconds.
177 */
178
179 void QDeclarativeHapticsEffect::setPeriod(int msecs)
180 {
181 if (msecs != d->period()) {
182 d->setPeriod(msecs);
183 emit periodChanged();
184 }
185 }
186
187 int QDeclarativeHapticsEffect::period() const
188 {
189 return d->period();
190 }
191
192 /*!
193 \qmlproperty Actuator HapticsEffect::actuator
194
195 The actuator that is used for playing this effect.
196 \sa Actuator
197 */
198 void QDeclarativeHapticsEffect::setActuator(QDeclarativeFeedbackActuator *actuator)
199 {
200 if (actuator != m_actuator) {
201 if (!actuator
202 || !m_actuator
203 || !(*(actuator->feedbackActuator()) == *(m_actuator->feedbackActuator()))) {
204 m_actuator = actuator;
205 d->setActuator(m_actuator ? m_actuator->feedbackActuator() : 0);
206 emit actuatorChanged();
207 }
208 }
209 }
210
211 QDeclarativeFeedbackActuator* QDeclarativeHapticsEffect::actuator() const
212 {
213 return m_actuator;
214 }
215 /*!
216 \qmlproperty list<Actuator> HapticsEffect::availableActuators
217
218 This property holds a list of available actuators.
219 This property is read only.
220 \sa Actuator
221 */
222 QQmlListProperty<QDeclarativeFeedbackActuator> QDeclarativeHapticsEffect::availableActuators() {
223 return QQmlListProperty<QDeclarativeFeedbackActuator>(this,
224 0,
225 0 /*appending actuators are not allowed*/,
226 actuator_count,
227 actuator_at,
228 0 /*removing actuators are not allowed*/);
229 }
230
231 int QDeclarativeHapticsEffect::actuator_count(QQmlListProperty<QDeclarativeFeedbackActuator> *prop)
232 {
233 return static_cast<QDeclarativeHapticsEffect*>(prop->object)->m_actuators.size();
234 }
235 QDeclarativeFeedbackActuator* QDeclarativeHapticsEffect::actuator_at(QQmlListProperty<QDeclarativeFeedbackActuator> *prop, int index)
236 {
237 return static_cast<QDeclarativeHapticsEffect*>(prop->object)->m_actuators.at(index);
238 }