Beispiel #1
0
void UIAnimation::prepare()
{
    /* Prepare animation-machine: */
    m_pAnimationMachine = new QStateMachine(this);
    /* Create 'start' state: */
    m_pStateStart = new QState(m_pAnimationMachine);
    connect(m_pStateStart, SIGNAL(propertiesAssigned()), this, SIGNAL(sigStateEnteredStart()));
    /* Create 'final' state: */
    m_pStateFinal = new QState(m_pAnimationMachine);
    connect(m_pStateFinal, SIGNAL(propertiesAssigned()), this, SIGNAL(sigStateEnteredFinal()));

    /* Prepare 'forward' animation: */
    m_pForwardAnimation = new QPropertyAnimation(parent(), m_pszPropertyName, m_pAnimationMachine);
    m_pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    m_pForwardAnimation->setDuration(m_iAnimationDuration);
    /* Prepare 'reverse' animation: */
    m_pReverseAnimation = new QPropertyAnimation(parent(), m_pszPropertyName, m_pAnimationMachine);
    m_pReverseAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    m_pReverseAnimation->setDuration(m_iAnimationDuration);

    /* Prepare state-transitions: */
    QSignalTransition *pStartToFinal = m_pStateStart->addTransition(parent(), m_pszSignalForward, m_pStateFinal);
    pStartToFinal->addAnimation(m_pForwardAnimation);
    QSignalTransition *pFinalToStart = m_pStateFinal->addTransition(parent(), m_pszSignalReverse, m_pStateStart);
    pFinalToStart->addAnimation(m_pReverseAnimation);

    /* Fetch animation-borders: */
    update();

    /* Choose initial state: */
    m_pAnimationMachine->setInitialState(!m_fReverse ? m_pStateStart : m_pStateFinal);
    /* Start animation-machine: */
    m_pAnimationMachine->start();
}
TransparentButton::TransparentButton(QIcon icon,QWidget *parent,int size) :
    QWidget(parent)
{
    icon_=icon.pixmap(size,size).toImage();
    this->setMinimumSize(size,size);
    this->setOpacity(0.0);

    showStartState = new QState;
    showFinishState = new QState;

    enterState = new QState;

    closeStartState = new QState;
    closeFinishState = new QState;
    finalState = new QFinalState;

    QPropertyAnimation *opacityAmination = new QPropertyAnimation (this, "opacity_");
    opacityAmination->setDuration (200);

    showStartState->assignProperty (this, "opacity_", 0.0);
    showFinishState->assignProperty (this, "opacity_", 0.6);
    closeStartState->assignProperty (this, "opacity_", 0.6);
    closeFinishState->assignProperty (this, "opacity_", 0.0);
    enterState->assignProperty(this, "opacity_", 1.0);

    showStartState->addTransition (showFinishState);

    showFinishState->addTransition (this,
    SIGNAL (initiateHide ()), closeStartState);

    showFinishState->addTransition (this,
    SIGNAL (mouseEntered()), enterState);

    enterState->addTransition(this,SIGNAL(mouseLeave()),showFinishState);

    closeStartState->addTransition (closeFinishState);
    //closeFinishState->addTransition(finalState);
    closeFinishState->addTransition (closeFinishState,
    SIGNAL (propertiesAssigned ()), finalState);

    Machine_.addState (showStartState);
    Machine_.addState (showFinishState);
    Machine_.addState (enterState);
    Machine_.addState (closeStartState);
    Machine_.addState (closeFinishState);
    Machine_.addState (finalState);

    Machine_.addDefaultAnimation (opacityAmination);
    Machine_.setInitialState (showStartState);
}
Beispiel #3
0
MainIdle::MainIdle(Fsm *parent):State(parent)
{
    m_pfsm = parent;
    connect(this,SIGNAL(propertiesAssigned()),this,SLOT(initialization()));
}
Beispiel #4
0
ChargerState::ChargerState(Fsm *parent):State(parent)
{
    qDebug() << "Enter chargerState";
    m_pfsm = parent;
    connect(this,SIGNAL(propertiesAssigned()),this,SLOT(initialization()));
}
KinotifyWidget::KinotifyWidget (int timeout, QWidget *widget, int animationTimout)
: QWebView (widget)
, Timeout_ (timeout)
, AnimationTime_ (animationTimout)
{
    setWindowOpacity (0.0);
    this->setContextMenuPolicy(Qt::NoContextMenu);

    CloseTimer_ = new QTimer (this);
    CheckTimer_ = new QTimer (this);
    CloseTimer_->setSingleShot (true);
    CheckTimer_->setSingleShot (true);

    showStartState = new QState;
    showFinishState = new QState;
    closeStartState = new QState;
    closeFinishState = new QState;
    finalState = new QFinalState;

    QPropertyAnimation *opacityAmination = new QPropertyAnimation (this, "opacity");
    opacityAmination->setDuration (AnimationTime_);

    showStartState->assignProperty (this, "opacity", 0.0);
    showFinishState->assignProperty (this, "opacity", 0.8);
    closeStartState->assignProperty (this, "opacity", 0.8);
    closeFinishState->assignProperty (this, "opacity", 0.0);

    showStartState->addTransition (showFinishState);
    showFinishState->addTransition (this,
    SIGNAL (initiateCloseNotification ()), closeStartState);

    closeStartState->addTransition (closeFinishState);
    closeFinishState->addTransition (closeFinishState,
    SIGNAL (propertiesAssigned ()), finalState);


    Machine_.addState (showStartState);
    Machine_.addState (showFinishState);
    Machine_.addState (closeStartState);
    Machine_.addState (closeFinishState);
    Machine_.addState (finalState);

    Machine_.addDefaultAnimation (opacityAmination);
    Machine_.setInitialState (showStartState);

    connect (&Machine_,
    SIGNAL (finished ()),
    this,
    SLOT (closeNotification ()));

    connect (showFinishState,
    SIGNAL (entered ()),
    this,
    SLOT (stateMachinePause ()));

    connect (CloseTimer_,
    SIGNAL (timeout ()),
    this,
    SIGNAL (initiateCloseNotification ()));

    connect (CheckTimer_,
    SIGNAL (timeout ()),
    this,
    SIGNAL (checkNotificationQueue ()));
}
Beispiel #6
0
int main(int argv, char **args)
{
    QApplication app(argv, args);
    QWidget *button;

  {
//![0]
    QStateMachine machine;
    machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);

    QState *s1 = new QState();
    s1->assignProperty(object, "fooBar", 1.0);
    machine.addState(s1);
    machine.setInitialState(s1);

    QState *s2 = new QState();
    machine.addState(s2);
//![0]
  }

  {

//![2]
    QStateMachine machine;
    machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);

    QState *s1 = new QState();
    s1->assignProperty(object, "fooBar", 1.0);
    machine.addState(s1);
    machine.setInitialState(s1);

    QState *s2 = new QState(s1);
    s2->assignProperty(object, "fooBar", 2.0);
    s1->setInitialState(s2);

    QState *s3 = new QState(s1);
