mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 02:42:55 +00:00
drop support for custom QEasingCurve type
use one of the animation classes instead if such is required Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
97d884a9cc
commit
99cec4d89e
4 changed files with 4 additions and 111 deletions
|
@ -471,7 +471,6 @@ void QProcessPrivate::startProcess()
|
||||||
char **argv = new char *[arguments.count() + 2];
|
char **argv = new char *[arguments.count() + 2];
|
||||||
argv[arguments.count() + 1] = 0;
|
argv[arguments.count() + 1] = 0;
|
||||||
|
|
||||||
|
|
||||||
// Encode the program name.
|
// Encode the program name.
|
||||||
QByteArray encodedProgramName;
|
QByteArray encodedProgramName;
|
||||||
// If the program does not specify a path, try to find it.
|
// If the program does not specify a path, try to find it.
|
||||||
|
|
|
@ -218,18 +218,9 @@
|
||||||
\value OutCurve
|
\value OutCurve
|
||||||
\value SineCurve
|
\value SineCurve
|
||||||
\value CosineCurve
|
\value CosineCurve
|
||||||
\value Custom This is returned if the user specified a custom curve type with
|
|
||||||
setCustomType(). Note that you cannot call setType() with this value,
|
|
||||||
but type() can return it.
|
|
||||||
\omitvalue NCurveTypes
|
\omitvalue NCurveTypes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
|
||||||
\typedef QEasingCurve::EasingFunction
|
|
||||||
|
|
||||||
This is a typedef for a pointer to a function.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qeasingcurve.h"
|
#include "qeasingcurve.h"
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
|
@ -254,17 +245,14 @@ class QEasingCurvePrivate
|
||||||
public:
|
public:
|
||||||
QEasingCurvePrivate()
|
QEasingCurvePrivate()
|
||||||
: type(QEasingCurve::Linear),
|
: type(QEasingCurve::Linear),
|
||||||
func(nullptr),
|
|
||||||
per(s_defaultperiod), amp(s_defaultamplitude), over(s_defaultovershoot)
|
per(s_defaultperiod), amp(s_defaultamplitude), over(s_defaultovershoot)
|
||||||
{ }
|
{ }
|
||||||
QEasingCurvePrivate(const QEasingCurvePrivate &other)
|
QEasingCurvePrivate(const QEasingCurvePrivate &other)
|
||||||
: type(other.type),
|
: type(other.type),
|
||||||
func(other.func),
|
|
||||||
per(other.per), amp(other.amp), over(other.over)
|
per(other.per), amp(other.amp), over(other.over)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QEasingCurve::Type type;
|
QEasingCurve::Type type;
|
||||||
QEasingCurve::EasingFunction func;
|
|
||||||
qreal per;
|
qreal per;
|
||||||
qreal amp;
|
qreal amp;
|
||||||
qreal over;
|
qreal over;
|
||||||
|
@ -302,7 +290,6 @@ QEasingCurve &QEasingCurve::operator=(const QEasingCurve &other)
|
||||||
{
|
{
|
||||||
if (*this != other) {
|
if (*this != other) {
|
||||||
d_ptr->type = other.d_ptr->type;
|
d_ptr->type = other.d_ptr->type;
|
||||||
d_ptr->func = other.d_ptr->func;
|
|
||||||
d_ptr->per = other.d_ptr->per;
|
d_ptr->per = other.d_ptr->per;
|
||||||
d_ptr->amp = other.d_ptr->amp;
|
d_ptr->amp = other.d_ptr->amp;
|
||||||
d_ptr->over = other.d_ptr->over;
|
d_ptr->over = other.d_ptr->over;
|
||||||
|
@ -316,7 +303,7 @@ QEasingCurve &QEasingCurve::operator=(const QEasingCurve &other)
|
||||||
*/
|
*/
|
||||||
bool QEasingCurve::operator==(const QEasingCurve &other) const
|
bool QEasingCurve::operator==(const QEasingCurve &other) const
|
||||||
{
|
{
|
||||||
bool res = (d_ptr->type == other.d_ptr->type && d_ptr->func == other.d_ptr->func);
|
bool res = (d_ptr->type == other.d_ptr->type);
|
||||||
if (res) {
|
if (res) {
|
||||||
res = qFuzzyCompare(period(), other.period()) &&
|
res = qFuzzyCompare(period(), other.period()) &&
|
||||||
qFuzzyCompare(amplitude(), other.amplitude()) &&
|
qFuzzyCompare(amplitude(), other.amplitude()) &&
|
||||||
|
@ -414,43 +401,11 @@ QEasingCurve::Type QEasingCurve::type() const
|
||||||
*/
|
*/
|
||||||
void QEasingCurve::setType(Type type)
|
void QEasingCurve::setType(Type type)
|
||||||
{
|
{
|
||||||
if (Q_UNLIKELY(type < Linear || type >= QEasingCurve::NCurveTypes - 1)) {
|
if (Q_UNLIKELY(type < Linear || type >= QEasingCurve::NCurveTypes)) {
|
||||||
qWarning("QEasingCurve: Invalid curve type %d", type);
|
qWarning("QEasingCurve: Invalid curve type %d", type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
d_ptr->type = type;
|
d_ptr->type = type;
|
||||||
d_ptr->func = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets a custom easing curve that is defined by the user in the function \a func.
|
|
||||||
The signature of the function is qreal myEasingFunction(qreal progress),
|
|
||||||
where \e progress and the return value is considered to be normalized between 0 and 1.
|
|
||||||
(In some cases the return value can be outside that range)
|
|
||||||
After calling this function type() will return QEasingCurve::Custom.
|
|
||||||
\a func cannot be zero.
|
|
||||||
|
|
||||||
\sa customType()
|
|
||||||
\sa valueForProgress()
|
|
||||||
*/
|
|
||||||
void QEasingCurve::setCustomType(EasingFunction func)
|
|
||||||
{
|
|
||||||
if (Q_UNLIKELY(!func)) {
|
|
||||||
qWarning("QEasingCurve: Function pointer must not be null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
d_ptr->type = QEasingCurve::Custom;
|
|
||||||
d_ptr->func = func;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Returns the function pointer to the custom easing curve.
|
|
||||||
If type() does not return QEasingCurve::Custom, this function
|
|
||||||
will return 0.
|
|
||||||
*/
|
|
||||||
QEasingCurve::EasingFunction QEasingCurve::customType() const
|
|
||||||
{
|
|
||||||
return (d_ptr->type == QEasingCurve::Custom ? d_ptr->func : nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOUND_PERIOD(per) (per < 0) ? s_defaultperiod : per
|
#define BOUND_PERIOD(per) (per < 0) ? s_defaultperiod : per
|
||||||
|
@ -603,12 +558,6 @@ qreal QEasingCurve::valueForProgress(qreal progress) const
|
||||||
case QEasingCurve::OutInBack: {
|
case QEasingCurve::OutInBack: {
|
||||||
return easeOutInBack(progress, BOUND_OVERSHOOT(d_ptr->over));
|
return easeOutInBack(progress, BOUND_OVERSHOOT(d_ptr->over));
|
||||||
}
|
}
|
||||||
case QEasingCurve::Custom: {
|
|
||||||
if (Q_LIKELY(d_ptr->func)) {
|
|
||||||
return d_ptr->func(progress);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEasingCurve::NCurveTypes: {
|
case QEasingCurve::NCurveTypes: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -759,9 +708,6 @@ static const char* const easingTypeName(const QEasingCurve::Type type)
|
||||||
case QEasingCurve::OutInBack: {
|
case QEasingCurve::OutInBack: {
|
||||||
return "OutInBack";
|
return "OutInBack";
|
||||||
}
|
}
|
||||||
case QEasingCurve::Custom: {
|
|
||||||
return "Custom";
|
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
return "";
|
return "";
|
||||||
|
@ -800,7 +746,6 @@ QDebug operator<<(QDebug debug, const QEasingCurve &easing)
|
||||||
QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing)
|
QDataStream &operator<<(QDataStream &stream, const QEasingCurve &easing)
|
||||||
{
|
{
|
||||||
stream << quint8(easing.d_ptr->type);
|
stream << quint8(easing.d_ptr->type);
|
||||||
stream << quint64(quintptr(easing.d_ptr->func));
|
|
||||||
stream << easing.d_ptr->per;
|
stream << easing.d_ptr->per;
|
||||||
stream << easing.d_ptr->amp;
|
stream << easing.d_ptr->amp;
|
||||||
stream << easing.d_ptr->over;
|
stream << easing.d_ptr->over;
|
||||||
|
@ -821,10 +766,6 @@ QDataStream &operator>>(QDataStream &stream, QEasingCurve &easing)
|
||||||
stream >> int_type;
|
stream >> int_type;
|
||||||
easing.setType(static_cast<QEasingCurve::Type>(int_type));
|
easing.setType(static_cast<QEasingCurve::Type>(int_type));
|
||||||
|
|
||||||
quint64 ptr_func;
|
|
||||||
stream >> ptr_func;
|
|
||||||
easing.d_ptr->func = QEasingCurve::EasingFunction(quintptr(ptr_func));
|
|
||||||
|
|
||||||
stream >> easing.d_ptr->per;
|
stream >> easing.d_ptr->per;
|
||||||
stream >> easing.d_ptr->amp;
|
stream >> easing.d_ptr->amp;
|
||||||
stream >> easing.d_ptr->over;
|
stream >> easing.d_ptr->over;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
InBack, OutBack, InOutBack, OutInBack,
|
InBack, OutBack, InOutBack, OutInBack,
|
||||||
InBounce, OutBounce, InOutBounce, OutInBounce,
|
InBounce, OutBounce, InOutBounce, OutInBounce,
|
||||||
InCurve, OutCurve, SineCurve, CosineCurve,
|
InCurve, OutCurve, SineCurve, CosineCurve,
|
||||||
Custom, NCurveTypes
|
NCurveTypes
|
||||||
};
|
};
|
||||||
|
|
||||||
QEasingCurve(Type type = Linear);
|
QEasingCurve(Type type = Linear);
|
||||||
|
@ -72,9 +72,6 @@ public:
|
||||||
|
|
||||||
Type type() const;
|
Type type() const;
|
||||||
void setType(Type type);
|
void setType(Type type);
|
||||||
typedef qreal (*EasingFunction)(qreal progress);
|
|
||||||
void setCustomType(EasingFunction func);
|
|
||||||
EasingFunction customType() const;
|
|
||||||
|
|
||||||
qreal valueForProgress(qreal progress) const;
|
qreal valueForProgress(qreal progress) const;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -43,7 +43,6 @@ private slots:
|
||||||
void propertyDefaults();
|
void propertyDefaults();
|
||||||
void valueForProgress_data();
|
void valueForProgress_data();
|
||||||
void valueForProgress();
|
void valueForProgress();
|
||||||
void setCustomType();
|
|
||||||
void operators();
|
void operators();
|
||||||
void properties();
|
void properties();
|
||||||
void metaTypes();
|
void metaTypes();
|
||||||
|
@ -107,10 +106,6 @@ void tst_QEasingCurve::type()
|
||||||
.arg(QEasingCurve::NCurveTypes).toLatin1().constData());
|
.arg(QEasingCurve::NCurveTypes).toLatin1().constData());
|
||||||
curve.setType(QEasingCurve::NCurveTypes);
|
curve.setType(QEasingCurve::NCurveTypes);
|
||||||
QCOMPARE(curve.type(), QEasingCurve::InCubic);
|
QCOMPARE(curve.type(), QEasingCurve::InCubic);
|
||||||
QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
|
|
||||||
.arg(QEasingCurve::Custom).toLatin1().constData());
|
|
||||||
curve.setType(QEasingCurve::Custom);
|
|
||||||
QCOMPARE(curve.type(), QEasingCurve::InCubic);
|
|
||||||
QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
|
QTest::ignoreMessage(QtWarningMsg, QString::fromAscii("QEasingCurve: Invalid curve type %1")
|
||||||
.arg(-1).toLatin1().constData());
|
.arg(-1).toLatin1().constData());
|
||||||
curve.setType((QEasingCurve::Type)-1);
|
curve.setType((QEasingCurve::Type)-1);
|
||||||
|
@ -380,7 +375,7 @@ void tst_QEasingCurve::valueForProgress()
|
||||||
// used to generate data tables...
|
// used to generate data tables...
|
||||||
QFile out;
|
QFile out;
|
||||||
out.open(stdout, QIODevice::WriteOnly);
|
out.open(stdout, QIODevice::WriteOnly);
|
||||||
for (int c = QEasingCurve::Linear; c < QEasingCurve::NCurveTypes - 1; ++c) {
|
for (int c = QEasingCurve::Linear; c < QEasingCurve::NCurveTypes; ++c) {
|
||||||
QEasingCurve curve((QEasingCurve::Type)c);
|
QEasingCurve curve((QEasingCurve::Type)c);
|
||||||
QMetaObject mo = QEasingCurve::staticMetaObject;
|
QMetaObject mo = QEasingCurve::staticMetaObject;
|
||||||
QString strCurve = QLatin1String(mo.enumerator(mo.indexOfEnumerator("Type")).key(c));
|
QString strCurve = QLatin1String(mo.enumerator(mo.indexOfEnumerator("Type")).key(c));
|
||||||
|
@ -420,50 +415,11 @@ void tst_QEasingCurve::valueForProgress()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static qreal discreteEase(qreal progress)
|
|
||||||
{
|
|
||||||
return qFloor(progress * 10) / qreal(10.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QEasingCurve::setCustomType()
|
|
||||||
{
|
|
||||||
QEasingCurve curve;
|
|
||||||
curve.setCustomType(&discreteEase);
|
|
||||||
QCOMPARE(curve.type(), QEasingCurve::Custom);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.0), 0.0);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.05), 0.0);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.10), 0.1);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.15), 0.1);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.20), 0.2);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.25), 0.2);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.30), 0.3);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.35), 0.3);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.999999), 0.9);
|
|
||||||
|
|
||||||
curve.setType(QEasingCurve::Linear);
|
|
||||||
QCOMPARE(curve.type(), QEasingCurve::Linear);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.0), 0.0);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.1), 0.1);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.5), 0.5);
|
|
||||||
QCOMPARE(curve.valueForProgress(0.99), 0.99);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QEasingCurve::operators()
|
void tst_QEasingCurve::operators()
|
||||||
{
|
{
|
||||||
// operator=
|
// operator=
|
||||||
QEasingCurve curve;
|
QEasingCurve curve;
|
||||||
QEasingCurve curve2;
|
QEasingCurve curve2;
|
||||||
curve.setCustomType(&discreteEase);
|
|
||||||
curve2 = curve;
|
|
||||||
QCOMPARE(curve2.type(), QEasingCurve::Custom);
|
|
||||||
QCOMPARE(curve2.valueForProgress(0.0), 0.0);
|
|
||||||
QCOMPARE(curve2.valueForProgress(0.05), 0.0);
|
|
||||||
QCOMPARE(curve2.valueForProgress(0.15), 0.1);
|
|
||||||
QCOMPARE(curve2.valueForProgress(0.25), 0.2);
|
|
||||||
QCOMPARE(curve2.valueForProgress(0.35), 0.3);
|
|
||||||
QCOMPARE(curve2.valueForProgress(0.999999), 0.9);
|
|
||||||
|
|
||||||
// operator==
|
|
||||||
curve.setType(QEasingCurve::InBack);
|
curve.setType(QEasingCurve::InBack);
|
||||||
curve2 = curve;
|
curve2 = curve;
|
||||||
curve2.setOvershoot(qreal(1.70158));
|
curve2.setOvershoot(qreal(1.70158));
|
||||||
|
|
Loading…
Add table
Reference in a new issue