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; }
QStateMachine *QAbstractTransitionPrivate::machine() const { QState *source = sourceState(); if (!source) return 0; return source->machine(); }
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; }
void IoModule::logic_init_lamp_machinestat() { pMachine = new QStateMachine(this); m_pTimer = new QTimer(this); m_pTimer->setSingleShot(true); QState *pInitS = new QState(); QState *pInitS1 = new QState(pInitS); QState *pInitS2 = new QState(pInitS); QState *pInitS3 = new QState(pInitS); QState *pInitS4 = new QState(pInitS); pInitS->setInitialState(pInitS1); pInitS1->addTransition(m_pTimer, SIGNAL(timeout()), pInitS2); pInitS2->addTransition(m_pTimer, SIGNAL(timeout()), pInitS3); pInitS3->addTransition(m_pTimer, SIGNAL(timeout()), pInitS4); pInitS4->addTransition(this, SIGNAL(resetMachine()), pInitS1); QState *pOperationS = new QState(); //pInitS->addTransition(this, SIGNAL(initLampSuccess()),pOperationS); pMachine->addState(pInitS);//³õʼ»¯×´Ì¬; pMachine->addState(pOperationS);//²Ù×÷״̬; pMachine->setInitialState(pInitS); connect(pInitS1, SIGNAL(entered()), this, SLOT(init_s1())); connect(pInitS2, SIGNAL(entered()), this, SLOT(init_s2())); connect(pInitS3, SIGNAL(entered()), this, SLOT(init_s3())); connect(pInitS4, SIGNAL(entered()), this, SLOT(init_s4())); connect(pOperationS, SIGNAL(entered()), this, SLOT(operation_s())); }
//! [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(); }
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(); } }
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); }
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(); }
CreateTool::CreateTool(CurveStateMachine &sm): EditionTool{sm} { this->setObjectName("CreateTool"); localSM().setObjectName("CreateToolLocalSM"); QState* waitState = new QState{&localSM()}; waitState->setObjectName("WaitState"); auto co = new CreatePointCommandObject(&sm.presenter(), sm.commandStack()); auto state = new OngoingState(*co, &localSM()); state->setObjectName("CreatePointFromNothingState"); make_transition<ClickOnSegment_Transition>(waitState, state, *state); make_transition<ClickOnNothing_Transition>(waitState, state, *state); state->addTransition(state, SIGNAL(finished()), waitState); localSM().setInitialState(waitState); localSM().start(); }
void ViewMachine::setup(LayoutUpdater *updater) { if (not updater) { qCritical() << __PRETTY_FUNCTION__ << "No updater specified. Aborting setup."; return; } setChildMode(QState::ExclusiveStates); QState *main = 0; QState *symbols0 = 0; QState *symbols1 = 0; // addState makes state machine to be a parent of passed state, // so we don't have to care about deleting states explicitly. addState(main = new QState); addState(symbols0 = new QState); addState(symbols1 = new QState); setInitialState(main); main->setObjectName(main_state); symbols0->setObjectName(symbols0_state); symbols1->setObjectName(symbols1_state); main->addTransition(updater, SIGNAL(symKeyReleased()), symbols0); connect(main, SIGNAL(entered()), updater, SLOT(switchToMainView())); symbols0->addTransition(updater, SIGNAL(symKeyReleased()), main); symbols0->addTransition(updater, SIGNAL(symSwitcherReleased()), symbols1); connect(symbols0, SIGNAL(entered()), updater, SLOT(switchToPrimarySymView())); symbols1->addTransition(updater, SIGNAL(symKeyReleased()), main); symbols1->addTransition(updater, SIGNAL(symSwitcherReleased()), symbols0); connect(symbols1, SIGNAL(entered()), updater, SLOT(switchToSecondarySymView())); // Defer to first main loop iteration: QTimer::singleShot(0, this, SLOT(start())); }
void onStateExited() { QState *state = qobject_cast<QState*>(sender()); switch (state->property("type").toInt()) { case Normal: { int idx = rand() % d.frames.size(); while (d.frames.at(idx)->status != Frame::Hidden) { if (++idx == d.frames.size()) idx = 0; } Q_ASSERT(!d.currentFrame); d.currentFrame = d.frames.at(idx); Q_ASSERT(d.currentFrame->status == Frame::Hidden); --d.framesLeft; break; } default: break; } // qDebug() << sender()->objectName() << "exited"; }
/* * InvokeState */ InvokeState::InvokeState(const QString& stateId, const QString& binding, const QString& parentStateId) : AbstractComplexState(stateId, parentStateId), binding(binding), communicationPlugin(Application::getInstance()->getCommunicationPluginLoader().getCommunicationPlugin(binding)), invocationActive(false) { if (communicationPlugin != NULL) { communicationPlugin->successCallback = std::bind(&InvokeState::success, this, std::placeholders::_1); communicationPlugin->errorCallback = std::bind(&InvokeState::error, this, std::placeholders::_1); } QState* stateInvoke = new QState(delegate); QFinalState* stateFinal = new QFinalState(delegate); InternalTransition* transitionFinal = new InternalTransition("done." + uuid); transitionFinal->setTargetState(stateFinal); stateInvoke->addTransition(transitionFinal); delegate->setInitialState(stateInvoke); endpoint = Value::Object(); }
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&))); }
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(); }
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(); }
QStateMachine* UIAnimationFramework::installPropertyAnimation(QWidget *pTarget, const char *pszPropertyName, const char *pszValuePropertyNameStart, const char *pszValuePropertyNameFinal, const char *pSignalForward, const char *pSignalBackward, bool fReversive /*= false*/, int iAnimationDuration /*= 300*/) { /* State-machine: */ QStateMachine *pStateMachine = new QStateMachine(pTarget); /* State-machine 'start' state: */ QState *pStateStart = new QState(pStateMachine); /* State-machine 'final' state: */ QState *pStateFinal = new QState(pStateMachine); /* State-machine 'forward' animation: */ QPropertyAnimation *pForwardAnimation = new QPropertyAnimation(pTarget, pszPropertyName, pStateMachine); pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic)); pForwardAnimation->setDuration(iAnimationDuration); pForwardAnimation->setStartValue(pTarget->property(pszValuePropertyNameStart)); pForwardAnimation->setEndValue(pTarget->property(pszValuePropertyNameFinal)); /* State-machine 'backward' animation: */ QPropertyAnimation *pBackwardAnimation = new QPropertyAnimation(pTarget, pszPropertyName, pStateMachine); pBackwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic)); pBackwardAnimation->setDuration(iAnimationDuration); pBackwardAnimation->setStartValue(pTarget->property(pszValuePropertyNameFinal)); pBackwardAnimation->setEndValue(pTarget->property(pszValuePropertyNameStart)); /* State-machine state transitions: */ QSignalTransition *pDefaultToHovered = pStateStart->addTransition(pTarget, pSignalForward, pStateFinal); pDefaultToHovered->addAnimation(pForwardAnimation); QSignalTransition *pHoveredToDefault = pStateFinal->addTransition(pTarget, pSignalBackward, pStateStart); pHoveredToDefault->addAnimation(pBackwardAnimation); /* Initial state is 'start': */ pStateMachine->setInitialState(!fReversive ? pStateStart : pStateFinal); /* Start hover-machine: */ pStateMachine->start(); /* Return machine: */ return pStateMachine; }
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(); }
Rect::Rect(QGraphicsItem *parent) : m_x(0), m_y(0), QGraphicsRectItem(parent) { this->setRect(m_x, m_y, 100, 100); this->setAcceptDrops(true); QObject::connect(this, SIGNAL(rectChange()), this, SLOT(slRectChange())); this->m_rectUpAn = new QPropertyAnimation(this, "rect"); // the animation will change rect and emit rectChange signal this->m_rectDownAn = new QPropertyAnimation(this, "rect"); this->m_rectUpAn->setDuration(150); this->m_rectUpAn->setStartValue(this->rect()); // animation start point this->m_rectUpAn->setKeyValueAt(0.7, QRectF(-6, -6, 120, 120)); // animation end point this->m_rectUpAn->setEndValue(QRectF(-3, -3, 110, 110)); this->m_rectDownAn->setDuration(150);; this->m_rectDownAn->setStartValue(this->rect()); this->m_rectDownAn->setEndValue(QRectF(0, 0, 100, 100)); this->m_mainStatus = new QStateMachine(this); QState *rectDragStart = new QState(this->m_mainStatus); QState *rectDragEnd = new QState(this->m_mainStatus); QSignalTransition *transition = rectDragStart->addTransition(this, SIGNAL(rectDragStart()), rectDragEnd); transition->addAnimation(this->m_rectUpAn); transition = rectDragEnd->addTransition(this, SIGNAL(rectDragEnd()), rectDragStart); transition->addAnimation(this->m_rectDownAn); this->m_mainStatus->addState(rectDragStart); this->m_mainStatus->addState(rectDragEnd); this->m_mainStatus->setInitialState(rectDragStart); this->m_mainStatus->start(); this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true); this->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); }
//! [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(); }
//! [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(); }
//! [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(); }
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(); }
ExampleView::ExampleView(QWidget* parent) : QFrame(parent) { _score = 0; setAcceptDrops(true); setFocusPolicy(Qt::StrongFocus); resetMatrix(); _fgPixmap = nullptr; if (preferences.getBool(PREF_UI_CANVAS_FG_USECOLOR)) _fgColor = preferences.getColor(PREF_UI_CANVAS_FG_COLOR); else { _fgPixmap = new QPixmap(preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER)); if (_fgPixmap == 0 || _fgPixmap->isNull()) qDebug("no valid pixmap %s", qPrintable(preferences.getString(PREF_UI_CANVAS_FG_WALLPAPER))); } // setup drag canvas state sm = new QStateMachine(this); QState* stateActive = new QState; QState* s1 = new QState(stateActive); s1->setObjectName("example-normal"); s1->assignProperty(this, "cursor", QCursor(Qt::ArrowCursor)); QState* s = new QState(stateActive); s->setObjectName("example-drag"); s->assignProperty(this, "cursor", QCursor(Qt::SizeAllCursor)); QEventTransition* cl = new QEventTransition(this, QEvent::MouseButtonRelease); cl->setTargetState(s1); s->addTransition(cl); s1->addTransition(new DragTransitionExampleView(this)); sm->addState(stateActive); stateActive->setInitialState(s1); sm->setInitialState(stateActive); sm->start(); }
UIGraphicsRotatorButton::UIGraphicsRotatorButton(QIGraphicsWidget *pParent, const QString &strPropertyName, bool fToggled, bool fReflected /* = false */, int iAnimationDuration /* = 300 */) : UIGraphicsButton(pParent, UIIconPool::iconSet(":/expanding_collapsing_16px.png")) , m_fReflected(fReflected) , m_state(fToggled ? UIGraphicsRotatorButtonState_Rotated : UIGraphicsRotatorButtonState_Default) , m_pAnimationMachine(0) , m_iAnimationDuration(iAnimationDuration) , m_pForwardButtonAnimation(0) , m_pBackwardButtonAnimation(0) , m_pForwardSubordinateAnimation(0) , m_pBackwardSubordinateAnimation(0) { /* Configure: */ setAutoHandleButtonClick(true); /* Create state machine: */ m_pAnimationMachine = new QStateMachine(this); /* Create 'default' state: */ QState *pStateDefault = new QState(m_pAnimationMachine); pStateDefault->assignProperty(this, "state", QVariant::fromValue(UIGraphicsRotatorButtonState_Default)); pStateDefault->assignProperty(this, "rotation", m_fReflected ? 180 : 0); /* Create 'animating' state: */ QState *pStateAnimating = new QState(m_pAnimationMachine); pStateAnimating->assignProperty(this, "state", QVariant::fromValue(UIGraphicsRotatorButtonState_Animating)); /* Create 'rotated' state: */ QState *pStateRotated = new QState(m_pAnimationMachine); pStateRotated->assignProperty(this, "state", QVariant::fromValue(UIGraphicsRotatorButtonState_Rotated)); pStateRotated->assignProperty(this, "rotation", 90); /* Forward button animation: */ m_pForwardButtonAnimation = new QPropertyAnimation(this, "rotation", this); m_pForwardButtonAnimation->setDuration(m_iAnimationDuration); m_pForwardButtonAnimation->setStartValue(m_fReflected ? 180 : 0); m_pForwardButtonAnimation->setEndValue(90); /* Backward button animation: */ m_pBackwardButtonAnimation = new QPropertyAnimation(this, "rotation", this); m_pBackwardButtonAnimation->setDuration(m_iAnimationDuration); m_pBackwardButtonAnimation->setStartValue(90); m_pBackwardButtonAnimation->setEndValue(m_fReflected ? 180 : 0); /* Forward subordinate animation: */ m_pForwardSubordinateAnimation = new QPropertyAnimation(pParent, strPropertyName.toLatin1(), this); m_pForwardSubordinateAnimation->setDuration(m_iAnimationDuration); m_pForwardSubordinateAnimation->setEasingCurve(QEasingCurve::InCubic); /* Backward subordinate animation: */ m_pBackwardSubordinateAnimation = new QPropertyAnimation(pParent, strPropertyName.toLatin1(), this); m_pBackwardSubordinateAnimation->setDuration(m_iAnimationDuration); m_pBackwardSubordinateAnimation->setEasingCurve(QEasingCurve::InCubic); /* Default => Animating: */ QSignalTransition *pDefaultToAnimating = pStateDefault->addTransition(this, SIGNAL(sigToAnimating()), pStateAnimating); pDefaultToAnimating->addAnimation(m_pForwardButtonAnimation); pDefaultToAnimating->addAnimation(m_pForwardSubordinateAnimation); /* Animating => Rotated: */ connect(m_pForwardButtonAnimation, SIGNAL(finished()), this, SIGNAL(sigToRotated()), Qt::QueuedConnection); pStateAnimating->addTransition(this, SIGNAL(sigToRotated()), pStateRotated); /* Rotated => Animating: */ QSignalTransition *pRotatedToAnimating = pStateRotated->addTransition(this, SIGNAL(sigToAnimating()), pStateAnimating); pRotatedToAnimating->addAnimation(m_pBackwardButtonAnimation); pRotatedToAnimating->addAnimation(m_pBackwardSubordinateAnimation); /* Animating => Default: */ connect(m_pBackwardButtonAnimation, SIGNAL(finished()), this, SIGNAL(sigToDefault()), Qt::QueuedConnection); pStateAnimating->addTransition(this, SIGNAL(sigToDefault()), pStateDefault); /* Default => Rotated: */ pStateDefault->addTransition(this, SIGNAL(sigToRotated()), pStateRotated); /* Rotated => Default: */ pStateRotated->addTransition(this, SIGNAL(sigToDefault()), pStateDefault); /* Initial state is 'default': */ m_pAnimationMachine->setInitialState(!fToggled ? pStateDefault : pStateRotated); /* Start state-machine: */ m_pAnimationMachine->start(); /* Refresh: */ refresh(); }
//! [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] }
QState* createFSMState(const QString& stateName,QState * parent) { QState *result = new QState(parent); result->setObjectName(stateName); return result; }
//helper static QState* createState(QString name, QState *parent=0) { QState *result = new QState(parent); result->setObjectName(name); return result; }
// NB: resizeEvent should just change the positions & sizes. However, // moving the first to last state transitions every time an item is // added is a pain. This means that setGeometry on this widget must // only be called after all items have been added. void CarouselGraphicsWidget::resizeEvent(QResizeEvent *event) { QSize size = event->size(); // TODO view changes size, should we really be changeing the scene size? scene()->setSceneRect(0, 0, size.width(), size.height()); // Use icons with same aspect ratio as VGA. int tw = size.width(); int th = size.height(); if (tw > th*640/480) tw = th*640/480; if (th > tw*480/640) th = tw*480/640; int iw = tw / 2; int ih = th / 2; int isw = tw * 3 / 16; int ish = th * 3 / 16; int w = (size.width() - iw/2 - isw/2) / 2; int h = (size.height() - ih/2 - ish/2) / 2; int cx = size.width()/2; int cy = (size.height() - ish)/2; int num_objects = icons.size(); for (int i=0; i<num_objects; ++i) { float angle = 2.0*PI*i / num_objects; QRect r; // When the icon is at the bottom of the screen (i=0), make it larger. // Though it would look nicer if the size was based on the 'depth', this // would involve a lot of scaling and then likely hit performance. if (i == 0) r.setRect(-iw/2, -ih/2, iw, ih); else r.setRect(-isw/2, -ish/2, isw, ish); r.translate(cx, cy); r.translate(w*sin(angle), h*cos(angle)); for (int j=0; j<num_objects; ++j) { QState *state = states.at((i+j) % num_objects); QObject *o = icons.at((num_objects-j) % num_objects); // Set the position & make only the item at the bottom // of the widget clickable state->assignProperty(o, "geometry", r); state->assignProperty(o, "enabled", i==0); state->assignProperty(o, "focus", i==0); } } if (states.size() > 1) { QSignalTransition *transition; QState *firstState = states.at(0); QState *lastState = states.at(states.size()-1); // Link to the next state - special case transition = lastState->addTransition(this, SIGNAL(m_next()), firstState); transition->addAnimation(animationGroup); // Link to the previous state - special case transition = firstState->addTransition(this, SIGNAL(m_back()), lastState); transition->addAnimation(animationGroup); machine->start(); } }
Creation_FromState::Creation_FromState( const ToolPalette& stateMachine, const Path<ScenarioModel>& scenarioPath, iscore::CommandStack& stack, QState* parent): CreationState{stateMachine, stack, std::move(scenarioPath), parent} { using namespace Scenario::Command; auto finalState = new QFinalState{this}; connect(finalState, &QState::entered, [&] () { clearCreatedIds(); }); QState* mainState = new QState{this}; { auto pressed = new QState{mainState}; auto released = new QState{mainState}; auto move_nothing = new StrongQState<ScenarioElement::Nothing + Modifier::Move_tag::value>{mainState}; auto move_state = new StrongQState<ScenarioElement::State + Modifier::Move_tag::value>{mainState}; auto move_event = new StrongQState<ScenarioElement::Event + Modifier::Move_tag::value>{mainState}; auto move_timenode = new StrongQState<ScenarioElement::TimeNode + Modifier::Move_tag::value>{mainState}; // General setup mainState->setInitialState(pressed); released->addTransition(finalState); // Release make_transition<ReleaseOnAnything_Transition>(mainState, released); // Pressed -> ... make_transition<MoveOnNothing_Transition>(pressed, move_state, *this); make_transition<MoveOnNothing_Transition>(pressed, move_nothing, *this); /// MoveOnNothing -> ... // MoveOnNothing -> MoveOnNothing. make_transition<MoveOnNothing_Transition>(move_nothing, move_nothing, *this); // MoveOnNothing -> MoveOnState. add_transition(move_nothing, move_state, [&] () { rollback(); createToState(); }); // MoveOnNothing -> MoveOnEvent. add_transition(move_nothing, move_event, [&] () { rollback(); createToEvent(); }); // MoveOnNothing -> MoveOnTimeNode add_transition(move_nothing, move_timenode, [&] () { rollback(); createToTimeNode(); }); /// MoveOnState -> ... // MoveOnState -> MoveOnNothing add_transition(move_state, move_nothing, [&] () { rollback(); createToNothing(); }); // MoveOnState -> MoveOnState // We don't do anything, the constraint should not move. // MoveOnState -> MoveOnEvent add_transition(move_state, move_event, [&] () { rollback(); createToEvent(); }); // MoveOnState -> MoveOnTimeNode add_transition(move_state, move_timenode, [&] () { rollback(); createToTimeNode(); }); /// MoveOnEvent -> ... // MoveOnEvent -> MoveOnNothing add_transition(move_event, move_nothing, [&] () { rollback(); createToNothing(); }); // MoveOnEvent -> MoveOnState add_transition(move_event, move_state, [&] () { if(m_parentSM.model().state(clickedState).eventId() != m_parentSM.model().state(hoveredState).eventId()) { rollback(); createToState(); } }); // MoveOnEvent -> MoveOnEvent make_transition<MoveOnEvent_Transition>(move_event, move_event, *this); // MoveOnEvent -> MoveOnTimeNode add_transition(move_event, move_timenode, [&] () { rollback(); createToTimeNode(); }); /// MoveOnTimeNode -> ... // MoveOnTimeNode -> MoveOnNothing add_transition(move_timenode, move_nothing, [&] () { rollback(); createToNothing(); }); // MoveOnTimeNode -> MoveOnState add_transition(move_timenode, move_state, [&] () { rollback(); createToState(); }); // MoveOnTimeNode -> MoveOnEvent add_transition(move_timenode, move_event, [&] () { rollback(); createToEvent(); }); // MoveOnTimeNode -> MoveOnTimeNode make_transition<MoveOnTimeNode_Transition>(move_timenode , move_timenode , *this); // What happens in each state. QObject::connect(pressed, &QState::entered, [&] () { m_clickedPoint = currentPoint; createToNothing(); }); QObject::connect(move_nothing, &QState::entered, [&] () { if(createdConstraints.empty() || createdEvents.empty()) { rollback(); return; } if(m_parentSM.editionSettings().sequence()) { const auto& st = m_parentSM.model().state(clickedState); currentPoint.y = st.heightPercentage(); } m_dispatcher.submitCommand<MoveNewEvent>( Path<ScenarioModel>{m_scenarioPath}, createdConstraints.last(), createdEvents.last(), currentPoint.date, currentPoint.y, stateMachine.editionSettings().sequence()); }); QObject::connect(move_event, &QState::entered, [&] () { if(createdStates.empty()) { rollback(); return; } m_dispatcher.submitCommand<MoveNewState>( Path<ScenarioModel>{m_scenarioPath}, createdStates.last(), currentPoint.y); }); QObject::connect(move_timenode, &QState::entered, [&] () { if(createdStates.empty()) { rollback(); return; } m_dispatcher.submitCommand<MoveNewState>( Path<ScenarioModel>{m_scenarioPath}, createdStates.last(), currentPoint.y); }); QObject::connect(released, &QState::entered, [&] () { this->makeSnapshot(); m_dispatcher.commit<Scenario::Command::CreationMetaCommand>(); }); } QState* rollbackState = new QState{this}; make_transition<Cancel_Transition>(mainState, rollbackState); rollbackState->addTransition(finalState); QObject::connect(rollbackState, &QState::entered, [&] () { rollback(); }); setInitialState(mainState); }
bool multiSelection() const { return m_multiSelection->active(); }