Debian Codegraph @

src/feedback/qfeedbackeffect.h

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 #ifndef QFEEDBACKEFFECT_H
41 #define QFEEDBACKEFFECT_H
42
43 #include "qfeedbackglobal.h"
44
45 #include <QtCore/QObject>
46 #include <QtCore/QStringList>
47 #include <QtCore/QUrl>
48
49 QT_BEGIN_HEADER
50 QT_BEGIN_NAMESPACE
51
52 class QFeedbackActuator;
53 class QFeedbackFileEffectPrivate;
54 class QFeedbackHapticsEffectPrivate;
55
56 class Q_FEEDBACK_EXPORT QFeedbackEffect : public QObject
57 {
58 Q_OBJECT
59 Q_ENUMS(Effect)
60 Q_ENUMS(Duration)
61 Q_ENUMS(State)
62 Q_ENUMS(ErrorType)
63
64 Q_PROPERTY(int duration READ duration)
65 Q_PROPERTY(State state READ state NOTIFY stateChanged)
66
67 public:
68 // Make sure these are kept up to date with the declarative version
69 enum Effect {
70 Undefined = -1, Press, Release, PressWeak, ReleaseWeak, PressStrong, ReleaseStrong, DragStart,
71 DragDropInZone, DragDropOutOfZone, DragCrossBoundary, Appear, Disappear, Move,
72 NumberOfEffects,
73 UserEffect = 65535
74 };
75
76 enum Duration {
77 Infinite = -1
78 };
79
80 enum State {
81 Stopped,
82 Paused,
83 Running,
84 Loading
85 };
86
87 enum ErrorType {
88 UnknownError,
89 DeviceBusy
90 };
91
92 explicit QFeedbackEffect(QObject *parent = Q_NULLPTR);
93
94 virtual State state() const = 0;
95 virtual int duration() const = 0;
96
97 //for themes
98 static bool supportsThemeEffect();
99 static bool playThemeEffect(Effect effect);
100
101 public Q_SLOTS:
102 void start();
103 void stop();
104 void pause();
105
106 protected:
107 virtual void setState(State) = 0;
108
109 Q_SIGNALS:
110 void error(QFeedbackEffect::ErrorType) const; //when an error occurs
111 void stateChanged();
112
113 private:
114 friend class QFeedbackInterface;
115 };
116
117 class Q_FEEDBACK_EXPORT QFeedbackHapticsEffect : public QFeedbackEffect
118 {
119 Q_OBJECT
120
121 Q_PROPERTY(int duration READ duration WRITE setDuration)
122 Q_PROPERTY(qreal intensity READ intensity WRITE setIntensity)
123 Q_PROPERTY(int attackTime READ attackTime WRITE setAttackTime)
124 Q_PROPERTY(qreal attackIntensity READ attackIntensity WRITE setAttackIntensity)
125 Q_PROPERTY(int fadeTime READ fadeTime WRITE setFadeTime)
126 Q_PROPERTY(qreal fadeIntensity READ fadeIntensity WRITE setFadeIntensity)
127 Q_PROPERTY(int period READ period WRITE setPeriod)
128 Q_PROPERTY(QFeedbackActuator* actuator READ actuator WRITE setActuator)
129
130 public:
131 explicit QFeedbackHapticsEffect(QObject *parent = Q_NULLPTR);
132 ~QFeedbackHapticsEffect();
133
134 void setDuration(int msecs);
135 int duration() const;
136
137 void setIntensity(qreal intensity);
138 qreal intensity() const;
139
140 //the envelope
141 void setAttackTime(int msecs);
142 int attackTime() const;
143
144 void setAttackIntensity(qreal intensity);
145 qreal attackIntensity() const;
146
147 void setFadeTime(int msecs);
148 int fadeTime() const;
149
150 void setFadeIntensity(qreal intensity);
151 qreal fadeIntensity() const;
152
153 void setPeriod(int msecs);
154 int period() const;
155
156 void setActuator(QFeedbackActuator *actuator);
157 QFeedbackActuator* actuator() const;
158
159 //reimplementations from QFeedbackEffect
160 virtual State state() const;
161
162 protected:
163 virtual void setState(State);
164
165 private:
166 Q_DISABLE_COPY(QFeedbackHapticsEffect)
167 friend class QFeedbackHapticsEffectPrivate;
168 QScopedPointer<QFeedbackHapticsEffectPrivate> priv;
169 };
170
171 class Q_FEEDBACK_EXPORT QFeedbackFileEffect : public QFeedbackEffect
172 {
173 Q_OBJECT
174
175 Q_PROPERTY(bool loaded READ isLoaded WRITE setLoaded)
176 Q_PROPERTY(QUrl source READ source WRITE setSource)
177
178 public:
179 explicit QFeedbackFileEffect(QObject *parent = Q_NULLPTR);
180 ~QFeedbackFileEffect();
181
182 int duration() const;
183
184 bool isLoaded() const;
185
186 void load();
187 void unload();
188 void setLoaded(bool);
189
190 QUrl source() const;
191 void setSource(const QUrl &);
192
193 static QStringList supportedMimeTypes();
194
195 //reimplementations from QFeedbackEffect
196 virtual State state() const;
197
198 protected:
199 virtual void setState(State);
200
201 private:
202 Q_DISABLE_COPY(QFeedbackFileEffect)
203 friend class QFeedbackFileEffectPrivate;
204 QScopedPointer<QFeedbackFileEffectPrivate> priv;
205 };
206
207 QT_END_NAMESPACE
208 QT_END_HEADER
209
210 #endif // QFEEDBACKEFFECT_H