src/hbcore/image/hbiconanimation_p.h
changeset 0 16d8024aca5e
child 5 627c4a0fd0e7
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 #ifndef HBICONANIMATION_H
       
    27 #define HBICONANIMATION_H
       
    28 
       
    29 #include <hbglobal.h>
       
    30 #include <hbiconanimationdefinition.h>
       
    31 #include <QtGlobal>
       
    32 #include <QTimer>
       
    33 #include <QObject>
       
    34 #include <QIcon>
       
    35 
       
    36 QT_BEGIN_NAMESPACE
       
    37 class QSvgRenderer;
       
    38 class QImageReader;
       
    39 QT_END_NAMESPACE
       
    40 
       
    41 class HbIconAnimationManagerPrivate;
       
    42 class HbIconAnimator;
       
    43 class HbView;
       
    44 class HbTimerSignalEntry;
       
    45 
       
    46 class HbIconAnimation : public QObject
       
    47 {
       
    48     Q_OBJECT
       
    49 
       
    50 public:
       
    51     HbIconAnimation(HbIconAnimator *animator, const QString &iconName);
       
    52     virtual ~HbIconAnimation();
       
    53 
       
    54     enum {
       
    55         SVG = 0,
       
    56         MNG = 1,
       
    57         GIF = 2,
       
    58         FrameSet = 3
       
    59     };
       
    60 
       
    61     virtual int type() const = 0;
       
    62 
       
    63     virtual void start() = 0;
       
    64     virtual void stop() = 0;
       
    65     virtual void pause() = 0;
       
    66     virtual void resume() = 0;
       
    67 
       
    68     virtual QPixmap currentFrame() const = 0;
       
    69 
       
    70     QString iconName() const;
       
    71 
       
    72     virtual QSizeF size() const;
       
    73     virtual void setSize(const QSizeF &size);
       
    74 
       
    75     virtual Qt::AspectRatioMode aspectRatioMode() const;
       
    76     virtual void setAspectRatioMode(Qt::AspectRatioMode mode);
       
    77 
       
    78     virtual QIcon::Mode mode() const;
       
    79     virtual void setMode(QIcon::Mode mode);
       
    80 
       
    81     virtual QSizeF defaultSize() const;
       
    82     virtual void setDefaultSize(const QSizeF &size);
       
    83 
       
    84     virtual QSizeF renderSize() const;
       
    85     virtual void setRenderSize(const QSizeF &size);
       
    86 
       
    87     bool mirrored() const;
       
    88     void setMirrored(bool mirrored);
       
    89 
       
    90     QColor color() const;
       
    91     void setColor(const QColor &color);	
       
    92 
       
    93     bool resolutionCorrected() const;
       
    94     void setResolutionCorrected(bool corrected);
       
    95 
       
    96     HbIconAnimationDefinition::PlayMode playMode() const;
       
    97     void setPlayMode(HbIconAnimationDefinition::PlayMode playMode);
       
    98 
       
    99     inline HbView *view() const
       
   100     {
       
   101         return mView;
       
   102     }
       
   103 
       
   104     inline void setView(HbView *view)
       
   105     {
       
   106         mView = view;
       
   107     }
       
   108 
       
   109     inline HbIconAnimator *animator() const
       
   110     {
       
   111         return mAnimator;
       
   112     }
       
   113 
       
   114     inline bool paused() const
       
   115     {
       
   116         return mPaused;
       
   117     }
       
   118 
       
   119     inline bool pausedDueToBackground() const
       
   120     {
       
   121         return mPausedDueToBackground;
       
   122     }
       
   123 
       
   124     inline void setPausedDueToBackground(bool status)
       
   125     {
       
   126         mPausedDueToBackground = status;
       
   127     }
       
   128 
       
   129 
       
   130 signals:
       
   131     void animationUpdated();
       
   132     void animationStarted();
       
   133     void animationStopped();
       
   134     void animationFinished();
       
   135 
       
   136 public slots:
       
   137     void notifyAnimationStarted();
       
   138     void notifyAnimationStopped();
       
   139     void notifyAnimationFinished();
       
   140 
       
   141 protected:
       
   142     void delayedEmitStarted();
       
   143 
       
   144     QString mIconName;
       
   145     bool mMirrored;
       
   146     bool mResolutionCorrected;
       
   147     // If size or aspectRatioMode are changed, it also recalculates the renderSize
       
   148     QSizeF mSize;
       
   149     Qt::AspectRatioMode mAspectRatioMode;
       
   150     QIcon::Mode mMode;
       
   151 
       
   152     QSizeF mDefaultSize;
       
   153     QSizeF mRenderSize;
       
   154 
       
   155     HbIconAnimationDefinition::PlayMode mPlayMode;
       
   156 
       
   157     QTimer *mStartSignalTimer;
       
   158 
       
   159     // Indicates that this is a newly constructed instance for which start() has never been called.
       
   160     bool mFresh;
       
   161 
       
   162     // dptr to the global animation manager instance
       
   163     HbIconAnimationManagerPrivate *mAnimMgrD;
       
   164 	QColor mColor;
       
   165 
       
   166     HbIconAnimator *mAnimator;
       
   167     HbView *mView;
       
   168 
       
   169     bool mPaused;
       
   170     bool mPausedDueToBackground;
       
   171 };
       
   172 
       
   173 class HbIconAnimationSvg : public HbIconAnimation
       
   174 {
       
   175     Q_OBJECT
       
   176 
       
   177 public:
       
   178     HbIconAnimationSvg(HbIconAnimator *animator, const QString &iconName, QSvgRenderer *renderer, const QString &iconPath);
       
   179     ~HbIconAnimationSvg();
       
   180 
       
   181     int type() const;
       
   182 
       
   183     void start();
       
   184     void stop();
       
   185     void pause();
       
   186     void resume();
       
   187 
       
   188     QPixmap currentFrame() const;
       
   189 
       
   190 private slots:
       
   191     void handleSvgAnimationUpdated();
       
   192 
       
   193 private:
       
   194     QSvgRenderer *mSvgRenderer;
       
   195     QString mIconPath;
       
   196 };
       
   197 
       
   198 class HbIconAnimationImage : public HbIconAnimation
       
   199 {
       
   200     Q_OBJECT
       
   201 
       
   202 public:
       
   203     HbIconAnimationImage(HbIconAnimator *animator, const QString &iconName, const QString &iconFileName, QImageReader *renderer, int type);
       
   204     ~HbIconAnimationImage();
       
   205 
       
   206     int type() const;
       
   207 
       
   208     void start();
       
   209     void stop();
       
   210     void pause();
       
   211     void resume();
       
   212 
       
   213     QPixmap currentFrame() const;
       
   214 
       
   215 private slots:
       
   216     void handleAnimationUpdated();
       
   217 
       
   218 private:
       
   219     QImageReader *mImageRenderer;
       
   220     QString mIconFileName;
       
   221     int mType;
       
   222     int mTimerInterval;
       
   223     HbTimerSignalEntry *mTimerEntry;
       
   224     QPixmap mCurrentFrame;
       
   225     QPixmap mLastFrame;
       
   226 };
       
   227 
       
   228 class HbIconAnimationFrameSet : public HbIconAnimation
       
   229 {
       
   230     Q_OBJECT
       
   231 
       
   232 public:
       
   233     struct JumpData {
       
   234         int targetFrameIndex;
       
   235         int repeatCount; // max exec count
       
   236         int execCount; // current exec count
       
   237     };
       
   238     struct FrameData {
       
   239         QPixmap pixmap;
       
   240         int duration; // in milliseconds
       
   241         QList<JumpData> jumps;
       
   242         void assignJumps(const QList<HbIconAnimationDefinition::AnimationFrame::Jump> &jlist)
       
   243             {
       
   244                 jumps.clear();
       
   245                 for (int i = 0, ie = jlist.count(); i != ie; ++i) {
       
   246                     JumpData jd;
       
   247                     jd.targetFrameIndex = jlist.at(i).targetFrameIndex;
       
   248                     jd.repeatCount = jlist.at(i).repeatCount;
       
   249                     jd.execCount = 0;
       
   250                     jumps.append(jd);
       
   251                 }
       
   252             }
       
   253     };
       
   254 
       
   255     HbIconAnimationFrameSet(HbIconAnimator *animator, const QString &iconName, const QList<FrameData> &frames);
       
   256     ~HbIconAnimationFrameSet();
       
   257 
       
   258     int type() const;
       
   259 
       
   260     void start();
       
   261     void stop();
       
   262     void pause();
       
   263     void resume();
       
   264 
       
   265     QPixmap currentFrame() const;
       
   266 
       
   267 public slots:
       
   268     void animationTimeout();
       
   269 
       
   270 private:
       
   271     void moveToNextFrame();
       
   272     void resetJumpCount(FrameData &frame);
       
   273     void resetJumpCounts();
       
   274 
       
   275     QList<FrameData> mFrames;
       
   276     int mTimerInterval;
       
   277     int mCurrentFrameIndex;
       
   278 
       
   279     bool mMirrored;
       
   280     
       
   281     HbTimerSignalEntry *mTimerEntry;
       
   282 };
       
   283 
       
   284 
       
   285 #endif // HBICONANIMATION_H