00001 #ifndef MYTHUIANIMATION_H
00002 #define MYTHUIANIMATION_H
00003
00004 #include "xmlparsebase.h"
00005 #include <QVariantAnimation>
00006
00007 class MythUIType;
00008
00009 class UIEffects
00010 {
00011 public:
00012 enum Centre { TopLeft, Top, TopRight,
00013 Left, Middle, Right,
00014 BottomLeft, Bottom, BottomRight };
00015
00016 UIEffects()
00017 : alpha(255), hzoom(1.0), vzoom(1.0), angle(0.0), centre(Middle) { }
00018
00019 QPointF GetCentre(const QRect &rect, int xoff, int yoff)
00020 {
00021 float x = xoff + rect.left();
00022 float y = yoff + rect.top();
00023 if (Middle == centre || Top == centre || Bottom == centre)
00024 x += rect.width() / 2.0;
00025 if (Middle == centre || Left == centre || Right == centre)
00026 y += rect.height() / 2.0;
00027 if (Right == centre || TopRight == centre || BottomRight == centre)
00028 x += rect.width();
00029 if (Bottom == centre || BottomLeft == centre || BottomRight == centre)
00030 y += rect.height();
00031 return QPointF(x, y);
00032 }
00033
00034 int alpha;
00035 float hzoom;
00036 float vzoom;
00037 float angle;
00038 Centre centre;
00039 };
00040
00041 class MythUIAnimation : public QVariantAnimation, XMLParseBase
00042 {
00043 public:
00044 enum Type { Alpha, Position, Zoom, HorizontalZoom, VerticalZoom, Angle };
00045 enum Trigger { AboutToHide, AboutToShow };
00046
00047 MythUIAnimation(MythUIType* parent = NULL,
00048 Trigger trigger = AboutToShow, Type type = Alpha);
00049 void Activate(void);
00050 void CopyFrom(const MythUIAnimation* animation);
00051 Trigger GetTrigger(void) const { return m_trigger; }
00052 QVariant Value() const { return m_value; }
00053 bool IsActive() const { return m_active; }
00054
00055 virtual void updateCurrentValue(const QVariant& value);
00056
00057 void IncrementCurrentTime(void);
00058 void SetEasingCurve(const QString &curve);
00059 void SetCentre(const QString ¢re);
00060 void SetLooped(bool looped) { m_looped = looped; }
00061 void SetReversible(bool rev) { m_reversible = rev; }
00062
00063 static void ParseElement(const QDomElement& element, MythUIType* parent);
00064
00065 private:
00066 static void ParseSection(const QDomElement &element,
00067 MythUIType* parent, Trigger trigger);
00068 static void parseAlpha(const QDomElement& element, QVariant& startValue,
00069 QVariant& endValue);
00070 static void parsePosition(const QDomElement& element, QVariant& startValue,
00071 QVariant& endValue, MythUIType *parent);
00072 static void parseZoom(const QDomElement& element, QVariant& startValue,
00073 QVariant& endValue);
00074 static void parseAngle(const QDomElement& element, QVariant& startValue,
00075 QVariant& endValue);
00076
00077 MythUIType* m_parent;
00078 Type m_type;
00079 Trigger m_trigger;
00080 UIEffects::Centre m_centre;
00081 QVariant m_value;
00082 bool m_active;
00083 bool m_looped;
00084 bool m_reversible;
00085 };
00086
00087 #endif // MYTHUIANIMATION_H