kjsembed
qlayout_binding.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 00003 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 00004 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org> 00005 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 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 // qDebug("Layout::CTOR(): args.size()=%d", args.size()); 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);//KJSEmbed::createQObject(exec, layout); 00088 return layoutObject; 00089 } 00090 return KJS::throwError(exec, KJS::GeneralError, i18n("'%1' is not a valid QLayout.", 00091 layoutName)); 00092 // return KJSEmbed::throwError(exec, i18n("'%1' is not a valid QLayout.").arg(layoutName)); 00093 } 00094 00095 // should Trow error incorrect args 00096 return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a layout name.")); 00097 // return KJSEmbed::throwError(exec, i18n("Must supply a layout name.")); 00098 KJSO_END_CTOR 00099 00100 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
KDE 4.6 API Reference