eine interpolations-Erweiterung für QString:
Code: Alles auswählen
QVariant interpolated(const QVariant &from, const QVariant &to, qreal progress) {
if (from.type()==QVariant::String && to.type()==QVariant::String) {
progress=qBound(0.0, progress, 1.0);
QString f=from.toString();
QString t=to.toString();
QString n=f;
const int size=f.size()+(qreal)(t.size()-f.size())*progress;
if (size>n.size()) {
n+=t.mid(n.size());
}
n=n.left(size);
for (int pos=0; pos<qMin(f.size(), t.size()); pos++) {
const QChar fc=f.at(pos);
const QChar tc=t.at(pos);
const int nc=fc.unicode()+(qreal)(tc.unicode()-fc.unicode())*progress;
n.replace(pos, 1, QChar(nc));
}
return n.left(size);
}
return QVariant();
};