-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
632 lines (545 loc) · 20.7 KB
/
Copy pathmainwindow.cpp
File metadata and controls
632 lines (545 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
#include "globalsettings.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtWidgets/QMessageBox>
#ifdef FFBC_PLATFORM_LINUX
#include "linuxdeviceprober.h"
#endif
#ifdef FFBC_HAVE_SDL2
#include "sdl2deviceprober.h"
#endif
const QString MainWindow::res_deviceErrorCap("Device error");
const QString MainWindow::res_effectNotLoaded("Not loaded");
const QString MainWindow::res_effectPlaying("Playing");
const QString MainWindow::res_effectUploaded("Uploaded");
const QString MainWindow::res_inputFormatErrCap("Invalid input format.");
MainWindow::MainWindow(const QString& title, QWidget* parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle(title);
m_constantEffSet = new ConstantEffectSettings();
m_periodicEffSet = new PeriodicEffectSettings();
m_conditionEffSet = new ConditionEffectSettings();
m_rampEffSet = new RampEffectSettings();
m_rumbleEffSet = new RumbleEffectSettings();
ui->qstw_effectSpecifics->addWidget(m_conditionEffSet);
ui->qstw_effectSpecifics->addWidget(m_constantEffSet);
ui->qstw_effectSpecifics->addWidget(m_periodicEffSet);
ui->qstw_effectSpecifics->addWidget(m_rampEffSet);
ui->qstw_effectSpecifics->addWidget(m_rumbleEffSet);
if (GlobalSettings::GS()->doSanityChecks)
ui->ql_noChecksWarning->setHidden(true);
/* Fill the list of available interfaces */
#ifdef FFBC_PLATFORM_LINUX
ui->cbox_interfaces->addItem("Linux API", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::LINUX));
#endif
#ifdef FFBC_HAVE_SDL2
if (SDL2DeviceProber::initializeSDL())
ui->cbox_interfaces->addItem("SDL2", static_cast<std::underlying_type<DeviceProber::DeviceInterfaces>::type>(DeviceProber::DeviceInterfaces::SDL2));
#endif
ui->cbox_interfaces->setCurrentIndex(0);
onInterfaceSelected(0);
fillDeviceList();
connect(ui->cbox_devices, SIGNAL(activated(const int)), this, SLOT(onDeviceSelected(const int)));
connect(ui->cbox_effectSlots, SIGNAL(activated(const int)), this, SLOT(onEffectSlotSelected(const int)));
connect(ui->cbox_effectTypes, SIGNAL(activated(const int)), this, SLOT(onEffectTypeSelected(const int)));
connect(ui->cbox_interfaces, SIGNAL(activated(int)), this, SLOT(onInterfaceSelected(const int)));
connect(ui->qpb_refreshDevices, SIGNAL(clicked()), this, SLOT(onRefreshDevicesClicked()));
connect(ui->qpb_remove, SIGNAL(clicked()), this, SLOT(onRemoveEffectClicked()));
connect(ui->qpb_setAC, SIGNAL(clicked()), this, SLOT(onSetACClicked()));
connect(ui->qpb_setGain, SIGNAL(clicked()), this, SLOT(onSetGainClicked()));
connect(ui->qpb_start, SIGNAL(clicked()), this, SLOT(onStartEffectClicked()));
connect(ui->qpb_stop, SIGNAL(clicked()), this, SLOT(onStopEffectClicked()));
connect(ui->qpb_upload, SIGNAL(clicked()), this, SLOT(onUploadEffectClicked()));
}
bool MainWindow::createDeviceProber(const DeviceProber::DeviceInterfaces iface)
{
std::shared_ptr<DeviceProber> prober;
if (m_prober != nullptr) {
if (m_prober->type == iface)
return false;
m_prober->closeAllDevices();
}
switch (iface) {
#ifdef FFBC_PLATFORM_LINUX
case DeviceProber::DeviceInterfaces::LINUX:
prober = std::make_shared<LinuxDeviceProber>();
break;
#endif
#ifdef FFBC_HAVE_SDL2
case DeviceProber::DeviceInterfaces::SDL2:
prober = std::make_shared<SDL2DeviceProber>();
break;
#endif
default:
QMessageBox::critical(this, "Cannot probe devices", "Selected interface is not supported yet.");
break;
}
m_prober = prober;
return true;
}
EffectSettings* MainWindow::effectSettingsByType(FFBEffectTypes type)
{
switch (type) {
case FFBEffectTypes::CONSTANT:
return m_constantEffSet;
case FFBEffectTypes::PERIODIC:
return m_periodicEffSet;
case FFBEffectTypes::CONDITION:
return m_conditionEffSet;
case FFBEffectTypes::RAMP:
return m_rampEffSet;
case FFBEffectTypes::RUMBLE:
return m_rumbleEffSet;
default:
abort();
}
}
QString MainWindow::effectTypeToEffectName(const FFBEffectTypes etype) const
{
switch (etype) {
case FFBEffectTypes::CONSTANT:
return "Constant force";
case FFBEffectTypes::PERIODIC:
return "Periodic force";
case FFBEffectTypes::RAMP:
return "Ramp";
case FFBEffectTypes::CONDITION:
return "Condition";
case FFBEffectTypes::RUMBLE:
return "Rumble";
default:
return "Unknown effect";
}
}
void MainWindow::fillDeviceList()
{
ui->cbox_devices->clear();
if (m_prober == nullptr)
return;
for (const DeviceProber::DeviceInfo& dinfo : m_prober->listDevices()) {
QString name;
if (dinfo.name.length() == 0)
name = "(no name)";
else
name = dinfo.name;
QString tag = QString("%1 [%2]").arg(name).arg(dinfo.id.toString());
ui->cbox_devices->addItem(tag, dinfo.id.toString());
}
}
void MainWindow::fillEffectSlotsList(const int effectCount)
{
ui->cbox_effectSlots->clear();
for (int i = 1; i <= effectCount; i++)
ui->cbox_effectSlots->addItem(QString::number(i), i-1);
}
void MainWindow::fillEffectTypesList(const std::vector<FFBEffectTypes>& list)
{
ui->cbox_effectTypes->clear();
for (const FFBEffectTypes etype : list)
ui->cbox_effectTypes->addItem(effectTypeToEffectName(etype), static_cast<std::underlying_type<FFBEffectTypes>::type>(etype));
}
void MainWindow::onDeviceSelected(const int cboxIdx)
{
Q_UNUSED(cboxIdx);
QString path = ui->cbox_devices->currentData(Qt::UserRole).toString();
ui->cbox_effectSlots->clear();
m_activeDevice = m_prober->openDevice(path);
if (m_activeDevice == nullptr)
return;
fillEffectSlotsList(m_activeDevice->maxEffectCount());
fillEffectTypesList(m_activeDevice->availableEffectsList());
m_conditionEffSet->fillAvailableSubtypesList(m_activeDevice->availableConditionSubtypesList());
m_periodicEffSet->fillAvailableWaveformsList(m_activeDevice->availableWaveformsList());
ui->cbox_effectSlots->setCurrentIndex(0);
onEffectSlotSelected(0);
}
void MainWindow::onEffectSlotSelected(const int cboxIdx)
{
int effectIdx;
bool ok;
Q_UNUSED(cboxIdx);
if (m_activeDevice == nullptr)
return;
effectIdx = ui->cbox_effectSlots->currentData(Qt::UserRole).toInt(&ok);
if (!ok) {
showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT);
return;
}
FFBEffectTypes etype = m_activeDevice->effectTypeByEffectIdx(effectIdx);
if (etype == FFBEffectTypes::NONE) {
setEffectTypeIndexByType(etype);
ui->qstw_effectSpecifics->setCurrentWidget(effectSettingsByType(FFBEffectTypes::CONSTANT));
setEffectStatusText(FFBEffect::FFBEffectStatus::NOT_LOADED);
return;
}
const std::shared_ptr<FFBEffectParameters> params = m_activeDevice->effectParameters(effectIdx);
/* Set global parameters */
ui->qle_direction->setText(QString::number(params->direction));
ui->qle_replayDelay->setText(QString::number(params->replayDelay));
ui->qle_replayLength->setText(QString::number(params->replayLength));
EffectSettings* efs = effectSettingsByType(etype);
if (!efs->fillFromParameters(params))
QMessageBox::warning(this, "UI error", "Unable to read effect parameters.");
setEffectTypeIndexByType(etype);
ui->qstw_effectSpecifics->setCurrentWidget(efs);
setEffectStatusText(m_activeDevice->effectStatusByIdx(effectIdx));
}
void MainWindow::onEffectTypeSelected(const int cboxIdx)
{
Q_UNUSED(cboxIdx);
if (m_activeDevice == nullptr)
return;
FFBEffectTypes etype = *static_cast<FFBEffectTypes*>(ui->cbox_effectTypes->currentData(Qt::UserRole).data());
ui->qstw_effectSpecifics->setCurrentWidget(effectSettingsByType(etype));
}
void MainWindow::onInterfaceSelected(const int cboxIdx)
{
Q_UNUSED(cboxIdx);
bool ok;
unsigned int rawIface;
DeviceProber::DeviceInterfaces iface;
rawIface = ui->cbox_interfaces->currentData().toUInt(&ok);
if (!ok) {
QMessageBox::critical(this, "Invalid data", "Invalid data passed as interface type.");
return;
}
iface = static_cast<DeviceProber::DeviceInterfaces>(rawIface);
if (!createDeviceProber(iface))
return;
ui->cbox_effectSlots->clear();
fillDeviceList();
}
void MainWindow::onRefreshDevicesClicked()
{
fillDeviceList();
}
void MainWindow::onRemoveEffectClicked()
{
int effectIdx;
bool ok;
if (m_activeDevice == nullptr)
return;
effectIdx = ui->cbox_effectSlots->currentData(Qt::UserRole).toInt(&ok);
if (!ok) {
showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT);
return;
}
if (!m_activeDevice->removeAndEraseEffect(effectIdx))
showErrorMsgBox(ErrorMessages::CANT_REMOVE_EFFECT);
else
setEffectStatusText(m_activeDevice->effectStatusByIdx(effectIdx));
}
void MainWindow::onSetACClicked()
{
bool ok;
int strength;
if (m_activeDevice == nullptr)
return;
strength = ui->qle_autocentering->text().toInt(&ok);
if (!ok) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid autocentering strength value");
return;
}
m_activeDevice->setAutocentering(strength);
}
void MainWindow::onSetGainClicked()
{
bool ok;
int gain;
if (m_activeDevice == nullptr)
return;
gain = ui->qle_gain->text().toInt(&ok);
if (!ok) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid gain value");
return;
}
m_activeDevice->setGain(gain);
}
void MainWindow::onStartEffectClicked()
{
bool ok;
int effectSlot;
if (m_activeDevice == nullptr)
return;
FFBEffectTypes etype = *static_cast<FFBEffectTypes*>(ui->cbox_effectTypes->currentData(Qt::UserRole).data());
std::shared_ptr<FFBEffectParameters> params;
effectSlot = ui->cbox_effectSlots->currentData().toInt(&ok);
if (!ok) {
showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT);
return;
}
if (!readEffectParameters(params, etype))
return;
bool ret = m_activeDevice->startEffect(effectSlot, etype, params);
if (ret)
setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot));
else
showErrorMsgBox(ErrorMessages::CANT_START_EFFECT);
}
void MainWindow::onStopEffectClicked()
{
int effectSlot;
bool ok;
if (m_activeDevice == nullptr)
return;
effectSlot = ui->cbox_effectSlots->currentData().toInt(&ok);
if (!ok) {
showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT);
return;
}
m_activeDevice->stopEffect(effectSlot);
setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot));
}
void MainWindow::onUploadEffectClicked()
{
bool ok;
int effectSlot;
if (m_activeDevice == nullptr)
return;
FFBEffectTypes etype = *static_cast<FFBEffectTypes*>(ui->cbox_effectTypes->currentData(Qt::UserRole).data());
std::shared_ptr<FFBEffectParameters> params;
effectSlot = ui->cbox_effectSlots->currentData().toInt(&ok);
if (!ok) {
showErrorMsgBox(ErrorMessages::BAD_EFFECT_SLOT);
return;
}
if (!readEffectParameters(params, etype))
return;
bool ret = m_activeDevice->uploadEffect(effectSlot, etype, params);
if (ret)
setEffectStatusText(m_activeDevice->effectStatusByIdx(effectSlot));
else
showErrorMsgBox(ErrorMessages::CANT_UPLOAD_EFFECT);
}
bool MainWindow::readEnvelopeParameters(std::shared_ptr<FFBEnvelopeParameters> params, const EnvelopeSettings* es)
{
if (!params->attackLengthFromString(es->attackLength())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Attack length\"");
return false;
}
if (!params->attackLevelFromString(es->attackLevel())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Attack level\"");
return false;
}
if (!params->fadeLengthFromString(es->fadeLength())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Fade length\"");
return false;
}
if (!params->fadeLevelFromString(es->fadeLevel())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Fade level\"");
return false;
}
return true;
}
bool MainWindow::readEffectParameters(std::shared_ptr<FFBEffectParameters>& params, FFBEffectTypes type)
{
switch (type) {
case FFBEffectTypes::CONSTANT:
{
std::shared_ptr<FFBConstantEffectParameters> iparams(new FFBConstantEffectParameters);
if (!readGeneralEffectParameters(iparams)) {
return false;
}
if (!readEnvelopeParameters(iparams, m_constantEffSet->envelopeSettings())) {
return false;
}
if (!iparams->levelFromString(m_constantEffSet->level())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"level\"");
return false;
}
params = iparams;
break;
}
case FFBEffectTypes::PERIODIC:
{
std::shared_ptr<FFBPeriodicEffectParameters> iparams(new FFBPeriodicEffectParameters);
if (!readGeneralEffectParameters(iparams)) {
return false;
}
if (!readEnvelopeParameters(iparams, m_periodicEffSet->envelopeSettings())) {
return false;
}
if (!iparams->magnitudeFromString(m_periodicEffSet->magnitude())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Magnitude\"");
return false ;
}
if (!iparams->offsetFromString(m_periodicEffSet->offset())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Offset\"");
return false;
}
if (!iparams->periodFromString(m_periodicEffSet->period())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Period\"");
return false;
}
if (!iparams->phaseFromString(m_periodicEffSet->phase())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Phase\"");
return false;
}
PeriodicWaveforms waveform = m_activeDevice->waveformByIdx(m_periodicEffSet->waveformIdx());
iparams->waveformFromIdx(waveform);
params = iparams;
break;
}
case FFBEffectTypes::CONDITION:
{
std::shared_ptr<FFBConditionEffectParameters> iParams = std::shared_ptr<FFBConditionEffectParameters>(new FFBConditionEffectParameters);
if (!readGeneralEffectParameters(iParams))
return false;
if (!iParams->centerFromString(m_conditionEffSet->centerX(), FFBConditionEffectParameters::Axis::X)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Center\"");
return false;
}
if (!iParams->centerFromString(m_conditionEffSet->centerY(), FFBConditionEffectParameters::Axis::Y)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Center\"");
return false;
}
if (!iParams->deadbandFromString(m_conditionEffSet->deadbandX(), FFBConditionEffectParameters::Axis::X)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Deadband\"");
return false;
}
if (!iParams->deadbandFromString(m_conditionEffSet->deadbandY(), FFBConditionEffectParameters::Axis::Y)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Deadband\"");
return false;
}
if (!iParams->leftCoeffFromString(m_conditionEffSet->leftCoeffX(), FFBConditionEffectParameters::Axis::X)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left coefficient\"");
return false;
}
if (!iParams->leftCoeffFromString(m_conditionEffSet->leftCoeffY(), FFBConditionEffectParameters::Axis::Y)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left coefficient\"");
return false;
}
if (!iParams->rightCoeffFromString(m_conditionEffSet->rightCoeffX(), FFBConditionEffectParameters::Axis::X)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right coefficient\"");
return false;
}
if (!iParams->rightCoeffFromString(m_conditionEffSet->rightCoeffY(), FFBConditionEffectParameters::Axis::Y)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right coefficient\"");
return false;
}
if (!iParams->leftSatFromString(m_conditionEffSet->leftSatX(), FFBConditionEffectParameters::Axis::X)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left saturation\"");
return false;
}
if (!iParams->leftSatFromString(m_conditionEffSet->leftSatY(), FFBConditionEffectParameters::Axis::Y)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Left saturation\"");
return false;
}
if (!iParams->rightSatFromString(m_conditionEffSet->rightSatX(), FFBConditionEffectParameters::Axis::X)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right saturation\"");
return false;
}
if (!iParams->rightSatFromString(m_conditionEffSet->rightSatY(), FFBConditionEffectParameters::Axis::Y)) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Right saturation\"");
return false;
}
ConditionSubtypes subtype = m_conditionEffSet->subtype();
iParams->subtype = subtype;
params = iParams;
break;
}
case FFBEffectTypes::RAMP: {
std::shared_ptr<FFBRampEffectParameters> iParams = std::shared_ptr<FFBRampEffectParameters>(new FFBRampEffectParameters);
if (!readGeneralEffectParameters(iParams))
return false;
if (!readEnvelopeParameters(iParams, m_rampEffSet->envelopeSettings()))
return false;
if (!iParams->endLevelFromString(m_rampEffSet->endLevel())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"End level\"");
return false;
}
if (!iParams->startLevelFromString(m_rampEffSet->startLevel())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Start level\"");
return false;
}
params = iParams;
break;
}
case FFBEffectTypes::RUMBLE: {
std::shared_ptr<FFBRumbleEffectParameters> iParams(new FFBRumbleEffectParameters());
if (!readGeneralEffectParameters(iParams))
return false;
if (!iParams->strongMagnitudeFromString(m_rumbleEffSet->strongMagnitude())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Strong magnitude\"");
return false;
}
if (!iParams->weakMagnitudeFromString(m_rumbleEffSet->weakMagnitude())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Weak magnitude\"");
return false;
}
params = iParams;
break;
}
default:
return false;
}
return true;
}
bool MainWindow::readGeneralEffectParameters(std::shared_ptr<FFBEffectParameters> params)
{
if (!params->directionFromString(ui->qle_direction->text())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"direction\"");
return false;
}
if (!params->repeatFromString(ui->qle_repeat->text())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Replay\"");
return false;
}
if (!params->replayDelayFromString(ui->qle_replayDelay->text())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Replay delay\"");
return false;
}
if (!params->replayLengthFromString(ui->qle_replayLength->text())) {
QMessageBox::warning(this, res_inputFormatErrCap, "Invalid data in field \"Replay length\"");
return false;
}
return true;
}
void MainWindow::setEffectStatusText(const FFBEffect::FFBEffectStatus status)
{
switch (status) {
case FFBEffect::FFBEffectStatus::NOT_LOADED:
ui->ql_effectStatus->setText(res_effectNotLoaded);
break;
case FFBEffect::FFBEffectStatus::PLAYING:
ui->ql_effectStatus->setText(res_effectPlaying);
break;
case FFBEffect::FFBEffectStatus::UPLOADED:
ui->ql_effectStatus->setText(res_effectUploaded);
break;
}
}
void MainWindow::setEffectTypeIndexByType(const FFBEffectTypes etype)
{
for (int idx = 0; idx < ui->cbox_effectTypes->count(); idx++) {
FFBEffectTypes ietype = *static_cast<FFBEffectTypes*>(ui->cbox_effectTypes->itemData(idx, Qt::UserRole).data());
if (ietype == etype) {
ui->cbox_effectTypes->setCurrentIndex(idx);
return;
}
}
}
void MainWindow::showErrorMsgBox(const ErrorMessages msgCode)
{
switch (msgCode) {
case ErrorMessages::BAD_EFFECT_SLOT:
QMessageBox::critical(this, "Runtime error", "Nonsensical data passed as effect slot index.");
break;
case ErrorMessages::CANT_REMOVE_EFFECT:
QMessageBox::warning(this, res_deviceErrorCap, "Unable to remove the effect.");
break;
case ErrorMessages::CANT_START_EFFECT:
QMessageBox::warning(this, res_deviceErrorCap, "Unable to start the effect.");
break;
case ErrorMessages::CANT_UPLOAD_EFFECT:
QMessageBox::warning(this, res_deviceErrorCap, "Unable to upload effect.");
break;
}
}
MainWindow::~MainWindow()
{
delete ui;
}