Exemple #1
0
Tank::Tank(QObject *parent)
    : QGLSceneNode(parent)
    , m_texture(0)
{
    QSequentialAnimationGroup *seq = new QSequentialAnimationGroup(this);
    QGraphicsScale3D *scale = new QGraphicsScale3D(this);
    addTransform(scale);
    QPropertyAnimation *anim = new QPropertyAnimation(scale, "scale");
    anim->setDuration(10000);
    anim->setStartValue(QVector3D(1.0f, 0.1f, 1.0f));
    anim->setEndValue(QVector3D(1.0f, 1.2f, 1.0f));
    anim->setEasingCurve(QEasingCurve(QEasingCurve::InOutQuad));
    seq->addAnimation(anim);
    seq->addPause(2000);
    anim = new QPropertyAnimation(scale, "scale");
    anim->setDuration(10000);
    anim->setStartValue(QVector3D(1.0f, 1.2f, 1.0f));
    anim->setEndValue(QVector3D(1.0f, 0.1f, 1.0f));
    anim->setEasingCurve(QEasingCurve(QEasingCurve::InOutQuad));
    seq->addAnimation(anim);
    seq->setLoopCount(-1);
    seq->start();

    addNode(tankObject());

    QGLMaterial *mat = qCreateFluid();
    m_texture = mat->texture();
    setMaterial(mat);
}
Exemple #2
0
void Creator::LogInToTest(QString user_name)
{
    testwidget->SetUserName(user_name);
    testwidget->upDateScores();

    TestWindow->show();

    QParallelAnimationGroup* parallelWindow = WindowAnimation(LogInWindow , TestWindow , LogState , TestState);
    QParallelAnimationGroup* parallelButton = ButtonAnimation(testwidget->but, 10);

    QParallelAnimationGroup* parallel = new QParallelAnimationGroup;
    parallel->addAnimation(parallelWindow);

    QSequentialAnimationGroup* sequential = new QSequentialAnimationGroup;
    sequential->addAnimation(parallel);
    sequential->addPause(0);
    sequential->addAnimation(parallelButton);

    sequential->start();
    sleep(1000);

    LogInWindow->close();
}
void ContactsViewDelegate::startAlertAnimation()
{
    if (!m_alertAnimation)
    {
        QSequentialAnimationGroup *ag = new QSequentialAnimationGroup(this);
        m_alertAnimation = ag;

        QPropertyAnimation *aIn = new QPropertyAnimation(this, "alertOpacity");
        aIn->setEndValue(qreal(1));
        aIn->setEasingCurve(QEasingCurve::OutQuad);
        aIn->setDuration(750);

        QPropertyAnimation *aOut = new QPropertyAnimation(this, "alertOpacity");
        aOut->setEndValue(qreal(0.2));
        aOut->setEasingCurve(QEasingCurve::InQuad);
        aOut->setDuration(750);

        ag->addAnimation(aIn);
        ag->addPause(150);
        ag->addAnimation(aOut);
        ag->setLoopCount(-1);
        ag->start();
    }
}
//! [0]
PadNavigator::PadNavigator(const QSize &size, QWidget *parent)
    : QGraphicsView(parent)
{
//! [0]
//! [1]
    // Splash item
    SplashItem *splash = new SplashItem;
    splash->setZValue(1);
//! [1]

//! [2]
    // Pad item
    FlippablePad *pad = new FlippablePad(size);
    QGraphicsRotation *flipRotation = new QGraphicsRotation(pad);
    QGraphicsRotation *xRotation = new QGraphicsRotation(pad);
    QGraphicsRotation *yRotation = new QGraphicsRotation(pad);
    flipRotation->setAxis(Qt::YAxis);
    xRotation->setAxis(Qt::YAxis);
    yRotation->setAxis(Qt::XAxis);
    pad->setTransformations(QList<QGraphicsTransform *>()
                            << flipRotation
                            << xRotation << yRotation);
//! [2]

//! [3]
    // Back (proxy widget) item
    QGraphicsProxyWidget *backItem = new QGraphicsProxyWidget(pad);
    QWidget *widget = new QWidget;
    form.setupUi(widget);
    form.hostName->setFocus();
    backItem->setWidget(widget);
    backItem->setVisible(false);
    backItem->setFocus();
    backItem->setCacheMode(QGraphicsItem::ItemCoordinateCache);
    const QRectF r = backItem->rect();
    backItem->setTransform(QTransform()
                           .rotate(180, Qt::YAxis)
                           .translate(-r.width()/2, -r.height()/2));
//! [3]

//! [4]
    // Selection item
    RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray, pad);
    selectionItem->setZValue(0.5);
