36 |
36 |
37 KeyBinder::KeyBinder(QWidget * parent, const QString & helpText, const QString & defaultText, const QString & resetButtonText) : QWidget(parent) |
37 KeyBinder::KeyBinder(QWidget * parent, const QString & helpText, const QString & defaultText, const QString & resetButtonText) : QWidget(parent) |
38 { |
38 { |
39 this->defaultText = defaultText; |
39 this->defaultText = defaultText; |
40 enableSignal = false; |
40 enableSignal = false; |
41 |
41 |
42 // Two-column tab layout |
42 // Two-column tab layout |
43 QHBoxLayout * pageKeysLayout = new QHBoxLayout(this); |
43 QHBoxLayout * pageKeysLayout = new QHBoxLayout(this); |
44 pageKeysLayout->setSpacing(0); |
44 pageKeysLayout->setSpacing(0); |
45 pageKeysLayout->setContentsMargins(0, 0, 0, 0); |
45 pageKeysLayout->setContentsMargins(0, 0, 0, 0); |
46 |
46 |
47 // Table for category list |
47 // Table for category list |
48 QVBoxLayout * catListContainer = new QVBoxLayout(); |
48 QVBoxLayout * catListContainer = new QVBoxLayout(); |
49 catListContainer->setContentsMargins(10, 10, 10, 10); |
49 catListContainer->setContentsMargins(10, 10, 10, 10); |
50 catList = new QListWidget(); |
50 catList = new QListWidget(); |
51 catList->setFixedWidth(180); |
51 catList->setFixedWidth(180); |
120 { |
120 { |
121 if (cbinds[i].category != NULL) |
121 if (cbinds[i].category != NULL) |
122 { |
122 { |
123 // Add stretch at end of previous layout |
123 // Add stretch at end of previous layout |
124 if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
124 if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
125 |
125 |
126 // Category list item |
126 // Category list item |
127 QListWidgetItem * catItem = new QListWidgetItem(HWApplication::translate("binds (categories)", cbinds[i].category)); |
127 QListWidgetItem * catItem = new QListWidgetItem(HWApplication::translate("binds (categories)", cbinds[i].category)); |
128 catItem->setSizeHint(catSize); |
128 catItem->setSizeHint(catSize); |
129 catList->addItem(catItem); |
129 catList->addItem(catItem); |
130 |
130 |
131 // Create new page |
131 // Create new page |
132 curPage = new QWidget(); |
132 curPage = new QWidget(); |
133 curLayout = new QVBoxLayout(curPage); |
133 curLayout = new QVBoxLayout(curPage); |
134 curLayout->setSpacing(2); |
134 curLayout->setSpacing(2); |
135 bindingsPages->addWidget(curPage); |
135 bindingsPages->addWidget(curPage); |
168 // Hidden combo box |
168 // Hidden combo box |
169 QComboBox * comboBox = CBBind[i] = new QComboBox(curTable); |
169 QComboBox * comboBox = CBBind[i] = new QComboBox(curTable); |
170 comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); |
170 comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); |
171 comboBox->setVisible(false); |
171 comboBox->setVisible(false); |
172 comboBox->setFixedWidth(200); |
172 comboBox->setFixedWidth(200); |
173 |
173 |
174 // Table row |
174 // Table row |
175 int row = curTable->rowCount(); |
175 int row = curTable->rowCount(); |
176 QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); |
176 QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); |
177 nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
177 nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
178 curTable->insertRow(row); |
178 curTable->insertRow(row); |
239 void KeyBinder::bindCellClicked(QTableWidgetItem * item) |
239 void KeyBinder::bindCellClicked(QTableWidgetItem * item) |
240 { |
240 { |
241 QComboBox * box = bindCellComboBoxMappings->value(item); |
241 QComboBox * box = bindCellComboBoxMappings->value(item); |
242 QTableWidget * table = item->tableWidget(); |
242 QTableWidget * table = item->tableWidget(); |
243 QFrame * frame = box->findChild<QFrame*>(); |
243 QFrame * frame = box->findChild<QFrame*>(); |
244 |
244 |
245 box->showPopup(); |
245 box->showPopup(); |
246 frame->move( |
246 frame->move( |
247 frame->x() + table->horizontalHeader()->sectionSize(0), |
247 frame->x() + table->horizontalHeader()->sectionSize(0), |
248 frame->y() + (table->verticalHeader()->defaultSectionSize() * item->row()) |
248 frame->y() + (table->verticalHeader()->defaultSectionSize() * item->row()) |
249 ); |
249 ); |
277 |
277 |
278 // Clears selection and goes to first category |
278 // Clears selection and goes to first category |
279 void KeyBinder::resetInterface() |
279 void KeyBinder::resetInterface() |
280 { |
280 { |
281 enableSignal = false; |
281 enableSignal = false; |
282 |
282 |
283 catList->setCurrentItem(catList->item(1)); |
283 catList->setCurrentItem(catList->item(1)); |
284 changeBindingsPage(1); |
284 changeBindingsPage(1); |
285 if (selectedBindTable != NULL) |
285 if (selectedBindTable != NULL) |
286 { |
286 { |
287 selectedBindTable->clearSelection(); |
287 selectedBindTable->clearSelection(); |
288 selectedBindTable = NULL; |
288 selectedBindTable = NULL; |
289 } |
289 } |
290 |
290 |
291 // Default bind text |
291 // Default bind text |
292 DataManager::instance().bindsModel()->item(0)->setData(defaultText, Qt::DisplayRole); |
292 DataManager::instance().bindsModel()->item(0)->setData(defaultText, Qt::DisplayRole); |
293 for (int i = 0; i < BINDS_NUMBER; i++) |
293 for (int i = 0; i < BINDS_NUMBER; i++) |
294 { |
294 { |
295 CBBind[i]->setModel(DataManager::instance().bindsModel()); |
295 CBBind[i]->setModel(DataManager::instance().bindsModel()); |