示例#1
0
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
0
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();
}
示例#3
0
void UIAnimation::prepare()
{
    /* Prepare animation-machine: */
    m_pAnimationMachine = new QStateMachine(this);
    /* Create 'start' state: */
    m_pStateStart = new QState(m_pAnimationMachine);
    connect(m_pStateStart, SIGNAL(propertiesAssigned()), this, SIGNAL(sigStateEnteredStart()));
    /* Create 'final' state: */
    m_pStateFinal = new QState(m_pAnimationMachine);
    connect(m_pStateFinal, SIGNAL(propertiesAssigned()), this, SIGNAL(sigStateEnteredFinal()));

    /* Prepare 'forward' animation: */
    m_pForwardAnimation = new QPropertyAnimation(parent(), m_pszPropertyName, m_pAnimationMachine);
    m_pForwardAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    m_pForwardAnimation->setDuration(m_iAnimationDuration);
    /* Prepare 'reverse' animation: */
    m_pReverseAnimation = new QPropertyAnimation(parent(), m_pszPropertyName, m_pAnimationMachine);
    m_pReverseAnimation->setEasingCurve(QEasingCurve(QEasingCurve::InOutCubic));
    m_pReverseAnimation->setDuration(m_iAnimationDuration);

    /* Prepare state-transitions: */
    QSignalTransition *pStartToFinal = m_pStateStart->addTransition(parent(), m_pszSignalForward, m_pStateFinal);
    pStartToFinal->addAnimation(m_pForwardAnimation);
    QSignalTransition *pFinalToStart = m_pStateFinal->addTransition(parent(), m_pszSignalReverse, m_pStateStart);
    pFinalToStart->addAnimation(m_pReverseAnimation);

    /* Fetch animation-borders: */
    update();

    /* Choose initial state: */
    m_pAnimationMachine->setInitialState(!m_fReverse ? m_pStateStart : m_pStateFinal);
    /* Start animation-machine: */
    m_pAnimationMachine->start();
}
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
0
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();
}
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();
}
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&)));
}
示例#8
0
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;
}
示例#9
0
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);
}
示例#10
0
/*
 * 功能:
 * 	  构造函数,初始化有限状态机并run之。
 * 参数:
 * 	  无
 * 返回值:
 * 	  无
 */
SlidingScreen::SlidingScreen(QGraphicsView *parent, bool isOneDirection):
        QGraphicsView(parent), m_isOneDirection(isOneDirection)
{
    m_enable = false;
    m_enableSliding = true;
    m_pressPos.setX(0);
    m_pressPos.setY(0);
    m_releasePos.setX(0);
    m_releasePos.setY(0);

    p_frame1 = new QFrame();
    p_frame2 = new QFrame();
    p_frame3 = new QFrame();

    p_layout1 = new QStackedLayout();
    p_layout2 = new QStackedLayout();
    p_layout3 = new QStackedLayout();

    m_layOut[0] = p_layout1;
    m_layOut[1] = p_layout2;
    m_layOut[2] = p_layout3;

    /****初始化窗体指针缓存,索引缓存,索引缓存长度*********/
    p_widgetBuf = new QVector<QWidget*>(BUF_LEN, nullptr);
    p_indexBuf = new QVector<int>();

    p_frame1->resize(DESKTOP_WIDTH,DESKTOP_HEIGHT);
    p_frame2->resize(DESKTOP_WIDTH,DESKTOP_HEIGHT);
    p_frame3->resize(DESKTOP_WIDTH,DESKTOP_HEIGHT);

    p_frame1->setLayout(p_layout1);
    p_frame2->setLayout(p_layout2);
    p_frame3->setLayout(p_layout3);

/**************动画类实例化**********************/
    p_group = new QParallelAnimationGroup;
    p_frame1Animation = new QPropertyAnimation(p_frame1, "pos");
    p_frame2Animation = new QPropertyAnimation(p_frame2, "pos");
    p_frame3Animation = new QPropertyAnimation(p_frame3, "pos");

    p_frame1Animation->setDuration(1200);
    p_frame2Animation->setDuration(1200);
    p_frame3Animation->setDuration(1200);
    p_frame1Animation->setEasingCurve(QEasingCurve::InOutQuad);
    p_frame2Animation->setEasingCurve(QEasingCurve::InOutQuad);
    p_frame3Animation->setEasingCurve(QEasingCurve::InOutQuad);

    p_group->addAnimation(p_frame1Animation);
    p_group->addAnimation(p_frame2Animation);
    p_group->addAnimation(p_frame3Animation);

    connect(p_group, SIGNAL(finished()), this, SLOT(slotAnimationFinish()));
/***********************状态机实例化*******************************/
    p_stateMachine = new QStateMachine(this);
    p_startState = new QState();

    p_leftState1 = new QState(p_startState);
    p_leftState2 = new QState(p_startState);
    p_leftState3 = new QState(p_startState);

    p_rightState1 = new QState(p_startState);
    p_rightState2 = new QState(p_startState);
    p_rightState3 = new QState(p_startState);

    p_upState1 = new QState(p_startState);
    p_upState2 = new QState(p_startState);
    p_upState3 = new QState(p_startState);

    p_downState1 = new QState(p_startState);
    p_downState2 = new QState(p_startState);
    p_downState3 = new QState(p_startState);

/*********************move to left state*************************************/
    p_leftState1->assignProperty(p_frame1, "visible", true);
    p_leftState1->assignProperty(p_frame2, "visible", true);
    p_leftState1->assignProperty(p_frame3, "visible", false);
    p_leftState1->assignProperty(p_frame1, "pos", QPointF(0, DESKTOP_HEIGHT));
    p_leftState1->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_leftState1->assignProperty(p_frame3, "pos", QPointF(2*DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_leftState1->assignProperty(p_frame1, "objectName", QString("1"));   //存放当前显示的frame索引号

    p_leftState2->assignProperty(p_frame2, "visible", true);
    p_leftState2->assignProperty(p_frame3, "visible", true);
    p_leftState2->assignProperty(p_frame1, "visible", false);
    p_leftState2->assignProperty(p_frame2, "pos", QPointF(0, DESKTOP_HEIGHT));
    p_leftState2->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_leftState2->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH*2, DESKTOP_HEIGHT));
    p_leftState2->assignProperty(p_frame1, "objectName", QString("2"));

    p_leftState3->assignProperty(p_frame3, "visible", true);
    p_leftState3->assignProperty(p_frame1, "visible", true);
    p_leftState3->assignProperty(p_frame2, "visible", false);
    p_leftState3->assignProperty(p_frame3, "pos", QPointF(0, DESKTOP_HEIGHT));
    p_leftState3->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_leftState3->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH*2, DESKTOP_HEIGHT));
    p_leftState3->assignProperty(p_frame1, "objectName", QString("0"));

