21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
26 #include "hbfeedbackplayer.h" |
|
27 #include "hbfeedbackplayer_p.h" |
26 #include "hbfeedbackplayer_p.h" |
28 |
27 #include "hbfeedbackplayer_p_p.h" |
29 #include "hbinstantfeedback.h" |
28 |
30 #include "hbcontinuousfeedback.h" |
29 #include <hbinstantfeedback.h> |
31 #include "hbtacticonfeedback.h" |
30 #include <hbcontinuousfeedback.h> |
32 #include "hbhitareafeedback.h" |
31 #include <hbfeedbacksettings.h> |
33 #include "hbfeedbackplayer_stub_p.h" |
32 #include "hbfeedbackplayer_stub_p.h" |
34 |
33 |
35 #ifdef FEEDBACK_TEST_EVENT |
34 #ifdef FEEDBACK_TEST_EVENT |
36 #include "hbfeedbacktestevent_p.h" |
35 #include "hbfeedbacktestevent_p.h" |
37 #endif |
36 #endif |
58 } |
57 } |
59 } |
58 } |
60 |
59 |
61 void HbFeedbackPlayerPrivate::init() |
60 void HbFeedbackPlayerPrivate::init() |
62 { |
61 { |
63 feedbackSettings = new HbFeedbackSettings(); |
62 feedbackSettings = new HbFeedbackSettings(this); |
64 connect(feedbackSettings, SIGNAL(feedbackDisabled()), |
63 connect(feedbackSettings, SIGNAL(feedbackDisabled()), |
65 this, SLOT(feedbackDisabled())); |
64 this, SLOT(feedbackDisabled())); |
66 connect(feedbackSettings, SIGNAL(feedbackTypeDisabled(HbFeedback::Type)), |
|
67 this, SLOT(feedbackTypeDisabled(HbFeedback::Type))); |
|
68 |
65 |
69 basePlayer = new HbFeedbackBasePlayer(); |
66 basePlayer = new HbFeedbackBasePlayer(); |
70 } |
67 } |
71 |
68 |
72 void HbFeedbackPlayerPrivate::feedbackDisabled() |
69 void HbFeedbackPlayerPrivate::feedbackDisabled() |
73 { |
70 { |
74 if (basePlayer) { |
71 if (basePlayer) { |
75 basePlayer->cancelContinuousFeedbacks(); |
72 basePlayer->cancelContinuousFeedbacks(); |
76 basePlayer->removeHitAreas(); |
73 } |
77 } |
74 } |
78 } |
75 |
79 |
76 Q_GLOBAL_STATIC(HbFeedbackPlayer, feedbackPlayerGlobal); |
80 void HbFeedbackPlayerPrivate::feedbackTypeDisabled(HbFeedback::Type type) |
77 |
81 { |
78 /*! |
82 if (basePlayer) { |
79 \internal |
83 switch (type) { |
80 |
84 case HbFeedback::TypeContinuous: |
81 Constructor. |
85 basePlayer->cancelContinuousFeedbacks(); |
82 |
86 break; |
83 Feedback player is used to initiate various haptic and sound feedback effects for the device. |
87 |
84 |
88 case HbFeedback::TypeHitArea: |
85 Current player supports instant feedback and continuous feedback effects. Separate HbFeedbackSettings |
89 basePlayer->removeHitAreas(); |
86 interface is reserved for applications wanting to limit or disable feedback effect playing. |
90 break; |
87 |
91 case HbFeedback::TypeInstant: |
88 \sa HbInstantFeedback, HbContinuousFeedback, HbFeedbackSettings |
92 case HbFeedback::TypeTacticon: |
89 |
93 default: |
90 */ |
94 break; |
91 HbFeedbackPlayer::HbFeedbackPlayer() : d(new HbFeedbackPlayerPrivate(this)) |
95 } |
92 { |
96 } |
93 d->init(); |
97 } |
94 } |
98 |
95 |
99 /*! |
96 /*! |
100 @beta |
97 \internal |
101 @hbfeedback |
98 Destructor. |
102 \class HbFeedbackPlayer |
99 |
103 |
100 \sa HbInstantFeedback, HbContinuousFeedback |
104 \brief Feedback player is used to initiate various haptic and sound feedback effects for the device. |
101 */ |
105 |
102 HbFeedbackPlayer::~HbFeedbackPlayer() |
106 Current player supports four kinds of effects: instant feedback, continuous feedback, tacticon feedback |
103 { |
107 and hit area feedback effects. Separate HbFeedbackSettings interface is reserved for applications wanting |
104 delete d; |
108 to limit or disable feedback effects emitted by the interface. See \ref feedback "Feedback Player" for |
105 } |
109 more information on the design of the player. |
106 |
110 |
107 /*! |
111 \sa HbInstantFeedback, HbContinuousFeedback, HbTacticonFeedback, HbHitAreaFeedback, HbFeedbackSettings. |
108 \internal |
112 |
109 Returns the handle to the global instance. |
113 \deprecated HbFeedbackPlayer |
|
114 is deprecated. Use HbInstantFeedback and HbContinuousFeedback classes instead. |
|
115 |
110 |
116 \sa HbInstantFeedback, HbContinuousFeedback |
111 \sa HbInstantFeedback, HbContinuousFeedback |
117 */ |
112 */ |
118 |
|
119 |
|
120 Q_GLOBAL_STATIC(HbFeedbackPlayer, feedbackPlayerGlobal); |
|
121 |
|
122 /*! |
|
123 Constructor. |
|
124 |
|
125 \deprecated HbFeedbackPlayer::HbFeedbackPlayer() |
|
126 is deprecated. Use HbInstantFeedback and HbContinuousFeedback classes instead. |
|
127 |
|
128 \sa HbInstantFeedback, HbContinuousFeedback |
|
129 |
|
130 */ |
|
131 HbFeedbackPlayer::HbFeedbackPlayer() : d(new HbFeedbackPlayerPrivate(this)) |
|
132 { |
|
133 d->init(); |
|
134 } |
|
135 |
|
136 /*! |
|
137 Destructor. |
|
138 |
|
139 \deprecated HbFeedbackPlayer::~HbFeedbackPlayer() |
|
140 is deprecated. Use HbInstantFeedback and HbContinuousFeedback classes instead. |
|
141 |
|
142 \sa HbInstantFeedback, HbContinuousFeedback |
|
143 */ |
|
144 HbFeedbackPlayer::~HbFeedbackPlayer() |
|
145 { |
|
146 delete d; |
|
147 } |
|
148 |
|
149 /*! |
|
150 Returns the handle to the global instance. |
|
151 |
|
152 \deprecated HbFeedbackPlayer::instance() |
|
153 is deprecated. Use HbInstantFeedback and HbContinuousFeedback classes instead. |
|
154 |
|
155 \sa HbInstantFeedback, HbContinuousFeedback |
|
156 */ |
|
157 HbFeedbackPlayer* HbFeedbackPlayer::instance() |
113 HbFeedbackPlayer* HbFeedbackPlayer::instance() |
158 { |
114 { |
159 return feedbackPlayerGlobal(); |
115 return feedbackPlayerGlobal(); |
160 } |
116 } |
161 |
117 |
162 /*! |
118 /*! |
|
119 \internal |
163 Returns a reference to the feedback settings interface. |
120 Returns a reference to the feedback settings interface. |
164 |
|
165 \deprecated HbFeedbackPlayer::settings() |
|
166 is deprecated. Use HbFeedbackSettings::instance() to access feedback settings. |
|
167 |
121 |
168 \sa HbFeedbackSettings |
122 \sa HbFeedbackSettings |
169 |
123 |
170 */ |
124 */ |
171 HbFeedbackSettings& HbFeedbackPlayer::settings() |
125 HbFeedbackSettings* HbFeedbackPlayer::settings() |
172 { |
126 { |
173 return *d->feedbackSettings; |
127 return d->feedbackSettings; |
174 } |
128 } |
175 |
129 |
176 /*! |
130 /*! |
|
131 \internal |
177 Triggers instant feedback effects. |
132 Triggers instant feedback effects. |
178 |
133 |
179 \param feedback instant feedback object |
134 \param feedback instant feedback object |
180 \sa HbInstantFeedback |
135 \sa HbInstantFeedback |
181 |
136 |
182 \deprecated HbFeedbackPlayer::playInstantFeedback(const HbInstantFeedback&) |
|
183 is deprecated. Use HbInstantFeedback::play() instead. |
|
184 |
|
185 \sa HbInstantFeedback |
|
186 */ |
137 */ |
187 void HbFeedbackPlayer::playInstantFeedback(const HbInstantFeedback& feedback) |
138 void HbFeedbackPlayer::playInstantFeedback(const HbInstantFeedback& feedback) |
188 { |
139 { |
189 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeInstant)) { |
140 if (feedback.isValid() && d->feedbackSettings->isFeedbackEnabled()) { |
190 if (d->basePlayer) { |
141 if (d->basePlayer) { |
191 d->basePlayer->playInstantFeedback(feedback); |
142 d->basePlayer->playInstantFeedback(feedback); |
192 } |
143 } |
193 #ifdef FEEDBACK_TEST_EVENT |
144 #ifdef FEEDBACK_TEST_EVENT |
194 HbFeedbackTestEvent te(feedback); |
145 HbFeedbackTestEvent te(feedback); |
196 #endif |
147 #endif |
197 } |
148 } |
198 } |
149 } |
199 |
150 |
200 /*! |
151 /*! |
201 Triggers tacticon feedback effects. |
152 \internal |
202 |
|
203 \param feedback tacticon feedback object |
|
204 \sa HbTacticonFeedback |
|
205 |
|
206 \deprecated HbFeedbackPlayer::playTacticonFeedback(const HbTacticonFeedback&) |
|
207 is deprecated. Please use HbInstantFeedback instead. |
|
208 |
|
209 \sa HbInstantFeedback |
|
210 */ |
|
211 void HbFeedbackPlayer::playTacticonFeedback(const HbTacticonFeedback& feedback) |
|
212 { |
|
213 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeTacticon)) { |
|
214 if (d->basePlayer) { |
|
215 d->basePlayer->playTacticonFeedback(feedback); |
|
216 #ifdef FEEDBACK_TEST_EVENT |
|
217 HbFeedbackTestEvent te(feedback); |
|
218 qApp->sendEvent(this, &te); |
|
219 #endif |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 /*! |
|
225 Starts a continuous feedback effect. |
153 Starts a continuous feedback effect. |
226 |
154 |
227 \param feedback continuous feedback object |
155 \param feedback continuous feedback object |
228 \return identifier The identifier for the started effect. |
156 \return identifier The identifier for the started effect. |
229 |
157 |
230 \sa HbContinuousFeedback |
158 \sa HbContinuousFeedback |
231 |
|
232 \deprecated HbFeedbackPlayer::startContinuousFeedback(const HbContinuousFeedback&) |
|
233 is deprecated. Use HbContinuousFeedback::play instead. |
|
234 |
|
235 \sa HbContinuousFeedback |
|
236 */ |
159 */ |
237 int HbFeedbackPlayer::startContinuousFeedback(const HbContinuousFeedback& feedback) |
160 int HbFeedbackPlayer::startContinuousFeedback(const HbContinuousFeedback& feedback) |
238 { |
161 { |
239 int identifier(-1); |
162 int identifier(-1); |
240 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeContinuous)) { |
163 if (feedback.isValid() && d->feedbackSettings->isFeedbackEnabled()) { |
241 if (d->basePlayer) { |
164 if (d->basePlayer) { |
242 identifier = d->basePlayer->startContinuousFeedback(feedback); |
165 identifier = d->basePlayer->startContinuousFeedback(feedback); |
243 #ifdef FEEDBACK_TEST_EVENT |
166 #ifdef FEEDBACK_TEST_EVENT |
244 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Start, identifier); |
167 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Start, identifier); |
245 qApp->sendEvent(this, &te); |
168 qApp->sendEvent(this, &te); |
252 |
175 |
253 return identifier; |
176 return identifier; |
254 } |
177 } |
255 |
178 |
256 /*! |
179 /*! |
|
180 \internal |
257 Updates an ongoing continuous feedback effect. |
181 Updates an ongoing continuous feedback effect. |
258 |
182 |
259 \param identifier The identifier for the ongoing effect. |
183 \param identifier The identifier for the ongoing effect. |
260 \param feedback continuous feedback object |
184 \param feedback continuous feedback object |
261 |
185 |
262 \sa HbContinuousFeedback |
186 \sa HbContinuousFeedback |
263 |
187 |
264 \deprecated HbFeedbackPlayer::updateContinuousFeedback(int, const HbContinuousFeedback&) |
|
265 is deprecated. |
|
266 |
|
267 \sa HbContinuousFeedback |
|
268 */ |
188 */ |
269 void HbFeedbackPlayer::updateContinuousFeedback(int identifier, const HbContinuousFeedback& feedback) |
189 void HbFeedbackPlayer::updateContinuousFeedback(int identifier, const HbContinuousFeedback& feedback) |
270 { |
190 { |
271 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeContinuous)) { |
191 if (feedback.isValid() && d->feedbackSettings->isFeedbackEnabled()) { |
272 if (d->basePlayer) { |
192 if (d->basePlayer) { |
273 d->basePlayer->updateContinuousFeedback(identifier, feedback); |
193 d->basePlayer->updateContinuousFeedback(identifier, feedback); |
274 #ifdef FEEDBACK_TEST_EVENT |
194 #ifdef FEEDBACK_TEST_EVENT |
275 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Update, identifier); |
195 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Update, identifier); |
276 qApp->sendEvent(this, &te); |
196 qApp->sendEvent(this, &te); |
320 d->basePlayer->cancelContinuousFeedbacks(); |
236 d->basePlayer->cancelContinuousFeedbacks(); |
321 } |
237 } |
322 } |
238 } |
323 |
239 |
324 /*! |
240 /*! |
|
241 \internal |
325 Checks if the given continuous feedback effect is currently running. |
242 Checks if the given continuous feedback effect is currently running. |
326 |
243 |
327 \param identifier The identifier for the ongoing effect. |
244 \param identifier The identifier for the ongoing effect. |
328 |
245 |
329 \return true, if the effect is ongoing. |
246 \return true, if the effect is ongoing. |
330 |
247 |
331 \deprecated HbFeedbackPlayer::continuousFeedbackOngoing(int) |
|
332 is deprecated. Use HbContinuousFeedback::isPlaying() instead. |
|
333 |
|
334 \sa HbContinuousFeedback |
248 \sa HbContinuousFeedback |
335 */ |
249 */ |
336 bool HbFeedbackPlayer::continuousFeedbackOngoing(int identifier) |
250 bool HbFeedbackPlayer::continuousFeedbackOngoing(int identifier) |
337 { |
251 { |
338 bool feedbackOngoing(false); |
252 bool feedbackOngoing(false); |
339 if (d->basePlayer) { |
253 if (d->basePlayer) { |
340 feedbackOngoing = d->basePlayer->continuousFeedbackOngoing(identifier); |
254 feedbackOngoing = d->basePlayer->continuousFeedbackOngoing(identifier); |
341 } |
255 } |
342 return feedbackOngoing; |
256 return feedbackOngoing; |
343 } |
257 } |
344 |
|
345 /*! |
|
346 Inserts a hit area to the specified window. |
|
347 |
|
348 \param feedback hit area feedback object |
|
349 \return The identifier for the inserted hit area. |
|
350 \sa HbHitAreaFeedback |
|
351 |
|
352 \deprecated HbFeedbackPlayer::insertHitArea(const HbHitAreaFeedback&) |
|
353 is deprecated. Please use HbInstantFeedback instead. |
|
354 |
|
355 \sa HbInstantFeedback |
|
356 */ |
|
357 int HbFeedbackPlayer::insertHitArea(const HbHitAreaFeedback& feedback) |
|
358 { |
|
359 int identifier(-1); |
|
360 |
|
361 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeHitArea)) { |
|
362 if (d->basePlayer) { |
|
363 identifier = d->basePlayer->insertHitArea(feedback); |
|
364 #ifdef FEEDBACK_TEST_EVENT |
|
365 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Start, identifier); |
|
366 qApp->sendEvent(this, &te); |
|
367 #endif |
|
368 } |
|
369 } else if (!feedback.isLocated()) { |
|
370 qWarning("HbFeedbackPlayer::insertHitArea: Hit area missing required parameters parent window and/or rectangle."); |
|
371 } |
|
372 |
|
373 return identifier; |
|
374 } |
|
375 |
|
376 /*! |
|
377 Update the specified hit area. |
|
378 |
|
379 \param identifier Identifier for the hit area. |
|
380 \param feedback hit area feedback object |
|
381 \sa HbHitAreaFeedback |
|
382 |
|
383 \deprecated HbFeedbackPlayer::updateHitArea(int, const HbHitAreaFeedback&) |
|
384 is deprecated. Please use HbInstantFeedback instead. |
|
385 |
|
386 \sa HbInstantFeedback |
|
387 */ |
|
388 void HbFeedbackPlayer::updateHitArea(int identifier, const HbHitAreaFeedback& feedback) |
|
389 { |
|
390 if (feedback.isValid() && d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeHitArea)) { |
|
391 if (d->basePlayer) { |
|
392 d->basePlayer->updateHitArea(identifier, feedback); |
|
393 #ifdef FEEDBACK_TEST_EVENT |
|
394 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Update, identifier); |
|
395 qApp->sendEvent(this, &te); |
|
396 #endif |
|
397 } |
|
398 } else if (!feedback.isLocated()) { |
|
399 qWarning("HbFeedbackPlayer::updateHitArea: Hit area missing required parameters parent window and/or rectangle."); |
|
400 } |
|
401 } |
|
402 |
|
403 /*! |
|
404 Remove the specified hit area. |
|
405 \param identifier The identifer for the hit area to be removed. |
|
406 \sa HbHitAreaFeedback |
|
407 |
|
408 \deprecated HbFeedbackPlayer::removeHitArea(int) |
|
409 is deprecated. Please use HbInstantFeedback instead. |
|
410 |
|
411 \sa HbInstantFeedback |
|
412 */ |
|
413 void HbFeedbackPlayer::removeHitArea(int identifier) |
|
414 { |
|
415 if (d->basePlayer) { |
|
416 d->basePlayer->removeHitArea(identifier); |
|
417 #ifdef FEEDBACK_TEST_EVENT |
|
418 HbHitAreaFeedback feedback; |
|
419 HbFeedbackTestEvent te(feedback, HbFeedbackTestEvent::Stop, identifier); |
|
420 qApp->sendEvent(this, &te); |
|
421 #endif |
|
422 } |
|
423 } |
|
424 |
|
425 /*! |
|
426 Remove all registered hit areas. |
|
427 |
|
428 \deprecated HbFeedbackPlayer::removeHitAreas() |
|
429 is deprecated. Please use HbInstantFeedback instead. |
|
430 |
|
431 \sa HbInstantFeedback |
|
432 */ |
|
433 void HbFeedbackPlayer::removeHitAreas() |
|
434 { |
|
435 if (d->basePlayer) { |
|
436 d->basePlayer->removeHitAreas(); |
|
437 } |
|
438 } |
|
439 |
|
440 /*! |
|
441 Check if the specified hit area still exists. |
|
442 |
|
443 \param identifier The identifier for the hit area. |
|
444 \return True, if the hit area exists. |
|
445 |
|
446 \deprecated HbFeedbackPlayer::hitAreaExists(int) |
|
447 is deprecated. Please use HbInstantFeedback instead. |
|
448 |
|
449 \sa HbInstantFeedback |
|
450 */ |
|
451 bool HbFeedbackPlayer::hitAreaExists(int identifier) |
|
452 { |
|
453 bool hitAreaExists = false; |
|
454 |
|
455 if (d->feedbackSettings->isFeedbackAllowed(HbFeedback::TypeHitArea)) { |
|
456 if (d->basePlayer) { |
|
457 hitAreaExists = d->basePlayer->hitAreaExists(identifier); |
|
458 } |
|
459 } |
|
460 |
|
461 return hitAreaExists; |
|
462 } |
|
463 |
|