summaryrefslogtreecommitdiff
path: root/editor/widget.cc
diff options
context:
space:
mode:
authordeva <deva>2008-07-14 09:32:45 +0000
committerdeva <deva>2008-07-14 09:32:45 +0000
commit48f92d13fa3a42007a068baf1d63f418b22a2b3e (patch)
treed5a2f314b6da4162e5a45afcf5473529152da288 /editor/widget.cc
parent0ca2a008e3d6f2578246326ba4180cf21d8064ca (diff)
Made the setValue actually set the values in the GUI. Fixed resize problem when labels got text filled into them. Added a simple toXml method to dunp xml from the contructed gui to stdout.
Diffstat (limited to 'editor/widget.cc')
-rw-r--r--editor/widget.cc129
1 files changed, 88 insertions, 41 deletions
diff --git a/editor/widget.cc b/editor/widget.cc
index cc60f9c..cb006f9 100644
--- a/editor/widget.cc
+++ b/editor/widget.cc
@@ -73,7 +73,7 @@ Widget::Widget(QDomNode &node)
if(elem.hasAttribute("name")) {
if(elem.attribute("name") == "combo") widget = new QComboBox();
else if(elem.attribute("name") == "label") widget = new QLabel();
- else if(elem.attribute("name") == "button") widget = new QPushButton("OK");
+ else if(elem.attribute("name") == "button") widget = new QPushButton();
else if(elem.attribute("name") == "checkbox") widget = new QCheckBox();
else if(elem.attribute("name") == "lineedit") widget = new QLineEdit();
else if(elem.attribute("name") == "textedit") widget = new QTextEdit();
@@ -86,8 +86,78 @@ Widget::Widget(QDomNode &node)
setSizePolicy(widget->sizePolicy());
}
+void Widget::paintEvent(QPaintEvent *)
+{
+ if(widget->minimumSizeHint().isValid()) setMinimumSize(widget->minimumSizeHint());
+
+ widget->resize(width(), height());
+
+ QPixmap pixmap = QPixmap::grabWidget(widget, 0, 0);
+
+ QPainter p(this);
+ int y = (height() - pixmap.height()) / 2;
+ p.drawPixmap(0, y, pixmap);
+
+ if(iscontainer) {
+
+ p.setPen(Qt::blue);
+ p.drawRect(0, 0, width()-1, height()-1);
+ p.setPen(QColor(150,150,200));
+ if(orientation == Qt::Vertical) {
+ p.drawLine(4, 2, 2, 4);
+ p.drawLine(4, 2, 6, 4);
+ p.drawLine(4, 2, 4, 12);
+ p.drawLine(4, 12, 2, 10);
+ p.drawLine(4, 12, 6, 10);
+ } else {
+ p.drawLine(2, 4, 4, 2);
+ p.drawLine(2, 4, 4, 6);
+ p.drawLine(2, 4 ,12, 4);
+ p.drawLine(12, 4, 10, 2);
+ p.drawLine(12, 4, 10, 6);
+ }
+ } else {
+ p.setPen(QColor(128, 128, 128, 128));
+ p.drawText(width() / 2 - 20, height() / 2 + 5, elem.attribute("name", "Widget"));
+ }
+}
+
void Widget::setValue(QString name, QString value)
{
+ if(iscontainer == false && elem.hasAttribute("name")) {
+ if(elem.attribute("name") == "combo") {
+ QComboBox *combo = ((QComboBox*)widget);
+ if(name == "value") {
+ while(combo->count()) combo->removeItem(0);
+ combo->addItem(value);
+ combo->setCurrentIndex(0);
+ }
+ repaint();
+ } else if(elem.attribute("name") == "label") {
+ QLabel *label = ((QLabel*)widget);
+ if(name == "caption") label->setText(value);
+ repaint();
+ } else if(elem.attribute("name") == "button") {
+ QPushButton *button = ((QPushButton*)widget);
+ if(name == "caption") button->setText(value);
+ repaint();
+ } else if(elem.attribute("name") == "checkbox") {
+ QCheckBox *checkbox = ((QCheckBox*)widget);
+ if(name == "caption") checkbox->setText(value);
+ if(name == "value") checkbox->setChecked(value == "true");
+ repaint();
+ } else if(elem.attribute("name") == "lineedit") {
+ QLineEdit *lineedit = ((QLineEdit*)widget);
+ if(name == "value") lineedit->setText(value);
+ repaint();
+ } else if(elem.attribute("name") == "textedit") {
+ QTextEdit *textedit = ((QTextEdit*)widget);
+ if(name == "value") textedit->setPlainText(value);
+ repaint();
+ } else {
+ ((QLabel*)widget)->setText("Unknown attribute " + name + ", set to " + value);
+ }
+ }
elem.attributeNode(name).setValue(value);
}
@@ -257,51 +327,28 @@ QWidget *Widget::findWidget(QPoint pos)
return w;
}
-void Widget::paintEvent(QPaintEvent *)
+QString Widget::toXml(QString tabs)
{
- int w = width();
- int h = height();
- /*
- if(widget->sizePolicy().controlType() == QSizePolicy::LineEdit ||
- widget->sizePolicy().controlType() == QSizePolicy::PushButton ||
- widget->sizePolicy().controlType() == QSizePolicy::ComboBox ||
- widget->sizePolicy().controlType() == QSizePolicy::CheckBox) {
- // w > widget->sizeHint().width()) w = widget->sizeHint().width();
- if(h > widget->sizeHint().height()) h = widget->sizeHint().height();
- }
- */
- widget->resize(w,h);
- // layout()->addWidget(widget);
- QPixmap pixmap = QPixmap::grabWidget(widget, 0, 0);
- // layout()->removeWidget(widget);
- // widget->setVisible(false);
+ QString xml;
- QPainter p(this);
- int y = (height() - pixmap.height()) / 2;
- p.drawPixmap(0,y,pixmap);
+ xml = tabs + "<" + elem.attribute("name");
+
+ QDomNamedNodeMap map = elem.attributes();
+ for(size_t i = 0; i < map.length(); i++) {
+ QDomAttr attr = map.item(i).toAttr();
+ xml += " " + attr.name() + "=\"" + attr.value() + "\"";
+ }
if(iscontainer) {
-
- p.setPen(Qt::blue);
- p.drawRect(0, 0, width()-1, height()-1);
- p.setPen(QColor(150,150,200));
- if(orientation == Qt::Vertical) {
- p.drawLine(4, 2, 2, 4);
- p.drawLine(4, 2, 6, 4);
- p.drawLine(4, 2, 4, 12);
- p.drawLine(4, 12, 2, 10);
- p.drawLine(4, 12, 6, 10);
- } else {
- p.drawLine(2, 4, 4, 2);
- p.drawLine(2, 4, 4, 6);
- p.drawLine(2, 4 ,12, 4);
- p.drawLine(12, 4, 10, 2);
- p.drawLine(12, 4, 10, 6);
+ xml += ">\n";
+ for(int i = 0; i < layout()->count(); i++) {
+ Widget *child = (Widget*)layout()->itemAt(i)->widget();
+ xml += child->toXml(" " + tabs);
}
- //p.setPen(QColor(128, 128, 128, 128));
- //p.drawText(0, 10, elem.attribute("name", "Container"));
+ xml += tabs + "</" + elem.attribute("name") + ">\n";
} else {
- p.setPen(QColor(128, 128, 128, 128));
- p.drawText(width() / 2 - 20, height() / 2 + 5, elem.attribute("name", "Widget"));
+ xml += "/>\n";
}
+
+ return xml;
}