本文整理汇总了C++中QStateMachine::addDefaultAnimation方法的典型用法代码示例。如果您正苦于以下问题:C++ QStateMachine::addDefaultAnimation方法的具体用法?C++ QStateMachine::addDefaultAnimation怎么用?C++ QStateMachine::addDefaultAnimation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStateMachine
的用法示例。
在下文中一共展示了QStateMachine::addDefaultAnimation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
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();
}
示例2: QGraphicsView
//.........这里部分代码省略.........
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]
示例3: size
PadNavigator::PadNavigator( QWidget *parent)
: QGraphicsView(parent)
{
QSize size(6,2);
// Pad item
this->pad = new FlippablePad(size);
// Selection item
RoundRectItem *selectionItem = new RoundRectItem(QRectF(-110, -110, 220, 220),
Qt::gray, pad);
selectionItem->setZValue(0.5);
// Selection animation
QPropertyAnimation *smoothXSelection = new QPropertyAnimation(selectionItem, "x");
QPropertyAnimation *smoothYSelection = new QPropertyAnimation(selectionItem, "y");
smoothXSelection->setDuration(100);
smoothYSelection->setDuration(100);
smoothXSelection->setEasingCurve(QEasingCurve::InCurve);
smoothYSelection->setEasingCurve(QEasingCurve::InCurve);
// Build the state machine
QStateMachine *stateMachine = new QStateMachine(this);
QState *frontState = new QState(stateMachine);
frontState->assignProperty(pad, "fill", false);
frontState->assignProperty(selectionItem, "visible", true);
stateMachine->addDefaultAnimation(smoothXSelection);
stateMachine->addDefaultAnimation(smoothYSelection);
stateMachine->setInitialState(frontState);
// 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());
// 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]);
RoundRectItem *icon = pad->iconAt(x, y);
state->assignProperty(selectionItem, "x", icon->x());
state->assignProperty(selectionItem, "y", icon->y());
}
}
// Scene
QGraphicsScene *scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->addItem(pad);
scene->setSceneRect(scene->itemsBoundingRect());
setScene(scene);
// View
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setMinimumSize(50, 50);
setCacheMode(CacheBackground);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
stateMachine->start();
}