summaryrefslogtreecommitdiff
path: root/client/widgets/widget.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets/widget.cc')
-rw-r--r--client/widgets/widget.cc175
1 files changed, 169 insertions, 6 deletions
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index 085ac21..33e4309 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -27,7 +27,7 @@
#include "widget.h"
#include "macrowindow.h"
-#include "lua.h"
+#include "luawidget.h"
#include "../widgets.h"
#include <QLayout>
@@ -44,7 +44,11 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow)
QDomElement elem = node.toElement();
this->macrowindow = macrowindow;
- this->lua = macrowindow->lua;
+ if(macrowindow) {
+ this->lua = macrowindow->lua;
+ } else {
+ this->lua = NULL;
+ }
widget_type = elem.tagName();
@@ -154,7 +158,7 @@ void Widget::runEventOnChange(bool deep)
//if(preValid() == false) setWdgValid(false);
setWdgValid(valid());
if(hasOnChangeEvent)
- lua->runScript(onChangeEventScript, this, "onChange");
+ if(lua) lua->runScript(onChangeEventScript, this, "onChange");
}
if(!deep) return;
@@ -172,7 +176,7 @@ void Widget::runEventOnInit(bool deep)
//if(preValid() == false) setWdgValid(false);
setWdgValid(valid());
if(hasOnInitEvent)
- lua->runScript(onInitEventScript, this, "onInit");
+ if(lua) lua->runScript(onInitEventScript, this, "onInit");
}
if(!deep) return;
@@ -299,7 +303,7 @@ void Widget::addChild(Widget *widget)
void Widget::addChildren(QDomNode &node, QLayout *layout)
{
QDomNodeList children = node.childNodes();
- for (int i=0; i<children.count();i++) {
+ for(int i = 0; i < children.count(); i++) {
QDomNode child = children.at(i);
createWidget(child, layout);
}
@@ -324,7 +328,7 @@ void Widget::createWidget(QDomNode &xml_node, QLayout *layout)
// TODO: Why do we do this??
if(xml_elem.hasAttribute("prefilled") &&
xml_elem.attribute("prefilled") != "pracro") {
- macrowindow->macroChanged();
+ if(macrowindow) macrowindow->macroChanged();
}
Widget *widget = NULL;
@@ -416,3 +420,162 @@ void Widget::createWidget(QDomNode &xml_node, QLayout *layout)
if(widget && widget->qwidget()) widget->qwidget()->show();
}
+
+int wdg_name(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ lua_pushstring(L, wdgu->widget->name().toStdString().c_str());
+
+ return 1;
+}
+
+int wdg_type(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ // return error code
+ lua_pushstring(L, wdgu->widget->type().toStdString().c_str());
+
+ return 1;
+}
+
+int wdg_value(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ lua_pushstring(L, wdgu->widget->value().toStdString().c_str());
+
+ return 1;
+}
+
+int wdg_set_value(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ const char *val = luaL_checkstring(L, 2);
+
+ wdgu->widget->setValue(val, LUA_SRC);
+
+ return 0;
+}
+
+int wdg_enabled(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ lua_pushboolean(L, wdgu->widget->enabled());
+
+ return 1;
+}
+
+int wdg_set_enabled(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ bool val = luaL_checkbool(L, 2);
+
+ wdgu->widget->setEnabled(val);
+
+ return 0;
+}
+
+int wdg_visible(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ lua_pushboolean(L, wdgu->widget->visible());
+
+ return 1;
+}
+
+int wdg_set_visible(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ bool val = luaL_checkbool(L, 2);
+
+ wdgu->widget->setVisible(val);
+
+ return 0;
+}
+
+int wdg_valid(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ lua_pushboolean(L, wdgu->widget->valid());
+
+ return 1;
+}
+
+int wdg_set_valid(lua_State *L)
+{
+ wdg_userdata *wdgu;
+
+ wdgu = (wdg_userdata *)luaL_isudata(L, 1, "Widget");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "CheckBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "ComboBox");
+ if(!wdgu) wdgu = (wdg_userdata *)luaL_isudata(L, 1, "LineEdit");
+ luaL_argcheck(L, wdgu, 1, "widget expected");
+
+ bool val = luaL_checkbool(L, 2);
+
+ wdgu->widget->setValid(val);
+
+ return 0;
+}