JoystickButton.cc 2.06 KB
Newer Older
1 2
#include "JoystickButton.h"
#include "ui_JoystickButton.h"
3
#include "UASManager.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->setActiveUAS(UASManager::instance()->getActiveUAS());
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 22

void JoystickButton::setActiveUAS(UASInterface* uas)
{
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 26 27 28 29 30 31 32 33 34
    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());
        }
35
        m_ui->joystickAction->setCurrentIndex(0);
36 37 38 39
    } else {
        m_ui->joystickAction->setEnabled(false);
        m_ui->joystickAction->clear();
        m_ui->joystickAction->addItem("--");
40
        m_ui->joystickAction->setCurrentIndex(0);
41
    }
42
    connect(m_ui->joystickAction, SIGNAL(currentIndexChanged(int)), this, SLOT(actionComboBoxChanged(int)));
43 44 45 46 47
}

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

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