20 animatableProperties->insert(QStringLiteral(
"fill"), QSvgAbstractAnimatedProperty::Color);
21 animatableProperties->insert(QStringLiteral(
"fill-opacity"), QSvgAbstractAnimatedProperty::Float);
22 animatableProperties->insert(QStringLiteral(
"stroke-opacity"), QSvgAbstractAnimatedProperty::Float);
23 animatableProperties->insert(QStringLiteral(
"stroke"), QSvgAbstractAnimatedProperty::Color);
24 animatableProperties->insert(QStringLiteral(
"opacity"), QSvgAbstractAnimatedProperty::Float);
25 animatableProperties->insert(QStringLiteral(
"transform"), QSvgAbstractAnimatedProperty::Transform);
87QSvgAbstractAnimatedProperty *QSvgAbstractAnimatedProperty::createAnimatedProperty(
const QString &name)
89 if (animatableProperties->isEmpty())
92 if (!animatableProperties->contains(name)) {
93 qCDebug(lcSvgAnimatedProperty) <<
"Property : " << name <<
" is not animatable";
97 QSvgAbstractAnimatedProperty::Type type = animatableProperties->value(name);
98 QSvgAbstractAnimatedProperty *prop =
nullptr;
101 case QSvgAbstractAnimatedProperty::Color:
102 prop =
new QSvgAnimatedPropertyColor(name);
104 case QSvgAbstractAnimatedProperty::Transform:
105 prop =
new QSvgAnimatedPropertyTransform(name);
107 case QSvgAbstractAnimatedProperty::Float:
108 prop =
new QSvgAnimatedPropertyFloat(name);
136void QSvgAnimatedPropertyColor::interpolate(uint index, qreal t)
const
138 QColor c1 = m_colors.at(index - 1);
139 QColor c2 = m_colors.at(index);
141 int alpha = q_lerp(c1.alpha(), c2.alpha(), t);
142 int red = q_lerp(c1.red(), c2.red(), t);
143 int green = q_lerp(c1.green(), c2.green(), t);
144 int blue = q_lerp(c1.blue(), c2.blue(), t);
146 m_interpolatedValue = QColor(red, green, blue, alpha);
169void QSvgAnimatedPropertyFloat::interpolate(uint index, qreal t)
const
171 if (index >= (uint)m_keyFrames.size()) {
172 qCWarning(lcSvgAnimatedProperty) <<
"Invalid index for key frames";
176 qreal float1 = m_values.at(index - 1);
177 qreal float2 = m_values.at(index);
179 m_interpolatedValue = q_lerp(float1, float2, t);
214void QSvgAnimatedPropertyTransform::interpolate(uint index, qreal t)
const
216 if (index >= (uint)m_keyFrames.size()) {
217 qCWarning(lcSvgAnimatedProperty) <<
"Invalid index for key frames";
221 if (!m_transformCount ||
222 ((m_components.size() / qsizetype(m_transformCount)) != m_keyFrames.size())) {
226 QTransform transform = QTransform();
228 qsizetype startIndex = (index - 1) * qsizetype(m_transformCount);
229 qsizetype endIndex = index * qsizetype(m_transformCount);
231 for (quint32 i = 0; i < m_transformCount; i++) {
232 TransformComponent tc1 = m_components.at(startIndex + i);
233 TransformComponent tc2 = m_components.at(endIndex + i);
234 if (tc1.type == tc2.type) {
235 if (tc1.type == TransformComponent::Translate) {
236 QPointF t1 = QPointF(tc1.values.at(0), tc1.values.at(1));
237 QPointF t2 = QPointF(tc2.values.at(0), tc2.values.at(1));
238 QPointF tr = pointInterpolator(t1, t2, t);
239 transform.translate(tr.x(), tr.y());
240 }
else if (tc1.type == TransformComponent::Scale) {
241 QPointF s1 = QPointF(tc1.values.at(0), tc1.values.at(1));
242 QPointF s2 = QPointF(tc2.values.at(0), tc2.values.at(1));
243 QPointF sr = pointInterpolator(s1, s2, t);
244 transform.scale(sr.x(), sr.y());
245 }
else if (tc1.type == TransformComponent::Rotate) {
246 QPointF cor1 = QPointF(tc1.values.at(1), tc1.values.at(2));
247 QPointF cor2 = QPointF(tc2.values.at(1), tc2.values.at(2));
248 QPointF corResult = pointInterpolator(cor1, cor2, t);
249 qreal angle1 = tc1.values.at(0);
250 qreal angle2 = tc2.values.at(0);
251 qreal angleResult = q_lerp(angle1, angle2, t);
252 transform.translate(corResult.x(), corResult.y());
253 transform.rotate(angleResult);
254 transform.translate(-corResult.x(), -corResult.y());
255 }
else if (tc1.type == TransformComponent::Skew) {
256 QPointF skew1 = QPointF(tc1.values.at(0), tc1.values.at(1));
257 QPointF skew2 = QPointF(tc2.values.at(0), tc2.values.at(1));
258 QPointF skewResult = pointInterpolator(skew1, skew2, t);
259 transform.shear(qTan(qDegreesToRadians(skewResult.x())),
260 qTan(qDegreesToRadians(skewResult.y())));
265 m_interpolatedValue = transform;