22 animatableProperties->insert(QStringLiteral(
"fill"), QSvgAbstractAnimatedProperty::Color);
23 animatableProperties->insert(QStringLiteral(
"fill-opacity"), QSvgAbstractAnimatedProperty::Float);
24 animatableProperties->insert(QStringLiteral(
"stroke-opacity"), QSvgAbstractAnimatedProperty::Float);
25 animatableProperties->insert(QStringLiteral(
"stroke"), QSvgAbstractAnimatedProperty::Color);
26 animatableProperties->insert(QStringLiteral(
"opacity"), QSvgAbstractAnimatedProperty::Float);
27 animatableProperties->insert(QStringLiteral(
"transform"), QSvgAbstractAnimatedProperty::Transform);
28 animatableProperties->insert(QStringLiteral(
"offset-distance"), QSvgAbstractAnimatedProperty::Float);
100QSvgAbstractAnimatedProperty *QSvgAbstractAnimatedProperty::createAnimatedProperty(
const QString &name)
102 if (animatableProperties->isEmpty())
105 if (!animatableProperties->contains(name)) {
106 qCDebug(lcSvgAnimatedProperty) <<
"Property : " << name <<
" is not animatable";
110 QSvgAbstractAnimatedProperty::Type type = animatableProperties->value(name);
111 QSvgAbstractAnimatedProperty *prop =
nullptr;
114 case QSvgAbstractAnimatedProperty::Color:
115 prop =
new QSvgAnimatedPropertyColor(name);
117 case QSvgAbstractAnimatedProperty::Transform:
118 prop =
new QSvgAnimatedPropertyTransform(name);
120 case QSvgAbstractAnimatedProperty::Float:
121 prop =
new QSvgAnimatedPropertyFloat(name);
149void QSvgAnimatedPropertyColor::interpolate(uint index, qreal t)
const
151 QColor c1 = m_colors.at(index - 1);
152 QColor c2 = m_colors.at(index);
154 int alpha = q_lerp(c1.alpha(), c2.alpha(), t);
155 int red = q_lerp(c1.red(), c2.red(), t);
156 int green = q_lerp(c1.green(), c2.green(), t);
157 int blue = q_lerp(c1.blue(), c2.blue(), t);
159 m_interpolatedValue = QColor(red, green, blue, alpha);
182void QSvgAnimatedPropertyFloat::interpolate(uint index, qreal t)
const
184 if (index >= (uint)m_keyFrames.size()) {
185 qCWarning(lcSvgAnimatedProperty) <<
"Invalid index for key frames";
189 qreal float1 = m_values.at(index - 1);
190 qreal float2 = m_values.at(index);
192 m_interpolatedValue = q_lerp(float1, float2, t);
227void QSvgAnimatedPropertyTransform::interpolate(uint index, qreal t)
const
229 if (index >= (uint)m_keyFrames.size()) {
230 qCWarning(lcSvgAnimatedProperty) <<
"Invalid index for key frames";
234 if (!m_transformCount ||
235 ((m_components.size() / qsizetype(m_transformCount)) != m_keyFrames.size())) {
239 QTransform transform = QTransform();
241 qsizetype startIndex = (index - 1) * qsizetype(m_transformCount);
242 qsizetype endIndex = index * qsizetype(m_transformCount);
244 for (quint32 i = 0; i < m_transformCount; i++) {
245 TransformComponent tc1 = m_components.at(startIndex + i);
246 TransformComponent tc2 = m_components.at(endIndex + i);
247 if (tc1.type == tc2.type) {
248 if (tc1.type == TransformComponent::Translate) {
249 QPointF t1 = QPointF(tc1.values.at(0), tc1.values.at(1));
250 QPointF t2 = QPointF(tc2.values.at(0), tc2.values.at(1));
251 QPointF tr = pointInterpolator(t1, t2, t);
252 transform.translate(tr.x(), tr.y());
253 }
else if (tc1.type == TransformComponent::Scale) {
254 QPointF s1 = QPointF(tc1.values.at(0), tc1.values.at(1));
255 QPointF s2 = QPointF(tc2.values.at(0), tc2.values.at(1));
256 QPointF sr = pointInterpolator(s1, s2, t);
257 transform.scale(sr.x(), sr.y());
258 }
else if (tc1.type == TransformComponent::Rotate) {
259 QPointF cor1 = QPointF(tc1.values.at(1), tc1.values.at(2));
260 QPointF cor2 = QPointF(tc2.values.at(1), tc2.values.at(2));
261 QPointF corResult = pointInterpolator(cor1, cor2, t);
262 qreal angle1 = tc1.values.at(0);
263 qreal angle2 = tc2.values.at(0);
264 qreal angleResult = q_lerp(angle1, angle2, t);
265 transform.translate(corResult.x(), corResult.y());
266 transform.rotate(angleResult);
267 transform.translate(-corResult.x(), -corResult.y());
268 }
else if (tc1.type == TransformComponent::Skew) {
269 QPointF skew1 = QPointF(tc1.values.at(0), tc1.values.at(1));
270 QPointF skew2 = QPointF(tc2.values.at(0), tc2.values.at(1));
271 QPointF skewResult = pointInterpolator(skew1, skew2, t);
272 transform.shear(qTan(qDegreesToRadians(skewResult.x())),
273 qTan(qDegreesToRadians(skewResult.y())));
278 m_interpolatedValue = transform;