kopia lustrzana https://gitlab.com/eliggett/wfview
Various (I hope) improvements!
rodzic
1f1800f046
commit
cad3bb9418
|
@ -13,27 +13,59 @@ controllerSetup::controllerSetup(QWidget* parent) :
|
|||
textItem = scene->addText("No USB controller found");
|
||||
textItem->setDefaultTextColor(Qt::gray);
|
||||
this->resize(this->sizeHint());
|
||||
|
||||
connect(&onEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(onEventIndexChanged(int)));
|
||||
connect(&offEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(offEventIndexChanged(int)));
|
||||
connect(&knobEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(knobEventIndexChanged(int)));
|
||||
}
|
||||
|
||||
controllerSetup::~controllerSetup()
|
||||
{
|
||||
// Remove any existing button text:
|
||||
for (QGraphicsItem* item : scene->items())
|
||||
{
|
||||
QGraphicsTextItem* txt = qgraphicsitem_cast<QGraphicsTextItem*>(item);
|
||||
if (!txt || txt == textItem)
|
||||
continue;
|
||||
scene->removeItem(txt);
|
||||
delete txt;
|
||||
}
|
||||
|
||||
if (bgImage != Q_NULLPTR) {
|
||||
scene->removeItem(bgImage);
|
||||
delete bgImage;
|
||||
bgImage = Q_NULLPTR;
|
||||
}
|
||||
if (onEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(onEventProxy);
|
||||
onEventProxy = Q_NULLPTR;
|
||||
delete onEvent;
|
||||
onEvent = Q_NULLPTR;
|
||||
}
|
||||
if (offEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(offEventProxy);
|
||||
offEventProxy = Q_NULLPTR;
|
||||
delete offEvent;
|
||||
offEvent = Q_NULLPTR;
|
||||
}
|
||||
if (knobEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(knobEventProxy);
|
||||
knobEventProxy = Q_NULLPTR;
|
||||
delete knobEvent;
|
||||
knobEvent = Q_NULLPTR;
|
||||
}
|
||||
|
||||
delete textItem;
|
||||
delete scene;
|
||||
delete ui;
|
||||
|
||||
if (bgImage != Q_NULLPTR) {
|
||||
delete bgImage;
|
||||
}
|
||||
}
|
||||
|
||||
void controllerSetup::mousePressed(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;
|
||||
for (BUTTON& b : *buttons)
|
||||
{
|
||||
|
@ -42,29 +74,23 @@ void controllerSetup::mousePressed(QPoint p)
|
|||
found = true;
|
||||
currentButton = &b;
|
||||
qDebug() << "Button" << currentButton->num << "On Event" << currentButton->onCommand->text << "Off Event" << currentButton->offCommand->text;
|
||||
// Add off event first so it doesn't obscure on event.
|
||||
if (offEventProxy == Q_NULLPTR) {
|
||||
offEventProxy = scene->addWidget(&offEvent);
|
||||
}
|
||||
if (onEventProxy == Q_NULLPTR) {
|
||||
onEventProxy = scene->addWidget(&onEvent);
|
||||
}
|
||||
onEvent.blockSignals(true);
|
||||
onEvent.move(p);
|
||||
onEvent.setCurrentIndex(onEvent.findData(currentButton->onCommand->index));
|
||||
onEvent.show();
|
||||
onEvent.blockSignals(false);
|
||||
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();
|
||||
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)
|
||||
{
|
||||
|
@ -73,32 +99,29 @@ void controllerSetup::mousePressed(QPoint p)
|
|||
found = true;
|
||||
currentKnob = &k;
|
||||
qDebug() << "Knob" << currentKnob->num << "Event" << currentKnob->command->text;
|
||||
if (knobEventProxy == Q_NULLPTR) {
|
||||
knobEventProxy = scene->addWidget(&knobEvent);
|
||||
}
|
||||
knobEvent.blockSignals(true);
|
||||
knobEvent.move(p);
|
||||
knobEvent.setCurrentIndex(knobEvent.findData(currentKnob->command->index));
|
||||
knobEvent.show();
|
||||
knobEvent.blockSignals(false);
|
||||
onEvent.hide();
|
||||
offEvent.hide();
|
||||
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) {
|
||||
onEvent.hide();
|
||||
offEvent.hide();
|
||||
knobEvent.hide();
|
||||
onEvent->hide();
|
||||
offEvent->hide();
|
||||
knobEvent->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void controllerSetup::onEventIndexChanged(int index) {
|
||||
Q_UNUSED(index);
|
||||
if (currentButton != Q_NULLPTR && onEvent.currentData().toInt() < commands->size()) {
|
||||
currentButton->onCommand = &commands->at(onEvent.currentData().toInt());
|
||||
if (currentButton != Q_NULLPTR && onEvent->currentData().toInt() < commands->size()) {
|
||||
currentButton->onCommand = &commands->at(onEvent->currentData().toInt());
|
||||
currentButton->onText->setPlainText(currentButton->onCommand->text);
|
||||
}
|
||||
}
|
||||
|
@ -106,16 +129,16 @@ void controllerSetup::onEventIndexChanged(int index) {
|
|||
|
||||
void controllerSetup::offEventIndexChanged(int index) {
|
||||
Q_UNUSED(index);
|
||||
if (currentButton != Q_NULLPTR && offEvent.currentData().toInt() < commands->size()) {
|
||||
currentButton->offCommand = &commands->at(offEvent.currentData().toInt());
|
||||
if (currentButton != Q_NULLPTR && offEvent->currentData().toInt() < commands->size()) {
|
||||
currentButton->offCommand = &commands->at(offEvent->currentData().toInt());
|
||||
currentButton->offText->setPlainText(currentButton->offCommand->text);
|
||||
}
|
||||
}
|
||||
|
||||
void controllerSetup::knobEventIndexChanged(int index) {
|
||||
Q_UNUSED(index);
|
||||
if (currentKnob != Q_NULLPTR && knobEvent.currentData().toInt() < commands->size()) {
|
||||
currentKnob->command = &commands->at(knobEvent.currentData().toInt());
|
||||
if (currentKnob != Q_NULLPTR && knobEvent->currentData().toInt() < commands->size()) {
|
||||
currentKnob->command = &commands->at(knobEvent->currentData().toInt());
|
||||
currentKnob->text->setPlainText(currentKnob->command->text);
|
||||
}
|
||||
}
|
||||
|
@ -134,25 +157,33 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
|
|||
if (!txt || txt==textItem)
|
||||
continue;
|
||||
scene->removeItem(txt);
|
||||
delete txt;
|
||||
}
|
||||
|
||||
if (bgImage != Q_NULLPTR) {
|
||||
scene->removeItem(bgImage);
|
||||
delete bgImage;
|
||||
bgImage = Q_NULLPTR;
|
||||
if (onEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(onEventProxy);
|
||||
onEventProxy = Q_NULLPTR;
|
||||
}
|
||||
if (offEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(offEventProxy);
|
||||
offEventProxy = Q_NULLPTR;
|
||||
}
|
||||
if (knobEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(knobEventProxy);
|
||||
knobEventProxy = Q_NULLPTR;
|
||||
}
|
||||
}
|
||||
if (onEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(onEventProxy);
|
||||
onEventProxy = Q_NULLPTR;
|
||||
delete onEvent;
|
||||
onEvent = Q_NULLPTR;
|
||||
}
|
||||
if (offEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(offEventProxy);
|
||||
offEventProxy = Q_NULLPTR;
|
||||
delete offEvent;
|
||||
offEvent = Q_NULLPTR;
|
||||
}
|
||||
if (knobEventProxy != Q_NULLPTR) {
|
||||
scene->removeItem(knobEventProxy);
|
||||
knobEventProxy = Q_NULLPTR;
|
||||
delete knobEvent;
|
||||
knobEvent = Q_NULLPTR;
|
||||
}
|
||||
|
||||
QImage image;
|
||||
|
||||
switch (devType) {
|
||||
|
@ -181,8 +212,9 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
|
|||
ui->graphicsView->setSceneRect(scene->itemsBoundingRect());
|
||||
this->adjustSize();
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
textItem->hide();
|
||||
bgImage = new QGraphicsPixmapItem(QPixmap::fromImage(image));
|
||||
scene->addItem(bgImage);
|
||||
|
@ -190,37 +222,48 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
|
|||
ui->graphicsView->setMinimumSize(bgImage->boundingRect().width() + 100, bgImage->boundingRect().height() + 2);
|
||||
currentDevice = devType;
|
||||
|
||||
onEvent.blockSignals(true);
|
||||
offEvent.blockSignals(true);
|
||||
knobEvent.blockSignals(true);
|
||||
onEvent.clear();
|
||||
offEvent.clear();
|
||||
knobEvent.clear();
|
||||
offEvent = new QComboBox;
|
||||
onEvent = new QComboBox;
|
||||
knobEvent = new QComboBox;
|
||||
|
||||
onEvent.setMaxVisibleItems(5);
|
||||
offEvent.setMaxVisibleItems(5);
|
||||
knobEvent.setMaxVisibleItems(5);
|
||||
onEvent.view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
offEvent.view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
knobEvent.view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
onEvent.setStyleSheet("combobox-popup: 0;");
|
||||
offEvent.setStyleSheet("combobox-popup: 0;");
|
||||
knobEvent.setStyleSheet("combobox-popup: 0;");
|
||||
onEvent->blockSignals(true);
|
||||
offEvent->blockSignals(true);
|
||||
knobEvent->blockSignals(true);
|
||||
|
||||
for (COMMAND &c : *commands) {
|
||||
onEvent->clear();
|
||||
offEvent->clear();
|
||||
knobEvent->clear();
|
||||
|
||||
onEvent->setMaxVisibleItems(5);
|
||||
offEvent->setMaxVisibleItems(5);
|
||||
knobEvent->setMaxVisibleItems(5);
|
||||
|
||||
onEvent->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
offEvent->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
knobEvent->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
|
||||
onEvent->setStyleSheet("combobox-popup: 0;");
|
||||
offEvent->setStyleSheet("combobox-popup: 0;");
|
||||
knobEvent->setStyleSheet("combobox-popup: 0;");
|
||||
|
||||
for (COMMAND& c : *commands) {
|
||||
if (c.cmdType == commandButton || c.text == "None") {
|
||||
onEvent.addItem(c.text,c.index);
|
||||
offEvent.addItem(c.text,c.index);
|
||||
onEvent->addItem(c.text, c.index);
|
||||
offEvent->addItem(c.text, c.index);
|
||||
}
|
||||
|
||||
if (c.cmdType == commandKnob || c.text == "None") {
|
||||
knobEvent.addItem(c.text,c.index);
|
||||
knobEvent->addItem(c.text, c.index);
|
||||
}
|
||||
}
|
||||
|
||||
onEvent.blockSignals(false);
|
||||
offEvent.blockSignals(false);
|
||||
knobEvent.blockSignals(false);
|
||||
onEvent->blockSignals(false);
|
||||
offEvent->blockSignals(false);
|
||||
knobEvent->blockSignals(false);
|
||||
|
||||
onEvent->hide();
|
||||
offEvent->hide();
|
||||
knobEvent->hide();
|
||||
|
||||
// Set button text
|
||||
for (BUTTON& b : *buttons)
|
||||
|
@ -230,12 +273,12 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
|
|||
b.onText = new QGraphicsTextItem(b.onCommand->text);
|
||||
b.onText->setDefaultTextColor(b.textColour);
|
||||
scene->addItem(b.onText);
|
||||
b.onText->setPos(b.pos.x(), b.pos.y());
|
||||
b.onText->setPos(b.pos.center().x() - b.onText->boundingRect().width() / 2, b.pos.y());
|
||||
|
||||
b.offText = new QGraphicsTextItem(b.offCommand->text);
|
||||
b.offText->setDefaultTextColor(b.textColour);
|
||||
scene->addItem(b.offText);
|
||||
b.offText->setPos(b.pos.x(), b.pos.y() + 10);
|
||||
b.offText->setPos(b.pos.center().x() - b.offText->boundingRect().width() / 2, b.pos.y() + 15);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,14 +290,22 @@ void controllerSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVe
|
|||
k.text = new QGraphicsTextItem(k.command->text);
|
||||
k.text->setDefaultTextColor(k.textColour);
|
||||
scene->addItem(k.text);
|
||||
k.text->setPos(k.pos.x(), k.pos.y());
|
||||
k.text->setPos(k.pos.center().x() - k.text->boundingRect().width() / 2, k.pos.y());
|
||||
}
|
||||
}
|
||||
|
||||
ui->graphicsView->setSceneRect(scene->itemsBoundingRect());
|
||||
ui->graphicsView->resize(ui->graphicsView->sizeHint());
|
||||
//this->resize(this->sizeHint());
|
||||
this->adjustSize();
|
||||
|
||||
// Add comboboxes to scene after everything else.
|
||||
offEventProxy = scene->addWidget(offEvent);
|
||||
connect(offEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(offEventIndexChanged(int)));
|
||||
onEventProxy = scene->addWidget(onEvent);
|
||||
connect(onEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(onEventIndexChanged(int)));
|
||||
knobEventProxy = scene->addWidget(knobEvent);
|
||||
connect(knobEvent, SIGNAL(currentIndexChanged(int)), this, SLOT(knobEventIndexChanged(int)));
|
||||
|
||||
}
|
||||
|
||||
void controllerSetup::receiveSensitivity(int val)
|
||||
|
|
|
@ -60,9 +60,9 @@ private:
|
|||
QVector<COMMAND>* commands;
|
||||
BUTTON* currentButton = Q_NULLPTR;
|
||||
KNOB* currentKnob = Q_NULLPTR;
|
||||
QComboBox onEvent;
|
||||
QComboBox offEvent;
|
||||
QComboBox knobEvent;
|
||||
QComboBox* onEvent = Q_NULLPTR;
|
||||
QComboBox* offEvent = Q_NULLPTR;
|
||||
QComboBox* knobEvent = Q_NULLPTR;
|
||||
QGraphicsProxyWidget* onEventProxy = Q_NULLPTR;
|
||||
QGraphicsProxyWidget* offEventProxy = Q_NULLPTR;
|
||||
QGraphicsProxyWidget* knobEventProxy = Q_NULLPTR;
|
||||
|
|
15
wfmain.cpp
15
wfmain.cpp
|
@ -9337,9 +9337,9 @@ void wfmain::resetUsbKnobs()
|
|||
#ifdef USB_CONTROLLER
|
||||
usbKnobs.clear();
|
||||
// eCoder
|
||||
usbKnobs.append(KNOB(eCoderPlus, 1, QRect(120, 153, 72, 27), Qt::red, &usbCommands[0]));
|
||||
usbKnobs.append(KNOB(eCoderPlus, 2, QRect(242, 153, 72, 27), Qt::red, &usbCommands[0]));
|
||||
usbKnobs.append(KNOB(eCoderPlus, 3, QRect(362, 153, 72, 27), Qt::red, &usbCommands[0]));
|
||||
usbKnobs.append(KNOB(eCoderPlus, 1, QRect(120, 153, 72, 27), Qt::green, &usbCommands[0]));
|
||||
usbKnobs.append(KNOB(eCoderPlus, 2, QRect(242, 153, 72, 27), Qt::green, &usbCommands[0]));
|
||||
usbKnobs.append(KNOB(eCoderPlus, 3, QRect(362, 153, 72, 27), Qt::green, &usbCommands[0]));
|
||||
emit sendUsbControllerKnobs(&usbKnobs);
|
||||
|
||||
#endif
|
||||
|
@ -9406,6 +9406,15 @@ void wfmain::resetUsbCommands()
|
|||
usbCommands.append(COMMAND(num++, "Swap VFOs", commandButton, cmdVFOSwap, 0x0));
|
||||
usbCommands.append(COMMAND(num++, "AF Gain", commandKnob, cmdSetAfGain, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "RF Gain", commandKnob, cmdSetRxRfGain, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "TX Power", commandKnob, cmdSetTxPower, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "Mic Gain", commandKnob, cmdSetMicGain, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "Mod Level", commandKnob, cmdSetModLevel, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "Squelch", commandKnob, cmdSetSql, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "IF Shift", commandKnob, cmdSetIFShift, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "Inner PBT", commandKnob, cmdSetTPBFInner, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "Outer PBT", commandKnob, cmdSetTPBFOuter, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "CW Pitch", commandKnob, cmdSetCwPitch, 0xff));
|
||||
usbCommands.append(COMMAND(num++, "CW Speed", commandKnob, cmdSetKeySpeed, 0xff));
|
||||
emit sendUsbControllerCommands(&usbCommands);
|
||||
#endif
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue