summaryrefslogtreecommitdiff
path: root/client/widgets/altcombobox.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets/altcombobox.cc')
-rw-r--r--client/widgets/altcombobox.cc82
1 files changed, 72 insertions, 10 deletions
diff --git a/client/widgets/altcombobox.cc b/client/widgets/altcombobox.cc
index 01fd36f..c68f816 100644
--- a/client/widgets/altcombobox.cc
+++ b/client/widgets/altcombobox.cc
@@ -33,6 +33,7 @@
#include "widgetbuilder.h"
#include <QObject>
+#include "multilist.h"
AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
: QFrame(), Widget(node, macrowindow)
@@ -45,7 +46,11 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
combobox = new ComboBox(node, macrowindow);
layout()->addWidget(combobox);
combobox->show();
-
+
+ altframerepl = new QFrame();
+ QHBoxLayout *l = new QHBoxLayout();
+ altframerepl->setLayout(l);
+ l->addStretch();
altframe = new QFrame();
layout()->addWidget(altframe);
@@ -87,7 +92,7 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
QDomNodeList children = item.childNodes();
for(int i = 0; i < children.count(); i++) {
QDomNode child = children.at(i);
- widgets += widgetBuilder(child, altframe, macrowindow);
+ widgets += widgetBuilder(child, altframe, macrowindow, false);
}
}
@@ -108,22 +113,31 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
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&)));
+ // To react to changes in any of the children:
+ connect(combobox, SIGNAL(wasChanged()), this, SLOT(onChildChange()));
+ innerwidget->connectFrom(SIGNAL(wasChanged()), this, SLOT(onChildChange()));
+
layout()->setContentsMargins(0,0,0,0);
altframe->layout()->setContentsMargins(0,0,0,0);
+
+ show(); // Force altframe to get resized to its real size.
+ altframerepl->setFixedHeight(altframe->height());
}
+
bool AltComboBox::isValid()
{
if(!combobox->isValid()) return false;
if(innerwidget && combobox->getValue() == altvalue) {
- return innerwidget->isValid();
+ if(!innerwidget->isValid()) return false;
}
- return true;
+ return regexpValidator() && luaValidator();
}
QString AltComboBox::getValue()
@@ -136,25 +150,41 @@ QString AltComboBox::getValue()
}
}
-void AltComboBox::setValue(QString value)
+void AltComboBox::setValue(QString value, QString source)
{
- combobox->setValue(value);
+ // if(isUserSource(source)) emit wasChanged(); // No need for this, it will be enitted by the children.
+
+ if(combobox->findData(value) != -1) {
+
+ combobox->setValue(value, source);
- if(combobox->isValid() == false) { // Combobox contain idx == -1 (invalid) if value didn't exist.
+ } else {
combobox->setValue(altvalue);
if(innerwidget) {
- innerwidget->setValue(value);
+ innerwidget->setValue(value, source);
}
}
+
+ setInitialValue(value);
}
void AltComboBox::onValueChange(int index)
{
if(combobox->itemData(index).toString() == altvalue) {
- altframe->setEnabled(true);
+ // altframe->setEnabled(true);
+ altframerepl->setVisible(false);
+ layout()->removeWidget(altframerepl);
+
+ layout()->addWidget(altframe);
+ altframe->setVisible(true);
} else {
- altframe->setEnabled(false);
+ // altframe->setEnabled(false);
+ altframe->setVisible(false);
+ layout()->removeWidget(altframe);
+
+ layout()->addWidget(altframerepl);
+ altframerepl->setVisible(true);
}
}
@@ -172,3 +202,35 @@ void AltComboBox::disable()
{
setEnabled(false);
}
+
+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);
+}
+
+bool AltComboBox::setKeyboardFocus()
+{
+ if(combobox->getValue() == altvalue) {
+ if(innerwidget) return innerwidget->setKeyboardFocus();
+ }
+
+ combobox->setKeyboardFocus();
+ return true;
+}
+
+void AltComboBox::setVisibility(bool visible)
+{
+ setVisible(visible);
+}