Example #1
0
void HitExplosion::determined(Ts::DetermineValue value)
{
    if (value == Ts::GOOD)
    {
        greatItem_->hide();
        goodItem_->show();
    }
    else if (value == Ts::GREAT)
    {
        goodItem_->hide();
        greatItem_->show();
    }
    else
    {
        return;
    }

    QParallelAnimationGroup *group = new QParallelAnimationGroup;
    QPropertyAnimation *animation = new QPropertyAnimation(this,"opacity");
    animation->setDuration(200);
    animation->setKeyValueAt(0.0,0.0);
    animation->setKeyValueAt(0.1,0.5);
    animation->setKeyValueAt(0.9,0.5);
    animation->setKeyValueAt(1.0,0.0);
    group->addAnimation(animation);

    show();
    group->start(QAbstractAnimation::DeleteWhenStopped);
}
void QIrParabolicEffectManager::slotHandleDockletClicked()
{
	QIR_P(QIrParabolicEffectManager);
	QIrDock * dock = p->view->dock();
	QIrDockletBundle * bundle = qobject_cast< QIrDockletBundle * >(sender());

	if ( !bundle )
		return;
	QPropertyAnimation * animation = p->offsetAnimations[bundle];

	animation->setStartValue(QPointF(0,0));
	switch ( dock->dockArea() ) {
		case QIrAbstractDock::DA_BottomDockArea :
			animation->setKeyValueAt(0.5,QPointF(0,-20));
			break;
		case QIrAbstractDock::DA_TopDockArea :
			animation->setKeyValueAt(0.5,QPointF(0,20));
			break;
		case QIrAbstractDock::DA_LeftDockArea :
			animation->setKeyValueAt(0.5,QPointF(20,0));
			break;
		default :
			animation->setKeyValueAt(0.5,QPointF(-20,0));
			break;
	}
	animation->setEndValue(QPointF(0,0));
	animation->start();
}
Example #3
0
void CardItem::goBack(bool kieru){
    if(home_pos == pos()){
        if(kieru)
            setOpacity(0.0);
        return;
    }

    QPropertyAnimation *goback = new QPropertyAnimation(this, "pos");
    goback->setEndValue(home_pos);   
    goback->setEasingCurve(QEasingCurve::OutBounce);

    if(kieru){
        QParallelAnimationGroup *group = new QParallelAnimationGroup;

        QPropertyAnimation *disappear = new QPropertyAnimation(this, "opacity");
        disappear->setKeyValueAt(0.9, 1.0);
        disappear->setEndValue(0.0);

        goback->setDuration(1000);
        disappear->setDuration(1000);

        group->addAnimation(goback);
        group->addAnimation(disappear);

        group->start(QParallelAnimationGroup::DeleteWhenStopped);
    }else
        goback->start(QPropertyAnimation::DeleteWhenStopped);
}
Example #4
0
QAbstractAnimation *QSanRoomSkin::createHuaShenAnimation(QPixmap &huashenAvatar, QPoint topLeft, QGraphicsItem *parent,
    QGraphicsItem *&huashenAvatarCreated) const
{
    QLabel *avatar = new QLabel;
    avatar->setStyleSheet("QLabel { background-color: transparent; }");
    avatar->setPixmap(huashenAvatar);
    QGraphicsProxyWidget *widget = new QGraphicsProxyWidget(parent);
    widget->setWidget(avatar);
    widget->setPos(topLeft);

    QPropertyAnimation *animation = new QPropertyAnimation(widget, "opacity");
    animation->setLoopCount(2000);
    JsonArray huashenConfig = _m_animationConfig["huashen"].value<JsonArray>();
    int duration;
    if (tryParse(huashenConfig[0], duration) && huashenConfig[1].canConvert<JsonArray>()) {
        animation->setDuration(duration);
        JsonArray keyValues = huashenConfig[1].value<JsonArray>();
        for (int i = 0; i < keyValues.size(); i++) {
            QVariant keyValue = keyValues[i];
            if (!keyValue.canConvert<JsonArray>() || keyValue.value<JsonArray>().length() != 2) continue;
            double step;
            double val;
            JsonArray keyArr = keyValue.value<JsonArray>();
            if (!tryParse(keyArr[0], step) || !tryParse(keyArr[1], val)) continue;
            animation->setKeyValueAt(step, val);
        }
    }
    huashenAvatarCreated = widget;
    return animation;
}
Example #5
0
void Photo::setEmotion(const QString &emotion, bool permanent) {
    if (emotion == ".") {
        hideEmotion();
        return;
    }

    QString path = QString("image/system/emotion/%1.png").arg(emotion);
    if (QFile::exists(path)) {
        QPixmap pixmap = QPixmap(path);
        emotion_item->setPixmap(pixmap);
        emotion_item->setPos((G_PHOTO_LAYOUT.m_normalWidth - pixmap.width()) / 2,
                             (G_PHOTO_LAYOUT.m_normalHeight - pixmap.height()) / 2);
        _layBetween(emotion_item, _m_chainIcon, _m_roleComboBox);

        QPropertyAnimation *appear = new QPropertyAnimation(emotion_item, "opacity");
        appear->setStartValue(0.0);
        if (permanent) {
            appear->setEndValue(1.0);
            appear->setDuration(500);
        } else {
            appear->setKeyValueAt(0.25, 1.0);
            appear->setKeyValueAt(0.75, 1.0);
            appear->setEndValue(0.0);
            appear->setDuration(2000);
        }
        appear->start(QAbstractAnimation::DeleteWhenStopped);
    } else {
        PixmapAnimation::GetPixmapAnimation(this, emotion);
    }
}
QAbstractAnimation *CardItem::getGoBackAnimation(bool doFade, bool smoothTransition, int duration) {
    m_animationMutex.lock();
    if (m_currentAnimation != NULL) {
        m_currentAnimation->stop();
        delete m_currentAnimation;
        m_currentAnimation = NULL;
    }
    QPropertyAnimation *goback = new QPropertyAnimation(this, "pos");
    goback->setEndValue(home_pos);
    goback->setEasingCurve(QEasingCurve::OutQuad);
    goback->setDuration(duration);

    if (doFade) {
        QParallelAnimationGroup *group = new QParallelAnimationGroup;
        QPropertyAnimation *disappear = new QPropertyAnimation(this, "opacity");        
        double middleOpacity = qMax(opacity(), m_opacityAtHome);
        if (middleOpacity == 0) middleOpacity = 1.0;        
        disappear->setEndValue(m_opacityAtHome);
        if (!smoothTransition) {
            disappear->setKeyValueAt(0.2, middleOpacity);
            disappear->setKeyValueAt(0.8, middleOpacity);
            disappear->setDuration(duration);
        }

        group->addAnimation(goback);
        group->addAnimation(disappear);

        m_currentAnimation = group;
    } else {
        m_currentAnimation = goback;
    }
    m_animationMutex.unlock();
    connect(m_currentAnimation, SIGNAL(finished()), this, SIGNAL(movement_animation_finished()));
    return m_currentAnimation;
}
void AudioChatWidgetHolder::addAudioData(const QString name, QByteArray* array)
{
    if (!audioMuteCaptureToggleButton->isChecked()) {
        //launch an animation. Don't launch it if already animating
        if (!audioMuteCaptureToggleButton->graphicsEffect() ||
            (audioMuteCaptureToggleButton->graphicsEffect()->inherits("QGraphicsOpacityEffect") &&
                ((QGraphicsOpacityEffect*)audioMuteCaptureToggleButton->graphicsEffect())->opacity() == 1)
            ) {
            QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(audioListenToggleButton);
            audioMuteCaptureToggleButton->setGraphicsEffect(effect);
            QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity");
            anim->setStartValue(1);
            anim->setKeyValueAt(0.5,0);
            anim->setEndValue(1);
            anim->setDuration(400);
            anim->start();
        }

//        soundManager->play(VOIP_SOUND_INCOMING_CALL);

        audioMuteCaptureToggleButton->setToolTip(tr("Answer"));

        //TODO make a toaster and a sound for the incoming call
        return;
    }

    if (!outputDevice) {
        outputDevice = AudioDeviceHelper::getDefaultOutputDevice();
    }

    if (!outputProcessor) {
        //start output audio device
        outputProcessor = new QtSpeex::SpeexOutputProcessor();
        if (inputProcessor) {
            connect(outputProcessor, SIGNAL(playingFrame(QByteArray*)), inputProcessor, SLOT(addEchoFrame(QByteArray*)));
        }
        outputProcessor->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
        outputDevice->start(outputProcessor);
    }

    if (outputDevice && outputDevice->error() != QAudio::NoError) {
        std::cerr << "Restarting output device. Error before reset " << outputDevice->error() << " buffer size : " << outputDevice->bufferSize() << std::endl;
        outputDevice->stop();
        outputDevice->reset();
        if (outputDevice->error() == QAudio::UnderrunError)
            outputDevice->setBufferSize(20);
        outputDevice->start(outputProcessor);
    }
    outputProcessor->putNetworkPacket(name, *array);

    //check the input device for errors
    if (inputDevice && inputDevice->error() != QAudio::NoError) {
        std::cerr << "Restarting input device. Error before reset " << inputDevice->error() << std::endl;
        inputDevice->stop();
        inputDevice->reset();
        inputDevice->start(inputProcessor);
    }
}
Example #8
0
QPropertyAnimation* LinearLayoutActor::createPaddingAnimation(const char* propertyName, qreal increaseFactor, qreal initialValue, int duration, int initialDelay)
{
	// Adjust animation time
	duration = VisualizationSpeed::getInstance().adjust(duration);
	int totalDuration = initialDelay + duration;

	// Create an animation and set its duration
	QPropertyAnimation* animation = new QPropertyAnimation(this, propertyName, this);
	animation->setDuration(totalDuration);

	// Do not change initial value on delay
	animation->setKeyValueAt(0.0, initialValue);
	if ( totalDuration > 0 )
		animation->setKeyValueAt(qreal(initialDelay) / totalDuration, initialValue);
	animation->setKeyValueAt(1.0, initialValue + increaseFactor);

	return animation;
}
Example #9
0
void Photo::tremble() {
    QPropertyAnimation *vibrate = new QPropertyAnimation(this, "x");
    static qreal offset = 20;

    vibrate->setKeyValueAt(0.5, x() - offset);
    vibrate->setEndValue(x());

    vibrate->setEasingCurve(QEasingCurve::OutInBounce);

    vibrate->start(QAbstractAnimation::DeleteWhenStopped);
}
Example #10
0
QPropertyAnimation* LinearLayoutActor::createMoveToAnimation(const char* propertyName, qreal endProportion, qreal startProportion, int duration, int initialDelay)
{
	// Adjust animation time
	duration = VisualizationSpeed::getInstance().adjust(duration);
	int totalDuration = initialDelay + duration;

	// Create an animation and set its duration
	QPropertyAnimation* animation = new QPropertyAnimation(this, propertyName, this);
	animation->setDuration(totalDuration);

	// Stay at the current proportion at the beginning of the animation
	animation->setKeyValueAt(0.0, startProportion);

	// After the delay is finished, start from the current porportion
	if ( totalDuration > 0 )
		animation->setKeyValueAt(qreal(initialDelay) / totalDuration, startProportion);

	// At the end of the animation, reach the desired end proportion
	animation->setKeyValueAt(1.0, endProportion);
	return animation;
}
Example #11
0
QAbstractAnimation* CardItem::goBack(bool kieru,bool fadein,bool fadeout){
    if(home_pos == pos()){
        if(kieru && home_pos != QPointF(-6, 8))
            setOpacity(0.0);
        return NULL;
    }

    QPropertyAnimation *goback = new QPropertyAnimation(this, "pos");
    goback->setEndValue(home_pos);
    goback->setEasingCurve(QEasingCurve::OutQuad);
    goback->setDuration(500);

    if(kieru){
        QParallelAnimationGroup *group = new QParallelAnimationGroup;

        QPropertyAnimation *disappear = new QPropertyAnimation(this, "opacity");
        if(fadein)disappear->setStartValue(0.0);
        disappear->setEndValue(1.0);
        if(fadeout)disappear->setEndValue(0.0);

        disappear->setKeyValueAt(0.2, 1.0);
        disappear->setKeyValueAt(0.8, 1.0);


        qreal dx = home_pos.x()-pos().x();
        qreal dy = home_pos.y()-pos().y();
        int length = sqrt(dx*dx+dy*dy);


        length = qBound(500/3,length,400);

        goback->setDuration(length*3);
        disappear->setDuration(length*3);

        group->addAnimation(goback);
        group->addAnimation(disappear);

        // prevent the cover face bug
        setEnabled(false);

        group->start(QParallelAnimationGroup::DeleteWhenStopped);
        return group;
    }else
    {
        setOpacity(this->isEnabled() ? 1.0 : 0.7);
        goback->start(QPropertyAnimation::DeleteWhenStopped);
        return goback;
    }
}
Example #12
0
void CardItem::goBack(bool kieru,bool fadein,bool fadeout){
    if(home_pos == pos()){
        if(kieru)
            setOpacity(0.0);
        return;
    }

    QPropertyAnimation *goback = new QPropertyAnimation(this, "pos");
    goback->setEndValue(home_pos);
    goback->setEasingCurve(QEasingCurve::OutQuad);
    goback->setDuration(300);

    if(kieru){
        QParallelAnimationGroup *group = new QParallelAnimationGroup;

        QPropertyAnimation *disappear = new QPropertyAnimation(this, "opacity");
        if(fadein)disappear->setStartValue(0.0);
        disappear->setEndValue(1.0);
        if(fadeout)disappear->setEndValue(0.0);

        disappear->setKeyValueAt(0.2, 1.0);
        disappear->setKeyValueAt(0.8, 1.0);


        int dx = home_pos.x()-pos().x();
        int dy = home_pos.y()-pos().y();
        int length = sqrt(dx*dx+dy*dy);


        if(length*3>500)disappear->setStartValue(0.0);
        else length = 500/3;

        if(length*3>1200)length =400;

        goback->setDuration(length*3);
        disappear->setDuration(length*3);

        group->addAnimation(goback);
        group->addAnimation(disappear);

        // prevent the cover face bug
        setEnabled(false);

        group->start(QParallelAnimationGroup::DeleteWhenStopped);
    }else
        goback->start(QPropertyAnimation::DeleteWhenStopped);
}
void PaintedWidget::animation()
{

    car->setPixmap(carimg);
    car->show();
    QPropertyAnimation *anim = new QPropertyAnimation(car,"pos");
    anim->setDuration(duration);

    QPoint temp=spline.s[0];    // temp是把曲线点移动(-40,-40)的点,原先是小车左上角贴着曲线运动,这样使得右下角贴着曲线运动
    temp.setX(spline.s[0].x()-40);
    temp.setY(spline.s[0].y()-40);

    anim->setStartValue(temp);
    /*
    for(int i=1;i<spline.allCount-1;i++)
    {

        temp.setX(spline.s[i].x()-40);
        temp.setY(spline.s[i].y()-40);
        anim->setKeyValueAt(((float)i)/(spline.allCount-1),temp);
    }
    */

    for(int i=0;i<spline.dividCount-1;i++){
        temp.setX(spline.dividPoint[i].x()-40);
        temp.setY(spline.dividPoint[i].y()-40);
        anim->setKeyValueAt(((float)i)/(spline.dividCount-1),temp);
    }

    /*
    temp.setX(spline.s[spline.allCount-1].x()-40);
    temp.setY(spline.s[spline.allCount-1].y()-40);
    anim->setEndValue(temp);
    //car->move();
    */
    temp.setX(spline.dividPoint[spline.dividCount-1].x()-40);
    temp.setY(spline.dividPoint[spline.dividCount-1].y()-40);
    anim->setEndValue(temp);

    anim->start();


    //qDebug()<<spline.s[0]<<" to " << spline.s[spline.allCount-1];
    qDebug()<<"animation exe";

}
Example #14
0
void Letter::showWelcomePage()
{
    welcome = new WelcomePage(this);
    connect(welcome, SIGNAL(welcomePageLoaded()), this, SLOT(removeWelcomePage()));

    QPropertyAnimation *welAnimation = new QPropertyAnimation(welcome, "opacity");
    welAnimation->setDuration(CHANGE_MSEC);
    welAnimation->setStartValue(0.0);
    welAnimation->setEndValue(0.0);
    welAnimation->setKeyValueAt(0.8, 1);
    connect(welAnimation, SIGNAL(finished()), welcome, SIGNAL(welcomePageLoaded()));
    connect(welAnimation, SIGNAL(finished()), this, SLOT(showLetter()));

    this->layout()->addWidget(welcome);

    welAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
Example #15
0
LrcView::LrcView(QWidget *parent) :
    QLabel(parent)
{
//////////////    setGeometry(276, 113, 731, 476);

    //创建 动画
    lab_left_top = new QLabel(this);
    lab_left_bottom = new QLabel(this);

    lab_left_top ->setGeometry(20, 40, 100, 100);
    lab_left_bottom  ->setGeometry(20, 100, 240, 320);

    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updateGif()));
    timer ->start(100);

    //创建 后续歌词
    textNext = new QLabel(this);
    textNext ->setGeometry(260, 260, 450, 200);
    textNext ->setAlignment(Qt::AlignTop);
    textNext ->setStyleSheet(
                "QLabel{"
//                    "color: rgba(40, 16, 144, 255);"
//                    "color: rgba(92, 133, 20, 255);"
//                    "color: rgba(95, 110, 13, 255);"       //黄绿色
                    "color: rgba(38, 79, 16, 255);"        //墨绿色
//                    "color: rgba(13, 72, 110, 255);"        //蓝绿色
                    "font-family: 楷体;"
                    "font-size: 20px;"
                "}"
                );

    //创建 当前播放歌词
    currentLrc = new CurrentLrc(this);
    currentLrc ->setGeometry(260, 232, 450, 26);

    //创建 播放过的歌词
    textPrevious = new QLabel(this);
    textPrevious ->setGeometry(260, 6, 450, 225);
    textPrevious ->setAlignment(Qt::AlignBottom);
    textPrevious ->setStyleSheet(
                "QLabel{"
                    "color: rgba(38, 79, 16, 255);"
                    "font-family: 楷体;"
                    "font-size: 20px;"
                "}"
                );
    this->setMouseTracking(true);
    textNext->setMouseTracking(true);
    currentLrc->setMouseTracking(true);
    textPrevious->setMouseTracking(true);
    lab_left_top->setMouseTracking(true);
    lab_left_bottom->setMouseTracking(true);


