QGCToolWidgetItem.cc 1.68 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 24 25 26 27
    deleteAction = new QAction(tr("Delete %1").arg(qgcToolWidgetItemName), this);
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(deleteLater()));

    QGCToolWidget* tool = dynamic_cast<QGCToolWidget*>(parent);
    if (tool)
    {
        connect(this, SIGNAL(editingFinished()), tool, SLOT(storeWidgetsToSettings()));
    }
28

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

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

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

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