• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

kjsembed

  • sources
  • kde-4.12
  • kdelibs
  • kjsembed
  • kjsembed
color.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3  Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4  Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
5  Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
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 <QtCore/QDebug>
25 #include <QtGui/QColor>
26 
27 using namespace KJSEmbed;
28 
29 const KJS::ClassInfo ColorBinding::info = { "QColor", &VariantBinding::info, 0, 0 };
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 
80 START_VARIANT_METHOD( callAlpha, QColor )
81  value.setAlpha( KJSEmbed::extractInt(exec, args, 0) );
82 END_VARIANT_METHOD
83 
84 START_VARIANT_METHOD( callBlue, QColor )
85  result = KJSEmbed::createInt( exec, value.blue() );
86 END_VARIANT_METHOD
87 
88 START_VARIANT_METHOD( callCyan, QColor )
89  result = KJSEmbed::createInt( exec, value.cyan() );
90 END_VARIANT_METHOD
91 
92 START_VARIANT_METHOD( callGreen, QColor )
93  result = KJSEmbed::createInt( exec, value.green() );
94 END_VARIANT_METHOD
95 
96 START_VARIANT_METHOD( callHue, QColor )
97  result = KJSEmbed::createInt( exec, value.hue() );
98 END_VARIANT_METHOD
99 
100 START_VARIANT_METHOD( callMagenta, QColor )
101  result = KJSEmbed::createInt( exec, value.magenta() );
102 END_VARIANT_METHOD
103 
104 START_VARIANT_METHOD( callRed, QColor )
105  result = KJSEmbed::createInt( exec, value.red() );
106 END_VARIANT_METHOD
107 
108 START_VARIANT_METHOD( callYellow, QColor )
109  result = KJSEmbed::createInt( exec, value.yellow() );
110 END_VARIANT_METHOD
111 
112 START_VARIANT_METHOD( callSaturation, QColor )
113  result = KJSEmbed::createInt( exec, value.saturation() );
114 END_VARIANT_METHOD
115 
116 START_VARIANT_METHOD( callDark, QColor )
117  QColor darkColor = value.dark( KJSEmbed::extractInt( exec, args, 0, 200));
118  result = KJSEmbed::createVariant(exec, "QColor", darkColor);
119 END_VARIANT_METHOD
120 
121 START_VARIANT_METHOD( callLight, QColor )
122  QColor darkColor = value.light( KJSEmbed::extractInt( exec, args, 0, 200));
123  result = KJSEmbed::createVariant(exec, "QColor", darkColor);
124 END_VARIANT_METHOD
125 
126 START_VARIANT_METHOD( callConvertTo, QColor )
127  QColor otherColor = value.convertTo( (QColor::Spec)KJSEmbed::extractInt( exec, args, 0));
128  result = KJSEmbed::createVariant(exec, "QColor", otherColor);
129 END_VARIANT_METHOD
130 
131 START_VARIANT_METHOD( callSpec, QColor )
132  result = KJS::jsNumber( value.spec() );
133 END_VARIANT_METHOD
134 
135 START_METHOD_LUT( Color )
136  {"setAlpha", 1, KJS::DontDelete|KJS::ReadOnly, &callSetAlpha},
137  {"setBlue", 1, KJS::DontDelete|KJS::ReadOnly, &callSetBlue},
138  {"setGreen", 1, KJS::DontDelete|KJS::ReadOnly, &callSetGreen},
139  {"setRed", 1, KJS::DontDelete|KJS::ReadOnly, &callSetRed},
140  {"setRgb", 4, KJS::DontDelete|KJS::ReadOnly, &callSetRgb},
141  {"setCmyk", 5, KJS::DontDelete|KJS::ReadOnly, &callSetCmyk},
142  {"setHsv", 4, KJS::DontDelete|KJS::ReadOnly, &callSetHsv},
143  {"setNamedColor", 1, KJS::DontDelete|KJS::ReadOnly, &callSetNamedColor},
144  {"alpha", 0, KJS::DontDelete|KJS::ReadOnly, &callAlpha},
145  {"blue", 0, KJS::DontDelete|KJS::ReadOnly, &callBlue},
146  {"cyan", 0, KJS::DontDelete|KJS::ReadOnly, &callCyan},
147  {"green", 0, KJS::DontDelete|KJS::ReadOnly, &callGreen},
148  {"hue", 0, KJS::DontDelete|KJS::ReadOnly, &callHue},
149  {"magenta", 0, KJS::DontDelete|KJS::ReadOnly, &callMagenta},
150  {"red", 0, KJS::DontDelete|KJS::ReadOnly, &callRed},
151  {"saturation", 0, KJS::DontDelete|KJS::ReadOnly, &callSaturation},
152  {"yellow", 0, KJS::DontDelete|KJS::ReadOnly, &callYellow},
153  {"light", 1, KJS::DontDelete|KJS::ReadOnly, &callLight},
154  {"dark", 1, KJS::DontDelete|KJS::ReadOnly, &callDark},
155  {"convertTo", 1, KJS::DontDelete|KJS::ReadOnly, &callConvertTo},
156  {"spec", 0, KJS::DontDelete|KJS::ReadOnly, &callSpec}
157 END_METHOD_LUT
158 
159 
160 START_ENUM_LUT( Color )
161  {"Rgb",QColor::Rgb},
162  {"Hsv",QColor::Hsv},
163  {"Cmyk",QColor::Cmyk},
164  {"Invalid",QColor::Invalid}
165 END_ENUM_LUT
166 
167 NO_STATICS( Color )
168 
169 START_CTOR( Color, QColor, 0)
170  if( args.size() == 1 )
171  {
172  return new KJSEmbed::ColorBinding( exec, QColor( KJSEmbed::extractQString(exec,args,0 ) ) );
173  }
174  else if( args.size() >= 3 )
175  {
176  return new KJSEmbed::ColorBinding(exec,
177  QColor( KJSEmbed::extractInt( exec, args, 0 ),
178  KJSEmbed::extractInt( exec, args, 1 ),
179  KJSEmbed::extractInt( exec, args, 2 )) );
180  }
181 
182  if( args.size() == 4 )
183  {
184  return new KJSEmbed::ColorBinding(exec,
185  QColor( KJSEmbed::extractInt( exec, args, 0 ),
186  KJSEmbed::extractInt( exec, args, 1 ),
187  KJSEmbed::extractInt( exec, args, 2 ),
188  KJSEmbed::extractInt( exec, args, 3 )) );
189  }
190 
191  return new KJSEmbed::ColorBinding( exec, QColor() );
192 END_CTOR
193 
194 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
KJSEmbed::VariantBinding::info
static const KJS::ClassInfo info
Definition: variant_binding.h:123
START_METHOD_LUT
END_VARIANT_METHOD START_METHOD_LUT(Color)
Definition: color.cpp:135
KJSEmbed::StaticBinding::publish
static void publish(KJS::ExecState *exec, KJS::JSObject *object, const Method *methods)
Publishes an array of Methods to an object.
Definition: static_binding.cpp:60
KJSEmbed::VariantBinding
QVariant based binding.
Definition: variant_binding.h:88
setAlpha
value setAlpha(KJSEmbed::extractInt(exec, args, 0))
KJSEmbed::createVariant
KJS::JSValue * createVariant(KJS::ExecState *exec, const KJS::UString &className, const T &value)
Can create any known KJSEmbed::VariantBinding object and set the value.
Definition: variant_binding.h:185
KJSEmbed::ColorBinding
Definition: color.h:34
END_CTOR
#define END_CTOR
Definition: binding_support.h:166
KJSEmbed::extractInt
int KJSEMBED_EXPORT extractInt(KJS::ExecState *exec, const KJS::List &args, int idx, int defaultValue=0)
Extracts an integer from an argument list.
Definition: binding_support.cpp:72
DomDocumentNS::if
if(!success)
Definition: dom.cpp:363
KJSEmbed::ColorBinding::ColorBinding
ColorBinding(KJS::ExecState *exec, const QColor &value)
Definition: color.cpp:30
setGreen
END_VARIANT_METHOD value setGreen(KJSEmbed::extractInt(exec, args, 0))
KJSEmbed::ColorBinding::info
static const KJS::ClassInfo info
Definition: color.h:39
START_CTOR
#define START_CTOR(TYPE, JSNAME, ARGS)
Definition: binding_support.h:157
setRgb
END_VARIANT_METHOD value setRgb(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3, 255))
setCmyk
END_VARIANT_METHOD value setCmyk(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3), KJSEmbed::extractInt(exec, args, 4, 255))
KJSEmbed::createInt
KJS::JSValue * createInt(KJS::ExecState *exec, int value)
Create a new KJS::JSValue with the value of the integer.
Definition: binding_support.cpp:94
END_METHOD_LUT
#define END_METHOD_LUT
Definition: binding_support.h:135
otherColor
END_VARIANT_METHOD QColor otherColor
Definition: color.cpp:127
setHsv
END_VARIANT_METHOD value setHsv(KJSEmbed::extractInt(exec, args, 0), KJSEmbed::extractInt(exec, args, 1), KJSEmbed::extractInt(exec, args, 2), KJSEmbed::extractInt(exec, args, 3, 255))
setRed
END_VARIANT_METHOD value setRed(KJSEmbed::extractInt(exec, args, 0))
result
END_VARIANT_METHOD result
Definition: color.cpp:85
KJSEmbed::VariantFactory::methods
static const Method * methods()
Definition: variant_binding.h:251
color.h
END_VARIANT_METHOD
#define END_VARIANT_METHOD
End a variant method started by START_VARIANT_METHOD.
Definition: variant_binding.h:56
setNamedColor
END_VARIANT_METHOD value setNamedColor(KJSEmbed::extractQString(exec, args, 0))
setBlue
END_VARIANT_METHOD value setBlue(KJSEmbed::extractInt(exec, args, 0))
darkColor
END_VARIANT_METHOD QColor darkColor
Definition: color.cpp:117
START_VARIANT_METHOD
#define START_VARIANT_METHOD(METHODNAME, TYPE)
A simple variant syle method.
Definition: variant_binding.h:42
value
QVariant value
Definition: settings.cpp:35
KJSEmbed::extractQString
QString KJSEMBED_EXPORT extractQString(KJS::ExecState *exec, const KJS::List &args, int idx, const QString defaultValue=QString())
Extracts a QString from an argument list.
Definition: binding_support.cpp:34
NO_STATICS
#define NO_STATICS(TYPE)
Definition: binding_support.h:153
START_ENUM_LUT
#define START_ENUM_LUT(TYPE)
Definition: binding_support.h:139
END_ENUM_LUT
#define END_ENUM_LUT
Definition: binding_support.h:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:53 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal