PHISlideAnimation::PHISlideAnimation(PHIBaseItem *item, qreal orgHeight, bool upDir ) : QPropertyAnimation( item ), _item( item ), _orgHeight( orgHeight ), _upDir( upDir ) { setTargetObject( item ); setPropertyName( "_height" ); connect( this, &QPropertyAnimation::finished, this, &PHISlideAnimation::slotFinished ); connect( this, &QPropertyAnimation::stateChanged, this, &PHISlideAnimation::slotStateChanged ); if ( _upDir ) { setStartValue( _orgHeight ); setEndValue( 0 ); } else { setStartValue( 0 ); setEndValue( _orgHeight ); } }
QScrollbarStyleAnimation::QScrollbarStyleAnimation(Mode mode, QObject *target) : QNumberStyleAnimation(target), _mode(mode), _active(false) { switch (mode) { case Activating: setDuration(ScrollBarFadeOutDuration); setStartValue(0.0); setEndValue(1.0); break; case Deactivating: setDuration(ScrollBarFadeOutDelay + ScrollBarFadeOutDuration); setDelay(ScrollBarFadeOutDelay); setStartValue(1.0); setEndValue(0.0); break; } }
LineAnimation::LineAnimation(QGraphicsLineItem *item, const QLineF &target, QObject *parent) : QVariantAnimation(parent), item(item) { setStartValue(item->line()); setEndValue(target); }
void ViewportView::zoomTo(Node* n) { // Find all ControlInstances that are declared by this node QList<ControlInstance*> instances; for (auto i : items()) { if (auto c = dynamic_cast<ControlInstance*>(i)) { if (c->getNode() == n) { instances.push_back(c); } } } // Find a weighted sum of central points QVector3D pos; float area_sum = 0; for (auto i : instances) { const float area = i->boundingRect().width() * i->boundingRect().height(); pos += i->getControl()->pos() * area; area_sum += area; } pos /= area_sum; auto a = new QPropertyAnimation(this, "_center"); a->setDuration(100); a->setStartValue(center); a->setEndValue(pos); a->start(QPropertyAnimation::DeleteWhenStopped); }
void MythUIAnimation::CopyFrom(const MythUIAnimation* animation) { m_type = animation->m_type; m_value = animation->m_value; m_trigger = animation->m_trigger; m_looped = animation->m_looped; m_reversible = animation->m_reversible; m_centre = animation->m_centre; setStartValue(animation->startValue()); setEndValue(animation->endValue()); setEasingCurve(animation->easingCurve()); setDuration(animation->duration()); if (m_looped) setLoopCount(-1); }
/*! Rotates item with an animation. */ void ImageDocumentItem::rotate(Qt::Axis axis, qreal delta) { const auto oldRotation = rotation(axis); const auto newRotation = oldRotation + delta; const auto animation = new AxisAnimation(this, axis, d->document); animation->setStartValue(oldRotation); animation->setEndValue(newRotation); animation->setDuration(75); animation->setEasingCurve(QEasingCurve::Linear); if (!d->animationGroup) { d->animationGroup = new QSequentialAnimationGroup(d->document); } d->animationGroup->addAnimation(animation); d->animationGroup->start(QAbstractAnimation::DeleteWhenStopped); setRotation(axis, newRotation); }
void Viewport::onJumpTo(Node* n) { auto proxies = getControlProxies(n); float area_sum = 0; if (!proxies.length()) return; QVector3D pos; for (auto p : proxies) { const float area = p->boundingRect().width() * p->boundingRect().height(); pos += p->getControl()->pos() * area; area_sum += area; } pos /= area_sum; auto a = new QPropertyAnimation(this, "center"); a->setDuration(100); a->setStartValue(center); a->setEndValue(pos); a->start(QPropertyAnimation::DeleteWhenStopped); }
void ColorPicker::changeColorWheel(ELayoutColorPicker oldLayout, ELayoutColorPicker newLayout, bool skipAnimation) { //------------------ // get resources //------------------ // get paths to resources for two color wheels QString oldLayoutResource = getWheelPixmapPath(oldLayout); QString newLayoutResource = getWheelPixmapPath(newLayout); // get pixmaps for two color wheels QPixmap oldPixmap(oldLayoutResource); QPixmap newPixmap(newLayoutResource); //------------------ // resize and set pixmaps //------------------ int wheelSize = int(this->size().height() * 0.55f); if (wheelSize > this->size().width() * 0.85f) { wheelSize = int(this->size().width() * 0.85f); } mTempWheel->setPixmap(oldPixmap.scaled(wheelSize, wheelSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); mColorWheel->setPixmap(newPixmap.scaled(wheelSize, wheelSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); const int animationMsec = 250; //------------------ // Animate if needed //------------------ if (!skipAnimation) { // check if a new color wheel is being added. if the two resources don't match // do a fade in/fade out between the color wheels. if (oldLayoutResource.compare(newLayoutResource) != 0) { // make temp wheel visible and overlapping the color wheel mTempWheel->setVisible(true); mTempWheel->setGeometry(mColorWheel->geometry()); auto fadeOutEffect = new QGraphicsOpacityEffect(mTempWheel); mTempWheel->setGraphicsEffect(fadeOutEffect); auto fadeOutAnimation = new QPropertyAnimation(fadeOutEffect, "opacity"); fadeOutAnimation->setDuration(animationMsec); fadeOutAnimation->setStartValue(mWheelOpacity); fadeOutAnimation->setEndValue(0.0f); connect(fadeOutAnimation, SIGNAL(finished()), this, SLOT(hideTempWheel())); auto fadeInEffect = new QGraphicsOpacityEffect(mColorWheel); mColorWheel->setGraphicsEffect(fadeInEffect); auto fadeInAnimation = new QPropertyAnimation(fadeInEffect, "opacity"); fadeInAnimation->setDuration(animationMsec); fadeInAnimation->setStartValue(0.0f); mWheelOpacity = 1.0; // catch edge case wehre multi color picker is sometimes disabled by default if (newLayout == ELayoutColorPicker::multiColorLayout && (mCustomColorPicker->palette()->selectedCount() == 0)) { mWheelOpacity = 0.333; } fadeInAnimation->setEndValue(mWheelOpacity); auto group = new QParallelAnimationGroup; group->addAnimation(fadeInAnimation); group->addAnimation(fadeOutAnimation); group->start(QAbstractAnimation::DeleteWhenStopped); } else if (mCustomColorPicker->palette()->selectedCount() == 0 && (newLayout == ELayoutColorPicker::multiColorLayout || oldLayout == ELayoutColorPicker::multiColorLayout) && (newLayout != oldLayout)) { mTempWheel->setVisible(false); // If the resources match but its either changing from or changing to a multi layout // and no indices are selected so the multi layout should be opaque. float startOpacity; // don't need two animations, just do one. if (newLayout == ELayoutColorPicker::multiColorLayout) { startOpacity = 1.0f; mWheelOpacity = 0.333; } else if (oldLayout == ELayoutColorPicker::multiColorLayout) { startOpacity = 0.333f; mWheelOpacity = 1.0; } else { startOpacity = 0.0f; mWheelOpacity = 0.0; qDebug() << "WARNING: shouldn't get here..."; } if (oldLayout == ELayoutColorPicker::multiColorLayout) { // just set opacity here immediately cause of weird bug... mWheelOpacity = 1.0; // un-fade out the wheel auto effect = new QGraphicsOpacityEffect(mColorWheel); effect->setOpacity(mWheelOpacity); mColorWheel->setGraphicsEffect(effect); } else { auto fadeEffect = new QGraphicsOpacityEffect(mColorWheel); mColorWheel->setGraphicsEffect(fadeEffect); auto fadeAnimation = new QPropertyAnimation(fadeEffect, "opacity"); fadeAnimation->setDuration(animationMsec); fadeAnimation->setStartValue(startOpacity); fadeAnimation->setEndValue(mWheelOpacity); fadeAnimation->start(); } } } else { mTempWheel->setVisible(false); } }