src/hbcore/feedback/hbwidgetfeedback.cpp
author hgs
Mon, 18 Oct 2010 18:23:13 +0300
changeset 34 ed14f46c0e55
parent 0 16d8024aca5e
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/****************************************************************************
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
** All rights reserved.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
** Contact: Nokia Corporation (developer.feedback@nokia.com)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
** This file is part of the HbCore module of the UI Extensions for Mobile.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
** GNU Lesser General Public License Usage
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
** This file may be used under the terms of the GNU Lesser General Public
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
** License version 2.1 as published by the Free Software Foundation and
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
** appearing in the file LICENSE.LGPL included in the packaging of this file.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
** Please review the following information to ensure the GNU Lesser General
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
** Public License version 2.1 requirements will be met:
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
** In addition, as a special exception, Nokia gives you certain additional
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
** rights.  These rights are described in the Nokia Qt LGPL Exception
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
** If you have questions regarding the use of this file, please contact
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
** Nokia at developer.feedback@nokia.com.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
**
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
****************************************************************************/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include "hbwidgetfeedback.h"
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include "hbfeedbackmanager.h"
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
/*!
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
    @beta
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
    @hbcore
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
    \class HbWidgetFeedback
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
34
hgs
parents: 0
diff changeset
    35
    \brief The HbWidgetFeedback class provides an interface for widgets
hgs
parents: 0
diff changeset
    36
    to inform the feedback framework about user interactions in order
hgs
parents: 0
diff changeset
    37
    to trigger feedback effects.
hgs
parents: 0
diff changeset
    38
    
hgs
parents: 0
diff changeset
    39
    The HbWidgetFeedback class is for use in widget implementations.
hgs
parents: 0
diff changeset
    40
    It is not relevant when you are simply using existing widgets in
hgs
parents: 0
diff changeset
    41
    an application.
hgs
parents: 0
diff changeset
    42
    
hgs
parents: 0
diff changeset
    43
    As a widget developer, you may want to give feedback when the user
hgs
parents: 0
diff changeset
    44
    interacts with your widget. Audio signals or vibration are examples of
hgs
parents: 0
diff changeset
    45
    possible feedback effects. To trigger the feedback effects supported by
hgs
parents: 0
diff changeset
    46
    the feedback framework, you must inform the feedback framework about
hgs
parents: 0
diff changeset
    47
    the detected user interaction and its specific type.
hgs
parents: 0
diff changeset
    48
    
hgs
parents: 0
diff changeset
    49
    Interactions are divided into two main types:
hgs
parents: 0
diff changeset
    50
    
hgs
parents: 0
diff changeset
    51
    <ul>
hgs
parents: 0
diff changeset
    52
    <li><b>Instant interactions.</b> Short user actions, such as clicking
hgs
parents: 0
diff changeset
    53
    a button or changing a selection on a list. A typical feedback effect
hgs
parents: 0
diff changeset
    54
    for these interactions is a fire-and-forget type of event, where
hgs
parents: 0
diff changeset
    55
    the physical response is played from beginning to end.</li>
hgs
parents: 0
diff changeset
    56
    <li><b>Continuous interactions.</b> Longer user actions, such as scrolling
hgs
parents: 0
diff changeset
    57
    or dragging. Playing the feedback for these interactions continues until
hgs
parents: 0
diff changeset
    58
    explicitly stopped.</li>
hgs
parents: 0
diff changeset
    59
    </ul>
hgs
parents: 0
diff changeset
    60
    
hgs
parents: 0
diff changeset
    61
    HbWidgetFeedback provides static methods for informing the feedback
hgs
parents: 0
diff changeset
    62
    framework about user interactions:
hgs
parents: 0
diff changeset
    63
    \link HbWidgetFeedback::triggered() triggered() \endlink for instant interactions,
hgs
parents: 0
diff changeset
    64
    and \link HbWidgetFeedback::continuousTriggered() continuousTriggered() \endlink
hgs
parents: 0
diff changeset
    65
    and \link HbWidgetFeedback::continuousStopped() continuousStopped() \endlink
hgs
parents: 0
diff changeset
    66
    for continuous interactions. Information on the target widget of the interaction
hgs
parents: 0
diff changeset
    67
    and the interaction type is passed in the method parameters. The feedback framework
hgs
parents: 0
diff changeset
    68
    makes decisions about the actual effects, based on the widget type, situation,
hgs
parents: 0
diff changeset
    69
    and specific interaction type.
hgs
parents: 0
diff changeset
    70
    
hgs
parents: 0
diff changeset
    71
    A widget should only call interaction methods when the user actually
hgs
parents: 0
diff changeset
    72
    interacts with the widget, and not when the widget state changes for some
hgs
parents: 0
diff changeset
    73
    other reason. For example, feedback effects are not desirable when
hgs
parents: 0
diff changeset
    74
    an application resets widget states by calling the widget API, or when
hgs
parents: 0
diff changeset
    75
    a progress bar is moved during a file transfer.
hgs
parents: 0
diff changeset
    76
    
hgs
parents: 0
diff changeset
    77
    How you use this class or whether you need to use it at all depends on 
hgs
parents: 0
diff changeset
    78
    what kind of widget you are developing:
hgs
parents: 0
diff changeset
    79
    
hgs
parents: 0
diff changeset
    80
    <b>Standard widgets.</b> If you are developing a standard %Hb widget, 
hgs
parents: 0
diff changeset
    81
    such as HbPushButton, HbComboBox, and so on, you should use this class,
hgs
parents: 0
diff changeset
    82
    %HbWidgetFeedback, for triggering feedback effects upon user interaction.
hgs
parents: 0
diff changeset
    83
    See the use case below for details.
hgs
parents: 0
diff changeset
    84
    
hgs
parents: 0
diff changeset
    85
    <b>Custom widgets that derive from a standard widget.</b> If you are 
hgs
parents: 0
diff changeset
    86
    developing a custom widget that derives from one of the standard
hgs
parents: 0
diff changeset
    87
    %Hb widgets (such as HbPushButton, HbComboBox, and so on),
hgs
parents: 0
diff changeset
    88
    the base class widget most probably has predefined feedback effects,
hgs
parents: 0
diff changeset
    89
    and you do not need to do anything. The base class takes care of triggering
hgs
parents: 0
diff changeset
    90
    the default effects upon user interaction.
hgs
parents: 0
diff changeset
    91
    
hgs
parents: 0
diff changeset
    92
    <b>Custom widgets that derive directly from HbWidget.</b> If your custom
hgs
parents: 0
diff changeset
    93
    widget derives directly from HbWidget, and not through any of the standard
hgs
parents: 0
diff changeset
    94
    %Hb widgets, you should not use %HbWidgetFeedback. The recommended way
hgs
parents: 0
diff changeset
    95
    to define feedback for your widget is to use classes HbInstantFeedback and
hgs
parents: 0
diff changeset
    96
    HbContinuousFeedback.
hgs
parents: 0
diff changeset
    97
    
hgs
parents: 0
diff changeset
    98
    \section _usecases_hbwidgetfeedback Using HbWidgetFeedback
hgs
parents: 0
diff changeset
    99
    
hgs
parents: 0
diff changeset
   100
    \subsection _uc_standardhb_hbwidgetfeedback Supporting feedback effects in a standard widget
hgs
parents: 0
diff changeset
   101
    
hgs
parents: 0
diff changeset
   102
    Call the HbWidgetFeedback methods in a standard widget when the user
hgs
parents: 0
diff changeset
   103
    interacts with the widget. Choose the correct method according to
hgs
parents: 0
diff changeset
   104
    the interaction style: instant or continuous.
hgs
parents: 0
diff changeset
   105
            
hgs
parents: 0
diff changeset
   106
    To support instant feedback features in a standard %Hb widget, call 
hgs
parents: 0
diff changeset
   107
    HbWidgetFeedback::triggered() with a suitable Hb::InstantInteraction
hgs
parents: 0
diff changeset
   108
    parameter to specify the interaction type, whenever you detect any
hgs
parents: 0
diff changeset
   109
    user interaction that is instant by nature. For example:
hgs
parents: 0
diff changeset
   110
    
hgs
parents: 0
diff changeset
   111
    \code
hgs
parents: 0
diff changeset
   112
    // The widget has been pressed down and released
hgs
parents: 0
diff changeset
   113
    HbWidgetFeedback::triggered(this, Hb::InstantClicked);
hgs
parents: 0
diff changeset
   114
    \endcode
hgs
parents: 0
diff changeset
   115
    
hgs
parents: 0
diff changeset
   116
    See Hb::InstantInteraction for the list of all predefined instant
hgs
parents: 0
diff changeset
   117
    interactions.
hgs
parents: 0
diff changeset
   118
    
hgs
parents: 0
diff changeset
   119
    Whenever you detect any of the specified continuous user interactions in
hgs
parents: 0
diff changeset
   120
    your standard %Hb widget, or when the continuous interaction ends, call
hgs
parents: 0
diff changeset
   121
    either HbWidgetFeedback::continuousTriggered() or HbWidgetFeedback::continuousStopped()
hgs
parents: 0
diff changeset
   122
    with the suitable Hb::ContinuousInteraction parameter. For example:
hgs
parents: 0
diff changeset
   123
    
hgs
parents: 0
diff changeset
   124
    \code
hgs
parents: 0
diff changeset
   125
    // User has started moving the slider handle.
hgs
parents: 0
diff changeset
   126
    HbWidgetFeedback::continuousTriggered(this, Hb::ContinuousDragged);
hgs
parents: 0
diff changeset
   127
    \endcode
hgs
parents: 0
diff changeset
   128
    
hgs
parents: 0
diff changeset
   129
    \code
hgs
parents: 0
diff changeset
   130
    // User has stopped moving the slider handle.
hgs
parents: 0
diff changeset
   131
    HbWidgetFeedback::continuousStopped(this, Hb::ContinuousDragged);
hgs
parents: 0
diff changeset
   132
    \endcode
hgs
parents: 0
diff changeset
   133
    
hgs
parents: 0
diff changeset
   134
    See Hb::ContinuousInteraction for the list of all predefined
hgs
parents: 0
diff changeset
   135
    continuous interactions.
hgs
parents: 0
diff changeset
   136
        
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
34
hgs
parents: 0
diff changeset
   138
    \sa HbInstantFeedback, HbContinuousFeedback
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   139
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   140
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
/*!
34
hgs
parents: 0
diff changeset
   142
    Passes information about an instant interaction from the widget to the
hgs
parents: 0
diff changeset
   143
    feedback manager, which forwards it to all active feedback plugins.
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   144
34
hgs
parents: 0
diff changeset
   145
    \param widget Target widget of the interaction
hgs
parents: 0
diff changeset
   146
    \param interaction The instant interaction type
hgs
parents: 0
diff changeset
   147
    \param modifiers Optional Hb::InteractionModifier flags with more detailed
hgs
parents: 0
diff changeset
   148
    information about the interaction
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   149
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   150
void HbWidgetFeedback::triggered(const HbWidget *widget, Hb::InstantInteraction interaction, Hb::InteractionModifiers modifiers)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   151
{
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
    HbFeedbackManager* manager = HbFeedbackManager::instance();
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
    if (manager) {
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   154
        manager->triggered(widget, interaction, modifiers);
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
    }
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
/*!
34
hgs
parents: 0
diff changeset
   159
    Passes information about a started continuous interaction from the
hgs
parents: 0
diff changeset
   160
    widget to the feedback manager, which forwards it to all active feedback
hgs
parents: 0
diff changeset
   161
    plugins.
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
34
hgs
parents: 0
diff changeset
   163
    \param widget Target widget of the interaction
hgs
parents: 0
diff changeset
   164
    \param interaction The continuous interaction type
hgs
parents: 0
diff changeset
   165
    \param delta The direction and distance of the interaction
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
void HbWidgetFeedback::continuousTriggered(const HbWidget *widget, Hb::ContinuousInteraction interaction, QPointF delta)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
{
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
    HbFeedbackManager* manager = HbFeedbackManager::instance();
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
    if (manager) {
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
        manager->continuousTriggered(widget, interaction, delta);
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
    }
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
}
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
/*!
34
hgs
parents: 0
diff changeset
   176
    Passes information about the stopped continuous interaction from the
hgs
parents: 0
diff changeset
   177
    widget to the feedback manager, which forwards it to all active feedback
hgs
parents: 0
diff changeset
   178
    plugins. This method is needed for stopping the continuous feedback
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
    effects started by the continuous interaction.
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   180
34
hgs
parents: 0
diff changeset
   181
    \param widget Target widget of the interaction
hgs
parents: 0
diff changeset
   182
    \param interaction The continuous interaction type
0
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
*/
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
void HbWidgetFeedback::continuousStopped(const HbWidget *widget, Hb::ContinuousInteraction interaction)
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
{
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
    HbFeedbackManager* manager = HbFeedbackManager::instance();
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
    if (manager) {
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
        manager->continuousStopped(widget, interaction);
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    }
16d8024aca5e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
}