author | Wuzzy <Wuzzy2@mail.ru> |
Tue, 07 May 2019 18:45:14 +0200 | |
changeset 14904 | 4d5df8d35a95 |
parent 14851 | 75b515a64202 |
child 14905 | 505c8d101be3 |
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; |
|
14904
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
41 |
p_hasConflicts = false; |
8434 | 42 |
|
8346 | 43 |
// Two-column tab layout |
44 |
QHBoxLayout * pageKeysLayout = new QHBoxLayout(this); |
|
45 |
pageKeysLayout->setSpacing(0); |
|
46 |
pageKeysLayout->setContentsMargins(0, 0, 0, 0); |
|
8434 | 47 |
|
8346 | 48 |
// Table for category list |
49 |
QVBoxLayout * catListContainer = new QVBoxLayout(); |
|
50 |
catListContainer->setContentsMargins(10, 10, 10, 10); |
|
51 |
catList = new QListWidget(); |
|
52 |
catList->setFixedWidth(180); |
|
53 |
catList->setStyleSheet("QListWidget::item { font-size: 14px; } QListWidget:hover { border-color: #F6CB1C; } QListWidget::item:selected { background: #150A61; color: yellow; }"); |
|
54 |
catList->setFocusPolicy(Qt::NoFocus); |
|
55 |
connect(catList, SIGNAL(currentRowChanged(int)), this, SLOT(changeBindingsPage(int))); |
|
56 |
catListContainer->addWidget(catList); |
|
57 |
pageKeysLayout->addLayout(catListContainer); |
|
58 |
||
59 |
// Reset all binds button |
|
60 |
if (!resetButtonText.isEmpty()) |
|
61 |
{ |
|
62 |
QPushButton * btnResetAll = new QPushButton(resetButtonText); |
|
63 |
catListContainer->addWidget(btnResetAll); |
|
12241
a0ed4caa6d35
Apply minimal padding to all text buttons in frontend
Wuzzy <almikes@aol.com>
parents:
11679
diff
changeset
|
64 |
btnResetAll->setStyleSheet("padding: 5px 10px"); |
8346 | 65 |
btnResetAll->setFixedHeight(40); |
66 |
catListContainer->setStretch(1, 0); |
|
67 |
catListContainer->setSpacing(10); |
|
68 |
connect(btnResetAll, SIGNAL(clicked()), this, SIGNAL(resetAllBinds())); |
|
69 |
} |
|
70 |
||
71 |
// Container for pages of key bindings |
|
72 |
QWidget * bindingsPagesContainer = new QWidget(); |
|
73 |
QVBoxLayout * rightLayout = new QVBoxLayout(bindingsPagesContainer); |
|
74 |
||
75 |
// Scroll area for key bindings |
|
76 |
QScrollArea * scrollArea = new QScrollArea(); |
|
77 |
scrollArea->setContentsMargins(0, 0, 0, 0); |
|
78 |
scrollArea->setWidget(bindingsPagesContainer); |
|
79 |
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
|
80 |
scrollArea->setWidgetResizable(true); |
|
81 |
scrollArea->setFrameShape(QFrame::NoFrame); |
|
82 |
scrollArea->setStyleSheet("background: #130F2A;"); |
|
83 |
||
84 |
// Add key binding pages to bindings tab |
|
85 |
pageKeysLayout->addWidget(scrollArea); |
|
86 |
pageKeysLayout->setStretch(1, 1); |
|
87 |
||
88 |
// Custom help text |
|
89 |
QLabel * helpLabel = new QLabel(); |
|
90 |
helpLabel->setText(helpText); |
|
91 |
helpLabel->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-radius: 10px; padding: auto 20px;"); |
|
92 |
helpLabel->setFixedHeight(24); |
|
93 |
rightLayout->addWidget(helpLabel, 0, Qt::AlignCenter); |
|
14904
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
94 |
conflictLabel = new QLabel(); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
95 |
conflictLabel->setText(tr("Warning: The same key is assigned multiple times!")); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
96 |
conflictLabel->setStyleSheet("color: #FFFFFF; background: #E31A1A; border: solid 4px #E31A1A; border-radius: 10px; padding: auto 20px;"); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
97 |
conflictLabel->setFixedHeight(24); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
98 |
conflictLabel->setHidden(true); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
99 |
rightLayout->addWidget(conflictLabel, 0, Qt::AlignCenter); |
8346 | 100 |
|
101 |
// Category list and bind table row heights |
|
102 |
const int rowHeight = 20; |
|
103 |
QSize catSize, headerSize; |
|
104 |
catSize.setHeight(36); |
|
105 |
headerSize.setHeight(24); |
|
106 |
||
107 |
// Category list header |
|
108 |
QListWidgetItem * catListHeader = new QListWidgetItem(tr("Category")); |
|
109 |
catListHeader->setSizeHint(headerSize); |
|
110 |
catListHeader->setFlags(Qt::NoItemFlags); |
|
111 |
catListHeader->setForeground(QBrush(QColor("#130F2A"))); |
|
112 |
catListHeader->setBackground(QBrush(QColor("#F6CB1C"))); |
|
113 |
catListHeader->setTextAlignment(Qt::AlignCenter); |
|
114 |
catList->addItem(catListHeader); |
|
115 |
||
116 |
// Populate |
|
117 |
bindingsPages = new QHBoxLayout(); |
|
118 |
bindingsPages->setContentsMargins(0, 0, 0, 0); |
|
119 |
rightLayout->addLayout(bindingsPages); |
|
120 |
QWidget * curPage = NULL; |
|
121 |
QVBoxLayout * curLayout = NULL; |
|
122 |
QTableWidget * curTable = NULL; |
|
123 |
bool bFirstPage = true; |
|
124 |
selectedBindTable = NULL; |
|
125 |
bindComboBoxCellMappings = new QHash<QObject *, QTableWidgetItem *>(); |
|
126 |
bindCellComboBoxMappings = new QHash<QTableWidgetItem *, QComboBox *>(); |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
127 |
|
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
128 |
QIcon dropDownIcon = QIcon(); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
129 |
QPixmap dd1 = QPixmap(":/res/dropdown.png"); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
130 |
QPixmap dd2 = QPixmap(":/res/dropdown_selected.png"); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
131 |
dropDownIcon.addPixmap(dd1, QIcon::Normal); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
132 |
dropDownIcon.addPixmap(dd2, QIcon::Selected); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
133 |
QPixmap emptySpace = QPixmap(16, 16); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
134 |
emptySpace.fill(QColor(0, 0, 0, 0)); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
135 |
QIcon emptyIcon = QIcon(emptySpace); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
136 |
|
8346 | 137 |
for (int i = 0; i < BINDS_NUMBER; i++) |
138 |
{ |
|
139 |
if (cbinds[i].category != NULL) |
|
140 |
{ |
|
141 |
// Add stretch at end of previous layout |
|
142 |
if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
|
8434 | 143 |
|
8346 | 144 |
// Category list item |
145 |
QListWidgetItem * catItem = new QListWidgetItem(HWApplication::translate("binds (categories)", cbinds[i].category)); |
|
146 |
catItem->setSizeHint(catSize); |
|
147 |
catList->addItem(catItem); |
|
8434 | 148 |
|
8346 | 149 |
// Create new page |
150 |
curPage = new QWidget(); |
|
151 |
curLayout = new QVBoxLayout(curPage); |
|
152 |
curLayout->setSpacing(2); |
|
153 |
bindingsPages->addWidget(curPage); |
|
154 |
if (!bFirstPage) curPage->setVisible(false); |
|
155 |
} |
|
156 |
||
157 |
// Description |
|
158 |
if (cbinds[i].description != NULL) |
|
159 |
{ |
|
160 |
QLabel * desc = new QLabel(HWApplication::translate("binds (descriptions)", cbinds[i].description)); |
|
161 |
curLayout->addWidget(desc, 0); |
|
162 |
QFrame * divider = new QFrame(); |
|
163 |
divider->setFrameShape(QFrame::HLine); |
|
164 |
divider->setFrameShadow(QFrame::Plain); |
|
165 |
curLayout->addWidget(divider, 0); |
|
166 |
} |
|
167 |
||
168 |
// New table |
|
169 |
if (cbinds[i].category != NULL || cbinds[i].description != NULL) |
|
170 |
{ |
|
171 |
curTable = new QTableWidget(0, 2); |
|
172 |
curTable->verticalHeader()->setVisible(false); |
|
173 |
curTable->horizontalHeader()->setVisible(false); |
|
12902
fc47fc4af6bd
Finish porting. Seems to work, but no thorough testing has been performed
unc0rr
parents:
12703
diff
changeset
|
174 |
curTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); |
8346 | 175 |
curTable->verticalHeader()->setDefaultSectionSize(rowHeight); |
176 |
curTable->setShowGrid(false); |
|
177 |
curTable->setStyleSheet("QTableWidget { border: none; } "); |
|
178 |
curTable->setSelectionBehavior(QAbstractItemView::SelectRows); |
|
179 |
curTable->setSelectionMode(QAbstractItemView::SingleSelection); |
|
180 |
curTable->setFocusPolicy(Qt::NoFocus); |
|
181 |
connect(curTable, SIGNAL(itemSelectionChanged()), this, SLOT(bindSelectionChanged())); |
|
182 |
connect(curTable, SIGNAL(itemClicked(QTableWidgetItem *)), this, SLOT(bindCellClicked(QTableWidgetItem *))); |
|
183 |
curLayout->addWidget(curTable, 0); |
|
184 |
} |
|
185 |
||
186 |
// Hidden combo box |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
187 |
QComboBox * comboBox; |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
188 |
if (cbinds[i].action != "!MULTI") |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
189 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
190 |
comboBox = CBBind[i] = new QComboBox(curTable); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
191 |
comboBox->setModel((QAbstractItemModel*)DataManager::instance().bindsModel()); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
192 |
comboBox->setVisible(false); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
193 |
comboBox->setMinimumWidth(400); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
194 |
comboBox->setMaxVisibleItems(50); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
195 |
} |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
196 |
else |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
197 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
198 |
comboBox = CBBind[i] = NULL; |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
199 |
} |
8434 | 200 |
|
8346 | 201 |
// Table row |
202 |
int row = curTable->rowCount(); |
|
203 |
QTableWidgetItem * nameCell = new QTableWidgetItem(HWApplication::translate("binds", cbinds[i].name)); |
|
204 |
curTable->insertRow(row); |
|
205 |
curTable->setItem(row, 0, nameCell); |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
206 |
QTableWidgetItem * bindCell; |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
207 |
if (cbinds[i].action != "!MULTI") |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
208 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
209 |
bindCell = new QTableWidgetItem(comboBox->currentText()); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
210 |
nameCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
211 |
bindCell->setIcon(dropDownIcon); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
212 |
bindCell->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
213 |
} |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
214 |
else |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
215 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
216 |
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:
14223
diff
changeset
|
217 |
nameCell->setFlags(Qt::NoItemFlags); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
218 |
bindCell->setFlags(Qt::NoItemFlags); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
219 |
bindCell->setIcon(emptyIcon); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
220 |
} |
8346 | 221 |
curTable->setItem(row, 1, bindCell); |
222 |
curTable->resizeColumnsToContents(); |
|
223 |
curTable->setFixedHeight(curTable->verticalHeader()->length() + 10); |
|
224 |
||
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
225 |
if (cbinds[i].action != "!MULTI") |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
226 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
227 |
// Updates the text in the table cell |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
228 |
connect(comboBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(bindChanged(const QString &))); |
8346 | 229 |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
230 |
// 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:
14223
diff
changeset
|
231 |
bindComboBoxCellMappings->insert(comboBox, bindCell); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
232 |
bindCellComboBoxMappings->insert(nameCell, comboBox); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
233 |
bindCellComboBoxMappings->insert(bindCell, comboBox); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
234 |
} |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
235 |
|
8346 | 236 |
} |
237 |
||
238 |
// Add stretch at end of last layout |
|
239 |
if (curLayout != NULL) curLayout->insertStretch(-1, 1); |
|
240 |
||
241 |
// Go to first page |
|
242 |
catList->setCurrentItem(catList->item(1)); |
|
243 |
||
244 |
enableSignal = true; |
|
245 |
} |
|
246 |
||
247 |
KeyBinder::~KeyBinder() |
|
248 |
{ |
|
249 |
delete bindComboBoxCellMappings; |
|
250 |
delete bindCellComboBoxMappings; |
|
251 |
} |
|
252 |
||
253 |
// Switches between different pages of key binds |
|
254 |
void KeyBinder::changeBindingsPage(int page) |
|
255 |
{ |
|
256 |
page--; // Disregard first item (the list header) |
|
257 |
int pages = bindingsPages->count(); |
|
258 |
for (int i = 0; i < pages; i++) |
|
259 |
bindingsPages->itemAt(i)->widget()->setVisible(false); |
|
260 |
bindingsPages->itemAt(page)->widget()->setVisible(true); |
|
261 |
} |
|
262 |
||
263 |
// When a key bind combobox value is changed, updates the table cell text |
|
264 |
void KeyBinder::bindChanged(const QString & text) |
|
265 |
{ |
|
266 |
bindComboBoxCellMappings->value(sender())->setText(text); |
|
267 |
||
268 |
if (enableSignal) |
|
269 |
{ |
|
270 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
271 |
{ |
|
272 |
if (CBBind[i] == sender()) |
|
273 |
{ |
|
274 |
emit bindUpdate(i); |
|
14904
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
275 |
checkConflicts(); |
8346 | 276 |
break; |
277 |
} |
|
278 |
} |
|
279 |
} |
|
280 |
} |
|
281 |
||
282 |
// When a row in a key bind table is clicked, this shows the popup |
|
283 |
void KeyBinder::bindCellClicked(QTableWidgetItem * item) |
|
284 |
{ |
|
285 |
QComboBox * box = bindCellComboBoxMappings->value(item); |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
286 |
if(box == NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
287 |
return; |
8346 | 288 |
QTableWidget * table = item->tableWidget(); |
8434 | 289 |
|
12703
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12241
diff
changeset
|
290 |
box->move( |
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12241
diff
changeset
|
291 |
table->horizontalHeader()->sectionSize(0), |
f2690a0ccf19
QTfrontend: Fix flickering and bad offset of control config popup
Wuzzy <almikes@aol.com>
parents:
12241
diff
changeset
|
292 |
(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:
12241
diff
changeset
|
293 |
); |
8346 | 294 |
box->showPopup(); |
295 |
} |
|
296 |
||
297 |
// When a new row in a bind table is *selected*, this clears selection in any other table |
|
298 |
void KeyBinder::bindSelectionChanged() |
|
299 |
{ |
|
300 |
QTableWidget * theSender = (QTableWidget*)sender(); |
|
301 |
if (theSender != selectedBindTable) |
|
302 |
{ |
|
303 |
if (selectedBindTable != NULL) |
|
304 |
selectedBindTable->clearSelection(); |
|
305 |
selectedBindTable = theSender; |
|
306 |
} |
|
307 |
} |
|
308 |
||
14904
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
309 |
// check if the given key is bound multiple times |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
310 |
bool KeyBinder::checkConflictsWith(int compareTo, bool updateState) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
311 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
312 |
// TODO: Make conflict check more efficient |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
313 |
for(int i=0; i<BINDS_NUMBER; i++) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
314 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
315 |
if(i == compareTo) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
316 |
continue; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
317 |
if(CBBind[i] == NULL || CBBind[compareTo] == NULL) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
318 |
continue; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
319 |
QString bind1 = CBBind[i]->currentData(Qt::UserRole + 1).toString(); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
320 |
QString bind2 = CBBind[compareTo]->currentData(Qt::UserRole + 1).toString(); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
321 |
if(bind1 == "none" || bind2 == "none" || bind1 == "default" || bind2 == "default") |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
322 |
continue; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
323 |
// TODO: For team key binds, also check collisions with global key binds |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
324 |
if(bind1 == bind2) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
325 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
326 |
if(updateState) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
327 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
328 |
p_hasConflicts = true; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
329 |
conflictLabel->setHidden(false); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
330 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
331 |
return true; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
332 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
333 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
334 |
if(updateState) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
335 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
336 |
p_hasConflicts = false; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
337 |
conflictLabel->setHidden(true); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
338 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
339 |
return false; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
340 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
341 |
|
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
342 |
// check if any key is bound multiple times and causing a conflict |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
343 |
bool KeyBinder::checkConflicts() |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
344 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
345 |
bool conflict = false; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
346 |
for(int i=0; i<BINDS_NUMBER; i++) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
347 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
348 |
conflict = checkConflictsWith(i, false); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
349 |
if(conflict) |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
350 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
351 |
p_hasConflicts = true; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
352 |
conflictLabel->setHidden(false); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
353 |
return true; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
354 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
355 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
356 |
p_hasConflicts = false; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
357 |
conflictLabel->setHidden(true); |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
358 |
return false; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
359 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
360 |
|
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
361 |
bool KeyBinder::hasConflicts() |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
362 |
{ |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
363 |
return p_hasConflicts; |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
364 |
} |
4d5df8d35a95
Display a warning when the same key is used multiple times
Wuzzy <Wuzzy2@mail.ru>
parents:
14851
diff
changeset
|
365 |
|
8346 | 366 |
// Set a combobox's index |
367 |
void KeyBinder::setBindIndex(int keyIndex, int bindIndex) |
|
368 |
{ |
|
369 |
enableSignal = false; |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
370 |
if(CBBind[keyIndex] != NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
371 |
CBBind[keyIndex]->setCurrentIndex(bindIndex); |
8346 | 372 |
enableSignal = true; |
373 |
} |
|
374 |
||
375 |
// Return a combobox's selected index |
|
376 |
int KeyBinder::bindIndex(int keyIndex) |
|
377 |
{ |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
378 |
if(CBBind[keyIndex] != NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
379 |
return CBBind[keyIndex]->currentIndex(); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
380 |
else |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
381 |
return 0; |
8346 | 382 |
} |
383 |
||
384 |
// Clears selection and goes to first category |
|
385 |
void KeyBinder::resetInterface() |
|
386 |
{ |
|
387 |
enableSignal = false; |
|
8434 | 388 |
|
8346 | 389 |
catList->setCurrentItem(catList->item(1)); |
390 |
changeBindingsPage(1); |
|
391 |
if (selectedBindTable != NULL) |
|
392 |
{ |
|
393 |
selectedBindTable->clearSelection(); |
|
394 |
selectedBindTable = NULL; |
|
395 |
} |
|
8434 | 396 |
|
8346 | 397 |
// Default bind text |
398 |
DataManager::instance().bindsModel()->item(0)->setData(defaultText, Qt::DisplayRole); |
|
399 |
for (int i = 0; i < BINDS_NUMBER; i++) |
|
400 |
{ |
|
14851
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
401 |
if (CBBind[i] != NULL) |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
402 |
{ |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
403 |
CBBind[i]->setModel(DataManager::instance().bindsModel()); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
404 |
CBBind[i]->setCurrentIndex(0); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
405 |
bindComboBoxCellMappings->value(CBBind[i])->setText(defaultText); |
75b515a64202
Show key combinations in controls config menu (read-only)
Wuzzy <Wuzzy2@mail.ru>
parents:
14223
diff
changeset
|
406 |
} |
8346 | 407 |
} |
408 |
||
409 |
enableSignal = true; |
|
410 |
} |