summaryrefslogtreecommitdiff
path: root/client/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets')
-rw-r--r--client/widgets/checkbox.cc7
-rw-r--r--client/widgets/checkbox.h5
-rw-r--r--client/widgets/combobox.cc2
-rw-r--r--client/widgets/combobox.h3
-rw-r--r--client/widgets/frame.cc2
-rw-r--r--client/widgets/frame.h3
-rw-r--r--client/widgets/groupbox.cc2
-rw-r--r--client/widgets/groupbox.h3
-rw-r--r--client/widgets/label.cc2
-rw-r--r--client/widgets/label.h8
-rw-r--r--client/widgets/lineedit.cc25
-rw-r--r--client/widgets/lineedit.h8
-rw-r--r--client/widgets/listbox.cc2
-rw-r--r--client/widgets/listbox.h3
-rw-r--r--client/widgets/pushbutton.cc2
-rw-r--r--client/widgets/pushbutton.h4
-rw-r--r--client/widgets/radiobutton.cc2
-rw-r--r--client/widgets/radiobutton.h3
-rw-r--r--client/widgets/radiobuttons.cc2
-rw-r--r--client/widgets/radiobuttons.h3
-rw-r--r--client/widgets/textedit.cc24
-rw-r--r--client/widgets/textedit.h11
-rw-r--r--client/widgets/widget.cc40
-rw-r--r--client/widgets/widget.h19
-rw-r--r--client/widgets/window.cc2
-rw-r--r--client/widgets/window.h3
26 files changed, 89 insertions, 101 deletions
diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc
index 222d879..2ce3802 100644
--- a/client/widgets/checkbox.cc
+++ b/client/widgets/checkbox.cc
@@ -26,7 +26,7 @@
*/
#include "checkbox.h"
-CheckBox::CheckBox(QDomNode node)
+CheckBox::CheckBox(QDomNode &node)
: QCheckBox(), Widget(node)
{
QDomElement elem = node.toElement();
@@ -63,3 +63,8 @@ QString CheckBox::getValue()
if(checkState() == Qt::Checked) return "true";
return "false";
}
+
+bool CheckBox::isValid()
+{
+ return true;
+}
diff --git a/client/widgets/checkbox.h b/client/widgets/checkbox.h
index c57f235..228723e 100644
--- a/client/widgets/checkbox.h
+++ b/client/widgets/checkbox.h
@@ -33,9 +33,10 @@
class CheckBox : public QCheckBox, public Widget
{
-
public:
- CheckBox(QDomNode node);
+ CheckBox(QDomNode &node);
+
+ bool isValid();
public slots:
QString getValue();
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc
index 799b05d..480cada 100644
--- a/client/widgets/combobox.cc
+++ b/client/widgets/combobox.cc
@@ -27,7 +27,7 @@
#include "combobox.h"
#include <QDomNodeList>
-ComboBox::ComboBox(QDomNode node)
+ComboBox::ComboBox(QDomNode &node)
: QComboBox(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/combobox.h b/client/widgets/combobox.h
index 06d3856..ab92e64 100644
--- a/client/widgets/combobox.h
+++ b/client/widgets/combobox.h
@@ -33,9 +33,8 @@
class ComboBox : public QComboBox, public Widget
{
-
public:
- ComboBox(QDomNode);
+ ComboBox(QDomNode &node);
public slots:
bool isValid();
diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc
index 37f035e..e2227cc 100644
--- a/client/widgets/frame.cc
+++ b/client/widgets/frame.cc
@@ -28,7 +28,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
-Frame::Frame(QDomNode node)
+Frame::Frame(QDomNode &node)
: QFrame(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/frame.h b/client/widgets/frame.h
index ff1a9f2..80aeded 100644
--- a/client/widgets/frame.h
+++ b/client/widgets/frame.h
@@ -33,9 +33,8 @@
class Frame : public QFrame, public Widget
{
-
public:
- Frame(QDomNode node);
+ Frame(QDomNode &node);
public slots:
QString getValue();
diff --git a/client/widgets/groupbox.cc b/client/widgets/groupbox.cc
index a2a818c..dba97cd 100644
--- a/client/widgets/groupbox.cc
+++ b/client/widgets/groupbox.cc
@@ -28,7 +28,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
-GroupBox::GroupBox(QDomNode node)
+GroupBox::GroupBox(QDomNode &node)
: QGroupBox(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/groupbox.h b/client/widgets/groupbox.h
index aa51aea..0cc1890 100644
--- a/client/widgets/groupbox.h
+++ b/client/widgets/groupbox.h
@@ -33,9 +33,8 @@
class GroupBox : public QGroupBox, public Widget
{
-
public:
- GroupBox(QDomNode node);
+ GroupBox(QDomNode &node);
public slots:
QString getValue();
diff --git a/client/widgets/label.cc b/client/widgets/label.cc
index 8b6c19b..95d53ac 100644
--- a/client/widgets/label.cc
+++ b/client/widgets/label.cc
@@ -27,7 +27,7 @@
#include "label.h"
#include <stdio.h>
-Label::Label(QDomNode node)
+Label::Label(QDomNode &node)
: QLabel(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/label.h b/client/widgets/label.h
index edf5cb8..9c539e7 100644
--- a/client/widgets/label.h
+++ b/client/widgets/label.h
@@ -34,16 +34,12 @@
class Label : public QLabel, public Widget
{
-
Q_OBJECT
-
public:
- Label(QDomNode node);
+ Label(QDomNode &node);
public slots:
QString getValue();
-
-private:
-
};
+
#endif/*__PRACRO_LABEL_H__*/
diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc
index 83f8d3e..26c2760 100644
--- a/client/widgets/lineedit.cc
+++ b/client/widgets/lineedit.cc
@@ -27,25 +27,20 @@
#include "lineedit.h"
#include <stdio.h>
-LineEdit::LineEdit(QDomNode node)
+LineEdit::LineEdit(QDomNode &node)
: QLineEdit(), Widget(node)
{
QDomElement elem = node.toElement();
if(elem.hasAttribute("width")) {
- //resize(elem.attribute("width").toInt(), height());
setMinimumWidth(elem.attribute("width").toInt());
}
if(elem.hasAttribute("height")) {
- //resize(width(), elem.attribute("height").toInt());
setMinimumHeight(elem.attribute("height").toInt());
}
- if(elem.hasAttribute("regexp")) {
- rx = QRegExp(elem.attribute("regexp"));
- connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed(QString)));
- }
+ connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed()));
if(elem.hasAttribute("value")) {
setText(elem.attribute("value"));
@@ -56,29 +51,19 @@ LineEdit::LineEdit(QDomNode node)
}
}
-void LineEdit::changed(QString new_text)
+void LineEdit::changed()
{
QPalette palette;
- if(rx.exactMatch(new_text)) {
+ if(regexpValidator()) {
// valid string
palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- valid = true;
} else {
// invalid string
palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- valid = false;
}
- setPalette(palette);
-}
-bool LineEdit::isValid()
-{
- if(rx.exactMatch(text())) {
- return true;
- } else {
- return false;
- }
+ setPalette(palette);
}
QString LineEdit::getValue()
diff --git a/client/widgets/lineedit.h b/client/widgets/lineedit.h
index 99574c2..faea440 100644
--- a/client/widgets/lineedit.h
+++ b/client/widgets/lineedit.h
@@ -34,19 +34,15 @@
class LineEdit : public QLineEdit, public Widget
{
-
Q_OBJECT
-
public:
- LineEdit(QDomNode node);
- bool isValid();
+ LineEdit(QDomNode &node);
public slots:
- void changed(QString text);
+ void changed();
QString getValue();
private:
- QRegExp rx;
bool valid;
};
diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc
index edaa5a2..c7151cc 100644
--- a/client/widgets/listbox.cc
+++ b/client/widgets/listbox.cc
@@ -27,7 +27,7 @@
#include "listbox.h"
#include <QListWidgetItem>
-ListBox::ListBox(QDomNode node)
+ListBox::ListBox(QDomNode &node)
: QListWidget(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/listbox.h b/client/widgets/listbox.h
index 658847e..e41838b 100644
--- a/client/widgets/listbox.h
+++ b/client/widgets/listbox.h
@@ -33,9 +33,8 @@
class ListBox : public QListWidget, public Widget
{
-
public:
- ListBox(QDomNode);
+ ListBox(QDomNode &node);
public slots:
bool isValid();
diff --git a/client/widgets/pushbutton.cc b/client/widgets/pushbutton.cc
index 1fa7589..d674162 100644
--- a/client/widgets/pushbutton.cc
+++ b/client/widgets/pushbutton.cc
@@ -27,7 +27,7 @@
#include "pushbutton.h"
#include <stdio.h>
-PushButton::PushButton(QDomNode node)
+PushButton::PushButton(QDomNode &node)
: QPushButton(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/pushbutton.h b/client/widgets/pushbutton.h
index ce6769b..42e3156 100644
--- a/client/widgets/pushbutton.h
+++ b/client/widgets/pushbutton.h
@@ -34,11 +34,9 @@
class PushButton : public QPushButton, public Widget
{
-
Q_OBJECT
-
public:
- PushButton(QDomNode node);
+ PushButton(QDomNode &node);
QString field;
public slots:
diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc
index 1a4287f..6de030d 100644
--- a/client/widgets/radiobutton.cc
+++ b/client/widgets/radiobutton.cc
@@ -27,7 +27,7 @@
#include "radiobutton.h"
#include <QRadioButton>
-RadioButton::RadioButton(QDomNode node, bool radio_bool)
+RadioButton::RadioButton(QDomNode &node, bool radio_bool)
: QRadioButton()
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/radiobutton.h b/client/widgets/radiobutton.h
index c2b7264..66c971e 100644
--- a/client/widgets/radiobutton.h
+++ b/client/widgets/radiobutton.h
@@ -35,9 +35,8 @@
class RadioButton : public QRadioButton
{
-
public:
- RadioButton(QDomNode, bool);
+ RadioButton(QDomNode &node, bool radio_bool);
public slots:
QString getValue();
diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc
index a6218d2..8c87a0c 100644
--- a/client/widgets/radiobuttons.cc
+++ b/client/widgets/radiobuttons.cc
@@ -30,7 +30,7 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
-RadioButtons::RadioButtons(QDomNode node)
+RadioButtons::RadioButtons(QDomNode &node)
: QFrame(), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/radiobuttons.h b/client/widgets/radiobuttons.h
index 4ee447b..454d159 100644
--- a/client/widgets/radiobuttons.h
+++ b/client/widgets/radiobuttons.h
@@ -36,9 +36,8 @@
class RadioButtons : public QFrame, public Widget
{
-
public:
- RadioButtons(QDomNode);
+ RadioButtons(QDomNode &node);
public slots:
bool isValid();
diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc
index 28ca010..e217cc6 100644
--- a/client/widgets/textedit.cc
+++ b/client/widgets/textedit.cc
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <QPalette>
-TextEdit::TextEdit(QDomNode node)
+TextEdit::TextEdit(QDomNode &node)
: QTextEdit(), Widget(node)
{
//setAutoFillBackground(true); /* Default is false, which disables background
@@ -37,23 +37,19 @@ TextEdit::TextEdit(QDomNode node)
QDomElement elem = node.toElement();
if(elem.hasAttribute("width")) {
- //resize(elem.attribute("width").toInt(), height());
setMinimumWidth(elem.attribute("width").toInt());
}
if(elem.hasAttribute("height")) {
- //resize(width(), elem.attribute("height").toInt());
setMinimumHeight(elem.attribute("height").toInt());
}
- if(elem.hasAttribute("regexp")) {
- rx = QRegExp(elem.attribute("regexp"));
- connect(this, SIGNAL(textChanged()), this, SLOT(changed()));
- }
+ connect(this, SIGNAL(textChanged()), this, SLOT(changed()));
if(elem.hasAttribute("value")) {
setText(elem.attribute("value"));
} else {
+ setText(" ");
setText("");
}
}
@@ -62,26 +58,14 @@ void TextEdit::changed()
{
QPalette palette;
- if(rx.exactMatch(QTextEdit::toPlainText())) {
+ if(regexpValidator()) {
// valid string
palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- valid = true;
} else {
// invalid string
palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- valid = false;
}
setPalette(palette);
- //printf("%s\n", text.toStdString().c_str());
-}
-
-bool TextEdit::isValid()
-{
- if(rx.exactMatch(QTextEdit::toPlainText())) {
- return true;
- } else {
- return false;
- }
}
QString TextEdit::getValue()
diff --git a/client/widgets/textedit.h b/client/widgets/textedit.h
index 0ddb15d..466af0f 100644
--- a/client/widgets/textedit.h
+++ b/client/widgets/textedit.h
@@ -34,20 +34,13 @@
class TextEdit : public QTextEdit, public Widget
{
-
Q_OBJECT
-
public:
- TextEdit(QDomNode node);
- bool isValid();
+ TextEdit(QDomNode &node);
public slots:
void changed();
QString getValue();
-
-private:
- QRegExp rx;
- bool valid;
-
};
+
#endif/*__PRACRO_TEXTEDIT_H__*/
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index 5a433e9..b128a53 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -26,20 +26,31 @@
*/
#include "widget.h"
-//Widget::Widget(QString parent_name, QDomNode node)
-Widget::Widget(QDomNode node)
+Widget::Widget(QDomNode &node)
{
QDomElement elem = node.toElement();
if(elem.hasAttribute("name")) {
- //if(parent_name != "")
- // widget_name = parent_name + "." + elem.attribute("name");
- //else
- widget_name = elem.attribute("name");
+ widget_name = elem.attribute("name");
} else {
printf("XML ERROR!! Unnamed widget of type: %s\n",
elem.tagName().toStdString().c_str());
}
+
+ if(elem.hasAttribute("lua_validator")) {
+ // lua_validator = elem.attribute("lua_validator");
+ hasluavalidator = true;
+ } else {
+ hasluavalidator = false;
+ }
+
+ if(elem.hasAttribute("regexp")) {
+ rx = QRegExp(elem.attribute("regexp"));
+ hasregexpvalidator = true;
+ } else {
+ hasregexpvalidator = false;
+ }
+
}
QString Widget::getName()
@@ -47,7 +58,22 @@ QString Widget::getName()
return widget_name;
}
+QString Widget::getValue()
+{
+ return "";
+}
+
bool Widget::isValid()
{
- return true;
+ return regexpValidator() && luaValidator();
+}
+
+bool Widget::regexpValidator()
+{
+ return !hasregexpvalidator || rx.exactMatch(getValue());
+}
+
+bool Widget::luaValidator()
+{
+ return !hasluavalidator || true;
}
diff --git a/client/widgets/widget.h b/client/widgets/widget.h
index 1f92ea9..89610bb 100644
--- a/client/widgets/widget.h
+++ b/client/widgets/widget.h
@@ -29,18 +29,29 @@
#include <QString>
#include <QDomNode>
+#include <QRegExp>
-class Widget {
+#include "lua.h"
+class Widget {
public:
- //Widget(QString parent_name, QDomNode node);
- Widget(QDomNode node);
+ Widget(QDomNode &node);
virtual ~Widget(){}
- virtual QString getValue() = 0;
+ virtual QString getValue();
virtual bool isValid();
QString getName();
protected:
QString widget_name;
+
+ bool luaValidator();
+ bool regexpValidator();
+
+private:
+ QRegExp rx;
+ LUA *lua;
+ bool hasregexpvalidator;
+ bool hasluavalidator;
};
+
#endif/*__PRACRO_WIDGET_H__*/
diff --git a/client/widgets/window.cc b/client/widgets/window.cc
index 8cb39ab..5d15733 100644
--- a/client/widgets/window.cc
+++ b/client/widgets/window.cc
@@ -28,7 +28,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
-Window::Window(QDomNode node)
+Window::Window(QDomNode &node)
: QWidget(NULL), Widget(node)
{
QDomElement elem = node.toElement();
diff --git a/client/widgets/window.h b/client/widgets/window.h
index e15a715..93c48ab 100644
--- a/client/widgets/window.h
+++ b/client/widgets/window.h
@@ -33,9 +33,8 @@
class Window : public QWidget, public Widget
{
-
public:
- Window(QDomNode node);
+ Window(QDomNode &node);
public slots:
QString getValue();