core/types: add implicit coversion from rect to box

This commit is contained in:
outfoxxed 2024-07-26 00:55:42 -07:00
parent 6b9b1fcb53
commit 58c3718287
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E

View file

@ -13,11 +13,21 @@ class Box {
Q_PROPERTY(qint32 h MEMBER h);
Q_PROPERTY(qint32 width MEMBER w);
Q_PROPERTY(qint32 height MEMBER h);
QML_CONSTRUCTIBLE_VALUE;
QML_VALUE_TYPE(box);
public:
explicit Box() = default;
Box(qint32 x, qint32 y, qint32 w, qint32 h): x(x), y(y), w(w), h(h) {}
Q_INVOKABLE Box(const QRect& rect): x(rect.x()), y(rect.y()), w(rect.width()), h(rect.height()) {}
Q_INVOKABLE Box(const QRectF& rect)
: x(static_cast<qint32>(rect.x()))
, y(static_cast<qint32>(rect.y()))
, w(static_cast<qint32>(rect.width()))
, h(static_cast<qint32>(rect.height())) {}
bool operator==(const Box& other) const;
qint32 x = 0;