summaryrefslogtreecommitdiff
path: root/client/widgets
diff options
context:
space:
mode:
authordeva <deva>2008-12-01 15:30:17 +0000
committerdeva <deva>2008-12-01 15:30:17 +0000
commit4ef42a9bae0bd8c17391d1fbb5aa21d78fbe92ce (patch)
tree31f2c7d0f2c63d6681fd86c94ebfae36784a5968 /client/widgets
parent3ab207d95e47f81cf75effee3822cd787979cae7 (diff)
Added two new widgets: metawidget and altcombobox. Modified multilist to use 'innerwidget' attribute instead of format string.
Diffstat (limited to 'client/widgets')
-rw-r--r--client/widgets/altcombobox.cc177
-rw-r--r--client/widgets/altcombobox.h62
-rw-r--r--client/widgets/metawidget.cc117
-rw-r--r--client/widgets/metawidget.h57
-rw-r--r--client/widgets/multilist.cc64
-rw-r--r--client/widgets/multilist.h2
6 files changed, 439 insertions, 40 deletions
diff --git a/client/widgets/altcombobox.cc b/client/widgets/altcombobox.cc
new file mode 100644
index 0000000..1dc874f
--- /dev/null
+++ b/client/widgets/altcombobox.cc
@@ -0,0 +1,177 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * altcombobox.cc
+ *
+ * Tue Nov 25 08:18:10 CET 2008
+ * Copyright 2008 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "altcombobox.h"
+
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+
+#include "common.h"
+#include "widgetbuilder.h"
+
+#include <QObject>
+
+AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow)
+ : QFrame(), Widget(node, macrowindow)
+{
+ innerwidget = NULL;
+
+ setCommonAttributes(this, node);
+ setCommonLayout(this, node);
+
+ combobox = new ComboBox(node, macrowindow);
+ layout()->addWidget(combobox);
+ combobox->show();
+
+ altframe = new QFrame();
+ layout()->addWidget(altframe);
+
+ QVector< Widget* > widgets;
+
+ QString iwname;
+
+ QDomNodeList items = node.childNodes();
+ for(int i = 0; i < items.count(); i++) {
+ QDomElement item = items.at(i).toElement();
+
+ if(item.tagName() == "altitem") {
+
+ if(item.hasAttribute("value")) {
+ altvalue = item.attribute("value");
+ } else {
+ 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");
+ }
+
+ 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 {
+ QHBoxLayout *layout = new QHBoxLayout();
+ 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);
+ }
+ }
+
+ }
+ macrowindow->addAuxWidgets(widgets);
+ /*
+ QVector< Widget* >::iterator ws = widgets.begin();
+ while(ws != widgets.end()) {
+ if((*ws)->getName() == iwname) innerwidget = *ws;
+ ws++;
+ }
+ */
+
+ innerwidget = macrowindow->getWidget(iwname);
+
+ if(innerwidget == NULL) {
+ printf("ERROR: Inner Widget %s not found (in multilist)!\n",
+ iwname.toStdString().c_str());
+ }
+
+ connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(onValueChange(int)));
+
+ layout()->setContentsMargins(0,0,0,0);
+ altframe->layout()->setContentsMargins(0,0,0,0);
+}
+
+bool AltComboBox::isValid()
+{
+ if(!combobox->isValid()) return false;
+
+ if(innerwidget && combobox->getValue() == altvalue) {
+ return innerwidget->isValid();
+ }
+
+ return true;
+}
+
+QString AltComboBox::getValue()
+{
+ if(combobox->getValue() == altvalue) {
+ if(innerwidget) return innerwidget->getValue();
+ else return "";
+ } else {
+ return combobox->getValue();
+ }
+}
+
+void AltComboBox::setValue(QString value)
+{
+ combobox->setValue(value);
+
+ if(combobox->isValid() == false) { // Combobox contain idx == -1 (invalid) if value didn't exist.
+ combobox->setValue(altvalue);
+
+ printf("Value %s not in combo.\n", value.toStdString().c_str());
+
+ if(innerwidget) {
+ printf("\tSetting value on inner widget (%s) to \"%s\".\n", innerwidget->getName().toStdString().c_str(), value.toStdString().c_str());
+ printf("\told value (%s).\n", innerwidget->getValue().toStdString().c_str());
+ innerwidget->setValue(value);
+ } else {
+ printf("Could not set value in AltComboBox, no innerwidget!\n");
+ }
+ altframe->setEnabled(true);
+ } else {
+ altframe->setEnabled(false);
+ }
+}
+
+void AltComboBox::onValueChange(int index)
+{
+ if(combobox->itemData(index).toString() == altvalue) {
+ altframe->setEnabled(true);
+ } else {
+ altframe->setEnabled(false);
+ }
+}
+
+void AltComboBox::enable()
+{
+ setEnabled(true);
+}
+
+void AltComboBox::disable()
+{
+ setEnabled(false);
+}
diff --git a/client/widgets/altcombobox.h b/client/widgets/altcombobox.h
new file mode 100644
index 0000000..c75b964
--- /dev/null
+++ b/client/widgets/altcombobox.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * altcombobox.h
+ *
+ * Tue Nov 25 08:18:10 CET 2008
+ * Copyright 2008 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_ALTCOMBOBOX_H__
+#define __PRACRO_ALTCOMBOBOX_H__
+
+#include "widget.h"
+
+#include "combobox.h"
+
+#include <QFrame>
+#include <QDomNode>
+#include <QMap>
+
+class AltComboBox : public QFrame, public Widget
+{
+Q_OBJECT
+public:
+ AltComboBox(QDomNode &node, MacroWindow *macrowindow);
+
+ bool isValid();
+
+ QString getValue();
+ void setValue(QString value);
+
+ void enable();
+ void disable();
+
+public slots:
+ void onValueChange(int index);
+
+private:
+ ComboBox *combobox;
+ Widget *innerwidget;
+ QString altvalue;
+ QWidget *altframe;
+};
+
+#endif/*__PRACRO_ALTCOMBOBOX_H__*/
diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc
new file mode 100644
index 0000000..5f53153
--- /dev/null
+++ b/client/widgets/metawidget.cc
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * metawidget.cc
+ *
+ * Wed Nov 26 08:51:52 CET 2008
+ * Copyright 2008 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "metawidget.h"
+
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+
+#include "widgetbuilder.h"
+#include "formatparser.h"
+
+#include "common.h"
+
+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);
+
+ 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"));
+ }
+ */
+
+ if(elem.hasAttribute("format")) {
+ format = elem.attribute("format");
+ } else {
+ QVector< Widget* >::iterator i = widgets.begin();
+ while (i != widgets.end()) {
+ Widget* w = *i;
+ if(format != "") format += ", ";
+ format += "${" + w->getName() + "}";
+ i++;
+ }
+ }
+
+ if(elem.hasAttribute("width")) {
+ setMinimumWidth(elem.attribute("width").toInt());
+ }
+
+ if(elem.hasAttribute("height")) {
+ setMinimumHeight(elem.attribute("height").toInt());
+ }
+
+ layout()->setContentsMargins(0,0,0,0);
+}
+
+void MetaWidget::changed()
+{
+}
+
+QString MetaWidget::getValue()
+{
+ return format_parser(format, widgets);
+}
+
+void MetaWidget::setValue(QString /*values*/)
+{
+ // Nothing reasonable we can do here.
+}
+
+void MetaWidget::enable()
+{
+ setEnabled(true);
+}
+
+void MetaWidget::disable()
+{
+ setEnabled(false);
+}
diff --git a/client/widgets/metawidget.h b/client/widgets/metawidget.h
new file mode 100644
index 0000000..5d0bbc9
--- /dev/null
+++ b/client/widgets/metawidget.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * metawidget.h
+ *
+ * Wed Nov 26 08:51:52 CET 2008
+ * Copyright 2008 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_METAWIDGET_H__
+#define __PRACRO_METAWIDGET_H__
+
+#include "widget.h"
+#include <QFrame>
+#include <QDomNode>
+
+#include <QListWidget>
+#include <QVector>
+
+class MetaWidget : public QFrame, public Widget
+{
+Q_OBJECT
+public:
+ MetaWidget(QDomNode &node, MacroWindow *macrowindow);
+
+public slots:
+ void changed();
+ QString getValue();
+ void setValue(QString value);
+
+ void enable();
+ void disable();
+
+private:
+ QListWidget *list;
+ QVector< Widget* > widgets;
+ QString format;
+};
+
+#endif/*__PRACRO_METAWIDGET_H__*/
diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc
index a33c054..d83423c 100644
--- a/client/widgets/multilist.cc
+++ b/client/widgets/multilist.cc
@@ -32,7 +32,6 @@
#include <QPushButton>
#include "widgetbuilder.h"
-#include "formatparser.h"
#include "common.h"
@@ -61,17 +60,34 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow)
QHBoxLayout *layout = new QHBoxLayout();
inputbox->setLayout(layout);
}
-
+
inputbox->layout()->setContentsMargins(0,0,0,0);
QDomNodeList children = node.childNodes();
-
+
+ QVector< Widget* > widgets;
for (int i=0; i<children.count();i++) {
QDomNode child = children.at(i);
widgets += widgetBuilder(child, inputbox, macrowindow);
}
macrowindow->addAuxWidgets(widgets);
-
+
+ innerwidget = NULL;
+ if(elem.hasAttribute("innerwidget")) {
+ QString iwname = elem.attribute("innerwidget");
+ QVector< Widget* >::iterator ws = widgets.begin();
+ while(ws != widgets.end()) {
+ if((*ws)->getName() == iwname) innerwidget = *ws;
+ ws++;
+ }
+ if(innerwidget == NULL) {
+ printf("ERROR: Inner Widget %s not found (in multilist)!\n",
+ iwname.toStdString().c_str());
+ }
+ } else {
+ printf("ERROR: Missing 'innerwidget' attribute on multilist!\n");
+ }
+
QPushButton *add = new QPushButton(this);
connect(add, SIGNAL(clicked()), this, SLOT(add()));
add->setText("Tilføj");
@@ -94,41 +110,6 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow)
}
*/
- if(elem.hasAttribute("format")) {
- format = elem.attribute("format");
- } else {
- QVector< Widget* >::iterator i = widgets.begin();
- while (i != widgets.end()) {
- Widget* w = *i;
- if(format != "") format += ", ";
- format += "${" + w->getName() + "}";
- i++;
- }
- }
-
- /*
- QVector< Widget* >::iterator i = widgets.begin();
- while (i != widgets.end()) {
- for (int j = 0; j < children.count(); j++) {
- QDomNode child = children.at(j);
- QDomElement elem = child.toElement();
- if(elem.attribute("name") == (*i)->getName()) {
- printf("Set\n");
- (*i)->setValue(elem.attribute("value"));
- }
- }
- i++;
- }
- */
-
- if(elem.hasAttribute("width")) {
- setMinimumWidth(elem.attribute("width").toInt());
- }
-
- if(elem.hasAttribute("height")) {
- setMinimumHeight(elem.attribute("height").toInt());
- }
-
layout->setContentsMargins(0,0,0,0);
}
@@ -173,12 +154,17 @@ void MultiList::remove()
void MultiList::add()
{
+ /*
QVector< Widget * >::iterator i = widgets.begin();
while(i != widgets.end()) {
if(!(*i)->isValid()) return;
i++;
}
list->addItem(format_parser(format, widgets));
+ */
+
+ if(innerwidget && innerwidget->isValid()) list->addItem(innerwidget->getValue());
+
}
void MultiList::enable()
diff --git a/client/widgets/multilist.h b/client/widgets/multilist.h
index 276c1b1..0a9e798 100644
--- a/client/widgets/multilist.h
+++ b/client/widgets/multilist.h
@@ -53,7 +53,7 @@ public slots:
private:
QListWidget *list;
- QVector< Widget* > widgets;
+ Widget *innerwidget;
QString format;
};