Debian Codegraph @

src/imports/feedback/qdeclarativefeedbackeffect.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 "qdeclarativefeedbackeffect_p.h"
41
42 /*!
43 \qmltype FeedbackEffect
44 \instantiates QDeclarativeFeedbackEffect
45 \brief The FeedbackEffect element is the base class for all feedback effects.
46 \ingroup qml-feedback-api
47
48 You can't create one of these elements directly, but several other elements
49 inherit the methods and properties of these elements.
50
51 There are several predefined enumerations and constants provided in this class:
52
53 1. Duration
54 This enum describes the possible predefined duration types. Generally a specific
55 value in milliseconds can be supplied instead of one of these values.
56 \list
57 \li Feedback.Infinite - Infinite effect duration
58 \endlist
59
60 2. State
61 This enum describes the state of the effect. An effect will be in one of these states.
62 \list
63 \li Feedback.Stopped - The effect is not running. This is the initial state.
64 \li Feedback.Paused - The effect is paused.
65 \li Feedback.Running - The effect is running.
66 \li Feedback.Loading - The effect is loading.
67 \endlist
68
69 3. ErrorType
70 This enum describes the possible errors happening on the effect.
71 \list
72 \li Feedback.UnknownError - An unknown error occurred.
73 \li Feedback.DeviceBusy - The feedback could not start because the device is busy,
74 the device could be busy if a higher-priority client is using the haptics/actuator device.
75 \endlist
76
77
78 \sa FileEffect, ThemeEffect, HapticsEffect, {QFeedbackEffect}
79 */
80
81 QDeclarativeFeedbackEffect::QDeclarativeFeedbackEffect(QObject *parent)
82 : QObject(parent), m_running(false), m_paused(false), m_error(UnknownError)
83 {
84 }
85
86 void QDeclarativeFeedbackEffect::setFeedbackEffect(QFeedbackEffect* effect)
87 {
88 m_effect = effect;
89 QObject::connect(m_effect, SIGNAL(stateChanged()), this, SLOT(updateState()));
90 QObject::connect(m_effect, SIGNAL(error(QFeedbackEffect::ErrorType)), this, SLOT(_error(QFeedbackEffect::ErrorType)));
91 }
92 QFeedbackEffect* QDeclarativeFeedbackEffect::feedbackEffect()
93 {
94 return m_effect;
95 }
96
97 /*!
98 \qmlproperty bool FeedbackEffect::running
99
100 This property is true if this feedback effect is running.
101 */
102 bool QDeclarativeFeedbackEffect::isRunning() const
103 {
104 return m_running;
105 }
106 void QDeclarativeFeedbackEffect::setRunning(bool running)
107 {
108 QDeclarativeFeedbackEffect::State currentState = static_cast<QDeclarativeFeedbackEffect::State>(m_effect->state());
109 if (currentState != QDeclarativeFeedbackEffect::Running && running) {
110 m_running = true;
111 m_effect->start();
112 emit runningChanged();
113 } else if (currentState != QDeclarativeFeedbackEffect::Stopped && !running) {
114 m_running = false;
115 m_effect->stop();
116 emit runningChanged();
117 }
118 }
119
120 /*!
121 \qmlproperty bool FeedbackEffect::paused
122
123 This property is true if this feedback effect is paused.
124 */
125 bool QDeclarativeFeedbackEffect::isPaused() const
126 {
127 return m_paused;
128 }
129 void QDeclarativeFeedbackEffect::setPaused(bool paused)
130 {
131 QDeclarativeFeedbackEffect::State currentState = static_cast<QDeclarativeFeedbackEffect::State>(m_effect->state());
132 if (currentState == QDeclarativeFeedbackEffect::Paused && !paused) {
133 m_paused = true;
134 m_effect->start();
135 emit pausedChanged();
136 } else if (currentState == QDeclarativeFeedbackEffect::Running && paused) {
137 paused = false;
138 m_effect->pause();
139 emit pausedChanged();
140 }
141 }
142
143
144 /*!
145 \qmlproperty int FeedbackEffect::duration
146
147 The duration of the effect, in milliseconds. This is 0 for effects of unknown
148 duration, or Feedback.Infinite for effects that don't stop.
149 \sa Feedback
150 */
151 int QDeclarativeFeedbackEffect::duration() const
152 {
153 return m_effect->duration();
154 }
155 void QDeclarativeFeedbackEffect::setDuration(int newDuration)
156 {
157 Q_UNUSED(newDuration)
158 //default do nothing
159 }
160
161 /*!
162 \qmlproperty FeedbackEffect::State FeedbackEffect::state
163
164 This is the current state of the effect. It is one of:
165 \list
166 \li Feedback.Stopped - the effect is not playing.
167 \li Feedback.Loading - the effect is being loaded.
168 \li Feedback.Running - the effect is playing.
169 \li Feedback.Paused - the effect was being played, but is now paused.
170 \endlist
171 \sa Feedback
172 */
173 QDeclarativeFeedbackEffect::State QDeclarativeFeedbackEffect::state() const
174 {
175 return static_cast<QDeclarativeFeedbackEffect::State>(m_effect->state());
176 }
177
178 void QDeclarativeFeedbackEffect::setState(QDeclarativeFeedbackEffect::State newState)
179 {
180 Q_UNUSED(newState)
181 //default do nothing
182 }
183 /*!
184 \qmlproperty Feedback::ErrorType FeedbackEffect::error
185
186 This property holds the error status of the FeedbackEffect.
187 The error is one of the following values:
188 \list
189 \li Feedback.UnknownError - An unknown error occurred.
190 \li Feedback.DeviceBusy - The device resource is already being used.
191 \endlist
192
193 \sa Feedback, QFeedbackEffect::ErrorType
194 */
195 QDeclarativeFeedbackEffect::ErrorType QDeclarativeFeedbackEffect::error() const
196 {
197 return m_error;
198 }
199
200 /*!
201 \qmlmethod Feedback::updateState()
202
203 updates the state of the effect.
204 */
205 void QDeclarativeFeedbackEffect::updateState() {
206 bool running = m_effect->state() == QFeedbackEffect::Running;
207 bool paused = m_effect->state() == QFeedbackEffect::Paused;
208 if (running != m_running) {
209 m_running = running;
210 emit runningChanged();
211 }
212 if (paused != m_paused) {
213 m_paused = paused;
214 emit pausedChanged();
215 }
216 emit stateChanged();
217 }
218
219 /*!
220 \qmlmethod Feedback::start()
221
222 makes sure that the effect associated with the feedback object is started.
223 \sa QFeedbackEffect::start()
224 */
225 void QDeclarativeFeedbackEffect::start() {
226 m_effect->start();
227 }
228
229 /*!
230 \qmlmethod Feedback::stop()
231
232 makes sure that the effect associated with the feedback object is stoped.
233 \sa QFeedbackEffect::stop()
234 */
235 void QDeclarativeFeedbackEffect::stop() {
236 m_effect->stop();
237 }
238
239 /*!
240 \qmlmethod Feedback::pause()
241
242 makes sure that the effect associated with the feedback object is paused.
243 \sa QFeedbackEffect::pause()
244 */
245 void QDeclarativeFeedbackEffect::pause() {
246 m_effect->pause();
247 }
248
249 void QDeclarativeFeedbackEffect::_error(QFeedbackEffect::ErrorType err)
250 {
251 if (static_cast<ErrorType>(err) != m_error) {
252 m_error = static_cast<ErrorType>(err);
253 emit errorChanged();
254 }
255 }