QGCTextLabel.cc 3.54 KB
Newer Older
1 2 3 4 5 6 7 8 9
#include <QDockWidget>

#include "QGCTextLabel.h"
#include "ui_QGCTextLabel.h"

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

QGCTextLabel::QGCTextLabel(QWidget *parent) :
10
    QGCToolWidgetItem("Text Label", parent),
11 12 13 14 15 16 17
    ui(new Ui::QGCTextLabel)
{
    uas = 0;
    enabledNum = -1;
    ui->setupUi(this);

    connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
18
    connect(ui->isMavCommand, SIGNAL(toggled(bool)), this, SLOT(update_isMavCommand()));
19 20 21 22 23

    // Hide all edit items
    ui->editFinishButton->hide();
    ui->editNameLabel->hide();
    ui->editLine1->hide();
24 25 26
    ui->editLine2->hide();
    ui->isMavCommand->hide();
    ui->textLabel->setText(QString());
27 28 29 30 31 32 33
}

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

34
void QGCTextLabel::setEditMode(bool editMode)
35
{
36 37 38 39 40 41 42 43 44
    if(!editMode)
        update_isMavCommand();
    ui->editFinishButton->setVisible(editMode);
    ui->editNameLabel->setVisible(editMode);
    ui->editLine1->setVisible(editMode);
    ui->editLine2->setVisible(editMode);
    ui->isMavCommand->setVisible(editMode);

    QGCToolWidgetItem::setEditMode(editMode);
45 46 47 48
}

void QGCTextLabel::writeSettings(QSettings& settings)
{
49 50 51
    settings.setValue("TYPE", "TEXT");
    settings.setValue("QGC_TEXT_TEXT", ui->editNameLabel->text());
    settings.setValue("QGC_TEXT_SOURCE", ui->isMavCommand->isChecked()?"MAV":"NONE");
52 53 54 55 56

    settings.sync();
}
void QGCTextLabel::readSettings(const QString& pre,const QVariantMap& settings)
{
57
    ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString());
58
    ui->isMavCommand->setChecked(settings.value(pre + "QGC_TEXT_SOURCE", "NONE").toString() == "MAV");
59
    update_isMavCommand();
60 61 62
}
void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, QString message)
{
63 64 65
    Q_UNUSED(uasid);
    Q_UNUSED(component);
    Q_UNUSED(severity);
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    if (enabledNum != -1)
    {
        //SUCCESS: Executed CMD: 241
        if (message.contains("SUCCESS"))
        {
            if (message.trimmed().endsWith(QString::number(enabledNum)))
            {
                enabledNum = -1;
                ui->textLabel->setText(ui->textLabel->text() + " Complete");
            }
        }
        else
        {
            ui->textLabel->setText(message);
        }
    }
}

void QGCTextLabel::readSettings(const QSettings& settings)
{
86
    ui->editNameLabel->setText(settings.value("QGC_TEXT_TEXT","").toString()); //Place this before setting isMavCommand
87
    ui->isMavCommand->setChecked(settings.value("QGC_TEXT_SOURCE", "NONE").toString() == "MAV");
88
    update_isMavCommand();
89
}
90

91 92 93 94 95 96 97
void QGCTextLabel::enableText(int num)
{
    enabledNum = num;
}

void QGCTextLabel::setActiveUAS(UASInterface *uas)
{
98 99
    if(this->uas)
        this->uas->disconnect(this);
100
    this->uas = uas;
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    update_isMavCommand(); //Might need to update the signal connections
}

void QGCTextLabel::update_isMavCommand()
{
    ui->textLabel->setText("");
    if (!ui->isMavCommand->isChecked())
    {
        ui->nameLabel->setText(ui->editNameLabel->text());
        if(this->uas)
            disconnect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString)));
        if(ui->nameLabel->text().isEmpty())
            ui->nameLabel->setText(tr("Text Label")); //Show something, so that we don't end up with just an empty label
    }
    else
    {
        //MAV command text
        ui->nameLabel->setText(ui->editNameLabel->text());
        if(this->uas)
        connect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString)));
    }
122
}