115 QTableWidget * curTable = NULL; |
115 QTableWidget * curTable = NULL; |
116 bool bFirstPage = true; |
116 bool bFirstPage = true; |
117 selectedBindTable = NULL; |
117 selectedBindTable = NULL; |
118 bindComboBoxCellMappings = new QHash<QObject *, QTableWidgetItem *>(); |
118 bindComboBoxCellMappings = new QHash<QObject *, QTableWidgetItem *>(); |
119 bindCellComboBoxMappings = new QHash<QTableWidgetItem *, QComboBox *>(); |
119 bindCellComboBoxMappings = new QHash<QTableWidgetItem *, QComboBox *>(); |
|
120 |
|
121 QIcon dropDownIcon = QIcon(); |
|
122 QPixmap dd1 = QPixmap(":/res/dropdown.png"); |
|
123 QPixmap dd2 = QPixmap(":/res/dropdown_selected.png"); |
|
124 dropDownIcon.addPixmap(dd1, QIcon::Normal); |
|
125 dropDownIcon.addPixmap(dd2, QIcon::Selected); |
|
126 QPixmap emptySpace = QPixmap(16, 16); |
|
127 emptySpace.fill(QColor(0, 0, 0, 0)); |
|
128 QIcon emptyIcon = QIcon(emptySpace); |
|
129 |
120 for (int i = 0; i < BINDS_NUMBER; i++) |
130 for (int i = 0; i < BINDS_NUMBER; i++) |
121 { |
131 { |
122 if (cbinds[i].category != NULL) |
132 if (cbinds[i].category != NULL) |
123 { |
133 { |
124 // Add stretch at end of previous layout |
134 // Add stretch at end of previous layout |
165 connect(curTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(bindCellClicked(QTableWidgetItem *))); |
175 connect(curTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(bindCellClicked(QTableWidgetItem *))); |
166 curLayout->addWidget(curTable, 0); |
176 curLayout->addWidget(curTable, 0); |
167 } |
177 } |
168 |
178 |
169 // Hidden combo box |
179 // Hidden combo box |
170 QComboBox * comboBox = CBBind[i] = new QComboBox(curTable); |
180 QComboBox * comboBox; |
171 comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); |
181 if (cbinds[i].action != "!MULTI") |
172 comboBox->setVisible(false); |
182 { |
173 comboBox->setMinimumWidth(400); |
183 comboBox = CBBind[i] = new QComboBox(curTable); |
174 comboBox->setMaxVisibleItems(50); |
184 comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); |
|
185 comboBox->setVisible(false); |
|
186 comboBox->setMinimumWidth(400); |
|
187 comboBox->setMaxVisibleItems(50); |
|
188 } |
|
189 else |
|
190 { |
|
191 comboBox = CBBind[i] = NULL; |
|
192 } |
175 |
193 |
176 // Table row |
194 // Table row |
177 int row = curTable->rowCount(); |
195 int row = curTable->rowCount(); |
178 QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); |
196 QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); |
179 nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
|
180 curTable->insertRow(row); |
197 curTable->insertRow(row); |
181 curTable->setItem(row, 0, nameCell); |
198 curTable->setItem(row, 0, nameCell); |
182 QTableWidgetItem * bindCell = new QTableWidgetItem(comboBox->currentText()); |
199 QTableWidgetItem * bindCell; |
183 QIcon dropDownIcon = QIcon(); |
200 if (cbinds[i].action != "!MULTI") |
184 QPixmap dd1 = QPixmap(":/res/dropdown.png"); |
201 { |
185 QPixmap dd2 = QPixmap(":/res/dropdown_selected.png"); |
202 bindCell = new QTableWidgetItem(comboBox->currentText()); |
186 dropDownIcon.addPixmap(dd1, QIcon::Normal); |
203 nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
187 dropDownIcon.addPixmap(dd2, QIcon::Selected); |
204 bindCell->setIcon(dropDownIcon); |
188 bindCell->setIcon(dropDownIcon); |
205 bindCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
189 bindCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
206 } |
|
207 else |
|
208 { |
|
209 bindCell = new QTableWidgetItem(HWApplication::translate("binds (combination)", cbinds[i].strbind.toUtf8().constData())); |
|
210 nameCell->setFlags(Qt::NoItemFlags); |
|
211 bindCell->setFlags(Qt::NoItemFlags); |
|
212 bindCell->setIcon(emptyIcon); |
|
213 } |
190 curTable->setItem(row, 1, bindCell); |
214 curTable->setItem(row, 1, bindCell); |
191 curTable->resizeColumnsToContents(); |
215 curTable->resizeColumnsToContents(); |
192 curTable->setFixedHeight(curTable->verticalHeader()->length() + 10); |
216 curTable->setFixedHeight(curTable->verticalHeader()->length() + 10); |
193 |
217 |
194 // Updates the text in the table cell |
218 if (cbinds[i].action != "!MULTI") |
195 connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(bindChanged(const QString &))); |
219 { |
196 |
220 // Updates the text in the table cell |
197 // Map combo box and that row's cells to each other |
221 connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(bindChanged(const QString &))); |
198 bindComboBoxCellMappings->insert(comboBox, bindCell); |
222 |
199 bindCellComboBoxMappings->insert(nameCell, comboBox); |
223 // Map combo box and that row's cells to each other |
200 bindCellComboBoxMappings->insert(bindCell, comboBox); |
224 bindComboBoxCellMappings->insert(comboBox, bindCell); |
|
225 bindCellComboBoxMappings->insert(nameCell, comboBox); |
|
226 bindCellComboBoxMappings->insert(bindCell, comboBox); |
|
227 } |
|
228 |
201 } |
229 } |
202 |
230 |
203 // Add stretch at end of last layout |
231 // Add stretch at end of last layout |
204 if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
232 if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
205 |
233 |
270 |
300 |
271 // Set a combobox's index |
301 // Set a combobox's index |
272 void KeyBinder::setBindIndex(int keyIndex, int bindIndex) |
302 void KeyBinder::setBindIndex(int keyIndex, int bindIndex) |
273 { |
303 { |
274 enableSignal = false; |
304 enableSignal = false; |
275 CBBind[keyIndex]->setCurrentIndex(bindIndex); |
305 if(CBBind[keyIndex] != NULL) |
|
306 CBBind[keyIndex]->setCurrentIndex(bindIndex); |
276 enableSignal = true; |
307 enableSignal = true; |
277 } |
308 } |
278 |
309 |
279 // Return a combobox's selected index |
310 // Return a combobox's selected index |
280 int KeyBinder::bindIndex(int keyIndex) |
311 int KeyBinder::bindIndex(int keyIndex) |
281 { |
312 { |
282 return CBBind[keyIndex]->currentIndex(); |
313 if(CBBind[keyIndex] != NULL) |
|
314 return CBBind[keyIndex]->currentIndex(); |
|
315 else |
|
316 return 0; |
283 } |
317 } |
284 |
318 |
285 // Clears selection and goes to first category |
319 // Clears selection and goes to first category |
286 void KeyBinder::resetInterface() |
320 void KeyBinder::resetInterface() |
287 { |
321 { |