JoystickButton.cc 2.14 KB
Newer Older
1 2
#include "JoystickButton.h"
#include "ui_JoystickButton.h"
3
#include "MultiVehicleManager.h"
4 5 6 7 8 9 10 11

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));
12
    this->activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());
13
    connect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
14 15 16 17 18 19
}

JoystickButton::~JoystickButton()
{
    delete m_ui;
}
20

21
void JoystickButton::activeVehicleChanged(Vehicle* vehicle)
22
{
23
    // Disable signals so that changes to joystickAction don't trigger JoystickInput updates.
24
    disconnect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
25
    if (vehicle)
26
    {
27 28
        UAS* uas = vehicle->uas();
        
29 30 31 32 33 34 35 36
        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());
        }
37
        m_ui->joystickAction->setCurrentIndex(0);
38 39 40 41
    } else {
        m_ui->joystickAction->setEnabled(false);
        m_ui->joystickAction->clear();
        m_ui->joystickAction->addItem("--");
42
        m_ui->joystickAction->setCurrentIndex(0);
43
    }
44
    connect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
45 46 47 48 49
}

void JoystickButton::setAction(int index)
{
    // Disable signals so that changes to joystickAction don't trigger JoystickInput updates.
50
    disconnect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
51 52
    // Add one because the default no-action takes the 0-spot.
    m_ui->joystickAction->setCurrentIndex(index + 1);
53
    connect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
54 55 56 57
}

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