summaryrefslogtreecommitdiffstats
path: root/scriptwrappers.cpp
blob: 211150464d349436b861fcfb928784c659c1d81d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "scriptwrappers.h"
#include <QPoint>
#include <QRect>

namespace Scripting {
namespace Internal {

QScriptValue scriptValueFromQPoint(QScriptEngine *engine, const QPoint &point)
{
  QScriptValue obj = engine->newObject();
  obj.setProperty(QLatin1String("x"), point.x());
  obj.setProperty(QLatin1String("y"), point.y());
  return obj;
}

void QPointFromScriptValue(const QScriptValue &obj, QPoint& point)
{
    point.setX( obj.property(QLatin1String("x")).toInt32() );
    point.setY( obj.property(QLatin1String("y")).toInt32() );
}

QScriptValue scriptValueFromQRect(QScriptEngine *engine, const QRect &rect)
{
  QScriptValue obj = engine->newObject();
  obj.setProperty(QLatin1String("x"), rect.x());
  obj.setProperty(QLatin1String("y"), rect.y());
  obj.setProperty(QLatin1String("width"), rect.width());
  obj.setProperty(QLatin1String("height"), rect.height());
  return obj;
}

void QRectFromScriptValue(const QScriptValue &obj, QRect& rect)
{
    rect.setX( obj.property(QLatin1String("x")).toInt32() );
    rect.setY( obj.property(QLatin1String("y")).toInt32() );
    rect.setWidth( obj.property(QLatin1String("width")).toInt32() );
    rect.setHeight( obj.property(QLatin1String("height")).toInt32() );
}


void registerWrappers(QScriptEngine* engine )
{
    qScriptRegisterMetaType(engine, scriptValueFromQPoint, QPointFromScriptValue );
    qScriptRegisterMetaType(engine, scriptValueFromQRect, QRectFromScriptValue );
}

} // namespace Internal
} // namespace Scripting