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.cc165
1 files changed, 44 insertions, 121 deletions
diff --git a/client/widgets/altcombobox.cc b/client/widgets/altcombobox.cc
index 78797f6..9956fff 100644
--- a/client/widgets/altcombobox.cc
+++ b/client/widgets/altcombobox.cc
@@ -30,16 +30,19 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QComboBox>
+#include <QLineEdit>
#include "common.h"
#include "multilist.h"
#include "macrowindow.h"
#include "debug.h"
+#include "luawidget.h"
AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
- : Widget(node, macrowindow)
+ : ComboBox(node, macrowindow)
{
+ combobox = (QComboBox*)widget;
frame = new QFrame();
widget = frame;
@@ -50,18 +53,10 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
setCommonAttributes(frame, node);
setCommonLayout(frame, node);
- combobox = new ComboBox(node, macrowindow);
- frame->layout()->addWidget(combobox->qwidget());
- combobox->qwidget()->show();
+ frame->layout()->addWidget(combobox);
+ frame->layout()->setContentsMargins(0,0,0,0);
- altframerepl = new QFrame();
- QHBoxLayout *l = new QHBoxLayout();
- altframerepl->setLayout(l);
- l->addStretch();
- altframe = new QFrame();
- frame->layout()->addWidget(altframe);
-
- QVector< Widget* > widgets;
+ altframe = NULL;
QString iwname;
@@ -70,11 +65,12 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
QDomElement item = items.at(i).toElement();
if(item.tagName() == "altitem") {
-
+ altframe = new Frame(item, macrowindow);
+
if(item.hasAttribute("value")) {
altvalue = item.attribute("value");
} else {
- ERROR(altcombobos, "altitem tag is missing the value attribute, "
+ ERROR(altcombobox, "altitem tag is missing the value attribute, "
"in altcombobox!\n");
}
@@ -85,63 +81,42 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
"in altcombobox!\n");
}
- if(item.hasAttribute("layout")) {
- if(item.attribute("layout") == "hbox") {
- QHBoxLayout *layout = new QHBoxLayout();
- altframe->setLayout(layout);
- } else if(item.attribute("layout") == "vbox") {
- QVBoxLayout *layout = new QVBoxLayout();
- altframe->setLayout(layout);
- } else { // Illigal layout choosen.
- QVBoxLayout *layout = new QVBoxLayout();
- altframe->setLayout(layout);
- }
- } else {
- QHBoxLayout *layout = new QHBoxLayout();
- altframe->setLayout(layout);
- }
-
- addChildren(item, altframe->layout());
+ frame->layout()->addWidget(altframe->qwidget());
+ children.push_back(altframe);
+ break;
}
-
}
innerwidget = findWidget(iwname, true);
if(innerwidget == NULL) {
ERROR(altcombobox, "Inner Widget %s not found (in altcombobox)!\n",
- iwname.toStdString().c_str());
+ iwname.toStdString().c_str());
}
- // To detect if the altvalue has been selected:
- connect(combobox->qwidget(), SIGNAL(currentIndexChanged(int)),
- this, SLOT(onValueChange(int)));
- connect(combobox->qwidget(), SIGNAL(editTextChanged(const QString&)),
- this, SLOT(onValueChange(const QString&)));
+ // Set visibility of altframe when combo selection changes.
+ connect(this, SIGNAL(eventOnChange()), this, SLOT(comboChanged()));
- // To react to changes in any of the children:
- connect(combobox, SIGNAL(wasChanged()), this, SLOT(onChildChange()));
+ // Propagate wasChanged events in the innerwidget
if(innerwidget)
connect(innerwidget, SIGNAL(wasChanged()), this, SLOT(onChildChange()));
-
- if(frame->layout()) frame->layout()->setContentsMargins(0,0,0,0);
- if(altframe->layout()) altframe->layout()->setContentsMargins(0,0,0,0);
-
- frame->show(); // Force altframe to get resized to its real size.
- altframerepl->setFixedHeight(altframe->height());
}
AltComboBox::~AltComboBox()
{
- // delete frame;
+}
+
+QComboBox *AltComboBox::qcombobox()
+{
+ return combobox;
}
bool AltComboBox::preValid()
{
- if(!combobox->valid()) return false;
+ if(ComboBox::preValid() == false) return false;
- if(innerwidget && combobox->value() == altvalue) {
+ if(innerwidget && ComboBox::value() == altvalue) {
if(!innerwidget->valid()) return false;
}
@@ -150,101 +125,49 @@ bool AltComboBox::preValid()
QString AltComboBox::value()
{
- if(combobox->value() == altvalue) {
+ QString val = ComboBox::value();
+
+ DEBUG(altcombobox, "ComboBox::value() => %s\n", val.toStdString().c_str());
+
+ if(val == altvalue) {
if(innerwidget) return innerwidget->value();
else return "";
} else {
- return combobox->value();
+ return val;
}
}
void AltComboBox::setValue(QString value, QString source)
{
- // No need for this, it will be enitted by the children.
- // if(isUserSource(source)) emit wasChanged();
-
- QComboBox *cmb = (QComboBox*)combobox->qwidget();
+ QComboBox *cmb = combobox;
if(cmb->findData(value) != -1) {
-
- combobox->setValue(value, source);
-
+ ComboBox::setValue(value, source);
} else {
- combobox->setValue(altvalue);
+ ComboBox::setValue(altvalue);
if(innerwidget) {
innerwidget->setValue(value, source);
}
}
-
- // setInitialValue(value);
}
-void AltComboBox::onValueChange(int index)
+void AltComboBox::comboChanged()
{
- QComboBox *cmb = (QComboBox*)combobox->qwidget();
-
- DEBUG(alcombobox, "Value changed: %s altvalue: %s\n",
- cmb->itemData(index).toString().toStdString().c_str(),
- altvalue.toStdString().c_str());
-
- if(cmb->itemData(index).toString() == altvalue) {
-
- altframerepl->setVisible(false);
- frame->layout()->removeWidget(altframerepl);
-
- frame->layout()->addWidget(altframe);
- altframe->setVisible(true);
-
- } else {
-
- altframe->setVisible(false);
- frame->layout()->removeWidget(altframe);
-
- frame->layout()->addWidget(altframerepl);
- altframerepl->setVisible(true);
+ DEBUG(altcombobox, "comboChanged to '%s'\n",
+ ComboBox::value().toStdString().c_str());
+ if(altframe) {
+ DEBUG(altcombobox, "inner->setVisible(%d)\n",
+ ComboBox::value() == altvalue);
+ altframe->setVisible(ComboBox::value() == altvalue);
}
-
- emit eventOnChange(true);
-}
-
-void AltComboBox::onValueChange(const QString &text)
-{
- QComboBox *cmb = (QComboBox*)combobox->qwidget();
- onValueChange(cmb->findText(text));
}
void AltComboBox::onChildChange()
{
- emit eventOnChange(true);
- emit wasChanged();
-}
-
-bool AltComboBox::setKeyboardFocus()
-{
- if(combobox->value() == altvalue) {
- if(innerwidget) return innerwidget->setKeyboardFocus();
+ DEBUG(altcombobox, "onChildChange\n");
+ if(ComboBox::value() == altvalue) {
+ emit eventOnChange(true);
+ emit wasChanged();
}
-
- combobox->setKeyboardFocus();
- return true;
-}
-
-void AltComboBox::setWdgValid(bool valid)
-{
- DEBUG(altcombobox, "Set valid(%s)\n", valid?"true":"false");
-
- 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->setWdgValid(valid);
- // if(innerwidget) innerwidget->setWdgValid(valid);
}