add more spacing
[personal-kdebase.git] / workspace / plasma / scriptengines / javascript / qtgui / font.cpp
blobb3c5b6f574f51d2820c0501025f9bbc409c18bd1
1 /*
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 <QtGui/QFont>
23 #include "../backportglobal.h"
25 Q_DECLARE_METATYPE(QFont*)
27 static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
29 if (ctx->argumentCount() == 0)
30 return qScriptValueFromValue(eng, QFont());
31 QString family = ctx->argument(0).toString();
32 if (ctx->argumentCount() == 1) {
33 QFont *other = qscriptvalue_cast<QFont*>(ctx->argument(0));
34 if (other)
35 return qScriptValueFromValue(eng, QFont(*other));
36 return qScriptValueFromValue(eng, QFont(family));
38 int pointSize = ctx->argument(1).toInt32();
39 if (ctx->argumentCount() == 2)
40 return qScriptValueFromValue(eng, QFont(family, pointSize));
41 int weight = ctx->argument(2).toInt32();
42 if (ctx->argumentCount() == 3)
43 return qScriptValueFromValue(eng, QFont(family, pointSize, weight));
44 bool italic = ctx->argument(3).toBoolean();
45 return qScriptValueFromValue(eng, QFont(family, pointSize, weight, italic));
48 static QScriptValue bold(QScriptContext *ctx, QScriptEngine *eng)
50 DECLARE_SELF(QFont, bold);
51 return QScriptValue(eng, self->bold());
54 static QScriptValue defaultFamily(QScriptContext *ctx, QScriptEngine *eng)
56 DECLARE_SELF(QFont, defaultFamily);
57 return QScriptValue(eng, self->defaultFamily());
60 static QScriptValue exactMatch(QScriptContext *ctx, QScriptEngine *eng)
62 DECLARE_SELF(QFont, exactMatch);
63 return QScriptValue(eng, self->exactMatch());
66 static QScriptValue family(QScriptContext *ctx, QScriptEngine *eng)
68 DECLARE_SELF(QFont, family);
69 return QScriptValue(eng, self->family());
72 static QScriptValue fixedPitch(QScriptContext *ctx, QScriptEngine *eng)
74 DECLARE_SELF(QFont, fixedPitch);
75 return QScriptValue(eng, self->fixedPitch());
78 static QScriptValue fromString(QScriptContext *ctx, QScriptEngine *eng)
80 DECLARE_SELF(QFont, fromString);
81 return QScriptValue(eng, self->fromString(ctx->argument(0).toString()));
84 static QScriptValue handle(QScriptContext *ctx, QScriptEngine *)
86 return ctx->throwError("QFont.prototype.handle is not implemented");
89 static QScriptValue isCopyOf(QScriptContext *ctx, QScriptEngine *eng)
91 DECLARE_SELF(QFont, isCopyOf);
92 QFont *other = qscriptvalue_cast<QFont*>(ctx->argument(0));
93 if (!other) {
94 return ctx->throwError(QScriptContext::TypeError,
95 "QFont.prototype.isCopyOf: argument is not a Font");
97 return QScriptValue(eng, self->isCopyOf(*other));
100 static QScriptValue italic(QScriptContext *ctx, QScriptEngine *eng)
102 DECLARE_SELF(QFont, italic);
103 return QScriptValue(eng, self->italic());
106 static QScriptValue kerning(QScriptContext *ctx, QScriptEngine *eng)
108 DECLARE_SELF(QFont, kerning);
109 return QScriptValue(eng, self->kerning());
112 static QScriptValue key(QScriptContext *ctx, QScriptEngine *eng)
114 DECLARE_SELF(QFont, key);
115 return QScriptValue(eng, self->key());
118 static QScriptValue lastResortFamily(QScriptContext *ctx, QScriptEngine *eng)
120 DECLARE_SELF(QFont, lastResortFamily);
121 return QScriptValue(eng, self->lastResortFamily());
124 static QScriptValue lastResortFont(QScriptContext *ctx, QScriptEngine *eng)
126 DECLARE_SELF(QFont, lastResortFont);
127 return QScriptValue(eng, self->lastResortFont());
130 static QScriptValue overline(QScriptContext *ctx, QScriptEngine *eng)
132 DECLARE_SELF(QFont, overline);
133 return QScriptValue(eng, self->overline());
136 static QScriptValue pixelSize(QScriptContext *ctx, QScriptEngine *eng)
138 DECLARE_SELF(QFont, pixelSize);
139 return QScriptValue(eng, self->pixelSize());
142 static QScriptValue pointSize(QScriptContext *ctx, QScriptEngine *eng)
144 DECLARE_SELF(QFont, pointSize);
145 return QScriptValue(eng, self->pointSize());
148 static QScriptValue pointSizeF(QScriptContext *ctx, QScriptEngine *eng)
150 DECLARE_SELF(QFont, pointSizeF);
151 return QScriptValue(eng, self->pointSizeF());
154 static QScriptValue rawMode(QScriptContext *ctx, QScriptEngine *eng)
156 DECLARE_SELF(QFont, rawMode);
157 return QScriptValue(eng, self->rawMode());
160 static QScriptValue rawName(QScriptContext *ctx, QScriptEngine *eng)
162 DECLARE_SELF(QFont, rawName);
163 return QScriptValue(eng, self->rawName());
166 static QScriptValue resolve(QScriptContext *ctx, QScriptEngine *eng)
168 DECLARE_SELF(QFont, resolve);
169 QFont *other = qscriptvalue_cast<QFont*>(ctx->argument(0));
170 if (!other) {
171 return ctx->throwError(QScriptContext::TypeError,
172 "QFont.prototype.isCopyOf: argument is not a Font");
174 return qScriptValueFromValue(eng, self->resolve(*other));
177 static QScriptValue setBold(QScriptContext *ctx, QScriptEngine *)
179 DECLARE_SELF(QFont, setBold);
180 QScriptValue arg = ctx->argument(0);
181 self->setBold(arg.toBoolean());
182 return arg;
185 static QScriptValue setFamily(QScriptContext *ctx, QScriptEngine *)
187 DECLARE_SELF(QFont, setFamily);
188 QScriptValue arg = ctx->argument(0);
189 self->setFamily(arg.toString());
190 return arg;
193 static QScriptValue setFixedPitch(QScriptContext *ctx, QScriptEngine *)
195 DECLARE_SELF(QFont, setFixedPitch);
196 QScriptValue arg = ctx->argument(0);
197 self->setFixedPitch(arg.toBoolean());
198 return arg;
201 static QScriptValue setItalic(QScriptContext *ctx, QScriptEngine *)
203 DECLARE_SELF(QFont, setItalic);
204 QScriptValue arg = ctx->argument(0);
205 self->setItalic(arg.toBoolean());
206 return arg;
209 static QScriptValue setKerning(QScriptContext *ctx, QScriptEngine *)
211 DECLARE_SELF(QFont, setKerning);
212 QScriptValue arg = ctx->argument(0);
213 self->setKerning(arg.toBoolean());
214 return arg;
217 static QScriptValue setOverline(QScriptContext *ctx, QScriptEngine *)
219 DECLARE_SELF(QFont, setOverline);
220 QScriptValue arg = ctx->argument(0);
221 self->setOverline(arg.toBoolean());
222 return arg;
225 static QScriptValue setPixelSize(QScriptContext *ctx, QScriptEngine *)
227 DECLARE_SELF(QFont, setPixelSize);
228 QScriptValue arg = ctx->argument(0);
229 self->setPixelSize(arg.toInt32());
230 return arg;
233 static QScriptValue setPointSize(QScriptContext *ctx, QScriptEngine *)
235 DECLARE_SELF(QFont, setPointSize);
236 QScriptValue arg = ctx->argument(0);
237 self->setPointSize(arg.toInt32());
238 return arg;
241 static QScriptValue setPointSizeF(QScriptContext *ctx, QScriptEngine *)
243 DECLARE_SELF(QFont, setPointSizeF);
244 QScriptValue arg = ctx->argument(0);
245 self->setPointSizeF(arg.toNumber());
246 return arg;
249 static QScriptValue setRawMode(QScriptContext *ctx, QScriptEngine *)
251 DECLARE_SELF(QFont, setRawMode);
252 QScriptValue arg = ctx->argument(0);
253 self->setRawMode(arg.toBoolean());
254 return arg;
257 static QScriptValue setRawName(QScriptContext *ctx, QScriptEngine *)
259 DECLARE_SELF(QFont, setRawName);
260 QScriptValue arg = ctx->argument(0);
261 self->setRawName(arg.toString());
262 return arg;
265 static QScriptValue setStretch(QScriptContext *ctx, QScriptEngine *)
267 DECLARE_SELF(QFont, setStretch);
268 QScriptValue arg = ctx->argument(0);
269 self->setStretch(arg.toInt32());
270 return arg;
273 static QScriptValue setStrikeOut(QScriptContext *ctx, QScriptEngine *)
275 DECLARE_SELF(QFont, setStrikeOut);
276 QScriptValue arg = ctx->argument(0);
277 self->setStrikeOut(arg.toBoolean());
278 return arg;
281 static QScriptValue setStyle(QScriptContext *ctx, QScriptEngine *)
283 return ctx->throwError("QFont.setStyle");
286 static QScriptValue setStyleHint(QScriptContext *ctx, QScriptEngine *)
288 return ctx->throwError("QFont.setStyleHint");
291 static QScriptValue setStyleStrategy(QScriptContext *ctx, QScriptEngine *)
293 return ctx->throwError("QFont.setStyleStrategy");
296 static QScriptValue setUnderline(QScriptContext *ctx, QScriptEngine *)
298 DECLARE_SELF(QFont, setUnderline);
299 QScriptValue arg = ctx->argument(0);
300 self->setUnderline(arg.toBoolean());
301 return arg;
304 static QScriptValue setWeight(QScriptContext *ctx, QScriptEngine *)
306 DECLARE_SELF(QFont, setWeight);
307 QScriptValue arg = ctx->argument(0);
308 self->setWeight(arg.toInt32());
309 return arg;
312 static QScriptValue stretch(QScriptContext *ctx, QScriptEngine *eng)
314 DECLARE_SELF(QFont, stretch);
315 return QScriptValue(eng, self->stretch());
318 static QScriptValue strikeOut(QScriptContext *ctx, QScriptEngine *eng)
320 DECLARE_SELF(QFont, strikeOut);
321 return QScriptValue(eng, self->strikeOut());
324 static QScriptValue style(QScriptContext *ctx, QScriptEngine *)
326 return ctx->throwError("QFont.prototype.style is not implemented");
329 static QScriptValue styleHint(QScriptContext *ctx, QScriptEngine *)
331 return ctx->throwError("QFont.prototype.styleHint is not implemented");
334 static QScriptValue styleStrategy(QScriptContext *ctx, QScriptEngine *)
336 return ctx->throwError("QFont.prototype.styleStrategy is not implemented");
339 static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
341 DECLARE_SELF(QFont, toString);
342 return QScriptValue(eng, self->toString());
345 static QScriptValue underline(QScriptContext *ctx, QScriptEngine *eng)
347 DECLARE_SELF(QFont, underline);
348 return QScriptValue(eng, self->underline());
351 static QScriptValue weight(QScriptContext *ctx, QScriptEngine *eng)
353 DECLARE_SELF(QFont, weight);
354 return QScriptValue(eng, self->weight());
357 QScriptValue constructFontClass(QScriptEngine *eng)
359 QScriptValue proto = qScriptValueFromValue(eng, QFont());
360 QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
361 QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
362 proto.setProperty("bold", eng->newFunction(bold), getter);
363 proto.setProperty("defaultFamily", eng->newFunction(defaultFamily));
364 proto.setProperty("exactMatch", eng->newFunction(exactMatch));
365 proto.setProperty("family", eng->newFunction(family), getter);
366 proto.setProperty("fixedPitch", eng->newFunction(fixedPitch), getter);
367 proto.setProperty("fromString", eng->newFunction(fromString));
368 proto.setProperty("handle", eng->newFunction(handle));
369 proto.setProperty("isCopyOf", eng->newFunction(isCopyOf));
370 proto.setProperty("italic", eng->newFunction(italic), getter);
371 proto.setProperty("kerning", eng->newFunction(kerning), getter);
372 proto.setProperty("key", eng->newFunction(key), getter);
373 proto.setProperty("lastResortFamily", eng->newFunction(lastResortFamily));
374 proto.setProperty("lastResortFont", eng->newFunction(lastResortFont));
375 proto.setProperty("overline", eng->newFunction(overline), getter);
376 proto.setProperty("pixelSize", eng->newFunction(pixelSize), getter);
377 proto.setProperty("pointSize", eng->newFunction(pointSize), getter);
378 proto.setProperty("pointSizeF", eng->newFunction(pointSizeF), getter);
379 proto.setProperty("rawMode", eng->newFunction(rawMode), getter);
380 proto.setProperty("rawName", eng->newFunction(rawName), getter);
381 proto.setProperty("resolve", eng->newFunction(resolve));
382 proto.setProperty("bold", eng->newFunction(setBold), setter);
383 proto.setProperty("bamily", eng->newFunction(setFamily), setter);
384 proto.setProperty("fixedPitch", eng->newFunction(setFixedPitch), setter);
385 proto.setProperty("italic", eng->newFunction(setItalic), setter);
386 proto.setProperty("kerning", eng->newFunction(setKerning), setter);
387 proto.setProperty("overline", eng->newFunction(setOverline), setter);
388 proto.setProperty("pixelSize", eng->newFunction(setPixelSize), setter);
389 proto.setProperty("pointSize", eng->newFunction(setPointSize), setter);
390 proto.setProperty("pointSizeF", eng->newFunction(setPointSizeF), setter);
391 proto.setProperty("rawMode", eng->newFunction(setRawMode), setter);
392 proto.setProperty("rawName", eng->newFunction(setRawName), setter);
393 proto.setProperty("stretch", eng->newFunction(setStretch), setter);
394 proto.setProperty("strikeOut", eng->newFunction(setStrikeOut), setter);
395 proto.setProperty("setStyle", eng->newFunction(setStyle));
396 proto.setProperty("setStyleHint", eng->newFunction(setStyleHint));
397 proto.setProperty("setStyleStrategy", eng->newFunction(setStyleStrategy));
398 proto.setProperty("underline", eng->newFunction(setUnderline), setter);
399 proto.setProperty("weight", eng->newFunction(setWeight), setter);
400 proto.setProperty("stretch", eng->newFunction(stretch), getter);
401 proto.setProperty("strikeOut", eng->newFunction(strikeOut), getter);
402 proto.setProperty("style", eng->newFunction(style));
403 proto.setProperty("styleHint", eng->newFunction(styleHint));
404 proto.setProperty("styleStrategy", eng->newFunction(styleStrategy));
405 proto.setProperty("toString", eng->newFunction(toString));
406 proto.setProperty("underline", eng->newFunction(underline), getter);
407 proto.setProperty("weight", eng->newFunction(weight), getter);
409 eng->setDefaultPrototype(qMetaTypeId<QFont>(), proto);
410 eng->setDefaultPrototype(qMetaTypeId<QFont*>(), proto);
412 return eng->newFunction(ctor, proto);