From 4696bdaa05f3990b3e70fa276c565ea623df1d5c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 19 Sep 2022 13:49:17 +0300 Subject: [PATCH] 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 --- src/scripting/scripting.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/scripting/scripting.cpp b/src/scripting/scripting.cpp index e82b3a2ec5..10140449c5 100644 --- a/src/scripting/scripting.cpp +++ b/src/scripting/scripting.cpp @@ -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()) { QMetaType::registerConverter(scriptValueToRect); } + if (!QMetaType::hasRegisteredConverterFunction()) { + QMetaType::registerConverter(scriptValueToRectF); + } + if (!QMetaType::hasRegisteredConverterFunction()) { QMetaType::registerConverter(scriptValueToPoint); } + if (!QMetaType::hasRegisteredConverterFunction()) { + QMetaType::registerConverter(scriptValueToPointF); + } + if (!QMetaType::hasRegisteredConverterFunction()) { QMetaType::registerConverter(scriptValueToSize); } + if (!QMetaType::hasRegisteredConverterFunction()) { + QMetaType::registerConverter(scriptValueToSizeF); + } qRegisterMetaType>(); }