#include "controllersetup.h" #include "ui_controllersetup.h" #include "logcategories.h" controllerSetup::controllerSetup(QWidget* parent) : QDialog(parent), ui(new Ui::controllerSetup) { ui->setupUi(this); ui->tabWidget->clear(); ui->tabWidget->hide(); noControllersText = new QLabel("No USB controller found"); noControllersText->setStyleSheet("QLabel { color : gray; }"); ui->hboxLayout->addWidget(noControllersText); this->resize(this->sizeHint()); } controllerSetup::~controllerSetup() { if (onEventProxy != Q_NULLPTR) { delete onEventProxy; delete onEvent; } if (offEventProxy != Q_NULLPTR) { delete offEventProxy; delete offEvent; } if (knobEventProxy != Q_NULLPTR) { delete knobEventProxy; delete knobEvent; } delete ui; } void controllerSetup::mousePressed(controllerScene* scene, QPoint p) { // Receive mouse event from the scene qDebug() << "Looking for button Point x=" << p.x() << " y=" << p.y(); if (onEvent == Q_NULLPTR|| offEvent == Q_NULLPTR|| knobEvent == Q_NULLPTR) { qInfo(logUsbControl()) << "Event missing, cannot continue..."; return; } bool found = false; QMutexLocker locker(mutex); for (BUTTON& b : *buttons) { if (ui->tabWidget->currentWidget()->objectName() == b.devicePath && b.pos.contains(p)) { found = true; currentButton = &b; qDebug() << "Button" << currentButton->num << "On Event" << currentButton->onCommand->text << "Off Event" << currentButton->offCommand->text; onEvent->blockSignals(true); onEvent->move(p); onEvent->setCurrentIndex(onEvent->findData(currentButton->onCommand->index)); onEvent->show(); onEvent->blockSignals(false); p.setY(p.y() + 40); offEvent->blockSignals(true); offEvent->move(p); offEvent->setCurrentIndex(offEvent->findData(currentButton->offCommand->index)); offEvent->show(); offEvent->blockSignals(false); knobEvent->hide(); break; } } if (!found) { for (KNOB& k : *knobs) { if (ui->tabWidget->currentWidget()->objectName() == k.devicePath && k.pos.contains(p)) { found = true; currentKnob = &k; qDebug() << "Knob" << currentKnob->num << "Event" << currentKnob->command->text; knobEvent->blockSignals(true); knobEvent->move(p); knobEvent->setCurrentIndex(knobEvent->findData(currentKnob->command->index)); knobEvent->show(); knobEvent->blockSignals(false); onEvent->hide(); offEvent->hide(); break; } } } if(found) { found=false; foreach (QGraphicsItem *item, scene->items()) { QGraphicsProxyWidget *node = dynamic_cast(item); if (node) { found=true; break; } } if (!found) { scene->addItem(offEvent->graphicsProxyWidget()); scene->addItem(onEvent->graphicsProxyWidget()); scene->addItem(knobEvent->graphicsProxyWidget()); } } else { onEvent->hide(); offEvent->hide(); knobEvent->hide(); } } void controllerSetup::onEventIndexChanged(int index) { Q_UNUSED(index); // If command is changed, delete current command and deep copy the new command if (currentButton != Q_NULLPTR && onEvent->currentData().toInt() < commands->size()) { QMutexLocker locker(mutex); if (currentButton->onCommand) delete currentButton->onCommand; currentButton->onCommand = new COMMAND(commands->at(onEvent->currentData().toInt())); currentButton->onText->setPlainText(currentButton->onCommand->text); currentButton->onText->setPos(currentButton->pos.center().x() - currentButton->onText->boundingRect().width() / 2, (currentButton->pos.center().y() - currentButton->onText->boundingRect().height() / 2)-6); // Signal that any button programming on the device should be completed. emit programButton(currentButton->devicePath,currentButton->num, currentButton->onCommand->text); } } void controllerSetup::offEventIndexChanged(int index) { Q_UNUSED(index); // If command is changed, delete current command and deep copy the new command if (currentButton != Q_NULLPTR && offEvent->currentData().toInt() < commands->size()) { QMutexLocker locker(mutex); if (currentButton->offCommand) delete currentButton->offCommand; currentButton->offCommand = new COMMAND(commands->at(offEvent->currentData().toInt())); currentButton->offText->setPlainText(currentButton->offCommand->text); currentButton->offText->setPos(currentButton->pos.center().x() - currentButton->offText->boundingRect().width() / 2, (currentButton->pos.center().y() - currentButton->offText->boundingRect().height() / 2)+6); } } void controllerSetup::knobEventIndexChanged(int index) { Q_UNUSED(index); // If command is changed, delete current command and deep copy the new command if (currentKnob != Q_NULLPTR && knobEvent->currentData().toInt() < commands->size()) { QMutexLocker locker(mutex); if (currentKnob->command) delete currentKnob->command; currentKnob->command = new COMMAND(commands->at(knobEvent->currentData().toInt())); currentKnob->text->setPlainText(currentKnob->command->text); currentKnob->text->setPos(currentKnob->pos.center().x() - currentKnob->text->boundingRect().width() / 2, (currentKnob->pos.center().y() - currentKnob->text->boundingRect().height() / 2)); } } void controllerSetup::removeDevice(USBDEVICE* dev) { QMutexLocker locker(mutex); int remove = -1; for (int i = 0; i < ui->tabWidget->count(); i++) { auto widget = ui->tabWidget->widget(i); if (widget->objectName() == dev->path) { qDeleteAll(widget->findChildren("", Qt::FindDirectChildrenOnly)); remove = i; } } if (remove != -1) { qInfo(logUsbControl()) << "Removing tab" << dev->product; ui->tabWidget->removeTab(remove); } if (ui->tabWidget->count() == 0) { ui->tabWidget->hide(); noControllersText->show(); this->adjustSize(); } } void controllerSetup::newDevice(USBDEVICE* dev, CONTROLLER* cntrl, QVector