From 9fcf15a06b9ec422dbad53508e8ce71d2d4145c3 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 13 Jan 2009 09:59:22 +0000 Subject: A huge amount of changes, based on the results of two usertest. The changes are contained (but not limited to) in the following list: - Make disabled widgets ignored in validation test. - Do not commit values of disabled widgets to the database. - Make storechildren attribute on metawidget, that enables storing of the child widgets in the database. - Implement LUA resume generator. - Make language attribute on resume tag, and switch parser (format/LUA). - Case insensitive search in combobox. - Click on macro name or line, expands macro. - Greyed out widgets in AltComboBox should be hidden instead. - Keyboard 'delete' should delete item from multilist. - "Commit" button needs to be more visible? Icon? - Upon opening of a second macro, the first macro should indicate itself as 'not saved'. - After 'add' in multilist, the input widgets should be reset. - First widget in a macro should have keyboard focus after expansion. - "Endnu ikke udfyldt" needs to be more clear (darker). - Meta widgets must recurse the isValid() call to its children. - Greyed out widgets must be hidden. - Multilist should be read as a list prior to its input fields. - Visible field on widgets. Hides a widget without disabling it. --- client/widgets/altcombobox.cc | 82 ++++++++++++++++++++++++---- client/widgets/altcombobox.h | 16 +++++- client/widgets/button.cc | 53 +++++++++++++++++- client/widgets/button.h | 17 +++++- client/widgets/checkbox.cc | 42 +++++++++++++-- client/widgets/checkbox.h | 19 ++++++- client/widgets/combobox.cc | 54 +++++++++++++++---- client/widgets/combobox.h | 18 ++++++- client/widgets/common.cc | 7 +++ client/widgets/common.h | 1 + client/widgets/datetime.cc | 120 +++++++++++++++++++++++++++++++++++++++++ client/widgets/datetime.h | 64 ++++++++++++++++++++++ client/widgets/dbwidget.cc | 35 +++++++++++- client/widgets/dbwidget.h | 17 +++++- client/widgets/frame.cc | 17 ++++++ client/widgets/frame.h | 7 +++ client/widgets/groupbox.cc | 17 ++++++ client/widgets/groupbox.h | 7 +++ client/widgets/label.cc | 16 ++++++ client/widgets/label.h | 7 +++ client/widgets/lineedit.cc | 35 +++++++++++- client/widgets/lineedit.h | 15 +++++- client/widgets/listbox.cc | 40 +++++++++++++- client/widgets/listbox.h | 23 +++++++- client/widgets/metawidget.cc | 115 +++++++++++++++++++++++++++------------ client/widgets/metawidget.h | 24 +++++++-- client/widgets/multilist.cc | 113 +++++++++++++++++++++++--------------- client/widgets/multilist.h | 25 +++++++-- client/widgets/radiobutton.h | 1 + client/widgets/radiobuttons.cc | 51 +++++++++++++++++- client/widgets/radiobuttons.h | 19 ++++++- client/widgets/textedit.cc | 37 ++++++++++++- client/widgets/textedit.h | 20 ++++++- client/widgets/widget.cc | 25 +++++---- client/widgets/widget.h | 33 ++++++++++-- client/widgets/window.cc | 12 +++++ client/widgets/window.h | 6 +++ 37 files changed, 1067 insertions(+), 143 deletions(-) create mode 100644 client/widgets/datetime.cc create mode 100644 client/widgets/datetime.h (limited to 'client/widgets') diff --git a/client/widgets/altcombobox.cc b/client/widgets/altcombobox.cc index 01fd36f..c68f816 100644 --- a/client/widgets/altcombobox.cc +++ b/client/widgets/altcombobox.cc @@ -33,6 +33,7 @@ #include "widgetbuilder.h" #include +#include "multilist.h" AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) @@ -45,7 +46,11 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) combobox = new ComboBox(node, macrowindow); layout()->addWidget(combobox); combobox->show(); - + + altframerepl = new QFrame(); + QHBoxLayout *l = new QHBoxLayout(); + altframerepl->setLayout(l); + l->addStretch(); altframe = new QFrame(); layout()->addWidget(altframe); @@ -87,7 +92,7 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) QDomNodeList children = item.childNodes(); for(int i = 0; i < children.count(); i++) { QDomNode child = children.at(i); - widgets += widgetBuilder(child, altframe, macrowindow); + widgets += widgetBuilder(child, altframe, macrowindow, false); } } @@ -108,22 +113,31 @@ AltComboBox::AltComboBox(QDomNode &node, MacroWindow *macrowindow) iwname.toStdString().c_str()); } + // To detect if the altvalue has been selected: connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(onValueChange(int))); connect(combobox, SIGNAL(editTextChanged(const QString&)), this, SLOT(onValueChange(const QString&))); + // To react to changes in any of the children: + connect(combobox, SIGNAL(wasChanged()), this, SLOT(onChildChange())); + innerwidget->connectFrom(SIGNAL(wasChanged()), this, SLOT(onChildChange())); + layout()->setContentsMargins(0,0,0,0); altframe->layout()->setContentsMargins(0,0,0,0); + + show(); // Force altframe to get resized to its real size. + altframerepl->setFixedHeight(altframe->height()); } + bool AltComboBox::isValid() { if(!combobox->isValid()) return false; if(innerwidget && combobox->getValue() == altvalue) { - return innerwidget->isValid(); + if(!innerwidget->isValid()) return false; } - return true; + return regexpValidator() && luaValidator(); } QString AltComboBox::getValue() @@ -136,25 +150,41 @@ QString AltComboBox::getValue() } } -void AltComboBox::setValue(QString value) +void AltComboBox::setValue(QString value, QString source) { - combobox->setValue(value); + // if(isUserSource(source)) emit wasChanged(); // No need for this, it will be enitted by the children. + + if(combobox->findData(value) != -1) { + + combobox->setValue(value, source); - if(combobox->isValid() == false) { // Combobox contain idx == -1 (invalid) if value didn't exist. + } else { combobox->setValue(altvalue); if(innerwidget) { - innerwidget->setValue(value); + innerwidget->setValue(value, source); } } + + setInitialValue(value); } void AltComboBox::onValueChange(int index) { if(combobox->itemData(index).toString() == altvalue) { - altframe->setEnabled(true); + // altframe->setEnabled(true); + altframerepl->setVisible(false); + layout()->removeWidget(altframerepl); + + layout()->addWidget(altframe); + altframe->setVisible(true); } else { - altframe->setEnabled(false); + // altframe->setEnabled(false); + altframe->setVisible(false); + layout()->removeWidget(altframe); + + layout()->addWidget(altframerepl); + altframerepl->setVisible(true); } } @@ -172,3 +202,35 @@ void AltComboBox::disable() { setEnabled(false); } + +void AltComboBox::onChildChange() +{ + emit wasChanged(); +} + +void AltComboBox::connectFrom(const char *signal, + const QObject *receiver, const char *method) +{ + connect(this, signal, receiver, method); +} + +void AltComboBox::connectTo(const QObject *sender, const char *signal, + const char *method) +{ + connect(sender, signal, this, method); +} + +bool AltComboBox::setKeyboardFocus() +{ + if(combobox->getValue() == altvalue) { + if(innerwidget) return innerwidget->setKeyboardFocus(); + } + + combobox->setKeyboardFocus(); + return true; +} + +void AltComboBox::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/altcombobox.h b/client/widgets/altcombobox.h index 222c797..5504f4a 100644 --- a/client/widgets/altcombobox.h +++ b/client/widgets/altcombobox.h @@ -44,20 +44,34 @@ public: bool isValid(); QString getValue(); - void setValue(QString value); + void setValue(QString value, QString source = ""); void enable(); void disable(); + 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); + public slots: void onValueChange(int index); void onValueChange(const QString &text); + void onChildChange(); + +signals: + void wasChanged(); private: ComboBox *combobox; Widget *innerwidget; QString altvalue; QWidget *altframe; + QWidget *altframerepl; }; #endif/*__PRACRO_ALTCOMBOBOX_H__*/ diff --git a/client/widgets/button.cc b/client/widgets/button.cc index c524084..6032678 100644 --- a/client/widgets/button.cc +++ b/client/widgets/button.cc @@ -32,6 +32,7 @@ Button::Button(QDomNode &node, MacroWindow *macrowindow) : QPushButton(), Widget(node, macrowindow) { + resetToDisabled = false; setCommonAttributes(this, node); QDomElement elem = node.toElement(); @@ -49,12 +50,27 @@ Button::Button(QDomNode &node, MacroWindow *macrowindow) 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())); + connect(this, SIGNAL(clicked()), this, SLOT(_reset())); + setIcon(QPixmap(":icons/del.png")); } 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())); } @@ -69,7 +85,7 @@ void Button::commit() printf("Emit: commit\n"); } -void Button::reset() +void Button::_reset() { emit act_reset(); printf("Emit: reset\n"); @@ -92,3 +108,36 @@ 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); +} diff --git a/client/widgets/button.h b/client/widgets/button.h index aba7ac7..d9d0b26 100644 --- a/client/widgets/button.h +++ b/client/widgets/button.h @@ -39,12 +39,25 @@ 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(); + public slots: void commit(); - void reset(); + void _reset(); void cancel(); void cont(); void cont_nocommit(); + void do_enable(); signals: void act_commit(); @@ -54,6 +67,6 @@ signals: void act_continue_nocommit(QString); private: - + bool resetToDisabled; }; #endif/*__PRACRO_BUTTON_H__*/ diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc index 1b8d64b..4fbdad1 100644 --- a/client/widgets/checkbox.cc +++ b/client/widgets/checkbox.cc @@ -31,6 +31,8 @@ CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow) : QCheckBox(), Widget(node, macrowindow) { + changedByUser = true; + setCommonAttributes(this, node); QDomElement elem = node.toElement(); @@ -51,7 +53,7 @@ CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow) falsevalue = "false"; } - connect(this, SIGNAL(stateChanged(int)), this, SLOT(state_change())); + connect(this, SIGNAL(stateChanged(int)), this, SLOT(state_change(int))); } QString CheckBox::getValue() @@ -60,8 +62,12 @@ QString CheckBox::getValue() return falsevalue; } -void CheckBox::setValue(QString value) +void CheckBox::setValue(QString value, QString source) { + if(isUserSource(source)) emit wasChanged(); + + changedByUser = false; + bool old = isChecked(); if(value == truevalue) { @@ -73,7 +79,11 @@ void CheckBox::setValue(QString value) } // If set operation did not change the value we must invocate the code manually. - if(old == isChecked()) state_change(); + if(old == isChecked()) state_change(0); + + setInitialValue(value); + + changedByUser = true; } /* bool CheckBox::isValid() @@ -81,7 +91,31 @@ bool CheckBox::isValid() return luaValidator(); } */ -void CheckBox::state_change() +void CheckBox::state_change(int) { + if(changedByUser) emit wasChanged(); luaValidator(); } + +void CheckBox::connectFrom(const char *signal, + const QObject *receiver, const char *method) +{ + connect(this, signal, receiver, method); +} + +void CheckBox::connectTo(const QObject *sender, const char *signal, + const char *method) +{ + connect(sender, signal, this, method); +} + +void CheckBox::setVisibility(bool visible) +{ + setVisible(visible); +} + +bool CheckBox::setKeyboardFocus() +{ + setFocus(); + return true; +} diff --git a/client/widgets/checkbox.h b/client/widgets/checkbox.h index 89f1f1b..34cac6b 100644 --- a/client/widgets/checkbox.h +++ b/client/widgets/checkbox.h @@ -40,14 +40,29 @@ public: // bool isValid(); QString getValue(); - void setValue(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); + + bool setKeyboardFocus(); public slots: - void state_change(); + void state_change(int); + +signals: + void wasChanged(); private: QString truevalue; QString falsevalue; + + bool changedByUser; }; #endif/*__PRACRO_CHECKBOX_H__*/ diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc index 630a449..4db6172 100644 --- a/client/widgets/combobox.cc +++ b/client/widgets/combobox.cc @@ -77,7 +77,6 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) setEditable(true); connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); - //setEditText(elem.attribute("value")); break; case SEARCH: @@ -90,6 +89,7 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) } rxs += ")"; rx = QRegExp(rxs); + rx.setCaseSensitivity(Qt::CaseInsensitive); } { QCompleter *completer = new QCompleter(itemlist, this); @@ -100,11 +100,12 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) } connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); - //setEditText(elem.attribute("value")); break; } + ischangingbyuser = false; changed(); + ischangingbyuser = true; } QString ComboBox::getValue() @@ -119,13 +120,20 @@ QString ComboBox::getValue() return value; } -void ComboBox::setValue(QString value) +void ComboBox::setValue(QString value, QString source) { + if(isUserSource(source)) emit wasChanged(); + int idx = findData(value); printf("setValue(\"%s\") - %d\n", value.toStdString().c_str(), idx); + ischangingbyuser = false; setCurrentIndex(idx); + ischangingbyuser = true; + + setInitialValue(value); + } bool ComboBox::isValid() @@ -134,17 +142,12 @@ bool ComboBox::isValid() if(currentIndex() != -1) return true; else return false; } - return rx.exactMatch(currentText()); + return rx.exactMatch(currentText()) && luaValidator(); } void ComboBox::changed() { - /* - if(combotype == SELECT) { - luaValidator(); - return; - } - */ + if(ischangingbyuser) emit wasChanged(); QPalette palette; @@ -169,3 +172,34 @@ void ComboBox::disable() { setEnabled(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::eventFilter(QObject *, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) emit wasChanged(); + return false; +} +*/ + +bool ComboBox::setKeyboardFocus() +{ + setFocus(); + return true; +} + +void ComboBox::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/combobox.h b/client/widgets/combobox.h index f072bea..2691ec3 100644 --- a/client/widgets/combobox.h +++ b/client/widgets/combobox.h @@ -47,18 +47,34 @@ public: bool isValid(); QString getValue(); - void setValue(QString value); + void setValue(QString value, QString source = ""); void enable(); void disable(); + 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); + public slots: void changed(); +signals: + void wasChanged(); + +protected: + // bool eventFilter(QObject *, QEvent *event); + private: QRegExp rx; QString combo_value; types_t combotype; + bool ischangingbyuser; }; #endif/*__PRACRO_COMBOBOX_H__*/ diff --git a/client/widgets/common.cc b/client/widgets/common.cc index f39c607..b650701 100644 --- a/client/widgets/common.cc +++ b/client/widgets/common.cc @@ -96,3 +96,10 @@ void setCommonLayout(QWidget *widget, QDomNode &node) widget->setContentsMargins(0,0,0,0); //widget->layout()->setContentsMargins(0,0,0,0); } + +bool isUserSource(QString source) +{ + if(source == "pentominos") return true; + if(source == "pracro") return false; + return false; +} diff --git a/client/widgets/common.h b/client/widgets/common.h index 11ce317..a3db783 100644 --- a/client/widgets/common.h +++ b/client/widgets/common.h @@ -32,5 +32,6 @@ void setCommonAttributes(QWidget *widget, QDomNode &node); void setCommonLayout(QWidget *widget, QDomNode &node); +bool isUserSource(QString source); #endif/*__PRACRO_COMMON_H__*/ diff --git a/client/widgets/datetime.cc b/client/widgets/datetime.cc new file mode 100644 index 0000000..1ca52ed --- /dev/null +++ b/client/widgets/datetime.cc @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * datetime.cc + * + * Fri Jan 9 09:00:12 CET 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "datetime.h" + +#include "common.h" + +DateTime::DateTime(QDomNode &node, MacroWindow *macrowindow) + : QDateTimeEdit(), Widget(node, macrowindow) +{ + changedByUser = true; + setCommonAttributes(this, node); + + setCalendarPopup(true); + setMinimumDateTime(QDateTime::fromTime_t(0)); + + 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); + } else { + printf("Unknown value of readonly: %s\n", elem.attribute("readonly").toStdString().c_str()); + } + } + */ + connect(this, SIGNAL(dateTimeChanged(const QDateTime &)), + this, SLOT(changed(const QDateTime &))); +} + +void DateTime::changed(const QDateTime &) +{ + 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); + + if(changedByUser) emit wasChanged(); +} + +QString DateTime::getValue() +{ + return QString::number(dateTime().toUTC().toTime_t()); +} + +void DateTime::setValue(QString value, QString source) +{ + changedByUser = false; + if(isUserSource(source)) emit wasChanged(); + + setDateTime(QDateTime::fromTime_t(value.toUInt())); + + setInitialValue(value); + changedByUser = true; +} + +void DateTime::enable() +{ + setEnabled(true); +} + +void DateTime::disable() +{ + setEnabled(false); +} + +void DateTime::connectFrom(const char *signal, + const QObject *receiver, const char *method) +{ + connect(this, signal, receiver, method); +} + +void DateTime::connectTo(const QObject *sender, const char *signal, + const char *method) +{ + connect(sender, signal, this, method); +} + +bool DateTime::setKeyboardFocus() +{ + setFocus(); + return true; +} + +void DateTime::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/datetime.h b/client/widgets/datetime.h new file mode 100644 index 0000000..0fb5703 --- /dev/null +++ b/client/widgets/datetime.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * datetime.h + * + * Fri Jan 9 09:00:12 CET 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_DATETIME_H__ +#define __PRACRO_DATETIME_H__ + +#include "widget.h" +#include +#include + +class DateTime : public QDateTimeEdit, public Widget +{ +Q_OBJECT +public: + DateTime(QDomNode &node, MacroWindow *macrowindow); + + QString getValue(); + void setValue(QString value, QString source = ""); + void enable(); + void disable(); + + 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); + +public slots: + void changed(const QDateTime &); + +signals: + void wasChanged(); + +private: + bool changedByUser; +}; + +#endif/*__PRACRO_DATETIME_H__*/ diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc index 1a68d2a..00b3886 100644 --- a/client/widgets/dbwidget.cc +++ b/client/widgets/dbwidget.cc @@ -40,6 +40,8 @@ DBWidget::DBWidget(QDomNode &node, MacroWindow *macrowindow) : QComboBox(), Widget(node, macrowindow) { + changedByUser = true; + QDomElement elem = node.toElement(); if(!elem.hasAttribute("driver") || @@ -108,9 +110,15 @@ QString DBWidget::getValue() return value; } -void DBWidget::setValue(QString value) +void DBWidget::setValue(QString value, QString source) { + changedByUser = false; + if(isUserSource(source)) emit wasChanged(); + setEditText(value); + + setInitialValue(value); + changedByUser = true; } bool DBWidget::isValid() @@ -133,6 +141,8 @@ void DBWidget::changed() } lineEdit()->setPalette(palette); + + if(changedByUser) emit wasChanged(); } void DBWidget::update_list(QString prefix) @@ -175,6 +185,29 @@ void DBWidget::disable() { setEnabled(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); +} + +bool DBWidget::setKeyboardFocus() +{ + setFocus(); + return true; +} + +void DBWidget::setVisibility(bool visible) +{ + setVisible(visible); +} /* $ psql -h sensei -d lms -U postgres =================================================================== diff --git a/client/widgets/dbwidget.h b/client/widgets/dbwidget.h index 98499b9..13e552d 100644 --- a/client/widgets/dbwidget.h +++ b/client/widgets/dbwidget.h @@ -45,15 +45,28 @@ public: bool isValid(); QString getValue(); - void setValue(QString value); + void setValue(QString value, QString source = ""); void enable(); void disable(); + 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(); + public slots: void changed(); void update_list(QString prefix); +signals: + void wasChanged(); + protected: // void focusInEvent(QFocusEvent *); @@ -64,6 +77,8 @@ private: QString from; QString where; QString format; + + bool changedByUser; }; #endif/*__PRACRO_DBWIDGET_H__*/ diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc index 79e060b..04a0e90 100644 --- a/client/widgets/frame.cc +++ b/client/widgets/frame.cc @@ -48,3 +48,20 @@ void Frame::disable() { setEnabled(false); } + +void Frame::connectFrom(const char *signal, + const QObject *receiver, const char *method) +{ + connect(this, signal, receiver, method); +} + +void Frame::connectTo(const QObject *sender, const char *signal, + const char *method) +{ + connect(sender, signal, this, method); +} + +void Frame::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/frame.h b/client/widgets/frame.h index 4fabd40..5375d06 100644 --- a/client/widgets/frame.h +++ b/client/widgets/frame.h @@ -38,6 +38,13 @@ public: void enable(); void disable(); + + 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); }; #endif/*__PRACRO_FRAME_H__*/ diff --git a/client/widgets/groupbox.cc b/client/widgets/groupbox.cc index c3947a7..f6c9b28 100644 --- a/client/widgets/groupbox.cc +++ b/client/widgets/groupbox.cc @@ -54,3 +54,20 @@ void GroupBox::disable() { setEnabled(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); +} + +void GroupBox::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/groupbox.h b/client/widgets/groupbox.h index 99e05ce..d1ffb86 100644 --- a/client/widgets/groupbox.h +++ b/client/widgets/groupbox.h @@ -38,6 +38,13 @@ public: void enable(); void disable(); + + 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); }; #endif/*__PRACRO_GROUPBOX_H__*/ diff --git a/client/widgets/label.cc b/client/widgets/label.cc index d4f5387..3f69861 100644 --- a/client/widgets/label.cc +++ b/client/widgets/label.cc @@ -59,5 +59,21 @@ Label::Label(QDomNode &node, MacroWindow *macrowindow) // 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); } diff --git a/client/widgets/label.h b/client/widgets/label.h index cbf3e06..6c02d1b 100644 --- a/client/widgets/label.h +++ b/client/widgets/label.h @@ -37,6 +37,13 @@ class Label : public QLabel, public Widget Q_OBJECT public: Label(QDomNode &node, MacroWindow *macrowindow); + + 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); }; #endif/*__PRACRO_LABEL_H__*/ diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 29ea06c..b699553 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -47,6 +47,7 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow) } connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed())); + connect(this, SIGNAL(textEdited(QString)), this, SLOT(user_changed())); } void LineEdit::changed() @@ -69,15 +70,24 @@ void LineEdit::changed() setPalette(palette); } +void LineEdit::user_changed() +{ + emit wasChanged(); +} + QString LineEdit::getValue() { return text(); } -void LineEdit::setValue(QString value) +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); + + setInitialValue(value); } void LineEdit::enable() @@ -89,3 +99,26 @@ void LineEdit::disable() { setEnabled(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); +} diff --git a/client/widgets/lineedit.h b/client/widgets/lineedit.h index 3f0bb17..0e060d6 100644 --- a/client/widgets/lineedit.h +++ b/client/widgets/lineedit.h @@ -39,12 +39,25 @@ public: LineEdit(QDomNode &node, MacroWindow *macrowindow); QString getValue(); - void setValue(QString value); + void setValue(QString value, QString source = ""); void enable(); void disable(); + 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); + public slots: void changed(); + void user_changed(); + +signals: + void wasChanged(); }; #endif/*__PRACRO_LINEEDIT_H__*/ diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc index 88a5cd2..303d288 100644 --- a/client/widgets/listbox.cc +++ b/client/widgets/listbox.cc @@ -71,6 +71,8 @@ static QListWidgetItem *createItem(QDomElement &elem) ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow) : QListWidget(), Widget(node, macrowindow) { + valueIsChangingByComputer = false; + setCommonAttributes(this, node); QDomNodeList children = node.childNodes(); @@ -80,6 +82,8 @@ ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow) QDomElement list_elem = child.toElement(); addItem(createItem(list_elem)); } + + connect(this, SIGNAL(itemSelectionChanged()), this, SLOT(changed())); } bool ListBox::isValid() @@ -94,8 +98,11 @@ QString ListBox::getValue() return value; } -void ListBox::setValue(QString value) +void ListBox::setValue(QString value, QString source) { + if(isUserSource(source)) emit wasChanged(); + + valueIsChangingByComputer = true; int sel = -1; // -1 is default for none selected for(int i = 0; i < count(); i++) { @@ -104,4 +111,35 @@ void ListBox::setValue(QString value) } 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; } diff --git a/client/widgets/listbox.h b/client/widgets/listbox.h index 627d31e..1485225 100644 --- a/client/widgets/listbox.h +++ b/client/widgets/listbox.h @@ -33,13 +33,32 @@ class ListBox : public QListWidget, public Widget { +Q_OBJECT public: ListBox(QDomNode &node, MacroWindow *macrowindow); -public slots: bool isValid(); QString getValue(); - void setValue(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); + + bool setKeyboardFocus(); + +public slots: + void changed(); + +signals: + void wasChanged(); + +private: + bool valueIsChangingByComputer; }; #endif/*__PRACRO_LISTBOX_H__*/ diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc index 5f53153..91c62ec 100644 --- a/client/widgets/metawidget.cc +++ b/client/widgets/metawidget.cc @@ -29,6 +29,8 @@ #include #include +#include + #include "widgetbuilder.h" #include "formatparser.h" @@ -38,37 +40,21 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { setCommonAttributes(this, node); - - QDomElement elem = node.toElement(); - if(elem.hasAttribute("layout")) { - if(elem.attribute("layout") == "hbox") { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } else if (elem.attribute("layout") == "vbox") { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - } - } else { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } - - layout()->setContentsMargins(0,0,0,0); + setCommonLayout(this, node); + QDomElement elem = node.toElement(); + storechildren = elem.attribute("storechildren", "false") == "true"; + + // Create children QDomNodeList children = node.childNodes(); - for (int i=0; iaddAuxWidgets(widgets); - - /* // This is done later - if(elem.hasAttribute("value")) { - setValue(elem.attribute("value")); + widgets += widgetBuilder(child, this, macrowindow, false); } - */ + if(storechildren) macrowindow->addWidgets(widgets); + else macrowindow->addAuxWidgets(widgets); + // Setup format string if(elem.hasAttribute("format")) { format = elem.attribute("format"); } else { @@ -81,19 +67,18 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow) } } - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); + // 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())); + i++; } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - - layout()->setContentsMargins(0,0,0,0); } void MetaWidget::changed() { + emit wasChanged(); } QString MetaWidget::getValue() @@ -101,7 +86,7 @@ QString MetaWidget::getValue() return format_parser(format, widgets); } -void MetaWidget::setValue(QString /*values*/) +void MetaWidget::setValue(QString, QString) { // Nothing reasonable we can do here. } @@ -115,3 +100,65 @@ void MetaWidget::disable() { setEnabled(false); } + +bool MetaWidget::isValid() +{ + // 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) { + QMessageBox::critical(NULL, "Fejl", + "Et af inputfelterne (" + w->getName() + + ") er ikke udfyldt korrekt, prøv igen.\n" + , QMessageBox::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); +} + +bool MetaWidget::setKeyboardFocus() +{ + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + if(w->setKeyboardFocus()) return true; + i++; + } + return false; +} + +void MetaWidget::reset() +{ + // If children are stored they will be reset individually. + if(!storechildren) { + QVector< Widget* >::iterator i = widgets.begin(); + while (i != widgets.end()) { + Widget* w = *i; + w->reset(); + i++; + } + } +} + +void MetaWidget::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/metawidget.h b/client/widgets/metawidget.h index 5d0bbc9..e920236 100644 --- a/client/widgets/metawidget.h +++ b/client/widgets/metawidget.h @@ -40,18 +40,36 @@ Q_OBJECT public: MetaWidget(QDomNode &node, MacroWindow *macrowindow); -public slots: - void changed(); QString getValue(); - void setValue(QString value); + void setValue(QString value, QString source = ""); void enable(); void disable(); + bool isValid(); + + 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 reset(); + +public slots: + void changed(); + +signals: + void wasChanged(); + private: QListWidget *list; QVector< Widget* > widgets; QString format; + bool storechildren; }; #endif/*__PRACRO_METAWIDGET_H__*/ diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index bff3ad7..5f28368 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -43,9 +43,29 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) QGridLayout *layout = new QGridLayout(); setLayout(layout); + list = new QListWidget(this); + layout->addWidget(list, 0, 0, 1, 2, Qt::AlignTop); + list->installEventFilter(this); + + QPushButton *add = new QPushButton(this); + connect(add, SIGNAL(clicked()), this, SLOT(add())); + add->setText("Tilføj nedenstående til listen"); + add->setIcon(QIcon(QPixmap(":icons/add.png"))); + layout->addWidget(add, 1, 0, 1, 1, Qt::AlignTop); + + QPushButton *rem = new QPushButton(this); + connect(rem, SIGNAL(clicked()), this, SLOT(remove())); + rem->setText("Fjern det markerede element fra listen"); + rem->setIcon(QIcon(QPixmap(":icons/del.png"))); + layout->addWidget(rem, 1, 1, 1, 1, Qt::AlignTop); + + QLabel *arrows = new QLabel(); + arrows->setPixmap(QPixmap(":icons/arrows.png")); + layout->addWidget(arrows, 2, 0, 1, 2, Qt::AlignHCenter); + QWidget *inputbox = new QWidget(this); inputbox->setContentsMargins(0,0,0,0); - layout->addWidget(inputbox, 0, 0, 1, 2, Qt::AlignTop); + layout->addWidget(inputbox, 3, 0, 1, 2, Qt::AlignTop); QDomElement elem = node.toElement(); if(elem.hasAttribute("layout")) { @@ -68,7 +88,7 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) QVector< Widget* > widgets; for (int i=0; iaddAuxWidgets(widgets); @@ -88,35 +108,6 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) printf("ERROR: Missing 'innerwidget' attribute on multilist!\n"); } - QLabel *arrows = new QLabel(); - arrows->setPixmap(QPixmap(":icons/arrows.png")); - layout->addWidget(arrows, 1, 0, 1, 2, Qt::AlignHCenter); - - QPushButton *add = new QPushButton(this); - connect(add, SIGNAL(clicked()), this, SLOT(add())); - add->setText("Tilføj ovenstående til listen"); - add->setIcon(QIcon(QPixmap(":icons/add.png"))); - - // layout->addWidget(add, 0, 1, Qt::AlignTop); - layout->addWidget(add, 2, 0, 1, 1, Qt::AlignTop); - - QPushButton *rem = new QPushButton(this); - connect(rem, SIGNAL(clicked()), this, SLOT(remove())); - rem->setText("Fjern det markerede element fra listen"); - rem->setIcon(QIcon(QPixmap(":icons/del.png"))); - // layout->addWidget(rem, 1, 1, Qt::AlignTop); - layout->addWidget(rem, 2, 1, 1, 1, Qt::AlignTop); - - list = new QListWidget(this); - // layout->addWidget(list, 1, 0, Qt::AlignTop); - layout->addWidget(list, 3, 0, 1, 2, Qt::AlignTop); - - /* // This is done later - if(elem.hasAttribute("value")) { - setValue(elem.attribute("value")); - } - */ - layout->setContentsMargins(0,0,0,0); } @@ -140,8 +131,10 @@ QString MultiList::getValue() return values; } -void MultiList::setValue(QString values) +void MultiList::setValue(QString values, QString source) { + if(isUserSource(source)) emit wasChanged(); + QString value; list->clear(); @@ -152,26 +145,28 @@ void MultiList::setValue(QString values) if(value != "") list->addItem(value); idx++; } while(value != ""); + + setInitialValue(values); } void MultiList::remove() { - list->takeItem(list->currentRow()); + QListWidgetItem *item = list->currentItem(); + + if(item && item->isSelected()) { + delete item; + emit wasChanged(); + } } void MultiList::add() { - /* - QVector< Widget * >::iterator i = widgets.begin(); - while(i != widgets.end()) { - if(!(*i)->isValid()) return; - i++; - } - list->addItem(format_parser(format, widgets)); - */ + if(innerwidget && innerwidget->isValid()) { + list->addItem(innerwidget->getValue()); + emit wasChanged(); - if(innerwidget && innerwidget->isValid()) list->addItem(innerwidget->getValue()); - + innerwidget->reset(); + } } void MultiList::enable() @@ -183,3 +178,35 @@ void MultiList::disable() { setEnabled(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(); + return false; +} + +bool MultiList::eventFilter(QObject *obj, QEvent *event) +{ + if(event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->key() == Qt::Key_Delete) remove(); + } + return QObject::eventFilter(obj, event); +} + +void MultiList::setVisibility(bool visible) +{ + setVisible(visible); +} diff --git a/client/widgets/multilist.h b/client/widgets/multilist.h index 0a9e798..3bd7b9c 100644 --- a/client/widgets/multilist.h +++ b/client/widgets/multilist.h @@ -40,16 +40,31 @@ Q_OBJECT public: MultiList(QDomNode &node, MacroWindow *macrowindow); -public slots: - void changed(); QString getValue(); - void setValue(QString value); + void setValue(QString value, QString source = ""); + + void enable(); + void disable(); + + 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); + +public slots: + void changed(); void remove(); void add(); - void enable(); - void disable(); +signals: + void wasChanged(); + +protected: + bool eventFilter(QObject *obj, QEvent *event); private: QListWidget *list; diff --git a/client/widgets/radiobutton.h b/client/widgets/radiobutton.h index d0cf149..6dbae7e 100644 --- a/client/widgets/radiobutton.h +++ b/client/widgets/radiobutton.h @@ -35,6 +35,7 @@ class RadioButton : public QRadioButton { +Q_OBJECT public: RadioButton(QDomNode &node); diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc index 1987459..ae40677 100644 --- a/client/widgets/radiobuttons.cc +++ b/client/widgets/radiobuttons.cc @@ -47,6 +47,9 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow) // Create radiobutton from child, insert in this layout()->addWidget(radiobutton); + + connect(radiobutton, SIGNAL(clicked()), this, SLOT(childChanged())); + radiobutton_list.push_back(radiobutton); } @@ -79,8 +82,10 @@ QString RadioButtons::getValue() return value; } -void RadioButtons::setValue(QString value) +void RadioButtons::setValue(QString value, QString source) { + if(isUserSource(source)) emit wasChanged(); + QVector< RadioButton* >::iterator i; for (i = radiobutton_list.begin(); i != radiobutton_list.end(); ++i) { RadioButton *widget = *i; @@ -90,4 +95,48 @@ void RadioButtons::setValue(QString value) widget->setChecked(false); } } + + setInitialValue(value); +} + +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() +{ + QVector< RadioButton* >::iterator i = radiobutton_list.begin(); + while(i != radiobutton_list.end()) { + RadioButton *rb = *i; + if(rb->isChecked()) { + rb->setFocus(); + return true; + } + i++; + } + + if(radiobutton_list.size()) { + radiobutton_list.at(0)->setFocus(); + return true; + } + + return false; +} + +void RadioButtons::setVisibility(bool visible) +{ + setVisible(visible); +} + +void RadioButtons::childChanged() +{ + emit wasChanged(); } diff --git a/client/widgets/radiobuttons.h b/client/widgets/radiobuttons.h index f1c89c4..cfdf1ef 100644 --- a/client/widgets/radiobuttons.h +++ b/client/widgets/radiobuttons.h @@ -36,13 +36,28 @@ class RadioButtons : public QFrame, public Widget { +Q_OBJECT public: RadioButtons(QDomNode &node, MacroWindow *macrowindow); -public slots: bool isValid(); QString getValue(); - void setValue(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 setKeyboardFocus(); + void setVisibility(bool visible); + +public slots: + void childChanged(); + +signals: + void wasChanged(); private: QVector < RadioButton* > radiobutton_list; diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc index cdbd8ad..ec7e3fc 100644 --- a/client/widgets/textedit.cc +++ b/client/widgets/textedit.cc @@ -49,6 +49,7 @@ TextEdit::TextEdit(QDomNode &node, MacroWindow *macrowindow) } connect(this, SIGNAL(textChanged()), this, SLOT(changed())); + installEventFilter(this); // Detect keyboard input. } void TextEdit::changed() @@ -76,7 +77,41 @@ QString TextEdit::getValue() return QTextEdit::toPlainText(); } -void TextEdit::setValue(QString value) +void TextEdit::setValue(QString value, QString source) { + if(isUserSource(source)) emit wasChanged(); setText(value); + setInitialValue(value); +} + +bool TextEdit::eventFilter(QObject *, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + if(keyEvent->text() != "") emit wasChanged(); + } + 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) +{ + connect(sender, signal, this, method); +} + +bool TextEdit::setKeyboardFocus() +{ + setFocus(); + return true; +} + +void TextEdit::setVisibility(bool visible) +{ + setVisible(visible); } diff --git a/client/widgets/textedit.h b/client/widgets/textedit.h index c734f38..722abcd 100644 --- a/client/widgets/textedit.h +++ b/client/widgets/textedit.h @@ -31,6 +31,7 @@ #include #include #include +#include class TextEdit : public QTextEdit, public Widget { @@ -39,10 +40,27 @@ public: TextEdit(QDomNode &node, MacroWindow *macrowindow); QString getValue(); - void setValue(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 setKeyboardFocus(); + + void setVisibility(bool visible); + +signals: + void wasChanged(); public slots: void changed(); + // void user_changed(); + +protected: + bool eventFilter(QObject *obj, QEvent *event); }; #endif/*__PRACRO_TEXTEDIT_H__*/ diff --git a/client/widgets/widget.cc b/client/widgets/widget.cc index de49968..0857d67 100644 --- a/client/widgets/widget.cc +++ b/client/widgets/widget.cc @@ -35,8 +35,10 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow) if(elem.hasAttribute("name")) { widget_name = elem.attribute("name"); } else { - printf("XML ERROR!! Unnamed widget of type: %s\n", - elem.tagName().toStdString().c_str()); + if(elem.tagName() != "frame" && elem.tagName() != "label" + && elem.tagName() != "button" && elem.tagName() != "window") + printf("XML ERROR!! Unnamed widget of type: %s\n", + elem.tagName().toStdString().c_str()); } if(elem.hasAttribute("script")) { @@ -52,6 +54,9 @@ Widget::Widget(QDomNode &node, MacroWindow *macrowindow) } else { hasregexpvalidator = false; } + + has_initial_value = false; + initial_value = ""; } QString Widget::getName() @@ -59,12 +64,7 @@ QString Widget::getName() return widget_name; } -QString Widget::getValue() -{ - return ""; -} - -void Widget::setValue(QString) +void Widget::setValue(QString, QString) { } @@ -85,10 +85,15 @@ bool Widget::luaValidator() return macrowindow->lua->run(luaprogram, getName(), getValue()); } -void Widget::disable() +void Widget::setInitialValue(QString value) { + if(!has_initial_value) { + initial_value = value; + has_initial_value = true; + } } -void Widget::enable() +void Widget::reset() { + setValue(initial_value); } diff --git a/client/widgets/widget.h b/client/widgets/widget.h index 9b6a996..2977e3a 100644 --- a/client/widgets/widget.h +++ b/client/widgets/widget.h @@ -38,13 +38,35 @@ class Widget { public: Widget(QDomNode &node, MacroWindow *macrowindow); virtual ~Widget(){} - virtual QString getValue(); - virtual void setValue(QString value); + + virtual QString getValue() { return ""; } + virtual void setValue(QString value, QString source = ""); + virtual bool isValid(); - virtual void disable(); - virtual void enable(); + + virtual void disable() {} + virtual void enable() {} + virtual bool isDisabled() { return false; } + + virtual void setVisibility(bool) {} + QString getName(); + /** + * Connect some signal from this object to some slot in some other object. + */ + virtual void connectFrom(const char *, const QObject *, const char *) {} + + /** + * Connect some signal from some other object to some slot in this object. + */ + virtual void connectTo(const QObject *, const char *, const char *) {} + + virtual bool setKeyboardFocus() { return false; } + + void setInitialValue(QString value); + virtual void reset(); + protected: QString widget_name; @@ -60,6 +82,9 @@ private: QString luaprogram; LUA *lua; MacroWindow *macrowindow; + + QString initial_value; + bool has_initial_value; }; #endif/*__PRACRO_WIDGET_H__*/ diff --git a/client/widgets/window.cc b/client/widgets/window.cc index fa44875..e685e79 100644 --- a/client/widgets/window.cc +++ b/client/widgets/window.cc @@ -51,3 +51,15 @@ Window::Window(QDomNode &node, MacroWindow *macrowindow) 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); +} diff --git a/client/widgets/window.h b/client/widgets/window.h index af1e3d7..6e3d5be 100644 --- a/client/widgets/window.h +++ b/client/widgets/window.h @@ -35,6 +35,12 @@ class Window : public QWidget, public Widget { public: Window(QDomNode &node, MacroWindow *macrowindow); + + void connectFrom(const char *signal, + const QObject *receiver, const char *method); + + void connectTo(const QObject *sender, const char *signal, + const char *method); }; #endif/*__PRACRO_WINDOW_H__*/ -- cgit v1.2.3