kjsembed
brush.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 00003 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 00004 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org> 00005 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 #include "brush.h" 00023 00024 #include <QtCore/QDebug> 00025 #include <QtGui/QBrush> 00026 #include <QtGui/QPixmap> 00027 #include <QtGui/QColor> 00028 00029 #include "pixmap.h" 00030 #include "color.h" 00031 #include "util.h" 00032 00033 using namespace KJSEmbed; 00034 00035 const KJS::ClassInfo BrushBinding::info = { "QBrush", &VariantBinding::info, 0, 0 }; 00036 BrushBinding::BrushBinding( KJS::ExecState *exec, const QBrush &value ) 00037 : VariantBinding(exec, value ) 00038 { 00039 StaticBinding::publish( exec, this, Brush::methods() ); 00040 StaticBinding::publish( exec, this, VariantFactory::methods() ); 00041 } 00042 00043 namespace BrushNS 00044 { 00045 00046 START_VARIANT_METHOD( callcolor, QBrush ) 00047 QColor cppValue = value.color(); 00048 result = KJSEmbed::createVariant(exec, "QColor", cppValue ); 00049 END_VARIANT_METHOD 00050 00051 START_VARIANT_METHOD( callgradient, QBrush ) 00052 const QGradient *cppValue = value.gradient(); 00053 result = KJSEmbed::createObject<QGradient>(exec, "QGradient", cppValue); 00054 END_VARIANT_METHOD 00055 00056 START_VARIANT_METHOD( callisOpaque, QBrush ) 00057 bool cppValue = value.isOpaque(); 00058 result = KJS::jsBoolean(cppValue); 00059 END_VARIANT_METHOD 00060 00061 START_VARIANT_METHOD( callsetColor, QBrush ) 00062 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec,args, 0); 00063 value.setColor(arg0); 00064 END_VARIANT_METHOD 00065 00066 START_VARIANT_METHOD( callsetStyle, QBrush ) 00067 Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0); 00068 value.setStyle(arg0); 00069 END_VARIANT_METHOD 00070 00071 START_VARIANT_METHOD( callsetTexture, QBrush ) 00072 QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec,args, 0); 00073 value.setTexture(arg0); 00074 END_VARIANT_METHOD 00075 00076 START_VARIANT_METHOD( callstyle, QBrush ) 00077 Qt::BrushStyle cppValue = value.style(); 00078 result = KJS::jsNumber(cppValue); 00079 END_VARIANT_METHOD 00080 00081 START_VARIANT_METHOD( calltexture, QBrush ) 00082 QPixmap cppValue = value.texture(); 00083 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue ); 00084 END_VARIANT_METHOD 00085 00086 } 00087 00088 START_METHOD_LUT( Brush ) 00089 {"color", 0, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callcolor}, 00090 {"gradient", 0, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callgradient}, 00091 {"isOpaque", 0, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callisOpaque}, 00092 {"setColor", 1, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callsetColor}, 00093 {"setStyle", 1, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callsetStyle}, 00094 {"setTexture", 1, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callsetTexture}, 00095 {"style", 0, KJS::DontDelete|KJS::ReadOnly, &BrushNS::callstyle}, 00096 {"texture", 0, KJS::DontDelete|KJS::ReadOnly, &BrushNS::calltexture} 00097 END_METHOD_LUT 00098 00099 NO_ENUMS( Brush ) 00100 NO_STATICS( Brush ) 00101 00102 START_CTOR( Brush, QBrush, 0) 00103 if( args.size() == 0 ) 00104 { 00105 return new KJSEmbed::BrushBinding( exec, QBrush() ); 00106 } 00107 else if( args.size() == 1 ) 00108 { 00109 KJS::JSValue* value0 = args[0]; 00110 KJS::JSObject* obj0 = value0->toObject(exec); 00111 if(obj0) 00112 { 00113 if(obj0->inherits(&PixmapBinding::info)) 00114 { 00115 QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0); 00116 return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); 00117 } 00118 if(obj0->inherits(&BrushBinding::info)) 00119 { 00120 QBrush arg0 = KJSEmbed::extractVariant<QBrush>(exec, args, 0); 00121 return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); 00122 } 00123 // if(obj0->inherits(&GradientBinding::info)) 00124 // { 00125 // QGradient arg0 = KJSEmbed::extractVariant<QGradient>(exec, args, 0); 00126 // return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); 00127 // } 00128 } 00129 else if(isBasic(value0)) 00130 { 00131 Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0); 00132 return new KJSEmbed::BrushBinding(exec, QBrush(arg0)); 00133 } 00134 } 00135 else if( args.size() == 2 ) 00136 { 00137 KJS::JSValue* value0= args[0]; 00138 KJS::JSValue* value1= args[1]; 00139 KJS::JSObject* obj0 = value0->toObject(exec); 00140 KJS::JSObject* obj1 = value1->toObject(exec); 00141 00142 if(obj0 && obj1 && obj0->inherits(&ColorBinding::info) && obj1->inherits(&PixmapBinding::info)) 00143 { 00144 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0); 00145 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1); 00146 return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); 00147 } 00148 if(obj1 && isBasic(value0) && obj1->inherits(&PixmapBinding::info)) 00149 { 00150 Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0); 00151 QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1); 00152 return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); 00153 } 00154 if(obj0 && obj0->inherits(&ColorBinding::info) && isBasic(value1)) 00155 { 00156 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0); 00157 Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1); 00158 return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); 00159 } 00160 if(isBasic(value0) && isBasic(value1)) 00161 { 00162 Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0); 00163 Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1); 00164 return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1)); 00165 } 00166 } 00167 return new KJSEmbed::BrushBinding( exec, QBrush() ); 00168 00169 END_CTOR 00170 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
KDE 4.6 API Reference