KJsEmbed

color.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 "color.h"
23 
24 #include <QDebug>
25 #include <QColor>
26 
27 using namespace KJSEmbed;
28 
29 const KJS::ClassInfo ColorBinding::info = { "QColor", &VariantBinding::info, nullptr, nullptr };
30 ColorBinding::ColorBinding(KJS::ExecState *exec, const QColor &value)
31  : VariantBinding(exec, value)
32 {
33  StaticBinding::publish(exec, this, Color::methods());
34  StaticBinding::publish(exec, this, VariantFactory::methods());
35 }
36 
37 START_VARIANT_METHOD(callSetAlpha, QColor)
38 value.setAlpha(KJSEmbed::extractInt(exec, args, 0));
39 END_VARIANT_METHOD
40 
41 START_VARIANT_METHOD(callSetBlue, QColor)
42 value.setBlue(KJSEmbed::extractInt(exec, args, 0));
43 END_VARIANT_METHOD
44 
45 START_VARIANT_METHOD(callSetGreen, QColor)
46 value.setGreen(KJSEmbed::extractInt(exec, args, 0));
47 END_VARIANT_METHOD
48 
49 START_VARIANT_METHOD(callSetRed, QColor)
50 value.setRed(KJSEmbed::extractInt(exec, args, 0));
51 END_VARIANT_METHOD
52 
53 START_VARIANT_METHOD(callSetRgb, QColor)
54 value.setRgb(KJSEmbed::extractInt(exec, args, 0),
55  KJSEmbed::extractInt(exec, args, 1),
56  KJSEmbed::extractInt(exec, args, 2),
57  KJSEmbed::extractInt(exec, args, 3, 255));
58 END_VARIANT_METHOD
59 
60 START_VARIANT_METHOD(callSetCmyk, QColor)
61 value.setCmyk(KJSEmbed::extractInt(exec, args, 0),
62  KJSEmbed::extractInt(exec, args, 1),
63  KJSEmbed::extractInt(exec, args, 2),
64  KJSEmbed::extractInt(exec, args, 3),
65  KJSEmbed::extractInt(exec, args, 4, 255));
66 END_VARIANT_METHOD
67 
68 START_VARIANT_METHOD(callSetHsv, QColor)
69 value.setHsv(KJSEmbed::extractInt(exec, args, 0),
70  KJSEmbed::extractInt(exec, args, 1),
71  KJSEmbed::extractInt(exec, args, 2),
72  KJSEmbed::extractInt(exec, args, 3, 255));
73 END_VARIANT_METHOD
74 
75 START_VARIANT_METHOD(callSetNamedColor, QColor)
76 value.setNamedColor(KJSEmbed::extractQString(exec, args, 0));
77 END_VARIANT_METHOD
78 
79 START_VARIANT_METHOD(callAlpha, QColor)
80 value.setAlpha(KJSEmbed::extractInt(exec, args, 0));
81 END_VARIANT_METHOD
82 
83 START_VARIANT_METHOD(callBlue, QColor)
84 result = KJSEmbed::createInt(exec, value.blue());
85 END_VARIANT_METHOD
86 
87 START_VARIANT_METHOD(callCyan, QColor)
88 result = KJSEmbed::createInt(exec, value.cyan());
89 END_VARIANT_METHOD
90 
91 START_VARIANT_METHOD(callGreen, QColor)
92 result = KJSEmbed::createInt(exec, value.green());
93 END_VARIANT_METHOD
94 
95 START_VARIANT_METHOD(callHue, QColor)
96 result = KJSEmbed::createInt(exec, value.hue());
97 END_VARIANT_METHOD
98 
99 START_VARIANT_METHOD(callMagenta, QColor)
100 result = KJSEmbed::createInt(exec, value.magenta());
101 END_VARIANT_METHOD
102 
103 START_VARIANT_METHOD(callRed, QColor)
104 result = KJSEmbed::createInt(exec, value.red());
105 END_VARIANT_METHOD
106 
107 START_VARIANT_METHOD(callYellow, QColor)
108 result = KJSEmbed::createInt(exec, value.yellow());
109 END_VARIANT_METHOD
110 
111 START_VARIANT_METHOD(callSaturation, QColor)
112 result = KJSEmbed::createInt(exec, value.saturation());
113 END_VARIANT_METHOD
114 
115 START_VARIANT_METHOD(callDark, QColor)
116 QColor darkColor = value.darker(KJSEmbed::extractInt(exec, args, 0, 200));
117 result = KJSEmbed::createVariant(exec, "QColor", darkColor);
118 END_VARIANT_METHOD
119 
120 START_VARIANT_METHOD(callLight, QColor)
121 QColor darkColor = value.lighter(KJSEmbed::extractInt(exec, args, 0, 200));
122 result = KJSEmbed::createVariant(exec, "QColor", darkColor);
123 END_VARIANT_METHOD
124 
125 START_VARIANT_METHOD(callConvertTo, QColor)
126 QColor otherColor = value.convertTo((QColor::Spec)KJSEmbed::extractInt(exec, args, 0));
127 result = KJSEmbed::createVariant(exec, "QColor", otherColor);
128 END_VARIANT_METHOD
129 
130 START_VARIANT_METHOD(callSpec, QColor)
131 result = KJS::jsNumber(value.spec());
132 END_VARIANT_METHOD
133 
134 START_METHOD_LUT(Color)
135 {"setAlpha", 1, KJS::DontDelete | KJS::ReadOnly, &callSetAlpha},
136 {"setBlue", 1, KJS::DontDelete | KJS::ReadOnly, &callSetBlue},
137 {"setGreen", 1, KJS::DontDelete | KJS::ReadOnly, &callSetGreen},
138 {"setRed", 1, KJS::DontDelete | KJS::ReadOnly, &callSetRed},
139 {"setRgb", 4, KJS::DontDelete | KJS::ReadOnly, &callSetRgb},
140 {"setCmyk", 5, KJS::DontDelete | KJS::ReadOnly, &callSetCmyk},
141 {"setHsv", 4, KJS::DontDelete | KJS::ReadOnly, &callSetHsv},
142 {"setNamedColor", 1, KJS::DontDelete | KJS::ReadOnly, &callSetNamedColor},
143 {"alpha", 0, KJS::DontDelete | KJS::ReadOnly, &callAlpha},
144 {"blue", 0, KJS::DontDelete | KJS::ReadOnly, &callBlue},
145 {"cyan", 0, KJS::DontDelete | KJS::ReadOnly, &callCyan},
146 {"green", 0, KJS::DontDelete | KJS::ReadOnly, &callGreen},
147 {"hue", 0, KJS::DontDelete | KJS::ReadOnly, &callHue},
148 {"magenta", 0, KJS::DontDelete | KJS::ReadOnly, &callMagenta},
149 {"red", 0, KJS::DontDelete | KJS::ReadOnly, &callRed},
150 {"saturation", 0, KJS::DontDelete | KJS::ReadOnly, &callSaturation},
151 {"yellow", 0, KJS::DontDelete | KJS::ReadOnly, &callYellow},
152 {"light", 1, KJS::DontDelete | KJS::ReadOnly, &callLight},
153 {"dark", 1, KJS::DontDelete | KJS::ReadOnly, &callDark},
154 {"convertTo", 1, KJS::DontDelete | KJS::ReadOnly, &callConvertTo},
155 {"spec", 0, KJS::DontDelete | KJS::ReadOnly, &callSpec}
156 END_METHOD_LUT
157 
158 START_ENUM_LUT(Color)
159 {"Rgb", QColor::Rgb},
160 {"Hsv", QColor::Hsv},
161 {"Cmyk", QColor::Cmyk},
162 {"Invalid", QColor::Invalid}
163 END_ENUM_LUT
164 
165 NO_STATICS(Color)
166 
167 START_CTOR(Color, QColor, 0)
168 if (args.size() == 1)
169 {
170  return new KJSEmbed::ColorBinding(exec, QColor(KJSEmbed::extractQString(exec, args, 0)));
171 } else if (args.size() >= 3)
172 {
173  return new KJSEmbed::ColorBinding(exec,
174  QColor(KJSEmbed::extractInt(exec, args, 0),
175  KJSEmbed::extractInt(exec, args, 1),
176  KJSEmbed::extractInt(exec, args, 2)));
177 }
178 
179 if (args.size() == 4)
180 {
181  return new KJSEmbed::ColorBinding(exec,
182  QColor(KJSEmbed::extractInt(exec, args, 0),
183  KJSEmbed::extractInt(exec, args, 1),
184  KJSEmbed::extractInt(exec, args, 2),
185  KJSEmbed::extractInt(exec, args, 3)));
186 }
187 
188 return new KJSEmbed::ColorBinding(exec, QColor());
189 END_CTOR
190 
static void publish(KJS::ExecState *exec, KJS::JSObject *object, const Method *methods)
Publishes an array of Methods to an object.
QVariant based binding.
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.