- // parse keyframes and adjust values
- const QStringList keyframes = parameter.attribute("keyframes").split(';', QString::SkipEmptyParts);
- QMap <int, double> kfr;
- int pos;
- double val;
- foreach(const QString &str, keyframes) {
- pos = str.section(':', 0, 0).toInt();
- val = str.section(':', 1, 1).toDouble();
- if (pos == previous) {
- // first or last keyframe
- kfr[current] = val;
- modified = true;
- } else {
- if ((fromStart && pos >= current) || (!fromStart && pos <= current)) {
- // only keyframes in range
- kfr[pos] = val;
- modified = true;
+
+ QMap<int, double>::iterator i = keyframes.end();
+ int lastPos = -1;
+ double lastValue = 0;
+ qreal relPos;
+
+ /*
+ * Take care of resize from start
+ */
+ bool startFound = false;
+ while (i-- != keyframes.begin()) {
+ if (i.key() < in && !startFound) {
+ startFound = true;
+ if (lastPos < 0) {
+ keyframes[in] = i.value();
+ } else {
+ relPos = (in - i.key()) / (qreal)(lastPos - i.key() + 1);
+ keyframes[in] = i.value() + (lastValue - i.value()) * relPos;