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/QSizeF>
23 #include "../backportglobal.h"
25 Q_DECLARE_METATYPE(QSizeF
*)
26 Q_DECLARE_METATYPE(QSizeF
)
28 static QScriptValue
ctor(QScriptContext
*ctx
, QScriptEngine
*eng
)
30 if (ctx
->argumentCount() == 2)
32 qreal width
= ctx
->argument(1).toNumber();
33 qreal height
= ctx
->argument(1).toNumber();
34 return qScriptValueFromValue(eng
, QSizeF(width
, height
));
37 return qScriptValueFromValue(eng
, QSizeF());
40 static QScriptValue
width(QScriptContext
*ctx
, QScriptEngine
*eng
)
42 DECLARE_SELF(QSizeF
, width
);
43 return QScriptValue(eng
, self
->width());
46 static QScriptValue
height(QScriptContext
*ctx
, QScriptEngine
*eng
)
48 DECLARE_SELF(QSizeF
, height
);
49 return QScriptValue(eng
, self
->height());
52 QScriptValue
constructQSizeFClass(QScriptEngine
*eng
)
54 QScriptValue proto
= qScriptValueFromValue(eng
, QSizeF());
55 QScriptValue::PropertyFlags getter
= QScriptValue::PropertyGetter
;
56 QScriptValue::PropertyFlags setter
= QScriptValue::PropertySetter
;
58 proto
.setProperty("width", eng
->newFunction(width
));
59 proto
.setProperty("height", eng
->newFunction(height
));
61 return eng
->newFunction(ctor
, proto
);