17 changed files with 618 additions and 26 deletions
@ -0,0 +1,32 @@ |
|||||||
|
#include "QGCActionButton.h" |
||||||
|
#include "ui_QGCActionButton.h" |
||||||
|
|
||||||
|
QGCActionButton::QGCActionButton(QWidget *parent) : |
||||||
|
QGCToolWidgetItem(parent), |
||||||
|
ui(new Ui::QGCActionButton) |
||||||
|
{ |
||||||
|
ui->setupUi(this); |
||||||
|
connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); |
||||||
|
endEditMode(); |
||||||
|
} |
||||||
|
|
||||||
|
QGCActionButton::~QGCActionButton() |
||||||
|
{ |
||||||
|
delete ui; |
||||||
|
} |
||||||
|
|
||||||
|
void QGCActionButton::startEditMode() |
||||||
|
{ |
||||||
|
ui->editActionComboBox->show(); |
||||||
|
ui->editActionsRefreshButton->show(); |
||||||
|
ui->editFinishButton->show(); |
||||||
|
isInEditMode = true; |
||||||
|
} |
||||||
|
|
||||||
|
void QGCActionButton::endEditMode() |
||||||
|
{ |
||||||
|
ui->editActionComboBox->hide(); |
||||||
|
ui->editActionsRefreshButton->hide(); |
||||||
|
ui->editFinishButton->hide(); |
||||||
|
isInEditMode = false; |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
#ifndef QGCACTIONBUTTON_H |
||||||
|
#define QGCACTIONBUTTON_H |
||||||
|
|
||||||
|
#include "QGCToolWidgetItem.h" |
||||||
|
|
||||||
|
namespace Ui { |
||||||
|
class QGCActionButton; |
||||||
|
} |
||||||
|
|
||||||
|
class QGCActionButton : public QGCToolWidgetItem |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
explicit QGCActionButton(QWidget *parent = 0); |
||||||
|
~QGCActionButton(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void startEditMode(); |
||||||
|
void endEditMode(); |
||||||
|
|
||||||
|
private: |
||||||
|
Ui::QGCActionButton *ui; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // QGCACTIONBUTTON_H
|
@ -0,0 +1,99 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<ui version="4.0"> |
||||||
|
<class>QGCActionButton</class> |
||||||
|
<widget class="QWidget" name="QGCActionButton"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>0</x> |
||||||
|
<y>0</y> |
||||||
|
<width>400</width> |
||||||
|
<height>111</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="windowTitle"> |
||||||
|
<string>Form</string> |
||||||
|
</property> |
||||||
|
<layout class="QGridLayout" name="gridLayout"> |
||||||
|
<item row="1" column="0" colspan="2"> |
||||||
|
<widget class="QLabel" name="nameLabel"> |
||||||
|
<property name="text"> |
||||||
|
<string>Description</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item row="1" column="2"> |
||||||
|
<widget class="QPushButton" name="actionButton"> |
||||||
|
<property name="text"> |
||||||
|
<string>Button name</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item row="2" column="0"> |
||||||
|
<widget class="QComboBox" name="editActionComboBox"/> |
||||||
|
</item> |
||||||
|
<item row="2" column="1"> |
||||||
|
<widget class="QPushButton" name="editActionsRefreshButton"> |
||||||
|
<property name="text"> |
||||||
|
<string>Refresh Actions</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item row="2" column="2"> |
||||||
|
<widget class="QPushButton" name="editFinishButton"> |
||||||
|
<property name="text"> |
||||||
|
<string>Done</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item row="0" column="2"> |
||||||
|
<widget class="QLineEdit" name="editButtonName"> |
||||||
|
<property name="text"> |
||||||
|
<string>Button name</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
<item row="0" column="0" colspan="2"> |
||||||
|
<widget class="QLineEdit" name="editNameLabel"> |
||||||
|
<property name="text"> |
||||||
|
<string>Description</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
</item> |
||||||
|
</layout> |
||||||
|
</widget> |
||||||
|
<resources/> |
||||||
|
<connections> |
||||||
|
<connection> |
||||||
|
<sender>editButtonName</sender> |
||||||
|
<signal>textChanged(QString)</signal> |
||||||
|
<receiver>actionButton</receiver> |
||||||
|
<slot>setWindowTitle(QString)</slot> |
||||||
|
<hints> |
||||||
|
<hint type="sourcelabel"> |
||||||
|
<x>310</x> |
||||||
|
<y>22</y> |
||||||
|
</hint> |
||||||
|
<hint type="destinationlabel"> |
||||||
|
<x>310</x> |
||||||
|
<y>55</y> |
||||||
|
</hint> |
||||||
|
</hints> |
||||||
|
</connection> |
||||||
|
<connection> |
||||||
|
<sender>editNameLabel</sender> |
||||||
|
<signal>textChanged(QString)</signal> |
||||||
|
<receiver>nameLabel</receiver> |
||||||
|
<slot>setText(QString)</slot> |
||||||
|
<hints> |
||||||
|
<hint type="sourcelabel"> |
||||||
|
<x>116</x> |
||||||
|
<y>22</y> |
||||||
|
</hint> |
||||||
|
<hint type="destinationlabel"> |
||||||
|
<x>116</x> |
||||||
|
<y>55</y> |
||||||
|
</hint> |
||||||
|
</hints> |
||||||
|
</connection> |
||||||
|
</connections> |
||||||
|
</ui> |
@ -0,0 +1,100 @@ |
|||||||
|
#include "QGCToolWidget.h" |
||||||
|
#include "ui_QGCToolWidget.h" |
||||||
|
|
||||||
|
#include <QMenu> |
||||||
|
#include <QList> |
||||||
|
#include <QInputDialog> |
||||||
|
#include <QDockWidget> |
||||||
|
#include <QContextMenuEvent> |
||||||
|
#include "QGCParamSlider.h" |
||||||
|
#include "QGCActionButton.h" |
||||||
|
#include "UASManager.h" |
||||||
|
|
||||||
|
QGCToolWidget::QGCToolWidget(QWidget *parent) : |
||||||
|
QWidget(parent), |
||||||
|
toolLayout(new QVBoxLayout(this)), |
||||||
|
mav(NULL), |
||||||
|
ui(new Ui::QGCToolWidget) |
||||||
|
{ |
||||||
|
ui->setupUi(this); |
||||||
|
createActions(); |
||||||
|
toolLayout->setAlignment(Qt::AlignTop); |
||||||
|
|
||||||
|
QList<UASInterface*> systems = UASManager::instance()->getUASList(); |
||||||
|
foreach (UASInterface* uas, systems) |
||||||
|
{ |
||||||
|
UAS* newMav = dynamic_cast<UAS*>(uas); |
||||||
|
if (newMav) |
||||||
|
{ |
||||||
|
addUAS(uas); |
||||||
|
} |
||||||
|
} |
||||||
|
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); |
||||||
|
} |
||||||
|
|
||||||
|
QGCToolWidget::~QGCToolWidget() |
||||||
|
{ |
||||||
|
delete ui; |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidget::addUAS(UASInterface* uas) |
||||||
|
{ |
||||||
|
UAS* newMav = dynamic_cast<UAS*>(uas); |
||||||
|
if (newMav) |
||||||
|
{ |
||||||
|
// FIXME Convert to list
|
||||||
|
if (mav == NULL) mav = newMav; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event) |
||||||
|
{ |
||||||
|
QMenu menu(this); |
||||||
|
menu.addAction(addParamAction); |
||||||
|
menu.addAction(addButtonAction); |
||||||
|
menu.addAction(setTitleAction); |
||||||
|
menu.exec(event->globalPos()); |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidget::createActions() |
||||||
|
{ |
||||||
|
addParamAction = new QAction(tr("New &Parameter Slider"), this); |
||||||
|
addParamAction->setStatusTip(tr("Add a parameter setting slider widget to the tool")); |
||||||
|
connect(addParamAction, SIGNAL(triggered()), this, SLOT(addParam())); |
||||||
|
|
||||||
|
addButtonAction = new QAction(tr("New MAV &Action Button"), this); |
||||||
|
addButtonAction->setStatusTip(tr("Add a new action button to the tool")); |
||||||
|
connect(addButtonAction, SIGNAL(triggered()), this, SLOT(addAction())); |
||||||
|
|
||||||
|
setTitleAction = new QAction(tr("Set Widget Title"), this); |
||||||
|
setTitleAction->setStatusTip(tr("Set the title caption of this tool widget")); |
||||||
|
connect(setTitleAction, SIGNAL(triggered()), this, SLOT(setTitle())); |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidget::addParam() |
||||||
|
{ |
||||||
|
QGCParamSlider* slider = new QGCParamSlider(this); |
||||||
|
toolLayout->addWidget(slider); |
||||||
|
slider->startEditMode(); |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidget::addAction() |
||||||
|
{ |
||||||
|
QGCActionButton* button = new QGCActionButton(this); |
||||||
|
toolLayout->addWidget(button); |
||||||
|
button->startEditMode(); |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidget::setTitle() |
||||||
|
{ |
||||||
|
QDockWidget* parent = dynamic_cast<QDockWidget*>(this->parentWidget()); |
||||||
|
if (parent) |
||||||
|
{ |
||||||
|
bool ok; |
||||||
|
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"), |
||||||
|
tr("Widget title:"), QLineEdit::Normal, |
||||||
|
parent->windowTitle(), &ok); |
||||||
|
if (ok && !text.isEmpty()) |
||||||
|
parent->setWindowTitle(text); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
#ifndef QGCTOOLWIDGET_H |
||||||
|
#define QGCTOOLWIDGET_H |
||||||
|
|
||||||
|
#include <QWidget> |
||||||
|
#include <QAction> |
||||||
|
#include <QVBoxLayout> |
||||||
|
|
||||||
|
#include "UAS.h" |
||||||
|
|
||||||
|
namespace Ui { |
||||||
|
class QGCToolWidget; |
||||||
|
} |
||||||
|
|
||||||
|
class QGCToolWidget : public QWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
explicit QGCToolWidget(QWidget *parent = 0); |
||||||
|
~QGCToolWidget(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void addUAS(UASInterface* uas); |
||||||
|
|
||||||
|
protected: |
||||||
|
QAction* addParamAction; |
||||||
|
QAction* addButtonAction; |
||||||
|
QAction* setTitleAction; |
||||||
|
QVBoxLayout* toolLayout; |
||||||
|
UAS* mav; |
||||||
|
|
||||||
|
void contextMenuEvent(QContextMenuEvent* event); |
||||||
|
void createActions(); |
||||||
|
|
||||||
|
protected slots: |
||||||
|
void addParam(); |
||||||
|
void addAction(); |
||||||
|
void setTitle(); |
||||||
|
|
||||||
|
|
||||||
|
private: |
||||||
|
Ui::QGCToolWidget *ui; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // QGCTOOLWIDGET_H
|
@ -0,0 +1,21 @@ |
|||||||
|
<ui version="4.0"> |
||||||
|
<author/> |
||||||
|
<comment/> |
||||||
|
<exportmacro/> |
||||||
|
<class>QGCToolWidget</class> |
||||||
|
<widget class="QWidget" name="QGCToolWidget"> |
||||||
|
<property name="geometry"> |
||||||
|
<rect> |
||||||
|
<x>0</x> |
||||||
|
<y>0</y> |
||||||
|
<width>400</width> |
||||||
|
<height>300</height> |
||||||
|
</rect> |
||||||
|
</property> |
||||||
|
<property name="windowTitle"> |
||||||
|
<string>Form</string> |
||||||
|
</property> |
||||||
|
</widget> |
||||||
|
<pixmapfunction/> |
||||||
|
<connections/> |
||||||
|
</ui> |
@ -0,0 +1,37 @@ |
|||||||
|
#include "QGCToolWidgetItem.h" |
||||||
|
|
||||||
|
#include <QMenu> |
||||||
|
#include <QContextMenuEvent> |
||||||
|
|
||||||
|
QGCToolWidgetItem::QGCToolWidgetItem(QWidget *parent) : |
||||||
|
QWidget(parent), |
||||||
|
isInEditMode(false), |
||||||
|
_component(-1) |
||||||
|
{ |
||||||
|
startEditAction = new QAction("Edit Slider", this); |
||||||
|
connect(startEditAction, SIGNAL(triggered()), this, SLOT(startEditMode())); |
||||||
|
stopEditAction = new QAction("Finish Editing Slider", this); |
||||||
|
connect(stopEditAction, SIGNAL(triggered()), this, SLOT(endEditMode())); |
||||||
|
|
||||||
|
endEditMode(); |
||||||
|
} |
||||||
|
|
||||||
|
QGCToolWidgetItem::~QGCToolWidgetItem() |
||||||
|
{ |
||||||
|
delete startEditAction; |
||||||
|
delete stopEditAction; |
||||||
|
} |
||||||
|
|
||||||
|
void QGCToolWidgetItem::contextMenuEvent (QContextMenuEvent* event) |
||||||
|
{ |
||||||
|
QMenu menu(this); |
||||||
|
if (!isInEditMode) |
||||||
|
{ |
||||||
|
menu.addAction(startEditAction); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
menu.addAction(stopEditAction); |
||||||
|
} |
||||||
|
menu.exec(event->globalPos()); |
||||||
|
} |
@ -0,0 +1,32 @@ |
|||||||
|
#ifndef QGCTOOLWIDGETITEM_H |
||||||
|
#define QGCTOOLWIDGETITEM_H |
||||||
|
|
||||||
|
#include <QWidget> |
||||||
|
#include <QAction> |
||||||
|
|
||||||
|
class QGCToolWidgetItem : public QWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
explicit QGCToolWidgetItem(QWidget *parent = 0); |
||||||
|
~QGCToolWidgetItem(); |
||||||
|
|
||||||
|
int component() {return _component;} |
||||||
|
|
||||||
|
public slots: |
||||||
|
virtual void startEditMode() {} |
||||||
|
virtual void endEditMode() {} |
||||||
|
virtual void setComponent(int comp) {_component = comp;} |
||||||
|
|
||||||
|
protected: |
||||||
|
QAction* startEditAction; |
||||||
|
QAction* stopEditAction; |
||||||
|
|
||||||
|
bool isInEditMode; |
||||||
|
int _component; ///< The MAV component (the process or device ID)
|
||||||
|
|
||||||
|
void contextMenuEvent (QContextMenuEvent* event); |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
#endif // QGCTOOLWIDGETITEM_H
|
Loading…
Reference in new issue