Exemplo n.º 1
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);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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) {

    }
}