void KItemListSmoothScroller::scrollContentsBy(qreal distance) { QObject* target = targetObject(); if (!target) { return; } const QByteArray name = propertyName(); const qreal currentOffset = target->property(name).toReal(); if (static_cast<int>(currentOffset) == m_scrollBar->value()) { // The current offset is already synchronous to the scrollbar return; } const bool animRunning = (m_animation->state() == QAbstractAnimation::Running); if (animRunning) { // Stopping a running animation means skipping the range from the current offset // until the target offset. To prevent skipping of the range the difference // is added to the new target offset. const qreal oldEndOffset = m_animation->endValue().toReal(); distance += (currentOffset - oldEndOffset); } const qreal endOffset = currentOffset - distance; if (m_smoothScrolling || animRunning) { qreal startOffset = currentOffset; if (animRunning) { // If the animation was running and has been interrupted by assigning a new end-offset // one frame must be added to the start-offset to keep the animation smooth. This also // assures that animation proceeds even in cases where new end-offset are triggered // within a very short timeslots. startOffset += (endOffset - currentOffset) * 1000 / (m_animation->duration() * 60); if (currentOffset < endOffset) { startOffset = qMin(startOffset, endOffset); } else { startOffset = qMax(startOffset, endOffset); } } m_animation->stop(); m_animation->setStartValue(startOffset); m_animation->setEndValue(endOffset); m_animation->setEasingCurve(animRunning ? QEasingCurve::OutQuad : QEasingCurve::InOutQuad); m_animation->start(); target->setProperty(name, startOffset); } else { target->setProperty(name, endOffset); } }
int QPropertyAnimation::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QVariantAnimation::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QByteArray*>(_v) = propertyName(); break; case 1: *reinterpret_cast< QObject**>(_v) = targetObject(); break; } _id -= 2; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setPropertyName(*reinterpret_cast< QByteArray*>(_v)); break; case 1: setTargetObject(*reinterpret_cast< QObject**>(_v)); break; } _id -= 2; } else if (_c == QMetaObject::ResetProperty) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 2; } #endif // QT_NO_PROPERTIES return _id; }
MyPropertyAnimation::~MyPropertyAnimation(){ delete targetObject(); }