Beispiel #1
0
Window::Window(QWidget *parent)
    : QWidget(parent),
    m_iconSize(64, 64)
{
    m_ui.setupUi(this);
    QButtonGroup *buttonGroup = findChild<QButtonGroup *>();     // ### workaround for uic in 4.4
    m_ui.easingCurvePicker->setIconSize(m_iconSize);
    m_ui.easingCurvePicker->setMinimumHeight(m_iconSize.height() + 50);
    buttonGroup->setId(m_ui.lineRadio, 0);
    buttonGroup->setId(m_ui.circleRadio, 1);

    QEasingCurve dummy;
    m_ui.periodSpinBox->setValue(dummy.period());
    m_ui.amplitudeSpinBox->setValue(dummy.amplitude());
    m_ui.overshootSpinBox->setValue(dummy.overshoot());

    connect(m_ui.easingCurvePicker, SIGNAL(currentRowChanged(int)), this, SLOT(curveChanged(int)));
    connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(pathChanged(int)));
    connect(m_ui.periodSpinBox, SIGNAL(valueChanged(double)), this, SLOT(periodChanged(double)));
    connect(m_ui.amplitudeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(amplitudeChanged(double)));
    connect(m_ui.overshootSpinBox, SIGNAL(valueChanged(double)), this, SLOT(overshootChanged(double)));
    createCurveIcons();

    QPixmap pix(QLatin1String(":/images/qt-logo.png"));
    m_item = new PixmapItem(pix);
    m_scene.addItem(m_item);
    m_ui.graphicsView->setScene(&m_scene);

    m_anim = new Animation(m_item, "pos");
    m_anim->setEasingCurve(QEasingCurve::OutBounce);
    m_ui.easingCurvePicker->setCurrentRow(int(QEasingCurve::OutBounce));

    startAnimation();
}
void QtViewportInteractionEngine::animateItemRectVisible(const QRectF& itemRect)
{
    ASSERT(m_scaleAnimation->state() == QAbstractAnimation::Stopped);

    ASSERT(!scrollAnimationActive());
    if (scrollAnimationActive())
        return;

    QRectF currentItemRectVisible = m_viewport->mapRectToWebContent(m_viewport->boundingRect());
    if (itemRect == currentItemRectVisible)
        return;

    // FIXME: Investigate why that animation doesn't run when we are unfocused.
    if (!m_viewport->isVisible() || !m_viewport->hasFocus()) {
        // Apply the end result immediately when we are non-visible.
        setItemRectVisible(itemRect);
        return;
    }

    QEasingCurve easingCurve;
    easingCurve.setCustomType(physicalOvershoot);

    m_scaleAnimation->setDuration(kScaleAnimationDurationMillis);
    m_scaleAnimation->setEasingCurve(easingCurve);

    m_scaleAnimation->setStartValue(currentItemRectVisible);
    m_scaleAnimation->setEndValue(itemRect);

    m_scaleAnimation->start();
}
static PyObject *meth_QEasingCurve_addTCBSegment(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        const QPointF* a0;
        int a0State = 0;
        qreal a1;
        qreal a2;
        qreal a3;
        QEasingCurve *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1ddd", &sipSelf, sipType_QEasingCurve, &sipCpp, sipType_QPointF, &a0, &a0State, &a1, &a2, &a3))
        {
            sipCpp->addTCBSegment(*a0,a1,a2,a3);
            sipReleaseType(const_cast<QPointF *>(a0),sipType_QPointF,a0State);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QEasingCurve, sipName_addTCBSegment, doc_QEasingCurve_addTCBSegment);

    return NULL;
}
static PyObject *meth_QEasingCurve_setCustomType(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        PyObject * a0;
        QEasingCurve *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BF", &sipSelf, sipType_QEasingCurve, &sipCpp, &a0))
        {
            sipErrorState sipError = sipErrorNone;

#line 232 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\sip/QtCore/qeasingcurve.sip"
        int i;
        ec_custom_type *ct;
        
        for (i = 0; i < ec_nr_custom_types; ++i)
        {
            ct = &ec_custom_types[i];
        
            if (!ct->py_func || ct->py_func == a0)
                break;
        }
        
        if (i == ec_nr_custom_types)
        {
            PyErr_Format(PyExc_ValueError, "a maximum of %d different easing functions are supported", ec_nr_custom_types);
            sipError = sipErrorFail;
        }
        else
        {
            if (!ct->py_func)
            {
                ct->py_func = a0;
                Py_INCREF(a0);
            }
        
            sipCpp->setCustomType(ct->func);
        }
#line 401 "C:\\Users\\marcus\\Downloads\\PyQt-gpl-5.4\\PyQt-gpl-5.4\\QtCore/sipQtCoreQEasingCurve.cpp"

            if (sipError == sipErrorFail)
                return 0;

            if (sipError == sipErrorNone)
            {
            Py_INCREF(Py_None);
            return Py_None;
            }

            sipAddException(sipError, &sipParseErr);
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QEasingCurve, sipName_setCustomType, doc_QEasingCurve_setCustomType);

    return NULL;
}
Beispiel #5
0
// Test getting and setting easing properties via the metaobject system.
void tst_QEasingCurve::properties()
{
    tst_QEasingProperties obj;

    QEasingCurve inOutBack(QEasingCurve::InOutBack);
    qreal overshoot = 1.5;
    inOutBack.setOvershoot(overshoot);
    qreal amplitude = inOutBack.amplitude();
    qreal period = inOutBack.period();

    obj.setEasing(inOutBack);

    QEasingCurve easing = qVariantValue<QEasingCurve>(obj.property("easing"));
    QCOMPARE(easing.type(), QEasingCurve::InOutBack);
    QCOMPARE(easing.overshoot(), overshoot);
    QCOMPARE(easing.amplitude(), amplitude);
    QCOMPARE(easing.period(), period);

    QEasingCurve linear(QEasingCurve::Linear);
    overshoot = linear.overshoot();
    amplitude = linear.amplitude();
    period = linear.period();

    obj.setProperty("easing",
                    qVariantFromValue(QEasingCurve(QEasingCurve::Linear)));

    easing = qVariantValue<QEasingCurve>(obj.property("easing"));
    QCOMPARE(easing.type(), QEasingCurve::Linear);
    QCOMPARE(easing.overshoot(), overshoot);
    QCOMPARE(easing.amplitude(), amplitude);
    QCOMPARE(easing.period(), period);
}
Beispiel #6
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);
    }
}
void PropertiesEditorItem::slotOpenEasingCurveEditor()
{
    EasingCurveEditor *editor = new EasingCurveEditor(parent());
    editor->setEasingCurve(mProperty.read(mObject.data()).toEasingCurve());
    if (editor->exec() == QDialog::Accepted) {
        QEasingCurve curve = editor->easingCurve();
        mProperty.write(mObject.data(), curve);

        QPushButton *button = qobject_cast<QPushButton*>(mWidget.data());
        button->setText(curve.staticMetaObject.enumerator(0).valueToKey(curve.type()));
    }

    delete editor;
}
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;

}
void tst_QEasingCurve::operators()
{
    // operator=
    QEasingCurve curve;
    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);
    curve2 = curve;
    curve2.setOvershoot(qreal(1.70158f));
    QCOMPARE(curve.overshoot(), curve2.overshoot());
    QVERIFY(curve2 == curve);

    curve.setOvershoot(3.0);
    QVERIFY(curve2 != curve);
    curve2.setOvershoot(3.0);
    QVERIFY(curve2 == curve);

    curve2.setType(QEasingCurve::Linear);
    QCOMPARE(curve.overshoot(), curve2.overshoot());
    QVERIFY(curve2 != curve);
    curve2.setType(QEasingCurve::InBack);
    QCOMPARE(curve.overshoot(), curve2.overshoot());
    QVERIFY(curve2 == curve);
}
Beispiel #10
0
/*!
    Compare this easing curve with \a other and returns true if they are
    equal. It will also compare the properties of a curve.
 */
