00001 #ifndef MYTHUI_IMAGE_H_
00002 #define MYTHUI_IMAGE_H_
00003
00004 #include <QDateTime>
00005 #include <QHash>
00006 #include <QMutex>
00007 #include <QWaitCondition>
00008 #include <QVector>
00009 #include <QPair>
00010
00011 #include "mythuitype.h"
00012 #include "mythuihelper.h"
00013 #include "mythimage.h"
00014
00015 class MythUIImagePrivate;
00016 class MythScreenType;
00017 class ImageLoadThread;
00018
00022 class ImageProperties
00023 {
00024 public:
00025 ImageProperties();
00026 ImageProperties(const ImageProperties& other);
00027 ~ImageProperties();
00028
00029 ImageProperties &operator=(const ImageProperties &other);
00030
00031 void SetMaskImage(MythImage* image);
00032 MythImage* GetMaskImage() { return maskImage; }
00033
00034 QString filename;
00035
00036 MythRect cropRect;
00037 QSize forceSize;
00038
00039 bool preserveAspect;
00040 bool isGreyscale;
00041 bool isReflected;
00042 bool isMasked;
00043
00044 ReflectAxis reflectAxis;
00045 int reflectScale;
00046 int reflectLength;
00047 int reflectShear;
00048 int reflectSpacing;
00049
00050 private:
00051 void Init(void);
00052 void Copy(const ImageProperties &other);
00053
00054 MythImage *maskImage;
00055 };
00056
00057 typedef QPair<MythImage *, int> AnimationFrame;
00058 typedef QVector<AnimationFrame> AnimationFrames;
00059
00067 class MUI_PUBLIC MythUIImage : public MythUIType
00068 {
00069 public:
00070 MythUIImage(const QString &filepattern, int low, int high, int delayms,
00071 MythUIType *parent, const QString &name);
00072 MythUIImage(const QString &filename, MythUIType *parent, const QString &name);
00073 MythUIImage(MythUIType *parent, const QString &name);
00074 ~MythUIImage();
00075
00076 QString GetFilename(void) { return m_Filename; }
00077
00079 void SetFilename(const QString &filename);
00080
00082 void SetFilepattern(const QString &filepattern, int low, int high);
00083
00084 void SetImageCount(int low, int high);
00085
00089 void SetImage(MythImage *img);
00090
00094 void SetImages(QVector<MythImage *> *images);
00095
00096 void SetDelay(int delayms);
00097 void SetDelays(QVector<int> delays);
00098
00099 void Reset(void);
00100 bool Load(bool allowLoadInBackground = true, bool forceStat = false);
00101
00102 virtual void Pulse(void);
00103
00104 virtual void LoadNow(void);
00105
00106 protected:
00107 virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset,
00108 int alphaMod, QRect clipRect);
00109
00110 void Init(void);
00111 void Clear(void);
00112
00113 void SetAnimationFrames(AnimationFrames frames);
00114 void customEvent(QEvent *event);
00115
00116 virtual bool ParseElement(
00117 const QString &filename, QDomElement &element, bool showWarnings);
00118 virtual void CopyFrom(MythUIType *base);
00119 virtual void CreateCopy(MythUIType *parent);
00120 virtual void Finalize(void);
00121
00122 void SetSize(int width, int height);
00123 void SetSize(const QSize &size);
00124 void ForceSize(const QSize &size);
00125
00126 void SetCropRect(int x, int y, int width, int height);
00127 void SetCropRect(const MythRect &rect);
00128
00129 QString m_Filename;
00130 QString m_OrigFilename;
00131
00132 QHash<int, MythImage *> m_Images;
00133 QHash<int, int> m_Delays;
00134 QMutex m_ImagesLock;
00135
00136 int m_Delay;
00137 int m_LowNum;
00138 int m_HighNum;
00139
00140 unsigned int m_CurPos;
00141 QTime m_LastDisplay;
00142
00143 bool m_NeedLoad;
00144
00145 ImageProperties m_imageProperties;
00146
00147 int m_runningThreads;
00148
00149 MythUIImagePrivate *d;
00150
00151 enum AnimationCycle {kCycleStart, kCycleReverse};
00152 AnimationCycle m_animationCycle;
00153 bool m_animationReverse;
00154 bool m_animatedImage;
00155
00156 friend class MythUIImagePrivate;
00157 friend class MythThemeBase;
00158 friend class MythUIButtonListItem;
00159 friend class MythUIProgressBar;
00160 friend class MythUIEditBar;
00161 friend class MythUITextEdit;
00162 friend class ImageLoadThread;
00163
00164 Q_DISABLE_COPY(MythUIImage)
00165 };
00166
00167 #endif