//![2]

  }

  {
//![3]
    QState *s1 = new QState();
    QState *s2 = new QState();

    s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
    s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));

    s1->addTransition(button, SIGNAL(clicked()), s2);
//![3]

  }

  {
//![4]
    QState *s1 = new QState();
    QState *s2 = new QState();

    s1->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
    s2->assignProperty(button, "geometry", QRectF(0, 0, 100, 100));

    QSignalTransition *transition = s1->addTransition(button, SIGNAL(clicked()), s2);
    transition->addAnimation(new QPropertyAnimation(button, "geometry"));
//![4]

  }

  {
    QMainWindow *mainWindow = 0;

//![5]
    QMessageBox *messageBox = new QMessageBox(mainWindow);
    messageBox->addButton(QMessageBox::Ok);
    messageBox->setText("Button geometry has been set!");
    messageBox->setIcon(QMessageBox::Information);

    QState *s1 = new QState();

    QState *s2 = new QState();
    s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));
    connect(s2, SIGNAL(entered()), messageBox, SLOT(exec()));

    s1->addTransition(button, SIGNAL(clicked()), s2);
//![5]
  }

  {
    QMainWindow *mainWindow = 0;

//![6]
    QMessageBox *messageBox = new QMessageBox(mainWindow);
    messageBox->addButton(QMessageBox::Ok);
    messageBox->setText("Button geometry has been set!");
    messageBox->setIcon(QMessageBox::Information);

    QState *s1 = new QState();

    QState *s2 = new QState();
    s2->assignProperty(button, "geometry", QRectF(0, 0, 50, 50));

    QState *s3 = new QState();
    connect(s3, SIGNAL(entered()), messageBox, SLOT(exec()));

    s1->addTransition(button, SIGNAL(clicked()), s2);
    s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3);
//![6]

  }

  {

//![7]
    QState *s1 = new QState();
    QState *s2 = new QState();

    s2->assignProperty(object, "fooBar", 2.0);
    s1->addTransition(s2);

    QStateMachine machine;
    machine.setInitialState(s1);
    machine.addDefaultAnimation(new QPropertyAnimation(object, "fooBar"));
//![7]

  }



    return app.exec();
}