src/hbfeedback/player/hbinstantfeedback.cpp
changeset 0 16d8024aca5e
child 2 06ff229162e9
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 "hbinstantfeedback.h"
       
    27 #include "hbfeedbackplayer.h"
       
    28 
       
    29 #include <QGraphicsItem>
       
    30 #include <QGraphicsView>
       
    31 #include <QDebug>
       
    32 
       
    33 class HbInstantFeedbackPrivate
       
    34 {
       
    35 public:
       
    36     HbInstantFeedbackPrivate() : cEffect(HbFeedback::SensitiveButton) {};
       
    37     ~HbInstantFeedbackPrivate() {};
       
    38 
       
    39 public:
       
    40     HbFeedback::InstantEffect cEffect;
       
    41 };
       
    42 
       
    43 /*!
       
    44     @beta
       
    45     @hbfeedback
       
    46 
       
    47     \class HbInstantFeedback
       
    48 
       
    49     \brief Tool class for instant feedback effects.
       
    50 
       
    51     Instant feedbacks are used to initiate fire&forget type of sound and haptic effects defined in the device themes.
       
    52     Effects are used as a feedback indication to the user when she/he is navigating and interacting
       
    53     with the device.
       
    54 */
       
    55 
       
    56 /*!
       
    57     \fn void HbInstantFeedback::setInstantEffect(HbFeedback::InstantEffect effect)
       
    58 
       
    59     Sets the instant effect that determines what kind of haptic and sound effects will
       
    60     be played when calling HbFeedbackPlayer::playInstantFeedback() or when user touches the screen
       
    61     over the hit area with the given instant effect. The actual effects are
       
    62     defined in the device themes.
       
    63 */
       
    64 
       
    65 void HbInstantFeedback::setInstantEffect(HbFeedback::InstantEffect effect)
       
    66 {
       
    67     d->cEffect = effect;
       
    68 }
       
    69 
       
    70 /*!
       
    71     \fn void HbFeedback::InstantEffect HbInstantFeedback::instantEffect() const
       
    72 
       
    73     Returns the instant effect of the instant feedback object. Instant effect is used to determine what kind of
       
    74     haptic and sound effects will be played when calling HbFeedbackPlayer::playInstantFeedback() or
       
    75     when user touches the screen over the hit area with the given instant effect. The actual effects
       
    76     are defined in the device themes.
       
    77 */
       
    78 
       
    79 HbFeedback::InstantEffect HbInstantFeedback::instantEffect() const
       
    80 {
       
    81     return d->cEffect;
       
    82 }
       
    83 
       
    84 /*!
       
    85     \fn bool HbInstantFeedback::isValid() const
       
    86 
       
    87     Instant feedback is valid if a proper instant effect (not HbFeedback::None) has beed
       
    88     defined for the feedback.
       
    89 */
       
    90 
       
    91 bool HbInstantFeedback::isValid() const
       
    92 {
       
    93     switch(d->cEffect) {
       
    94     case HbFeedback::None:
       
    95     case HbFeedback::NoOverride:
       
    96         return false;
       
    97     default:
       
    98         return true;
       
    99     }
       
   100 }
       
   101 
       
   102 /*!
       
   103     \fn HbFeedback::Type HbInstantFeedback::type() const
       
   104 
       
   105     Returns HbFeedback::TypeInstant.
       
   106 */
       
   107 
       
   108 /*!
       
   109     Constructor.
       
   110 */
       
   111 HbInstantFeedback::HbInstantFeedback() : d(new HbInstantFeedbackPrivate)
       
   112 {
       
   113 }
       
   114 
       
   115 /*!
       
   116     Constructor.
       
   117 
       
   118     \param effect instant feedback to be played
       
   119 */
       
   120 HbInstantFeedback::HbInstantFeedback(HbFeedback::InstantEffect effect) : d(new HbInstantFeedbackPrivate)
       
   121 {
       
   122     d->cEffect = effect;
       
   123 }
       
   124 
       
   125 /*!
       
   126     Destructor.
       
   127 */
       
   128 HbInstantFeedback::~HbInstantFeedback()
       
   129 {
       
   130     delete d;
       
   131 }
       
   132 
       
   133 /*!
       
   134     Initiates the instant feedback effect.
       
   135 */
       
   136 void HbInstantFeedback::play()
       
   137 {
       
   138     HbFeedbackPlayer* player = HbFeedbackPlayer::instance();
       
   139     if (player) {
       
   140         player->playInstantFeedback(d->cEffect);
       
   141     }
       
   142 }
       
   143 
       
   144 /*!
       
   145     Initiates the given instant feedback effect.
       
   146 */
       
   147 void HbInstantFeedback::play(HbFeedback::InstantEffect effect)
       
   148 {
       
   149     HbFeedbackPlayer* player = HbFeedbackPlayer::instance();
       
   150     if (player) {
       
   151         player->playInstantFeedback(effect);
       
   152     }
       
   153 }
       
   154 
       
   155 /*!
       
   156     Assigns a copy of the feedback \a feedback to this feedback, and returns a
       
   157     reference to it.
       
   158 */
       
   159 HbInstantFeedback &HbInstantFeedback::operator=(const HbInstantFeedback & feedback)
       
   160 {
       
   161     HbAbstractFeedback::operator =(feedback);
       
   162     setInstantEffect(feedback.instantEffect());
       
   163     return *this;
       
   164 }
       
   165 
       
   166 /*!
       
   167     Returns true if this feedback has the same configuration as the feedback \a
       
   168     feedback; otherwise returns false.
       
   169 */
       
   170 bool HbInstantFeedback::operator==(const HbInstantFeedback &feedback) const
       
   171 {
       
   172     return (rect() == feedback.rect()
       
   173             && window() == feedback.window()
       
   174             && d->cEffect == feedback.instantEffect());
       
   175 }
       
   176 
       
   177 /*!
       
   178     Returns true if this feedback has different configuration than the feedback \a
       
   179     feedback; otherwise returns false.
       
   180 */
       
   181 bool HbInstantFeedback::operator!=(const HbInstantFeedback &feedback) const
       
   182 {
       
   183     return !(*this == feedback);
       
   184 }