diff options
Diffstat (limited to 'client/widgets/metawidget.cc')
-rw-r--r-- | client/widgets/metawidget.cc | 115 |
1 files changed, 81 insertions, 34 deletions
diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc index 5f53153..91c62ec 100644 --- a/client/widgets/metawidget.cc +++ b/client/widgets/metawidget.cc @@ -29,6 +29,8 @@ #include <QHBoxLayout> #include <QVBoxLayout> +#include <QMessageBox> + #include "widgetbuilder.h" #include "formatparser.h" @@ -38,37 +40,21 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { setCommonAttributes(this, node); - - QDomElement elem = node.toElement(); - if(elem.hasAttribute("layout")) { - if(elem.attribute("layout") == "hbox") { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } else if (elem.attribute("layout") == "vbox") { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - } - } else { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } - - layout()->setContentsMargins(0,0,0,0); + setCommonLayout(this, node); + QDomElement elem = node.toElement(); + storechildren = elem.attribute("storechildren", "false") == "true"; + + // Create children QDomNodeList children = node.childNodes(); - for (int i=0; i<children.count();i++) { QDomNode child = children.at(i); - widgets += widgetBuilder(child, this, macrowindow); - } - macrowindow->addAuxWidgets(widgets); - - /* // This is done later - if(elem.hasAttribute("value")) { - setValue(elem.attribute("value")); + widgets += widgetBuilder(child, this, macrowindow, false); } - */ + if(storechildren) macrowindow->addWidgets(widgets); + else macrowindow->addAuxWidgets(widgets); + // Setup format string if(elem.hasAttribute("format")) { format = elem.attribute("format"); } else { @@ -81,19 +67,18 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow) } } - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); + // Connect all children wasChanged signal, to catch changes. + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + w->connectFrom(SIGNAL(wasChanged()), this, SLOT(changed())); + i++; } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - - layout()->setContentsMargins(0,0,0,0); } void MetaWidget::changed() { + emit wasChanged(); } QString MetaWidget::getValue() @@ -101,7 +86,7 @@ QString MetaWidget::getValue() return format_parser(format, widgets); } -void MetaWidget::setValue(QString /*values*/) +void MetaWidget::setValue(QString, QString) { // Nothing reasonable we can do here. } @@ -115,3 +100,65 @@ void MetaWidget::disable() { setEnabled(false); } + +bool MetaWidget::isValid() +{ + // If children are stored they will validate themselves. + if(!storechildren) { + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(w->isValid() == false) { + QMessageBox::critical(NULL, "Fejl", + "Et af inputfelterne (" + w->getName() + + ") er ikke udfyldt korrekt, prøv igen.\n" + , QMessageBox::Ok); + return false; + } + i++; + } + } + + return regexpValidator() && luaValidator(); +} + +void MetaWidget::connectFrom(const char *signal, + const QObject *receiver, const char *method) +{ + connect(this, signal, receiver, method); +} + +void MetaWidget::connectTo(const QObject *sender, const char *signal, + const char *method) +{ + connect(sender, signal, this, method); +} + +bool MetaWidget::setKeyboardFocus() +{ + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(w->setKeyboardFocus()) return true; + i++; + } + return false; +} + +void MetaWidget::reset() +{ + // If children are stored they will be reset individually. + if(!storechildren) { + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + w->reset(); + i++; + } + } +} + +void MetaWidget::setVisibility(bool visible) +{ + setVisible(visible); +} |