kjsembed
qlayout_binding.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "qlayout_binding.h"
00023 #include "static_binding.h"
00024 #include "kjseglobal.h"
00025
00026 #include <kjs/object.h>
00027 #include <QtCore/QDebug>
00028
00029 #include <QtGui/QWidget>
00030 #include <QtGui/QAction>
00031 #include <QtGui/QLayout>
00032 #include <QtUiTools/QUiLoader>
00033
00034 namespace KJSEmbed
00035 {
00036 QUiLoader *uiLoader();
00037 }
00038
00039
00040 using namespace KJSEmbed;
00041
00042 namespace LayoutNS
00043 {
00044 START_QOBJECT_METHOD( addWidget, QLayout )
00045 QWidget *w = KJSEmbed::extractObject<QWidget>(exec, args, 0, 0);
00046 object->addWidget(w);
00047 END_QOBJECT_METHOD
00048 START_QOBJECT_METHOD( removeWidget, QLayout )
00049 QWidget *w = KJSEmbed::extractObject<QWidget>(exec, args, 0, 0);
00050 object->removeWidget(w);
00051 END_QOBJECT_METHOD
00052 START_QOBJECT_METHOD( parentWidget, QLayout )
00053 QWidget *w = object->parentWidget();
00054 result = KJSEmbed::createQObject(exec,w);
00055 END_QOBJECT_METHOD
00056
00057 }
00058
00059 START_METHOD_LUT( Layout )
00060 {"addWidget", 1, KJS::DontDelete|KJS::ReadOnly, &LayoutNS::addWidget},
00061 {"removeWidget", 1, KJS::DontDelete|KJS::ReadOnly, &LayoutNS::removeWidget},
00062 {"parentWidget", 0, KJS::DontDelete|KJS::ReadOnly, &LayoutNS::parentWidget}
00063 END_METHOD_LUT
00064
00065 NO_ENUMS( Layout )
00066 NO_STATICS( Layout )
00067
00068 KJSO_SIMPLE_BINDING_CTOR( Layout, QLayout, QObjectBinding )
00069 KJSO_QOBJECT_BIND( Layout, QLayout )
00070
00071 KJSO_START_CTOR( Layout, QLayout, 0 )
00072
00073
00074 if( args.size() > 0 )
00075 {
00076 QString layoutName = toQString(args[0]->toString(exec));
00077 QObject *parentObject = 0;
00078 KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp<KJSEmbed::QObjectBinding>(exec, args[1] );
00079 if( parentImp )
00080 {
00081 parentObject = parentImp->object<QObject>();
00082 }
00083
00084 QLayout *layout = uiLoader()->createLayout(layoutName, parentObject, "QLayout");
00085 if( layout )
00086 {
00087 KJS::JSObject *layoutObject = new Layout(exec, layout);
00088 return layoutObject;
00089 }
00090 return KJS::throwError(exec, KJS::GeneralError, i18n("'%1' is not a valid QLayout.",
00091 layoutName));
00092
00093 }
00094
00095
00096 return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a layout name."));
00097
00098 KJSO_END_CTOR
00099
00100