/***************move to right state*********************************/
    p_rightState1->assignProperty(p_frame1, "visible", false);
    p_rightState1->assignProperty(p_frame2, "visible", true);
    p_rightState1->assignProperty(p_frame3, "visible", true);
    p_rightState1->assignProperty(p_frame1, "pos", QPointF(0, DESKTOP_HEIGHT));
    p_rightState1->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_rightState1->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH*2, DESKTOP_HEIGHT));
    p_rightState1->assignProperty(p_frame1, "objectName", QString("1"));

    p_rightState2->assignProperty(p_frame2, "visible", false);
    p_rightState2->assignProperty(p_frame3, "visible", true);
    p_rightState2->assignProperty(p_frame1, "visible", true);
    p_rightState2->assignProperty(p_frame2, "pos", QPointF(0, DESKTOP_HEIGHT));
    p_rightState2->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_rightState2->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH*2, DESKTOP_HEIGHT));
    p_rightState2->assignProperty(p_frame1, "objectName", QString("2"));

    p_rightState3->assignProperty(p_frame3, "visible", false);
    p_rightState3->assignProperty(p_frame1, "visible", true);
    p_rightState3->assignProperty(p_frame2, "visible", true);
    p_rightState3->assignProperty(p_frame3, "pos", QPointF(0, DESKTOP_HEIGHT));
    p_rightState3->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_rightState3->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH*2, DESKTOP_HEIGHT));
    p_rightState3->assignProperty(p_frame1, "objectName", QString("0"));

/***********************move to up state******************************************/
    p_upState1->assignProperty(p_frame1, "visible", true);
    p_upState1->assignProperty(p_frame2, "visible", true);
    p_upState1->assignProperty(p_frame3, "visible", false);
    p_upState1->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, 0));
    p_upState1->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_upState1->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT*2));
    p_upState1->assignProperty(p_frame1, "objectName", QString("1"));

    p_upState2->assignProperty(p_frame2, "visible", true);
    p_upState2->assignProperty(p_frame3, "visible", true);
    p_upState2->assignProperty(p_frame1, "visible", false);
    p_upState2->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, 0));
    p_upState2->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_upState2->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT*2));
    p_upState2->assignProperty(p_frame1, "objectName", QString("2"));

    p_upState3->assignProperty(p_frame3, "visible", true);
    p_upState3->assignProperty(p_frame1, "visible", true);
    p_upState3->assignProperty(p_frame2, "visible", false);
    p_upState3->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, 0));
    p_upState3->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_upState3->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT*2));
    p_upState3->assignProperty(p_frame1, "objectName", QString("0"));

