summaryrefslogtreecommitdiff
path: root/client/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets')
-rw-r--r--client/widgets/altcombobox.cc148
-rw-r--r--client/widgets/altcombobox.h25
-rw-r--r--client/widgets/button.cc128
-rw-r--r--client/widgets/button.h34
-rw-r--r--client/widgets/checkbox.cc81
-rw-r--r--client/widgets/checkbox.h29
-rw-r--r--client/widgets/combobox.cc148
-rw-r--r--client/widgets/combobox.h31
-rw-r--r--client/widgets/datetime.cc107
-rw-r--r--client/widgets/datetime.h26
-rw-r--r--client/widgets/dbwidget.cc162
-rw-r--r--client/widgets/dbwidget.h30
-rw-r--r--client/widgets/frame.cc42
-rw-r--r--client/widgets/frame.h19
-rw-r--r--client/widgets/groupbox.cc44
-rw-r--r--client/widgets/groupbox.h19
-rw-r--r--client/widgets/label.cc56
-rw-r--r--client/widgets/label.h21
-rw-r--r--client/widgets/lineedit.cc126
-rw-r--r--client/widgets/lineedit.h30
-rw-r--r--client/widgets/listbox.cc76
-rw-r--r--client/widgets/listbox.h30
-rw-r--r--client/widgets/metawidget.cc85
-rw-r--r--client/widgets/metawidget.h29
-rw-r--r--client/widgets/multilist.cc117
-rw-r--r--client/widgets/multilist.h27
-rw-r--r--client/widgets/radiobutton.cc1
-rw-r--r--client/widgets/radiobuttons.cc102
-rw-r--r--client/widgets/radiobuttons.h34
-rw-r--r--client/widgets/textedit.cc98
-rw-r--r--client/widgets/textedit.h31
-rw-r--r--client/widgets/widget.cc290
-rw-r--r--client/widgets/widget.h90
-rw-r--r--client/widgets/window.cc45
-rw-r--r--client/widgets/window.h16
35 files changed, 1046 insertions, 1331 deletions
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 <QFrame>
#include <QHBoxLayout>
#include <QVBoxLayout>
+#include <QComboBox>
#include "common.h"
#include "widgetbuilder.h"
-
-#include <QObject>
#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);
}
diff --git a/client/widgets/altcombobox.h b/client/widgets/altcombobox.h
index c52bd20..9f90f8b 100644
--- a/client/widgets/altcombobox.h
+++ b/client/widgets/altcombobox.h
@@ -31,43 +31,32 @@
#include "combobox.h"
-#include <QFrame>
#include <QDomNode>
#include <QMap>
-class AltComboBox : public QFrame, public Widget
+class QFrame;
+class AltComboBox : public Widget
{
Q_OBJECT
public:
AltComboBox(QDomNode &node, MacroWindow *macrowindow);
+ ~AltComboBox();
- bool isValid();
-
- QString getValue();
+ QString value();
void setValue(QString value, QString source = "");
- void disable();
- void enable();
- bool isDisabled();
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
+ bool preValid();
+ void setWdgValid(bool valid);
bool setKeyboardFocus();
- void setVisibility(bool visible);
public slots:
void onValueChange(int index);
void onValueChange(const QString &text);
void onChildChange();
-signals:
- void wasChanged();
-
private:
+ QFrame *frame;
ComboBox *combobox;
Widget *innerwidget;
QString altvalue;
diff --git a/client/widgets/button.cc b/client/widgets/button.cc
index 963242c..3234296 100644
--- a/client/widgets/button.cc
+++ b/client/widgets/button.cc
@@ -25,70 +25,53 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "button.h"
+
#include <stdio.h>
+#include <QPushButton>
#include "common.h"
+#include "macrowindow.h"
+
Button::Button(QDomNode &node, MacroWindow *macrowindow)
- : QPushButton(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- resetToDisabled = false;
- setCommonAttributes(this, node);
+ button = new QPushButton();
+ widget = button;
- QDomElement elem = node.toElement();
+ setCommonAttributes(button, node);
- if(elem.hasAttribute("field")) {
- field = elem.attribute("field");
- }
+ QDomElement elem = node.toElement();
- if(elem.hasAttribute("caption")) {
- setText(elem.attribute("caption"));
- } else {
- setText("");
- }
+ button->setText(elem.attribute("caption", ""));
if(elem.hasAttribute("action")) {
if(elem.attribute("action") == "commit") {
- connect(this, SIGNAL(clicked()), this, SLOT(commit()));
- setIcon(QPixmap(":icons/add.png"));
- setEnabled(false);
-
- //
- // Hack to re-disable the commit button when the macro is reset.
- //
- resetToDisabled = true;
- widget_name = "commit_button_" + QString::number((int)this);
- QVector< Widget* > ws;
- ws.push_back(this);
- macrowindow->addAuxWidgets(ws);
-
- } else if(elem.attribute("action") == "reset") {
- connect(this, SIGNAL(clicked()), this, SLOT(_reset()));
- setIcon(QPixmap(":icons/del.png"));
+ connect(button, SIGNAL(clicked()), this, SLOT(commit()));
+ button->setIcon(QPixmap(":icons/add.png"));
+ button->setEnabled(false);
} else if(elem.attribute("action") == "cancel") {
- connect(this, SIGNAL(clicked()), this, SLOT(cancel()));
- setIcon(QPixmap(":icons/del.png"));
- } else if(elem.attribute("action") == "continue") {
- connect(this, SIGNAL(clicked()), this, SLOT(cont()));
- setIcon(QPixmap(":icons/add.png"));
- } else if(elem.attribute("action") == "continue_nocommit") {
- connect(this, SIGNAL(clicked()), this, SLOT(cont_nocommit()));
- }
- } else {
- setEnabled(false);
+ connect(button, SIGNAL(clicked()), this, SLOT(cancel()));
+ button->setIcon(QPixmap(":icons/del.png"));
+ }
}
+
+ connect(this, SIGNAL(act_commit()), macrowindow, SLOT(commit()));
+ connect(this, SIGNAL(act_cancel()), macrowindow, SLOT(cancel()));
+ connect(macrowindow, SIGNAL(macroHasChanged()), this, SLOT(do_enable()));
+
}
-void Button::commit()
+Button::~Button()
{
- emit act_commit();
- printf("Emit: commit\n");
+ printf("Delete (Button) %p\n", this); fflush(stdout);
+ // delete button;
}
-void Button::_reset()
+void Button::commit()
{
- emit act_reset();
- printf("Emit: reset\n");
+ emit act_commit();
+ printf("Emit: commit\n");
}
void Button::cancel()
@@ -97,62 +80,7 @@ void Button::cancel()
printf("Emit: cancel\n");
}
-void Button::cont()
-{
- emit act_continue(field);
- printf("Emit: continue\n");
-}
-
-void Button::cont_nocommit()
-{
- emit act_continue_nocommit(field);
- printf("Emit: continue_nocommit\n");
-}
-
void Button::do_enable()
{
- setEnabled(true);
-}
-
-void Button::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void Button::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-void Button::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
-bool Button::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void Button::reset()
-{
- if(resetToDisabled) setEnabled(false);
-}
-
-void Button::enable()
-{
- setEnabled(true);
-}
-
-void Button::disable()
-{
- setEnabled(false);
-}
-
-bool Button::isDisabled()
-{
- return isEnabled() == false;
+ button->setEnabled(true);
}
diff --git a/client/widgets/button.h b/client/widgets/button.h
index 64d51f9..80594db 100644
--- a/client/widgets/button.h
+++ b/client/widgets/button.h
@@ -28,49 +28,31 @@
#define __PRACRO_BUTTON_H__
#include "widget.h"
-#include <QPushButton>
-#include <QWidget>
+
#include <QDomNode>
-class Button : public QPushButton, public Widget
+class QPushButton;
+class Button : public Widget
{
Q_OBJECT
public:
Button(QDomNode &node, MacroWindow *macrowindow);
- QString field;
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- void setVisibility(bool visible);
-
- bool setKeyboardFocus();
-
- void reset();
+ ~Button();
- void disable();
- void enable();
- bool isDisabled();
+ QString value() { return ""; }
+ void setValue(QString, QString) {}
+ void setWdgValid(bool) {}
public slots:
void commit();
- void _reset();
void cancel();
- void cont();
- void cont_nocommit();
void do_enable();
signals:
void act_commit();
- void act_reset();
void act_cancel();
- void act_continue(QString);
- void act_continue_nocommit(QString);
private:
- bool resetToDisabled;
+ QPushButton *button;
};
#endif/*__PRACRO_BUTTON_H__*/
diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc
index e550289..19b59e6 100644
--- a/client/widgets/checkbox.cc
+++ b/client/widgets/checkbox.cc
@@ -26,19 +26,24 @@
*/
#include "checkbox.h"
+#include <QCheckBox>
+
#include "common.h"
CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow)
- : QCheckBox(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
+ checkbox = new QCheckBox();
+ widget = checkbox;
+
changedByUser = true;
- setCommonAttributes(this, node);
+ setCommonAttributes(checkbox, node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("caption")) {
- setText(elem.attribute("caption"));
+ checkbox->setText(elem.attribute("caption"));
}
if(elem.hasAttribute("truevalue")) {
@@ -53,12 +58,18 @@ CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow)
falsevalue = "false";
}
- connect(this, SIGNAL(stateChanged(int)), this, SLOT(state_change(int)));
+ connect(checkbox, SIGNAL(stateChanged(int)), this, SLOT(state_change(int)));
+}
+
+CheckBox::~CheckBox()
+{
+ printf("Delete (CheckBox) %p\n", this); fflush(stdout);
+ // delete checkbox;
}
-QString CheckBox::getValue()
+QString CheckBox::value()
{
- if(isChecked()) return truevalue;
+ if(checkbox->isChecked()) return truevalue;
return falsevalue;
}
@@ -68,69 +79,51 @@ void CheckBox::setValue(QString value, QString source)
changedByUser = false;
- bool old = isChecked();
+ bool old = checkbox->isChecked();
if(value == truevalue) {
- setChecked(true);
+ checkbox->setChecked(true);
} else if(value == falsevalue) {
- setChecked(false);
+ checkbox->setChecked(false);
} else {
printf("Unknown checkbox value: %s\n", value.toStdString().c_str());
}
// If set operation did not change the value we must invocate the code manually.
- if(old == isChecked()) state_change(0);
+ if(old == checkbox->isChecked()) state_change(0);
setInitialValue(value);
changedByUser = true;
}
-/*
-bool CheckBox::isValid()
-{
- return luaValidator();
-}
-*/
+
void CheckBox::state_change(int)
{
if(changedByUser) emit wasChanged();
- luaValidator();
+ eventOnChange();
}
-void CheckBox::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
+bool CheckBox::checked()
{
- connect(this, signal, receiver, method);
+ return value() == truevalue;
}
-void CheckBox::connectTo(const QObject *sender, const char *signal,
- const char *method)
+void CheckBox::setChecked(bool checked)
{
- connect(sender, signal, this, method);
+ setValue(checked ? truevalue : falsevalue);
}
-void CheckBox::setVisibility(bool visible)
+void CheckBox::setWdgValid(bool valid)
{
- setVisible(visible);
-}
+ QPalette palette;
-bool CheckBox::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void CheckBox::enable()
-{
- setEnabled(true);
-}
-
-void CheckBox::disable()
-{
- setEnabled(false);
-}
+ 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)));
+ }
-bool CheckBox::isDisabled()
-{
- return isEnabled() == false;
+ checkbox->setPalette(palette);
}
diff --git a/client/widgets/checkbox.h b/client/widgets/checkbox.h
index 5131f56..7cf2651 100644
--- a/client/widgets/checkbox.h
+++ b/client/widgets/checkbox.h
@@ -29,44 +29,33 @@
#include "widget.h"
#include <QDomNode>
-#include <QCheckBox>
-class CheckBox : public QCheckBox, public Widget
+class QCheckBox;
+class CheckBox : public Widget
{
Q_OBJECT
public:
CheckBox(QDomNode &node, MacroWindow *macrowindow);
+ ~CheckBox();
- // bool isValid();
-
- QString getValue();
+ QString value();
void setValue(QString value, QString source = "");
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- void setVisibility(bool visible);
+ void setWdgValid(bool valid);
- bool setKeyboardFocus();
-
- void enable();
- void disable();
- bool isDisabled();
+ bool checked();
+ void setChecked(bool checked);
public slots:
void state_change(int);
-signals:
- void wasChanged();
-
private:
QString truevalue;
QString falsevalue;
bool changedByUser;
+
+ QCheckBox *checkbox;
};
#endif/*__PRACRO_CHECKBOX_H__*/
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc
index f81d989..5980400 100644
--- a/client/widgets/combobox.cc
+++ b/client/widgets/combobox.cc
@@ -25,6 +25,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "combobox.h"
+
+#include <QComboBox>
+
#include <QDomNodeList>
#include <QCompleter>
#include <QRegExpValidator>
@@ -32,6 +35,9 @@
#include <QLineEdit>
#include <QCoreApplication>
+#include <QEvent>
+#include <QWheelEvent>
+
#include "common.h"
// Enable this to make the combobox drawn in windows style.
@@ -44,15 +50,18 @@ QWindowsStyle s;
#endif/*STYLE_HACK*/
ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
- : QComboBox(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
+ combobox = new QComboBox();
+ widget = combobox;
+
+ setCommonAttributes(combobox, node);
#ifdef STYLE_HACK
- setStyle(&s);
+ combobox->setStyle(&s);
#endif/*STYLE_HACK*/
- setInsertPolicy(QComboBox::InsertAlphabetically);
+ combobox->setInsertPolicy(QComboBox::InsertAlphabetically);
QDomNodeList children = node.childNodes();
QStringList itemlist;
@@ -61,15 +70,16 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
QDomNode child = children.at(i);
QDomElement combo_elem = child.toElement();
if(combo_elem.hasAttribute("caption") && combo_elem.hasAttribute("value")) {
- addItem(combo_elem.attribute("caption"), combo_elem.attribute("value"));
+ combobox->addItem(combo_elem.attribute("caption"),
+ combo_elem.attribute("value"));
itemlist << combo_elem.attribute("caption");
} else {
- printf("XML Error!!! Combobox item is missing one or more attributes...\n");
+ printf("XML Error!!! Combobox is missing one or more attributes...\n");
}
}
// Make empty default selection.
- setCurrentIndex(-1);
+ combobox->setCurrentIndex(-1);
QDomElement elem = node.toElement();
@@ -82,25 +92,26 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
switch(combotype) {
case SELECT:
- setEditable(false);
+ combobox->setEditable(false);
#ifndef STYLE_HACK
- setEditable(true);
- lineEdit()->setReadOnly(true);
- lineEdit()->installEventFilter(this);
+ combobox->setEditable(true);
+ combobox->lineEdit()->setReadOnly(true);
+ combobox->lineEdit()->installEventFilter(this);
#endif/*STYLE_HACK*/
- connect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(changed()));
+ connect(combobox, SIGNAL(currentIndexChanged(QString)),
+ this, SLOT(changed()));
break;
case EDIT:
- setEditable(true);
+ combobox->setEditable(true);
- connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
+ connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
break;
case SEARCH:
- setEditable(true);
+ combobox->setEditable(true);
{
QString rxs = "(";
for(int i = 0; i < itemlist.size(); i++) {
@@ -115,11 +126,11 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
QCompleter *completer = new QCompleter(itemlist, this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setCompletionMode(QCompleter::PopupCompletion);
- setCompleter(completer);
- setValidator(new QRegExpValidator(rx, this));
+ combobox->setCompleter(completer);
+ combobox->setValidator(new QRegExpValidator(rx, this));
}
- connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
+ connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
break;
}
@@ -128,14 +139,20 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow)
ischangingbyuser = true;
}
-QString ComboBox::getValue()
+ComboBox::~ComboBox()
+{
+ // delete combobox;
+}
+
+QString ComboBox::value()
{
QString value;
- int idx = currentIndex();
+ int idx = combobox->currentIndex();
- if(idx != -1 && itemText(idx) == currentText()) value = itemData(idx).toString();
- else value = currentText();
+ if(idx != -1 && combobox->itemText(idx) == combobox->currentText())
+ value = combobox->itemData(idx).toString();
+ else value = combobox->currentText();
return value;
}
@@ -144,93 +161,38 @@ void ComboBox::setValue(QString value, QString source)
{
if(isUserSource(source)) emit wasChanged();
- int idx = findData(value);
+ int idx = combobox->findData(value);
// printf("setValue(\"%s\") - %d\n", value.toStdString().c_str(), idx);
ischangingbyuser = false;
- setCurrentIndex(idx);
+ combobox->setCurrentIndex(idx);
ischangingbyuser = true;
setInitialValue(value);
}
-bool ComboBox::isValid()
+bool ComboBox::preValid()
{
if(combotype == SELECT) {
- if(currentIndex() != -1) return true;
+ if(combobox->currentIndex() != -1) return true;
else return false;
}
- return rx.exactMatch(currentText()) && luaValidator();
+ return true;
}
void ComboBox::changed()
{
if(ischangingbyuser) emit wasChanged();
-
- QPalette palette;
-
- if(isEnabled()) {
- if(isValid() && luaValidator()) {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- }
- } else {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- }
-
- if(lineEdit()) lineEdit()->setPalette(palette);
- else setPalette(palette);
-}
-
-void ComboBox::enable()
-{
- setEnabled(true);
-}
-
-void ComboBox::disable()
-{
- setEnabled(false);
-}
-
-bool ComboBox::isDisabled()
-{
- return isEnabled() == false;
-}
-
-void ComboBox::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void ComboBox::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-bool ComboBox::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void ComboBox::setVisibility(bool visible)
-{
- setVisible(visible);
+ eventOnChange();
}
bool ComboBox::eventFilter(QObject *obj, QEvent *event)
{
if(combotype == SELECT) {
if(event->type() == QEvent::MouseButtonRelease) {
- showPopup();
+ combobox->showPopup();
}
}
@@ -239,7 +201,7 @@ bool ComboBox::eventFilter(QObject *obj, QEvent *event)
void ComboBox::wheelEvent(QWheelEvent *e)
{
- QCoreApplication::sendEvent(nativeParentWidget(), e);
+ QCoreApplication::sendEvent(combobox->nativeParentWidget(), e);
}
void ComboBox::changeEvent(QEvent *event)
@@ -248,3 +210,19 @@ void ComboBox::changeEvent(QEvent *event)
changed();
}
}
+
+void ComboBox::setWdgValid(bool valid)
+{
+ 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)));
+ }
+
+ if(combobox->lineEdit()) combobox->lineEdit()->setPalette(palette);
+ combobox->setPalette(palette);
+}
diff --git a/client/widgets/combobox.h b/client/widgets/combobox.h
index 8059e81..a706075 100644
--- a/client/widgets/combobox.h
+++ b/client/widgets/combobox.h
@@ -27,47 +27,36 @@
#ifndef __PRACRO_COMBOBOX_H__
#define __PRACRO_COMBOBOX_H__
-#include "widget.h"
#include <QDomNode>
-#include <QComboBox>
#include <QRegExp>
+#include "widget.h"
+
typedef enum {
SELECT,
EDIT,
SEARCH
} types_t;
-class ComboBox : public QComboBox, public Widget
+class QComboBox;
+class QWheelEvent;
+class ComboBox : public Widget
{
Q_OBJECT
public:
ComboBox(QDomNode &node, MacroWindow *macrowindow);
+ ~ComboBox();
- bool isValid();
-
- QString getValue();
+ QString value();
void setValue(QString value, QString source = "");
- void disable();
- void enable();
- bool isDisabled();
+ bool preValid();
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- bool setKeyboardFocus();
- void setVisibility(bool visible);
+ void setWdgValid(bool valid);
public slots:
void changed();
-signals:
- void wasChanged();
-
protected:
bool eventFilter(QObject *obj, QEvent *event);
void wheelEvent(QWheelEvent *);
@@ -78,6 +67,8 @@ private:
QString combo_value;
types_t combotype;
bool ischangingbyuser;
+
+ QComboBox *combobox;
};
#endif/*__PRACRO_COMBOBOX_H__*/
diff --git a/client/widgets/datetime.cc b/client/widgets/datetime.cc
index 0b91a40..b97178f 100644
--- a/client/widgets/datetime.cc
+++ b/client/widgets/datetime.cc
@@ -26,87 +26,89 @@
*/
#include "datetime.h"
+#include <QDateTimeEdit>
+
#include "common.h"
DateTime::DateTime(QDomNode &node, MacroWindow *macrowindow)
- : QDateTimeEdit(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
+ datetimeedit = new QDateTimeEdit();
+ widget = datetimeedit;
+
changedByUser = true;
- setCommonAttributes(this, node);
+ setCommonAttributes(datetimeedit, node);
- setCalendarPopup(true);
+ datetimeedit->setCalendarPopup(true);
// setMinimumDateTime(QDateTime::fromTime_t(0));
- setMinimumDate(QDate(1900,1,1));
- setMinimumTime(QTime(0,0));
+ datetimeedit->setMinimumDate(QDate(1900,1,1));
+ datetimeedit->setMinimumTime(QTime(0,0));
QDomElement elem = node.toElement();
switch(elem.attribute("fuzziness", "5").toLong()) {
case 1:
- setDisplayFormat("yyyy");
+ datetimeedit->setDisplayFormat("yyyy");
break;
case 2:
- setDisplayFormat("MMMM yyyy");
+ datetimeedit->setDisplayFormat("MMMM yyyy");
break;
case 3:
- setDisplayFormat("dd MMMM yyyy");
+ datetimeedit->setDisplayFormat("dd MMMM yyyy");
break;
case 4:
- setDisplayFormat("dd MMMM yyyy hh");
+ datetimeedit->setDisplayFormat("dd MMMM yyyy hh");
break;
case 5:
- setDisplayFormat("dd MMMM yyyy hh:mm");
+ datetimeedit->setDisplayFormat("dd MMMM yyyy hh:mm");
break;
case 6:
- setDisplayFormat("dd MMMM yyyy hh:mm:ss");
+ datetimeedit->setDisplayFormat("dd MMMM yyyy hh:mm:ss");
break;
case 7:
default:
- setDisplayFormat("dd MMMM yyyy hh:mm:ss:zzz");
+ datetimeedit->setDisplayFormat("dd MMMM yyyy hh:mm:ss:zzz");
break;
}
/*
if(elem.hasAttribute("readonly")) {
- if(elem.attribute("readonly") == "true" || elem.attribute("readonly") == "1") {
+ if(elem.attribute("readonly") == "true" ||
+ elem.attribute("readonly") == "1") {
setReadOnly(true);
- } else if(elem.attribute("readonly") == "false" || elem.attribute("readonly") == "0") {
+ } else if(elem.attribute("readonly") == "false" ||
+ elem.attribute("readonly") == "0") {
setReadOnly(false);
} else {
- printf("Unknown value of readonly: %s\n", elem.attribute("readonly").toStdString().c_str());
+ printf("Unknown value of readonly: %s\n",
+ elem.attribute("readonly").toStdString().c_str());
}
}
*/
- connect(this, SIGNAL(dateTimeChanged(const QDateTime &)),
+ connect(datetimeedit, SIGNAL(dateTimeChanged(const QDateTime &)),
this, SLOT(changed(const QDateTime &)));
}
-void DateTime::changed(const QDateTime &)
+DateTime::~DateTime()
{
- QPalette palette;
-
- if(luaValidator()) {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200)));
- }
-
- setPalette(palette);
+ // delete datetimeedit;
+}
+void DateTime::changed(const QDateTime &)
+{
if(changedByUser) emit wasChanged();
+ eventOnChange();
}
-QString DateTime::getValue()
+QString DateTime::value()
{
- return QString::number(dateTime().toUTC().toTime_t());
+ return QString::number(datetimeedit->dateTime().toUTC().toTime_t());
}
void DateTime::setValue(QString value, QString source)
@@ -114,46 +116,23 @@ void DateTime::setValue(QString value, QString source)
changedByUser = false;
if(isUserSource(source)) emit wasChanged();
- setDateTime(QDateTime::fromTime_t(value.toUInt()));
+ datetimeedit->setDateTime(QDateTime::fromTime_t(value.toUInt()));
setInitialValue(value);
changedByUser = true;
}
-void DateTime::enable()
-{
- setEnabled(true);
-}
-
-void DateTime::disable()
-{
- setEnabled(false);
-}
-
-bool DateTime::isDisabled()
-{
- return isEnabled() == false;
-}
-
-void DateTime::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
+void DateTime::setWdgValid(bool valid)
{
- connect(this, signal, receiver, method);
-}
-
-void DateTime::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
+ QPalette palette;
-bool DateTime::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
+ if(valid) {
+ // valid string
+ palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
+ } else {
+ // invalid string
+ palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200)));
+ }
-void DateTime::setVisibility(bool visible)
-{
- setVisible(visible);
+ datetimeedit->setPalette(palette);
}
diff --git a/client/widgets/datetime.h b/client/widgets/datetime.h
index 8699816..b6e2d36 100644
--- a/client/widgets/datetime.h
+++ b/client/widgets/datetime.h
@@ -28,39 +28,29 @@
#define __PRACRO_DATETIME_H__
#include "widget.h"
-#include <QDateTimeEdit>
+
#include <QDomNode>
+#include <QDateTime>
-class DateTime : public QDateTimeEdit, public Widget
+class QDateTimeEdit;
+class DateTime : public Widget
{
Q_OBJECT
public:
DateTime(QDomNode &node, MacroWindow *macrowindow);
+ ~DateTime();
- QString getValue();
+ QString value();
void setValue(QString value, QString source = "");
- void disable();
- void enable();
- bool isDisabled();
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- bool setKeyboardFocus();
- void setVisibility(bool visible);
+ void setWdgValid(bool valid);
public slots:
void changed(const QDateTime &);
-signals:
- void wasChanged();
-
private:
bool changedByUser;
+ QDateTimeEdit *datetimeedit;
};
#endif/*__PRACRO_DATETIME_H__*/
diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc
index 31a6a42..3852b21 100644
--- a/client/widgets/dbwidget.cc
+++ b/client/widgets/dbwidget.cc
@@ -34,12 +34,19 @@
#include <QSqlQuery>
#include <QSqlError>
#include <QLineEdit>
+#include <QComboBox>
+
#include "formatparser.h"
#include "common.h"
+#define EMPTY_STRING "Write something in the searchfield"
+
DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow)
- : QComboBox(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
+ combobox = new QComboBox();
+ widget = combobox;
+
changedByUser = true;
QDomElement elem = node.toElement();
@@ -72,24 +79,25 @@ DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow)
printf("DB connect failed!\n");
}
- setCommonAttributes(this, node);
+ setCommonAttributes(combobox, node);
- setInsertPolicy(QComboBox::InsertAlphabetically);
- setEditable(true);
+ combobox->setInsertPolicy(QComboBox::InsertAlphabetically);
+ combobox->setEditable(true);
// Make empty default selection.
- addItem(tr("Write something in the searchfield"));
- setCurrentIndex(-1);
+ combobox->addItem(tr("Write something in the searchfield"));
+ combobox->setCurrentIndex(-1);
QStringListModel *strlst = new QStringListModel();
QCompleter *completer = new QCompleter(this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
completer->setCompletionMode(QCompleter::PopupCompletion);
completer->setModel(strlst);
- setCompleter(completer);
+ combobox->setCompleter(completer);
- connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
- connect((QWidget*)lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(update_list(QString)));
+ connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed()));
+ connect((QWidget*)combobox->lineEdit(), SIGNAL(textEdited(QString)),
+ this, SLOT(update_list(QString)));
changed();
}
@@ -98,14 +106,15 @@ DBWidget::~DBWidget()
{
db.close();
db = QSqlDatabase();
+ // delete combobox;
}
-QString DBWidget::getValue()
+QString DBWidget::value()
{
QString value;
- value = currentText();
+ value = combobox->currentText();
return value;
}
@@ -115,52 +124,39 @@ void DBWidget::setValue(QString value, QString source)
changedByUser = false;
if(isUserSource(source)) emit wasChanged();
- setEditText(value);
+ combobox->setEditText(value);
setInitialValue(value);
changedByUser = true;
}
-bool DBWidget::isValid()
+bool DBWidget::preValid()
{
-
- return currentText() != tr("Write something in the searchfield")
- && findText(currentText()) != -1;
-
- /*
- QSqlQuery query = db.exec("SELECT " + select + " FROM " + from + " WHERE LOWER(" + where + ") = '" + currentText().toLower() + "';");
-
- return query.size() != 0;
- */
+ return combobox->currentText() != tr(EMPTY_STRING) &&
+ combobox->currentText() != "" &&
+ combobox->findText(combobox->currentText()) != -1
+ ;
}
void DBWidget::changed()
{
- QPalette palette;
-
- if(isValid() && luaValidator()) {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- }
-
- lineEdit()->setPalette(palette);
-
if(changedByUser) emit wasChanged();
+ eventOnChange();
}
void DBWidget::update_list(QString prefix)
{
if(prefix == "") {
- clear();
- addItem(tr("Write something in the searchfield"));
- setCurrentIndex(-1);
+ combobox->clear();
+ combobox->addItem(tr(EMPTY_STRING));
+ combobox->setCurrentIndex(-1);
return;
}
- QSqlQuery query = db.exec("SELECT " + select + " FROM " + from + " WHERE LOWER(" + where + ") LIKE '" + prefix.toLower() + "%';");
+ QSqlQuery query = db.exec("SELECT " + select +
+ " FROM " + from +
+ " WHERE LOWER(" + where + ")"
+ " LIKE '" + prefix.toLower() + "%';");
QStringList lst;
while(query.next()) {
@@ -169,88 +165,30 @@ void DBWidget::update_list(QString prefix)
lst.sort();
- QStringListModel *mdl = (QStringListModel *)completer()->model();
+ QStringListModel *mdl = (QStringListModel *)combobox->completer()->model();
if(mdl->stringList() != lst) {
- QString val = currentText();
- clear();
+ QString val = combobox->currentText();
+ combobox->clear();
if(lst.size() == 0) lst << "Søgningen passede ikke på noget.";
- addItems(lst);
- setEditText(val);
+ combobox->addItems(lst);
+ combobox->setEditText(val);
mdl->setStringList(lst);
//showPopup();
}
}
-void DBWidget::enable()
+void DBWidget::setWdgValid(bool valid)
{
- setEnabled(true);
-}
-
-void DBWidget::disable()
-{
- setEnabled(false);
-}
-
-bool DBWidget::isDisabled()
-{
- return isEnabled() == false;
-}
-
-void DBWidget::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void DBWidget::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
+ QPalette palette;
-bool DBWidget::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
+ 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)));
+ }
-void DBWidget::setVisibility(bool visible)
-{
- setVisible(visible);
+ combobox->lineEdit()->setPalette(palette);
+ combobox->setPalette(palette);
}
-/*
-$ psql -h sensei -d lms -U postgres
-===================================================================
- List of relations
- Schema | Name | Type | Owner
---------+-------+-------+----------
- public | lms01 | table | postgres
-(1 row)
-
-lms=# \d lms01
- Table "public.lms01"
- Column | Type | Modifiers
--------------------------------+-----------------------+-----------
- drugid | character varying(32) |
- producttype | character varying(14) |
- productsubtype | character varying(14) |
- sequencetext | character varying(28) |
- specialitynumber | character varying(20) |
- drugname | character varying(70) |
- dosageform_text | character varying(50) |
- dosageform_code | character varying(24) |
- further_dos_info | character varying(24) |
- strength_text | character varying(50) |
- strength_numeric | character varying(30) |
- strength_unit | character varying(16) |
- marketing_authorisation_owner | character varying(22) |
- importer | character varying(22) |
- atc | character varying(26) |
- route_of_administration | character varying(26) |
- traffic_warning | character varying(12) |
- substitution | character varying(12) |
- substitution_group | character varying(18) |
- dose_dispensing | character varying(12) |
- deregistration_date | character varying(26) |
- quarantine_date | character varying(26) |
-*/
diff --git a/client/widgets/dbwidget.h b/client/widgets/dbwidget.h
index ce2b596..3eb8f94 100644
--- a/client/widgets/dbwidget.h
+++ b/client/widgets/dbwidget.h
@@ -28,46 +28,32 @@
#define __PRACRO_DBWIDGET_H__
#include "widget.h"
+
#include <QDomNode>
-#include <QComboBox>
+
#include <QRegExp>
#include <QSqlDatabase>
#include <QEvent>
-class DBWidget : public QComboBox, public Widget
+class QComboBox;
+class DBWidget : public Widget
{
Q_OBJECT
public:
DBWidget(QDomNode &node, MacroWindow *macrowindow);
~DBWidget();
- bool isValid();
-
- QString getValue();
+ QString value();
void setValue(QString value, QString source = "");
- void disable();
- void enable();
- bool isDisabled();
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- void setVisibility(bool visible);
-
- bool setKeyboardFocus();
+ void setWdgValid(bool valid);
+ bool preValid();
public slots:
void changed();
void update_list(QString prefix);
-signals:
- void wasChanged();
-
protected:
// void focusInEvent(QFocusEvent *);
@@ -80,6 +66,8 @@ private:
QString format;
bool changedByUser;
+
+ QComboBox *combobox;
};
#endif/*__PRACRO_DBWIDGET_H__*/
diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc
index d6f4fb2..e117467 100644
--- a/client/widgets/frame.cc
+++ b/client/widgets/frame.cc
@@ -25,48 +25,28 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "frame.h"
+
#include <QVBoxLayout>
#include <QHBoxLayout>
+#include <QFrame>
#include "common.h"
Frame::Frame(QDomNode &node, MacroWindow *macrowindow)
- : QFrame(), Widget(node, macrowindow)
-{
- setCommonAttributes(this, node);
- setCommonLayout(this, node);
-
- layout()->setContentsMargins(0,0,0,0);
-}
-
-void Frame::enable()
-{
- setEnabled(true);
-}
-
-void Frame::disable()
+ : Widget(node, macrowindow)
{
- setEnabled(false);
-}
+ frame = new QFrame();
+ widget = frame;
-bool Frame::isDisabled()
-{
- return isEnabled() == false;
-}
+ setCommonAttributes(frame, node);
+ setCommonLayout(frame, node);
-void Frame::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
+ frame->layout()->setContentsMargins(0,0,0,0);
-void Frame::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
+ addChildren(node);
}
-void Frame::setVisibility(bool visible)
+Frame::~Frame()
{
- setVisible(visible);
+ // delete frame;
}
diff --git a/client/widgets/frame.h b/client/widgets/frame.h
index 3f83fc4..fe57a0f 100644
--- a/client/widgets/frame.h
+++ b/client/widgets/frame.h
@@ -28,24 +28,23 @@
#define __PRACRO_FRAME_H__
#include "widget.h"
-#include <QFrame>
+
#include <QDomNode>
-class Frame : public QFrame, public Widget
+class QFrame;
+class Frame : public Widget
{
public:
Frame(QDomNode &node, MacroWindow *macrowindow);
+ ~Frame();
- void disable();
- void enable();
- bool isDisabled();
+ QString value() { return ""; }
+ void setValue(QString, QString) {}
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
+ void setWdgValid(bool) {}
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
- void setVisibility(bool visible);
+private:
+ QFrame *frame;
};
#endif/*__PRACRO_FRAME_H__*/
diff --git a/client/widgets/groupbox.cc b/client/widgets/groupbox.cc
index e6f8b97..085a876 100644
--- a/client/widgets/groupbox.cc
+++ b/client/widgets/groupbox.cc
@@ -25,6 +25,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "groupbox.h"
+
+#include <QGroupBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
@@ -33,46 +35,24 @@
#include "common.h"
GroupBox::GroupBox(QDomNode &node, MacroWindow *macrowindow)
- : QGroupBox(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
- setCommonLayout(this, node);
+ groupbox = new QGroupBox();
+ widget = groupbox;
+
+ setCommonAttributes(groupbox, node);
+ setCommonLayout(groupbox, node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("caption")) {
- setTitle(elem.attribute("caption"));
+ groupbox->setTitle(elem.attribute("caption"));
}
-}
-
-void GroupBox::enable()
-{
- setEnabled(true);
-}
-
-void GroupBox::disable()
-{
- setEnabled(false);
-}
-
-bool GroupBox::isDisabled()
-{
- return isEnabled() == false;
-}
-void GroupBox::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void GroupBox::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
+ addChildren(node);
}
-void GroupBox::setVisibility(bool visible)
+GroupBox::~GroupBox()
{
- setVisible(visible);
+ // delete groupbox;
}
diff --git a/client/widgets/groupbox.h b/client/widgets/groupbox.h
index ed848f7..bf12765 100644
--- a/client/widgets/groupbox.h
+++ b/client/widgets/groupbox.h
@@ -28,24 +28,23 @@
#define __PRACRO_GROUPBOX_H__
#include "widget.h"
-#include <QGroupBox>
+
#include <QDomNode>
-class GroupBox : public QGroupBox, public Widget
+class QGroupBox;
+class GroupBox : public Widget
{
public:
GroupBox(QDomNode &node, MacroWindow *macrowindow);
+ ~GroupBox();
- void disable();
- void enable();
- bool isDisabled();
+ QString value() { return ""; }
+ void setValue(QString, QString) {}
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
+ void setWdgValid(bool) {}
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
- void setVisibility(bool visible);
+private:
+ QGroupBox *groupbox;
};
#endif/*__PRACRO_GROUPBOX_H__*/
diff --git a/client/widgets/label.cc b/client/widgets/label.cc
index fc81099..d9a5814 100644
--- a/client/widgets/label.cc
+++ b/client/widgets/label.cc
@@ -27,68 +27,46 @@
#include "label.h"
#include <stdio.h>
+#include <QLabel>
+
#include "common.h"
Label::Label(QDomNode &node, MacroWindow *macrowindow)
- : QLabel(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
+ label = new QLabel();
+ widget = label;
+
QDomElement elem = node.toElement();
- setCommonAttributes(this, node);
+ setCommonAttributes(label, node);
- setWordWrap(true);
+ label->setWordWrap(true);
if(elem.hasAttribute("caption")) {
- setText(elem.attribute("caption"));
+ label->setText(elem.attribute("caption"));
} else {
- setText(elem.attribute(""));
+ label->setText(elem.attribute(""));
}
// Check for horizontal alignment and set it up accordingly
if(elem.hasAttribute("alignment")) {
if(elem.attribute("alignment") == "left") {
- setAlignment(Qt::AlignLeft);
+ label->setAlignment(Qt::AlignLeft);
} else if (elem.attribute("alignment") == "center") {
- setAlignment(Qt::AlignHCenter);
+ label->setAlignment(Qt::AlignHCenter);
} else if (elem.attribute("alignment") == "right") {
- setAlignment(Qt::AlignRight);
+ label->setAlignment(Qt::AlignRight);
}
} else {
- setAlignment(Qt::AlignLeft);
+ label->setAlignment(Qt::AlignLeft);
}
// Always center vertically in the addressed space
- setAlignment(Qt::AlignVCenter);
-}
-
-void Label::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void Label::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-void Label::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
-void Label::enable()
-{
- setEnabled(true);
-}
-
-void Label::disable()
-{
- setEnabled(false);
+ label->setAlignment(Qt::AlignVCenter);
}
-bool Label::isDisabled()
+Label::~Label()
{
- return isEnabled() == false;
+ // delete label;
}
diff --git a/client/widgets/label.h b/client/widgets/label.h
index ff905a7..529a79e 100644
--- a/client/widgets/label.h
+++ b/client/widgets/label.h
@@ -28,27 +28,24 @@
#define __PRACRO_LABEL_H__
#include "widget.h"
-#include <QWidget>
-#include <QLabel>
+
#include <QDomNode>
-class Label : public QLabel, public Widget
+class QLabel;
+class Label : public Widget
{
Q_OBJECT
public:
Label(QDomNode &node, MacroWindow *macrowindow);
+ ~Label();
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
+ QString value() { return ""; }
+ void setValue(QString, QString) {}
- void setVisibility(bool visible);
+ void setWdgValid(bool) {}
- void disable();
- void enable();
- bool isDisabled();
+private:
+ QLabel *label;
};
#endif/*__PRACRO_LABEL_H__*/
diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc
index c3a799a..918f152 100644
--- a/client/widgets/lineedit.cc
+++ b/client/widgets/lineedit.cc
@@ -27,119 +27,78 @@
#include "lineedit.h"
#include <stdio.h>
+#include <QCoreApplication>
+#include <QLineEdit>
+#include <QEvent>
+#include <QKeyEvent>
+
#include "common.h"
LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow)
- : QLineEdit(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
+ lineedit = new QLineEdit();
+ widget = lineedit;
+
+ setCommonAttributes(lineedit, node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("readonly")) {
- if(elem.attribute("readonly") == "true" || elem.attribute("readonly") == "1") {
- setReadOnly(true);
- } else if(elem.attribute("readonly") == "false" || elem.attribute("readonly") == "0") {
- setReadOnly(false);
+ if(elem.attribute("readonly") == "true" ||
+ elem.attribute("readonly") == "1") {
+ lineedit->setReadOnly(true);
+ } else if(elem.attribute("readonly") == "false" ||
+ elem.attribute("readonly") == "0") {
+ lineedit->setReadOnly(false);
} else {
- printf("Unknown value of readonly: %s\n", elem.attribute("readonly").toStdString().c_str());
+ printf("Unknown value of readonly: %s\n",
+ elem.attribute("readonly").toStdString().c_str());
}
}
- connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed()));
- connect(this, SIGNAL(textEdited(QString)), this, SLOT(user_changed()));
+ connect(lineedit, SIGNAL(textChanged(QString)), this, SLOT(changed()));
+ connect(lineedit, SIGNAL(textEdited(QString)), this, SLOT(user_changed()));
- installEventFilter(this); // Detect keyboard input.
+ installEventFilter(lineedit); // Detect keyboard input.
}
-void LineEdit::changed()
+LineEdit::~LineEdit()
{
- QPalette palette;
-
- if(isEnabled()) {
- if(regexpValidator()) {
- if(luaValidator()) {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200)));
- }
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- }
- } else {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- }
+ printf("Delete (LineEdit) %p\n", this); fflush(stdout);
+ // delete lineedit;
+}
- setPalette(palette);
+void LineEdit::changed()
+{
+ eventOnChange();
}
void LineEdit::user_changed()
{
emit wasChanged();
+ eventOnChange();
}
-QString LineEdit::getValue()
+QString LineEdit::value()
{
- return text();
+ return lineedit->text();
}
void LineEdit::setValue(QString value, QString source)
{
if(isUserSource(source)) emit wasChanged();
- if(text() == value) setText(value + " "); // Hack to make sure the textChanged signal is emitted.
- setText(value);
+ if(lineedit->text() == value)
+ lineedit->setText(value + " "); // Hack to make sure the textChanged signal is emitted.
+ lineedit->setText(value);
setInitialValue(value);
}
-void LineEdit::enable()
-{
- setEnabled(true);
-}
-
-void LineEdit::disable()
-{
- setEnabled(false);
-}
-
-bool LineEdit::isDisabled()
-{
- return isEnabled() == false;
-}
-
-void LineEdit::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void LineEdit::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-bool LineEdit::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void LineEdit::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
-
-#include <QCoreApplication>
bool LineEdit::eventFilter(QObject *, QEvent *event)
{
- if (event->type() == QEvent::KeyPress) {
+ if(event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Return ||
keyEvent->key() == Qt::Key_Enter) {
@@ -156,3 +115,18 @@ void LineEdit::changeEvent(QEvent *event)
changed();
}
}
+
+void LineEdit::setWdgValid(bool valid)
+{
+ 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)));
+ }
+
+ lineedit->setPalette(palette);
+}
diff --git a/client/widgets/lineedit.h b/client/widgets/lineedit.h
index 556e52c..90fac75 100644
--- a/client/widgets/lineedit.h
+++ b/client/widgets/lineedit.h
@@ -28,44 +28,32 @@
#define __PRACRO_LINEEDIT_H__
#include "widget.h"
-#include <QLineEdit>
-#include <QWidget>
-#include <QDomNode>
-class LineEdit : public QLineEdit, public Widget
+class QLineEdit;
+class QEvent;
+class LineEdit : public Widget
{
Q_OBJECT
public:
LineEdit(QDomNode &node, MacroWindow *macrowindow);
+ ~LineEdit();
- QString getValue();
- void setValue(QString value, QString source = "");
+ QString value();
+ void setValue(QString value, QString source);
- void enable();
- void disable();
- bool isDisabled();
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- bool setKeyboardFocus();
- void setVisibility(bool visible);
+ void setWdgValid(bool valid);
public slots:
void changed();
void user_changed();
-signals:
- void wasChanged();
-
protected:
void changeEvent(QEvent *event);
private:
bool eventFilter(QObject *, QEvent *event);
+
+ QLineEdit *lineedit;
};
#endif/*__PRACRO_LINEEDIT_H__*/
diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc
index bddc34f..da234ab 100644
--- a/client/widgets/listbox.cc
+++ b/client/widgets/listbox.cc
@@ -25,7 +25,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "listbox.h"
+
#include <QListWidgetItem>
+#include <QListWidget>
#include "common.h"
@@ -69,32 +71,41 @@ static QListWidgetItem *createItem(QDomElement &elem)
}
ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow)
- : QListWidget(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
+ listwidget = new QListWidget();
+ widget = listwidget;
+
valueIsChangingByComputer = false;
- setCommonAttributes(this, node);
+ setCommonAttributes(listwidget, node);
QDomNodeList children = node.childNodes();
for (int i=0; i < children.count(); i++) {
QDomNode child = children.at(i);
QDomElement list_elem = child.toElement();
- addItem(createItem(list_elem));
+ listwidget->addItem(createItem(list_elem));
}
- connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(changed()));
+ connect(listwidget, SIGNAL(itemSelectionChanged()), this, SLOT(changed()));
+}
+
+ListBox::~ListBox()
+{
+ // delete listwidget;
}
-bool ListBox::isValid()
+bool ListBox::preValid()
{
- return selectedItems().size() != 0;
+ return listwidget->selectedItems().size() != 0;
}
-QString ListBox::getValue()
+QString ListBox::value()
{
QString value = "none";
- if(currentRow() != -1) value = currentItem()->data(Qt::UserRole).toString();
+ if(listwidget->currentRow() != -1)
+ value = listwidget->currentItem()->data(Qt::UserRole).toString();
return value;
}
@@ -105,56 +116,33 @@ void ListBox::setValue(QString value, QString source)
valueIsChangingByComputer = true;
int sel = -1; // -1 is default for none selected
- for(int i = 0; i < count(); i++) {
- QListWidgetItem *listitem = item(i);
+ for(int i = 0; i < listwidget->count(); i++) {
+ QListWidgetItem *listitem = listwidget->item(i);
if(listitem->data(Qt::UserRole).toString() == value) sel = i;
}
- setCurrentRow(sel);
+ listwidget->setCurrentRow(sel);
setInitialValue(value);
valueIsChangingByComputer = false;
}
-void ListBox::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void ListBox::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-void ListBox::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
void ListBox::changed()
{
if(!valueIsChangingByComputer) emit wasChanged();
}
-bool ListBox::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void ListBox::enable()
+void ListBox::setWdgValid(bool valid)
{
- setEnabled(true);
-}
+ QPalette palette;
-void ListBox::disable()
-{
- setEnabled(false);
-}
+ 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)));
+ }
-bool ListBox::isDisabled()
-{
- return isEnabled() == false;
+ listwidget->setPalette(palette);
}
diff --git a/client/widgets/listbox.h b/client/widgets/listbox.h
index b48e258..d775655 100644
--- a/client/widgets/listbox.h
+++ b/client/widgets/listbox.h
@@ -28,41 +28,29 @@
#define __PRACRO_LISTBOX_H__
#include "widget.h"
+
#include <QDomNode>
-#include <QListWidget>
-class ListBox : public QListWidget, public Widget
+class QListWidget;
+class ListBox : public Widget
{
Q_OBJECT
public:
ListBox(QDomNode &node, MacroWindow *macrowindow);
+ ~ListBox();
- bool isValid();
- QString getValue();
- void setValue(QString value, QString source = "");
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
+ QString value();
+ void setValue(QString value, QString source);
- void setVisibility(bool visible);
-
- bool setKeyboardFocus();
-
- void disable();
- void enable();
- bool isDisabled();
+ bool preValid();
+ void setWdgValid(bool valid);
public slots:
void changed();
-signals:
- void wasChanged();
-
private:
bool valueIsChangingByComputer;
+ QListWidget *listwidget;
};
#endif/*__PRACRO_LISTBOX_H__*/
diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc
index 5933212..9634c76 100644
--- a/client/widgets/metawidget.cc
+++ b/client/widgets/metawidget.cc
@@ -28,19 +28,24 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
+#include <QFrame>
#include "messagebox.h"
-
#include "widgetbuilder.h"
#include "formatparser.h"
-
+#include "macrowindow.h"
#include "common.h"
MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow)
- : QFrame(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
- setCommonLayout(this, node);
+ frame = new QFrame();
+ widget = frame;
+
+ setCommonAttributes(frame, node);
+ setCommonLayout(frame, node);
+
+ hideChildren = true;
QDomElement elem = node.toElement();
storechildren = elem.attribute("storechildren", "false") == "true";
@@ -49,10 +54,8 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow)
QDomNodeList children = node.childNodes();
for (int i=0; i<children.count();i++) {
QDomNode child = children.at(i);
- widgets += widgetBuilder(child, this, macrowindow, false);
+ widgetBuilder(child);
}
- if(storechildren) macrowindow->addWidgets(widgets);
- else macrowindow->addAuxWidgets(widgets);
// Setup format string
if(elem.hasAttribute("formatlanguage")) {
@@ -73,23 +76,30 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow)
}
}
+ addChildren(node);
+
// 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()));
+ connect(w, SIGNAL(wasChanged()), this, SLOT(changed()));
i++;
}
}
+MetaWidget::~MetaWidget()
+{
+ // delete frame;
+}
+
void MetaWidget::changed()
{
emit wasChanged();
}
-QString MetaWidget::getValue()
+QString MetaWidget::value()
{
- return format_parser(format, widgets, formatlanguage);
+ return format_parser(format, this, formatlanguage);
}
void MetaWidget::setValue(QString, QString)
@@ -97,52 +107,25 @@ void MetaWidget::setValue(QString, QString)
// Nothing reasonable we can do here.
}
-void MetaWidget::enable()
-{
- setEnabled(true);
-}
-
-void MetaWidget::disable()
-{
- setEnabled(false);
-}
-
-bool MetaWidget::isDisabled()
-{
- return isEnabled() == false;
-}
-
-bool MetaWidget::isValid()
+bool MetaWidget::preValid()
{
// 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) {
+ if(w->enabled() && !w->local() && !w->valid()) {
MessageBox::critical(NULL, "Fejl",
- "Et af inputfelterne (" + w->name()
- + ") er ikke udfyldt korrekt, prøv igen.\n"
- , MessageBox::Ok);
+ "Et af inputfelterne (" + w->name()
+ + ") er ikke udfyldt korrekt, prøv igen.\n",
+ MessageBox::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);
+ return true;
}
bool MetaWidget::setKeyboardFocus()
@@ -169,7 +152,17 @@ void MetaWidget::reset()
}
}
-void MetaWidget::setVisibility(bool visible)
+void MetaWidget::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);
}
diff --git a/client/widgets/metawidget.h b/client/widgets/metawidget.h
index 022197a..dd32adf 100644
--- a/client/widgets/metawidget.h
+++ b/client/widgets/metawidget.h
@@ -28,50 +28,41 @@
#define __PRACRO_METAWIDGET_H__
#include "widget.h"
-#include <QFrame>
+
#include <QDomNode>
#include <QListWidget>
#include <QVector>
-class MetaWidget : public QFrame, public Widget
+class QFrame;
+class MetaWidget : public Widget
{
Q_OBJECT
public:
MetaWidget(QDomNode &node, MacroWindow *macrowindow);
+ ~MetaWidget();
- QString getValue();
- void setValue(QString value, QString source = "");
-
- bool isValid();
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
+ QString value();
+ void setValue(QString value, QString source);
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
+ bool preValid();
+ void setWdgValid(bool valid);
bool setKeyboardFocus();
- void setVisibility(bool visible);
void reset();
- void disable();
- void enable();
- bool isDisabled();
-
public slots:
void changed();
-signals:
- void wasChanged();
-
private:
QListWidget *list;
QVector< Widget* > widgets;
QString format;
QString formatlanguage;
bool storechildren;
+
+ QFrame *frame;
};
#endif/*__PRACRO_METAWIDGET_H__*/
diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc
index 01a2d77..2c4438f 100644
--- a/client/widgets/multilist.cc
+++ b/client/widgets/multilist.cc
@@ -30,44 +30,52 @@
#include <QVBoxLayout>
#include <QGridLayout>
#include <QPushButton>
+#include <QFrame>
+#include <QLabel>
+#include <QEvent>
+#include <QKeyEvent>
#include "messagebox.h"
-
#include "widgetbuilder.h"
-
#include "common.h"
+#include "macrowindow.h"
MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow)
- : QFrame(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
+ frame = new QFrame();
+ widget = frame;
+
+ hideChildren = true;
+
innerwidget_has_changes = false;
- setCommonAttributes(this, node);
+ setCommonAttributes(frame, node);
QGridLayout *layout = new QGridLayout();
- setLayout(layout);
+ frame->setLayout(layout);
- list = new QListWidget(this);
+ list = new QListWidget(frame);
layout->addWidget(list, 0, 0, 1, 2, Qt::AlignTop);
list->installEventFilter(this);
- QPushButton *add = new QPushButton(this);
+ QPushButton *add = new QPushButton(frame);
connect(add, SIGNAL(clicked()), this, SLOT(add()));
add->setText(tr("Add to list"));
add->setIcon(QIcon(QPixmap(":icons/add.png")));
layout->addWidget(add, 1, 0, 1, 1, Qt::AlignTop);
- QPushButton *rem = new QPushButton(this);
+ QPushButton *rem = new QPushButton(frame);
connect(rem, SIGNAL(clicked()), this, SLOT(remove()));
rem->setText(tr("Remove from list"));
rem->setIcon(QIcon(QPixmap(":icons/del.png")));
layout->addWidget(rem, 1, 1, 1, 1, Qt::AlignTop);
- QLabel *arrows = new QLabel();
+ QLabel *arrows = new QLabel(frame);
arrows->setPixmap(QPixmap(":icons/arrows.png"));
layout->addWidget(arrows, 2, 0, 1, 2, Qt::AlignHCenter);
- QWidget *inputbox = new QWidget(this);
+ QWidget *inputbox = new QWidget(frame);
inputbox->setContentsMargins(0,0,0,0);
layout->addWidget(inputbox, 3, 0, 1, 2, Qt::AlignTop);
@@ -87,29 +95,16 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow)
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, false);
- }
- macrowindow->addAuxWidgets(widgets);
+ addChildren(node);
innerwidget = NULL;
if(elem.hasAttribute("innerwidget")) {
- QString iwname = elem.attribute("innerwidget");
- QVector< Widget* >::iterator ws = widgets.begin();
- while(ws != widgets.end()) {
- if((*ws)->name() == iwname) {
- innerwidget = *ws;
- innerwidget->connectFrom(SIGNAL(wasChanged()), this, SLOT(changed()));
- }
- ws++;
- }
- if(innerwidget == NULL) {
+ innerwidget = findWidget(elem.attribute("innerwidget"), true);
+ if(innerwidget) {
+ connect(innerwidget, SIGNAL(wasChanged()), this, SLOT(changed()));
+ } else {
printf("ERROR: Inner Widget %s not found (in multilist)!\n",
- iwname.toStdString().c_str());
+ elem.attribute("innerwidget").toStdString().c_str());
}
} else {
printf("ERROR: Missing 'innerwidget' attribute on multilist!\n");
@@ -118,6 +113,11 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow)
layout->setContentsMargins(0,0,0,0);
}
+MultiList::~MultiList()
+{
+ // delete frame;
+}
+
void MultiList::changed()
{
innerwidget_has_changes = true;
@@ -125,7 +125,7 @@ void MultiList::changed()
}
-bool MultiList::isValid()
+bool MultiList::preValid()
{
if(innerwidget_has_changes) {
switch(MessageBox::warning(NULL,
@@ -134,7 +134,7 @@ bool MultiList::isValid()
"Ønsker du at tilføje ændringen til listen inden du gemmer makroen?",
MessageBox::Save | MessageBox::Close | MessageBox::Cancel)) {
case MessageBox::Save:
- if(innerwidget && innerwidget->isValid()) {
+ if(innerwidget && innerwidget->valid()) {
add();
} else {
return false;
@@ -150,10 +150,10 @@ bool MultiList::isValid()
}
}
- return regexpValidator() && luaValidator();
+ return true;
}
-QString MultiList::getValue()
+QString MultiList::value()
{
QString values;
@@ -186,7 +186,7 @@ void MultiList::setValue(QString values, QString source)
setInitialValue(values);
- luaValidator();
+ eventOnChange();
}
void MultiList::remove()
@@ -196,50 +196,23 @@ void MultiList::remove()
if(item && item->isSelected()) {
delete item;
emit wasChanged();
- luaValidator();
+ eventOnChange();
}
}
void MultiList::add()
{
- if(innerwidget && innerwidget->isValid()) {
- list->addItem(innerwidget->getValue());
+ if(innerwidget && innerwidget->valid()) {
+ list->addItem(innerwidget->value());
emit wasChanged();
innerwidget->reset();
innerwidget_has_changes = false;
- luaValidator();
+ eventOnChange();
}
}
-void MultiList::enable()
-{
- setEnabled(true);
-}
-
-void MultiList::disable()
-{
- setEnabled(false);
-}
-
-bool MultiList::isDisabled()
-{
- return isEnabled() == false;
-}
-
-void MultiList::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void MultiList::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
bool MultiList::setKeyboardFocus()
{
if(innerwidget) return innerwidget->setKeyboardFocus();
@@ -255,7 +228,17 @@ bool MultiList::eventFilter(QObject *obj, QEvent *event)
return QObject::eventFilter(obj, event);
}
-void MultiList::setVisibility(bool visible)
+void MultiList::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);
}
diff --git a/client/widgets/multilist.h b/client/widgets/multilist.h
index 3b0f51e..8e806fa 100644
--- a/client/widgets/multilist.h
+++ b/client/widgets/multilist.h
@@ -28,44 +28,33 @@
#define __PRACRO_MULTILIST_H__
#include "widget.h"
-#include <QFrame>
+
#include <QDomNode>
#include <QListWidget>
#include <QVector>
-class MultiList : public QFrame, public Widget
+class QFrame;
+class MultiList : public Widget
{
Q_OBJECT
public:
MultiList(QDomNode &node, MacroWindow *macrowindow);
+ ~MultiList();
- QString getValue();
+ QString value();
void setValue(QString value, QString source = "");
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
+ bool preValid();
+ void setWdgValid(bool valid);
bool setKeyboardFocus();
- void setVisibility(bool visible);
-
- void disable();
- void enable();
- bool isDisabled();
-
- bool isValid();
public slots:
void changed();
void remove();
void add();
-signals:
- void wasChanged();
-
protected:
bool eventFilter(QObject *obj, QEvent *event);
@@ -74,6 +63,8 @@ private:
Widget *innerwidget;
QString format;
bool innerwidget_has_changes;
+
+ QFrame *frame;
};
#endif/*__PRACRO_MULTILIST_H__*/
diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc
index 6646f59..a315577 100644
--- a/client/widgets/radiobutton.cc
+++ b/client/widgets/radiobutton.cc
@@ -25,6 +25,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "radiobutton.h"
+
#include <QRadioButton>
#include "common.h"
diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc
index e4555ff..7f1bda7 100644
--- a/client/widgets/radiobuttons.cc
+++ b/client/widgets/radiobuttons.cc
@@ -25,18 +25,23 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "radiobuttons.h"
-#include "radiobutton.h"
-#include <QRadioButton>
+
+#include <QEvent>
#include <QHBoxLayout>
#include <QVBoxLayout>
+#include <QFrame>
#include "common.h"
+#include "radiobutton.h"
RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow)
- : QFrame(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
- setCommonLayout(this, node);
+ frame = new QFrame();
+ widget = frame;
+
+ setCommonAttributes(frame, node);
+ setCommonLayout(frame, node);
QDomNodeList children = node.childNodes();
@@ -46,17 +51,22 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow)
RadioButton *radiobutton = new RadioButton(child);
// Create radiobutton from child, insert in this
- layout()->addWidget(radiobutton);
+ frame->layout()->addWidget(radiobutton);
connect(radiobutton, SIGNAL(clicked()), this, SLOT(childChanged()));
radiobutton_list.push_back(radiobutton);
}
- layout()->setContentsMargins(0,0,0,0);
+ frame->layout()->setContentsMargins(0,0,0,0);
}
-bool RadioButtons::setBGColor(bool valid)
+RadioButtons::~RadioButtons()
+{
+ // delete frame;
+}
+
+void RadioButtons::setWdgValid(bool valid)
{
QPalette palette;
@@ -72,35 +82,32 @@ bool RadioButtons::setBGColor(bool valid)
RadioButton *widget = *i;
widget->setPalette(palette);
}
-
- return valid;
}
-bool RadioButtons::isValid()
+bool RadioButtons::preValid()
{
- if(!regexpValidator()) return setBGColor(false);
- if(!luaValidator()) return setBGColor(false);
-
QVector< RadioButton* >::iterator i;
for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) {
- RadioButton *widget = *i;
- if(widget->isChecked()) {
- return setBGColor(true);
+ RadioButton *rbtn = *i;
+ if(rbtn->isChecked()) {
+ return true;
}
}
-
- return setBGColor(false);
+ return false;
}
-QString RadioButtons::getValue()
+QString RadioButtons::value()
{
QVector< RadioButton* >::iterator i;
QString value;
for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) {
- RadioButton *widget = *i;
- if(widget->isChecked()) {
- printf("Radiobutton returned: %s\n", widget->getValue().toStdString().c_str());
- value = widget->getValue();
+ RadioButton *rbtn = *i;
+ if(rbtn->isChecked()) {
+ /*
+ printf("Radiobutton returned: %s\n",
+ rbtn->getValue().toStdString().c_str());
+ */
+ value = rbtn->getValue();
}
}
return value;
@@ -112,29 +119,15 @@ void RadioButtons::setValue(QString value, QString source)
QVector< RadioButton* >::iterator i;
for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) {
- RadioButton *widget = *i;
- if(value == widget->getValue()) {
- widget->setChecked(true);
+ RadioButton *rbtn = *i;
+ if(value == rbtn->getValue()) {
+ rbtn->setChecked(true);
} else {
- widget->setChecked(false);
+ rbtn->setChecked(false);
}
}
setInitialValue(value);
-
- isValid();
-}
-
-void RadioButtons::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void RadioButtons::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
}
bool RadioButtons::setKeyboardFocus()
@@ -157,36 +150,15 @@ bool RadioButtons::setKeyboardFocus()
return false;
}
-void RadioButtons::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
void RadioButtons::childChanged()
{
- isValid();
-
+ eventOnChange();
emit wasChanged();
}
-void RadioButtons::enable()
-{
- setEnabled(true);
-}
-
-void RadioButtons::disable()
-{
- setEnabled(false);
-}
-
-bool RadioButtons::isDisabled()
-{
- return isEnabled() == false;
-}
-
void RadioButtons::changeEvent(QEvent *event)
{
if(event->type() == QEvent::EnabledChange) {
- setBGColor(isValid() || !isEnabled());
+ // setWdgValid(valid() || !frame->isEnabled());
}
}
diff --git a/client/widgets/radiobuttons.h b/client/widgets/radiobuttons.h
index 9b165c9..b83f7a9 100644
--- a/client/widgets/radiobuttons.h
+++ b/client/widgets/radiobuttons.h
@@ -27,49 +27,39 @@
#ifndef __PRACRO_RADIOBUTTONS_H__
#define __PRACRO_RADIOBUTTONS_H__
-#include "widget.h"
-#include "widgets/radiobutton.h"
-#include <QFrame>
#include <QDomNode>
#include <QVector>
-#include <QRadioButton>
-class RadioButtons : public QFrame, public Widget
+#include "widget.h"
+
+class QFrame;
+class QEvent;
+class RadioButton;
+class RadioButtons : public Widget
{
Q_OBJECT
public:
RadioButtons(QDomNode &node, MacroWindow *macrowindow);
+ ~RadioButtons();
- bool isValid();
- QString getValue();
- void setValue(QString value, QString source = "");
+ QString value();
+ void setValue(QString value, QString source);
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
+ bool preValid();
+ void setWdgValid(bool valid);
bool setKeyboardFocus();
- void setVisibility(bool visible);
-
- void disable();
- void enable();
- bool isDisabled();
public slots:
void childChanged();
-signals:
- void wasChanged();
-
protected:
void changeEvent(QEvent *event);
private:
QVector < RadioButton* > radiobutton_list;
- bool setBGColor(bool valid);
+ QFrame *frame;
};
#endif/*__PRACRO_RADIOBUTTONS_H__*/
diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc
index 83ef62a..0b7ddde 100644
--- a/client/widgets/textedit.cc
+++ b/client/widgets/textedit.cc
@@ -25,62 +25,59 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "textedit.h"
-#include <QPalette>
+#include <QPalette>
+#include <QTextEdit>
#include <stdio.h>
#include "common.h"
TextEdit::TextEdit(QDomNode &node, MacroWindow *macrowindow)
- : QTextEdit(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
+ textedit = new QTextEdit();
+ widget = textedit;
+
+ setCommonAttributes(textedit, node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("readonly")) {
- if(elem.attribute("readonly") == "true" || elem.attribute("readonly") == "1") {
- setReadOnly(true);
- } else if(elem.attribute("readonly") == "false" || elem.attribute("readonly") == "0") {
- setReadOnly(false);
+ if(elem.attribute("readonly") == "true" ||
+ elem.attribute("readonly") == "1") {
+ textedit->setReadOnly(true);
+ } else if(elem.attribute("readonly") == "false" ||
+ elem.attribute("readonly") == "0") {
+ textedit->setReadOnly(false);
} else {
- printf("Unknown value of readonly: %s\n", elem.attribute("readonly").toStdString().c_str());
+ printf("Unknown value of readonly: %s\n",
+ elem.attribute("readonly").toStdString().c_str());
}
}
- connect(this, SIGNAL(textChanged()), this, SLOT(changed()));
- installEventFilter(this); // Detect keyboard input.
+ connect(textedit, SIGNAL(textChanged()), this, SLOT(changed()));
+ textedit->installEventFilter(this); // Detect keyboard input.
}
-void TextEdit::changed()
+TextEdit::~TextEdit()
{
- QPalette palette;
-
- if(regexpValidator()) {
- if(luaValidator()) {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200)));
- }
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- }
+ //delete textedit;
+}
- setPalette(palette);
+void TextEdit::changed()
+{
+ eventOnChange();
}
-QString TextEdit::getValue()
+QString TextEdit::value()
{
- return QTextEdit::toPlainText();
+ return textedit->toPlainText();
}
void TextEdit::setValue(QString value, QString source)
{
if(isUserSource(source)) emit wasChanged();
- setText(value);
+ textedit->setText(value);
setInitialValue(value);
}
@@ -93,40 +90,17 @@ bool TextEdit::eventFilter(QObject *, QEvent *event)
return false;
}
-void TextEdit::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void TextEdit::connectTo(const QObject *sender, const char *signal,
- const char *method)
+void TextEdit::setWdgValid(bool valid)
{
- connect(sender, signal, this, method);
-}
-
-bool TextEdit::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void TextEdit::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
-void TextEdit::enable()
-{
- setEnabled(true);
-}
+ QPalette palette;
-void TextEdit::disable()
-{
- setEnabled(false);
-}
+ 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)));
+ }
-bool TextEdit::isDisabled()
-{
- return isEnabled() == false;
+ textedit->setPalette(palette);
}
diff --git a/client/widgets/textedit.h b/client/widgets/textedit.h
index f3e1989..86d6e42 100644
--- a/client/widgets/textedit.h
+++ b/client/widgets/textedit.h
@@ -28,36 +28,22 @@
#define __PRACRO_TEXTEDIT_H__
#include "widget.h"
-#include <QTextEdit>
-#include <QWidget>
+
#include <QDomNode>
#include <QKeyEvent>
-class TextEdit : public QTextEdit, public Widget
+class QTextEdit;
+class TextEdit : public Widget
{
Q_OBJECT
public:
TextEdit(QDomNode &node, MacroWindow *macrowindow);
+ ~TextEdit();
- QString getValue();
- void setValue(QString value, QString source = "");
-
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- bool setKeyboardFocus();
+ QString value();
+ void setValue(QString value, QString source);
- void setVisibility(bool visible);
-
- void disable();
- void enable();
- bool isDisabled();
-
-signals:
- void wasChanged();
+ void setWdgValid(bool valid);
public slots:
void changed();
@@ -65,6 +51,9 @@ public slots:
protected:
bool eventFilter(QObject *obj, QEvent *event);
+
+private:
+ QTextEdit *textedit;
};
#endif/*__PRACRO_TEXTEDIT_H__*/
diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc
index c17633f..af03843 100644
--- a/client/widgets/widget.cc
+++ b/client/widgets/widget.cc
@@ -26,43 +26,77 @@
*/
#include "widget.h"
+#include "macrowindow.h"
+#include "lua.h"
+
+#include "../widgets.h"
+#include <QLayout>
+#include <QObject>
+
Widget::Widget(QDomNode &node, MacroWindow *macrowindow)
{
+ widget = NULL;
+
QDomElement elem = node.toElement();
this->macrowindow = macrowindow;
+ this->lua = macrowindow->lua;
widget_type = elem.tagName();
if(elem.hasAttribute("name")) {
widget_name = elem.attribute("name");
- } else {
- if(elem.tagName() != "frame" && elem.tagName() != "label"
- && elem.tagName() != "button" && elem.tagName() != "widgets")
- printf("XML ERROR!! Unnamed widget of type: %s\n",
- elem.tagName().toStdString().c_str());
}
+ widget_local =
+ elem.hasAttribute("local") && elem.attribute("local") == "true";
+
if(elem.hasAttribute("prefilled")) {
prefilled = elem.attribute("prefilled");
}
- if(elem.hasAttribute("script")) {
- luaprogram = elem.attribute("script");
- hasluaprogram = true;
- } else {
- hasluaprogram = false;
+ has_initial_value = false;
+ initial_value = "";
+
+ if((hasOnChangeEvent = elem.hasAttribute("onChange"))) {
+ onChangeEventScript = elem.attribute("onChange");
}
-
- if(elem.hasAttribute("regexp")) {
- rx = QRegExp(elem.attribute("regexp"));
- hasregexpvalidator = true;
- } else {
- hasregexpvalidator = false;
+
+ is_valid = true;
+
+ printf("Create Widget '%s' of type '%s'\n",
+ name().toStdString().c_str(),
+ type().toStdString().c_str());
+}
+
+Widget::~Widget()
+{
+ printf("Delete Widget '%s' of type '%s'\n",
+ name().toStdString().c_str(),
+ type().toStdString().c_str());
+
+ /* // This is done by Qt
+ if(widget) {
+ delete widget;
+ widget = NULL;
+ }
+ */
+ QVector< Widget* >::iterator i = children.begin();
+ while(i != children.end()) {
+ if(*i) delete *i;
+ i++;
}
- has_initial_value = false;
- initial_value = "";
+ children.clear();
+}
+
+void Widget::addChildren(QDomNode &node)
+{
+ QDomNodeList children = node.childNodes();
+ for (int i=0; i<children.count();i++) {
+ QDomNode child = children.at(i);
+ widgetBuilder(child);
+ }
}
QString Widget::name()
@@ -75,29 +109,29 @@ QString Widget::type()
return widget_type;
}
-void Widget::setValue(QString, QString)
+bool Widget::local()
{
+ return widget_local;
}
-bool Widget::isValid()
+bool Widget::valid()
{
- return regexpValidator() && luaValidator();
-}
+ if(preValid() == false) return false;
+ if(is_valid == false) return false;
+
+ QVector< Widget* >::iterator i = children.begin();
+ while(i != children.end()) {
+ if((*i)->valid() == false) return false;
+ i++;
+ }
-bool Widget::regexpValidator()
-{
- return !hasregexpvalidator || rx.exactMatch(getValue());
+ return true;
}
-bool Widget::luaValidator()
-{
- if(!hasluaprogram) return true;
-
- QString program = "";
-
- program += luaprogram;
-
- return macrowindow->lua->runValidator(program, this, name(), getValue());
+void Widget::setValid(bool valid)
+{
+ is_valid = valid;
+ setWdgValid(valid);
}
void Widget::setInitialValue(QString value)
@@ -113,8 +147,192 @@ bool Widget::hasInitialValue()
return has_initial_value;
}
-
void Widget::reset()
{
- setValue(initial_value);
+ setValue(initial_value, "");
+}
+
+void Widget::eventOnChange()
+{
+ if(enabled() && hasOnChangeEvent)
+ lua->runScript(onChangeEventScript, this, "onChange");
+}
+
+void Widget::setEnabled(bool enabled)
+{
+ widget->setEnabled(enabled);
+}
+
+bool Widget::enabled()
+{
+ return widget->isEnabled();
+}
+
+void Widget::setVisible(bool visible)
+{
+ widget->setVisible(visible);
+}
+
+bool Widget::visible()
+{
+ return widget->isVisible();
+}
+
+bool Widget::setKeyboardFocus()
+{
+ widget->setFocus();
+ return true;
+}
+
+Widget *Widget::findWidget(QString n, bool deep)
+{
+ printf("Find Widget %p\n", this); fflush(stdout);
+
+ if(n == name()) return this;
+
+ if(hideChildren && deep == false) return NULL;
+
+ QVector< Widget* >::iterator i = children.begin();
+ while(i != children.end()) {
+ Widget *w = (*i)->findWidget(n, deep);
+ if(w) return w;
+ i++;
+ }
+
+ return NULL;
+}
+
+QVector< Widget* > Widget::widgetList(bool deep)
+{
+ printf("Widget List %p\n", this); fflush(stdout);
+
+ QVector< Widget* > lst = children;
+
+ if(hideChildren && deep == false) return lst;
+
+ QVector< Widget* >::iterator i = children.begin();
+ while(i != children.end()) {
+ lst += (*i)->widgetList(deep);
+ i++;
+ }
+
+ return lst;
+}
+
+void Widget::childWasChanged()
+{
+ emit wasChanged();
+}
+
+void Widget::addChild(Widget *widget)
+{
+ if(widget == NULL) {
+ printf("Trying to add NULL child to '%s'\n", name().toStdString().c_str());
+ return;
+ }
+ children.push_back(widget);
+ connect(widget, SIGNAL(wasChanged()), this, SLOT(childWasChanged()));
+}
+
+void Widget::widgetBuilder(QDomNode &xml_node)
+{
+ QDomElement xml_elem = xml_node.toElement();
+
+
+ // TODO: Why do we do this??
+ if(xml_elem.hasAttribute("prefilled") &&
+ xml_elem.attribute("prefilled") != "pracro") {
+ macrowindow->macroChanged();
+ }
+
+ Widget *widget = NULL;
+ if(xml_elem.tagName() == "spacer") {
+
+ if(qwidget() && qwidget()->layout()) {
+ ((QBoxLayout*)qwidget()->layout())->addStretch();
+ }
+ return; // This is not a real widget.
+ } else if(xml_elem.tagName() == "frame") {
+
+ if(xml_elem.hasAttribute("caption")) {
+ GroupBox *frame = new GroupBox(xml_elem, macrowindow);
+ widget = frame;
+ } else {
+ Frame *frame = new Frame(xml_elem, macrowindow);
+ widget = frame;
+ }
+
+ } else if(xml_elem.tagName() == "label") {
+
+ Label *label = new Label(xml_elem, macrowindow);
+ widget = label;
+
+ } else if(xml_elem.tagName() == "lineedit") {
+
+ LineEdit *lineedit = new LineEdit(xml_elem, macrowindow);
+ widget = lineedit;
+
+ } else if(xml_elem.tagName() == "datetime") {
+
+ DateTime *datetime = new DateTime(xml_elem, macrowindow);
+ widget = datetime;
+
+ } else if(xml_elem.tagName() == "button") {
+
+ Button *button = new Button(xml_elem, macrowindow);
+ widget = button;
+
+ } else if(xml_elem.tagName() == "textedit") {
+
+ TextEdit *textedit = new TextEdit(xml_elem, macrowindow);
+ widget = textedit;
+
+ } else if(xml_elem.tagName() == "checkbox") {
+
+ CheckBox *checkbox = new CheckBox(xml_elem, macrowindow);
+ widget = checkbox;
+
+ } else if(xml_elem.tagName() == "radiobuttons") {
+
+ RadioButtons *radiobuttons = new RadioButtons(xml_elem, macrowindow);
+ widget = radiobuttons;
+
+ } else if(xml_elem.tagName() == "combobox") {
+
+ ComboBox *combobox = new ComboBox(xml_elem, macrowindow);
+ widget = combobox;
+
+ } else if(xml_elem.tagName() == "dbwidget") {
+
+ DBWidget *dbwidget = new DBWidget(xml_elem, macrowindow);
+ widget = dbwidget;
+
+ } else if(xml_elem.tagName() == "listbox") {
+
+ ListBox *listbox = new ListBox(xml_elem, macrowindow);
+ widget = listbox;
+
+ } else if(xml_elem.tagName() == "multilist") {
+
+ MultiList *multilist = new MultiList(xml_elem, macrowindow);
+ widget = multilist;
+
+ } else if(xml_elem.tagName() == "altcombobox") {
+
+ AltComboBox *altcombobox = new AltComboBox(xml_elem, macrowindow);
+ widget = altcombobox;
+
+ } else if(xml_elem.tagName() == "metawidget") {
+
+ MetaWidget *metawidget = new MetaWidget(xml_elem, macrowindow);
+ widget = metawidget;
+
+ }
+
+ addChild(widget);
+
+ if(qwidget() && qwidget()->layout())
+ qwidget()->layout()->addWidget(widget->qwidget());
+
+ if(widget && widget->qwidget()) widget->qwidget()->show();
}
diff --git a/client/widgets/widget.h b/client/widgets/widget.h
index 732dce9..9e493d0 100644
--- a/client/widgets/widget.h
+++ b/client/widgets/widget.h
@@ -30,64 +30,88 @@
#include <QString>
#include <QDomNode>
#include <QRegExp>
+#include <QObject>
+#include <QVector>
-#include "macrowindow.h"
#include "lua.h"
-class Widget {
+class MacroWindow;
+class LUA;
+class Widget;
+class Widget : public QObject {
+Q_OBJECT
public:
Widget(QDomNode &node, MacroWindow *macrowindow);
- virtual ~Widget(){}
+ virtual ~Widget();
- virtual QString getValue() { return ""; }
- virtual void setValue(QString value, QString source = "");
+ QString name();
+ QString type();
+ bool local();
- virtual bool isValid();
- virtual void setValid(bool valid) { valid = valid; }
+ virtual QString value() = 0;
+ virtual void setValue(QString value, QString source) = 0;
- virtual void disable() {}
- virtual void enable() {}
- virtual bool isDisabled() { return false; }
+ bool valid();
+ void setValid(bool valid);
- virtual void setVisibility(bool) {}
- virtual bool getVisibility() { return true; }
-
- QString name();
- QString type();
+ // Implement in subclasses to contribute to the validation.
+ virtual bool preValid() { return true; }
- /**
- * Connect some signal from this object to some slot in some other object.
- */
- virtual void connectFrom(const char *, const QObject *, const char *) {}
+ // Implement in subclasses to change widget according to validation status.
+ virtual void setWdgValid(bool valid) = 0;
- /**
- * Connect some signal from some other object to some slot in this object.
- */
- virtual void connectTo(const QObject *, const char *, const char *) {}
+ virtual void setEnabled(bool enabled);
+ virtual bool enabled();
+
+ virtual void setVisible(bool visible);
+ virtual bool visible();
- virtual bool setKeyboardFocus() { return false; }
+ virtual bool setKeyboardFocus();
void setInitialValue(QString value);
bool hasInitialValue();
virtual void reset();
+ QWidget *qwidget() { return widget; }
+
+ // Set deep to true to find widgets inside altcombobox, multilist and
+ // metawidgets.
+ Widget *findWidget(QString name, bool deep = false);
+ QVector< Widget* > widgetList(bool deep = false);
+ void addChild(Widget *widget);
+
+signals:
+ void wasChanged();
+
+public slots:
+ void childWasChanged();
+
protected:
- QString widget_name;
- QString widget_type;
+ /*
+ * LUA scripting events:
+ */
+ void eventOnChange();
+
+ QWidget *widget;
+ bool hideChildren;
- bool luaValidator();
- bool regexpValidator();
+ void widgetBuilder(QDomNode &xml_node);
+ void addChildren(QDomNode &xml_node);
private:
- QRegExp rx;
+ QVector< Widget* > children;
- bool hasregexpvalidator;
- bool hasluaprogram;
+ bool is_valid;
+ QString widget_name;
+ QString widget_type;
+ bool widget_local;
- QString luaprogram;
LUA *lua;
MacroWindow *macrowindow;
-
+
+ bool hasOnChangeEvent;
+ QString onChangeEventScript;
+
QString initial_value;
bool has_initial_value;
diff --git a/client/widgets/window.cc b/client/widgets/window.cc
index ea27321..f51cfd9 100644
--- a/client/widgets/window.cc
+++ b/client/widgets/window.cc
@@ -27,54 +27,39 @@
#include "window.h"
#include "common.h"
+#include <QWidget>
#include <QIcon>
Window::Window(QDomNode &node, MacroWindow *macrowindow)
- : QWidget(NULL), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setWindowFlags(Qt::WindowContextHelpButtonHint | Qt::WindowSystemMenuHint);
+ widget = new QWidget(NULL);
- setWindowIcon(QIcon(":/icons/icon.png"));
+ widget->setWindowFlags(Qt::WindowContextHelpButtonHint |
+ Qt::WindowSystemMenuHint);
- setCommonAttributes(this, node);
- setCommonLayout(this, node);
+ widget->setWindowIcon(QIcon(":/icons/icon.png"));
+
+ setCommonAttributes(widget, node);
+ setCommonLayout(widget, node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("fixed")) {
if(elem.attribute("fixed") == "true") {
- setFixedSize(width(), height());
+ widget->setFixedSize(widget->width(), widget->height());
}
}
if(elem.hasAttribute("caption")) {
- setWindowTitle(elem.attribute("caption"));
+ widget->setWindowTitle(elem.attribute("caption"));
}
-}
-
-void Window::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void Window::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-void Window::enable()
-{
- setEnabled(true);
-}
-void Window::disable()
-{
- setEnabled(false);
+ addChildren(node);
}
-bool Window::isDisabled()
+Window::~Window()
{
- return isEnabled() == false;
+ printf("Delete (Window) %p\n", this); fflush(stdout);
+ // delete widget;
}
diff --git a/client/widgets/window.h b/client/widgets/window.h
index 497c237..b7098d6 100644
--- a/client/widgets/window.h
+++ b/client/widgets/window.h
@@ -28,24 +28,18 @@
#define __PRACRO_WINDOW_H__
#include "widget.h"
-#include <QWidget>
#include <QDomNode>
-class Window : public QWidget, public Widget
+class Window : public Widget
{
public:
Window(QDomNode &node, MacroWindow *macrowindow);
+ ~Window();
- void connectFrom(const char *signal,
- const QObject *receiver, const char *method);
-
- void connectTo(const QObject *sender, const char *signal,
- const char *method);
-
- void disable();
- void enable();
- bool isDisabled();
+ QString value() { return ""; }
+ void setValue(QString, QString) {}
+ void setWdgValid(bool) {}
};
#endif/*__PRACRO_WINDOW_H__*/