scripting: Add js object <-> QRectF/QSizeF/QPointF conversion helpers
The js code contains code such as window.frameGeometry = {x: 42, y: 42, width: 100, height: 50}; However, QJSEngine doesn't know how to convert js object to QRect. For that purpose, we need to register conversion functions. So far, we kept registering converter functions only for integer based geometry types, i.e. QRect, QSize and QPoint. In 5.26, Window was ported to QRectF, QSizeF and QPointF, but the corresponding conversion helpers were not added. BUG: 459369
This commit is contained in:
parent
b81123865d
commit
4696bdaa05
1 changed files with 31 additions and 0 deletions
|
@ -58,18 +58,38 @@ static QRect scriptValueToRect(const QJSValue &value)
|
|||
value.property(QStringLiteral("height")).toInt());
|
||||
}
|
||||
|
||||
static QRectF scriptValueToRectF(const QJSValue &value)
|
||||
{
|
||||
return QRectF(value.property(QStringLiteral("x")).toNumber(),
|
||||
value.property(QStringLiteral("y")).toNumber(),
|
||||
value.property(QStringLiteral("width")).toNumber(),
|
||||
value.property(QStringLiteral("height")).toNumber());
|
||||
}
|
||||
|
||||
static QPoint scriptValueToPoint(const QJSValue &value)
|
||||
{
|
||||
return QPoint(value.property(QStringLiteral("x")).toInt(),
|
||||
value.property(QStringLiteral("y")).toInt());
|
||||
}
|
||||
|
||||
static QPointF scriptValueToPointF(const QJSValue &value)
|
||||
{
|
||||
return QPointF(value.property(QStringLiteral("x")).toNumber(),
|
||||
value.property(QStringLiteral("y")).toNumber());
|
||||
}
|
||||
|
||||
static QSize scriptValueToSize(const QJSValue &value)
|
||||
{
|
||||
return QSize(value.property(QStringLiteral("width")).toInt(),
|
||||
value.property(QStringLiteral("height")).toInt());
|
||||
}
|
||||
|
||||
static QSizeF scriptValueToSizeF(const QJSValue &value)
|
||||
{
|
||||
return QSizeF(value.property(QStringLiteral("width")).toNumber(),
|
||||
value.property(QStringLiteral("height")).toNumber());
|
||||
}
|
||||
|
||||
KWin::AbstractScript::AbstractScript(int id, QString scriptName, QString pluginName, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_scriptId(id)
|
||||
|
@ -113,12 +133,23 @@ KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject *pa
|
|||
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QRect>()) {
|
||||
QMetaType::registerConverter<QJSValue, QRect>(scriptValueToRect);
|
||||
}
|
||||
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QRectF>()) {
|
||||
QMetaType::registerConverter<QJSValue, QRectF>(scriptValueToRectF);
|
||||
}
|
||||
|
||||
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QPoint>()) {
|
||||
QMetaType::registerConverter<QJSValue, QPoint>(scriptValueToPoint);
|
||||
}
|
||||
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QPointF>()) {
|
||||
QMetaType::registerConverter<QJSValue, QPointF>(scriptValueToPointF);
|
||||
}
|
||||
|
||||
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QSize>()) {
|
||||
QMetaType::registerConverter<QJSValue, QSize>(scriptValueToSize);
|
||||
}
|
||||
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QSizeF>()) {
|
||||
QMetaType::registerConverter<QJSValue, QSizeF>(scriptValueToSizeF);
|
||||
}
|
||||
|
||||
qRegisterMetaType<QList<KWin::Window *>>();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue