6#include <QtCore/qmutex.h>
7#include <private/qqmlglobal_p.h>
8#include <QtCore/qdebug.h>
9#include <private/qqmlengine_p.h>
10#include <private/qmetaobjectbuilder_p.h>
14QQmlValueType::~QQmlValueType()
16 ::free(m_dynamicMetaObject);
19QQmlGadgetPtrWrapper *QQmlGadgetPtrWrapper::instance(QQmlEngine *engine, QMetaType type)
21 return engine ? QQmlEnginePrivate::get(engine)->valueTypeInstance(type) :
nullptr;
24QQmlGadgetPtrWrapper::QQmlGadgetPtrWrapper(QQmlValueType *valueType, QObject *parent)
25 : QObject(parent), m_gadgetPtr(valueType->create())
27 QObjectPrivate *d = QObjectPrivate::get(
this);
28 Q_ASSERT(!d->metaObject);
29 d->metaObject = valueType;
32QQmlGadgetPtrWrapper::~QQmlGadgetPtrWrapper()
34 QObjectPrivate *d = QObjectPrivate::get(
this);
35 static_cast<
const QQmlValueType *>(d->metaObject)->destroy(m_gadgetPtr);
36 d->metaObject =
nullptr;
39void QQmlGadgetPtrWrapper::read(QObject *obj,
int idx)
41 Q_ASSERT(m_gadgetPtr);
42 void *a[] = { m_gadgetPtr,
nullptr };
43 QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a);
46void QQmlGadgetPtrWrapper::write(
47 QObject *obj,
int idx, QQmlPropertyData::WriteFlags flags,
int internalIndex)
const
49 Q_ASSERT(m_gadgetPtr);
51 void *a[] = { m_gadgetPtr,
nullptr, &status, &flags, &internalIndex };
52 QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a);
55QVariant QQmlGadgetPtrWrapper::value()
const
57 Q_ASSERT(m_gadgetPtr);
59 const QMetaType m = metaType();
60 return m == QMetaType::fromType<QVariant>()
61 ? *
static_cast<
const QVariant *>(m_gadgetPtr)
62 : QVariant(m, m_gadgetPtr);
65void QQmlGadgetPtrWrapper::setValue(
const QVariant &value)
67 Q_ASSERT(m_gadgetPtr);
69 const QMetaType m = metaType();
70 m.destruct(m_gadgetPtr);
71 if (m == QMetaType::fromType<QVariant>()) {
72 m.construct(m_gadgetPtr, &value);
74 Q_ASSERT(m == value.metaType());
75 m.construct(m_gadgetPtr, value.constData());
79int QQmlGadgetPtrWrapper::metaCall(QMetaObject::Call type,
int id,
void **argv)
81 Q_ASSERT(m_gadgetPtr);
82 const QMetaObject *metaObject = valueType()->staticMetaObject();
83 QQmlMetaObject::resolveGadgetMethodOrPropertyIndex(type, &metaObject, &id);
84 metaObject->d.static_metacall(
static_cast<QObject *>(m_gadgetPtr), type, id, argv);
88const QQmlValueType *QQmlGadgetPtrWrapper::valueType()
const
90 const QObjectPrivate *d = QObjectPrivate::get(
this);
91 return static_cast<
const QQmlValueType *>(d->metaObject);
94QMetaObject *QQmlValueType::toDynamicMetaObject(QObject *)
96 if (!m_dynamicMetaObject) {
97 QMetaObjectBuilder builder(m_staticMetaObject);
103 m_dynamicMetaObject = builder.toMetaObject();
105 return m_dynamicMetaObject;
108void QQmlValueType::objectDestroyed(QObject *)
112int QQmlValueType::metaCall(QObject *object, QMetaObject::Call type,
int _id,
void **argv)
114 return static_cast<QQmlGadgetPtrWrapper *>(object)->metaCall(type, _id, argv);
117QString QQmlPointFValueType::toString()
const
119 return QString::asprintf(
"QPointF(%g, %g)", QPointF::x(), QPointF::y());
122qreal QQmlPointFValueType::x()
const
127qreal QQmlPointFValueType::y()
const
132void QQmlPointFValueType::setX(qreal x)
137void QQmlPointFValueType::setY(qreal y)
143QString QQmlPointValueType::toString()
const
145 return QString::asprintf(
"QPoint(%d, %d)", QPoint::x(), QPoint::y());
148int QQmlPointValueType::x()
const
153int QQmlPointValueType::y()
const
158void QQmlPointValueType::setX(
int x)
163void QQmlPointValueType::setY(
int y)
169QString QQmlSizeFValueType::toString()
const
171 return QString::asprintf(
"QSizeF(%g, %g)", QSizeF::width(), QSizeF::height());
174qreal QQmlSizeFValueType::width()
const
176 return QSizeF::width();
179qreal QQmlSizeFValueType::height()
const
181 return QSizeF::height();
184void QQmlSizeFValueType::setWidth(qreal w)
189void QQmlSizeFValueType::setHeight(qreal h)
191 QSizeF::setHeight(h);
195QString QQmlSizeValueType::toString()
const
197 return QString::asprintf(
"QSize(%d, %d)", QSize::width(), QSize::height());
200int QQmlSizeValueType::width()
const
202 return QSize::width();
205int QQmlSizeValueType::height()
const
207 return QSize::height();
210void QQmlSizeValueType::setWidth(
int w)
215void QQmlSizeValueType::setHeight(
int h)
220QString QQmlRectFValueType::toString()
const
222 return QString::asprintf(
223 "QRectF(%g, %g, %g, %g)", QRectF::x(), QRectF::y(), QRectF::width(), QRectF::height());
226qreal QQmlRectFValueType::x()
const
231qreal QQmlRectFValueType::y()
const
236void QQmlRectFValueType::setX(qreal x)
241void QQmlRectFValueType::setY(qreal y)
246qreal QQmlRectFValueType::width()
const
248 return QRectF::width();
251qreal QQmlRectFValueType::height()
const
253 return QRectF::height();
256void QQmlRectFValueType::setWidth(qreal w)
261void QQmlRectFValueType::setHeight(qreal h)
263 QRectF::setHeight(h);
266qreal QQmlRectFValueType::left()
const
268 return QRectF::left();
271qreal QQmlRectFValueType::right()
const
273 return QRectF::right();
276qreal QQmlRectFValueType::top()
const
278 return QRectF::top();
281qreal QQmlRectFValueType::bottom()
const
283 return QRectF::bottom();
287QString QQmlRectValueType::toString()
const
289 return QString::asprintf(
290 "QRect(%d, %d, %d, %d)", QRect::x(), QRect::y(), QRect::width(), QRect::height());
293int QQmlRectValueType::x()
const
298int QQmlRectValueType::y()
const
303void QQmlRectValueType::setX(
int x)
308void QQmlRectValueType::setY(
int y)
313int QQmlRectValueType::width()
const
315 return QRect::width();
318int QQmlRectValueType::height()
const
320 return QRect::height();
323void QQmlRectValueType::setWidth(
int w)
328void QQmlRectValueType::setHeight(
int h)
333int QQmlRectValueType::left()
const
335 return QRect::left();
338int QQmlRectValueType::right()
const
340 return QRect::right();
343int QQmlRectValueType::top()
const
348int QQmlRectValueType::bottom()
const
350 return QRect::bottom();
353QString QQmlMarginsFValueType::toString()
const
355 return QString::asprintf(
356 "QMarginsF(%g, %g, %g, %g)",
357 QMarginsF::left(), QMarginsF::top(), QMarginsF::right(), QMarginsF::bottom());
360qreal QQmlMarginsFValueType::left()
const
362 return QMarginsF::left();
365qreal QQmlMarginsFValueType::top()
const
367 return QMarginsF::top();
370qreal QQmlMarginsFValueType::right()
const
372 return QMarginsF::right();
375qreal QQmlMarginsFValueType::bottom()
const
377 return QMarginsF::bottom();
380void QQmlMarginsFValueType::setLeft(qreal left)
382 QMarginsF::setLeft(left);
385void QQmlMarginsFValueType::setTop(qreal top)
387 QMarginsF::setTop(top);
390void QQmlMarginsFValueType::setRight(qreal right)
392 QMarginsF::setRight(right);
395void QQmlMarginsFValueType::setBottom(qreal bottom)
397 QMarginsF::setBottom(bottom);
400QString QQmlMarginsValueType::toString()
const
402 return QString::asprintf(
403 "QMargins(%d, %d, %d, %d)",
404 QMargins::left(), QMargins::top(), QMargins::right(), QMargins::bottom());
407int QQmlMarginsValueType::left()
const
409 return QMargins::left();
412int QQmlMarginsValueType::top()
const
414 return QMargins::top();
417int QQmlMarginsValueType::right()
const
419 return QMargins::right();
422int QQmlMarginsValueType::bottom()
const
424 return QMargins::bottom();
427void QQmlMarginsValueType::setLeft(
int left)
429 QMargins::setLeft(left);
432void QQmlMarginsValueType::setTop(
int top)
434 QMargins::setTop(top);
437void QQmlMarginsValueType::setRight(
int right)
439 QMargins::setRight(right);
442void QQmlMarginsValueType::setBottom(
int bottom)
444 QMargins::setBottom(bottom);
447#if QT_CONFIG(easingcurve)
448QQmlEasingEnums::Type QQmlEasingValueType::type()
const
450 return (QQmlEasingEnums::Type)QEasingCurve::type();
453qreal QQmlEasingValueType::amplitude()
const
455 return QEasingCurve::amplitude();
458qreal QQmlEasingValueType::overshoot()
const
460 return QEasingCurve::overshoot();
463qreal QQmlEasingValueType::period()
const
465 return QEasingCurve::period();
468void QQmlEasingValueType::setType(QQmlEasingEnums::Type type)
470 QEasingCurve::setType((QEasingCurve::Type)type);
473void QQmlEasingValueType::setAmplitude(qreal amplitude)
475 QEasingCurve::setAmplitude(amplitude);
478void QQmlEasingValueType::setOvershoot(qreal overshoot)
480 QEasingCurve::setOvershoot(overshoot);
483void QQmlEasingValueType::setPeriod(qreal period)
485 QEasingCurve::setPeriod(period);
488void QQmlEasingValueType::setBezierCurve(
const QList<qreal> &customCurveVariant)
490 if (customCurveVariant.isEmpty())
493 if ((customCurveVariant.size() % 6) != 0)
496 QEasingCurve newEasingCurve(QEasingCurve::BezierSpline);
497 for (
int i = 0, ei = customCurveVariant.size(); i < ei; i += 6) {
498 const qreal c1x = customCurveVariant.at(i );
499 const qreal c1y = customCurveVariant.at(i + 1);
500 const qreal c2x = customCurveVariant.at(i + 2);
501 const qreal c2y = customCurveVariant.at(i + 3);
502 const qreal c3x = customCurveVariant.at(i + 4);
503 const qreal c3y = customCurveVariant.at(i + 5);
505 const QPointF c1(c1x, c1y);
506 const QPointF c2(c2x, c2y);
507 const QPointF c3(c3x, c3y);
509 newEasingCurve.addCubicBezierSegment(c1, c2, c3);
512 *
this = newEasingCurve;
515QList<qreal> QQmlEasingValueType::bezierCurve()
const
518 const QVector<QPointF> points = QEasingCurve::toCubicSpline();
519 rv.reserve(points.size() * 2);
520 for (
const auto &point : points)
521 rv << point.x() << point.y();
529#include "moc_qqmlvaluetype_p.cpp"
Combined button and popup list for selecting options.