diff options
author | deva <deva> | 2010-08-12 10:57:04 +0000 |
---|---|---|
committer | deva <deva> | 2010-08-12 10:57:04 +0000 |
commit | d9338083192084613e5530b02710b796252d342b (patch) | |
tree | e0ec2b36e0de62328e5fd5d3b597f6ee71d1b18f /client/widgets/checkbox.cc | |
parent | dbab8458dcce186e7eb7a114a83f759d7db5445a (diff) |
New scripting system part2.
Diffstat (limited to 'client/widgets/checkbox.cc')
-rw-r--r-- | client/widgets/checkbox.cc | 81 |
1 files changed, 37 insertions, 44 deletions
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); } |