bool QEasingCurve::operator==(const QEasingCurve &other) const
{
    bool res = d_ptr->func == other.d_ptr->func
            && d_ptr->type == other.d_ptr->type;
    if (res) {
        if (d_ptr->config && other.d_ptr->config) {
        // catch the config content
            res = d_ptr->config->operator==(*(other.d_ptr->config));

        } else if (d_ptr->config || other.d_ptr->config) {
        // one one has a config object, which could contain default values
            res = qFuzzyCompare(amplitude(), other.amplitude()) &&
                  qFuzzyCompare(period(), other.period()) &&
                  qFuzzyCompare(overshoot(), other.overshoot());
        }
    }
    return res;
}
Beispiel #11
0
void GameScene::spawnEnemies(GraphicsEnemyObject::EnemyType type, bool inverted)
{
    QEasingCurve curve;

    switch (type)
    {
    case GraphicsEnemyObject::EnemyType::White:
    case GraphicsEnemyObject::EnemyType::Green:
        curve.setType(static_cast<QEasingCurve::Type>(qrand() % 41));
        break;
    case GraphicsEnemyObject::EnemyType::Boss:
        curve.setCustomType(&CustomEasingCurve::simpleEasingCurve);
        break;
    }

    auto enemy = new GraphicsEnemyObject(type, curve, inverted);
    addItem(enemy);
    connect(enemy, &GraphicsEnemyObject::cannonTriggered, this,
        &GameScene::planeShot);
    connect(enemy, &GraphicsEnemyObject::exploded, this,
        &GameScene::planeExploded);
}
static PyObject *meth_QEasingCurve_setType(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QEasingCurve::Type a0;
        QEasingCurve *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BE", &sipSelf, sipType_QEasingCurve, &sipCpp, sipType_QEasingCurve_Type, &a0))
        {
            sipCpp->setType(a0);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QEasingCurve, sipName_setType, doc_QEasingCurve_setType);

    return NULL;
}
Beispiel #13
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;
}
static PyObject *meth_QEasingCurve_swap(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QEasingCurve* a0;
        int a0State = 0;
        QEasingCurve *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QEasingCurve, &sipCpp, sipType_QEasingCurve, &a0, &a0State))
        {
            sipCpp->swap(*a0);
            sipReleaseType(a0,sipType_QEasingCurve,a0State);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QEasingCurve, sipName_swap, doc_QEasingCurve_swap);

    return NULL;
}
Beispiel #15
0
void tst_QEasingCurve::operators()
{
    // operator=
    QEasingCurve curve;
    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);
    curve2 = curve;
    curve2.setOvershoot(qreal(1.70158));
    QCOMPARE(curve.overshoot(), curve2.overshoot());
    QVERIFY(curve2 == curve);

    curve.setOvershoot(3.0);
    QVERIFY(curve2 != curve);
    curve2.setOvershoot(3.0);
    QVERIFY(curve2 == curve);

    curve2.setType(QEasingCurve::Linear);
    QCOMPARE(curve.overshoot(), curve2.overshoot());
    QVERIFY(curve2 != curve);
    curve2.setType(QEasingCurve::InBack);
    QCOMPARE(curve.overshoot(), curve2.overshoot());
    QVERIFY(curve2 == curve);

    QEasingCurve curve3;
    QEasingCurve curve4;
    curve4.setAmplitude(curve4.amplitude());
    QEasingCurve curve5;
    curve5.setAmplitude(0.12345);
    QVERIFY(curve3 == curve4); // default value and not assigned
    QVERIFY(curve3 != curve5); // unassinged and other value
    QVERIFY(curve4 != curve5);
}
Beispiel #16
0
void Window::overshootChanged(double value)
{
    QEasingCurve curve = m_anim->easingCurve();
    curve.setOvershoot(value);
    m_anim->setEasingCurve(curve);
}
void PropertiesEditorItem::slotPropertyValueChanged()
{
    if (mProperty.type() == QVariant::BitArray) {

    } else if (mProperty.type() == QVariant::Bitmap) {

    } else if (mProperty.type() == QVariant::Bool) {
        QCheckBox *checkBox = qobject_cast<QCheckBox*>(mWidget.data());
        checkBox->setChecked(mProperty.read(mObject.data()).toBool());

    } else if (mProperty.type() == QVariant::Brush) {

    } else if (mProperty.type() == QVariant::ByteArray) {

    } else if (mProperty.type() == QVariant::Char) {

    } else if (mProperty.type() == QVariant::Color) {

    } else if (mProperty.type() == QVariant::Cursor) {

    } else if (mProperty.type() == QVariant::Date) {

    } else if (mProperty.type() == QVariant::DateTime) {

    } else if (mProperty.type() == QVariant::Double) {
        QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(mWidget.data());
        spinBox->setValue(mProperty.read(mObject.data()).toDouble());

    } else if (mProperty.type() == QVariant::EasingCurve) {
        QPushButton *button = qobject_cast<QPushButton*>(mWidget.data());
        QEasingCurve curve = mProperty.read(mObject.data()).toEasingCurve();
        button->setText(curve.staticMetaObject.enumerator(0).valueToKey(curve.type()));

    } else if (mProperty.type() == QVariant::Font) {
        QFontComboBox *comboBox = qobject_cast<QFontComboBox*>(mWidget.data());
        comboBox->setCurrentFont(mProperty.read(mObject.data()).value<QFont>());

    } else if (mProperty.type() == QVariant::Hash) {

    } else if (mProperty.type() == QVariant::Icon) {

    } else if (mProperty.type() == QVariant::Image) {

    } else if (mProperty.type() == QVariant::Int) {
        QSpinBox *spinBox = qobject_cast<QSpinBox*>(mWidget.data());
        spinBox->setValue(mProperty.read(mObject.data()).toInt());

    } else if (mProperty.type() == QVariant::KeySequence) {

    } else if (mProperty.type() == QVariant::Line) {

    } else if (mProperty.type() == QVariant::LineF) {

    } else if (mProperty.type() == QVariant::List) {

    } else if (mProperty.type() == QVariant::Locale) {

    } else if (mProperty.type() == QVariant::LongLong) {
        QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(mWidget.data());
        spinBox->setValue(mProperty.read(mObject.data()).toLongLong());

    } else if (mProperty.type() == QVariant::Map) {

    } else if (mProperty.type() == QVariant::Matrix) {

    } else if (mProperty.type() == QVariant::Matrix4x4) {

    } else if (mProperty.type() == QVariant::Palette) {

    } else if (mProperty.type() == QVariant::Pen) {

    } else if (mProperty.type() == QVariant::Pixmap) {

    } else if (mProperty.type() == QVariant::Point) {

    } else if (mProperty.type() == QVariant::PointF) {

    } else if (mProperty.type() == QVariant::Polygon) {

    } else if (mProperty.type() == QVariant::Quaternion) {

    } else if (mProperty.type() == QVariant::Rect) {

    } else if (mProperty.type() == QVariant::RectF) {

    } else if (mProperty.type() == QVariant::RegExp) {

    } else if (mProperty.type() == QVariant::Region) {

    } else if (mProperty.type() == QVariant::Size) {

    } else if (mProperty.type() == QVariant::SizeF) {

    } else if (mProperty.type() == QVariant::SizePolicy) {

    } else if (mProperty.type() == QVariant::String) {
        QLineEdit *lineEdit = qobject_cast<QLineEdit*>(mWidget.data());
        lineEdit->setText(mProperty.read(mObject.data()).toString());

    } else if (mProperty.type() == QVariant::StringList) {

    } else if (mProperty.type() == QVariant::TextFormat) {

    } else if (mProperty.type() == QVariant::TextLength) {

    } else if (mProperty.type() == QVariant::Time) {

    } else if (mProperty.type() == QVariant::Transform) {

    } else if (mProperty.type() == QVariant::UInt) {
        QSpinBox *spinBox = qobject_cast<QSpinBox*>(mWidget.data());
        spinBox->setValue(mProperty.read(mObject.data()).toUInt());

    } else if (mProperty.type() == QVariant::ULongLong) {
        QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(mWidget.data());
        spinBox->setValue(mProperty.read(mObject.data()).toULongLong());

    } else if (mProperty.type() == QVariant::Url) {
        QPushButton *button = qobject_cast<QPushButton*>(mWidget.data());
        QUrl url = mProperty.read(mObject.data()).toUrl();
        setButtonUrl(button, url);

    } else if (mProperty.type() == QVariant::UserType) {

    } else if (mProperty.type() == QVariant::Vector2D) {

    } else if (mProperty.type() == QVariant::Vector3D) {

    } else if (mProperty.type() == QVariant::Vector4D) {

    }
}
Beispiel #18
0
void Window::amplitudeChanged(double value)
{
    QEasingCurve curve = m_anim->easingCurve();
    curve.setAmplitude(value);
    m_anim->setEasingCurve(curve);
}
Beispiel #19
0
void Window::periodChanged(double value)
{
    QEasingCurve curve = m_anim->easingCurve();
    curve.setPeriod(value);
    m_anim->setEasingCurve(curve);
}
Beispiel #20
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 PropertiesEditorItem::prepareWidget()
{
    QWidget *editor = 0;

    if (mProperty.type() == QVariant::BitArray) {

    } else if (mProperty.type() == QVariant::Bitmap) {

    } else if (mProperty.type() == QVariant::Bool) {
        QCheckBox *checkBox = new QCheckBox(parent());
        checkBox->setText(QString());
        checkBox->setChecked(mProperty.read(mObject.data()).toBool());
        editor = qobject_cast< QWidget* >(checkBox);
        connect(checkBox, SIGNAL(toggled(bool)), SLOT(slotCheckBoxToggled()));

    } else if (mProperty.type() == QVariant::Brush) {

    } else if (mProperty.type() == QVariant::ByteArray) {

    } else if (mProperty.type() == QVariant::Char) {

    } else if (mProperty.type() == QVariant::Color) {
        QPushButton *button = new QPushButton(parent());
        button->setText(mProperty.read(mObject.data()).value<QColor>().name());
        connect(button, SIGNAL(clicked(bool)), SLOT(slotOpenColorEditor()));
        editor = qobject_cast< QWidget* >(button);

    } else if (mProperty.type() == QVariant::Cursor) {

    } else if (mProperty.type() == QVariant::Date) {

    } else if (mProperty.type() == QVariant::DateTime) {

    } else if (mProperty.type() == QVariant::Double) {
        QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent());
        spinBox->setMaximum(LONG_MAX);
        spinBox->setMinimum(LONG_MIN);
        spinBox->setSingleStep(0.01);
        spinBox->setValue(mProperty.read(mObject.data()).toDouble());
        editor = qobject_cast< QWidget* >(spinBox);
        connect(spinBox, SIGNAL(valueChanged(double)), SLOT(slotDoubleSpinBoxValueChanged()));

    } else if (mProperty.type() == QVariant::EasingCurve) {
        QPushButton *button = new QPushButton(parent());
        QEasingCurve curve = mProperty.read(mObject.data()).toEasingCurve();
        button->setText(curve.staticMetaObject.enumerator(0).valueToKey(curve.type()));
        connect(button, SIGNAL(clicked(bool)), SLOT(slotOpenEasingCurveEditor()));
        editor = qobject_cast< QWidget* >(button);

    } else if (mProperty.type() == QVariant::Font) {
        QFontComboBox *comboBox = new QFontComboBox(parent());
        comboBox->setCurrentFont(mProperty.read(mObject.data()).value<QFont>());
        editor = qobject_cast< QWidget* >(comboBox);
        connect(comboBox, SIGNAL(currentFontChanged(QFont)), SLOT(slotFontComboChanged()));

    } else if (mProperty.type() == QVariant::Hash) {

    } else if (mProperty.type() == QVariant::Icon) {

    } else if (mProperty.type() == QVariant::Image) {

    } else if (mProperty.type() == QVariant::Int) {
        QSpinBox *spinBox = new QSpinBox(parent());
        spinBox->setMinimum(INT_MIN);
        spinBox->setMaximum(INT_MAX);
        spinBox->setValue(mProperty.read(mObject.data()).toInt());
        editor = qobject_cast< QWidget* >(spinBox);
        connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotSpinBoxValueChanged()));

    } else if (mProperty.type() == QVariant::KeySequence) {

    } else if (mProperty.type() == QVariant::Line) {

    } else if (mProperty.type() == QVariant::LineF) {

    } else if (mProperty.type() == QVariant::List) {

    } else if (mProperty.type() == QVariant::Locale) {

    } else if (mProperty.type() == QVariant::LongLong) {
        QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent());
        spinBox->setSingleStep(1.0);
        spinBox->setDecimals(0);
        spinBox->setMaximum(LONG_MAX);
        spinBox->setMinimum(LONG_MIN);
        spinBox->setValue(mProperty.read(mObject.data()).toLongLong());
        editor = qobject_cast< QWidget* >(spinBox);
        connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotDoubleSpinBoxValueChanged()));

    } else if (mProperty.type() == QVariant::Map) {

    } else if (mProperty.type() == QVariant::Matrix) {

    } else if (mProperty.type() == QVariant::Matrix4x4) {

    } else if (mProperty.type() == QVariant::Palette) {

    } else if (mProperty.type() == QVariant::Pen) {

    } else if (mProperty.type() == QVariant::Pixmap) {

    } else if (mProperty.type() == QVariant::Point) {

    } else if (mProperty.type() == QVariant::PointF) {

    } else if (mProperty.type() == QVariant::Polygon) {

    } else if (mProperty.type() == QVariant::Quaternion) {

    } else if (mProperty.type() == QVariant::Rect) {

    } else if (mProperty.type() == QVariant::RectF) {

    } else if (mProperty.type() == QVariant::RegExp) {

    } else if (mProperty.type() == QVariant::Region) {

    } else if (mProperty.type() == QVariant::Size) {

    } else if (mProperty.type() == QVariant::SizeF) {

    } else if (mProperty.type() == QVariant::SizePolicy) {

    } else if (mProperty.type() == QVariant::String) {
        QLineEdit *lineEdit = new QLineEdit(parent());
        lineEdit->setText(mProperty.read(mObject.data()).toString());
        editor = qobject_cast< QWidget* >(lineEdit);
        connect(lineEdit, SIGNAL(textChanged(QString)), SLOT(slotLineEditChanged()));

    } else if (mProperty.type() == QVariant::StringList) {

    } else if (mProperty.type() == QVariant::TextFormat) {

    } else if (mProperty.type() == QVariant::TextLength) {

    } else if (mProperty.type() == QVariant::Time) {

    } else if (mProperty.type() == QVariant::Transform) {

    } else if (mProperty.type() == QVariant::UInt) {
        QSpinBox *spinBox = new QSpinBox(parent());
        spinBox->setMaximum(UINT_MAX);
        spinBox->setMinimum(0);
        spinBox->setValue(mProperty.read(mObject.data()).toUInt());
        editor = qobject_cast< QWidget* >(spinBox);
        connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotSpinBoxValueChanged()));

    } else if (mProperty.type() == QVariant::ULongLong) {
        QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent());
        spinBox->setSingleStep(1.0);
        spinBox->setDecimals(0);
        spinBox->setMinimum(0);
        spinBox->setMaximum(ULONG_MAX);
        spinBox->setValue(mProperty.read(mObject.data()).toULongLong());
        editor = qobject_cast< QWidget* >(spinBox);
        connect(spinBox, SIGNAL(valueChanged(int)), SLOT(slotDoubleSpinBoxValueChanged()));

    } else if (mProperty.type() == QVariant::Url) {
        QPushButton *button = new QPushButton(parent());
        QUrl url = mProperty.read(mObject.data()).toUrl();
        setButtonUrl(button, url);
        editor = qobject_cast< QWidget* >(button);
        connect(button, SIGNAL(clicked(bool)), SLOT(slotUrlButtonClicked()));

    } else if (mProperty.type() == QVariant::UserType) {

    } else if (mProperty.type() == QVariant::Vector2D) {

    } else if (mProperty.type() == QVariant::Vector3D) {

    } else if (mProperty.type() == QVariant::Vector4D) {

    }

    mWidget = editor;
}
bool MStyleSheetAttribute::writeAttribute(MUniqueStringCache::Index filename,
        MStyle *style,
        const QMetaProperty &property,
        M::Orientation orientation) const
{
    // first check if the attribute is cached orientation independent, if not found
    // check for the given orientation
    QVariant cachedVariant = variantCache[M::Landscape + 1][value][property.userType()];
    if (cachedVariant.isValid()) {
        return property.write(style, cachedVariant);
    } else {
        cachedVariant = variantCache[orientation][value][property.userType()];
        if (cachedVariant.isValid()) {
            style->setOrientationDependent(true);
            return property.write(style, cachedVariant);
        }
    }

    bool conversionOK = false;
    // most types are the same in landscape and portrait
    CacheOrientationFlags cacheOrientation = CacheOrientationFlags(PortraitFlag | LandscapeFlag);

    QLatin1String vs = MStyleSheetParser::stringCacheWithoutReverseLookup()->indexToString(value);
    QByteArray valueString = QByteArray::fromRawData(vs.latin1(), strlen(vs.latin1()));

    const int attributeType = property.userType();
    if (attributeType == QMetaType::Bool) {
        bool result = booleanFromString(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, result);
        }
    } else if (attributeType == QMetaType::Int) {
        int integer = attributeToInt(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, integer);
        }
    } else if (attributeType == QMetaType::QColor) {
        if(valueString == "none")
            return fillProperty(property, style, cacheOrientation, QColor());

        QColor color = colorFromString(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, color);
        }
    } else if (attributeType == QMetaType::QReal) {
        qreal real = attributeToFloat(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, real);
        }
    } else if (attributeType == qMetaTypeId<const QPixmap*>()) {
        if(valueString == "none")
            return fillProperty(property, style, cacheOrientation, qVariantFromValue((const QPixmap *) NULL));

        //"image: image_id;"
        //"image: image_id 64px 64px;"
        //"image: "image id";"
        //"image: "image id" 64px 64px;"

        QList<QByteArray> list;
        if (valueString.startsWith('\"')) {
            //parse name inside quotes
            int idx = valueString.indexOf('\"', 1);
            if (idx != -1) {
                //get quoted image_id
                QByteArray imageid = valueString.mid(1, idx - 1);

                //split rest of the parameters
                QByteArray values = valueString.mid(idx + 1).trimmed();
                list = values.split(' ');
                list.removeAll("");

                //insert image_id as first parameter
                list.insert(0, imageid);
            }
        } else {
            //no quotes, just split the parameters
            list = valueString.split(' ');
            list.removeAll("");
        }

        //only image_id
        if (list.size() == 1) {
            const QPixmap *pixmap = MTheme::pixmap(list.at(0));
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(pixmap), false);
        }
        //image_id + width + height
        else if (list.size() == 3) {
            int width = attributeToInt(list.at(1), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
            int height = attributeToInt(list.at(2), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
            const QPixmap *pixmap = MTheme::pixmap(list.at(0), QSize(width, height));
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(pixmap), false);
        }
        //no parameters
        else if (list.size() == 0) {
            //init null pixmap which is ok if someone does not want to use it
            return fillProperty(property, style, cacheOrientation, qVariantFromValue((const QPixmap *) NULL));
        }
    } else if (attributeType == qMetaTypeId<const MScalableImage*>() || attributeType == qMetaTypeId<MBackgroundTiles>()) {
        //"background: image_id left right top bottom;"
        //"background: image_id;"
        //"background: "image id" left right top bottom;"
        //"background: "image id";"

        QList<QByteArray> list;
        if (valueString.startsWith('\"')) {
            //parse name inside quotes
            int idx = valueString.indexOf('\"', 1);
            if (idx != -1) {
                //get quoted image_id
                QByteArray imageid = valueString.mid(1, idx - 1);

                //split rest of the parameters
                QByteArray values = valueString.mid(idx + 1).trimmed();
                list = values.split(' ');
                list.removeAll("");
                //insert image_id as first parameter
                list.insert(0, imageid);
            }
        } else {
            //no quotes, just split the parameters
            list = valueString.split(' ');
            list.removeAll("");
        }

        //no parameters
        if (valueString.isEmpty() || valueString == "none") {
            //init null image which is ok if someone does not want to use it
            if(attributeType == qMetaTypeId<const MScalableImage*>())
                return fillProperty(property, style, cacheOrientation, qVariantFromValue((const MScalableImage *) NULL));
            else
                return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles()), false);
        }
        //only image_id
        else if (list.size() == 1) {
            if(attributeType == qMetaTypeId<const MScalableImage*>()) {
                const MScalableImage *image = MTheme::scalableImage(list.at(0), 0, 0, 0, 0);
                return fillProperty(property, style, cacheOrientation, qVariantFromValue(image), false);
            } else {
                return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles(list.at(0), 0,0,0,0)), false);
            }
        }
        //image_id + border width paramaters
        else if (list.size() == 5) {
            //image_id and the border parameters
            if(attributeType == qMetaTypeId<const MScalableImage*>()) {
                const MScalableImage *image = MTheme::scalableImage(list.at(0),
                                                attributeToInt(list.at(1), &conversionOK),
                                                attributeToInt(list.at(2), &conversionOK),
                                                attributeToInt(list.at(3), &conversionOK),
                                                attributeToInt(list.at(4), &conversionOK));
                return fillProperty(property, style, cacheOrientation, qVariantFromValue(image), false);
            } else {
                return fillProperty(property, style, cacheOrientation, QVariant::fromValue(MBackgroundTiles(list.at(0),
                                                                attributeToInt(list.at(1), &conversionOK),
                                                                attributeToInt(list.at(2), &conversionOK),
                                                                attributeToInt(list.at(3), &conversionOK),
                                                                attributeToInt(list.at(4), &conversionOK))), false);
            }
        }
    } else if (attributeType == QMetaType::QSize || attributeType == QMetaType::QSizeF) {
        //size: 25px 25px;

        //just split into pieces and create QSize or QSizeF depending on the attributeType
        QList<QByteArray> list = valueString.split(' ');
        list.removeAll("");
        if (list.size() == 2) {
            if (attributeType == QMetaType::QSize) {
                int width = attributeToInt(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                int height = attributeToInt(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QSize(width, height));
            } else {
                qreal width = attributeToFloat(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                qreal height = attributeToFloat(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QSizeF(width, height));
            }
        }
    } else if (attributeType == QMetaType::QPoint || attributeType == QMetaType::QPointF) {
        //"point: 256px 123px;

        //just split into pieces and create QPoint or QPointF depending on the attributeType
        QList<QByteArray> list = valueString.split(' ');
        list.removeAll("");
        if (list.size() == 2) {
            if (attributeType == QMetaType::QPoint) {
                int x = attributeToInt(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                int y = attributeToInt(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QPoint(x, y));
            } else {
                qreal x = attributeToFloat(list.at(0), &conversionOK, WidthAttribute, orientation, &cacheOrientation);
                qreal y = attributeToFloat(list.at(1), &conversionOK, HeightAttribute, orientation, &cacheOrientation);
                return fillProperty(property, style, cacheOrientation, QPointF(x, y));
            }
        }
    } else if (attributeType == QMetaType::QFont) {
        QFont font = fontFromString(valueString, &conversionOK);
        if (conversionOK) {
            return fillProperty(property, style, cacheOrientation, font);
        }
    } else if (attributeType == QMetaType::QString) {
        if (valueString.length() >= 2) {
            if ((valueString.at(0) == 0x22) && (valueString.at(valueString.length()-1) == 0x22)) {
                return fillProperty(property, style, cacheOrientation, QString(valueString.mid(1, valueString.length() - 2)));
            }
        } else if (valueString.length() == 0) {
            return fillProperty(property, style, cacheOrientation, QString());
        }
    } else if (attributeType == QMetaType::QChar) {
        if (valueString.length() == 3) {
            if ((valueString.at(0) == '\'') && (valueString.at(2) == '\'')) {
                return fillProperty(property, style, cacheOrientation, static_cast<QChar>(valueString.at(1)));
            }
        }
    } else if (attributeType == qMetaTypeId<Qt::Alignment>()) {
        if (DataTypeConverter.ALIGNMENTS.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.ALIGNMENTS[valueString]));
        }
    } else if (attributeType == qMetaTypeId<Qt::Orientation>()) {
        if (DataTypeConverter.ORIENTATIONS.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.ORIENTATIONS[valueString]));
        }
    } else if (attributeType == qMetaTypeId<QTextCharFormat::UnderlineStyle>()) {
        if (DataTypeConverter.UNDERLINESTYLES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.UNDERLINESTYLES[valueString]));
        }
    } else if (attributeType == qMetaTypeId<Qt::PenStyle>()) {
        if (DataTypeConverter.PENSTYLES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.PENSTYLES[valueString]));
        }
    } else if (attributeType == qMetaTypeId<Qt::Axis>()) {
        if (DataTypeConverter.AXES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.AXES[valueString]));
        }
    } else if (attributeType == qMetaTypeId<MFeedback>()) {
        MFeedback feedback(valueString);
        return fillProperty(property, style, cacheOrientation, qVariantFromValue(feedback));
    } else if (attributeType == QMetaType::QEasingCurve) {
        QEasingCurve curve;
        // curve type
        QList<QByteArray> list = valueString.split(',');
        if (list.size() > 0) {
            if (DataTypeConverter.EASINGCURVETYPES.contains(list.at(0))) {
                int type = DataTypeConverter.EASINGCURVETYPES[list.at(0)];
                if (type < FirstCustomType)
                    curve.setType(static_cast<QEasingCurve::Type>(type));
                else if (type == OvershotBezier)
                    curve = MOvershotBezierEasingCurve();
                // curve amplitude
                if (list.size() > 1) {
                    curve.setAmplitude((qreal) list.at(1).toDouble());
                    // curve overshoot
                    if (list.size() > 2) {
                        curve.setOvershoot((qreal) list.at(2).toDouble());
                        // curve period
                        if (list.size() > 3) {
                            curve.setPeriod((qreal) list.at(3).toDouble());
                        }
                    }
                }
                return fillProperty(property, style, cacheOrientation, qVariantFromValue(curve));
            }
        }
    } else if (attributeType == qMetaTypeId<QTextOption::WrapMode>()) {
        if (DataTypeConverter.WRAPMODES.contains(valueString)) {
            return fillProperty(property, style, cacheOrientation, qVariantFromValue(DataTypeConverter.WRAPMODES[valueString]));
        }
    }

    MStyleSheetParser::outputParseError(MStyleSheetParser::stringCacheWithReverseLookup()->indexToString(filename), "Not a valid attribute(" + QLatin1String(property.typeName()) + "): " + MStyleSheetParser::stringCacheWithoutReverseLookup()->indexToString(name) + " : " + valueString, MStyleSheetParser::getLineNum(MStyleSheetParser::stringCacheWithReverseLookup()->indexToString(filename), position));
    return false;
}