[324] | 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | #include "SpinBox.h"
|
---|
| 6 | #include <QFormLayout>
|
---|
| 7 | #include "Layout.h"
|
---|
| 8 | #include <QSpinBox>
|
---|
| 9 |
|
---|
| 10 | SpinBox::SpinBox(Layout *parent, int row, int col, QString name, QString suffix,
|
---|
| 11 | int value, int min, int max, int step)
|
---|
| 12 | : FormLayout(parent, row, col, name, "SpinBox") {
|
---|
| 13 | spinbox = new QSpinBox();
|
---|
| 14 |
|
---|
| 15 | spinbox->setRange(min, max);
|
---|
| 16 | spinbox->setSingleStep(step);
|
---|
| 17 | spinbox->setValue(value);
|
---|
| 18 | spinbox->setSuffix(suffix);
|
---|
| 19 | spinbox_value = value;
|
---|
| 20 |
|
---|
| 21 | object_layout->addRow(name, spinbox);
|
---|
| 22 |
|
---|
| 23 | connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(valuechanged(int)));
|
---|
| 24 |
|
---|
| 25 | SetValue(QString::number(spinbox_value));
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | SpinBox::~SpinBox() { delete spinbox; }
|
---|
| 29 |
|
---|
| 30 | void SpinBox::SetUptodate(void) {
|
---|
| 31 | ui_to_var();
|
---|
| 32 | ui_to_xml();
|
---|
| 33 | visible_widget->setPalette(black_pal);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | void SpinBox::ui_to_var(void) { spinbox_value = spinbox->value(); }
|
---|
| 37 |
|
---|
| 38 | void SpinBox::ui_to_xml(void) { SetValue(QString::number(spinbox->value())); }
|
---|
| 39 |
|
---|
| 40 | void SpinBox::Reset(void) { spinbox->setValue(spinbox_value); }
|
---|
| 41 |
|
---|
| 42 | void SpinBox::LoadEvent(QDomElement *dom) {
|
---|
| 43 | if (spinbox->isEnabled() == true) {
|
---|
| 44 | spinbox->setValue((dom->attribute("value")).toInt());
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | void SpinBox::valuechanged(int value) {
|
---|
| 49 | if (value != spinbox_value) {
|
---|
| 50 | visible_widget->setPalette(red_pal);
|
---|
| 51 | } else {
|
---|
| 52 | visible_widget->setPalette(black_pal);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|