summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/luawidget.cc91
-rw-r--r--client/widgets/combobox.cc10
-rw-r--r--client/widgets/combobox.h3
-rw-r--r--client/widgets/dbwidget.cc2
4 files changed, 80 insertions, 26 deletions
diff --git a/client/luawidget.cc b/client/luawidget.cc
index 529984c..ba64257 100644
--- a/client/luawidget.cc
+++ b/client/luawidget.cc
@@ -29,6 +29,8 @@
#include "widgets.h"
+#include "debug.h"
+
#define LUA_SRC "lua"
/**
@@ -196,20 +198,32 @@ static int wdg_set_valid(lua_State *L)
return 0;
}
-static int wdg_checked(lua_State *L)
+#define WDG_METHS \
+ {"name", wdg_name},\
+ {"type", wdg_type},\
+ {"value", wdg_value},\
+ {"setValue", wdg_set_value},\
+ {"enabled", wdg_enabled},\
+ {"setEnabled", wdg_set_enabled},\
+ {"visible", wdg_visible},\
+ {"setVisible", wdg_set_visible},\
+ {"valid", wdg_valid},\
+ {"setValid", wdg_set_valid}
+
+static int wdg_chk_checked(lua_State *L)
{
wdg_userdata *wdgu;
wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
luaL_argcheck(L, wdgu, 1, "checkbox expected");
- CheckBox *cmb = (CheckBox*)wdgu->widget;
- lua_pushboolean(L, cmb->checked());
+ CheckBox *chk = (CheckBox*)wdgu->widget;
+ lua_pushboolean(L, chk->checked());
return 1;
}
-static int wdg_set_checked(lua_State *L)
+static int wdg_chk_set_checked(lua_State *L)
{
wdg_userdata *wdgu;
@@ -218,27 +232,47 @@ static int wdg_set_checked(lua_State *L)
bool val = luaL_checkbool(L, 2);
- CheckBox *cmb = (CheckBox*)wdgu->widget;
- cmb->setChecked(val);
+ CheckBox *chk = (CheckBox*)wdgu->widget;
+ chk->setChecked(val);
return 0;
}
-#define WDG_METHS \
- {"name", wdg_name},\
- {"type", wdg_type},\
- {"value", wdg_value},\
- {"setValue", wdg_set_value},\
- {"enabled", wdg_enabled},\
- {"setEnabled", wdg_set_enabled},\
- {"visible", wdg_visible},\
- {"setVisible", wdg_set_visible},\
- {"valid", wdg_valid},\
- {"setValid", wdg_set_valid}
+#define WDG_CMBBOX_METHS \
+ {"checked", wdg_chk_checked},\
+ {"setChecked", wdg_chk_set_checked}
+
+static int wdg_cmb_clear(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ luaL_argcheck(L, wdgu, 1, "combobox expected");
+
+ ComboBox *cmb = (ComboBox*)wdgu->widget;
+ cmb->clear();
+
+ return 0;
+}
+
+static int wdg_cmb_add_item(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ luaL_argcheck(L, wdgu, 1, "combobox expected");
+
+ QString val = luaL_checkstring(L, 2);
+
+ ComboBox *cmb = (ComboBox*)wdgu->widget;
+ cmb->addItem(val);
+
+ return 0;
+}
#define WDG_CHKBOX_METHS \
- {"checked", wdg_checked},\
- {"setChecked", wdg_set_checked}
+ {"clear", wdg_cmb_clear},\
+ {"addItem", wdg_cmb_add_item}
static const struct luaL_Reg wdg_meths[] = {
WDG_METHS, {NULL, NULL} };
@@ -246,6 +280,9 @@ static const struct luaL_Reg wdg_meths[] = {
static const struct luaL_Reg wdg_chkbox_meths[] = {
WDG_METHS, WDG_CHKBOX_METHS, {NULL, NULL} };
+static const struct luaL_Reg wdg_cmbbox_meths[] = {
+ WDG_METHS, WDG_CMBBOX_METHS, {NULL, NULL} };
+
static const struct luaL_Reg wdg_chk_meths[] =
{
{NULL, NULL}
@@ -256,12 +293,10 @@ int wdg_make_widget(lua_State *L, Widget *widget)
wdg_userdata *wdgu;
wdgu = (wdg_userdata *)lua_newuserdata(L, sizeof(wdg_userdata));
- if(widget->type() == "checkbox") {
- luaL_getmetatable(L, "CheckBox");
- } else {
- luaL_getmetatable(L, "Widget");
- }
-
+ if(widget->type() == "combobox") luaL_getmetatable(L, "ComboBox");
+ else if(widget->type() == "checkbox") luaL_getmetatable(L, "CheckBox");
+ else luaL_getmetatable(L, "Widget");
+
lua_setmetatable(L, -2);
wdgu->widget = widget;
@@ -283,5 +318,11 @@ void register_widget(lua_State *L)
lua_rawset(L, -3);
luaL_register(L, NULL, wdg_chkbox_meths);
+ luaL_newmetatable(L, "ComboBox");
+ lua_pushliteral(L, "__index");
+ lua_pushvalue(L, -2);
+ lua_rawset(L, -3);
+ luaL_register(L, NULL, wdg_cmbbox_meths);
+
}
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc
index ec260ea..b625848 100644
--- a/client/widgets/combobox.cc
+++ b/client/widgets/combobox.cc
@@ -228,3 +228,13 @@ void ComboBox::setWdgValid(bool valid)
if(combobox->lineEdit()) combobox->lineEdit()->setPalette(palette);
combobox->setPalette(palette);
}
+
+void ComboBox::clear()
+{
+ combobox->clear();
+}
+
+void ComboBox::addItem(QString item)
+{
+ combobox->addItem(item, item);
+}
diff --git a/client/widgets/combobox.h b/client/widgets/combobox.h
index 57800d2..02b4ccd 100644
--- a/client/widgets/combobox.h
+++ b/client/widgets/combobox.h
@@ -54,6 +54,9 @@ public:
void setWdgValid(bool valid);
+ void clear();
+ void addItem(QString item);
+
public slots:
void changed();
diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc
index 1292708..0708304 100644
--- a/client/widgets/dbwidget.cc
+++ b/client/widgets/dbwidget.cc
@@ -84,7 +84,7 @@ DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow)
combobox->setEditable(true);
// Make empty default selection.
- combobox->addItem(tr("Write something in the searchfield"));
+ combobox->addItem(tr("EMPTY_STRING"));
combobox->setCurrentIndex(-1);
QStringListModel *strlst = new QStringListModel();