pen, without which painter is a lot less useful

svn path=/trunk/KDE/kdebase/runtime/; revision=1055311
This commit is contained in:
Aaron J. Seigo 2009-11-27 20:29:14 +00:00
parent bd7231cd97
commit 0ab7db4524
3 changed files with 173 additions and 0 deletions

View File

@ -10,6 +10,7 @@ set(simple_javascript_engine_SRCS
simplebindings/graphicsitem.cpp
simplebindings/linearlayout.cpp
simplebindings/painter.cpp
simplebindings/pen.cpp
simplebindings/pixmap.cpp
simplebindings/point.cpp
simplebindings/rect.cpp

View File

@ -0,0 +1,170 @@
/*
* Copyright 2009 Aaron J. Seigo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
#include <QtGui/QPen>
#include "../backportglobal.h"
Q_DECLARE_METATYPE(QPen*)
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{
Q_UNUSED(ctx)
return qScriptValueFromValue(eng, QPen());
}
static QScriptValue brush(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, brush);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setBrush(qscriptvalue_cast<QBrush>(arg));
}
return qScriptValueFromValue(eng, self->brush());
}
static QScriptValue color(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, color);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setColor(qscriptvalue_cast<QColor>(arg));
}
return qScriptValueFromValue(eng, self->color());
}
static QScriptValue style(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, style);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setStyle(Qt::PenStyle(arg.toInt32()));
}
return QScriptValue(eng, self->style());
}
static QScriptValue capStyle(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, capStyle);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setCapStyle(Qt::PenCapStyle(arg.toInt32()));
}
return QScriptValue(eng, self->capStyle());
}
static QScriptValue joinStyle(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, joinStyle);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setJoinStyle(Qt::PenJoinStyle(arg.toInt32()));
}
return QScriptValue(eng, self->joinStyle());
}
static QScriptValue dashOffset(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, dashOffset);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setDashOffset(arg.toInt32());
}
return QScriptValue(eng, self->dashOffset());
}
static QScriptValue miterLimit(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, miterLimit);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setMiterLimit(arg.toInt32());
}
return QScriptValue(eng, self->miterLimit());
}
static QScriptValue width(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, width);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
self->setWidth(arg.toInt32());
}
return QScriptValue(eng, self->width());
}
static QScriptValue isSolid(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QPen, isSolid);
return QScriptValue(eng, self->isSolid());
}
QScriptValue constructPenClass(QScriptEngine *eng)
{
QScriptValue proto = qScriptValueFromValue(eng, QColor());
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
proto.setProperty("brush", eng->newFunction(brush), getter | setter);
proto.setProperty("color", eng->newFunction(color), getter | setter);
proto.setProperty("capStyle", eng->newFunction(capStyle), getter | setter);
proto.setProperty("joinStyle", eng->newFunction(joinStyle), getter | setter);
proto.setProperty("style", eng->newFunction(style), getter | setter);
proto.setProperty("dashOffset", eng->newFunction(dashOffset), getter | setter);
proto.setProperty("miterLimit", eng->newFunction(miterLimit), getter | setter);
proto.setProperty("width", eng->newFunction(width), getter | setter);
proto.setProperty("isSolid", eng->newFunction(isSolid), getter);
QScriptValue ctorFun = eng->newFunction(ctor, proto);
ADD_ENUM_VALUE(ctorFun, Qt, FlatCap);
ADD_ENUM_VALUE(ctorFun, Qt, SquareCap);
ADD_ENUM_VALUE(ctorFun, Qt, RoundCap);
ADD_ENUM_VALUE(ctorFun, Qt, RoundCap);
ADD_ENUM_VALUE(ctorFun, Qt, BevelJoin);
ADD_ENUM_VALUE(ctorFun, Qt, MiterJoin);
ADD_ENUM_VALUE(ctorFun, Qt, RoundJoin);
ADD_ENUM_VALUE(ctorFun, Qt, SolidLine);
ADD_ENUM_VALUE(ctorFun, Qt, DashLine);
ADD_ENUM_VALUE(ctorFun, Qt, DotLine);
ADD_ENUM_VALUE(ctorFun, Qt, DashDotLine);
ADD_ENUM_VALUE(ctorFun, Qt, DashDotDotLine);
ADD_ENUM_VALUE(ctorFun, Qt, CustomDashLine);
eng->setDefaultPrototype(qMetaTypeId<QPen>(), proto);
eng->setDefaultPrototype(qMetaTypeId<QPen*>(), proto);
return ctorFun;
}

View File

@ -69,6 +69,7 @@ QScriptValue constructKUrlClass(QScriptEngine *engine);
QScriptValue constructLinearLayoutClass(QScriptEngine *engine);
QScriptValue constructAnchorLayoutClass(QScriptEngine *engine);
QScriptValue constructPainterClass(QScriptEngine *engine);
QScriptValue constructPenClass(QScriptEngine *engine);
QScriptValue constructQPixmapClass(QScriptEngine *engine);
QScriptValue constructQPointClass(QScriptEngine *engine);
QScriptValue constructQRectFClass(QScriptEngine *engine);
@ -554,6 +555,7 @@ void SimpleJavaScriptApplet::setupObjects()
global.setProperty("QFont", constructFontClass(m_engine));
global.setProperty("QColor", constructColorClass(m_engine));
global.setProperty("QRectF", constructQRectFClass(m_engine));
global.setProperty("QPen", constructPenClass(m_engine));
global.setProperty("QPixmap", constructQPixmapClass(m_engine));
global.setProperty("QSizeF", constructQSizeFClass(m_engine));
global.setProperty("QPoint", constructQPointClass(m_engine));