/*
    QAxWidget *flash = new QAxWidget(this);
    flash->setControl(QString::fromUtf8("{d27cdb6e-ae6d-11cf-96b8-444553540000}"));
    QString name=qApp->applicationDirPath();
    flash->dynamicCall("LoadMovie(long,string)",0,qApp->applicationDirPath()+"/top.swf");
    flash->show();
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(flash);
    layout->setMargin(0);
    setLayout(layout);
*/
/*
    QPropertyAnimation *animation = new QPropertyAnimation(lab_left_bottom, "pos");
    animation->setKeyValueAt(0.0, QPoint(lab_left_bottom->x(), lab_left_bottom->y()));
    animation->setKeyValueAt(0.5, QPoint(this->x()-lab_left_bottom->width(), lab_left_bottom->y()));
    animation->setKeyValueAt(1.0, QPoint(lab_left_bottom->x(), lab_left_bottom->y()));
    animation->setDuration(20000);
    animation->setLoopCount(-1);
    animation->start();
*/
    QPropertyAnimation *animation = new QPropertyAnimation(lab_left_bottom, "geometry");
    animation->setKeyValueAt(0.0, QRectF(lab_left_bottom->pos(), lab_left_bottom->size()));
    animation->setKeyValueAt(0.5, QRectF(lab_left_bottom->x()+50, lab_left_bottom->y()+50, lab_left_bottom->width()-100, lab_left_bottom->height()-133));
    animation->setKeyValueAt(1.0, QRectF(lab_left_bottom->pos(), lab_left_bottom->size()));
    animation->setDuration(20000);
    animation->setLoopCount(-1);
    animation->start();
}
void VOIPChatWidgetHolder::addAudioData(const RsPeerId &peer_id, QByteArray* array)
{
    if (!audioCaptureToggleButton->isChecked()) {
        //launch an animation. Don't launch it if already animating
        if (!audioCaptureToggleButton->graphicsEffect() ||
            (audioCaptureToggleButton->graphicsEffect()->inherits("QGraphicsOpacityEffect") &&
                ((QGraphicsOpacityEffect*)audioCaptureToggleButton->graphicsEffect())->opacity() == 1)
            ) {
            QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect(audioListenToggleButton);
            audioCaptureToggleButton->setGraphicsEffect(effect);
            QPropertyAnimation *anim = new QPropertyAnimation(effect, "opacity", effect);
            anim->setStartValue(1);
            anim->setKeyValueAt(0.5,0);
            anim->setEndValue(1);
            anim->setDuration(400);
            anim->start();
        }
        
        if (mChatWidget) {
        QString buttonName = QString::fromUtf8(rsPeers->getPeerName(peer_id).c_str());
        if (buttonName.isEmpty()) buttonName = "VoIP";//TODO maybe change all with GxsId
        button_map::iterator it = buttonMapTakeVideo.find(buttonName);
        if (it == buttonMapTakeVideo.end()){
				mChatWidget->addChatMsg(true, tr("VoIP Status"), QDateTime::currentDateTime(), QDateTime::currentDateTime()
				                        , tr("%1 inviting you to start a audio conversation. do you want Accept or Decline the invitation?").arg(buttonName), ChatWidget::MSGTYPE_SYSTEM);
				RSButtonOnText *button = mChatWidget->getNewButtonOnTextBrowser(tr("Accept Call"));
				button->setToolTip(tr("Activate audio"));
				button->setStyleSheet(QString("border: 1px solid #199909;")
				                      .append("font-size: 12pt;  color: white;")
				                      .append("min-width: 128px; min-height: 24px;")
				                      .append("border-radius: 6px;")
				                      .append("background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
                                        "stop: 0 #22c70d, stop: 1 #116a06);")

				                      );
                                       

				button->updateImage();

				connect(button,SIGNAL(clicked()),this,SLOT(startAudioCapture()));
				connect(button,SIGNAL(mouseEnter()),this,SLOT(botMouseEnter()));
				connect(button,SIGNAL(mouseLeave()),this,SLOT(botMouseLeave()));

				buttonMapTakeVideo.insert(buttonName, button);
        }
        }

        audioCaptureToggleButton->setToolTip(tr("Answer"));

        //TODO make a sound for the incoming call
//        soundManager->play(VOIP_SOUND_INCOMING_CALL);
        if (mVOIPNotify) mVOIPNotify->notifyReceivedVoipAudioCall(peer_id);

        return;
    }

    if (!outputAudioDevice) {
        outputAudioDevice = AudioDeviceHelper::getDefaultOutputDevice();
    }

    if (!outputAudioProcessor) {
        //start output audio device
        outputAudioProcessor = new QtSpeex::SpeexOutputProcessor();
        if (inputAudioProcessor) {
            connect(outputAudioProcessor, SIGNAL(playingFrame(QByteArray*)), inputAudioProcessor, SLOT(addEchoFrame(QByteArray*)));
        }
        outputAudioProcessor->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
        outputAudioDevice->start(outputAudioProcessor);
    }

    if (outputAudioDevice && outputAudioDevice->error() != QAudio::NoError) {
        std::cerr << "Restarting output device. Error before reset " << outputAudioDevice->error() << " buffer size : " << outputAudioDevice->bufferSize() << std::endl;
        outputAudioDevice->stop();
        outputAudioDevice->reset();
        if (outputAudioDevice->error() == QAudio::UnderrunError)
            outputAudioDevice->setBufferSize(20);
        outputAudioDevice->start(outputAudioProcessor);
    }
    outputAudioProcessor->putNetworkPacket(QString::fromStdString(peer_id.toStdString()), *array);

    //check the input device for errors
    if (inputAudioDevice && inputAudioDevice->error() != QAudio::NoError) {
        std::cerr << "Restarting input device. Error before reset " << inputAudioDevice->error() << std::endl;
        inputAudioDevice->stop();
        inputAudioDevice->reset();
        inputAudioDevice->start(inputAudioProcessor);
    }
}
    void edge_relaxed(edge_d e, graph_t const& g) {
//        predecessor_map[g.target(e)] = g.source(e);
        vertex_d target = boost::target(e, g), src = boost::source(e, g);
//        predecessor_map[target] = src;

        VertexLabel *labelItem = labelVector[target].get();
        auto prlAnim =
            std::shared_ptr<QParallelAnimationGroup>(new QParallelAnimationGroup); 

        /* repaint vertex */
        // source vertex
        if(src != source) {
            prlAnim->addAnimation(create(vertexList[src], "color", 
                        Vertex::InitColor, Vertex::DiscoveredColor));
        }

        // target vertex
        prlAnim->addAnimation(create(vertexList[target], "color", 
                    Vertex::InitColor, Vertex::DiscoveredColor));
        /* finish repaint vertex */

        /* repaint edge */
        for(Edge *edge : vertexList[src]->outEdges()) {
            if(edge->destVertex() == vertexList[target]) {
                edge->setZValue(edge->zValue()+2);

                prlAnim->addAnimation(create(edge, "state", Edge::Init, Edge::Relaxed));
                break;
            }
        }
        /* finish repaint edge */

        /* set label */
        std::pair<int, int> new_label = 
                { distance_map[target], vertexList[src]->getId() };

        // set distance
        prlAnim->addAnimation(create(labelItem, "distance",
                    old_label[target].first, new_label.first));

        // set predecessor
        prlAnim->addAnimation(create(labelItem, "predecessor",
                    old_label[target].second, new_label.second));

        old_label[target] = new_label;
        /* finish set label */

        /* select label item */
        // unselect old label
        QPropertyAnimation *unselectLabelAnim =
            new QPropertyAnimation(lastestLabel, "selected");
        unselectLabelAnim->setDuration(200);
        unselectLabelAnim->setStartValue(1);
        unselectLabelAnim->setKeyValueAt(.75, 0);
        unselectLabelAnim->setEndValue(0);
        prlAnim->addAnimation(unselectLabelAnim);

        // select new label
        QPropertyAnimation *selectLabelAnim =
            new QPropertyAnimation(labelItem, "selected");
        selectLabelAnim->setDuration(200);
        selectLabelAnim->setStartValue(0);
        selectLabelAnim->setKeyValueAt(.75, 1);
        selectLabelAnim->setEndValue(1);
        prlAnim->addAnimation(selectLabelAnim);

        lastestLabel = labelItem;
        /* finish select label item */

        animList << prlAnim;
//        animList << std::shared_ptr<QAbstractAnimation>(labelAnim);

//        qDebug() << labelAnim->targetObject();
    }
Example #18
0
//! [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]
}