#ifndef WIDGET_H
#define WIDGET_H

#include <QObject>
#include <QPointF>
#include <QState>
#include <QFinalState>
#include <QStateMachine>
#include <QPropertyAnimation>
#include <QPauseAnimation>
#include <QPixmap>
#include <QWidget>

// 定义与Q_PROPERTY宏配套的宏
#define DECLRARE_PROPERTY_WITH_GETTERS_AND_SETTERS( aType, aProperty ) protected:\
    aType m_ ## aProperty; public:\
    aType aProperty( void ) { return m_ ## aProperty; }\
    void set ## aProperty( const aType& property )\
    { m_ ## aProperty = property; }

class FlyInVanishEffect: public QObject
{
    Q_OBJECT
    Q_PROPERTY( QPointF Pos READ Pos WRITE setPos )
public:
    FlyInVanishEffect( QWidget* pWidget = 0 );
    void RenderPixmap( const QString& text );
    QPixmap& Pixmap( void );
    void StartEffect( void );
signals:
    void Start( );
private:
    DECLRARE_PROPERTY_WITH_GETTERS_AND_SETTERS( QPointF, Pos )
    //QState m_InitialState, m_MiddleState1, m_MiddleState2;
    //QFinalState m_FinalState;
    //QStateMachine m_Machine;
    QState *m_pInitialState, *m_pMiddleState1, *m_pMiddleState2;
    QFinalState* m_pFinalState;
    QStateMachine* m_pMachine;
    //QPropertyAnimation *m_pFlyInAnim, *m_pVanishAnim;

    //QPropertyAnimation m_FlyInAnim, m_VanishAnim;
    //QPauseAnimation m_PauseAnim;
    QPropertyAnimation *m_pFlyInAnim, *m_pVanishAnim;
    QPauseAnimation* m_pPauseAnim;
    QPixmap m_TextPixmap;
    QWidget* m_pWidget;
};

class Widget: public QWidget
{
    Q_OBJECT
public:
    Widget( QWidget* pParent = 0 );
protected:
    void paintEvent( QPaintEvent* pEvent );
    void keyPressEvent( QKeyEvent* pEvent );
private:
    FlyInVanishEffect m_Effect;
};

#endif // WIDGET_H
