diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor.cc | 7 | ||||
-rw-r--r-- | editor/toolbox.cc | 17 | ||||
-rw-r--r-- | editor/toolbox.h | 9 | ||||
-rw-r--r-- | editor/widget.cc | 129 | ||||
-rw-r--r-- | editor/widget.h | 4 | ||||
-rw-r--r-- | editor/widgets.xml | 2 |
6 files changed, 118 insertions, 50 deletions
diff --git a/editor/editor.cc b/editor/editor.cc index e7d8781..1de16a1 100644 --- a/editor/editor.cc +++ b/editor/editor.cc @@ -67,16 +67,17 @@ int main(int argc, char *argv[]) n = n.nextSibling(); } - Toolbox toolbox(docElem); + MacroWindow macrowindow(node); + Toolbox toolbox(docElem, ¯owindow); + propertieseditor = new PropertiesEditor(); + toolbox.move(OFFSET_X, OFFSET_Y); toolbox.show(); - MacroWindow macrowindow(node); macrowindow.resize(400, 300); macrowindow.move(toolbox.width() + OFFSET_X + SPACING, OFFSET_Y); macrowindow.show(); - propertieseditor = new PropertiesEditor(); propertieseditor->setProperties(¯owindow); propertieseditor->move(macrowindow.width() + toolbox.width() + OFFSET_X + 2 * SPACING, OFFSET_Y); propertieseditor->show(); diff --git a/editor/toolbox.cc b/editor/toolbox.cc index 57c2ad1..e1983f1 100644 --- a/editor/toolbox.cc +++ b/editor/toolbox.cc @@ -28,12 +28,21 @@ #include <QVBoxLayout> #include "tool.h" +#include "widget.h" +#include <QPushButton> -Toolbox::Toolbox(QDomNode &node) +Toolbox::Toolbox(QDomNode &node, MacroWindow *macrowindow) : QDialog() { setLayout(new QVBoxLayout()); + this->macrowindow = macrowindow; + + QPushButton *btn_toxml = new QPushButton("save"); + connect(btn_toxml, SIGNAL(clicked()), this, SLOT(toXml())); + + layout()->addWidget(btn_toxml); + QDomNode n = node.firstChild(); while(!n.isNull()) { QDomElement e = n.toElement(); @@ -44,3 +53,9 @@ Toolbox::Toolbox(QDomNode &node) n = n.nextSibling(); } } + +void Toolbox::toXml() +{ + Widget *w = macrowindow; + printf("XML:\n%s\n", w->toXml("").toStdString().c_str()); +} diff --git a/editor/toolbox.h b/editor/toolbox.h index a74293a..66e77d1 100644 --- a/editor/toolbox.h +++ b/editor/toolbox.h @@ -29,11 +29,18 @@ #include <QDialog> #include <QDomNode> +#include "macrowindow.h" class Toolbox : public QDialog { Q_OBJECT public: - Toolbox(QDomNode &node); + Toolbox(QDomNode &node, MacroWindow *macrowindow); + +public slots: + void toXml(); + +private: + MacroWindow *macrowindow; }; #endif/*__PRACRO_TOOLBOX_H__*/ 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; } diff --git a/editor/widget.h b/editor/widget.h index 20baef9..eda50b5 100644 --- a/editor/widget.h +++ b/editor/widget.h @@ -38,10 +38,8 @@ Q_OBJECT public: Widget(QDomNode &node); - QString type; - void setValue(QString name, QString value); - + QString toXml(QString tabs); QDomElement elem; protected: diff --git a/editor/widgets.xml b/editor/widgets.xml index e1ed490..e10003e 100644 --- a/editor/widgets.xml +++ b/editor/widgets.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <widgets> <widget name="label" caption="" border="false"/> - <widget name="checkbox" value="true"/> + <widget name="checkbox" value="false" caption=""/> <widget name="button" caption="ok"/> <widget name="lineedit" value=""/> <widget name="textedit" value=""/> |