diff options
Diffstat (limited to 'client/widgets')
-rw-r--r-- | client/widgets/checkgroupbox.cc | 89 | ||||
-rw-r--r-- | client/widgets/checkgroupbox.h | 11 |
2 files changed, 77 insertions, 23 deletions
diff --git a/client/widgets/checkgroupbox.cc b/client/widgets/checkgroupbox.cc index 7204418..07b7632 100644 --- a/client/widgets/checkgroupbox.cc +++ b/client/widgets/checkgroupbox.cc @@ -28,29 +28,59 @@ #include "checkgroupbox.h" #include <QGroupBox> +#include <QCheckBox> + +#include <QHBoxLayout> #include "common.h" +#include "debug.h" CheckGroupBox::CheckGroupBox(QDomNode &node, MacroWindow *macrowindow) : Widget(node, macrowindow) { - // - // From GroupBox - // - groupbox = new QGroupBox(); - groupbox->setCheckable(true); - widget = groupbox; + QDomElement elem = node.toElement(); - setCommonAttributes(groupbox, node); - setCommonLayout(groupbox, node); + type = elem.attribute("type", "framed"); + + checkbox = NULL; + groupbox = NULL; - QDomElement elem = node.toElement(); + if(type == "framed") { + groupbox = new QGroupBox(); + groupbox->setCheckable(true); + connect(groupbox, SIGNAL(toggled(bool)), this, SLOT(state_change(bool))); + widget = groupbox; - if(elem.hasAttribute("caption")) { - groupbox->setTitle(elem.attribute("caption")); - } + if(elem.hasAttribute("caption")) { + groupbox->setTitle(elem.attribute("caption")); + } + + setCommonAttributes(widget, node); + setCommonLayout(widget, node); - addChildren(node, groupbox->layout()); + addChildren(node, widget->layout()); + + } else if(type == "simple") { + widget = new QWidget(); + QHBoxLayout *l = new QHBoxLayout(); + 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); + + setCommonAttributes(widget, node); + setCommonLayout(container, node); + + addChildren(node, container->layout()); + + } else { + ERROR(checkgroupbox, "Illigal value of attribute 'type'\n"); + } // // From CheckBox @@ -68,8 +98,6 @@ CheckGroupBox::CheckGroupBox(QDomNode &node, MacroWindow *macrowindow) } else { falsevalue = "false"; } - - connect(groupbox, SIGNAL(toggled(bool)), this, SLOT(state_change(bool))); } CheckGroupBox::~CheckGroupBox() @@ -79,7 +107,8 @@ CheckGroupBox::~CheckGroupBox() QString CheckGroupBox::value() { - if(groupbox->isChecked()) return truevalue; + if(groupbox && groupbox->isChecked()) return truevalue; + if(checkbox && checkbox->isChecked()) return truevalue; return falsevalue; } @@ -89,28 +118,43 @@ void CheckGroupBox::setValue(QString value, QString source) changedByUser = false; - bool old = groupbox->isChecked(); + bool old = false; + if(groupbox) old = groupbox->isChecked(); + if(checkbox) old = checkbox->isChecked(); if(value == truevalue) { - groupbox->setChecked(true); + if(groupbox) groupbox->setChecked(true); + if(checkbox) { + checkbox->setChecked(true); + container->setEnabled(true); + } } else if(value == falsevalue) { - groupbox->setChecked(false); + 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 set operation did not change the value we must invocate the code manually. - if(old == groupbox->isChecked()) state_change(0); + 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) +void CheckGroupBox::state_change(bool state) { emit eventOnChange(); if(changedByUser) emit wasChanged(); + + if(checkbox) { + container->setEnabled(state); + } } bool CheckGroupBox::checked() @@ -135,7 +179,8 @@ void CheckGroupBox::setWdgValid(bool valid) palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); } - groupbox->setPalette(palette); + if(groupbox) groupbox->setPalette(palette); + if(checkbox) checkbox->setPalette(palette); } bool CheckGroupBox::setKeyboardFocus() diff --git a/client/widgets/checkgroupbox.h b/client/widgets/checkgroupbox.h index eac85f9..9b6dcdc 100644 --- a/client/widgets/checkgroupbox.h +++ b/client/widgets/checkgroupbox.h @@ -37,10 +37,15 @@ * @extends checkbox * @screenshot * @container - * @att layout the layout used in the groupbox. Can be one of 'vbox' or 'hbox'. + * @att layout The layout used in the groupbox. Can be one of 'vbox' or 'hbox'. + * @att type Defines the type of the checkbox. It can be one of 'framed' or + * 'simple'. Framed will draw a frame with the checkbox contained in the + * caption. 'simple' will draw the checkbox without the frame and put the inner + * to the right of it. Default is 'framed'. */ class QGroupBox; +class QCheckBox; class CheckGroupBox : public Widget { Q_OBJECT @@ -65,9 +70,13 @@ private: QString truevalue; QString falsevalue; + QString type; + bool changedByUser; QGroupBox *groupbox; + QCheckBox *checkbox; + QWidget *container; }; #endif/*__PRACRO_CHECKGROUPBOX_H__*/ |