QGCToolWidgetItem.cc 1.67 KB
Newer Older
1 2 3 4 5
#include "QGCToolWidgetItem.h"

#include <QMenu>
#include <QContextMenuEvent>

lm's avatar
lm committed
6
#include "QGCToolWidget.h"
7 8 9
#include "UASManager.h"

QGCToolWidgetItem::QGCToolWidgetItem(const QString& name, QWidget *parent) :
10 11
    QWidget(parent),
    isInEditMode(false),
12 13
    qgcToolWidgetItemName(name),
    uas(NULL),
14 15
    _component(-1)
{
lm's avatar
lm committed
16
    startEditAction = new QAction(tr("Edit %1").arg(qgcToolWidgetItemName), this);
17
    connect(startEditAction, SIGNAL(triggered()), this, SLOT(startEditMode()));
lm's avatar
lm committed
18
    stopEditAction = new QAction(tr("Finish Editing %1").arg(qgcToolWidgetItemName), this);
19
    connect(stopEditAction, SIGNAL(triggered()), this, SLOT(endEditMode()));
lm's avatar
lm committed
20 21 22 23
    deleteAction = new QAction(tr("Delete %1").arg(qgcToolWidgetItemName), this);
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteLater()));

    QGCToolWidget* tool = dynamic_cast<QGCToolWidget*>(parent);
24
    if (tool) {
lm's avatar
lm committed
25 26
        connect(this, SIGNAL(editingFinished()), tool, SLOT(storeWidgetsToSettings()));
    }
27

28 29 30 31
    connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
            this, SLOT(setActiveUAS(UASInterface*)));
    // Set first UAS if it exists
    setActiveUAS(UASManager::instance()->getActiveUAS());
32 33 34 35 36 37
}

QGCToolWidgetItem::~QGCToolWidgetItem()
{
    delete startEditAction;
    delete stopEditAction;
lm's avatar
lm committed
38
    delete deleteAction;
39 40 41 42 43
}

void QGCToolWidgetItem::contextMenuEvent (QContextMenuEvent* event)
{
    QMenu menu(this);
44
    if (!isInEditMode) {
45
        menu.addAction(startEditAction);
lm's avatar
lm committed
46
        menu.addAction(deleteAction);
47
    } else {
48 49 50 51
        menu.addAction(stopEditAction);
    }
    menu.exec(event->globalPos());
}
52 53 54 55 56

void QGCToolWidgetItem::setActiveUAS(UASInterface *uas)
{
    this->uas = uas;
}