summaryrefslogtreecommitdiff
path: root/client/widgets/multilist.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets/multilist.cc')
-rw-r--r--client/widgets/multilist.cc117
1 files changed, 50 insertions, 67 deletions
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);
}