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);
90QSvgAbstractAnimatedProperty *QSvgAbstractAnimatedProperty::createAnimatedProperty(
const QString &name)
92 if (animatableProperties->isEmpty())
95 if (!animatableProperties->contains(name)) {
96 qCDebug(lcSvgAnimatedProperty) <<
"Property : " << name <<
" is not animatable";
100 QSvgAbstractAnimatedProperty::Type type = animatableProperties->value(name);
101 QSvgAbstractAnimatedProperty *prop =
nullptr;
104 case QSvgAbstractAnimatedProperty::Color:
105 prop =
new QSvgAnimatedPropertyColor(name);
107 case QSvgAbstractAnimatedProperty::Transform:
108 prop =
new QSvgAnimatedPropertyTransform(name);
110 case QSvgAbstractAnimatedProperty::Float:
111 prop =
new QSvgAnimatedPropertyFloat(name);
139void QSvgAnimatedPropertyColor::interpolate(uint index, qreal t)
const
141 QColor c1 = m_colors.at(index - 1);
142 QColor c2 = m_colors.at(index);
144 int alpha = q_lerp(c1.alpha(), c2.alpha(), t);
145 int red = q_lerp(c1.red(), c2.red(), t);
146 int green = q_lerp(c1.green(), c2.green(), t);
147 int blue = q_lerp(c1.blue(), c2.blue(), t);
149 m_interpolatedValue = QColor(red, green, blue, alpha);
172void QSvgAnimatedPropertyFloat::interpolate(uint index, qreal t)
const
174 if (index >= (uint)m_keyFrames.size()) {
175 qCWarning(lcSvgAnimatedProperty) <<
"Invalid index for key frames";
179 qreal float1 = m_values.at(index - 1);
180 qreal float2 = m_values.at(index);
182 m_interpolatedValue = q_lerp(float1, float2, t);
217void QSvgAnimatedPropertyTransform::interpolate(uint index, qreal t)
const
219 if (index >= (uint)m_keyFrames.size()) {
220 qCWarning(lcSvgAnimatedProperty) <<
"Invalid index for key frames";
224 if (!m_transformCount ||
225 ((m_components.size() / qsizetype(m_transformCount)) != m_keyFrames.size())) {
229 QTransform transform = QTransform();
231 qsizetype startIndex = (index - 1) * qsizetype(m_transformCount);
232 qsizetype endIndex = index * qsizetype(m_transformCount);
234 for (quint32 i = 0; i < m_transformCount; i++) {
235 TransformComponent tc1 = m_components.at(startIndex + i);
236 TransformComponent tc2 = m_components.at(endIndex + i);
237 if (tc1.type == tc2.type) {
238 if (tc1.type == TransformComponent::Translate) {
239 QPointF t1 = QPointF(tc1.values.at(0), tc1.values.at(1));
240 QPointF t2 = QPointF(tc2.values.at(0), tc2.values.at(1));
241 QPointF tr = pointInterpolator(t1, t2, t);
242 transform.translate(tr.x(), tr.y());
243 }
else if (tc1.type == TransformComponent::Scale) {
244 QPointF s1 = QPointF(tc1.values.at(0), tc1.values.at(1));
245 QPointF s2 = QPointF(tc2.values.at(0), tc2.values.at(1));
246 QPointF sr = pointInterpolator(s1, s2, t);
247 transform.scale(sr.x(), sr.y());
248 }
else if (tc1.type == TransformComponent::Rotate) {
249 QPointF cor1 = QPointF(tc1.values.at(1), tc1.values.at(2));
250 QPointF cor2 = QPointF(tc2.values.at(1), tc2.values.at(2));
251 QPointF corResult = pointInterpolator(cor1, cor2, t);
252 qreal angle1 = tc1.values.at(0);
253 qreal angle2 = tc2.values.at(0);
254 qreal angleResult = q_lerp(angle1, angle2, t);
255 transform.translate(corResult.x(), corResult.y());
256 transform.rotate(angleResult);
257 transform.translate(-corResult.x(), -corResult.y());
258 }
else if (tc1.type == TransformComponent::Skew) {
259 QPointF skew1 = QPointF(tc1.values.at(0), tc1.values.at(1));
260 QPointF skew2 = QPointF(tc2.values.at(0), tc2.values.at(1));
261 QPointF skewResult = pointInterpolator(skew1, skew2, t);
262 transform.shear(qTan(qDegreesToRadians(skewResult.x())),
263 qTan(qDegreesToRadians(skewResult.y())));
268 m_interpolatedValue = transform;