iCub-main
customcombobox.cpp
Go to the documentation of this file.
1 #include "customcombobox.h"
2 #include "downloader.h"
3 
4 CustomComboBox::CustomComboBox(QWidget *parent) : QComboBox(parent), mutex(QMutex::Recursive)
5 {
6  initialized = false;
7 
8  modified = false;
9  setStyleSheet("font: 9pt");
10  previousIndex = -1;
11  connect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
12 
13  initItems();
14 }
15 
16 
18 {
19  mutex.lock();
20  if(previousIndex < 0){
21  mutex.unlock();
22  return;
23  }
24  disconnect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
25  //setCurrentIndex(previousIndex);
26  previousIndex = -1;
27  modified = false;
28  setStyleSheet("font: 9pt");
29  connect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
30  mutex.unlock();
31 }
32 
34 {
35  mutex.lock();
36  if(previousIndex >= 0){
37  if(modified || v == currentIndex()){
38  mutex.unlock();
39  return;
40  }
41  }
42  disconnect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
43  setCurrentIndex(v);
44  previousIndex = v;
45  connect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
46  mutex.unlock();
47 }
48 
49 void CustomComboBox::onCurrentIndexChanged(int v)
50 {
51  mutex.lock();
52  if(previousIndex < 0){
53  mutex.unlock();
54  return;
55  }
56 
57  if(v == count() -1 && itemData(count() - 1,GAINAMPROLE).toInt() < 0){
58  removeItem(count() - 1);
59  disconnect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
60  setCurrentIndex(0);
61  previousIndex = 0;
62  connect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
63  } else if(itemData(count() - 1,GAINAMPROLE).toInt() < 0){
64  removeItem(count() - 1);
65  }
66 
67  modified = true;
68  setStyleSheet("color: rgb(239, 41, 41);"
69  "font: bold 9pt");
70  mutex.unlock();
71 }
72 
74 {
75  mutex.lock();
76  while (count() > 0) {
77  removeItem(count() - 1);
78  }
79  initialized = false;
80  mutex.unlock();
81 }
83 {
84  mutex.lock();
85  if(initialized){
86  mutex.unlock();
87  return;
88  }
89  //Luca
90  addItem("256,000",256);
91  setItemData(count() - 1,ampl_gain256,GAINAMPROLE);
92  addItem("128,000",128);
93  setItemData(count() - 1,ampl_gain128,GAINAMPROLE);
94  addItem("96,000",96);
95  setItemData(count() - 1,ampl_gain96,GAINAMPROLE);
96  addItem("64,000",64);
97  setItemData(count() - 1,ampl_gain64,GAINAMPROLE);
98  addItem("48,000",48);
99  setItemData(count() - 1,ampl_gain48,GAINAMPROLE);
100  addItem("36,000",36);
101  setItemData(count() - 1,ampl_gain36,GAINAMPROLE);
102  addItem("24,000",24);
103  setItemData(count() - 1,ampl_gain24,GAINAMPROLE);
104  addItem("20,000",20);
105  setItemData(count() - 1,ampl_gain20,GAINAMPROLE);
106  addItem("16,000",16);
107  setItemData(count() - 1,ampl_gain16,GAINAMPROLE);
108  addItem("10,000",10);
109  setItemData(count() - 1,ampl_gain10,GAINAMPROLE);
110  addItem("8,000",8);
111  setItemData(count() - 1,ampl_gain08,GAINAMPROLE);
112  addItem("6,000",6);
113  setItemData(count() - 1,ampl_gain06,GAINAMPROLE);
114  addItem("4,000",4);
115  setItemData(count() - 1,ampl_gain04,GAINAMPROLE);
116 
117  initialized = true;
118  mutex.unlock();
119 }
120 
122 {
123 
124 
125  mutex.lock();
126  int index;
127  disconnect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
128 
129  //LUCA
130  switch (g) {
131  case ampl_gain256:
132  case ampl_gain128:
133  case ampl_gain96:
134  case ampl_gain64:
135  case ampl_gain48:
136  case ampl_gain36:
137  case ampl_gain24:
138  case ampl_gain20:
139  case ampl_gain16:
140  case ampl_gain10:
141  case ampl_gain08:
142  case ampl_gain06:
143  case ampl_gain04:
144  index = g;
145  break;
146  default:
147  index = 0;
148  break;
149  }
150  setStyleSheet("color: rgb(239, 41, 41);"
151  "font: bold 9pt");
152  modified = true;
153  setCurrentIndex(index);
154  previousIndex = index;
155  connect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
156  mutex.unlock();
157 }
158 
160 {
161  mutex.lock();
162  int c = count();
163  QString s = QString("%1").arg(val);
164  QString s1 = itemText(c - 1);
165 
166 
167  if(modified || s1 == s){
168  mutex.unlock();
169  return;
170  }
171  if(itemData(c - 1,GAINAMPROLE ).toInt() < 0){
172  removeItem(c - 1);
173  }
174  addItem(s,val);
175  setItemData(c, -100, GAINAMPROLE);
176  disconnect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
177  setCurrentIndex(c);
178  connect(this,SIGNAL(currentIndexChanged(int)),this,SLOT(onCurrentIndexChanged(int)));
179  previousIndex = c;
180  mutex.unlock();
181 }
182 
void setCurrIndex(int v)
void addCustomValue(float val)
CustomComboBox(QWidget *parent=nullptr)
void setIndexFromAmpGain(int g)
#define GAINAMPROLE
Definition: customcombobox.h:8
@ ampl_gain36
Definition: downloader.h:106
@ ampl_gain08
Definition: downloader.h:107
@ ampl_gain24
Definition: downloader.h:106
@ ampl_gain256
Definition: downloader.h:106
@ ampl_gain64
Definition: downloader.h:106
@ ampl_gain06
Definition: downloader.h:107
@ ampl_gain96
Definition: downloader.h:106
@ ampl_gain10
Definition: downloader.h:107
@ ampl_gain48
Definition: downloader.h:106
@ ampl_gain16
Definition: downloader.h:106
@ ampl_gain20
Definition: downloader.h:106
@ ampl_gain04
Definition: downloader.h:107
@ ampl_gain128
Definition: downloader.h:106