From 22de7bf19fb6fcce8d11c0e01afdfafa2a8c00d6 Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 23 Jul 2007 07:40:05 +0000 Subject: porting widgets to use QDomNodes --- client/widgets/frame.cc | 5 +++-- client/widgets/frame.h | 3 ++- client/widgets/label.cc | 11 ++++++----- client/widgets/label.h | 3 ++- client/widgets/lineedit.cc | 19 ++++++++++--------- client/widgets/lineedit.h | 5 ++--- client/widgets/radiobutton.cc | 20 ++++++++++++++++++-- client/widgets/radiobutton.h | 3 ++- 8 files changed, 45 insertions(+), 24 deletions(-) (limited to 'client') diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc index 285619a..0ea7d25 100644 --- a/client/widgets/frame.cc +++ b/client/widgets/frame.cc @@ -26,9 +26,10 @@ */ #include "frame.h" -Frame::Frame(QWidget *parent, QString caption) : QGroupBox(parent) +Frame::Frame(QDomNode node) : QGroupBox() { - setTitle(caption); + QDomElement elem = node.toElement(); + setTitle(elem.attribute("caption")); } QString Frame::getValue() diff --git a/client/widgets/frame.h b/client/widgets/frame.h index 73bf704..f934269 100644 --- a/client/widgets/frame.h +++ b/client/widgets/frame.h @@ -29,12 +29,13 @@ #include "widget.h" #include +#include class Frame : public Widget, public QGroupBox { public: - Frame(QWidget *parent, QString caption); + Frame(QDomNode node); public slots: QString getValue(); diff --git a/client/widgets/label.cc b/client/widgets/label.cc index 377fd10..b30d1cb 100644 --- a/client/widgets/label.cc +++ b/client/widgets/label.cc @@ -27,15 +27,16 @@ #include "label.h" #include -Label::Label(QWidget *parent, QString text, QString align) : QLabel(parent) +Label::Label(QDomNode node) : QLabel(NULL) { - setText(text); + QDomElement elem = node.toElement(); + setText(elem.attribute("caption")); - if(align == "left") { + if(elem.attribute("align") == "left") { setAlignment(Qt::AlignLeft); - } else if (align == "center") { + } else if (elem.attribute("align") == "center") { setAlignment(Qt::AlignHCenter); - } else if (align == "right") { + } else if (elem.attribute("align") == "right") { setAlignment(Qt::AlignRight); } } diff --git a/client/widgets/label.h b/client/widgets/label.h index 3138ce1..78376dd 100644 --- a/client/widgets/label.h +++ b/client/widgets/label.h @@ -29,6 +29,7 @@ #include #include +#include class Label : public QLabel { @@ -36,7 +37,7 @@ class Label : public QLabel Q_OBJECT public: - Label(QWidget *parent, QString text, QString align); + Label(QDomNode node); public slots: diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 0a16947..686791d 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -27,16 +27,17 @@ #include "lineedit.h" #include -LineEdit::LineEdit(QWidget *parent, QString reg_exp) : QLineEdit(parent) +LineEdit::LineEdit(QDomNode node) : QLineEdit() { - widget_name = "widget_name"; - - rx = QRegExp(reg_exp); - //validator = new QRegExpValidator(rx, this); - //setValidator(validator); - changed(""); - + QDomElement elem = node.toElement(); + rx = QRegExp(elem.attribute("regexp")); connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed(QString))); + + if(elem.hasAttribute("value")) { + setText(elem.attribute("value")); + } else { + setText(""); + } } void LineEdit::changed(QString text) @@ -49,7 +50,7 @@ void LineEdit::changed(QString text) valid = true; } else { // invalid string - palette.setBrush(backgroundRole(), QBrush(QColor(220, 150, 150))); + palette.setBrush(backgroundRole(), QBrush(QColor(230, 200, 200))); valid = false; } setPalette(palette); diff --git a/client/widgets/lineedit.h b/client/widgets/lineedit.h index 45af6f3..247a562 100644 --- a/client/widgets/lineedit.h +++ b/client/widgets/lineedit.h @@ -30,7 +30,7 @@ #include "widget.h" #include #include -#include +#include class LineEdit : public QLineEdit, public Widget { @@ -38,7 +38,7 @@ class LineEdit : public QLineEdit, public Widget Q_OBJECT public: - LineEdit(QWidget *parent, QString reg_exp = "*"); + LineEdit(QDomNode node); bool isValid(); public slots: @@ -46,7 +46,6 @@ public slots: QString getValue(); private: - QValidator *validator; QRegExp rx; bool valid; diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc index cad1ebf..89f9f4f 100644 --- a/client/widgets/radiobutton.cc +++ b/client/widgets/radiobutton.cc @@ -26,9 +26,25 @@ */ #include "radiobutton.h" -RadioButton::RadioButton(QWidget *parent) : QRadioButton(parent) +RadioButton::RadioButton(QDomNode node) : QRadioButton() { - setText("Radio button"); + QDomElement elem = node.toElement(); + + if(elem.hasAttribute("caption")) { + setText(elem.attribute("caption")); + } else { + setText(""); + } + + if(elem.hasAttribute("value")) { + if(elem.attribute("value") == "true") { + setChecked(true); + } else if(elem.attribute("value") == "false") { + setChecked(false); + } + } else { + setChecked(false); + } } QString RadioButton::getValue() diff --git a/client/widgets/radiobutton.h b/client/widgets/radiobutton.h index 65a87c7..6239c3f 100644 --- a/client/widgets/radiobutton.h +++ b/client/widgets/radiobutton.h @@ -29,12 +29,13 @@ #include "widget.h" #include +#include class RadioButton : public Widget, public QRadioButton { public: - RadioButton(QWidget *parent); + RadioButton(QDomNode); public slots: QString getValue(); -- cgit v1.2.3