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

Plasma

  • plasma
  • animations
  • bindings
easingcurve.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2010 Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
12 *
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include <QEasingCurve>
20#include <QMetaEnum>
21#include <QScriptValue>
22#include <QScriptEngine>
23#include <QScriptContext>
24#include <QScriptable>
25
26Q_DECLARE_METATYPE(QEasingCurve)
27Q_DECLARE_METATYPE(QEasingCurve*)
28#define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
29 __c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
30
31#define DECLARE_SELF(Class, __fn__) \
32 Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \
33 if (!self) { \
34 return ctx->throwError(QScriptContext::TypeError, \
35 QString::fromLatin1("%0.prototype.%1: this object is not a %0") \
36 .arg(#Class).arg(#__fn__)); \
37 }
38
39namespace Plasma
40{
41
42static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
43{
44 if (ctx->argumentCount() > 0) {
45 QScriptValue arg = ctx->argument(0);
46 if (arg.isNumber()) {
47 qint32 type = arg.toInt32();
48 if (type > -1 && type < QEasingCurve::Custom) {
49 return qScriptValueFromValue(eng, QEasingCurve(static_cast<QEasingCurve::Type>(type)));
50 }
51 }
52 }
53
54 return qScriptValueFromValue(eng, QEasingCurve());
55}
56
57static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
58{
59 DECLARE_SELF(QEasingCurve, toString);
60 return QScriptValue(eng, QString::fromLatin1("QEasingCurve(type=%0)").arg(self->type()));
61}
62
63static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
64{
65 DECLARE_SELF(QEasingCurve, type);
66
67 if (ctx->argumentCount()) {
68 QScriptValue arg = ctx->argument(0);
69
70 qint32 type = -1;
71 if (arg.isNumber()) {
72 type = arg.toInt32();
73 } else if (arg.isString()) {
74 QMetaObject meta = QEasingCurve::staticMetaObject;
75 QMetaEnum easingCurveEnum = meta.enumerator(meta.indexOfEnumerator("Type"));
76
77 type = easingCurveEnum.keyToValue(arg.toString().toLatin1().data());
78 }
79 if (type > -1 && type < QEasingCurve::Custom) {
80 self->setType(static_cast<QEasingCurve::Type>(type));
81 }
82 }
83
84 return QScriptValue(eng, self->type());
85}
86
87static QScriptValue valueForProgress(QScriptContext *ctx, QScriptEngine *eng)
88{
89 DECLARE_SELF(QEasingCurve, valueForProgress);
90 if (ctx->argumentCount() < 1 || !ctx->argument(0).isNumber()) {
91 return eng->undefinedValue();
92 }
93
94 return self->valueForProgress(ctx->argument(0).toNumber());
95}
96
97QScriptValue constructEasingCurveClass(QScriptEngine *eng)
98{
99 QScriptValue proto = qScriptValueFromValue(eng, QEasingCurve());
100 QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
101 QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
102
103 proto.setProperty("type", eng->newFunction(type), getter | setter);
104 proto.setProperty("toString", eng->newFunction(toString), getter);
105 proto.setProperty("valueForProgress", eng->newFunction(valueForProgress), getter);
106
107 QScriptValue ctorFun = eng->newFunction(ctor, proto);
108
109 ADD_ENUM_VALUE(ctorFun, QEasingCurve, Linear);
110
111 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuad);
112 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuad);
113 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuad);
114 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuad);
115
116 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCubic);
117 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCubic);
118 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutCubic);
119 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInCubic);
120
121 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuart);
122 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuart);
123 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuart);
124 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuart);
125
126 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuint);
127 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuint);
128 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuint);
129 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuint);
130
131 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InSine);
132 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutSine);
133 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutSine);
134 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInSine);
135
136 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InExpo);
137 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutExpo);
138 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutExpo);
139 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInExpo);
140
141 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCirc);
142 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCirc);
143 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutCirc);
144 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInCirc);
145
146 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InElastic);
147 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutElastic);
148 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutElastic);
149 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInElastic);
150
151 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InBack);
152 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutBack);
153 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutBack);
154 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInBack);
155
156 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InBounce);
157 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutBounce);
158 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutBounce);
159
160 ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCurve);
161 ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCurve);
162 ADD_ENUM_VALUE(ctorFun, QEasingCurve, SineCurve);
163 ADD_ENUM_VALUE(ctorFun, QEasingCurve, CosineCurve);
164
165 eng->setDefaultPrototype(qMetaTypeId<QEasingCurve>(), proto);
166 eng->setDefaultPrototype(qMetaTypeId<QEasingCurve*>(), proto);
167
168 return ctorFun;
169}
170
171}
172
DECLARE_SELF
#define DECLARE_SELF(Class, __fn__)
Definition: easingcurve.cpp:31
ADD_ENUM_VALUE
#define ADD_ENUM_VALUE(__c__, __ns__, __v__)
Definition: easingcurve.cpp:28
Plasma
Namespace for everything in libplasma.
Definition: abstractdialogmanager.cpp:25
Plasma::constructEasingCurveClass
QScriptValue constructEasingCurveClass(QScriptEngine *engine)
Definition: easingcurve.cpp:97
Plasma::ctor
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:42
Plasma::type
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:63
Plasma::valueForProgress
static QScriptValue valueForProgress(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:87
Plasma::toString
static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
Definition: easingcurve.cpp:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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