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 "ComboBox.h"
|
---|
6 | #include "Layout.h"
|
---|
7 | #include <QComboBox>
|
---|
8 | #include <QFormLayout>
|
---|
9 |
|
---|
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);
|
---|
14 |
|
---|
15 | combobox_value = value;
|
---|
16 |
|
---|
17 | object_layout->addRow(name, combobox);
|
---|
18 |
|
---|
19 | connect(combobox, SIGNAL(currentIndexChanged(int)), this,
|
---|
20 | SLOT(valuechanged(int)));
|
---|
21 |
|
---|
22 | SetValue(QString::number(combobox_value));
|
---|
23 |
|
---|
24 | // pour ne pas faire de doublons qd on ajoute des items
|
---|
25 | SetIsExpandable(true);
|
---|
26 | }
|
---|
27 |
|
---|
28 | ComboBox::~ComboBox() { delete combobox; }
|
---|
29 |
|
---|
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 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | void ComboBox::SetUptodate(void) {
|
---|
39 | ui_to_var();
|
---|
40 | ui_to_xml();
|
---|
41 | visible_widget->setPalette(black_pal);
|
---|
42 | }
|
---|
43 |
|
---|
44 | void ComboBox::ui_to_var(void) { combobox_value = combobox->currentIndex(); }
|
---|
45 |
|
---|
46 | void ComboBox::ui_to_xml(void) {
|
---|
47 | SetValue(QString::number(combobox->currentIndex()));
|
---|
48 | }
|
---|
49 |
|
---|
50 | void ComboBox::Reset(void) { combobox->setCurrentIndex(combobox_value); }
|
---|
51 |
|
---|
52 | void ComboBox::LoadEvent(QDomElement dom) {
|
---|
53 | if (combobox->isEnabled() == true) {
|
---|
54 | combobox->setCurrentIndex((dom.attribute("value")).toInt());
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
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 | }
|
---|
64 | }
|
---|