本文整理汇总了C++中QState类的典型用法代码示例。如果您正苦于以下问题:C++ QState类的具体用法?C++ QState怎么用?C++ QState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scene
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;
}
示例2: sourceState
QStateMachine *QAbstractTransitionPrivate::machine() const
{
QState *source = sourceState();
if (!source)
return 0;
return source->machine();
}
示例3: 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;
}
示例4: QStateMachine
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()));
}
示例5: 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();
}
示例6: m_fRoot
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();
}
}
示例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: localSM
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();
}
示例9: qCritical
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()));
}
示例10: onStateExited
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";
}
示例11: AbstractComplexState
/*
* 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();
}
示例12: font
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&)));
}
示例13: QState
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();
}
示例14: QStateMachine
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();
}
示例15: 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();
}