//! [4]

//! [5]
    // Splash animations
    QPropertyAnimation *smoothSplashMove = new QPropertyAnimation(splash, "y");
    QPropertyAnimation *smoothSplashOpacity = new QPropertyAnimation(splash, "opacity");
    smoothSplashMove->setEasingCurve(QEasingCurve::InQuad);
    smoothSplashMove->setDuration(250);
    smoothSplashOpacity->setDuration(250);
//! [5]

//! [6]
    // Selection animation
    QPropertyAnimation *smoothXSelection = new QPropertyAnimation(selectionItem, "x");
    QPropertyAnimation *smoothYSelection = new QPropertyAnimation(selectionItem, "y");
    QPropertyAnimation *smoothXRotation = new QPropertyAnimation(xRotation, "angle");
    QPropertyAnimation *smoothYRotation = new QPropertyAnimation(yRotation, "angle");
    smoothXSelection->setDuration(125);
    smoothYSelection->setDuration(125);
    smoothXRotation->setDuration(125);
    smoothYRotation->setDuration(125);
    smoothXSelection->setEasingCurve(QEasingCurve::InOutQuad);
    smoothYSelection->setEasingCurve(QEasingCurve::InOutQuad);
    smoothXRotation->setEasingCurve(QEasingCurve::InOutQuad);
    smoothYRotation->setEasingCurve(QEasingCurve::InOutQuad);
//! [6]

//! [7]
    // Flip animation setup
    QPropertyAnimation *smoothFlipRotation = new QPropertyAnimation(flipRotation, "angle");
    QPropertyAnimation *smoothFlipScale = new QPropertyAnimation(pad, "scale");
    QPropertyAnimation *smoothFlipXRotation = new QPropertyAnimation(xRotation, "angle");
    QPropertyAnimation *smoothFlipYRotation = new QPropertyAnimation(yRotation, "angle");
    QParallelAnimationGroup *flipAnimation = new QParallelAnimationGroup(this);
    smoothFlipScale->setDuration(500);
    smoothFlipRotation->setDuration(500);
    smoothFlipXRotation->setDuration(500);
    smoothFlipYRotation->setDuration(500);
    smoothFlipScale->setEasingCurve(QEasingCurve::InOutQuad);
    smoothFlipRotation->setEasingCurve(QEasingCurve::InOutQuad);
    smoothFlipXRotation->setEasingCurve(QEasingCurve::InOutQuad);
    smoothFlipYRotation->setEasingCurve(QEasingCurve::InOutQuad);
    smoothFlipScale->setKeyValueAt(0, qvariant_cast<qreal>(1.0));
    smoothFlipScale->setKeyValueAt(0.5, qvariant_cast<qreal>(0.7));
    smoothFlipScale->setKeyValueAt(1, qvariant_cast<qreal>(1.0));
    flipAnimation->addAnimation(smoothFlipRotation);
    flipAnimation->addAnimation(smoothFlipScale);
    flipAnimation->addAnimation(smoothFlipXRotation);
    flipAnimation->addAnimation(smoothFlipYRotation);
//! [7]

//! [8]
    // Flip animation delayed property assignment
    QSequentialAnimationGroup *setVariablesSequence = new QSequentialAnimationGroup;
    QPropertyAnimation *setFillAnimation = new QPropertyAnimation(pad, "fill");
    QPropertyAnimation *setBackItemVisibleAnimation = new QPropertyAnimation(backItem, "visible");
    QPropertyAnimation *setSelectionItemVisibleAnimation = new QPropertyAnimation(selectionItem, "visible");
    setFillAnimation->setDuration(0);
    setBackItemVisibleAnimation->setDuration(0);
    setSelectionItemVisibleAnimation->setDuration(0);
    setVariablesSequence->addPause(250);
    setVariablesSequence->addAnimation(setBackItemVisibleAnimation);
    setVariablesSequence->addAnimation(setSelectionItemVisibleAnimation);
    setVariablesSequence->addAnimation(setFillAnimation);
    flipAnimation->addAnimation(setVariablesSequence);
//! [8]

//! [9]
    // Build the state machine
    QStateMachine *stateMachine = new QStateMachine(this);
    QState *splashState = new QState(stateMachine);
    QState *frontState = new QState(stateMachine);
    QHistoryState *historyState = new QHistoryState(frontState);
    QState *backState = new QState(stateMachine);
