class Anim : public QWidget
{
Q_OBJECT
public:
Anim(QWidget *parent = 0, Qt::WFlags flags = 0);
~Anim();
public:
void createWidget();
void createWidgetV();
void createWidgetH();
void createTransitionV();
void createTransitionHRetrun();
void createTransitionVRetrun();
void createTransitionH();
private:
QStateMachine* machine;
QState* stateV;
QState* stateH;
QState* state;
QWidget* widget;
QWidget* widgetV;
QWidget* widgetH;
QPushButton* hButton;
QPushButton* vButton;
QPushButton* hReturn;
QPushButton* vReturn;
};
Anim::Anim(QWidget* parent,Qt::WFlags flags):
QWidget(parent,flags | Qt::MSWindowsFixedSizeDialogHint)
{
machine = new QStateMachine(this);
resize(320,280);
createWidget();
createWidgetV();
createWidgetH();
state = new QState(machine);
stateV = new QState(machine);
stateH = new QState(machine);
state->assignProperty(widget, "geometry",QRect(0,0,320,280));
state->assignProperty(widgetH,"geometry",QRect(320,0,0,280));
state->assignProperty(widgetV,"geometry",QRect(0,280,320,0));
stateH->assignProperty(widget, "geometry",QRect(0,0,0,280));
stateH->assignProperty(widgetH,"geometry",QRect(0,0,320,280));
stateH->assignProperty(widgetV,"geometry",QRect(0,280,320,0));
stateV->assignProperty(widget, "geometry",QRect(0,0,320,0));
stateV->assignProperty(widgetH,"geometry",QRect(0,0,0,280));
stateV->assignProperty(widgetV,"geometry",QRect(0,0,320,280));
createTransitionHRetrun();
createTransitionVRetrun();
createTransitionH();
createTransitionV();
machine->setInitialState(state);
machine->start();
}
Anim::~Anim()
{
}
void Anim::createWidget()
{
widget = new QWidget(this);
widget->resize(320,280);
QVBoxLayout* vLayout = new QVBoxLayout(widget);
vButton = new QPushButton("V Click");
hButton = new QPushButton("H Click");
QHBoxLayout* hLayout = new QHBoxLayout();
hLayout->addWidget(vButton);
hLayout->addWidget(hButton);
vLayout->addLayout(hLayout);
vLayout->addWidget(new QTextEdit());
}
void Anim::createWidgetV()
{
widgetV = new QWidget(this);
widgetV->resize(320,0);
widgetV->move(0,280);
QVBoxLayout* vLayout = new QVBoxLayout(widgetV);
vReturn = new QPushButton("V Return");
vLayout->addWidget(vReturn);
vLayout->addWidget(new QTextEdit());
}
void Anim::createWidgetH()
{
widgetH = new QWidget(this);
widgetH->resize(0,280);
widgetH->move(320,0);
QVBoxLayout* vLayout = new QVBoxLayout(widgetH);
hReturn = new QPushButton("H Return");
vLayout->addWidget(hReturn);
vLayout->addWidget(new QTextEdit());
}
void Anim::createTransitionH()
{
QPropertyAnimation* widgetAnim = new QPropertyAnimation(widget,"geometry");
widgetAnim->setDuration(800);
widgetAnim->setEasingCurve(QEasingCurve::Linear);
QPropertyAnimation* widgetHAnim = new QPropertyAnimation(widgetH,"geometry");
widgetHAnim->setDuration(800);
widgetHAnim->setEasingCurve(QEasingCurve::Linear);
QSignalTransition* transition = state->addTransition(hButton,SIGNAL(clicked()),stateH);
transition->addAnimation(widgetAnim);
transition->addAnimation(widgetHAnim);
}
void Anim::createTransitionV()
{
QPropertyAnimation* widgetAnim = new QPropertyAnimation(widget,"geometry");
widgetAnim->setDuration(800);
widgetAnim->setEasingCurve(QEasingCurve::Linear);
QPropertyAnimation* widgetVAnim = new QPropertyAnimation(widgetV,"geometry");
widgetVAnim->setDuration(800);
widgetVAnim->setEasingCurve(QEasingCurve::Linear);
QSignalTransition* transition = state->addTransition(vButton,SIGNAL(clicked()),stateV);
transition->addAnimation(widgetAnim);
transition->addAnimation(widgetVAnim);
}
void Anim::createTransitionHRetrun()
{
QPropertyAnimation* widgetAnim = new QPropertyAnimation(widget,"geometry");
widgetAnim->setDuration(800);
widgetAnim->setEasingCurve(QEasingCurve::Linear);
QPropertyAnimation* widgetHAnim = new QPropertyAnimation(widgetH,"geometry");
widgetHAnim->setDuration(800);
widgetHAnim->setEasingCurve(QEasingCurve::Linear);
QSignalTransition* transition = stateH->addTransition(hReturn,SIGNAL(clicked()),state);
transition->addAnimation(widgetAnim);
transition->addAnimation(widgetHAnim);
}
void Anim::createTransitionVRetrun()
{
QPropertyAnimation* widgetAnim = new QPropertyAnimation(widget,"geometry");
widgetAnim->setDuration(800);
widgetAnim->setEasingCurve(QEasingCurve::Linear);
QPropertyAnimation* widgetVAnim = new QPropertyAnimation(widgetV,"geometry");
widgetVAnim->setDuration(800);
widgetVAnim->setEasingCurve(QEasingCurve::Linear);
QSignalTransition* transition = stateV->addTransition(vReturn,SIGNAL(clicked()),state);
transition->addAnimation(widgetAnim);
transition->addAnimation(widgetVAnim);
}