summaryrefslogtreecommitdiff
path: root/client/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets')
-rw-r--r--client/widgets/common.cc27
-rw-r--r--client/widgets/textedit.cc6
-rw-r--r--client/widgets/textedit.h4
-rw-r--r--client/widgets/widget.cc53
-rw-r--r--client/widgets/widget.h41
5 files changed, 125 insertions, 6 deletions
diff --git a/client/widgets/common.cc b/client/widgets/common.cc
index 2262074..3cf0d54 100644
--- a/client/widgets/common.cc
+++ b/client/widgets/common.cc
@@ -31,6 +31,8 @@
#include <QDomElement>
#include <QString>
+#include <stdio.h>
+
//#define LINEWIDTH 80
static QString reformatHelpString(QString help)
@@ -74,6 +76,31 @@ void setCommonAttributes(QWidget *widget, QDomNode &node)
widget->setWhatsThis(helptext);
// widget->setToolTip(helptext);
}
+
+ if(elem.hasAttribute("colour") &&
+ elem.attribute("colour").length() == 6) {
+ unsigned int r, g, b;
+ sscanf(elem.attribute("colour").toStdString().c_str(),
+ "%02x%02x%02x", &r, &g, &b);
+
+ char style[128];
+ sprintf(style, "* { color: #%02x%02x%02x; }",
+ r, g, b);
+ widget->setStyleSheet(style);
+ }
+
+ if(elem.hasAttribute("bgcolour") &&
+ elem.attribute("bgcolour").length() == 6) {
+ unsigned int r, g, b;
+ sscanf(elem.attribute("bgcolour").toStdString().c_str(),
+ "%02x%02x%02x", &r, &g, &b);
+
+ char style[128];
+ sprintf(style, "* { background-color: #%02x%02x%02x; }",
+ r, g, b);
+ widget->setStyleSheet(style);
+ }
+
}
void setCommonLayout(QWidget *widget, QDomNode &node)
diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc
index 757a353..96783d9 100644
--- a/client/widgets/textedit.cc
+++ b/client/widgets/textedit.cc
@@ -27,7 +27,7 @@
#include "textedit.h"
#include <QPalette>
-#include <QTextEdit>
+#include <QPlainTextEdit>
#include <stdio.h>
#include "common.h"
@@ -35,7 +35,7 @@
TextEdit::TextEdit(QDomNode &node, MacroWindow *macrowindow)
: Widget(node, macrowindow)
{
- textedit = new QTextEdit();
+ textedit = new QPlainTextEdit();
widget = textedit;
setCommonAttributes(textedit, node);
@@ -77,7 +77,7 @@ QString TextEdit::value()
void TextEdit::setValue(QString value, QString source)
{
if(isUserSource(source)) emit wasChanged();
- textedit->setText(value);
+ textedit->setPlainText(value);
// setInitialValue(value);
}
diff --git a/client/widgets/textedit.h b/client/widgets/textedit.h
index bfe7374..542dd6f 100644
--- a/client/widgets/textedit.h
+++ b/client/widgets/textedit.h
@@ -45,7 +45,7 @@
* still able to select and copy text.
*/
-class QTextEdit;
+class QPlainTextEdit;
class TextEdit : public Widget
{
Q_OBJECT
@@ -66,7 +66,7 @@ protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
- QTextEdit *textedit;
+ QPlainTextEdit *textedit;
};
#endif/*__PRACRO_TEXTEDIT_H__*/
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;
+}
+
diff --git a/client/widgets/widget.h b/client/widgets/widget.h
index d0f1799..4f23790 100644
--- a/client/widgets/widget.h
+++ b/client/widgets/widget.h
@@ -61,6 +61,12 @@
* @att local This attribute is a boolean telling wether the field can be stored
* in the database on commits. It can be either 'true' or 'false'. The default
* is 'false'.
+ * @att colour The foreground (text) colour of the widget. The value must be a
+ * 6 byte hexadecimal string with each 2 byte pair describing the colour
+ * channels in order: Red, green blue. Example: '0f1a3b'.
+ * @att bgcolour The background colour of the widget. The value must be a
+ * 6 byte hexadecimal string with each 2 byte pair describing the colour
+ * channels in order: Red, green blue. Example: '0f1a3b'.
*/
class QLayout;
@@ -106,6 +112,13 @@ public:
virtual bool setKeyboardFocus();
+ virtual void setForegroundColour(unsigned char red,
+ unsigned char green,
+ unsigned char blue);
+ virtual void setBackgroundColour(unsigned char red,
+ unsigned char green,
+ unsigned char blue);
+
virtual QWidget *qwidget() { return widget; }
// Set deep to true to search through inner widgets.
@@ -278,6 +291,30 @@ int wdg_valid(lua_State *L);
*/
int wdg_set_valid(lua_State *L);
+/***
+ * @method nil setBackgroundColour(integer red, integer green, integer blue)
+ * This method is used to change to background colour of the widget.
+ * @param red An integer value in the range 0-255. This is the red component of
+ * the RGB colour value.
+ * @param green An integer value in the range 0-255. This is the green component
+ * of the RGB colour value.
+ * @param blue An integer value in the range 0-255. This is the blue component
+ * of the RGB colour value.
+ */
+int wdg_set_bgcol(lua_State *L);
+
+/***
+ * @method nil setForegroundColour(integer red, integer green, integer blue)
+ * This method is used to change to foreground (text) colour of the widget.
+ * @param red An integer value in the range 0-255. This is the red component of
+ * the RGB colour value.
+ * @param green An integer value in the range 0-255. This is the green component
+ * of the RGB colour value.
+ * @param blue An integer value in the range 0-255. This is the blue component
+ * of the RGB colour value.
+ */
+int wdg_set_fgcol(lua_State *L);
+
#define WDG_METHS \
{"name", wdg_name},\
{"type", wdg_type},\
@@ -290,7 +327,9 @@ int wdg_set_valid(lua_State *L);
{"hidden", wdg_hidden},\
{"setHidden", wdg_set_hidden},\
{"valid", wdg_valid},\
- {"setValid", wdg_set_valid}
+ {"setValid", wdg_set_valid},\
+ {"setForegroundColour", wdg_set_fgcol},\
+ {"setBackgroundColour", wdg_set_bgcol}
const struct luaL_Reg wdg_meths[] =
{ WDG_METHS, {NULL, NULL} };