author | Wuzzy <Wuzzy2@mail.ru> |
Sat, 27 Apr 2019 19:14:00 +0200 | |
changeset 14846 | 75b515a64202 |
parent 14218 | 925e2c9877a8 |
child 14899 | 4d5df8d35a95 |
permissions | -rw-r--r-- |
8346 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
8346 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
8346 | 17 |
*/ |
18 |
||
19 |
#include "keybinder.h" |
|
20 |
#include "HWApplication.h" |
|
21 |
#include "DataManager.h" |
|
22 |
#include <QHBoxLayout> |
|
23 |
#include <QScrollArea> |
|
24 |
#include <QTableWidget> |
|
25 |
#include <QTableWidgetItem> |
|
26 |
#include <QStandardItemModel> |
|
27 |
#include <QAbstractItemModel> |
|
28 |
#include <QListWidget> |
|
29 |
#include <QListWidgetItem> |
|
30 |
#include <QPushButton> |
|
31 |
#include <QHeaderView> |
|
32 |
#include <QComboBox> |
|
33 |
#include <QLabel> |
|
34 |
#include <QFrame> |
|
35 |
#include <QDebug> |
|
36 |
||
37 |
KeyBinder::KeyBinder(QWidget * parent, const QString & helpText, const QString & defaultText, const QString & resetButtonText) : QWidget(parent) |
|
38 |
{ |
|
39 |
this->defaultText = defaultText; |
|
40 |
enableSignal = false; |
|
8434 | 41 |
|
8346 | 42 |
// Two-column tab layout |
43 |
QHBoxLayout * pageKeysLayout = new QHBoxLayout(this); |
|
44 |
pageKeysLayout->setSpacing(0); |
|
45 |
pageKeysLayout->setContentsMargins(0, 0, 0, 0); |
|
8434 | 46 |
|
8346 | 47 |
// Table for category list |
48 |
QVBoxLayout * catListContainer = new QVBoxLayout(); |
|
49 |
catListContainer->setContentsMargins(10, 10, 10, 10); |
|
50 |
catList = new QListWidget(); |
|
51 |
catList->setFixedWidth(180); |
|
52 |
catList->setStyleSheet("QListWidget::item { font-size: 14px; } QListWidget:hover { border-color: #F6CB1C; } QListWidget::item:selected { background: #150A61; color: yellow; }"); |
|
53 |
catList->setFocusPolicy(Qt::NoFocus); |
|
54 |
connect(catList, SIGNAL(currentRowChanged(int)), this, SLOT(changeBindingsPage(int))); |
|
55 |
catListContainer->addWidget(catList); |
|
56 |
pageKeysLayout->addLayout(catListContainer); |
|
57 |
||
58 |
// Reset all binds button |
|
59 |
if (!resetButtonText.isEmpty()) |
|
60 |
{ |
|
61 |
QPushButton * btnResetAll = new QPushButton(resetButtonText); |
|
62 |
catListContainer->addWidget(btnResetAll); |
|
12236
a0ed4caa6d35
Apply minimal padding to all text buttons in frontend
Wuzzy <almikes@aol.com>
parents:
11674
diff
changeset
|
63 |
btnResetAll->setStyleSheet("padding: 5px 10px"); |
8346 | 64 |
btnResetAll->setFixedHeight(40); |
65 |
catListContainer->setStretch(1, 0); |
|
66 |
catListContainer->setSpacing(10); |
|
67 |
connect(btnResetAll, SIGNAL(clicked()), this, SIGNAL(resetAllBinds())); |
|
68 |
} |
|
69 |
||
70 |
// Container for pages of key bindings |
|
71 |
QWidget * bindingsPagesContainer = new QWidget(); |
|
72 |
QVBoxLayout * rightLayout = new QVBoxLayout(bindingsPagesContainer); |
|
73 |
||
74 |
// Scroll area for key bindings |
|
75 |
QScrollArea * scrollArea = new QScrollArea(); |
|
76 |
scrollArea->setContentsMargins(0, 0, 0, 0); |
|
77 |
scrollArea->setWidget(bindingsPagesContainer); |
|
78 |
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
|
79 |
scrollArea->setWidgetResizable(true); |
|
80 |
scrollArea->setFrameShape(QFrame::NoFrame); |
|
81 |
scrollArea->setStyleSheet("background: #130F2A;"); |
|
82 |
||
83 |
// Add key binding pages to bindings tab |
|
84 |
pageKeysLayout->addWidget(scrollArea); |
|
85 |
pageKeysLayout->setStretch(1, 1); |
|
86 |
||
87 |
// Custom help text |
|
88 |
QLabel * helpLabel = new QLabel(); |
|
89 |
helpLabel->setText(helpText); |
|
90 |
helpLabel->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-radius: 10px; padding: auto 20px;"); |
|
91 |
helpLabel->setFixedHeight(24); |
|
92 |
rightLayout->addWidget(helpLabel, 0, Qt::AlignCenter); |
|
93 |
||
94 |
// Category list and bind table row heights |
|
95 |
const int rowHeight = 20; |
|
96 |
QSize catSize, headerSize; |
|
97 |
catSize.setHeight(36); |
|
98 |
headerSize.setHeight(24); |
|
99 |
||
100 |
// Category list header |
|
101 |
QListWidgetItem * catListHeader = new QListWidgetItem(tr("Category")); |
|
102 |
catListHeader->setSizeHint(headerSize); |
|
103 |
catListHeader->setFlags(Qt::NoItemFlags); |
|
104 |
catListHeader->setForeground(QBrush(QColor("#130F2A"))); |
|
105 |
catListHeader->setBackground(QBrush(QColor("#F6CB1C"))); |
|
106 |
catListHeader->setTextAlignment(Qt::AlignCenter); |
|
107 |
catList->addItem(catListHeader); |
|
108 |
||
109 |
// Populate |
|
110 |
bindingsPages = new QHBoxLayout(); |
|
111 |
bindingsPages->setContentsMargins(0, 0, 0, 0); |
|
112 |
rightLayout->addLayout(bindingsPages); |
|
113 |
QWidget * curPage = NULL; |
|
114 |
QVBoxLayout * curLayout = NULL; |
|
115 |
QTableWidget * curTable = NULL; |
|
116 |
bool bFirstPage = true; |
|
117 |
selectedBindTable = NULL; |
|
118 |
bindComboBoxCellMappings = new QHash<QObject *, QTableWidgetItem *>(); |
|
119 |
bindCellComboBoxMappings = new QHash<QTableWidgetItem *, QComboBox *>(); |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
120 |
|
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
121 |
QIcon dropDownIcon = QIcon(); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
122 |
QPixmap dd1 = QPixmap(":/res/dropdown.png"); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
123 |
QPixmap dd2 = QPixmap(":/res/dropdown_selected.png"); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
124 |
dropDownIcon.addPixmap(dd1, QIcon::Normal); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
125 |
dropDownIcon.addPixmap(dd2, QIcon::Selected); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
126 |
QPixmap emptySpace = QPixmap(16, 16); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
127 |
emptySpace.fill(QColor(0, 0, 0, 0)); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
128 |
QIcon emptyIcon = QIcon(emptySpace); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
129 |
|
8346 | 130 |
for (int i = 0; i < BINDS_NUMBER; i++) |
131 |
{ |
|
132 |
if (cbinds[i].category != NULL) |
|
133 |
{ |
|
134 |
// Add stretch at end of previous layout |
|
135 |
if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
|
8434 | 136 |
|
8346 | 137 |
// Category list item |
138 |
QListWidgetItem * catItem = new QListWidgetItem(HWApplication::translate("binds (categories)", cbinds[i].category)); |
|
139 |
catItem->setSizeHint(catSize); |
|
140 |
catList->addItem(catItem); |
|
8434 | 141 |
|
8346 | 142 |
// Create new page |
143 |
curPage = new QWidget(); |
|
144 |
curLayout = new QVBoxLayout(curPage); |
|
145 |
curLayout->setSpacing(2); |
|
146 |
bindingsPages->addWidget(curPage); |
|
147 |
if (!bFirstPage) curPage->setVisible(false); |
|
148 |
} |
|
149 |
||
150 |
// Description |
|
151 |
if (cbinds[i].description != NULL) |
|
152 |
{ |
|
153 |
QLabel * desc = new QLabel(HWApplication::translate("binds (descriptions)", cbinds[i].description)); |
|
154 |
curLayout->addWidget(desc, 0); |
|
155 |
QFrame * divider = new QFrame(); |
|
156 |
divider->setFrameShape(QFrame::HLine); |
|
157 |
divider->setFrameShadow(QFrame::Plain); |
|
158 |
curLayout->addWidget(divider, 0); |
|
159 |
} |
|
160 |
||
161 |
// New table |
|
162 |
if (cbinds[i].category != NULL || cbinds[i].description != NULL) |
|
163 |
{ |
|
164 |
curTable = new QTableWidget(0, 2); |
|
165 |
curTable->verticalHeader()->setVisible(false); |
|
166 |
curTable->horizontalHeader()->setVisible(false); |
|
12897
fc47fc4af6bd
Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents:
12698
diff
changeset
|
167 |
curTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
8346 | 168 |
curTable->verticalHeader()->setDefaultSectionSize(rowHeight); |
169 |
curTable->setShowGrid(false); |
|
170 |
curTable->setStyleSheet("QTableWidget { border: none; } "); |
|
171 |
curTable->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
172 |
curTable->setSelectionMode(QAbstractItemView::SingleSelection); |
|
173 |
curTable->setFocusPolicy(Qt::NoFocus); |
|
174 |
connect(curTable, SIGNAL(itemSelectionChanged()), this, SLOT(bindSelectionChanged())); |
|
175 |
connect(curTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(bindCellClicked(QTableWidgetItem *))); |
|
176 |
curLayout->addWidget(curTable, 0); |
|
177 |
} |
|
178 |
||
179 |
// Hidden combo box |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
180 |
QComboBox * comboBox; |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
181 |
if (cbinds[i].action != "!MULTI") |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
182 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
183 |
comboBox = CBBind[i] = new QComboBox(curTable); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
184 |
comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
185 |
comboBox->setVisible(false); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
186 |
comboBox->setMinimumWidth(400); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
187 |
comboBox->setMaxVisibleItems(50); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
188 |
} |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
189 |
else |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
190 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
191 |
comboBox = CBBind[i] = NULL; |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
192 |
} |
8434 | 193 |
|
8346 | 194 |
// Table row |
195 |
int row = curTable->rowCount(); |
|
196 |
QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); |
|
197 |
curTable->insertRow(row); |
|
198 |
curTable->setItem(row, 0, nameCell); |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
199 |
QTableWidgetItem * bindCell; |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
200 |
if (cbinds[i].action != "!MULTI") |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
201 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
202 |
bindCell = new QTableWidgetItem(comboBox->currentText()); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
203 |
nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
204 |
bindCell->setIcon(dropDownIcon); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
205 |
bindCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
206 |
} |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
207 |
else |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
208 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
209 |
bindCell = new QTableWidgetItem(HWApplication::translate("binds (combination)", cbinds[i].strbind.toUtf8().constData())); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
210 |
nameCell->setFlags(Qt::NoItemFlags); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
211 |
bindCell->setFlags(Qt::NoItemFlags); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
212 |
bindCell->setIcon(emptyIcon); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
213 |
} |
8346 | 214 |
curTable->setItem(row, 1, bindCell); |
215 |
curTable->resizeColumnsToContents(); |
|
216 |
curTable->setFixedHeight(curTable->verticalHeader()->length() + 10); |
|
217 |
||
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
218 |
if (cbinds[i].action != "!MULTI") |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
219 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
220 |
// Updates the text in the table cell |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
221 |
connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(bindChanged(const QString &))); |
8346 | 222 |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
223 |
// Map combo box and that row's cells to each other |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
224 |
bindComboBoxCellMappings->insert(comboBox, bindCell); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
225 |
bindCellComboBoxMappings->insert(nameCell, comboBox); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
226 |
bindCellComboBoxMappings->insert(bindCell, comboBox); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
227 |
} |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
228 |
|
8346 | 229 |
} |
230 |
||
231 |
// Add stretch at end of last layout |
|
232 |
if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
|
233 |
||
234 |
// Go to first page |
|
235 |
catList->setCurrentItem(catList->item(1)); |
|
236 |
||
237 |
enableSignal = true; |
|
238 |
} |
|
239 |
||
240 |
KeyBinder::~KeyBinder() |
|
241 |
{ |
|
242 |
delete bindComboBoxCellMappings; |
|
243 |
delete bindCellComboBoxMappings; |
|
244 |
} |
|
245 |
||
246 |
// Switches between different pages of key binds |
|
247 |
void KeyBinder::changeBindingsPage(int page) |
|
248 |
{ |
|
249 |
page--; // Disregard first item (the list header) |
|
250 |
int pages = bindingsPages->count(); |
|
251 |
for (int i = 0; i < pages; i++) |
|
252 |
bindingsPages->itemAt(i)->widget()->setVisible(false); |
|
253 |
bindingsPages->itemAt(page)->widget()->setVisible(true); |
|
254 |
} |
|
255 |
||
256 |
// When a key bind combobox value is changed, updates the table cell text |
|
257 |
void KeyBinder::bindChanged(const QString & text) |
|
258 |
{ |
|
259 |
bindComboBoxCellMappings->value(sender())->setText(text); |
|
260 |
||
261 |
if (enableSignal) |
|
262 |
{ |
|
263 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
264 |
{ |
|
265 |
if (CBBind[i] == sender()) |
|
266 |
{ |
|
267 |
emit bindUpdate(i); |
|
268 |
break; |
|
269 |
} |
|
270 |
} |
|
271 |
} |
|
272 |
} |
|
273 |
||
274 |
// When a row in a key bind table is clicked, this shows the popup |
|
275 |
void KeyBinder::bindCellClicked(QTableWidgetItem * item) |
|
276 |
{ |
|
277 |
QComboBox * box = bindCellComboBoxMappings->value(item); |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
278 |
if(box == NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
279 |
return; |
8346 | 280 |
QTableWidget * table = item->tableWidget(); |
8434 | 281 |
|
12698
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12236
diff
changeset
|
282 |
box->move( |
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12236
diff
changeset
|
283 |
table->horizontalHeader()->sectionSize(0), |
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12236
diff
changeset
|
284 |
(table->verticalHeader()->defaultSectionSize() * (item->row() + 1)) - (box->height()) + 1 |
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12236
diff
changeset
|
285 |
); |
8346 | 286 |
box->showPopup(); |
287 |
} |
|
288 |
||
289 |
// When a new row in a bind table is *selected*, this clears selection in any other table |
|
290 |
void KeyBinder::bindSelectionChanged() |
|
291 |
{ |
|
292 |
QTableWidget * theSender = (QTableWidget*)sender(); |
|
293 |
if (theSender != selectedBindTable) |
|
294 |
{ |
|
295 |
if (selectedBindTable != NULL) |
|
296 |
selectedBindTable->clearSelection(); |
|
297 |
selectedBindTable = theSender; |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
// Set a combobox's index |
|
302 |
void KeyBinder::setBindIndex(int keyIndex, int bindIndex) |
|
303 |
{ |
|
304 |
enableSignal = false; |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
305 |
if(CBBind[keyIndex] != NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
306 |
CBBind[keyIndex]->setCurrentIndex(bindIndex); |
8346 | 307 |
enableSignal = true; |
308 |
} |
|
309 |
||
310 |
// Return a combobox's selected index |
|
311 |
int KeyBinder::bindIndex(int keyIndex) |
|
312 |
{ |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
313 |
if(CBBind[keyIndex] != NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
314 |
return CBBind[keyIndex]->currentIndex(); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
315 |
else |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
316 |
return 0; |
8346 | 317 |
} |
318 |
||
319 |
// Clears selection and goes to first category |
|
320 |
void KeyBinder::resetInterface() |
|
321 |
{ |
|
322 |
enableSignal = false; |
|
8434 | 323 |
|
8346 | 324 |
catList->setCurrentItem(catList->item(1)); |
325 |
changeBindingsPage(1); |
|
326 |
if (selectedBindTable != NULL) |
|
327 |
{ |
|
328 |
selectedBindTable->clearSelection(); |
|
329 |
selectedBindTable = NULL; |
|
330 |
} |
|
8434 | 331 |
|
8346 | 332 |
// Default bind text |
333 |
DataManager::instance().bindsModel()->item(0)->setData(defaultText, Qt::DisplayRole); |
|
334 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
335 |
{ |
|
14846
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
336 |
if (CBBind[i] != NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
337 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
338 |
CBBind[i]->setModel(DataManager::instance().bindsModel()); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
339 |
CBBind[i]->setCurrentIndex(0); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
340 |
bindComboBoxCellMappings->value(CBBind[i])->setText(defaultText); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14218
diff
changeset
|
341 |
} |
8346 | 342 |
} |
343 |
||
344 |
enableSignal = true; |
|
345 |
} |