diff options
author | deva <deva> | 2011-06-28 06:38:10 +0000 |
---|---|---|
committer | deva <deva> | 2011-06-28 06:38:10 +0000 |
commit | 6389aabffe198ece92b58ae34a905902c7eefe7c (patch) | |
tree | cfda4b340e462e5193f4ac2e6814cce5d707ca4f /client/widgets/widget.cc | |
parent | 01febc40e2aad29bf6cf6cbeb457c44354aba0f9 (diff) |
Complete rewrite of the way lua widget methods, 'inheritance' in particular, are handled.
Diffstat (limited to 'client/widgets/widget.cc')
-rw-r--r-- | client/widgets/widget.cc | 144 |
1 files changed, 100 insertions, 44 deletions
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index c0c9e81..2374c6f 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -77,6 +77,8 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow) connect(this, SIGNAL(eventOnInit()), this, SLOT(runEventOnInit()), Qt::QueuedConnection); + replwidget = NULL; + DEBUG(widget, "Create Widget '%s' of type '%s'\n", name().toStdString().c_str(), type().toStdString().c_str()); @@ -238,8 +240,64 @@ bool Widget::enabled() void Widget::setVisible(bool visible) { + if(visible == this->visible()) return; + + QBoxLayout *l = (QBoxLayout *)widget->parentWidget()->layout(); + + if(visible == false) { + if(replwidget == NULL) delete replwidget; + + replwidget = new QFrame(); + replwidget->setMinimumSize(widget->frameGeometry().size()); + + { + int l,t,r,b; + widget->getContentsMargins(&l,&t,&r,&b); + replwidget->setContentsMargins(l, t, r, b); + } + + int idx = l->indexOf(widget); + l->insertWidget(idx, replwidget); + + } else { + int idx = l->indexOf(replwidget); + if(replwidget) { + delete replwidget; + replwidget = NULL; + } + l->insertWidget(idx, widget); + } + + // replwidget->setVisible(!visible); widget->setVisible(visible); - if(visible) emit eventOnChange(); + + if(visible) { + emit eventOnChange(); + + QVector< Widget* >::iterator i = children.begin(); + while(i != children.end()) { + if(*i) (*i)->runEventOnChange(true); + i++; + } + } +} + +bool Widget::visible() +{ + return widget->isVisible(); +} + +void Widget::setHidden(bool hidden) +{ + if(hidden == this->hidden()) return; + + widget->setHidden(hidden); + if(replwidget) replwidget->setHidden(hidden); + + if(macrowindow) + macrowindow->setFixedHeight(macrowindow->minimumSizeHint().height()); + + if(hidden == false) emit eventOnChange(); QVector< Widget* >::iterator i = children.begin(); while(i != children.end()) { @@ -248,9 +306,9 @@ void Widget::setVisible(bool visible) } } -bool Widget::visible() +bool Widget::hidden() { - return widget->isVisible(); + return widget->isHidden(); } bool Widget::setKeyboardFocus() @@ -261,7 +319,9 @@ bool Widget::setKeyboardFocus() Widget *Widget::findWidget(QString n, bool deep) { - DEBUG(widget, "Find Widget this: %s\n", name().toStdString().c_str()); + DEBUG(widget, "Find Widget '%s' this: '%s' (hide?%d deep?%d #child:%d)\n", + n.toStdString().c_str(), name().toStdString().c_str(), + hideChildren, deep, children.size()); if(n == name()) return this; @@ -445,10 +505,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); lua_pushstring(L, wdgu->widget->name().toStdString().c_str()); @@ -460,10 +517,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); // return error code @@ -476,10 +530,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); lua_pushstring(L, wdgu->widget->value().toStdString().c_str()); @@ -491,10 +542,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); const char *val = luaL_checkstring(L, 2); @@ -508,10 +556,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); lua_pushboolean(L, wdgu->widget->enabled()); @@ -523,10 +568,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); bool val = luaL_checkbool(L, 2); @@ -540,10 +582,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); lua_pushboolean(L, wdgu->widget->visible()); @@ -555,10 +594,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); bool val = luaL_checkbool(L, 2); @@ -568,14 +604,37 @@ int wdg_set_visible(lua_State *L) return 0; } +int wdg_hidden(lua_State *L) +{ + wdg_userdata *wdgu; + + wdgu = (wdg_userdata *)lua_touserdata(L, 1); + luaL_argcheck(L, wdgu, 1, "widget expected"); + + lua_pushboolean(L, wdgu->widget->hidden()); + + return 1; +} + +int wdg_set_hidden(lua_State *L) +{ + wdg_userdata *wdgu; + + wdgu = (wdg_userdata *)lua_touserdata(L, 1); + luaL_argcheck(L, wdgu, 1, "widget expected"); + + bool val = luaL_checkbool(L, 2); + + wdgu->widget->setHidden(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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); lua_pushboolean(L, wdgu->widget->valid()); @@ -587,10 +646,7 @@ 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"); + wdgu = (wdg_userdata *)lua_touserdata(L, 1); luaL_argcheck(L, wdgu, 1, "widget expected"); bool val = luaL_checkbool(L, 2); |