/*************************move to down state *************************************/
    p_downState1->assignProperty(p_frame1, "visible", false);
    p_downState1->assignProperty(p_frame2, "visible", true);
    p_downState1->assignProperty(p_frame3, "visible", true);
    p_downState1->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, 0));
    p_downState1->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_downState1->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT*2));
    p_downState1->assignProperty(p_frame1, "objectName", QString("1"));

    p_downState2->assignProperty(p_frame2, "visible", false);
    p_downState2->assignProperty(p_frame3, "visible", true);
    p_downState2->assignProperty(p_frame1, "visible", true);
    p_downState2->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, 0));
    p_downState2->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_downState2->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT*2));
    p_downState2->assignProperty(p_frame1, "objectName", QString("2"));

    p_downState3->assignProperty(p_frame3, "visible", false);
    p_downState3->assignProperty(p_frame1, "visible", true);
    p_downState3->assignProperty(p_frame2, "visible", true);
    p_downState3->assignProperty(p_frame3, "pos", QPointF(DESKTOP_WIDTH, 0));
    p_downState3->assignProperty(p_frame1, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT));
    p_downState3->assignProperty(p_frame2, "pos", QPointF(DESKTOP_WIDTH, DESKTOP_HEIGHT*2));
    p_downState3->assignProperty(p_frame1, "objectName", QString("0"));

