File indexing completed on 2024-12-01 12:37:39
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 0003 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 0004 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org> 0005 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 #include "qlayout_binding.h" 0023 #include "static_binding.h" 0024 #include "kjseglobal.h" 0025 0026 #include <kjs/object.h> 0027 #include <QDebug> 0028 0029 #include <QWidget> 0030 #include <QAction> 0031 #include <QtUiTools/QUiLoader> 0032 0033 namespace KJSEmbed 0034 { 0035 QUiLoader *uiLoader(); 0036 } 0037 0038 using namespace KJSEmbed; 0039 0040 namespace LayoutNS 0041 { 0042 START_QOBJECT_METHOD(addWidget, QLayout) 0043 QWidget *w = KJSEmbed::extractObject<QWidget>(exec, args, 0, nullptr); 0044 object->addWidget(w); 0045 END_QOBJECT_METHOD 0046 START_QOBJECT_METHOD(removeWidget, QLayout) 0047 QWidget *w = KJSEmbed::extractObject<QWidget>(exec, args, 0, nullptr); 0048 object->removeWidget(w); 0049 END_QOBJECT_METHOD 0050 START_QOBJECT_METHOD(parentWidget, QLayout) 0051 QWidget *w = object->parentWidget(); 0052 result = KJSEmbed::createQObject(exec, w); 0053 END_QOBJECT_METHOD 0054 0055 } 0056 0057 START_METHOD_LUT(Layout) 0058 {"addWidget", 1, KJS::DontDelete | KJS::ReadOnly, &LayoutNS::addWidget}, 0059 {"removeWidget", 1, KJS::DontDelete | KJS::ReadOnly, &LayoutNS::removeWidget}, 0060 {"parentWidget", 0, KJS::DontDelete | KJS::ReadOnly, &LayoutNS::parentWidget} 0061 END_METHOD_LUT 0062 0063 NO_ENUMS(Layout) 0064 NO_STATICS(Layout) 0065 0066 KJSO_SIMPLE_BINDING_CTOR(Layout, QLayout, QObjectBinding) 0067 KJSO_QOBJECT_BIND(Layout, QLayout) 0068 0069 KJSO_START_CTOR(Layout, QLayout, 0) 0070 // qDebug("Layout::CTOR(): args.size()=%d", args.size()); 0071 0072 if (args.size() > 0) 0073 { 0074 QString layoutName = toQString(args[0]->toString(exec)); 0075 QObject *parentObject = nullptr; 0076 KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp<KJSEmbed::QObjectBinding>(exec, args[1]); 0077 if (parentImp) { 0078 parentObject = parentImp->object<QObject>(); 0079 } 0080 0081 QLayout *layout = uiLoader()->createLayout(layoutName, parentObject, "QLayout"); 0082 if (layout) { 0083 KJS::JSObject *layoutObject = new Layout(exec, layout);//KJSEmbed::createQObject(exec, layout); 0084 return layoutObject; 0085 } 0086 return KJS::throwError(exec, KJS::GeneralError, i18n("'%1' is not a valid QLayout.", 0087 layoutName)); 0088 // return KJSEmbed::throwError(exec, i18n("'%1' is not a valid QLayout.").arg(layoutName)); 0089 } 0090 0091 // should Trow error incorrect args 0092 return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a layout name.")); 0093 // return KJSEmbed::throwError(exec, i18n("Must supply a layout name.")); 0094 KJSO_END_CTOR 0095