Skip to content
JoystickButton.cc 1.63 KiB
Newer Older
#include "JoystickButton.h"
#include "ui_JoystickButton.h"

JoystickButton::JoystickButton(int id, QWidget *parent) :
    QWidget(parent),
    id(id),
    m_ui(new Ui::JoystickButton)
{
    m_ui->setupUi(this);
    m_ui->joystickButtonLabel->setText(QString::number(id));
    this->setActiveUAS(UASManager::instance()->getActiveUAS());
    connect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));

void JoystickButton::setActiveUAS(UASInterface* uas)
{
    // Disable signals so that changes to joystickAction don't trigger JoystickInput updates.
    blockSignals(true);
    if (uas)
    {
        m_ui->joystickAction->setEnabled(true);
        m_ui->joystickAction->clear();
        m_ui->joystickAction->addItem("--");
        QList<QAction*> actions = uas->getActions();
        foreach (QAction* a, actions)
        {
            m_ui->joystickAction->addItem(a->text());
        }
    } else {
        m_ui->joystickAction->setEnabled(false);
        m_ui->joystickAction->clear();
        m_ui->joystickAction->addItem("--");
    }
    blockSignals(false);
}

void JoystickButton::setAction(int index)
{
    // Disable signals so that changes to joystickAction don't trigger JoystickInput updates.
    //blockSignals(true);
    // Add one because the default no-action takes the 0-spot.
    m_ui->joystickAction->setCurrentIndex(index + 1);
    //blockSignals(false);
}

void JoystickButton::actionComboBoxChanged(int index)
{
    // Subtract one because the default no-action takes the 0-spot.
    emit actionChanged(id, index - 1);