[10] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[10] | 4 | // %flair:license}
|
---|
[9] | 5 | #include "ComboBox.h"
|
---|
| 6 | #include "Layout.h"
|
---|
| 7 | #include <QComboBox>
|
---|
| 8 | #include <QFormLayout>
|
---|
| 9 |
|
---|
[15] | 10 | ComboBox::ComboBox(Layout *parent, int row, int col, QString name, int value)
|
---|
| 11 | : FormLayout(parent, row, col, name, "ComboBox") {
|
---|
| 12 | combobox = new QComboBox();
|
---|
| 13 | combobox->setCurrentIndex(value);
|
---|
[9] | 14 |
|
---|
[15] | 15 | combobox_value = value;
|
---|
[9] | 16 |
|
---|
[15] | 17 | object_layout->addRow(name, combobox);
|
---|
[9] | 18 |
|
---|
[15] | 19 | connect(combobox, SIGNAL(currentIndexChanged(int)), this,
|
---|
| 20 | SLOT(valuechanged(int)));
|
---|
[9] | 21 |
|
---|
[15] | 22 | SetValue(QString::number(combobox_value));
|
---|
[9] | 23 |
|
---|
[15] | 24 | // pour ne pas faire de doublons qd on ajoute des items
|
---|
| 25 | SetIsExpandable(true);
|
---|
[9] | 26 | }
|
---|
| 27 |
|
---|
[15] | 28 | ComboBox::~ComboBox() { delete combobox; }
|
---|
[9] | 29 |
|
---|
[15] | 30 | void ComboBox::XmlEvent(QDomElement dom) {
|
---|
| 31 | if (dom.attribute("item") != "") {
|
---|
| 32 | QString item = dom.attribute("item");
|
---|
| 33 | combobox->addItem(item);
|
---|
| 34 | combobox->setCurrentIndex(combobox_value);
|
---|
| 35 | }
|
---|
[9] | 36 | }
|
---|
| 37 |
|
---|
[15] | 38 | void ComboBox::SetUptodate(void) {
|
---|
| 39 | ui_to_var();
|
---|
| 40 | ui_to_xml();
|
---|
| 41 | visible_widget->setPalette(black_pal);
|
---|
[9] | 42 | }
|
---|
| 43 |
|
---|
[15] | 44 | void ComboBox::ui_to_var(void) { combobox_value = combobox->currentIndex(); }
|
---|
[9] | 45 |
|
---|
[15] | 46 | void ComboBox::ui_to_xml(void) {
|
---|
| 47 | SetValue(QString::number(combobox->currentIndex()));
|
---|
[9] | 48 | }
|
---|
| 49 |
|
---|
[15] | 50 | void ComboBox::Reset(void) { combobox->setCurrentIndex(combobox_value); }
|
---|
[9] | 51 |
|
---|
[15] | 52 | void ComboBox::LoadEvent(QDomElement dom) {
|
---|
| 53 | if (combobox->isEnabled() == true) {
|
---|
| 54 | combobox->setCurrentIndex((dom.attribute("value")).toInt());
|
---|
| 55 | }
|
---|
[9] | 56 | }
|
---|
| 57 |
|
---|
[15] | 58 | void ComboBox::valuechanged(int value) {
|
---|
| 59 | if (value != combobox_value) {
|
---|
| 60 | visible_widget->setPalette(red_pal);
|
---|
| 61 | } else {
|
---|
| 62 | visible_widget->setPalette(black_pal);
|
---|
| 63 | }
|
---|
[9] | 64 | }
|
---|