1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtFeedback module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QFEEDBACKEFFECT_H
38#define QFEEDBACKEFFECT_H
39
40#include "qfeedbackglobal.h"
41
42#include <QtCore/QObject>
43#include <QtCore/QStringList>
44#include <QtCore/QUrl>
45
46QT_BEGIN_HEADER
47QT_BEGIN_NAMESPACE
48
49class QFeedbackActuator;
50class QFeedbackFileEffectPrivate;
51class QFeedbackHapticsEffectPrivate;
52
53class Q_FEEDBACK_EXPORT QFeedbackEffect : public QObject
54{
55 Q_OBJECT
56 Q_ENUMS(Effect)
57 Q_ENUMS(Duration)
58 Q_ENUMS(State)
59 Q_ENUMS(ErrorType)
60
61 Q_PROPERTY(int duration READ duration)
62 Q_PROPERTY(State state READ state NOTIFY stateChanged)
63
64public:
65 // Make sure these are kept up to date with the declarative version
66 enum Effect {
67 Undefined = -1, Press, Release, PressWeak, ReleaseWeak, PressStrong, ReleaseStrong, DragStart,
68 DragDropInZone, DragDropOutOfZone, DragCrossBoundary, Appear, Disappear, Move,
69 NumberOfEffects,
70 UserEffect = 65535
71 };
72
73 enum Duration {
74 Infinite = -1
75 };
76
77 enum State {
78 Stopped,
79 Paused,
80 Running,
81 Loading
82 };
83
84 enum ErrorType {
85 UnknownError,
86 DeviceBusy
87 };
88
89 explicit QFeedbackEffect(QObject *parent = Q_NULLPTR);
90
91 virtual State state() const = 0;
92 virtual int duration() const = 0;
93
94 //for themes
95 static bool supportsThemeEffect();
96 static bool playThemeEffect(Effect effect);
97
98public Q_SLOTS:
99 void start();
100 void stop();
101 void pause();
102
103protected:
104 virtual void setState(State) = 0;
105
106Q_SIGNALS:
107 void error(QFeedbackEffect::ErrorType) const; //when an error occurs
108 void stateChanged();
109
110private:
111 friend class QFeedbackInterface;
112};
113
114class Q_FEEDBACK_EXPORT QFeedbackHapticsEffect : public QFeedbackEffect
115{
116 Q_OBJECT
117
118 Q_PROPERTY(int duration READ duration WRITE setDuration)
119 Q_PROPERTY(qreal intensity READ intensity WRITE setIntensity)
120 Q_PROPERTY(int attackTime READ attackTime WRITE setAttackTime)
121 Q_PROPERTY(qreal attackIntensity READ attackIntensity WRITE setAttackIntensity)
122 Q_PROPERTY(int fadeTime READ fadeTime WRITE setFadeTime)
123 Q_PROPERTY(qreal fadeIntensity READ fadeIntensity WRITE setFadeIntensity)
124 Q_PROPERTY(int period READ period WRITE setPeriod)
125 Q_PROPERTY(QFeedbackActuator* actuator READ actuator WRITE setActuator)
126
127public:
128 explicit QFeedbackHapticsEffect(QObject *parent = Q_NULLPTR);
129 ~QFeedbackHapticsEffect();
130
131 void setDuration(int msecs);
132 int duration() const;
133
134 void setIntensity(qreal intensity);
135 qreal intensity() const;
136
137 //the envelope
138 void setAttackTime(int msecs);
139 int attackTime() const;
140
141 void setAttackIntensity(qreal intensity);
142 qreal attackIntensity() const;
143
144 void setFadeTime(int msecs);
145 int fadeTime() const;
146
147 void setFadeIntensity(qreal intensity);
148 qreal fadeIntensity() const;
149
150 void setPeriod(int msecs);
151 int period() const;
152
153 void setActuator(QFeedbackActuator *actuator);
154 QFeedbackActuator* actuator() const;
155
156 //reimplementations from QFeedbackEffect
157 virtual State state() const;
158
159protected:
160 virtual void setState(State);
161
162private:
163 Q_DISABLE_COPY(QFeedbackHapticsEffect)
164 friend class QFeedbackHapticsEffectPrivate;
165 QScopedPointer<QFeedbackHapticsEffectPrivate> priv;
166};
167
168class Q_FEEDBACK_EXPORT QFeedbackFileEffect : public QFeedbackEffect
169{
170 Q_OBJECT
171
172 Q_PROPERTY(bool loaded READ isLoaded WRITE setLoaded)
173 Q_PROPERTY(QUrl source READ source WRITE setSource)
174
175public:
176 explicit QFeedbackFileEffect(QObject *parent = Q_NULLPTR);
177 ~QFeedbackFileEffect();
178
179 int duration() const;
180
181 bool isLoaded() const;
182
183 void load();
184 void unload();
185 void setLoaded(bool);
186
187 QUrl source() const;
188 void setSource(const QUrl &);
189
190 static QStringList supportedMimeTypes();
191
192 //reimplementations from QFeedbackEffect
193 virtual State state() const;
194
195protected:
196 virtual void setState(State);
197
198private:
199 Q_DISABLE_COPY(QFeedbackFileEffect)
200 friend class QFeedbackFileEffectPrivate;
201 QScopedPointer<QFeedbackFileEffectPrivate> priv;
202};
203
204QT_END_NAMESPACE
205QT_END_HEADER
206
207#endif // QFEEDBACKEFFECT_H
208

source code of qtfeedback/src/feedback/qfeedbackeffect.h