KJsEmbed

brush.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005, 2006 Ian Reinhart Geiser <[email protected]>
3  Copyright (C) 2005, 2006 Matt Broadstone <[email protected]>
4  Copyright (C) 2005, 2006 Richard J. Moore <[email protected]>
5  Copyright (C) 2005, 2006 Erik L. Bunce <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 #include "brush.h"
23 
24 #include <QDebug>
25 #include <QBrush>
26 #include <QPixmap>
27 #include <QColor>
28 
29 #include "pixmap.h"
30 #include "color.h"
31 #include "util.h"
32 
33 using namespace KJSEmbed;
34 
35 const KJS::ClassInfo BrushBinding::info = { "QBrush", &VariantBinding::info, nullptr, nullptr };
36 BrushBinding::BrushBinding(KJS::ExecState *exec, const QBrush &value)
37  : VariantBinding(exec, value)
38 {
39  StaticBinding::publish(exec, this, Brush::methods());
40  StaticBinding::publish(exec, this, VariantFactory::methods());
41 }
42 
43 namespace BrushNS
44 {
45 
46 START_VARIANT_METHOD(callcolor, QBrush)
47 QColor cppValue = value.color();
48 result = KJSEmbed::createVariant(exec, "QColor", cppValue);
49 END_VARIANT_METHOD
50 
51 START_VARIANT_METHOD(callgradient, QBrush)
52 const QGradient *cppValue = value.gradient();
53 result = KJSEmbed::createObject<QGradient>(exec, "QGradient", cppValue);
54 END_VARIANT_METHOD
55 
56 START_VARIANT_METHOD(callisOpaque, QBrush)
57 bool cppValue = value.isOpaque();
58 result = KJS::jsBoolean(cppValue);
59 END_VARIANT_METHOD
60 
61 START_VARIANT_METHOD(callsetColor, QBrush)
62 QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
63 value.setColor(arg0);
64 END_VARIANT_METHOD
65 
66 START_VARIANT_METHOD(callsetStyle, QBrush)
67 Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0);
68 value.setStyle(arg0);
69 END_VARIANT_METHOD
70 
71 START_VARIANT_METHOD(callsetTexture, QBrush)
72 QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0);
73 value.setTexture(arg0);
74 END_VARIANT_METHOD
75 
76 START_VARIANT_METHOD(callstyle, QBrush)
77 Qt::BrushStyle cppValue = value.style();
78 result = KJS::jsNumber(cppValue);
79 END_VARIANT_METHOD
80 
81 START_VARIANT_METHOD(calltexture, QBrush)
82 QPixmap cppValue = value.texture();
83 result = KJSEmbed::createVariant(exec, "QPixmap", cppValue);
84 END_VARIANT_METHOD
85 
86 }
87 
88 START_METHOD_LUT(Brush)
89 {"color", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callcolor},
90 {"gradient", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callgradient},
91 {"isOpaque", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callisOpaque},
92 {"setColor", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetColor},
93 {"setStyle", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetStyle},
94 {"setTexture", 1, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callsetTexture},
95 {"style", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::callstyle},
96 {"texture", 0, KJS::DontDelete | KJS::ReadOnly, &BrushNS::calltexture}
97 END_METHOD_LUT
98 
99 NO_ENUMS(Brush)
100 NO_STATICS(Brush)
101 
102 START_CTOR(Brush, QBrush, 0)
103 if (args.size() == 0)
104 {
105  return new KJSEmbed::BrushBinding(exec, QBrush());
106 } else if (args.size() == 1)
107 {
108  KJS::JSValue *value0 = args[0];
109  KJS::JSObject *obj0 = value0->toObject(exec);
110  if (obj0) {
111  if (obj0->inherits(&PixmapBinding::info)) {
112  QPixmap arg0 = KJSEmbed::extractVariant<QPixmap>(exec, args, 0);
113  return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
114  }
115  if (obj0->inherits(&BrushBinding::info)) {
116  QBrush arg0 = KJSEmbed::extractVariant<QBrush>(exec, args, 0);
117  return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
118  }
119 // if(obj0->inherits(&GradientBinding::info))
120 // {
121 // QGradient arg0 = KJSEmbed::extractVariant<QGradient>(exec, args, 0);
122 // return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
123 // }
124  } else if (isBasic(value0)) {
125  Qt::BrushStyle arg0 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 0);
126  return new KJSEmbed::BrushBinding(exec, QBrush(arg0));
127  }
128 } else if (args.size() == 2)
129 {
130  KJS::JSValue *value0 = args[0];
131  KJS::JSValue *value1 = args[1];
132  KJS::JSObject *obj0 = value0->toObject(exec);
133  KJS::JSObject *obj1 = value1->toObject(exec);
134 
135  if (obj0 && obj1 && obj0->inherits(&ColorBinding::info) && obj1->inherits(&PixmapBinding::info)) {
136  QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
137  QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
138  return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
139  }
140  if (obj1 && isBasic(value0) && obj1->inherits(&PixmapBinding::info)) {
141  Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0);
142  QPixmap arg1 = KJSEmbed::extractVariant<QPixmap>(exec, args, 1);
143  return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
144  }
145  if (obj0 && obj0->inherits(&ColorBinding::info) && isBasic(value1)) {
146  QColor arg0 = KJSEmbed::extractVariant<QColor>(exec, args, 0);
147  Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1);
148  return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
149  }
150  if (isBasic(value0) && isBasic(value1)) {
151  Qt::GlobalColor arg0 = (Qt::GlobalColor)KJSEmbed::extractInt(exec, args, 0);
152  Qt::BrushStyle arg1 = (Qt::BrushStyle)KJSEmbed::extractInt(exec, args, 1);
153  return new KJSEmbed::BrushBinding(exec, QBrush(arg0, arg1));
154  }
155 }
156 return new KJSEmbed::BrushBinding(exec, QBrush());
157 
158 END_CTOR
static void publish(KJS::ExecState *exec, KJS::JSObject *object, const Method *methods)
Publishes an array of Methods to an object.
QVariant based binding.
BrushStyle
GlobalColor
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 10 2023 03:59:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.