/*************************收到向右滑动信号*********************绑定状态切换转换和动画效果***/  
    QSignalTransition *rightTransition = p_rightState1->addTransition(this, SIGNAL(sigMoveRight()), p_rightState3);
    rightTransition->addAnimation(p_group);
    rightTransition = p_rightState2->addTransition(this, SIGNAL(sigMoveRight()), p_rightState1);
    rightTransition->addAnimation(p_group);
    rightTransition = p_rightState3->addTransition(this, SIGNAL(sigMoveRight()), p_rightState2);
    rightTransition->addAnimation(p_group);

    rightTransition = p_leftState1->addTransition(this, SIGNAL(sigMoveRight()), p_rightState3);
    rightTransition->addAnimation(p_group);
    rightTransition = p_leftState2->addTransition(this, SIGNAL(sigMoveRight()), p_rightState1);
    rightTransition->addAnimation(p_group);
    rightTransition = p_leftState3->addTransition(this, SIGNAL(sigMoveRight()), p_rightState2);
    rightTransition->addAnimation(p_group);

    p_upState1->addTransition(this, SIGNAL(sigMoveRight()), p_rightState1);
    p_upState2->addTransition(this, SIGNAL(sigMoveRight()), p_rightState2);
    p_upState3->addTransition(this, SIGNAL(sigMoveRight()), p_rightState3);

    p_downState1->addTransition(this, SIGNAL(sigMoveRight()), p_rightState1);
    p_downState2->addTransition(this, SIGNAL(sigMoveRight()), p_rightState2);
    p_downState3->addTransition(this, SIGNAL(sigMoveRight()), p_rightState3);

   /*************************收到向左滑动信号*********************绑定状态切换转换和动画效果***/
    QSignalTransition *leftTransition = p_leftState1->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState2);
    leftTransition->addAnimation(p_group);
    leftTransition = p_leftState2->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState3);
    leftTransition->addAnimation(p_group);
    leftTransition = p_leftState3->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState1);
    leftTransition->addAnimation(p_group);

    leftTransition = p_rightState1->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState2);
    leftTransition->addAnimation(p_group);
    leftTransition = p_rightState2->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState3);
    leftTransition->addAnimation(p_group);
    leftTransition = p_rightState3->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState1);
    leftTransition->addAnimation(p_group);

    p_upState1->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState1);
    p_upState2->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState2);
    p_upState3->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState3);

    p_downState1->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState1);
    p_downState2->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState2);
    p_downState3->addTransition(this, SIGNAL(sigMoveLeft()), p_leftState3);

    /*************************收到向上滑动信号*********************绑定状态切换转换和动画效果***/
    QSignalTransition *upTransition = p_upState1->addTransition(this, SIGNAL(sigMoveUp()), p_upState2);
    upTransition->addAnimation(p_group);
    upTransition = p_upState2->addTransition(this, SIGNAL(sigMoveUp()), p_upState3);
    upTransition->addAnimation(p_group);
    upTransition = p_upState3->addTransition(this, SIGNAL(sigMoveUp()), p_upState1);
    upTransition->addAnimation(p_group);

    upTransition = p_downState1->addTransition(this, SIGNAL(sigMoveUp()), p_upState2);
    upTransition->addAnimation(p_group);
    upTransition = p_downState2->addTransition(this, SIGNAL(sigMoveUp()), p_upState3);
    upTransition->addAnimation(p_group);
    upTransition = p_downState3->addTransition(this, SIGNAL(sigMoveUp()), p_upState1);
    upTransition->addAnimation(p_group);

    p_leftState1->addTransition(this, SIGNAL(sigMoveUp()), p_upState1);
    p_leftState2->addTransition(this, SIGNAL(sigMoveUp()), p_upState2);
    p_leftState3->addTransition(this, SIGNAL(sigMoveUp()), p_upState3);

    p_rightState1->addTransition(this, SIGNAL(sigMoveUp()), p_upState1);
    p_rightState2->addTransition(this, SIGNAL(sigMoveUp()), p_upState2);
    p_rightState3->addTransition(this, SIGNAL(sigMoveUp()), p_upState3);

    /*************************收到向下滑动信号*********************绑定状态切换转换和动画效果***/
    QSignalTransition *downTransition = p_downState1->addTransition(this, SIGNAL(sigMoveDown()), p_downState3);
    downTransition->addAnimation(p_group);
    downTransition = p_downState2->addTransition(this, SIGNAL(sigMoveDown()), p_downState1);
    downTransition->addAnimation(p_group);
    downTransition = p_downState3->addTransition(this, SIGNAL(sigMoveDown()), p_downState2);
    downTransition->addAnimation(p_group);

    downTransition = p_upState1->addTransition(this, SIGNAL(sigMoveDown()), p_downState3);
    downTransition->addAnimation(p_group);
    downTransition = p_upState2->addTransition(this, SIGNAL(sigMoveDown()), p_downState1);
    downTransition->addAnimation(p_group);
    downTransition = p_upState3->addTransition(this, SIGNAL(sigMoveDown()), p_downState2);
    downTransition->addAnimation(p_group);


    p_leftState1->addTransition(this, SIGNAL(sigMoveDown()), p_downState1);
    p_leftState2->addTransition(this, SIGNAL(sigMoveDown()), p_downState2);
    p_leftState3->addTransition(this, SIGNAL(sigMoveDown()), p_downState3);

    p_rightState1->addTransition(this, SIGNAL(sigMoveDown()), p_downState1);
    p_rightState2->addTransition(this, SIGNAL(sigMoveDown()), p_downState2);
    p_rightState3->addTransition(this, SIGNAL(sigMoveDown()), p_downState3);

    /**************************收到恢复初始状态信号*******************************************/
    p_leftState1->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_leftState2->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_leftState3->addTransition(this, SIGNAL(sigInitState()), p_leftState1);

    p_rightState1->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_rightState2->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_rightState3->addTransition(this, SIGNAL(sigInitState()), p_leftState1);

    p_upState1->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_upState2->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_upState3->addTransition(this, SIGNAL(sigInitState()), p_leftState1);

    p_downState1->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_downState2->addTransition(this, SIGNAL(sigInitState()), p_leftState1);
    p_downState3->addTransition(this, SIGNAL(sigInitState()), p_leftState1);

    /************************初始化状态机和场景并关联之***********************************/
    p_scene = new QGraphicsScene(this);
    p_scene->addWidget(p_frame1);
    p_scene->addWidget(p_frame2);
    p_scene->addWidget(p_frame3);
    p_scene->setSceneRect(DESKTOP_WIDTH,DESKTOP_HEIGHT, DESKTOP_WIDTH, DESKTOP_HEIGHT);
    setScene(p_scene);

    p_startState->setInitialState(p_leftState1);
    m_isXDirection = true;
    m_currentWidgetIndex = 1;         //这个值跟初始状态当前显示索引有关
    m_currentFrameIndexl = 1;
    p_stateMachine->addState(p_startState);
    p_stateMachine->setInitialState(p_startState);
    p_stateMachine->start();
    connect(p_frame1, SIGNAL(objectNameChanged(QString)), this, SLOT(slotSendCurrentWidgetPointer(QString)));
}
示例#11
0
// 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();
	}
}
示例#12
0
文件: main5.cpp 项目: RSATom/Qt
int main(int argv, char **args)
{
    QApplication app(argv, args);
    QWidget *button;

  {
//![0]
    QStateMachine machine;
    machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);

    QState *s1 = new QState();
    s1->assignProperty(object, "fooBar", 1.0);
    machine.addState(s1);
    machine.setInitialState(s1);

    QState *s2 = new QState();
    machine.addState(s2);
//![0]
  }

  {

//![2]
    QStateMachine machine;
    machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);

    QState *s1 = new QState();
    s1->assignProperty(object, "fooBar", 1.0);
    machine.addState(s1);
    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();
}
示例#13
0
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();
}