//! [9]
//! [10]
    frontState->assignProperty(pad, "fill", false);
    frontState->assignProperty(splash, "opacity", 0.0);
    frontState->assignProperty(backItem, "visible", false);
    frontState->assignProperty(flipRotation, "angle", qvariant_cast<qreal>(0.0));
    frontState->assignProperty(selectionItem, "visible", true);
    backState->assignProperty(pad, "fill", true);
    backState->assignProperty(backItem, "visible", true);
    backState->assignProperty(xRotation, "angle", qvariant_cast<qreal>(0.0));
    backState->assignProperty(yRotation, "angle", qvariant_cast<qreal>(0.0));
    backState->assignProperty(flipRotation, "angle", qvariant_cast<qreal>(180.0));
    backState->assignProperty(selectionItem, "visible", false);
    stateMachine->addDefaultAnimation(smoothXRotation);
    stateMachine->addDefaultAnimation(smoothYRotation);
    stateMachine->addDefaultAnimation(smoothXSelection);
    stateMachine->addDefaultAnimation(smoothYSelection);
    stateMachine->setInitialState(splashState);
//! [10]

//! [11]
    // Transitions
    QEventTransition *anyKeyTransition = new QEventTransition(this, QEvent::KeyPress, splashState);
    anyKeyTransition->setTargetState(frontState);
    anyKeyTransition->addAnimation(smoothSplashMove);
    anyKeyTransition->addAnimation(smoothSplashOpacity);
//! [11]

//! [12]
    QKeyEventTransition *enterTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                   Qt::Key_Enter, backState);
    QKeyEventTransition *returnTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                    Qt::Key_Return, backState);
    QKeyEventTransition *backEnterTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                       Qt::Key_Enter, frontState);
    QKeyEventTransition *backReturnTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                        Qt::Key_Return, frontState);
    enterTransition->setTargetState(historyState);
    returnTransition->setTargetState(historyState);
    backEnterTransition->setTargetState(backState);
    backReturnTransition->setTargetState(backState);
    enterTransition->addAnimation(flipAnimation);
    returnTransition->addAnimation(flipAnimation);
    backEnterTransition->addAnimation(flipAnimation);
    backReturnTransition->addAnimation(flipAnimation);
//! [12]

//! [13]
    // Create substates for each icon; store in temporary grid.
    int columns = size.width();
    int rows = size.height();
    QVector< QVector< QState * > > stateGrid;
    stateGrid.resize(rows);
    for (int y = 0; y < rows; ++y) {
        stateGrid[y].resize(columns);
        for (int x = 0; x < columns; ++x)
            stateGrid[y][x] = new QState(frontState);
    }
    frontState->setInitialState(stateGrid[0][0]);
    selectionItem->setPos(pad->iconAt(0, 0)->pos());
//! [13]

//! [14]
    // Enable key navigation using state transitions
    for (int y = 0; y < rows; ++y) {
        for (int x = 0; x < columns; ++x) {
            QState *state = stateGrid[y][x];
            QKeyEventTransition *rightTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                           Qt::Key_Right, state);
            QKeyEventTransition *leftTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                          Qt::Key_Left, state);
            QKeyEventTransition *downTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                          Qt::Key_Down, state);
            QKeyEventTransition *upTransition = new QKeyEventTransition(this, QEvent::KeyPress,
                                                                        Qt::Key_Up, state);
            rightTransition->setTargetState(stateGrid[y][(x + 1) % columns]);
            leftTransition->setTargetState(stateGrid[y][((x - 1) + columns) % columns]);
            downTransition->setTargetState(stateGrid[(y + 1) % rows][x]);
            upTransition->setTargetState(stateGrid[((y - 1) + rows) % rows][x]);
//! [14]
//! [15]
            RoundRectItem *icon = pad->iconAt(x, y);
            state->assignProperty(xRotation, "angle", -icon->x() / 6.0);
            state->assignProperty(yRotation, "angle", icon->y() / 6.0);
            state->assignProperty(selectionItem, "x", icon->x());
            state->assignProperty(selectionItem, "y", icon->y());
            frontState->assignProperty(icon, "visible", true);
            backState->assignProperty(icon, "visible", false);

            QPropertyAnimation *setIconVisibleAnimation = new QPropertyAnimation(icon, "visible");
            setIconVisibleAnimation->setDuration(0);
            setVariablesSequence->addAnimation(setIconVisibleAnimation);
        }
    }
//! [15]

//! [16]
    // Scene
    QGraphicsScene *scene = new QGraphicsScene(this);
    scene->setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg"));
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    scene->addItem(pad);
    scene->setSceneRect(scene->itemsBoundingRect());
    setScene(scene);
//! [16]

//! [17]
    // Adjust splash item to scene contents
    const QRectF sbr = splash->boundingRect();
    splash->setPos(-sbr.width() / 2, scene->sceneRect().top() - 2);
    frontState->assignProperty(splash, "y", splash->y() - 100.0);
    scene->addItem(splash);
