minimal icon bindings, makes Plasma::IconWidget actually useful
svn path=/trunk/KDE/kdebase/runtime/; revision=1095318
This commit is contained in:
parent
d89fab4a41
commit
befcae6884
@ -15,6 +15,7 @@ set(simple_javascript_engine_SRCS
|
||||
simplebindings/font.cpp
|
||||
simplebindings/filedialogproxy.cpp
|
||||
simplebindings/graphicsitem.cpp
|
||||
simplebindings/icon.cpp
|
||||
simplebindings/linearlayout.cpp
|
||||
simplebindings/gridlayout.cpp
|
||||
simplebindings/painter.cpp
|
||||
|
111
scriptengines/javascript/simplebindings/icon.cpp
Normal file
111
scriptengines/javascript/simplebindings/icon.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Aaron J. Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <QtScript/QScriptEngine>
|
||||
#include <QtScript/QScriptContext>
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
#include "../backportglobal.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QIcon)
|
||||
Q_DECLARE_METATYPE(QIcon*)
|
||||
Q_DECLARE_METATYPE(KIcon)
|
||||
Q_DECLARE_METATYPE(KIcon*)
|
||||
|
||||
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue v = ctx->argument(0);
|
||||
if (v.isString()) {
|
||||
return qScriptValueFromValue(eng, KIcon(v.toString()));
|
||||
} else if (v.isVariant()) {
|
||||
QVariant variant = v.toVariant();
|
||||
QPixmap p = variant.value<QPixmap>();
|
||||
if (!p.isNull()) {
|
||||
return qScriptValueFromValue(eng, QIcon(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
return qScriptValueFromValue(eng, QIcon());
|
||||
}
|
||||
|
||||
static QScriptValue addPixmap(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QIcon, addPixmap);
|
||||
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
|
||||
if (arg.isVariant()) {
|
||||
QVariant variant = arg.toVariant();
|
||||
QPixmap p = variant.value<QPixmap>();
|
||||
if (!p.isNull()) {
|
||||
self->addPixmap(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return eng->undefinedValue();
|
||||
}
|
||||
|
||||
static QScriptValue addFile(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QIcon, addFile);
|
||||
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
|
||||
if (arg.isString()) {
|
||||
self->addFile(arg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return eng->undefinedValue();
|
||||
}
|
||||
|
||||
static QScriptValue isNull(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
Q_UNUSED(eng)
|
||||
DECLARE_SELF(QIcon, isNull);
|
||||
return self->isNull();
|
||||
}
|
||||
|
||||
QScriptValue constructIconClass(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue proto = qScriptValueFromValue(eng, QIcon());
|
||||
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
||||
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
||||
proto.setProperty("addPixmap", eng->newFunction(addPixmap));
|
||||
proto.setProperty("addFile", eng->newFunction(addFile));
|
||||
proto.setProperty("null", eng->newFunction(isNull), getter);
|
||||
|
||||
QScriptValue ctorFun = eng->newFunction(ctor, proto);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Normal);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Disabled);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Active);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Selected);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, Off);
|
||||
ADD_ENUM_VALUE(ctorFun, QIcon, On);
|
||||
|
||||
eng->setDefaultPrototype(qMetaTypeId<QIcon>(), proto);
|
||||
|
||||
return ctorFun;
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ QScriptValue constructColorClass(QScriptEngine *engine);
|
||||
QScriptValue constructEasingCurveClass(QScriptEngine *engine);
|
||||
QScriptValue constructFontClass(QScriptEngine *engine);
|
||||
QScriptValue constructGraphicsItemClass(QScriptEngine *engine);
|
||||
QScriptValue constructIconClass(QScriptEngine *engine);
|
||||
QScriptValue constructKUrlClass(QScriptEngine *engine);
|
||||
QScriptValue constructLinearLayoutClass(QScriptEngine *engine);
|
||||
QScriptValue constructGridLayoutClass(QScriptEngine *engine);
|
||||
@ -350,6 +351,7 @@ void SimpleJavaScriptApplet::setupObjects()
|
||||
// Add stuff from Qt
|
||||
global.setProperty("QPainter", constructPainterClass(m_engine));
|
||||
global.setProperty("QGraphicsItem", constructGraphicsItemClass(m_engine));
|
||||
global.setProperty("QIcon", constructIconClass(m_engine));
|
||||
global.setProperty("QTimer", constructTimerClass(m_engine));
|
||||
global.setProperty("QFont", constructFontClass(m_engine));
|
||||
global.setProperty("QColor", constructColorClass(m_engine));
|
||||
|
Loading…
x
Reference in New Issue
Block a user