本文整理汇总了C++中QState::addTransition方法的典型用法代码示例。如果您正苦于以下问题:C++ QState::addTransition方法的具体用法?C++ QState::addTransition怎么用?C++ QState::addTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QState
的用法示例。
在下文中一共展示了QState::addTransition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initShowHideAnimation
void DockPanel::initShowHideAnimation()
{
QStateMachine * machine = new QStateMachine(this);
QState * showState = new QState(machine);
showState->assignProperty(this,"y", 0);
QState * hideState = new QState(machine);
//y should change with DockMode changed
connect(this, &DockPanel::startHide, [=]{
hideState->assignProperty(this,"y", m_dockModeData->getDockHeight());
});
machine->setInitialState(showState);
QPropertyAnimation *showAnimation = new QPropertyAnimation(this, "y");
showAnimation->setDuration(SHOW_ANIMATION_DURATION);
showAnimation->setEasingCurve(SHOW_EASINGCURVE);
connect(showAnimation,&QPropertyAnimation::finished,this,&DockPanel::onShowPanelFinished);
QPropertyAnimation *hideAnimation = new QPropertyAnimation(this, "y");
hideAnimation->setDuration(HIDE_ANIMATION_DURATION);
hideAnimation->setEasingCurve(HIDE_EASINGCURVE);
connect(hideAnimation,&QPropertyAnimation::finished,this,&DockPanel::onHidePanelFinished);
QSignalTransition *st = showState->addTransition(this,SIGNAL(startHide()), hideState);
st->addAnimation(hideAnimation);
QSignalTransition *ht = hideState->addTransition(this,SIGNAL(startShow()),showState);
ht->addAnimation(showAnimation);
machine->start();
}
示例2: setupItemAnimations
void DiscountPage::setupItemAnimations()
{
QState *smallState = new QState();
QState *bigState = new QState();
for (int i = 0; i < this->m_itemList.size(); i++) {
smallState->assignProperty(this->m_itemList[i],"scale", 0);
bigState->assignProperty(this->m_itemList[i],"scale",1);
}
QSequentialAnimationGroup *showItemGroup = new QSequentialAnimationGroup(this);
for (int i = 0; i < this->m_itemList.size(); i++) {
QPropertyAnimation *anim = new QPropertyAnimation(this->m_itemList[i], "scale", this);
anim->setDuration(300);
anim->setEasingCurve(QEasingCurve::OutBack);
showItemGroup->addAnimation(anim);
}
QSignalTransition *trans = smallState->addTransition(this, SIGNAL(start()), bigState);
trans->addAnimation(showItemGroup);
connect(showItemGroup,SIGNAL(finished()),this,SLOT(startSelect()));
trans = bigState->addTransition(this,SIGNAL(quitPage()),smallState);
connect(smallState,SIGNAL(entered()),this,SLOT(closeSelect()));
QStateMachine *states = new QStateMachine(this);
states->addState(smallState);
states->addState(bigState);
states->setInitialState(smallState);
states->start();
}
示例3: QPropertyAnimation
QGraphicsItem *CarouselGraphicsWidget::addItem(QGraphicsWidget *p)
{
scene()->addItem(p);
icons.append(p);
// Set the speed of the animation (it has to be set on the objects in the scene)
QPropertyAnimation *anim = new QPropertyAnimation(p, "geometry");
anim->setDuration(500);
animationGroup->addAnimation(anim);
QState *newState = new QState(machine);
QState *lastState = states.at(states.size()-1);
if (states.size() == 0) {
machine->setInitialState(newState);
} else {
// Link this new state to the next state
QSignalTransition *transition;
transition = lastState->addTransition(this, SIGNAL(m_next()), newState);
transition->addAnimation(animationGroup);
// Link the next state to this new state
transition = newState->addTransition(this, SIGNAL(m_back()), lastState);
transition->addAnimation(animationGroup);
}
states.append(newState);
// NB: Don't update the scene yet. See resizeEvent comment
return p;
}
示例4: setOwnedByLayout
UIGChooserItem::UIGChooserItem(UIGChooserItem *pParent, bool fTemporary)
: m_fRoot(!pParent)
, m_fTemporary(fTemporary)
, m_pParent(pParent)
, m_iPreviousMinimumWidthHint(0)
, m_iPreviousMinimumHeightHint(0)
, m_dragTokenPlace(DragToken_Off)
, m_fHovered(false)
, m_pHighlightMachine(0)
, m_pForwardAnimation(0)
, m_pBackwardAnimation(0)
, m_iAnimationDuration(400)
, m_iDefaultDarkness(100)
, m_iHighlightDarkness(90)
, m_iAnimationDarkness(m_iDefaultDarkness)
, m_iDragTokenDarkness(110)
{
/* Basic item setup: */
setOwnedByLayout(false);
setAcceptDrops(true);
setFocusPolicy(Qt::NoFocus);
setFlag(QGraphicsItem::ItemIsSelectable, false);
setAcceptHoverEvents(!isRoot());
/* Non-root item? */
if (!isRoot())
{
/* Create state machine: */
m_pHighlightMachine = new QStateMachine(this);
/* Create 'default' state: */
QState *pStateDefault = new QState(m_pHighlightMachine);
/* Create 'highlighted' state: */
QState *pStateHighlighted = new QState(m_pHighlightMachine);
/* Forward animation: */
m_pForwardAnimation = new QPropertyAnimation(this, "animationDarkness", this);
m_pForwardAnimation->setDuration(m_iAnimationDuration);
m_pForwardAnimation->setStartValue(m_iDefaultDarkness);
m_pForwardAnimation->setEndValue(m_iHighlightDarkness);
/* Backward animation: */
m_pBackwardAnimation = new QPropertyAnimation(this, "animationDarkness", this);
m_pBackwardAnimation->setDuration(m_iAnimationDuration);
m_pBackwardAnimation->setStartValue(m_iHighlightDarkness);
m_pBackwardAnimation->setEndValue(m_iDefaultDarkness);
/* Add state transitions: */
QSignalTransition *pDefaultToHighlighted = pStateDefault->addTransition(this, SIGNAL(sigHoverEnter()), pStateHighlighted);
pDefaultToHighlighted->addAnimation(m_pForwardAnimation);
QSignalTransition *pHighlightedToDefault = pStateHighlighted->addTransition(this, SIGNAL(sigHoverLeave()), pStateDefault);
pHighlightedToDefault->addAnimation(m_pBackwardAnimation);
/* Initial state is 'default': */
m_pHighlightMachine->setInitialState(pStateDefault);
/* Start state-machine: */
m_pHighlightMachine->start();
}
}
示例5: Foo
explicit Foo(QObject * parent = 0) :
QObject(parent),
m_state1(&m_stateMachine),
m_state2(&m_stateMachine)
{
m_stateMachine.setInitialState(&m_state1);
m_state1.addTransition(this, SIGNAL(sigGoToStateTwo()), &m_state2);
m_state2.addTransition(this, SIGNAL(sigGoToStateOne()), &m_state1);
}
示例6: main
//! [3]
Q_DECL_EXPORT int main(int argc, char **argv)
{
Application app(argc, argv);
Factorial factorial;
// Create the state machine
QStateMachine machine;
//! [3]
//! [4]
// Create the 'compute' state as child of the state machine
QState *compute = new QState(&machine);
// Initialize the 'fac', 'x' and 'xorig' properties of the Factorial object whenever the compute state is entered
compute->assignProperty(&factorial, "fac", 1);
compute->assignProperty(&factorial, "x", 6);
compute->assignProperty(&factorial, "xorig", 6);
/**
* Add the custom transition to the compute state.
* Note: This transition has the compute state as source and target state.
*/
compute->addTransition(new FactorialLoopTransition(&factorial));
//! [4]
//! [5]
// Create a final state
QFinalState *done = new QFinalState(&machine);
// Add a custom transition with the 'compute' state as source state and the 'done' state as target state
FactorialDoneTransition *doneTransition = new FactorialDoneTransition(&factorial);
doneTransition->setTargetState(done);
compute->addTransition(doneTransition);
//! [5]
//! [6]
// Set the 'compute' state as initial state of the state machine
machine.setInitialState(compute);
// Load the UI description from main.qml
QmlDocument *qml = QmlDocument::create("asset:///main.qml");
// Make the Factorial and StateMachine object available to the UI as context properties
qml->setContextProperty("_factorial", &factorial);
qml->setContextProperty("_machine", &machine);
// Create the application scene
AbstractPane *appPage = qml->createRootObject<AbstractPane>();
Application::instance()->setScene(appPage);
return Application::exec();
}
示例7: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
stateMachine(new QStateMachine(this)),
lastSelectDir(OP_DIR)
{
ui->setupUi(this);
ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
//Setting states
QState *runningState = new QState();
QState *stopState = new QState();
stopState->addTransition(this,SIGNAL(started()),runningState);
runningState->addTransition(this,SIGNAL(finished()),stopState);
runningState->assignProperty(ui->addButton,"enabled","false");
runningState->assignProperty(ui->clearAllButton,"enabled","false");
runningState->assignProperty(ui->removeButton,"enabled","false");
stopState->assignProperty(ui->addButton,"enabled","true");
stopState->assignProperty(ui->clearAllButton,"enabled","true");
stopState->assignProperty(ui->removeButton,"enabled","true");
connect(runningState,&QState::entered,[&]{
qDebug()<<QTime::currentTime()<<"start convert";
});
connect(runningState,&QState::exited,[&]{
qDebug()<<QTime::currentTime()<<"stop convert";
});
connect(runningState,&QState::exited,[&]{
ui->progressBar->setValue(100);
QMessageBox::information(
this,
tr("Nook HD+ Manga Converter"),
tr("All job completed!") );
});
stateMachine->addState(stopState);
stateMachine->addState(runningState);
stateMachine->setInitialState(stopState);
connect(ui->convertButton,&QPushButton::clicked,this,&MainWindow::convert);
connect(ui->addButton,&QPushButton::clicked,this,&MainWindow::addBook);
connect(ui->clearAllButton,&QPushButton::clicked,ui->listWidget,&QListWidget::clear);
connect(ui->removeButton,&QPushButton::clicked,[&]{qDeleteAll(ui->listWidget->selectedItems());});
connect(this,&MainWindow::completed,ui->progressBar,&QProgressBar::setValue);
stateMachine->start();
}
示例8: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString n = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
ipValidator = new QRegExpValidator(QRegExp("^" + n + "\\." + n + "\\." + n + "\\." + n + "$"));
intValidator = new QRegExpValidator(QRegExp("[0-9]+"));
hexValidator = new QRegExpValidator(QRegExp("[0-9a-fA-F]+"));
base64Validator = new QRegExpValidator(QRegExp("^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$"));
setIpValidator();
machine = new QStateMachine(this);
QState *ipToInt = new QState();
QState *intToHex = new QState();
QState *hexToBase64 = new QState();
QState *base64ToHex = new QState();
QState *hexToInt = new QState();
QState *intToIp = new QState();
ipToInt->addTransition(ui->pushButton, SIGNAL(clicked()), intToHex);
intToHex->addTransition(ui->pushButton, SIGNAL(clicked()), hexToBase64);
hexToBase64->addTransition(ui->pushButton, SIGNAL(clicked()), base64ToHex);
base64ToHex->addTransition(ui->pushButton, SIGNAL(clicked()), hexToInt);
hexToInt->addTransition(ui->pushButton, SIGNAL(clicked()), intToIp);
intToIp->addTransition(ui->pushButton, SIGNAL(clicked()), ipToInt);
QObject::connect(ipToInt, SIGNAL(exited()), this, SLOT(convertIpToInt()));
QObject::connect(intToHex, SIGNAL(exited()), this, SLOT(convertIntToHex()));
QObject::connect(hexToBase64, SIGNAL(exited()), this, SLOT(convertHexToBase64()));
QObject::connect(base64ToHex, SIGNAL(exited()), this, SLOT(convertBase64ToHex()));
QObject::connect(hexToInt, SIGNAL(exited()), this, SLOT(convertHexToInt()));
QObject::connect(intToIp, SIGNAL(exited()), this, SLOT(convertIntToIp()));
machine->addState(ipToInt);
machine->addState(intToHex);
machine->addState(hexToBase64);
machine->addState(base64ToHex);
machine->addState(hexToInt);
machine->addState(intToIp);
machine->setInitialState(ipToInt);
machine->start();
}
示例9: initialize
bool AbstractTransition::initialize() {
logger->info(QString("%1 initialize").arg(toString()));
if (sourceState == NULL) {
logger->warning(QString("%1 transition initialization failed: couldn't find source state \"%2\"").arg(toString()).arg(sourceStateId));
return false;
}
if (targetState == NULL) {
logger->warning(QString("%1 transition initialization failed: couldn't find target state \"%2\"").arg(toString()).arg(targetStateId));
return false;
}
// cast abstract state
QState* state = dynamic_cast<QState*>(sourceState->getDelegate());
if (state == NULL) {
logger->warning(QString("%1 transition initialization failed: source delegate is not of type QState").arg(toString()));
return false;
}
logger->info(QString("%1 add transition from \"%2\" to \"%3\"").arg(toString()).arg(sourceState->getId()).arg(targetState->getId()));
setTargetState(targetState->getDelegate());
state->addTransition(this);
return true;
}
示例10: main
//! [4]
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QStateMachine machine;
QState *group = new QState(QState::ParallelStates);
group->setObjectName("group");
//! [4]
//! [5]
Pinger *pinger = new Pinger(group);
pinger->setObjectName("pinger");
pinger->addTransition(new PongTransition());
QState *ponger = new QState(group);
ponger->setObjectName("ponger");
ponger->addTransition(new PingTransition());
//! [5]
//! [6]
machine.addState(group);
machine.setInitialState(group);
machine.start();
return app.exec();
}
示例11: UIGraphicsButton
UIGraphicsZoomButton::UIGraphicsZoomButton(QIGraphicsWidget *pParent, const QIcon &icon, int iDirection)
: UIGraphicsButton(pParent, icon)
, m_iIndent(4)
, m_iDirection(iDirection)
, m_iAnimationDuration(200)
, m_pStateMachine(0)
, m_pForwardAnimation(0)
, m_pBackwardAnimation(0)
, m_fStateDefault(true)
{
/* Setup: */
setAcceptHoverEvents(true);
/* Create state machine: */
m_pStateMachine = new QStateMachine(this);
/* Create 'default' state: */
QState *pStateDefault = new QState(m_pStateMachine);
pStateDefault->assignProperty(this, "stateDefault", true);
/* Create 'zoomed' state: */
QState *pStateZoomed = new QState(m_pStateMachine);
pStateZoomed->assignProperty(this, "stateDefault", false);
/* Initial state is 'default': */
m_pStateMachine->setInitialState(pStateDefault);
/* Zoom animation: */
m_pForwardAnimation = new QPropertyAnimation(this, "geometry", this);
m_pForwardAnimation->setDuration(m_iAnimationDuration);
/* Unzoom animation: */
m_pBackwardAnimation = new QPropertyAnimation(this, "geometry", this);
m_pBackwardAnimation->setDuration(m_iAnimationDuration);
/* Add state transitions: */
QSignalTransition *pDefaultToZoomed = pStateDefault->addTransition(this, SIGNAL(sigHoverEnter()), pStateZoomed);
pDefaultToZoomed->addAnimation(m_pForwardAnimation);
QSignalTransition *pZoomedToDefault = pStateZoomed->addTransition(this, SIGNAL(sigHoverLeave()), pStateDefault);
pZoomedToDefault->addAnimation(m_pBackwardAnimation);
/* Start state-machine: */
m_pStateMachine->start();
}
示例12: main
//! [0]
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPushButton button;
QStateMachine machine;
//! [0]
//! [1]
QState *off = new QState();
off->assignProperty(&button, "text", "Off");
off->setObjectName("off");
QState *on = new QState();
on->setObjectName("on");
on->assignProperty(&button, "text", "On");
//! [1]
//! [2]
off->addTransition(&button, SIGNAL(clicked()), on);
on->addTransition(&button, SIGNAL(clicked()), off);
//! [2]
//! [3]
machine.addState(off);
machine.addState(on);
//! [3]
//! [4]
machine.setInitialState(off);
machine.start();
//! [4]
//! [5]
#if defined(Q_OS_SYMBIAN)
button.showMaximized();
#elif defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
button.show();
#else
button.resize(100, 50);
button.show();
#endif
return app.exec();
}
示例13: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// Загружаем интерфейс пользователя из формы и устанавливаем действия в меню
ui->setupUi(this);
connect(ui->action_start, SIGNAL(triggered()), ui->startButton, SLOT(click()));
connect(ui->action_exit, SIGNAL(triggered()), this, SLOT(close()));
connect(ui->action_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
connect(ui->action_help, SIGNAL(triggered()), this, SLOT(showHelp()));
connect(ui->action_about, SIGNAL(triggered()), this, SLOT(showAbout()));
connect(ui->action_tech, SIGNAL(triggered()), this, SLOT(showTz()));
// Заводим машину состояний
QStateMachine *animation = new QStateMachine(this);
QState *idle = new QState();
QState *animating = new QState();
animating->assignProperty(ui->startButton,"text", tr("&Стоп"));
animating->assignProperty(ui->startButton,"icon", QIcon(":/icons/control-stop-square.png"));
animating->assignProperty(ui->action_start,"text",tr("О&становить анимацию"));
animating->assignProperty(ui->action_start,"icon", QIcon(":/icons/control-stop-square.png"));
idle->assignProperty(ui->startButton,"text", tr("Пу&ск"));
idle->assignProperty(ui->startButton,"icon", QIcon(":/icons/control.png"));
idle->assignProperty(ui->action_start,"text",tr("Запу&стить анимацию"));
idle->assignProperty(ui->action_start,"icon", QIcon(":/icons/control.png"));
QSignalTransition *startTransition = new QSignalTransition(ui->startButton, SIGNAL(clicked()), idle);
startTransition->setTargetState(animating);
QSignalTransition *stopTransition = new QSignalTransition(ui->startButton, SIGNAL(clicked()), animating);
stopTransition->setTargetState(idle);
QSignalTransition *doneTransition = new QSignalTransition(ui->widget, SIGNAL(animationStopped()), animating);
doneTransition->setTargetState(idle);
connect(startTransition, SIGNAL(triggered()), ui->widget, SLOT(startAnimation()));
connect(stopTransition, SIGNAL(triggered()), ui->widget, SLOT(stopAnimation()));
idle->addTransition(startTransition);
animating->addTransition(stopTransition);
animating->addTransition(doneTransition);
animation->addState(idle);
animation->addState(animating);
animation->setInitialState(idle);
animation->start();
// В Linux мячик иногда сразу не отображается...
ui->widget->updateGL();
}
示例14: prepareElement
void UIGDetailsElement::prepareElement()
{
/* Initialization: */
m_nameFont = font();
m_nameFont.setWeight(QFont::Bold);
m_textFont = font();
/* Create highlight machine: */
m_pHighlightMachine = new QStateMachine(this);
/* Create 'default' state: */
QState *pStateDefault = new QState(m_pHighlightMachine);
/* Create 'highlighted' state: */
QState *pStateHighlighted = new QState(m_pHighlightMachine);
/* Forward animation: */
m_pForwardAnimation = new QPropertyAnimation(this, "animationDarkness", this);
m_pForwardAnimation->setDuration(m_iAnimationDuration);
m_pForwardAnimation->setStartValue(m_iDefaultDarkness);
m_pForwardAnimation->setEndValue(m_iHighlightDarkness);
/* Backward animation: */
m_pBackwardAnimation = new QPropertyAnimation(this, "animationDarkness", this);
m_pBackwardAnimation->setDuration(m_iAnimationDuration);
m_pBackwardAnimation->setStartValue(m_iHighlightDarkness);
m_pBackwardAnimation->setEndValue(m_iDefaultDarkness);
/* Add state transitions: */
QSignalTransition *pDefaultToHighlighted = pStateDefault->addTransition(this, SIGNAL(sigHoverEnter()), pStateHighlighted);
pDefaultToHighlighted->addAnimation(m_pForwardAnimation);
QSignalTransition *pHighlightedToDefault = pStateHighlighted->addTransition(this, SIGNAL(sigHoverLeave()), pStateDefault);
pHighlightedToDefault->addAnimation(m_pBackwardAnimation);
/* Initial state is 'default': */
m_pHighlightMachine->setInitialState(pStateDefault);
/* Start state-machine: */
m_pHighlightMachine->start();
connect(this, SIGNAL(sigToggleElement(DetailsElementType, bool)), model(), SLOT(sltToggleElements(DetailsElementType, bool)));
connect(this, SIGNAL(sigLinkClicked(const QString&, const QString&, const QString&)),
model(), SIGNAL(sigLinkClicked(const QString&, const QString&, const QString&)));
}
示例15: main
//! [0]
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QPushButton button;
QStateMachine machine;
//! [0]
//! [1]
QState *off = new QState();
off->assignProperty(&button, "text", "Off");
off->setObjectName("off");
QState *on = new QState();
on->setObjectName("on");
on->assignProperty(&button, "text", "On");
//! [1]
//! [2]
off->addTransition(&button, SIGNAL(clicked()), on);
on->addTransition(&button, SIGNAL(clicked()), off);
//! [2]
//! [3]
machine.addState(off);
machine.addState(on);
//! [3]
//! [4]
machine.setInitialState(off);
machine.start();
//! [4]
//! [5]
button.resize(100, 50);
button.show();
return app.exec();
}