summaryrefslogtreecommitdiffstats
path: root/scriptwrappers.cpp
diff options
context:
space:
mode:
authorJesper K. Pedersen <jesper.pedersen@kdab.com>2013-04-17 12:09:57 +0200
committerJesper K. Pedersen <jesper.pedersen@kdab.com>2013-04-17 20:50:24 +0200
commit487770e422e4c55e128c210bb82b30ed99f3f401 (patch)
tree2827f7ec704ea06cc4de858eaf56f4ce68a8b35c /scriptwrappers.cpp
parente793225595a8010d35506011ac2a915df8e21119 (diff)
Introduced the class TextEditor
This is to make it similar in heirarchy as the IEditor subclasses. This commit also wraps QPoint and QRect so they are usable from the scripts Change-Id: I214a7323cf6cc20cb9df509d0ea0515358248714 Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Diffstat (limited to 'scriptwrappers.cpp')
-rw-r--r--scriptwrappers.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/scriptwrappers.cpp b/scriptwrappers.cpp
new file mode 100644
index 0000000..2111504
--- /dev/null
+++ b/scriptwrappers.cpp
@@ -0,0 +1,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