src/hbfeedback/player/hbcontinuousfeedback.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbFeedback module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbcontinuousfeedback.h"
       
    27 
       
    28 #include <QGraphicsItem>
       
    29 #include <QGraphicsView>
       
    30 #include <QDebug>
       
    31 
       
    32 class HbContinuousFeedbackPrivate
       
    33 {
       
    34 public:
       
    35     HbContinuousFeedbackPrivate() : cEffect(HbFeedback::ContinuousSmooth),
       
    36         cTimeout(HbFeedback::StandardFeedbackTimeout),
       
    37         cIntensity(HbFeedback::IntensityFull)
       
    38     {
       
    39     };
       
    40 
       
    41     ~HbContinuousFeedbackPrivate() {};
       
    42 
       
    43 public:
       
    44     HbFeedback::ContinuousEffect cEffect;
       
    45     int cTimeout;
       
    46     int cIntensity;
       
    47 };
       
    48 
       
    49 /*!
       
    50     @beta
       
    51     @hbfeedback
       
    52 
       
    53     \class HbContinuousFeedback
       
    54 
       
    55     \brief Tool class for continuous feedback effects.
       
    56 
       
    57     Continuous feedbacks are used to play sound and haptic effects that last as long as the user is touching the screen,
       
    58     for example when dragging an interface object, scrolling a list or a slider. Continuous feedback
       
    59     effects need to be started, updated and cancelled during the life time of the feedback using methods
       
    60     HbFeedbackPlayer::startContinuousFeedback(), HbFeedbackPlayer::updateContinuousFeedback() and
       
    61     HbFeedbackPlayer::cancelContinuousFeedback(). The effect intensity can be varied during the feedback.
       
    62 */
       
    63 
       
    64 
       
    65 /*!
       
    66     \fn void HbContinuousFeedback::setContinuousEffect(HbFeedback::ContinuousEffect effect)
       
    67 
       
    68     Sets the continuous effect that determines what kind of continuous haptic and sound effects will
       
    69     be played when calling HbFeedbackPlayer::startContinuousFeedback(). The actual effects are
       
    70     defined in the device themes.
       
    71 */
       
    72 
       
    73 void HbContinuousFeedback::setContinuousEffect(HbFeedback::ContinuousEffect effect)
       
    74 {
       
    75     d->cEffect = effect;
       
    76 }
       
    77 
       
    78 /*!
       
    79     \fn void HbFeedback::ContinuousEffect HbContinuousFeedback::continuousEffect() const
       
    80 
       
    81     Returns the continuous effect of the continuous feedback object. Continuous effect is used to determine what kind of continuous
       
    82     haptic and sound effects will be played when calling HbFeedbackPlayer::startContinuousFeedback(). The actual effects are
       
    83     defined in the device themes.
       
    84 */
       
    85 
       
    86 HbFeedback::ContinuousEffect HbContinuousFeedback::continuousEffect() const
       
    87 {
       
    88     return d->cEffect;
       
    89 }
       
    90 
       
    91 /*!
       
    92     \fn int HbContinuousFeedback::timeout() const
       
    93 
       
    94     The timeout value of the feedback in milliseconds. Continuous feedback is
       
    95     automatically cancelled if previously started continuous feedback hasn't been
       
    96     updated within the timeout.
       
    97 */
       
    98 
       
    99 int HbContinuousFeedback::timeout() const {
       
   100     return d->cTimeout;
       
   101 }
       
   102 
       
   103 /*!
       
   104     \fn int HbContinuousFeedback::intensity() const
       
   105 
       
   106     The intensity of the continuous feedback effect. Intensity
       
   107     can be varied between values zero and HbFeedback::IntensityFull = 100.
       
   108 */
       
   109 
       
   110 int HbContinuousFeedback::intensity() const {
       
   111     return d->cIntensity;
       
   112 }
       
   113 
       
   114 /*!
       
   115     \fn HbFeedback::Type HbContinuousFeedback::type() const
       
   116 
       
   117     Returns HbFeedback::TypeContinuous.
       
   118 */
       
   119 
       
   120 /*!
       
   121     Constructor.
       
   122 */
       
   123 HbContinuousFeedback::HbContinuousFeedback() :d(new HbContinuousFeedbackPrivate)
       
   124 {
       
   125 }
       
   126 
       
   127 /*!
       
   128     Constructor.
       
   129 
       
   130     \param effect continuous feedback to be played
       
   131     \param widget used to determine the window where continuous feedback is active.
       
   132            There can only be one ongoing continuous feedback per application window.
       
   133 */
       
   134 HbContinuousFeedback::HbContinuousFeedback(HbFeedback::ContinuousEffect effect, const QWidget *widget) : d(new HbContinuousFeedbackPrivate)
       
   135 {
       
   136     d->cEffect = effect;
       
   137     setOwningWindow(widget);
       
   138 }
       
   139 
       
   140 /*!
       
   141     Destructor.
       
   142 */
       
   143 HbContinuousFeedback::~HbContinuousFeedback()
       
   144 {
       
   145     delete d;
       
   146 }
       
   147 
       
   148 /*!
       
   149     Sets the timeout value in milliseconds. Continuous feedback is automatically cancelled
       
   150     if the continuous feedback hasn't been updated within the timeout.
       
   151 */
       
   152 void HbContinuousFeedback::setTimeout(int msecTimeout)
       
   153 {
       
   154     if (msecTimeout > 0) {
       
   155         d->cTimeout = msecTimeout;
       
   156     }
       
   157 }
       
   158 
       
   159 /*!
       
   160     Sets the intensity of the continuous feedback effect. The intensity
       
   161     has to always be between zero and HbFeedback::IntensityFull = 100.
       
   162 */
       
   163 void HbContinuousFeedback::setIntensity(int intensity)
       
   164 {
       
   165     if (intensity >= 0 && intensity <= HbFeedback::IntensityFull) {
       
   166         d->cIntensity = intensity;
       
   167     }
       
   168 }
       
   169 
       
   170 /*!
       
   171     Continuous feedback is valid if the feedback effect is not set to HbFeedback::ContinuousNone
       
   172     and if the owning window has been defined. There can only be one ongoing continuous feedback effect
       
   173     per one application window.
       
   174 */
       
   175 bool HbContinuousFeedback::isValid() const
       
   176 {
       
   177     switch(d->cEffect) {
       
   178     case HbFeedback::NoContinuousOverride :
       
   179         return false;
       
   180     default:
       
   181         return d->cEffect != HbFeedback::ContinuousNone && window();
       
   182     }
       
   183 };
       
   184 
       
   185 
       
   186 /*!
       
   187     Assigns a copy of the feedback \a feedback to this feedback, and returns a
       
   188     reference to it.
       
   189 */
       
   190 HbContinuousFeedback &HbContinuousFeedback::operator=(const HbContinuousFeedback &feedback)
       
   191 {
       
   192     HbAbstractFeedback::operator =(feedback);
       
   193     setContinuousEffect(feedback.continuousEffect());
       
   194     setTimeout(feedback.timeout());
       
   195     setIntensity(feedback.intensity());
       
   196     return *this;
       
   197 }
       
   198 
       
   199 /*!
       
   200     Returns true if the continuous feedbacks have the same parent window,
       
   201     area rect, continuous effect, timeout and intensity.
       
   202 */
       
   203 bool HbContinuousFeedback::operator==(const HbContinuousFeedback &feedback) const
       
   204 {
       
   205     return (rect() == feedback.rect()
       
   206             && window() == feedback.window()
       
   207             && d->cEffect == feedback.continuousEffect()
       
   208             && d->cTimeout == feedback.timeout()
       
   209             && d->cIntensity == feedback.intensity());
       
   210 }
       
   211 
       
   212 /*!
       
   213     Returns true if the continuous feedbacks have different parent window,
       
   214     area rect, continuous effect, timeout or intensity.
       
   215 */
       
   216 bool HbContinuousFeedback::operator!=(const HbContinuousFeedback &feedback) const
       
   217 {
       
   218     return !(*this == feedback);
       
   219 }