From 01ab57dabbc15f52143089e53317bb51b71dc7f2 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 8 Nov 2011 10:46:30 +0100 Subject: New lua and xml attr methods for setting widget foreground and background colours. --- client/widgets/widget.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'client/widgets/widget.cc') diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index 2374c6f..ac90ef2 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -401,6 +401,26 @@ void Widget::setValues() else emit eventOnChange(); // Make sure we run validation on the unset widget. } +void Widget::setForegroundColour(unsigned char red, + unsigned char green, + unsigned char blue) +{ + char style[128]; + sprintf(style, "* { color: #%02x%02x%02x; }", + red, green, blue); + qwidget()->setStyleSheet(style); +} + +void Widget::setBackgroundColour(unsigned char red, + unsigned char green, + unsigned char blue) +{ + char style[128]; + sprintf(style, "* { background-color: #%02x%02x%02x; }", + red, green, blue); + qwidget()->setStyleSheet(style); +} + void Widget::createWidget(QDomNode &xml_node, QLayout *layout) { QDomElement xml_elem = xml_node.toElement(); @@ -655,3 +675,36 @@ int wdg_set_valid(lua_State *L) return 0; } + +int wdg_set_bgcol(lua_State *L) +{ + wdg_userdata *wdgu; + + wdgu = (wdg_userdata *)lua_touserdata(L, 1); + luaL_argcheck(L, wdgu, 1, "widget expected"); + + int r = luaL_checknumber(L, 2); + int g = luaL_checknumber(L, 3); + int b = luaL_checknumber(L, 4); + + wdgu->widget->setBackgroundColour((unsigned char)r, (unsigned char)g, (unsigned char)b); + + return 0; +} + +int wdg_set_fgcol(lua_State *L) +{ + wdg_userdata *wdgu; + + wdgu = (wdg_userdata *)lua_touserdata(L, 1); + luaL_argcheck(L, wdgu, 1, "widget expected"); + + int r = luaL_checknumber(L, 2); + int g = luaL_checknumber(L, 3); + int b = luaL_checknumber(L, 4); + + wdgu->widget->setForegroundColour((unsigned char)r, (unsigned char)g, (unsigned char)b); + + return 0; +} + -- cgit v1.2.3