Beispiel #1
0
void Window::createCurveIcons()
{
    QPixmap pix(m_iconSize);
    QPainter painter(&pix);
    QLinearGradient gradient(0,0, 0, m_iconSize.height());
    gradient.setColorAt(0.0, QColor(240, 240, 240));
    gradient.setColorAt(1.0, QColor(224, 224, 224));
    QBrush brush(gradient);
    const QMetaObject &mo = QEasingCurve::staticMetaObject;
    QMetaEnum metaEnum = mo.enumerator(mo.indexOfEnumerator("Type"));
    // Skip QEasingCurve::Custom
    for (int i = 0; i < QEasingCurve::NCurveTypes - 1; ++i) {
        painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush);
        QEasingCurve curve = createEasingCurve((QEasingCurve::Type) i);
        painter.setPen(QColor(0, 0, 255, 64));
        qreal xAxis = m_iconSize.height()/1.5;
        qreal yAxis = m_iconSize.width()/3;
        painter.drawLine(0, xAxis, m_iconSize.width(),  xAxis);
        painter.drawLine(yAxis, 0, yAxis, m_iconSize.height());

        qreal curveScale = m_iconSize.height()/2;

        painter.setPen(Qt::NoPen);

        // start point
        painter.setBrush(Qt::red);
        QPoint start(yAxis, xAxis - curveScale * curve.valueForProgress(0));
        painter.drawRect(start.x() - 1, start.y() - 1, 3, 3);

        // end point
        painter.setBrush(Qt::blue);
        QPoint end(yAxis + curveScale, xAxis - curveScale * curve.valueForProgress(1));
        painter.drawRect(end.x() - 1, end.y() - 1, 3, 3);

        QPainterPath curvePath;
        curvePath.moveTo(start);
        for (qreal t = 0; t <= 1.0; t+=1.0/curveScale) {
            QPoint to;
            to.setX(yAxis + curveScale * t);
            to.setY(xAxis - curveScale * curve.valueForProgress(t));
            curvePath.lineTo(to);
        }
        painter.setRenderHint(QPainter::Antialiasing, true);
        painter.strokePath(curvePath, QColor(32, 32, 32));
        painter.setRenderHint(QPainter::Antialiasing, false);
        QListWidgetItem *item = new QListWidgetItem;
        item->setIcon(QIcon(pix));
        item->setText(metaEnum.key(i));
        m_ui.easingCurvePicker->addItem(item);
    }
}
Beispiel #2
0
QString GenEasingCurveCode(QEasingCurve easingCurve, QString strLabel)
{
	QString str = strLabel + "\r\n";
	for (int i = 0; i <= 1000; ++i)
	{
		str += QString("%1f, ").arg(easingCurve.valueForProgress((i * 1.0 / 1000)));
		if (i % 10 == 0 && i != 0)
		{
			str += "\r\n";
		}
	}
	str += "\r\n";
	return str;
}
slideShowEngine::AnimationState slideShowEngine::applyAnimation()
{
effect e;
QEasingCurve curve;
qreal currentValue;
Pixmap *item;

    if(m_currentStep==EnterAnimation)
        e=m_currentNode.enterEffect();
    else
        if(m_currentStep==DisplayAnimation)
            e=m_currentNode.displayEffect();
        else
            if(m_currentStep==ExitAnimation)
                e=m_currentNode.exitEffect();

    int duration=e.duration();
    //int elapsed=m_stepCurrentTime;
    curve.setPeriod(duration);
    qreal startVal=qreal(e.startValue());
    qreal endVal=qreal(e.endValue());

    curve.setType(e.easingCurve());
    //qreal valore=qreal(m_stepCurrentTime*TIMER_ANIMATION);
    qreal valore=qreal(m_stepCurrentTime);
    //qreal valore=qreal(m_stepCurrentTime*10);
    valore=valore/(qreal(duration));
    //valore=valore/10;
    //currentValue=curve.valueForProgress(valore);
    currentValue=endVal+(1.0-curve.valueForProgress(valore))*(startVal-endVal);    


    item=m_PixmapList[m_currentSlideIndex];

    if(e.effectType()=="pos")
        item->setProperty(e.effectType().toLatin1(),QVariant(QPointF(currentValue,0)));
    else
        item->setProperty(e.effectType().toLatin1(),QVariant(currentValue));


    //if(m_stepCurrentTime*TIMER_ANIMATION < e.duration()/**10*/)
    if(m_stepCurrentTime < duration)
    //if(m_stepCurrentTime*10 < e.duration()/**10*/)
        return RunningAnimation;
    else
        return EndAnimation;

}
Beispiel #4
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);
}