QGCCommandButton.cc 5.69 KB
Newer Older
lm's avatar
lm committed
1 2 3 4 5 6 7
#include "QGCCommandButton.h"
#include "ui_QGCCommandButton.h"

#include "MAVLinkProtocol.h"
#include "UASManager.h"

QGCCommandButton::QGCCommandButton(QWidget *parent) :
8
    QGCToolWidgetItem("Command Button", parent),
lm's avatar
lm committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
    ui(new Ui::QGCCommandButton),
    uas(NULL)
{
    ui->setupUi(this);

    connect(ui->commandButton, SIGNAL(clicked()), this, SLOT(sendCommand()));
    connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
    connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setCommandButtonName(QString)));
    connect(ui->editCommandComboBox, SIGNAL(currentIndexChanged(QString)), ui->nameLabel, SLOT(setText(QString)));

    // Hide all edit items
    ui->editCommandComboBox->hide();
    ui->editFinishButton->hide();
    ui->editNameLabel->hide();
    ui->editButtonName->hide();
24 25 26 27 28 29 30
    ui->editConfirmationCheckBox->hide();
    ui->editComponentSpinBox->hide();
    ui->editParamsVisibleCheckBox->hide();
    ui->editParam1SpinBox->hide();
    ui->editParam2SpinBox->hide();
    ui->editParam3SpinBox->hide();
    ui->editParam4SpinBox->hide();
31 32 33 34 35
    ui->editLine1->hide();
    ui->editLine2->hide();

    ui->editLine1->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
    ui->editLine2->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
lm's avatar
lm committed
36 37 38 39 40 41 42 43 44 45 46 47 48

    // Add commands to combo box
    ui->editCommandComboBox->addItem("DO: Control Video", MAV_CMD_DO_CONTROL_VIDEO);
    ui->editCommandComboBox->addItem("PREFLIGHT: Calibration", MAV_CMD_PREFLIGHT_CALIBRATION);
}

QGCCommandButton::~QGCCommandButton()
{
    delete ui;
}

void QGCCommandButton::sendCommand()
{
49
    if (QGCToolWidgetItem::uas) {
lm's avatar
lm committed
50
        // FIXME
51
        int index = ui->editCommandComboBox->itemData(ui->editCommandComboBox->currentIndex()).toInt();
lm's avatar
lm committed
52
        MAV_CMD command = static_cast<MAV_CMD>(index);
53 54 55 56 57 58 59 60
        int confirm = (ui->editConfirmationCheckBox->isChecked()) ? 1 : 0;
        float param1 = ui->editParam1SpinBox->value();
        float param2 = ui->editParam2SpinBox->value();
        float param3 = ui->editParam3SpinBox->value();
        float param4 = ui->editParam4SpinBox->value();
        int component = ui->editComponentSpinBox->value();

        QGCToolWidgetItem::uas->executeCommand(command, confirm, param1, param2, param3, param4, component);
61
    } else {
lm's avatar
lm committed
62 63 64 65 66 67 68 69 70 71 72
        qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING";
    }
}

void QGCCommandButton::setCommandButtonName(QString text)
{
    ui->commandButton->setText(text);
}

void QGCCommandButton::startEditMode()
{
73 74 75 76
    // Hide elements
    ui->commandButton->hide();
    ui->nameLabel->hide();

lm's avatar
lm committed
77 78 79 80
    ui->editCommandComboBox->show();
    ui->editFinishButton->show();
    ui->editNameLabel->show();
    ui->editButtonName->show();
81 82 83 84 85 86 87
    ui->editConfirmationCheckBox->show();
    ui->editComponentSpinBox->show();
    ui->editParamsVisibleCheckBox->show();
    ui->editParam1SpinBox->show();
    ui->editParam2SpinBox->show();
    ui->editParam3SpinBox->show();
    ui->editParam4SpinBox->show();
88 89
    ui->editLine1->show();
    ui->editLine2->show();
90
    //setStyleSheet("QGroupBox { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
lm's avatar
lm committed
91 92 93 94 95 96 97 98 99
    isInEditMode = true;
}

void QGCCommandButton::endEditMode()
{
    ui->editCommandComboBox->hide();
    ui->editFinishButton->hide();
    ui->editNameLabel->hide();
    ui->editButtonName->hide();
100 101 102
    ui->editConfirmationCheckBox->hide();
    ui->editComponentSpinBox->hide();
    ui->editParamsVisibleCheckBox->hide();
103 104
    ui->editLine1->hide();
    ui->editLine2->hide();
105
    if (!ui->editParamsVisibleCheckBox->isChecked()) {
106 107 108 109 110
        ui->editParam1SpinBox->hide();
        ui->editParam2SpinBox->hide();
        ui->editParam3SpinBox->hide();
        ui->editParam4SpinBox->hide();
    }
lm's avatar
lm committed
111

112 113 114
    ui->commandButton->show();
    ui->nameLabel->show();

lm's avatar
lm committed
115 116
    // Write to settings
    emit editingFinished();
117
    //setStyleSheet("");
lm's avatar
lm committed
118 119 120 121 122 123 124 125 126
    isInEditMode = false;
}

void QGCCommandButton::writeSettings(QSettings& settings)
{
    settings.setValue("TYPE", "COMMANDBUTTON");
    settings.setValue("QGC_ACTION_BUTTON_DESCRIPTION", ui->nameLabel->text());
    settings.setValue("QGC_ACTION_BUTTON_BUTTONTEXT", ui->commandButton->text());
    settings.setValue("QGC_ACTION_BUTTON_ACTIONID", ui->editCommandComboBox->currentIndex());
127
    settings.setValue("QGC_COMMAND_BUTTON_PARAMS_VISIBLE", ui->editParamsVisibleCheckBox->isChecked());
lm's avatar
lm committed
128 129 130 131 132 133 134 135 136 137 138 139
    settings.sync();
}

void QGCCommandButton::readSettings(const QSettings& settings)
{
    ui->editNameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString());
    ui->editButtonName->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
    ui->editCommandComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt());

    ui->nameLabel->setText(settings.value("QGC_ACTION_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString());
    ui->commandButton->setText(settings.value("QGC_ACTION_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
    ui->editCommandComboBox->setCurrentIndex(settings.value("QGC_ACTION_BUTTON_ACTIONID", 0).toInt());
140
    ui->editParamsVisibleCheckBox->setChecked(settings.value("QGC_COMMAND_BUTTON_PARAMS_VISIBLE").toBool());
141
    if (ui->editParamsVisibleCheckBox->isChecked()) {
142 143 144 145
        ui->editParam1SpinBox->show();
        ui->editParam2SpinBox->show();
        ui->editParam3SpinBox->show();
        ui->editParam4SpinBox->show();
146
    } else {
147 148 149 150 151
        ui->editParam1SpinBox->hide();
        ui->editParam2SpinBox->hide();
        ui->editParam3SpinBox->hide();
        ui->editParam4SpinBox->hide();
    }
lm's avatar
lm committed
152 153
    qDebug() << "DONE READING SETTINGS";
}