//! [17]

//! [18]
    // View
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setMinimumSize(50, 50);
    setViewportUpdateMode(FullViewportUpdate);
    setCacheMode(CacheBackground);
    setRenderHints(QPainter::Antialiasing
                   | QPainter::SmoothPixmapTransform
                   | QPainter::TextAntialiasing);
#ifndef QT_NO_OPENGL
    setViewport(new QOpenGLWidget);
#endif

    stateMachine->start();
//! [18]
}
Exemple #5
0
	void init()
	{
		Q_Q(KFlipWidget);
		flipRotation = new QGraphicsRotation(q);
		xRotation = new QGraphicsRotation(q);
		yRotation = new QGraphicsRotation(q);

		flipRotation->setAxis(Qt::YAxis);
		xRotation->setAxis(Qt::YAxis);
		yRotation->setAxis(Qt::XAxis);
		q->setTransformations(QList<QGraphicsTransform *>() << flipRotation << xRotation << yRotation);

		front = new KWidget(q);
		back = new KWidget(q);

		QSizeF s = q->size();
		back->setTransform(QTransform().rotate(180, Qt::YAxis).translate(-s.width(), 0));

		smoothFlipRotation = new QPropertyAnimation(flipRotation, "angle");
		smoothFlipScale = new QPropertyAnimation(q, "scale");
		smoothFlipXRotation = new QPropertyAnimation(xRotation, "angle");
		smoothFlipYRotation = new QPropertyAnimation(yRotation, "angle");
		flipAnimation = new QParallelAnimationGroup(q);

		smoothFlipScale->setDuration(500);
		smoothFlipRotation->setDuration(500);
		smoothFlipXRotation->setDuration(500);
		smoothFlipYRotation->setDuration(500);
		smoothFlipScale->setEasingCurve(QEasingCurve::InOutQuad);
		smoothFlipRotation->setEasingCurve(QEasingCurve::InOutQuad);
		smoothFlipXRotation->setEasingCurve(QEasingCurve::InOutQuad);
		smoothFlipYRotation->setEasingCurve(QEasingCurve::InOutQuad);
		smoothFlipScale->setKeyValueAt(0, qVariantValue<qreal>(1.0));
		smoothFlipScale->setKeyValueAt(0.5, qVariantValue<qreal>(0.7));
		smoothFlipScale->setKeyValueAt(1, qVariantValue<qreal>(1.0));

		flipAnimation->addAnimation(smoothFlipRotation);
		flipAnimation->addAnimation(smoothFlipScale);
		flipAnimation->addAnimation(smoothFlipXRotation);
		flipAnimation->addAnimation(smoothFlipYRotation);


		// Flip animation delayed property assignment
		QSequentialAnimationGroup *setVariablesSequence = new QSequentialAnimationGroup;
		QPropertyAnimation *setBackItemVisibleAnimation = new QPropertyAnimation(back, "visible");
		QPropertyAnimation *setSelectionItemVisibleAnimation = new QPropertyAnimation(front, "visible");
		setBackItemVisibleAnimation->setDuration(0);
		setSelectionItemVisibleAnimation->setDuration(0);
		setVariablesSequence->addPause(250);
		setVariablesSequence->addAnimation(setBackItemVisibleAnimation);
		setVariablesSequence->addAnimation(setSelectionItemVisibleAnimation);
		flipAnimation->addAnimation(setVariablesSequence);

		// Build the state machine
		stateMachine = new QStateMachine(q);
		frontState = new QState(stateMachine);
		backState = new QState(stateMachine);

		frontState->assignProperty(back, "visible", false);
		frontState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(0.0));
		frontState->assignProperty(front, "visible", true);

		backState->assignProperty(back, "visible", true);
		backState->assignProperty(xRotation, "angle", qVariantValue<qreal>(0.0));
		backState->assignProperty(yRotation, "angle", qVariantValue<qreal>(0.0));
		backState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(180.0));
		backState->assignProperty(front, "visible", false);

		stateMachine->setInitialState(frontState);

		frontTransition = new QSignalTransition(q, SIGNAL(activeBack()), frontState);
		backTransition = new QSignalTransition(q, SIGNAL(activeFront()), backState);
		frontTransition->addAnimation(flipAnimation);
		backTransition->addAnimation(flipAnimation);
		frontTransition->setTargetState(backState);
		backTransition->setTargetState(frontState);

		bool bok = QObject::connect(flipAnimation, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), q, SLOT(on_animation_stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
		bool bok1 = QObject::connect(flipAnimation, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), q, SLOT(on_animation_stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));

		stateMachine->start();
	}