| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQMLVALUETYPE_P_H |
| 5 | #define QQMLVALUETYPE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtQml/private/qqmlproperty_p.h> |
| 19 | |
| 20 | #include <private/qqmlnullablevalue_p.h> |
| 21 | #include <private/qmetatype_p.h> |
| 22 | #include <private/qv4referenceobject_p.h> |
| 23 | |
| 24 | #include <QtCore/qobject.h> |
| 25 | #include <QtCore/qrect.h> |
| 26 | #if QT_CONFIG(easingcurve) |
| 27 | #include <QtCore/qeasingcurve.h> |
| 28 | #endif |
| 29 | #include <QtCore/qvariant.h> |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | class Q_QML_EXPORT QQmlValueType : public QDynamicMetaObjectData |
| 34 | { |
| 35 | public: |
| 36 | QQmlValueType() = default; |
| 37 | QQmlValueType(QMetaType type, const QMetaObject *staticMetaObject) |
| 38 | : m_metaType(type), m_staticMetaObject(staticMetaObject) |
| 39 | {} |
| 40 | ~QQmlValueType(); |
| 41 | |
| 42 | void *create() const { return m_metaType.create(); } |
| 43 | void destroy(void *gadgetPtr) const { m_metaType.destroy(data: gadgetPtr); } |
| 44 | |
| 45 | void construct(void *gadgetPtr, const void *copy) const { m_metaType.construct(where: gadgetPtr, copy); } |
| 46 | void destruct(void *gadgetPtr) const { m_metaType.destruct(data: gadgetPtr); } |
| 47 | |
| 48 | QMetaType metaType() const { return m_metaType; } |
| 49 | const QMetaObject *staticMetaObject() const { return m_staticMetaObject; } |
| 50 | |
| 51 | // ---- dynamic meta object data interface |
| 52 | QMetaObject *toDynamicMetaObject(QObject *) override; |
| 53 | void objectDestroyed(QObject *) override; |
| 54 | int metaCall(QObject *obj, QMetaObject::Call type, int _id, void **argv) override; |
| 55 | // ---- |
| 56 | |
| 57 | private: |
| 58 | QMetaType m_metaType; |
| 59 | const QMetaObject *m_staticMetaObject = nullptr; |
| 60 | QMetaObject *m_dynamicMetaObject = nullptr; |
| 61 | }; |
| 62 | |
| 63 | class Q_QML_EXPORT QQmlGadgetPtrWrapper : public QObject |
| 64 | { |
| 65 | Q_OBJECT |
| 66 | public: |
| 67 | static QQmlGadgetPtrWrapper *instance(QQmlEngine *engine, QMetaType type); |
| 68 | |
| 69 | QQmlGadgetPtrWrapper(QQmlValueType *valueType, QObject *parent = nullptr); |
| 70 | ~QQmlGadgetPtrWrapper(); |
| 71 | |
| 72 | void read(QObject *obj, int idx); |
| 73 | void write(QObject *obj, int idx, QQmlPropertyData::WriteFlags flags, |
| 74 | int internalIndex = QV4::ReferenceObject::AllProperties) const; |
| 75 | QVariant value() const; |
| 76 | void setValue(const QVariant &value); |
| 77 | |
| 78 | QMetaType metaType() const { return valueType()->metaType(); } |
| 79 | int metaCall(QMetaObject::Call type, int id, void **argv); |
| 80 | |
| 81 | QMetaProperty property(int index) const |
| 82 | { |
| 83 | return valueType()->staticMetaObject()->property(index); |
| 84 | } |
| 85 | |
| 86 | QVariant readOnGadget(const QMetaProperty &property) const |
| 87 | { |
| 88 | return property.readOnGadget(gadget: m_gadgetPtr); |
| 89 | } |
| 90 | |
| 91 | void writeOnGadget(const QMetaProperty &property, const QVariant &value) |
| 92 | { |
| 93 | property.writeOnGadget(gadget: m_gadgetPtr, value); |
| 94 | } |
| 95 | |
| 96 | void writeOnGadget(const QMetaProperty &property, QVariant &&value) |
| 97 | { |
| 98 | property.writeOnGadget(gadget: m_gadgetPtr, value: std::move(value)); |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | const QQmlValueType *valueType() const; |
| 103 | void *m_gadgetPtr = nullptr; |
| 104 | }; |
| 105 | |
| 106 | struct Q_QML_EXPORT QQmlPointFValueType |
| 107 | { |
| 108 | QPointF v; |
| 109 | Q_PROPERTY(qreal x READ x WRITE setX FINAL) |
| 110 | Q_PROPERTY(qreal y READ y WRITE setY FINAL) |
| 111 | Q_GADGET |
| 112 | QML_VALUE_TYPE(point) |
| 113 | QML_FOREIGN(QPointF) |
| 114 | QML_EXTENDED(QQmlPointFValueType) |
| 115 | QML_STRUCTURED_VALUE |
| 116 | |
| 117 | public: |
| 118 | Q_INVOKABLE QQmlPointFValueType() = default; |
| 119 | Q_INVOKABLE QQmlPointFValueType(const QPoint &point) : v(point) {} |
| 120 | Q_INVOKABLE QString toString() const; |
| 121 | qreal x() const; |
| 122 | qreal y() const; |
| 123 | void setX(qreal); |
| 124 | void setY(qreal); |
| 125 | |
| 126 | operator QPointF() const { return v; } |
| 127 | }; |
| 128 | |
| 129 | struct Q_QML_EXPORT QQmlPointValueType |
| 130 | { |
| 131 | QPoint v; |
| 132 | Q_PROPERTY(int x READ x WRITE setX FINAL) |
| 133 | Q_PROPERTY(int y READ y WRITE setY FINAL) |
| 134 | Q_GADGET |
| 135 | QML_ANONYMOUS |
| 136 | QML_FOREIGN(QPoint) |
| 137 | QML_EXTENDED(QQmlPointValueType) |
| 138 | QML_STRUCTURED_VALUE |
| 139 | |
| 140 | public: |
| 141 | QQmlPointValueType() = default; |
| 142 | Q_INVOKABLE QQmlPointValueType(const QPointF &point) : v(point.toPoint()) {} |
| 143 | Q_INVOKABLE QString toString() const; |
| 144 | int x() const; |
| 145 | int y() const; |
| 146 | void setX(int); |
| 147 | void setY(int); |
| 148 | |
| 149 | operator QPoint() const { return v; } |
| 150 | }; |
| 151 | |
| 152 | struct Q_QML_EXPORT QQmlSizeFValueType |
| 153 | { |
| 154 | QSizeF v; |
| 155 | Q_PROPERTY(qreal width READ width WRITE setWidth FINAL) |
| 156 | Q_PROPERTY(qreal height READ height WRITE setHeight FINAL) |
| 157 | Q_GADGET |
| 158 | QML_VALUE_TYPE(size) |
| 159 | QML_FOREIGN(QSizeF) |
| 160 | QML_EXTENDED(QQmlSizeFValueType) |
| 161 | QML_STRUCTURED_VALUE |
| 162 | |
| 163 | public: |
| 164 | Q_INVOKABLE QQmlSizeFValueType() = default; |
| 165 | Q_INVOKABLE QQmlSizeFValueType(const QSize &size) : v(size) {} |
| 166 | Q_INVOKABLE QString toString() const; |
| 167 | qreal width() const; |
| 168 | qreal height() const; |
| 169 | void setWidth(qreal); |
| 170 | void setHeight(qreal); |
| 171 | |
| 172 | operator QSizeF() const { return v; } |
| 173 | }; |
| 174 | |
| 175 | struct Q_QML_EXPORT QQmlSizeValueType |
| 176 | { |
| 177 | QSize v; |
| 178 | Q_PROPERTY(int width READ width WRITE setWidth FINAL) |
| 179 | Q_PROPERTY(int height READ height WRITE setHeight FINAL) |
| 180 | Q_GADGET |
| 181 | QML_ANONYMOUS |
| 182 | QML_FOREIGN(QSize) |
| 183 | QML_EXTENDED(QQmlSizeValueType) |
| 184 | QML_STRUCTURED_VALUE |
| 185 | |
| 186 | public: |
| 187 | QQmlSizeValueType() = default; |
| 188 | Q_INVOKABLE QQmlSizeValueType(const QSizeF &size) : v(size.toSize()) {} |
| 189 | Q_INVOKABLE QString toString() const; |
| 190 | int width() const; |
| 191 | int height() const; |
| 192 | void setWidth(int); |
| 193 | void setHeight(int); |
| 194 | |
| 195 | operator QSize() const { return v; } |
| 196 | }; |
| 197 | |
| 198 | struct Q_QML_EXPORT QQmlRectFValueType |
| 199 | { |
| 200 | QRectF v; |
| 201 | Q_PROPERTY(qreal x READ x WRITE setX FINAL) |
| 202 | Q_PROPERTY(qreal y READ y WRITE setY FINAL) |
| 203 | Q_PROPERTY(qreal width READ width WRITE setWidth FINAL) |
| 204 | Q_PROPERTY(qreal height READ height WRITE setHeight FINAL) |
| 205 | Q_PROPERTY(qreal left READ left DESIGNABLE false FINAL) |
| 206 | Q_PROPERTY(qreal right READ right DESIGNABLE false FINAL) |
| 207 | Q_PROPERTY(qreal top READ top DESIGNABLE false FINAL) |
| 208 | Q_PROPERTY(qreal bottom READ bottom DESIGNABLE false FINAL) |
| 209 | Q_GADGET |
| 210 | QML_VALUE_TYPE(rect) |
| 211 | QML_FOREIGN(QRectF) |
| 212 | QML_EXTENDED(QQmlRectFValueType) |
| 213 | QML_STRUCTURED_VALUE |
| 214 | |
| 215 | public: |
| 216 | Q_INVOKABLE QQmlRectFValueType() = default; |
| 217 | Q_INVOKABLE QQmlRectFValueType(const QRect &rect) : v(rect) {} |
| 218 | Q_INVOKABLE QString toString() const; |
| 219 | qreal x() const; |
| 220 | qreal y() const; |
| 221 | void setX(qreal); |
| 222 | void setY(qreal); |
| 223 | |
| 224 | qreal width() const; |
| 225 | qreal height() const; |
| 226 | void setWidth(qreal); |
| 227 | void setHeight(qreal); |
| 228 | |
| 229 | qreal left() const; |
| 230 | qreal right() const; |
| 231 | qreal top() const; |
| 232 | qreal bottom() const; |
| 233 | |
| 234 | operator QRectF() const { return v; } |
| 235 | }; |
| 236 | |
| 237 | struct Q_QML_EXPORT QQmlRectValueType |
| 238 | { |
| 239 | QRect v; |
| 240 | Q_PROPERTY(int x READ x WRITE setX FINAL) |
| 241 | Q_PROPERTY(int y READ y WRITE setY FINAL) |
| 242 | Q_PROPERTY(int width READ width WRITE setWidth FINAL) |
| 243 | Q_PROPERTY(int height READ height WRITE setHeight FINAL) |
| 244 | Q_PROPERTY(int left READ left DESIGNABLE false FINAL) |
| 245 | Q_PROPERTY(int right READ right DESIGNABLE false FINAL) |
| 246 | Q_PROPERTY(int top READ top DESIGNABLE false FINAL) |
| 247 | Q_PROPERTY(int bottom READ bottom DESIGNABLE false FINAL) |
| 248 | Q_GADGET |
| 249 | QML_ANONYMOUS |
| 250 | QML_FOREIGN(QRect) |
| 251 | QML_EXTENDED(QQmlRectValueType) |
| 252 | QML_STRUCTURED_VALUE |
| 253 | |
| 254 | public: |
| 255 | QQmlRectValueType() = default; |
| 256 | Q_INVOKABLE QQmlRectValueType(const QRectF &rect) : v(rect.toRect()) {} |
| 257 | Q_INVOKABLE QString toString() const; |
| 258 | int x() const; |
| 259 | int y() const; |
| 260 | void setX(int); |
| 261 | void setY(int); |
| 262 | |
| 263 | int width() const; |
| 264 | int height() const; |
| 265 | void setWidth(int); |
| 266 | void setHeight(int); |
| 267 | |
| 268 | int left() const; |
| 269 | int right() const; |
| 270 | int top() const; |
| 271 | int bottom() const; |
| 272 | |
| 273 | operator QRect() const { return v; } |
| 274 | }; |
| 275 | |
| 276 | struct Q_QML_EXPORT QQmlMarginsFValueType |
| 277 | { |
| 278 | QMarginsF m; |
| 279 | Q_PROPERTY(qreal left READ left WRITE setLeft FINAL) |
| 280 | Q_PROPERTY(qreal right READ right WRITE setRight FINAL) |
| 281 | Q_PROPERTY(qreal top READ top WRITE setTop FINAL) |
| 282 | Q_PROPERTY(qreal bottom READ bottom WRITE setBottom FINAL) |
| 283 | Q_GADGET |
| 284 | QML_ANONYMOUS |
| 285 | QML_FOREIGN(QMarginsF) |
| 286 | QML_EXTENDED(QQmlMarginsFValueType) |
| 287 | QML_STRUCTURED_VALUE |
| 288 | |
| 289 | public: |
| 290 | QQmlMarginsFValueType() = default; |
| 291 | Q_INVOKABLE QQmlMarginsFValueType(const QMargins &margins) : m(margins) {} |
| 292 | Q_INVOKABLE QString toString() const; |
| 293 | qreal left() const; |
| 294 | qreal right() const; |
| 295 | qreal top() const; |
| 296 | qreal bottom() const; |
| 297 | void setLeft(qreal); |
| 298 | void setRight(qreal); |
| 299 | void setTop(qreal); |
| 300 | void setBottom(qreal); |
| 301 | |
| 302 | operator QMarginsF() const { return m; } |
| 303 | }; |
| 304 | |
| 305 | struct Q_QML_EXPORT QQmlMarginsValueType |
| 306 | { |
| 307 | QMargins m; |
| 308 | Q_PROPERTY(int left READ left WRITE setLeft FINAL) |
| 309 | Q_PROPERTY(int right READ right WRITE setRight FINAL) |
| 310 | Q_PROPERTY(int top READ top WRITE setTop FINAL) |
| 311 | Q_PROPERTY(int bottom READ bottom WRITE setBottom FINAL) |
| 312 | Q_GADGET |
| 313 | QML_ANONYMOUS |
| 314 | QML_FOREIGN(QMargins) |
| 315 | QML_EXTENDED(QQmlMarginsValueType) |
| 316 | QML_STRUCTURED_VALUE |
| 317 | |
| 318 | public: |
| 319 | QQmlMarginsValueType() = default; |
| 320 | Q_INVOKABLE QQmlMarginsValueType(const QMarginsF &margins) : m(margins.toMargins()) {} |
| 321 | Q_INVOKABLE QString toString() const; |
| 322 | int left() const; |
| 323 | int right() const; |
| 324 | int top() const; |
| 325 | int bottom() const; |
| 326 | void setLeft(int); |
| 327 | void setRight(int); |
| 328 | void setTop(int); |
| 329 | void setBottom(int); |
| 330 | |
| 331 | operator QMargins() const { return m; } |
| 332 | }; |
| 333 | |
| 334 | #if QT_CONFIG(easingcurve) |
| 335 | namespace QQmlEasingEnums |
| 336 | { |
| 337 | Q_NAMESPACE_EXPORT(Q_QML_EXPORT) |
| 338 | QML_NAMED_ELEMENT(Easing) |
| 339 | |
| 340 | enum Type { |
| 341 | Linear = QEasingCurve::Linear, |
| 342 | InQuad = QEasingCurve::InQuad, OutQuad = QEasingCurve::OutQuad, |
| 343 | InOutQuad = QEasingCurve::InOutQuad, OutInQuad = QEasingCurve::OutInQuad, |
| 344 | InCubic = QEasingCurve::InCubic, OutCubic = QEasingCurve::OutCubic, |
| 345 | InOutCubic = QEasingCurve::InOutCubic, OutInCubic = QEasingCurve::OutInCubic, |
| 346 | InQuart = QEasingCurve::InQuart, OutQuart = QEasingCurve::OutQuart, |
| 347 | InOutQuart = QEasingCurve::InOutQuart, OutInQuart = QEasingCurve::OutInQuart, |
| 348 | InQuint = QEasingCurve::InQuint, OutQuint = QEasingCurve::OutQuint, |
| 349 | InOutQuint = QEasingCurve::InOutQuint, OutInQuint = QEasingCurve::OutInQuint, |
| 350 | InSine = QEasingCurve::InSine, OutSine = QEasingCurve::OutSine, |
| 351 | InOutSine = QEasingCurve::InOutSine, OutInSine = QEasingCurve::OutInSine, |
| 352 | InExpo = QEasingCurve::InExpo, OutExpo = QEasingCurve::OutExpo, |
| 353 | InOutExpo = QEasingCurve::InOutExpo, OutInExpo = QEasingCurve::OutInExpo, |
| 354 | InCirc = QEasingCurve::InCirc, OutCirc = QEasingCurve::OutCirc, |
| 355 | InOutCirc = QEasingCurve::InOutCirc, OutInCirc = QEasingCurve::OutInCirc, |
| 356 | InElastic = QEasingCurve::InElastic, OutElastic = QEasingCurve::OutElastic, |
| 357 | InOutElastic = QEasingCurve::InOutElastic, OutInElastic = QEasingCurve::OutInElastic, |
| 358 | InBack = QEasingCurve::InBack, OutBack = QEasingCurve::OutBack, |
| 359 | InOutBack = QEasingCurve::InOutBack, OutInBack = QEasingCurve::OutInBack, |
| 360 | InBounce = QEasingCurve::InBounce, OutBounce = QEasingCurve::OutBounce, |
| 361 | InOutBounce = QEasingCurve::InOutBounce, OutInBounce = QEasingCurve::OutInBounce, |
| 362 | InCurve = QEasingCurve::InCurve, OutCurve = QEasingCurve::OutCurve, |
| 363 | SineCurve = QEasingCurve::SineCurve, CosineCurve = QEasingCurve::CosineCurve, |
| 364 | BezierSpline = QEasingCurve::BezierSpline, |
| 365 | |
| 366 | Bezier = BezierSpline // Evil! Don't use this! |
| 367 | }; |
| 368 | Q_ENUM_NS(Type) |
| 369 | }; |
| 370 | |
| 371 | struct Q_QML_EXPORT QQmlEasingValueType |
| 372 | { |
| 373 | QEasingCurve v; |
| 374 | Q_GADGET |
| 375 | QML_ANONYMOUS |
| 376 | QML_FOREIGN(QEasingCurve) |
| 377 | QML_EXTENDED(QQmlEasingValueType) |
| 378 | QML_STRUCTURED_VALUE |
| 379 | |
| 380 | Q_PROPERTY(QQmlEasingEnums::Type type READ type WRITE setType FINAL) |
| 381 | Q_PROPERTY(qreal amplitude READ amplitude WRITE setAmplitude FINAL) |
| 382 | Q_PROPERTY(qreal overshoot READ overshoot WRITE setOvershoot FINAL) |
| 383 | Q_PROPERTY(qreal period READ period WRITE setPeriod FINAL) |
| 384 | Q_PROPERTY(QVariantList bezierCurve READ bezierCurve WRITE setBezierCurve FINAL) |
| 385 | |
| 386 | public: |
| 387 | QQmlEasingEnums::Type type() const; |
| 388 | qreal amplitude() const; |
| 389 | qreal overshoot() const; |
| 390 | qreal period() const; |
| 391 | void setType(QQmlEasingEnums::Type); |
| 392 | void setAmplitude(qreal); |
| 393 | void setOvershoot(qreal); |
| 394 | void setPeriod(qreal); |
| 395 | void setBezierCurve(const QVariantList &); |
| 396 | QVariantList bezierCurve() const; |
| 397 | |
| 398 | operator QEasingCurve() const { return v; } |
| 399 | }; |
| 400 | #endif |
| 401 | |
| 402 | struct QQmlV4ExecutionEnginePtrForeign |
| 403 | { |
| 404 | Q_GADGET |
| 405 | QML_ANONYMOUS |
| 406 | QML_FOREIGN(QQmlV4ExecutionEnginePtr) |
| 407 | QML_EXTENDED(QQmlV4ExecutionEnginePtrForeign) |
| 408 | }; |
| 409 | |
| 410 | QT_END_NAMESPACE |
| 411 | |
| 412 | #endif // QQMLVALUETYPE_P_H |
| 413 | |