summaryrefslogtreecommitdiff
path: root/client/widgets/checkgroupbox.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/widgets/checkgroupbox.cc')
-rw-r--r--client/widgets/checkgroupbox.cc163
1 files changed, 28 insertions, 135 deletions
diff --git a/client/widgets/checkgroupbox.cc b/client/widgets/checkgroupbox.cc
index a5692b2..fa662e1 100644
--- a/client/widgets/checkgroupbox.cc
+++ b/client/widgets/checkgroupbox.cc
@@ -28,7 +28,6 @@
#include "checkgroupbox.h"
#include <QGroupBox>
-#include <QCheckBox>
#include <QHBoxLayout>
@@ -36,168 +35,62 @@
#include "debug.h"
CheckGroupBox::CheckGroupBox(QDomNode &node, MacroWindow *macrowindow)
- : Widget(node, macrowindow)
+ : CheckBox(node, macrowindow)
{
- QDomElement elem = node.toElement();
+ checkbox = (QCheckBox*)widget;
+ connect(this, SIGNAL(wasChanged()), this, SLOT(cgb_state_change()));
+ QDomElement elem = node.toElement();
type = elem.attribute("type", "framed");
-
- checkbox = NULL;
- groupbox = NULL;
if(type == "framed") {
- groupbox = new QGroupBox();
- groupbox->setCheckable(true);
- connect(groupbox, SIGNAL(toggled(bool)), this, SLOT(state_change(bool)));
-
- widget = groupbox;
-
- setCommonLayout(widget, node);
-
- addChildren(node, widget->layout());
-
- if(elem.hasAttribute("caption")) {
- groupbox->setTitle(elem.attribute("caption"));
- }
-
+ QGroupBox *gb = new QGroupBox();
+ gb->setTitle(" ");
+ widget = gb;
} else if(type == "simple") {
widget = new QWidget();
- widget->setContentsMargins(0,0,0,0);
- QHBoxLayout *l = new QHBoxLayout();
- l->setContentsMargins(0,0,0,0);
- widget->setLayout(l);
- checkbox = new QCheckBox();
- connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(state_change(bool)));
- if(elem.hasAttribute("caption")) {
- checkbox->setText(elem.attribute("caption"));
- }
- l->addWidget(checkbox);
- container = new QWidget();
- l->addWidget(container);
-
- setCommonLayout(container, node);
-
- addChildren(node, container->layout());
- container->layout()->setContentsMargins(0,0,0,0);
-
-
} else {
ERROR(checkgroupbox, "Illegal value of attribute 'type'\n");
+ return;
}
+ setCommonLayout(widget, node);
setCommonAttributes(widget, node);
- //
- // From CheckBox
- //
- changedByUser = true;
-
- if(elem.hasAttribute("truevalue")) {
- truevalue = elem.attribute("truevalue");
- } else {
- truevalue = "true";
- }
-
- if(elem.hasAttribute("falsevalue")) {
- falsevalue = elem.attribute("falsevalue");
- } else {
- falsevalue = "false";
- }
-}
-
-CheckGroupBox::~CheckGroupBox()
-{
- // delete groupbox;
-}
-
-QString CheckGroupBox::value()
-{
- if(groupbox && groupbox->isChecked()) return truevalue;
- if(checkbox && checkbox->isChecked()) return truevalue;
- return falsevalue;
-}
-
-void CheckGroupBox::setValue(QString value, QString source)
-{
- if(isUserSource(source)) emit wasChanged();
+ checkbox->setParent(widget);
+ checkbox->resize(checkbox->sizeHint().width(), 32);
+ checkbox->show();
- changedByUser = false;
-
- bool old = false;
- if(groupbox) old = groupbox->isChecked();
- if(checkbox) old = checkbox->isChecked();
-
- if(value == truevalue) {
- if(groupbox) groupbox->setChecked(true);
- if(checkbox) {
- checkbox->setChecked(true);
- container->setEnabled(true);
- }
- } else if(value == falsevalue) {
- if(groupbox) groupbox->setChecked(false);
- if(checkbox) {
- checkbox->setChecked(false);
- container->setEnabled(false);
- }
- } else {
- printf("Unknown checkbox value: %s\n", value.toStdString().c_str());
+ if(type == "framed") {
+ widget->setContentsMargins(0, 10, 0, 0);
+ checkbox->move(5, -9);
+ checkbox->setAutoFillBackground(true);
}
- // If set operation did not change the value we must invocate the code manually.
- if(groupbox && old == groupbox->isChecked()) state_change(old);
- if(checkbox && old == checkbox->isChecked()) state_change(old);
-
- // setInitialValue(value);
-
- changedByUser = true;
-}
-
-void CheckGroupBox::state_change(bool state)
-{
- emit eventOnChange();
- if(changedByUser) emit wasChanged();
-
- if(checkbox) {
- container->setEnabled(state);
+ if(type == "simple") {
+ widget->setContentsMargins(checkbox->sizeHint().width(), 0, 0, 0);
+ checkbox->move(0, 3);
}
-}
-
-bool CheckGroupBox::checked()
-{
- return value() == truevalue;
-}
-void CheckGroupBox::setChecked(bool checked)
-{
- setValue(checked ? truevalue : falsevalue);
+ addChildren(node, widget->layout());
}
-void CheckGroupBox::setWdgValid(bool valid)
+CheckGroupBox::~CheckGroupBox()
{
- 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(groupbox) groupbox->setPalette(palette);
- if(checkbox) checkbox->setPalette(palette);
}
-bool CheckGroupBox::setKeyboardFocus()
+void CheckGroupBox::cgb_state_change()
{
QVector< Widget* >::iterator i = children.begin();
while(i != children.end()) {
Widget *w = *i;
- if(w) {
- if(w->setKeyboardFocus()) return true;
- }
+ if(w) w->setEnabled(checkbox->isChecked());
i++;
}
+}
- return false;
+bool CheckGroupBox::setKeyboardFocus()
+{
+ checkbox->setFocus();
+ return true;
}