From 6389aabffe198ece92b58ae34a905902c7eefe7c Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 28 Jun 2011 06:38:10 +0000 Subject: Complete rewrite of the way lua widget methods, 'inheritance' in particular, are handled. --- client/widgets/listbox.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'client/widgets/listbox.h') diff --git a/client/widgets/listbox.h b/client/widgets/listbox.h index fcfc1b0..82c5dfc 100644 --- a/client/widgets/listbox.h +++ b/client/widgets/listbox.h @@ -31,10 +31,28 @@ #include +#ifdef LUA_CLASS +#undef LUA_CLASS +#endif +#define LUA_CLASS "ListBox" + /*** * ListBox Widget * @tag listbox - * @screenshot + * @screenshot Example + * + * + * + * + * + * + * + * + * + * + * + * + * * @extends widget * This widget is a list of selectable items. * @att value [item] The value of the item and the value of the widget if this @@ -54,12 +72,17 @@ public: ListBox(QDomNode &node, MacroWindow *macrowindow); ~ListBox(); + virtual QString luaclass() { return LUA_CLASS; } + QString value(); void setValue(QString value, QString source); bool preValid(); void setWdgValid(bool valid); + void clear(); + void addItem(QString text, QString type); + public slots: void changed(); @@ -68,4 +91,49 @@ private: QListWidget *listwidget; }; +/*** + * @method nil clear() + * This method removes all items from the listbox. + */ +int lst_clear(lua_State *L); + +/*** + * @method nil addItem(string text) + * This method adds an item to the list. + * @param text The item text to be added. It will be added both as the value + * and caption of the item. + */ +int lst_add_item(lua_State *L); + +/*** + * @method nil addHeader(string text) + * This method adds a header item to the list. + * @param text The caption of the header. + */ +int lst_add_header(lua_State *L); + +/*** + * @method nil addSeparator() + * This method adds a separator item to the list. + */ +int lst_add_separator(lua_State *L); + +#define LSTBOX_METHS \ + {"clear", lst_clear},\ + {"addItem", lst_add_item}, \ + {"addHeader", lst_add_header}, \ + {"addSeparator", lst_add_separator} + +const struct luaL_Reg lstbox_meths[] = + { WDG_METHS, LSTBOX_METHS, {NULL, NULL} }; + +inline void register_listbox(lua_State *L) +{ + luaL_newmetatable(L, LUA_CLASS); + lua_pushliteral(L, "__index"); + lua_pushvalue(L, -2); + lua_rawset(L, -3); + luaL_register(L, NULL, lstbox_meths); +} + #endif/*__PRACRO_LISTBOX_H__*/ -- cgit v1.2.3