/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of this
** file.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example hapticsquare
    \title Haptic Square Example

    \section1 Overview

    This example shows how to use simple haptic effects in an application via
    the \l{Feedback}{QtMobility Feedback API}.

    It provides an example of how to use the QtMobility libraries to:
    \list
    \o play "system theme" haptic effects corresponding to certain predefined events
    \o play a custom effect, single or repeating
    \endlist

    \section2 Use Case

    Compelling applications attempt to immerse the user in the application
    experience.  There are many elements to an immersive experience, including
    a consistent and beautiful graphical user interface design, unobtrusive yet
    informative sound design, and intuitive program flow.  Another important
    aspect of immersive applications is tactile feedback and haptic effects.

    The \l{Feedback}{QtMobility Feedback API} allows application developers to
    include tactile feedback into their application via a simple to use and
    extensible API.  Some common uses for tactile feedback are:

    \list
    \o maintain consistency with system theme for tactile feedback about interface events (button clicks, scrolling, etc)
    \o notify the user of an application-specific event (invalid operation, status change, etc)
    \o multisensory user interface (status can be "read" by touching the screen, tactile interfaces, etc)
    \o immersive gaming experiences (explosions, impacts, collisions, etc)
    \endlist

    This example application provides some short snippets which illustrate how
    the first two of those use cases may be fulfilled.

    \section1 The Application

    The application is designed to work on desktop and mobile platforms with
    minimal differences in code between the platforms. The interface consists
    of four buttons arranged into a square, each of which causes a different
    tactile effect to be played by the default tactile effect provider plugin
    on the platform.

    \image hapticsquare-example.png

    \list
    \o "Rumble!" plays a non-repeating effect with symmetric attack and decay
    \o "Ocean" is a toggle button which plays a repeating ocean wave-like effect
    \o "Click" plays the system theme effect for a basic button click
    \o "Oops!" plays the system theme effect for a negative or invalid response
    \endlist

    The example implements two classes:

    \list
        \o \c {HapticButton}: Implementation of a button. It
            inherits QWidget and sends signals for button clicks.
        \o \c {Dialog}: A QDialog subclass that displays the four
            \c{HapticButton}s mentioned above,
            connects them to its slots, and implements the functionality to
            play the haptic effects.
    \endlist

    \section2 The Dialog Class

    We will now go through the code for the \c Dialog class. Here is its
    definition:

    \snippet examples/hapticsquare/hapticsquare.h 0

    The buttons are connected to the slots, which play the effects. We will now
    go through the implementation of \c Dialog.

    The constructor starts by setting up the non-repeating haptic effect, which
    is played by clicking the \gui {Rumble! Button}.

    \snippet examples/hapticsquare/hapticsquare.cpp 0

    Custom haptics effects are created by setting up a QFeedbackHapticsEffect.

    A haptics effect provides a fade-in of the effect's
    \l{QFeedbackHapticsEffect::}{intensity()}. With vibration, you can think of
    the intensity as how hard the device will vibrate. The effect will start at
    \l{QFeedbackHapticsEffect::}{attackIntensity()} and interpolate to
    \l{QFeedbackHapticsEffect::}{intensity()} in
    \l{QFeedbackHapticsEffect::}{attackTime()} milliseconds. When the effect
    ends, we have a similar fade-out, where the haptics effect's intensity will
    interpolate from \l{QFeedbackHapticsEffect::}{intensity()} to
    \l{QFeedbackHapticsEffect::}{fadeTime()} in
    \l{QFeedbackHapticsEffect::}{fadeTime()} milliseconds.
    The effect will last for a total duration of
    \l{QFeedbackHapticsEffect::}{duration()} milliseconds.

    We next set up the effect for the \gui {Ocean Button}.

    \snippet examples/hapticsquare/hapticsquare.cpp 1

    The \c m_ocean is a periodic effect, i.e., it repeats after
    \l{QFeedbackHapticsEffect::}{period()} milliseconds.  Note that the
    \l{QFeedbackHapticsEffect::}{duration()} must be greater than the period
    in order for the periodicity of the effect to be discernable.

    We then set up the GUI and connects the buttons to slots that will play the
    effects.

    \snippet examples/hapticsquare/hapticsquare.cpp 2

    Let's look at the slots to see how the effects are played.

    \snippet examples/hapticsquare/hapticsquare.cpp 3

    With the \c m_rumble, we only have to call \l{QFeedbackEffect::}{start()}. It
    will stop when the effect has finished, and can be played again by calling
    \l{QFeedbackEffect::}{start()} again.

    The periodic \c m_ocean effect is started the same way as the \c m_rumble
    effect, and may be stopped with the \l{QFeedbackEffect::}{stop()} function.
    It will start playing from the beginning again when
    \l{QFeedbackEffect::}{start()} is called. We could also have paused the
    effect with \l{QFeedbackEffect::}{pause()}.

    \snippet examples/hapticsquare/hapticsquare.cpp 4

    System theme effects are played with the static
    QFeedbackEffect::playThemeEffect() function. Theme effects cannot be stopped
    or paused. There is no guarantee that the backend can play the effect;
    \l{QFeedbackEffect::}{playThemeEffect()} will return false if the effect
    could not be played.

    \section1 Known Issues

    The example is not intended to exercise the entire API.  Instead, it is a
    simple example which illustrates some simple uses of the API.
    Also, the example will not work correctly on platforms which do not have a
    QFeedbackHapticInterface (haptic effect provider) plugin loaded.  On such
    platforms, clicking the buttons will have no effect.  On Maemo5, periodic
    effects do not support attack or fade, and so the ocean effect is not
    smooth.
*/

