From d9338083192084613e5530b02710b796252d342b Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 12 Aug 2010 10:57:04 +0000 Subject: New scripting system part2. --- client/widgets/altcombobox.cc | 148 ++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 77 deletions(-) (limited to 'client/widgets/altcombobox.cc') diff --git a/client/widgets/altcombobox.cc b/client/widgets/altcombobox.cc index 352cd19..66eb444 100644 --- a/client/widgets/altcombobox.cc +++ b/client/widgets/altcombobox.cc @@ -26,33 +26,39 @@ */ #include "altcombobox.h" +#include #include #include +#include #include "common.h" #include "widgetbuilder.h" - -#include #include "multilist.h" +#include "macrowindow.h" AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) - : QFrame(), Widget(node, macrowindow) + : Widget(node, macrowindow) { + frame = new QFrame(); + widget = frame; + + hideChildren = true; + innerwidget = NULL; - setCommonAttributes(this, node); - setCommonLayout(this, node); + setCommonAttributes(frame, node); + setCommonLayout(frame, node); combobox = new ComboBox(node, macrowindow); - layout()->addWidget(combobox); - combobox->show(); + frame->layout()->addWidget(combobox->qwidget()); + combobox->qwidget()->show(); altframerepl = new QFrame(); QHBoxLayout *l = new QHBoxLayout(); altframerepl->setLayout(l); l->addStretch(); altframe = new QFrame(); - layout()->addWidget(altframe); + frame->layout()->addWidget(altframe); QVector< Widget* > widgets; @@ -67,13 +73,15 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) if(item.hasAttribute("value")) { altvalue = item.attribute("value"); } else { - printf("ERROR: altitem tag is missing the value attribute, in altcombobox!\n"); + printf("ERROR: altitem tag is missing the value attribute, " + "in altcombobox!\n"); } if(item.hasAttribute("innerwidget")) { iwname = item.attribute("innerwidget"); } else { - printf("ERROR: altitem tag is missing the innerwidget attribute, in altcombobox!\n"); + printf("ERROR: altitem tag is missing the innerwidget attribute, " + "in altcombobox!\n"); } if(item.hasAttribute("layout")) { @@ -89,72 +97,70 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) altframe->setLayout(layout); } - QDomNodeList children = item.childNodes(); - for(int i = 0; i < children.count(); i++) { - QDomNode child = children.at(i); - widgets += widgetBuilder(child, altframe, macrowindow, false); - } + addChildren(item); + } } - macrowindow->addAuxWidgets(widgets); - /* - QVector< Widget* >::iterator ws = widgets.begin(); - while(ws != widgets.end()) { - if((*ws)->getName() == iwname) innerwidget = *ws; - ws++; - } - */ - innerwidget = macrowindow->getWidget(iwname); + innerwidget = findWidget(iwname, true); if(innerwidget == NULL) { - printf("ERROR: Inner Widget %s not found (in multilist)!\n", + printf("ERROR: Inner Widget %s not found (in altcombobox)!\n", iwname.toStdString().c_str()); } // To detect if the altvalue has been selected: - connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(onValueChange(int))); - connect(combobox, SIGNAL(editTextChanged(const QString&)), this, SLOT(onValueChange(const QString&))); + connect(combobox->qwidget(), SIGNAL(currentIndexChanged(int)), + this, SLOT(onValueChange(int))); + connect(combobox->qwidget(), SIGNAL(editTextChanged(const QString&)), + this, SLOT(onValueChange(const QString&))); // To react to changes in any of the children: connect(combobox, SIGNAL(wasChanged()), this, SLOT(onChildChange())); - innerwidget->connectFrom(SIGNAL(wasChanged()), this, SLOT(onChildChange())); + if(innerwidget) + connect(innerwidget, SIGNAL(wasChanged()), this, SLOT(onChildChange())); - layout()->setContentsMargins(0,0,0,0); + frame->layout()->setContentsMargins(0,0,0,0); altframe->layout()->setContentsMargins(0,0,0,0); - show(); // Force altframe to get resized to its real size. + frame->show(); // Force altframe to get resized to its real size. altframerepl->setFixedHeight(altframe->height()); } +AltComboBox::~AltComboBox() +{ + // delete frame; +} -bool AltComboBox::isValid() +bool AltComboBox::preValid() { - if(!combobox->isValid()) return false; + if(!combobox->valid()) return false; - if(innerwidget && combobox->getValue() == altvalue) { - if(!innerwidget->isValid()) return false; + if(innerwidget && combobox->value() == altvalue) { + if(!innerwidget->valid()) return false; } - return regexpValidator() && luaValidator(); + return true; } -QString AltComboBox::getValue() +QString AltComboBox::value() { - if(combobox->getValue() == altvalue) { - if(innerwidget) return innerwidget->getValue(); + if(combobox->value() == altvalue) { + if(innerwidget) return innerwidget->value(); else return ""; } else { - return combobox->getValue(); + return combobox->value(); } } void AltComboBox::setValue(QString value, QString source) { - // if(isUserSource(source)) emit wasChanged(); // No need for this, it will be enitted by the children. + // No need for this, it will be enitted by the children. + // if(isUserSource(source)) emit wasChanged(); - if(combobox->findData(value) != -1) { + QComboBox *cmb = (QComboBox*)combobox->qwidget(); + if(cmb->findData(value) != -1) { combobox->setValue(value, source); @@ -171,63 +177,39 @@ void AltComboBox::setValue(QString value, QString source) void AltComboBox::onValueChange(int index) { - if(combobox->itemData(index).toString() == altvalue) { + QComboBox *cmb = (QComboBox*)combobox->qwidget(); + if(cmb->itemData(index).toString() == altvalue) { // altframe->setEnabled(true); altframerepl->setVisible(false); - layout()->removeWidget(altframerepl); + frame->layout()->removeWidget(altframerepl); - layout()->addWidget(altframe); + frame->layout()->addWidget(altframe); altframe->setVisible(true); } else { // altframe->setEnabled(false); altframe->setVisible(false); - layout()->removeWidget(altframe); + frame->layout()->removeWidget(altframe); - layout()->addWidget(altframerepl); + frame->layout()->addWidget(altframerepl); altframerepl->setVisible(true); } } void AltComboBox::onValueChange(const QString &text) { - onValueChange(combobox->findText(text)); -} - -void AltComboBox::enable() -{ - setEnabled(true); -} - -void AltComboBox::disable() -{ - setEnabled(false); -} - -bool AltComboBox::isDisabled() -{ - return isEnabled() == false; + QComboBox *cmb = (QComboBox*)combobox->qwidget(); + onValueChange(cmb->findText(text)); } void AltComboBox::onChildChange() { emit wasChanged(); -} - -void AltComboBox::connectFrom(const char *signal, - const QObject *receiver, const char *method) -{ - connect(this, signal, receiver, method); -} - -void AltComboBox::connectTo(const QObject *sender, const char *signal, - const char *method) -{ - connect(sender, signal, this, method); + eventOnChange(); } bool AltComboBox::setKeyboardFocus() { - if(combobox->getValue() == altvalue) { + if(combobox->value() == altvalue) { if(innerwidget) return innerwidget->setKeyboardFocus(); } @@ -235,7 +217,19 @@ bool AltComboBox::setKeyboardFocus() return true; } -void AltComboBox::setVisibility(bool visible) +void AltComboBox::setWdgValid(bool valid) { - setVisible(visible); + QPalette palette; + + if(valid) { + // valid string + palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + } else { + // invalid string + palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); + } + + frame->setPalette(palette); + combobox->qwidget()->setPalette(palette); + if(innerwidget) innerwidget->setWdgValid(valid); } -- cgit v1.2.3