diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/lua.cc | 2 | ||||
| -rw-r--r-- | client/widgets/lineedit.cc | 9 | ||||
| -rw-r--r-- | client/widgets/widget.cc | 16 | ||||
| -rw-r--r-- | client/widgets/widget.h | 4 | 
4 files changed, 26 insertions, 5 deletions
| diff --git a/client/lua.cc b/client/lua.cc index 46c8fbd..c803e23 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -42,6 +42,8 @@ LUA::LUA(Variables &variables)      var++;    } +  //  printf("preload: [%s]\n", preload.c_str());  +    int s = luaL_loadbuffer(L, preload.c_str(), preload.size(), "preload");    switch(s) {    case 0: //no errors; diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 26c2760..a6f2e83 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -56,8 +56,13 @@ void LineEdit::changed()    QPalette palette;    if(regexpValidator()) { -    // valid string -    palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); +    if(luaValidator()) { +      // valid string +      palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); +    } else { +      // invalid string +      palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200))); +    }    } else {      // invalid string      palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index b128a53..d17754e 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -38,7 +38,7 @@ Widget::Widget(QDomNode &node)    }    if(elem.hasAttribute("lua_validator")) { -    //      lua_validator = elem.attribute("lua_validator"); +    lua_validator = elem.attribute("lua_validator");      hasluavalidator = true;    } else {      hasluavalidator = false; @@ -75,5 +75,17 @@ bool Widget::regexpValidator()  bool Widget::luaValidator()  { -  return !hasluavalidator || true; +  if(!hasluavalidator) return true; + +  Variables v; +  v["value"] = getValue().toStdString(); +  LUA lua(v); +   +  std::string program = lua_validator.toStdString(); + +  std::string result = lua.run(program); + +  //  printf("Running [%s] => [%s]\n", program.c_str(), result.c_str()); + +  return result == "true";  } diff --git a/client/widgets/widget.h b/client/widgets/widget.h index 89610bb..391f2e9 100644 --- a/client/widgets/widget.h +++ b/client/widgets/widget.h @@ -49,9 +49,11 @@ protected:  private:    QRegExp rx; -  LUA *lua; +    bool hasregexpvalidator;    bool hasluavalidator; + +  QString lua_validator;  };  #endif/*__PRACRO_WIDGET_H__*/ | 
