summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/lua.cc136
-rw-r--r--client/lua.h14
-rw-r--r--client/macrowindow.cc12
-rw-r--r--client/widgets/widget.cc24
-rw-r--r--client/widgets/widget.h5
5 files changed, 185 insertions, 6 deletions
diff --git a/client/lua.cc b/client/lua.cc
index 2753139..320d91a 100644
--- a/client/lua.cc
+++ b/client/lua.cc
@@ -90,10 +90,118 @@ static int debug(lua_State *L)
return 0;
}
-LUA::LUA(Widget **rootwidget)
+static int get_template(lua_State *L)
{
- this->rootwidget = rootwidget;
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString templ = lua->getTemplate();
+ lua_pushstring(L, templ.toStdString().c_str());
+
+ return 1;
+}
+
+static int get_macro(lua_State *L)
+{
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString macro = lua->getMacro();
+ lua_pushstring(L, macro.toStdString().c_str());
+
+ return 1;
+}
+
+static int get_user(lua_State *L)
+{
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString user = lua->getUser();
+ lua_pushstring(L, user.toStdString().c_str());
+
+ return 1;
+}
+
+static int get_patientid(lua_State *L)
+{
+ int n = lua_gettop(L); // number of arguments
+ if(n != 0) {
+ char errstr[512];
+ sprintf(errstr, "Number of args expected 0, got %d", n);
+ lua_pushstring(L, errstr);
+ lua_error(L);
+ return 1;
+ }
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUA *lua = (LUA*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ QString patientid = lua->getPatientID();
+ lua_pushstring(L, patientid.toStdString().c_str());
+
+ return 1;
+}
+
+LUA::LUA(Widget **rootwidget, QString templ, QString macro, QString user,
+ QString patientid)
+{
+ this->rootwidget = rootwidget;
+ this->templ = templ;
+ this->macro = macro;
+ this->user = user;
+ this->patientid = patientid;
L = NULL;
clear();
}
@@ -120,6 +228,10 @@ void LUA::clear()
lua_register(L, "widget", get_widget);
lua_register(L, "debug", debug);
+ lua_register(L, "template", get_template);
+ lua_register(L, "macro", get_macro);
+ lua_register(L, "user", get_user);
+ lua_register(L, "patientid", get_patientid);
register_widget(L);
register_db(L);
@@ -216,3 +328,23 @@ Widget *LUA::getWidget(QString name)
return NULL;
}
}
+
+QString LUA::getTemplate()
+{
+ return templ;
+}
+
+QString LUA::getMacro()
+{
+ return macro;
+}
+
+QString LUA::getUser()
+{
+ return user;
+}
+
+QString LUA::getPatientID()
+{
+ return patientid;
+}
diff --git a/client/lua.h b/client/lua.h
index 8200873..fcc7f54 100644
--- a/client/lua.h
+++ b/client/lua.h
@@ -36,7 +36,8 @@
class Widget;
class LUA {
public:
- LUA(Widget **rootwidget);
+ LUA(Widget **rootwidget, QString templ, QString macro, QString user,
+ QString patientid);
~LUA();
bool runScript(QString script, Widget *widget, QString name = "");
@@ -46,9 +47,20 @@ public:
void clear();
+ QString getTemplate();
+ QString getMacro();
+ QString getUser();
+ QString getPatientID();
+
+ QString macro;
+
private:
lua_State *L;
Widget **rootwidget;
+
+ QString templ;
+ QString user;
+ QString patientid;
};
#endif/*__PRACRO_LUA_H__*/
diff --git a/client/macrowindow.cc b/client/macrowindow.cc
index 7641fdc..ca76b46 100644
--- a/client/macrowindow.cc
+++ b/client/macrowindow.cc
@@ -42,6 +42,9 @@
extern MainWindow *gmainwindow;
+extern QString cpr;
+extern QString user;
+
MacroWindow::MacroWindow(NetCom &n, QString templ,
bool is_static, bool compact,
QScrollArea *scrollarea)
@@ -52,7 +55,7 @@ MacroWindow::MacroWindow(NetCom &n, QString templ,
DEBUG(macrowindow, "Constructor %p\n", this);
mainwidget = NULL;
- lua = new LUA(&mainwidget);
+ lua = new LUA(&mainwidget, templ, "", user, cpr);
waschanged = false;
@@ -80,6 +83,8 @@ void MacroWindow::update(QDomNode &node)
if(macro == "") macro = elem.attribute("name", "");
if(version == "") version = elem.attribute("version", "");
+ lua->macro = macro;
+
if(macro != elem.attribute("name", "")) return;
if(version != elem.attribute("version", "")) return;
@@ -133,14 +138,15 @@ void MacroWindow::initMacro(QDomNode &node)
if(elem.tagName() == "widgets") {
Window *window = new Window(elem, this);
+ mainwidget = window;
connect(window, SIGNAL(wasChanged()), this, SLOT(macroChanged()));
macrotitle = elem.attribute("caption");
window->setValues();
+ window->runEventOnInit(true);
if(waschanged == true) macroChanged();
- WARN(macrowindow, "New window.");
- mainwidget = window;
+ WARN(macrowindow, "New window.\n");
animateToWidget(mainwidget->qwidget());
return; // No further recursion here.
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index 1fefae8..085ac21 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -62,11 +62,17 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow)
hasOnChangeEvent = elem.hasAttribute("onChange");
onChangeEventScript = elem.attribute("onChange", "");
+ hasOnInitEvent = elem.hasAttribute("onInit");
+ onInitEventScript = elem.attribute("onInit", "");
+
is_valid = true;
connect(this, SIGNAL(eventOnChange()),
this, SLOT(runEventOnChange()), Qt::QueuedConnection);
+ connect(this, SIGNAL(eventOnInit()),
+ this, SLOT(runEventOnInit()), Qt::QueuedConnection);
+
DEBUG(widget, "Create Widget '%s' of type '%s'\n",
name().toStdString().c_str(),
type().toStdString().c_str());
@@ -160,6 +166,24 @@ void Widget::runEventOnChange(bool deep)
}
}
+void Widget::runEventOnInit(bool deep)
+{
+ if(enabled()) {
+ //if(preValid() == false) setWdgValid(false);
+ setWdgValid(valid());
+ if(hasOnInitEvent)
+ lua->runScript(onInitEventScript, this, "onInit");
+ }
+
+ if(!deep) return;
+
+ QVector< Widget* >::iterator i = children.begin();
+ while(i != children.end()) {
+ if(*i) (*i)->runEventOnInit(deep);
+ i++;
+ }
+}
+
void Widget::setWdgValidRecursive(bool forcevalid)
{
if(forcevalid) setWdgValid(true);
diff --git a/client/widgets/widget.h b/client/widgets/widget.h
index d964974..37a365f 100644
--- a/client/widgets/widget.h
+++ b/client/widgets/widget.h
@@ -85,10 +85,12 @@ signals:
* LUA scripting events:
*/
void eventOnChange(bool deep = false);
+ void eventOnInit(bool deep = false);
public slots:
void childWasChanged();
void runEventOnChange(bool deep = false);
+ void runEventOnInit(bool deep = false);
protected:
QWidget *widget;
@@ -118,6 +120,9 @@ private:
bool hasOnChangeEvent;
QString onChangeEventScript;
+
+ bool hasOnInitEvent;
+ QString onInitEventScript;
};
#endif/*__PRACRO_WIDGET_H__*/