2 * Copyright 2007 Richard J. Moore <rich@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <QtScript/QScriptValue>
20 #include <QtScript/QScriptEngine>
21 #include <QtScript/QScriptContext>
22 #include <QtCore/QRectF>
23 #include "../backportglobal.h"
25 Q_DECLARE_METATYPE(QRectF
*)
26 Q_DECLARE_METATYPE(QRectF
)
28 static QScriptValue
ctor(QScriptContext
*ctx
, QScriptEngine
*eng
)
30 if (ctx
->argumentCount() == 4)
32 qreal x
= ctx
->argument(0).toNumber();
33 qreal y
= ctx
->argument(1).toNumber();
34 qreal width
= ctx
->argument(2).toNumber();
35 qreal height
= ctx
->argument(3).toNumber();
36 return qScriptValueFromValue(eng
, QRectF(x
, y
, width
, height
));
39 return qScriptValueFromValue(eng
, QRectF());
42 static QScriptValue
adjust(QScriptContext
*ctx
, QScriptEngine
*)
44 DECLARE_SELF(QRectF
, adjust
);
45 qreal dx1
= ctx
->argument(0).toNumber();
46 qreal dy1
= ctx
->argument(1).toNumber();
47 qreal dx2
= ctx
->argument(2).toNumber();
48 qreal dy2
= ctx
->argument(3).toNumber();
50 self
->adjust(dx1
, dy1
, dx2
, dy2
);
51 return QScriptValue();
54 static QScriptValue
adjusted(QScriptContext
*ctx
, QScriptEngine
*eng
)
56 DECLARE_SELF(QRectF
, adjusted
);
57 qreal dx1
= ctx
->argument(0).toNumber();
58 qreal dy1
= ctx
->argument(1).toNumber();
59 qreal dx2
= ctx
->argument(2).toNumber();
60 qreal dy2
= ctx
->argument(3).toNumber();
62 QRectF tmp
= self
->adjusted(dx1
, dy1
, dx2
, dy2
);
63 return qScriptValueFromValue(eng
, tmp
);
66 static QScriptValue
bottom(QScriptContext
*ctx
, QScriptEngine
*eng
)
68 DECLARE_SELF(QRectF
, bottom
);
69 return QScriptValue(eng
, self
->bottom());
72 static QScriptValue
top(QScriptContext
*ctx
, QScriptEngine
*eng
)
74 DECLARE_SELF(QRectF
, top
);
75 return QScriptValue(eng
, self
->top());
78 static QScriptValue
contains(QScriptContext
*ctx
, QScriptEngine
*eng
)
80 DECLARE_SELF(QRectF
, contains
);
81 qreal x
= ctx
->argument(0).toNumber();
82 qreal y
= ctx
->argument(1).toNumber();
83 return QScriptValue(eng
, self
->contains(x
, y
));
86 static QScriptValue
height(QScriptContext
*ctx
, QScriptEngine
*eng
)
88 DECLARE_SELF(QRectF
, height
);
89 return QScriptValue(eng
, self
->height());
92 static QScriptValue
isEmpty(QScriptContext
*ctx
, QScriptEngine
*eng
)
94 DECLARE_SELF(QRectF
, isEmpty
);
95 return QScriptValue(eng
, self
->isEmpty());
98 static QScriptValue
isNull(QScriptContext
*ctx
, QScriptEngine
*eng
)
100 DECLARE_SELF(QRectF
, isNull
);
101 return QScriptValue(eng
, self
->isNull());
104 static QScriptValue
isValid(QScriptContext
*ctx
, QScriptEngine
*eng
)
106 DECLARE_SELF(QRectF
, isValid
);
107 return QScriptValue(eng
, self
->isValid());
110 static QScriptValue
left(QScriptContext
*ctx
, QScriptEngine
*eng
)
112 DECLARE_SELF(QRectF
, left
);
113 return QScriptValue(eng
, self
->left());
116 static QScriptValue
moveBottom(QScriptContext
*ctx
, QScriptEngine
*)
118 DECLARE_SELF(QRectF
, moveBottom
);
119 qreal bottom
= ctx
->argument(0).toNumber();
120 self
->moveBottom(bottom
);
121 return QScriptValue();
124 static QScriptValue
moveLeft(QScriptContext
*ctx
, QScriptEngine
*)
126 DECLARE_SELF(QRectF
, moveLeft
);
127 qreal left
= ctx
->argument(0).toNumber();
128 self
->moveBottom(left
);
129 return QScriptValue();
132 static QScriptValue
moveRight(QScriptContext
*ctx
, QScriptEngine
*)
134 DECLARE_SELF(QRectF
, moveRight
);
135 qreal right
= ctx
->argument(0).toNumber();
136 self
->moveBottom(right
);
137 return QScriptValue();
141 static QScriptValue
moveTo(QScriptContext
*ctx
, QScriptEngine
*)
143 DECLARE_SELF(QRectF
, moveTo
);
144 qreal x
= ctx
->argument(0).toNumber();
145 qreal y
= ctx
->argument(1).toNumber();
147 return QScriptValue();
150 static QScriptValue
moveTop(QScriptContext
*ctx
, QScriptEngine
*)
152 DECLARE_SELF(QRectF
, moveTop
);
153 qreal top
= ctx
->argument(0).toNumber();
155 return QScriptValue();
158 static QScriptValue
right(QScriptContext
*ctx
, QScriptEngine
*eng
)
160 DECLARE_SELF(QRectF
, right
);
161 return QScriptValue(eng
, self
->right());
164 static QScriptValue
setBottom(QScriptContext
*ctx
, QScriptEngine
*)
166 DECLARE_SELF(QRectF
, setBottom
);
167 qreal bottom
= ctx
->argument(0).toNumber();
168 self
->setBottom(bottom
);
169 return QScriptValue();
172 static QScriptValue
setCoords(QScriptContext
*ctx
, QScriptEngine
*)
174 DECLARE_SELF(QRectF
, setCoords
);
175 qreal x1
= ctx
->argument(0).toNumber();
176 qreal y1
= ctx
->argument(1).toNumber();
177 qreal x2
= ctx
->argument(2).toNumber();
178 qreal y2
= ctx
->argument(3).toNumber();
179 self
->setCoords(x1
, y1
, x2
, y2
);
180 return QScriptValue();
183 static QScriptValue
setHeight(QScriptContext
*ctx
, QScriptEngine
*)
185 DECLARE_SELF(QRectF
, setHeight
);
186 qreal height
= ctx
->argument(0).toNumber();
187 self
->setHeight(height
);
188 return QScriptValue();
191 static QScriptValue
setLeft(QScriptContext
*ctx
, QScriptEngine
*)
193 DECLARE_SELF(QRectF
, setLeft
);
194 qreal left
= ctx
->argument(0).toNumber();
196 return QScriptValue();
199 static QScriptValue
setRect(QScriptContext
*ctx
, QScriptEngine
*)
201 DECLARE_SELF(QRectF
, setRect
);
202 qreal x
= ctx
->argument(0).toNumber();
203 qreal y
= ctx
->argument(1).toNumber();
204 qreal width
= ctx
->argument(2).toNumber();
205 qreal height
= ctx
->argument(3).toNumber();
206 self
->setRect(x
, y
, width
, height
);
207 return QScriptValue();
210 static QScriptValue
setRight(QScriptContext
*ctx
, QScriptEngine
*)
212 DECLARE_SELF(QRectF
, setRight
);
213 qreal right
= ctx
->argument(0).toNumber();
214 self
->setRight(right
);
215 return QScriptValue();
218 static QScriptValue
setTop(QScriptContext
*ctx
, QScriptEngine
*)
220 DECLARE_SELF(QRectF
, setTop
);
221 qreal top
= ctx
->argument(0).toNumber();
223 return QScriptValue();
226 static QScriptValue
setWidth(QScriptContext
*ctx
, QScriptEngine
*)
228 DECLARE_SELF(QRectF
, setWidth
);
229 qreal width
= ctx
->argument(0).toNumber();
230 self
->setWidth(width
);
231 return QScriptValue();
234 static QScriptValue
setX(QScriptContext
*ctx
, QScriptEngine
*)
236 DECLARE_SELF(QRectF
, setX
);
237 qreal x
= ctx
->argument(0).toNumber();
239 return QScriptValue();
242 static QScriptValue
setY(QScriptContext
*ctx
, QScriptEngine
*)
244 DECLARE_SELF(QRectF
, setY
);
245 qreal y
= ctx
->argument(0).toNumber();
247 return QScriptValue();
250 static QScriptValue
translate(QScriptContext
*ctx
, QScriptEngine
*)
252 DECLARE_SELF(QRectF
, translate
);
253 qreal dx
= ctx
->argument(0).toNumber();
254 qreal dy
= ctx
->argument(1).toNumber();
255 self
->translate(dx
, dy
);
256 return QScriptValue();
259 static QScriptValue
width(QScriptContext
*ctx
, QScriptEngine
*eng
)
261 DECLARE_SELF(QRectF
, width
);
262 return QScriptValue(eng
, self
->width());
265 static QScriptValue
x(QScriptContext
*ctx
, QScriptEngine
*eng
)
267 DECLARE_SELF(QRectF
, x
);
268 return QScriptValue(eng
, self
->x());
271 static QScriptValue
y(QScriptContext
*ctx
, QScriptEngine
*eng
)
273 DECLARE_SELF(QRectF
, y
);
274 return QScriptValue(eng
, self
->y());
277 /* Not Implemented Yet */
278 // QPointF bottomLeft () const
279 // QPointF bottomRight () const
280 // QPointF center () const
281 // bool contains ( const QPointF & point ) const
282 // bool contains ( const QRectF & rectangle ) const
283 // void getCoords ( qreal * x1, qreal * y1, qreal * x2, qreal * y2 ) const
284 // void getRect ( qreal * x, qreal * y, qreal * width, qreal * height ) const
285 // QRectF intersected ( const QRectF & rectangle ) const
286 // bool intersects ( const QRectF & rectangle ) const
287 // void moveBottomLeft ( const QPointF & position )
288 // void moveBottomRight ( const QPointF & position )
289 // void moveCenter ( const QPointF & position )
290 // void moveTo ( const QPointF & position )
291 // void moveTopLeft ( const QPointF & position )
292 // void moveTopRight ( const QPointF & position )
293 // QRectF normalized () const
294 // void setBottomLeft ( const QPointF & position )
295 // void setBottomRight ( const QPointF & position )
296 // void setSize ( const QSizeF & size )
297 // void setTopLeft ( const QPointF & position )
298 // void setTopRight ( const QPointF & position )
299 // QSizeF size () const
300 // QRect toAlignedRect () const
301 // QRect toRect () const
302 // QPointF topLeft () const
303 // QPointF topRight () const
304 // void translate ( const QPointF & offset )
305 // QRectF translated ( qreal dx, qreal dy ) const
306 // QRectF translated ( const QPointF & offset ) const
307 // QRectF united ( const QRectF & rectangle ) const
309 QScriptValue
constructQRectFClass(QScriptEngine
*eng
)
311 QScriptValue proto
= qScriptValueFromValue(eng
, QRectF());
312 QScriptValue::PropertyFlags getter
= QScriptValue::PropertyGetter
;
313 QScriptValue::PropertyFlags setter
= QScriptValue::PropertySetter
;
315 proto
.setProperty("adjust", eng
->newFunction(adjust
));
316 proto
.setProperty("bottom", eng
->newFunction(bottom
));
317 proto
.setProperty("contains", eng
->newFunction(contains
));
318 proto
.setProperty("height", eng
->newFunction(height
));
319 proto
.setProperty("isEmpty", eng
->newFunction(isEmpty
));
320 proto
.setProperty("isNull", eng
->newFunction(isNull
));
321 proto
.setProperty("isValid", eng
->newFunction(isValid
));
322 proto
.setProperty("left", eng
->newFunction(left
));
323 proto
.setProperty("moveBottom", eng
->newFunction(moveBottom
));
324 proto
.setProperty("moveLeft", eng
->newFunction(moveLeft
));
325 proto
.setProperty("moveRight", eng
->newFunction(moveRight
));
326 proto
.setProperty("moveTo", eng
->newFunction(moveTo
));
327 proto
.setProperty("moveTop", eng
->newFunction(moveTop
));
328 proto
.setProperty("right", eng
->newFunction(right
));
329 proto
.setProperty("setBottom", eng
->newFunction(setBottom
));
330 proto
.setProperty("setCoords", eng
->newFunction(setCoords
));
331 proto
.setProperty("setHeight", eng
->newFunction(setHeight
));
332 proto
.setProperty("setLeft", eng
->newFunction(setLeft
));
333 proto
.setProperty("setRect", eng
->newFunction(setRect
));
334 proto
.setProperty("setRight", eng
->newFunction(setRight
));
335 proto
.setProperty("setTop", eng
->newFunction(setTop
));
336 proto
.setProperty("setWidth", eng
->newFunction(setWidth
));
337 proto
.setProperty("setX", eng
->newFunction(setX
));
338 proto
.setProperty("setY", eng
->newFunction(setY
));
339 proto
.setProperty("top", eng
->newFunction(top
));
340 proto
.setProperty("translate", eng
->newFunction(translate
));
341 proto
.setProperty("width", eng
->newFunction(width
));
342 proto
.setProperty("x", eng
->newFunction(x
));
343 proto
.setProperty("y", eng
->newFunction(y
));
345 eng
->setDefaultPrototype(qMetaTypeId
<QRectF
>(), proto
);
346 eng
->setDefaultPrototype(qMetaTypeId
<QRectF
*>(), proto
);
348 return eng
->newFunction(ctor
, proto
);