Add the toDOMRect/fromDOMRect functions to QRectF
These are very helpful when converting to and from DOMRect. Change-Id: I4a7fc6318f45bed8e2b82fd5d6ec174dc1762326 Fixes: QTBUG-107740 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
parent
fda5061abd
commit
9c6b8ea290
@ -574,6 +574,10 @@ qt_internal_extend_target(Core CONDITION WIN32
|
||||
userenv
|
||||
)
|
||||
|
||||
qt_internal_extend_target(Core CONDITION WASM
|
||||
SOURCES
|
||||
kernel/qcore_wasm.cpp)
|
||||
|
||||
qt_internal_extend_target(Core CONDITION APPLE
|
||||
SOURCES
|
||||
global/qoperatingsystemversion_darwin.mm
|
||||
|
45
src/corelib/kernel/qcore_wasm.cpp
Normal file
45
src/corelib/kernel/qcore_wasm.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#include <QtCore/qrect.h>
|
||||
|
||||
#include <emscripten/val.h>
|
||||
|
||||
#if !defined(Q_OS_WASM)
|
||||
static_assert(false, "This is a wasm-only file.");
|
||||
#endif // !defined(Q_OS_WASM)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
/*!
|
||||
Converts the DOMRect (https://www.w3.org/TR/geometry-1/) \a domRect to QRectF. The behavior is
|
||||
undefined if the provided parameter is not a DOMRect.
|
||||
|
||||
\since 6.5
|
||||
\ingroup platform-type-conversions
|
||||
|
||||
\sa toDOMRect()
|
||||
*/
|
||||
QRectF QRectF::fromDOMRect(emscripten::val domRect)
|
||||
{
|
||||
Q_ASSERT_X(domRect["constructor"]["name"].as<std::string>() == "DOMRect", Q_FUNC_INFO,
|
||||
"Passed object is not a DOMRect");
|
||||
|
||||
return QRectF(domRect["left"].as<qreal>(), domRect["top"].as<qreal>(),
|
||||
domRect["width"].as<qreal>(), domRect["height"].as<qreal>());
|
||||
}
|
||||
|
||||
/*!
|
||||
Converts this object to a DOMRect (https://www.w3.org/TR/geometry-1/).
|
||||
|
||||
\since 6.5
|
||||
\ingroup platform-type-conversions
|
||||
|
||||
\sa fromDOMRect()
|
||||
*/
|
||||
emscripten::val QRectF::toDOMRect() const
|
||||
{
|
||||
return emscripten::val::global("DOMRect").new_(left(), top(), width(), height());
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
@ -16,6 +16,11 @@
|
||||
#if defined(Q_OS_DARWIN) || defined(Q_QDOC)
|
||||
struct CGRect;
|
||||
#endif
|
||||
#if defined(Q_OS_WASM) || defined(Q_QDOC)
|
||||
namespace emscripten {
|
||||
class val;
|
||||
}
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -586,6 +591,11 @@ public:
|
||||
[[nodiscard]] CGRect toCGRect() const noexcept;
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WASM) || defined(Q_QDOC)
|
||||
[[nodiscard]] static QRectF fromDOMRect(emscripten::val domRect);
|
||||
[[nodiscard]] emscripten::val toDOMRect() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
qreal xp;
|
||||
qreal yp;
|
||||
|
Loading…
x
Reference in New Issue
Block a user