src/hbcore/image/hbiconanimationdefinition.cpp
changeset 0 16d8024aca5e
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 HbCore 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 "hbiconanimationdefinition.h"
       
    27 
       
    28 // Private class
       
    29 class HbIconAnimationDefinitionPrivate : public QSharedData
       
    30 {
       
    31 public:
       
    32     HbIconAnimationDefinitionPrivate();
       
    33     ~HbIconAnimationDefinitionPrivate();
       
    34 
       
    35     // This constructor is used only by NULL instance
       
    36     HbIconAnimationDefinitionPrivate(bool nullInstance);
       
    37 
       
    38     HbIconAnimationDefinitionPrivate(const HbIconAnimationDefinitionPrivate &other);
       
    39 
       
    40 private:
       
    41     // disabled
       
    42     HbIconAnimationDefinitionPrivate &operator=(const HbIconAnimationDefinitionPrivate &other);
       
    43 
       
    44 public:
       
    45     QList<HbIconAnimationDefinition::AnimationFrame> frameList;
       
    46     HbIconAnimationDefinition::PlayMode playMode;
       
    47 };
       
    48 
       
    49 // Shared null private object
       
    50 static HbIconAnimationDefinitionPrivate shared_null(true);
       
    51 
       
    52 /*!
       
    53 \internal
       
    54 */
       
    55 HbIconAnimationDefinitionPrivate::HbIconAnimationDefinitionPrivate() :
       
    56     QSharedData(),
       
    57     frameList(),
       
    58     playMode(HbIconAnimationDefinition::PlayOnce)
       
    59 {
       
    60 }
       
    61 
       
    62 /*!
       
    63 \internal
       
    64 */
       
    65 HbIconAnimationDefinitionPrivate::HbIconAnimationDefinitionPrivate(bool nullInstance) :
       
    66     QSharedData(),
       
    67     frameList(),
       
    68     playMode(HbIconAnimationDefinition::PlayOnce)
       
    69 {
       
    70     Q_UNUSED(nullInstance)
       
    71     // Need to ref here so null instance does not get destroyed
       
    72     ref.ref();
       
    73 }
       
    74 
       
    75 /*!
       
    76 \internal
       
    77 */
       
    78 HbIconAnimationDefinitionPrivate::~HbIconAnimationDefinitionPrivate()
       
    79 {
       
    80     frameList.clear();
       
    81 }
       
    82 
       
    83 /*!
       
    84 \internal
       
    85 */
       
    86 HbIconAnimationDefinitionPrivate::HbIconAnimationDefinitionPrivate(
       
    87     const HbIconAnimationDefinitionPrivate &other) :
       
    88     QSharedData(other),
       
    89     frameList(other.frameList),
       
    90     playMode(other.playMode)
       
    91 {
       
    92 }
       
    93 
       
    94 /*!
       
    95     @stable
       
    96     @hbcore
       
    97     \class HbIconAnimationDefinition
       
    98     \brief HbIconAnimationDefinition contains animation definition for an animated icon.
       
    99 
       
   100     Global definitions are managed by theme server.
       
   101     Definitions added in an application are local to the application.
       
   102 */
       
   103 
       
   104 /*!
       
   105   \enum HbIconAnimationDefinition::PlayMode
       
   106 
       
   107   This enum defines the play mode for the animation.
       
   108  */
       
   109 
       
   110 /*!
       
   111   \var HbIconAnimationDefinition::PlayOnce
       
   112 
       
   113   The animation is played once.
       
   114  */
       
   115 
       
   116 /*!
       
   117   \var HbIconAnimationDefinition::Loop
       
   118 
       
   119   The animation is repeated from the beginning when the end is reached, until it is
       
   120   stopped manually.
       
   121 */
       
   122 
       
   123 /*!
       
   124   \struct HbIconAnimationDefinition::AnimationFrame
       
   125 
       
   126   \brief Stores the data for one frame of the animation.
       
   127 */
       
   128 
       
   129 /*!
       
   130   \var HbIconAnimationDefinition::AnimationFrame::iconName
       
   131 
       
   132   Name of the icon.
       
   133  */
       
   134 
       
   135 /*!
       
   136   \var HbIconAnimationDefinition::AnimationFrame::duration
       
   137 
       
   138   Duration in milliseconds defining how long the frame is shown.
       
   139  */
       
   140 
       
   141 /*!
       
   142   \var HbIconAnimationDefinition::AnimationFrame::jumps
       
   143 
       
   144   Contains the list of jumps that need to be performed after showing this frame for the
       
   145   given duration.  For a simple animation that has no local loops (meaning that no frames
       
   146   are repeated more than once) this list will be empty. If there are multiple jumps
       
   147   associated with a frame then they will performed in their order in this list, e.g. the
       
   148   second jump will be performed when the first has already been executed for the specified
       
   149   number of times.
       
   150  */
       
   151 
       
   152 /*!
       
   153   \struct HbIconAnimationDefinition::AnimationFrame::Jump
       
   154 
       
   155   \brief Stores the information for one jump associated with a frame.
       
   156 
       
   157   Jumps are used to implement local loops (where some frames are repeated for a number of
       
   158   times).  For example the animation xml parser translates loop elements into these
       
   159   lightweight jump instructions so the animation player can play such animations
       
   160   correctly.
       
   161 */
       
   162 
       
   163 /*!
       
   164   \var HbIconAnimationDefinition::AnimationFrame::Jump::targetFrameIndex
       
   165 
       
   166   Index of the target frame of the jump.
       
   167  */
       
   168 
       
   169 /*!
       
   170   \var HbIconAnimationDefinition::AnimationFrame::Jump::repeatCount
       
   171 
       
   172   Defines how many times the jump should be executed.
       
   173  */
       
   174 
       
   175 /*!
       
   176     Creates an empty animation definition.
       
   177 */
       
   178 HbIconAnimationDefinition::HbIconAnimationDefinition() : d(&shared_null)
       
   179 {
       
   180 }
       
   181 
       
   182 /*!
       
   183     Destroys the animation definition.
       
   184 */
       
   185 HbIconAnimationDefinition::~HbIconAnimationDefinition()
       
   186 {
       
   187 }
       
   188 
       
   189 /*!
       
   190     Creates a copy of the /a other animation definition.
       
   191     This is just a shallow copy, a deep copy of the data is done
       
   192     if the instance is modified.
       
   193 */
       
   194 HbIconAnimationDefinition::HbIconAnimationDefinition(
       
   195     const HbIconAnimationDefinition &other) : d(other.d)
       
   196 {
       
   197 }
       
   198 
       
   199 /*!
       
   200     Assigns the /a other animation definition to this animation definition.
       
   201     This is just a shallow copy, a deep copy of the data is done
       
   202     if the instance is modified.
       
   203 */
       
   204 HbIconAnimationDefinition &HbIconAnimationDefinition::operator=(
       
   205     const HbIconAnimationDefinition &other)
       
   206 {
       
   207     if (&other != this) {
       
   208         d = other.d;
       
   209     }
       
   210     return *this;
       
   211 }
       
   212 
       
   213 /*!
       
   214     Returns true if the animation definition is an empty default constructed instance.
       
   215     Note that even if isNull() returns false, the animation frame list of the definition may be empty.
       
   216 */
       
   217 bool HbIconAnimationDefinition::isNull() const
       
   218 {
       
   219     return d.constData() == &shared_null;
       
   220 }
       
   221 
       
   222 /*!
       
   223     Returns the animation frame list. It contains information of the icon files for the animation
       
   224     frames and their durations.
       
   225 */
       
   226 QList<HbIconAnimationDefinition::AnimationFrame> HbIconAnimationDefinition::frameList() const
       
   227 {
       
   228     return d->frameList;
       
   229 }
       
   230 
       
   231 /*!
       
   232     Sets the animation frame list in the animation definition.
       
   233 */
       
   234 void HbIconAnimationDefinition::setFrameList(const QList<HbIconAnimationDefinition::AnimationFrame> &list)
       
   235 {
       
   236     d.detach();
       
   237     d->frameList = list;
       
   238 }
       
   239 
       
   240 /*!
       
   241     Returns the play mode of the animation.
       
   242 */
       
   243 HbIconAnimationDefinition::PlayMode HbIconAnimationDefinition::playMode() const
       
   244 {
       
   245     return d->playMode;
       
   246 }
       
   247 
       
   248 /*!
       
   249     Sets the play mode of the animation.
       
   250 */
       
   251 void HbIconAnimationDefinition::setPlayMode(PlayMode mode)
       
   252 {
       
   253     if (mode != d->playMode) {
       
   254         d.detach();
       
   255         d->playMode = mode;
       
   256     }
       
   257 }
       
   258 
       
   259 
       
   260 // End of File