src/hbfeedback/player/hbcontinuousfeedback.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 7 923ff622b8b9
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbcontinuousfeedback.h"
    26 #include "hbcontinuousfeedback.h"
    27 #include "hbfeedbackplayer.h"
    27 #include "hbfeedbackplayer_p.h"
    28 
    28 
    29 #include <QGraphicsItem>
    29 #include <QGraphicsItem>
    30 #include <QGraphicsView>
    30 #include <QGraphicsView>
    31 #include <QDebug>
    31 #include <QDebug>
    32 
    32 
    53     @beta
    53     @beta
    54     @hbfeedback
    54     @hbfeedback
    55 
    55 
    56     \class HbContinuousFeedback
    56     \class HbContinuousFeedback
    57 
    57 
    58     \brief Tool class for continuous feedback effects.
    58     \brief Class for continuous feedback effects.
    59 
    59 
    60     Continuous feedbacks are used to play sound and haptic effects that last as long as the user is touching the screen,
    60     Continuous feedbacks are feedback effects that last as long as the user is touching the screen,
    61     for example when dragging an interface object, scrolling a list or a slider. Continuous feedback
    61     for example when dragging a slider handle. Continuous feedback effects need to be started, updated 
    62     effects need to be started, updated and cancelled during the life time of the feedback using methods
    62     and stopped using methods HbFeedbackPlayer::startContinuousFeedback(), HbFeedbackPlayer::updateContinuousFeedback()
    63     HbFeedbackPlayer::startContinuousFeedback(), HbFeedbackPlayer::updateContinuousFeedback() and
    63     and HbFeedbackPlayer::cancelContinuousFeedback(). The effect intensity can be varied during the feedback.
    64     HbFeedbackPlayer::cancelContinuousFeedback(). The effect intensity can be varied during the feedback.
    64 */
    65 */
    65 
       
    66 #define UPDATE_IF_ONGOING \
       
    67 HbFeedbackPlayer *player = HbFeedbackPlayer::instance(); \
       
    68 if(player && player->continuousFeedbackOngoing(d->cFeedbackId)) { \
       
    69     player->updateContinuousFeedback(d->cFeedbackId,*this); \
       
    70 }
    66 
    71 
    67 
    72 
    68 /*!
    73 /*!
    69     \fn void HbContinuousFeedback::setContinuousEffect(HbFeedback::ContinuousEffect effect)
    74     \fn void HbContinuousFeedback::setContinuousEffect(HbFeedback::ContinuousEffect effect)
    70 
    75 
    71     Sets the continuous effect that determines what kind of continuous haptic and sound effects will
    76     Sets the continuous feedback effect that determines what kind of continuous effects will
    72     be played when calling HbFeedbackPlayer::startContinuousFeedback(). The actual effects are
    77     be played when calling HbFeedbackPlayer::startContinuousFeedback().
    73     defined in the device themes.
       
    74 */
    78 */
    75 
    79 
    76 void HbContinuousFeedback::setContinuousEffect(HbFeedback::ContinuousEffect effect)
    80 void HbContinuousFeedback::setContinuousEffect(HbFeedback::ContinuousEffect effect)
    77 {
    81 {
    78     d->cEffect = effect;
    82     d->cEffect = effect;
       
    83     UPDATE_IF_ONGOING;
    79 }
    84 }
    80 
    85 
    81 /*!
    86 /*!
    82     \fn void HbFeedback::ContinuousEffect HbContinuousFeedback::continuousEffect() const
    87     \fn void HbFeedback::ContinuousEffect HbContinuousFeedback::continuousEffect() const
    83 
    88 
    84     Returns the continuous effect of the continuous feedback object. Continuous effect is used to determine what kind of continuous
    89     Returns the continuous effect of the continuous feedback object. Continuous effect represents the continuous
    85     haptic and sound effects will be played when calling HbFeedbackPlayer::startContinuousFeedback(). The actual effects are
    90     feedback effect that will be played when calling HbFeedbackPlayer::startContinuousFeedback().
    86     defined in the device themes.
       
    87 */
    91 */
    88 
    92 
    89 HbFeedback::ContinuousEffect HbContinuousFeedback::continuousEffect() const
    93 HbFeedback::ContinuousEffect HbContinuousFeedback::continuousEffect() const
    90 {
    94 {
    91     return d->cEffect;
    95     return d->cEffect;
    93 
    97 
    94 /*!
    98 /*!
    95     \fn int HbContinuousFeedback::timeout() const
    99     \fn int HbContinuousFeedback::timeout() const
    96 
   100 
    97     The timeout value of the feedback in milliseconds. Continuous feedback is
   101     The timeout value of the feedback in milliseconds. Continuous feedback is
    98     automatically cancelled if previously started continuous feedback hasn't been
   102     automatically stopped if previously started continuous feedback has not been
    99     updated within the timeout.
   103     updated within the timeout.
   100 */
   104 */
   101 
   105 
   102 int HbContinuousFeedback::timeout() const {
   106 int HbContinuousFeedback::timeout() const {
   103     return d->cTimeout;
   107     return d->cTimeout;
   104 }
   108 }
   105 
   109 
   106 /*!
   110 /*!
   107     \fn int HbContinuousFeedback::intensity() const
   111     \fn int HbContinuousFeedback::intensity() const
   108 
   112 
   109     The intensity of the continuous feedback effect. Intensity
   113     The intensity of the continuous feedback effect. Intensity can be varied between 
   110     can be varied between values zero and HbFeedback::IntensityFull = 100.
   114     values HbFeedback::IntensityZero and HbFeedback::IntensityFull.
   111 */
   115 */
   112 
   116 
   113 int HbContinuousFeedback::intensity() const {
   117 int HbContinuousFeedback::intensity() const {
   114     return d->cIntensity;
   118     return d->cIntensity;
   115 }
   119 }
   147 {
   151 {
   148     delete d;
   152     delete d;
   149 }
   153 }
   150 
   154 
   151 /*!
   155 /*!
   152     Sets the timeout value in milliseconds. Continuous feedback is automatically cancelled
   156     Sets the timeout value in milliseconds. Continuous feedback is automatically stopped
   153     if the continuous feedback hasn't been updated within the timeout.
   157     if the continuous feedback has not been updated within the timeout.
   154 */
   158 */
   155 void HbContinuousFeedback::setTimeout(int msecTimeout)
   159 void HbContinuousFeedback::setTimeout(int msecTimeout)
   156 {
   160 {
   157     if (msecTimeout > 0) {
   161     if (msecTimeout > 0) {
   158         d->cTimeout = msecTimeout;
   162         d->cTimeout = msecTimeout;
   159     }
   163         UPDATE_IF_ONGOING;
   160 }
   164     }
   161 
   165 }
   162 /*!
   166 
   163     Sets the intensity of the continuous feedback effect. The intensity
   167 /*!
   164     has to always be between HbFeedback::IntensityZero and HbFeedback::IntensityFull.
   168     Sets the intensity of the continuous feedback effect. The intensity can be varied between 
       
   169     HbFeedback::IntensityZero and HbFeedback::IntensityFull.
   165 */
   170 */
   166 void HbContinuousFeedback::setIntensity(int intensity)
   171 void HbContinuousFeedback::setIntensity(int intensity)
   167 {
   172 {
   168     if (intensity >= 0 && intensity <= HbFeedback::IntensityFull) {
   173     if (intensity >= 0 && intensity <= HbFeedback::IntensityFull) {
   169         d->cIntensity = intensity;
   174         d->cIntensity = intensity;
   170     }
   175         UPDATE_IF_ONGOING;
   171 }
   176     }
       
   177 }
       
   178 
   172 /*!
   179 /*!
   173     Plays the continuous feedback.
   180     Plays the continuous feedback.
   174 */
   181 */
   175 void HbContinuousFeedback::play()
   182 void HbContinuousFeedback::play()
   176 {
   183 {
   178 
   185 
   179     if (feedbackPlayer) {
   186     if (feedbackPlayer) {
   180         d->cFeedbackId = feedbackPlayer->startContinuousFeedback(*this);
   187         d->cFeedbackId = feedbackPlayer->startContinuousFeedback(*this);
   181     }
   188     }
   182 }
   189 }
       
   190 
   183 /*!
   191 /*!
   184     Stops the continous feedback.
   192     Stops the continous feedback.
   185   */
   193 */
   186 void HbContinuousFeedback::stop()
   194 void HbContinuousFeedback::stop()
   187 {
   195 {
   188     HbFeedbackPlayer* feedbackPlayer = HbFeedbackPlayer::instance();
   196     HbFeedbackPlayer* feedbackPlayer = HbFeedbackPlayer::instance();
   189 
   197 
   190     if (feedbackPlayer) {
   198     if (feedbackPlayer) {
   206     }
   214     }
   207 
   215 
   208     return feedbackOngoing;
   216     return feedbackOngoing;
   209 }
   217 }
   210 
   218 
   211 /*!
   219 
   212   \deprecated HbContinuousFeedback::isValid() const
   220 /*!
   213         is deprecated.
       
   214 
       
   215     Continuous feedback is valid if the feedback effect is not set to HbFeedback::ContinuousNone
   221     Continuous feedback is valid if the feedback effect is not set to HbFeedback::ContinuousNone
   216     and if the owning window has been defined. There can only be one ongoing continuous feedback effect
   222     and if the owning window has been defined. There can only be one ongoing continuous feedback effect
   217     per one application window.
   223     per one application window.
   218 */
   224 */
   219 bool HbContinuousFeedback::isValid() const
   225 bool HbContinuousFeedback::isValid() const
   220 {
   226 {
   221     switch(d->cEffect) {
   227     return d->cEffect != HbFeedback::ContinuousNone && window();
   222     case HbFeedback::NoContinuousOverride :
       
   223         return false;
       
   224     default:
       
   225         return d->cEffect != HbFeedback::ContinuousNone && window();
       
   226     }
       
   227 };
   228 };
   228 
       
   229 
   229 
   230 /*!
   230 /*!
   231     Assigns a copy of the feedback \a feedback to this feedback, and returns a
   231     Assigns a copy of the feedback \a feedback to this feedback, and returns a
   232     reference to it.
   232     reference to it.
   233 */
   233 */