simple binding of QGraphicsLinearLayout; will do Grid later
svn path=/trunk/KDE/kdebase/workspace/plasma/scriptengines/javascript/; revision=905862
This commit is contained in:
parent
b27afeb94d
commit
57f3358108
@ -4,6 +4,7 @@ set(simple_javascript_engine_SRCS
|
||||
uiloader.cpp
|
||||
qtgui/font.cpp
|
||||
qtgui/graphicsitem.cpp
|
||||
qtgui/linearlayout.cpp
|
||||
qtgui/painter.cpp
|
||||
qtgui/point.cpp
|
||||
qtgui/rect.cpp
|
||||
|
@ -141,6 +141,7 @@ enum AspectRatioMode {
|
||||
|
||||
const Plasma::Package *package() const;
|
||||
QList<QAction*> contextualActions() const;
|
||||
Plasma::Applet *applet() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void releaseVisualFocus();
|
||||
@ -151,7 +152,6 @@ public Q_SLOTS:
|
||||
void dataUpdated(QString source, Plasma::DataEngine::Data data);
|
||||
|
||||
private:
|
||||
Plasma::Applet *applet() const;
|
||||
SimpleJavaScriptApplet *m_appletScriptEngine;
|
||||
QSet<QString> m_actions;
|
||||
QSignalMapper *m_actionSignals;
|
||||
|
@ -180,6 +180,12 @@ BEGIN_DECLARE_METHOD(Class, __fun__) { \
|
||||
return eng->undefinedValue(); \
|
||||
} END_DECLARE_METHOD
|
||||
|
||||
#define DECLARE_VOID_QUAD_NUMBER_METHOD(Class, __fun__) \
|
||||
BEGIN_DECLARE_METHOD(Class, __fun__) { \
|
||||
self->__fun__(ctx->argument(0).toNumber(), ctx->argument(1).toNumber(), ctx->argument(2).toNumber(), ctx->argument(3).toNumber()); \
|
||||
return eng->undefinedValue(); \
|
||||
} END_DECLARE_METHOD
|
||||
|
||||
#define DECLARE_VOID_1ARG_METHOD(Class, ArgType, __fun__) \
|
||||
BEGIN_DECLARE_METHOD(Class, __fun__) { \
|
||||
self->__fun__(qscriptvalue_cast<ArgType>(ctx->argument(0))); \
|
||||
|
147
scriptengines/javascript/qtgui/linearlayout.cpp
Normal file
147
scriptengines/javascript/qtgui/linearlayout.cpp
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright 2007 Richard J. Moore <rich@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 <QtGui/QGraphicsWidget>
|
||||
#include <QtGui/QGraphicsGridLayout>
|
||||
#include <QtGui/QGraphicsLinearLayout>
|
||||
|
||||
#include <Plasma/Applet>
|
||||
|
||||
#include "../backportglobal.h"
|
||||
#include "../appletinterface.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QScript::Pointer<QGraphicsItem>::wrapped_pointer_type)
|
||||
Q_DECLARE_METATYPE(QGraphicsWidget*)
|
||||
Q_DECLARE_METATYPE(QGraphicsGridLayout*)
|
||||
DECLARE_POINTER_METATYPE(QGraphicsLinearLayout)
|
||||
|
||||
DECLARE_VOID_NUMBER_METHOD(QGraphicsLinearLayout, removeAt)
|
||||
DECLARE_VOID_NUMBER_METHOD(QGraphicsLinearLayout, addStretch)
|
||||
DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsLinearLayout, insertStretch)
|
||||
DECLARE_VOID_NUMBER_NUMBER_METHOD(QGraphicsLinearLayout, setItemSpacing)
|
||||
DECLARE_VOID_QUAD_NUMBER_METHOD(QGraphicsLinearLayout, setContentsMargins)
|
||||
DECLARE_NUMBER_GET_SET_METHODS(QGraphicsLinearLayout, spacing, setSpacing)
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
QGraphicsLayoutItem *layoutItem(QScriptContext *ctx, int index)
|
||||
{
|
||||
QGraphicsLayoutItem *item = qscriptvalue_cast<QGraphicsWidget*>(ctx->argument(0));
|
||||
|
||||
if (!item) {
|
||||
item = qscriptvalue_cast<QGraphicsLinearLayout*>(ctx->argument(0));
|
||||
}
|
||||
|
||||
if (!item) {
|
||||
item = qscriptvalue_cast<QGraphicsGridLayout*>(ctx->argument(0));
|
||||
}
|
||||
|
||||
QObject *appletObject = ctx->argument(0).toQObject();
|
||||
if (appletObject) {
|
||||
AppletInterface *interface = qobject_cast<AppletInterface*>(appletObject);
|
||||
if (interface) {
|
||||
item = interface->applet();
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() == 0) {
|
||||
//FIXME 4.3: i18n
|
||||
return ctx->throwError("GridLayout requires a parent");
|
||||
}
|
||||
|
||||
QGraphicsLayoutItem *parent = layoutItem(ctx, 0);
|
||||
|
||||
if (!parent) {
|
||||
//FIXME 4.3: i18n
|
||||
return ctx->throwError("The parent must be a QGraphicsLayoutItem");
|
||||
}
|
||||
|
||||
return qScriptValueFromValue(eng, new QGraphicsLinearLayout(parent));
|
||||
}
|
||||
|
||||
BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, orientation) {
|
||||
return QScriptValue(eng, static_cast<int>(self->orientation()));
|
||||
} END_DECLARE_METHOD
|
||||
|
||||
BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, setOrientation) {
|
||||
self->setOrientation(static_cast<Qt::Orientation>(ctx->argument(0).toInt32()));
|
||||
return eng->undefinedValue();
|
||||
} END_DECLARE_METHOD
|
||||
|
||||
/*
|
||||
void insertItem(int index, QGraphicsLayoutItem * item)
|
||||
void removeItem(QGraphicsLayoutItem * item)
|
||||
|
||||
void setAlignment(QGraphicsLayoutItem * item, Qt::Alignment alignment)
|
||||
void setStretchFactor(QGraphicsLayoutItem * item, int stretch)
|
||||
*/
|
||||
|
||||
BEGIN_DECLARE_METHOD(QGraphicsLinearLayout, addItem) {
|
||||
QGraphicsLayoutItem *item = layoutItem(ctx, 0);
|
||||
if (!item) {
|
||||
return ctx->throwError(QScriptContext::TypeError,
|
||||
"QGraphicsLinearLayout.prototype.addItem: argument is not a GraphicsLayoutItem");
|
||||
}
|
||||
|
||||
self->addItem(item);
|
||||
return eng->undefinedValue();
|
||||
} END_DECLARE_METHOD
|
||||
|
||||
BEGIN_DECLARE_METHOD(QGraphicsItem, toString) {
|
||||
return QScriptValue(eng, "QGraphicsLinearLayout");
|
||||
} END_DECLARE_METHOD
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
class PrototypeLinearLayout : public QGraphicsLinearLayout
|
||||
{
|
||||
public:
|
||||
PrototypeLinearLayout()
|
||||
{ }
|
||||
};
|
||||
|
||||
QScriptValue constructLinearLayoutClass(QScriptEngine *eng)
|
||||
{
|
||||
// QScriptValue proto = QScript::wrapGVPointer<QGraphicsLinearLayout>(eng, new QGraphicsLinearLayout(), );
|
||||
QScriptValue proto = QScript::wrapPointer<QGraphicsLinearLayout>(eng, new QGraphicsLinearLayout(), QScript::UserOwnership);
|
||||
ADD_GET_SET_METHODS(proto, spacing, setSpacing);
|
||||
ADD_GET_SET_METHODS(proto, orientation, setOrientation);
|
||||
//ADD_GET_METHOD(proto, y);
|
||||
ADD_METHOD(proto, removeAt);
|
||||
ADD_METHOD(proto, addStretch);
|
||||
ADD_METHOD(proto, insertStretch);
|
||||
ADD_METHOD(proto, setItemSpacing);
|
||||
ADD_METHOD(proto, setContentsMargins);
|
||||
ADD_METHOD(proto, addItem);
|
||||
ADD_METHOD(proto, toString);
|
||||
|
||||
QScript::registerPointerMetaType<QGraphicsLinearLayout>(eng, proto);
|
||||
|
||||
QScriptValue ctorFun = eng->newFunction(ctor, proto);
|
||||
//ADD_ENUM_VALUE(ctorFun, QGraphicsItem, ItemIsMovable);
|
||||
|
||||
return ctorFun;
|
||||
}
|
@ -52,6 +52,7 @@ Q_SCRIPT_DECLARE_QMETAOBJECT(AppletInterface, SimpleJavaScriptApplet*)
|
||||
|
||||
QScriptValue constructPainterClass(QScriptEngine *engine);
|
||||
QScriptValue constructGraphicsItemClass(QScriptEngine *engine);
|
||||
QScriptValue constructLinearLayoutClass(QScriptEngine *engine);
|
||||
QScriptValue constructTimerClass(QScriptEngine *engine);
|
||||
QScriptValue constructFontClass(QScriptEngine *engine);
|
||||
QScriptValue constructQRectFClass(QScriptEngine *engine);
|
||||
@ -218,7 +219,7 @@ void SimpleJavaScriptApplet::paintInterface(QPainter *p, const QStyleOptionGraph
|
||||
//kDebug() << "paintInterface() (c++)";
|
||||
QScriptValue fun = m_self.property("paintInterface");
|
||||
if (!fun.isFunction()) {
|
||||
kDebug() << "Script: paintInterface is not a function, " << fun.toString();
|
||||
//kDebug() << "Script: paintInterface is not a function, " << fun.toString();
|
||||
AppletScript::paintInterface(p, option, contentsRect);
|
||||
return;
|
||||
}
|
||||
@ -367,6 +368,7 @@ void SimpleJavaScriptApplet::setupObjects()
|
||||
global.setProperty("QRectF", constructQRectFClass(m_engine));
|
||||
global.setProperty("QSizeF", constructQSizeFClass(m_engine));
|
||||
global.setProperty("QPoint", constructQPointClass(m_engine));
|
||||
global.setProperty("LinearLayout", constructLinearLayoutClass(m_engine));
|
||||
|
||||
// Bindings for data engine
|
||||
m_engine->setDefaultPrototype(qMetaTypeId<DataEngine*>(), m_engine->newQObject(new DataEngine()));
|
||||
@ -381,7 +383,6 @@ void SimpleJavaScriptApplet::setupObjects()
|
||||
qScriptRegisterMetaType<DataEngine::Data>(m_engine, qScriptValueFromData, 0, QScriptValue());
|
||||
|
||||
installWidgets(m_engine);
|
||||
installLayouts(m_engine);
|
||||
}
|
||||
|
||||
QString SimpleJavaScriptApplet::findDataResource(const QString &filename)
|
||||
@ -522,15 +523,14 @@ void SimpleJavaScriptApplet::installWidgets(QScriptEngine *engine)
|
||||
QScriptValue globalObject = engine->globalObject();
|
||||
UiLoader loader;
|
||||
|
||||
QStringList widgets = loader.availableWidgets();
|
||||
for (int i=0; i < widgets.size(); ++i) {
|
||||
foreach (const QString &widget, loader.availableWidgets()) {
|
||||
QScriptValue fun = engine->newFunction(createWidget);
|
||||
QScriptValue name = engine->toScriptValue(widgets[i]);
|
||||
QScriptValue name = engine->toScriptValue(widget);
|
||||
fun.setProperty(QString("functionName"), name,
|
||||
QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
|
||||
fun.setProperty(QString("prototype"), createPrototype(engine, name.toString()));
|
||||
|
||||
globalObject.setProperty(widgets[i], fun);
|
||||
globalObject.setProperty(widget, fun);
|
||||
}
|
||||
}
|
||||
|
||||
@ -564,56 +564,6 @@ QScriptValue SimpleJavaScriptApplet::createWidget(QScriptContext *context, QScri
|
||||
return fun;
|
||||
}
|
||||
|
||||
void SimpleJavaScriptApplet::installLayouts(QScriptEngine *engine)
|
||||
{
|
||||
QScriptValue globalObject = engine->globalObject();
|
||||
UiLoader loader;
|
||||
|
||||
QStringList layouts = loader.availableLayouts();
|
||||
for (int i=0; i < layouts.size(); ++i) {
|
||||
QScriptValue fun = engine->newFunction(createLayout);
|
||||
QScriptValue name = engine->toScriptValue(layouts[i]);
|
||||
fun.setProperty(QString("functionName"), name,
|
||||
QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
|
||||
fun.setProperty(QString("prototype"), createPrototype(engine, name.toString()));
|
||||
|
||||
globalObject.setProperty(layouts[i], fun);
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::createLayout(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
return context->throwError("CreateLayout is currently broken.");
|
||||
/*
|
||||
if (context->argumentCount() > 1) {
|
||||
//FIXME: 4.3: i18nc
|
||||
return context->throwError("CreateLayout takes one argument");
|
||||
}
|
||||
|
||||
QGraphicsWidget *parent = 0;
|
||||
if (context->argumentCount()) {
|
||||
parent = qscriptvalue_cast<QGraphicsWidget*>(context->argument(0));
|
||||
|
||||
if (!parent) {
|
||||
return context->throwError(i18n("The parent must be a QGraphicsWidget"));
|
||||
}
|
||||
}
|
||||
|
||||
QString self = context->callee().property("functionName").toString();
|
||||
UiLoader loader;
|
||||
QGraphicsLayout *w = loader.createLayout(self, parent);
|
||||
|
||||
if (!w) {
|
||||
return QScriptValue();
|
||||
}
|
||||
|
||||
QScriptValue fun = engine->newQObject(w);
|
||||
fun.setPrototype(context->callee().property("prototype"));
|
||||
|
||||
return fun;
|
||||
*/
|
||||
}
|
||||
|
||||
QScriptValue SimpleJavaScriptApplet::print(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
|
@ -65,9 +65,7 @@ private:
|
||||
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
|
||||
|
||||
void installWidgets( QScriptEngine *engine );
|
||||
void installLayouts( QScriptEngine *engine );
|
||||
static QScriptValue createWidget(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue createLayout(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue print(QScriptContext *context, QScriptEngine *engine);
|
||||
static QScriptValue createPrototype( QScriptEngine *engine, const QString &name );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user