Commit 505236a6 authored by lm's avatar lm

Fixed control widget, made QGCToolWidgets more general, preparing the parameter interface widget

parent 713474b0
...@@ -454,18 +454,10 @@ void DebugConsole::handleConnectButton() ...@@ -454,18 +454,10 @@ void DebugConsole::handleConnectButton()
if (currLink->isConnected()) if (currLink->isConnected())
{ {
currLink->disconnect(); currLink->disconnect();
m_ui->connectButton->setText(tr("Connect"));
} }
else else
{ {
if (currLink->connect()) currLink->connect();
{
m_ui->connectButton->setText(tr("Disconn."));
}
else
{
m_ui->receiveText->appendHtml(QString("<font color=\"%1\">%2</font>").arg(QGC::colorRed.name(), tr("Could not connect link %1 ! Please check link hardware.").arg(currLink->getName())));
}
} }
} }
} }
......
...@@ -745,6 +745,7 @@ void MainWindow::connectSlugsWidgets() ...@@ -745,6 +745,7 @@ void MainWindow::connectSlugsWidgets()
void MainWindow::arrangeCommonCenterStack() void MainWindow::arrangeCommonCenterStack()
{ {
centerStack = new QStackedWidget(this); centerStack = new QStackedWidget(this);
centerStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if (!centerStack) return; if (!centerStack) return;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1000</width> <width>1000</width>
<height>22</height> <height>25</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuMGround"> <widget class="QMenu" name="menuMGround">
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>210</width> <width>222</width>
<height>141</height> <height>172</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
...@@ -18,14 +18,23 @@ ...@@ -18,14 +18,23 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>210</width> <width>222</width>
<height>130</height> <height>172</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>267</width>
<height>194</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,100,50,50,100,0"> <property name="toolTip">
<string>Control widget to send basic control actions to the micro air vehicle</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="60,150,80,80,80,100" columnstretch="1,100,40,40,100,1" rowminimumheight="0,0,0,0,0,0">
<item row="0" column="0" rowspan="6"> <item row="0" column="0" rowspan="6">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
...@@ -93,7 +102,7 @@ ...@@ -93,7 +102,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Liftoff</string> <string>Start</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../mavground.qrc"> <iconset resource="../../mavground.qrc">
......
...@@ -42,17 +42,12 @@ const char* kActionLabels[MAV_ACTION_NB] = ...@@ -42,17 +42,12 @@ const char* kActionLabels[MAV_ACTION_NB] =
"RESET MAP"}; "RESET MAP"};
QGCActionButton::QGCActionButton(QWidget *parent) : QGCActionButton::QGCActionButton(QWidget *parent) :
QGCToolWidgetItem(parent), QGCToolWidgetItem("Button", parent),
ui(new Ui::QGCActionButton), ui(new Ui::QGCActionButton),
uas(NULL) uas(NULL)
{ {
ui->setupUi(this); ui->setupUi(this);
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
this, SLOT(setActiveUAS(UASInterface*)));
// Set first UAS if it exists
this->setActiveUAS(UASManager::instance()->getActiveUAS());
connect(ui->actionButton, SIGNAL(clicked()), this, SLOT(sendAction())); connect(ui->actionButton, SIGNAL(clicked()), this, SLOT(sendAction()));
connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setActionButtonName(QString))); connect(ui->editButtonName, SIGNAL(textChanged(QString)), this, SLOT(setActionButtonName(QString)));
...@@ -73,12 +68,16 @@ QGCActionButton::~QGCActionButton() ...@@ -73,12 +68,16 @@ QGCActionButton::~QGCActionButton()
void QGCActionButton::sendAction() void QGCActionButton::sendAction()
{ {
if (uas) if (QGCToolWidgetItem::uas)
{ {
MAV_ACTION action = static_cast<MAV_ACTION>( MAV_ACTION action = static_cast<MAV_ACTION>(
ui->editActionComboBox->currentIndex()); ui->editActionComboBox->currentIndex());
uas->setAction(action); QGCToolWidgetItem::uas->setAction(action);
}
else
{
qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING";
} }
} }
...@@ -110,8 +109,3 @@ void QGCActionButton::endEditMode() ...@@ -110,8 +109,3 @@ void QGCActionButton::endEditMode()
isInEditMode = false; isInEditMode = false;
} }
void QGCActionButton::setActiveUAS(UASInterface *uas)
{
this->uas = uas;
}
...@@ -23,9 +23,6 @@ public slots: ...@@ -23,9 +23,6 @@ public slots:
void startEditMode(); void startEditMode();
void endEditMode(); void endEditMode();
private slots:
void setActiveUAS(UASInterface* uas);
private: private:
Ui::QGCActionButton *ui; Ui::QGCActionButton *ui;
UASInterface* uas; UASInterface* uas;
......
...@@ -3,9 +3,16 @@ ...@@ -3,9 +3,16 @@
#include "QGCParamSlider.h" #include "QGCParamSlider.h"
#include "ui_QGCParamSlider.h" #include "ui_QGCParamSlider.h"
#include "UASInterface.h"
QGCParamSlider::QGCParamSlider(QWidget *parent) : QGCParamSlider::QGCParamSlider(QWidget *parent) :
QGCToolWidgetItem(parent), QGCToolWidgetItem("Slider", parent),
parameterName(""),
parameterValue(0.0f),
parameterScalingFactor(0.0),
parameterMin(0.0f),
parameterMax(0.0f),
component(0),
ui(new Ui::QGCParamSlider) ui(new Ui::QGCParamSlider)
{ {
ui->setupUi(this); ui->setupUi(this);
...@@ -48,6 +55,18 @@ void QGCParamSlider::endEditMode() ...@@ -48,6 +55,18 @@ void QGCParamSlider::endEditMode()
isInEditMode = false; isInEditMode = false;
} }
void QGCParamSlider::sendParameter()
{
if (QGCToolWidgetItem::uas)
{
QGCToolWidgetItem::uas->setParameter(component, parameterName, parameterValue);
}
else
{
qDebug() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING";
}
}
void QGCParamSlider::changeEvent(QEvent *e) void QGCParamSlider::changeEvent(QEvent *e)
{ {
QWidget::changeEvent(e); QWidget::changeEvent(e);
......
...@@ -22,8 +22,16 @@ public: ...@@ -22,8 +22,16 @@ public:
public slots: public slots:
void startEditMode(); void startEditMode();
void endEditMode(); void endEditMode();
/** @brief Send the parameter to the MAV */
void sendParameter();
protected: protected:
QString parameterName; ///< Key/Name of the parameter
float parameterValue; ///< Value of the parameter
double parameterScalingFactor; ///< Factor to scale the parameter between slider and true value
float parameterMin;
float parameterMax;
int component; ///< ID of the MAV component to address
void changeEvent(QEvent *e); void changeEvent(QEvent *e);
private: private:
......
...@@ -50,7 +50,7 @@ void QGCToolWidget::addUAS(UASInterface* uas) ...@@ -50,7 +50,7 @@ void QGCToolWidget::addUAS(UASInterface* uas)
void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event) void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event)
{ {
QMenu menu(this); QMenu menu(this);
menu.addAction(addParamAction); //menu.addAction(addParamAction);
menu.addAction(addButtonAction); menu.addAction(addButtonAction);
menu.addAction(setTitleAction); menu.addAction(setTitleAction);
menu.exec(event->globalPos()); menu.exec(event->globalPos());
......
...@@ -3,16 +3,25 @@ ...@@ -3,16 +3,25 @@
#include <QMenu> #include <QMenu>
#include <QContextMenuEvent> #include <QContextMenuEvent>
QGCToolWidgetItem::QGCToolWidgetItem(QWidget *parent) : #include "UASManager.h"
QGCToolWidgetItem::QGCToolWidgetItem(const QString& name, QWidget *parent) :
QWidget(parent), QWidget(parent),
isInEditMode(false), isInEditMode(false),
qgcToolWidgetItemName(name),
uas(NULL),
_component(-1) _component(-1)
{ {
startEditAction = new QAction("Edit Slider", this); startEditAction = new QAction("Edit "+qgcToolWidgetItemName, this);
connect(startEditAction, SIGNAL(triggered()), this, SLOT(startEditMode())); connect(startEditAction, SIGNAL(triggered()), this, SLOT(startEditMode()));
stopEditAction = new QAction("Finish Editing Slider", this); stopEditAction = new QAction("Finish Editing Slider", this);
connect(stopEditAction, SIGNAL(triggered()), this, SLOT(endEditMode())); connect(stopEditAction, SIGNAL(triggered()), this, SLOT(endEditMode()));
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
this, SLOT(setActiveUAS(UASInterface*)));
// Set first UAS if it exists
setActiveUAS(UASManager::instance()->getActiveUAS());
endEditMode(); endEditMode();
} }
...@@ -35,3 +44,8 @@ void QGCToolWidgetItem::contextMenuEvent (QContextMenuEvent* event) ...@@ -35,3 +44,8 @@ void QGCToolWidgetItem::contextMenuEvent (QContextMenuEvent* event)
} }
menu.exec(event->globalPos()); menu.exec(event->globalPos());
} }
void QGCToolWidgetItem::setActiveUAS(UASInterface *uas)
{
this->uas = uas;
}
...@@ -4,11 +4,13 @@ ...@@ -4,11 +4,13 @@
#include <QWidget> #include <QWidget>
#include <QAction> #include <QAction>
#include "UASInterface.h"
class QGCToolWidgetItem : public QWidget class QGCToolWidgetItem : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QGCToolWidgetItem(QWidget *parent = 0); QGCToolWidgetItem(const QString& name, QWidget *parent = 0);
~QGCToolWidgetItem(); ~QGCToolWidgetItem();
int component() {return _component;} int component() {return _component;}
...@@ -17,12 +19,14 @@ public slots: ...@@ -17,12 +19,14 @@ public slots:
virtual void startEditMode() {} virtual void startEditMode() {}
virtual void endEditMode() {} virtual void endEditMode() {}
virtual void setComponent(int comp) {_component = comp;} virtual void setComponent(int comp) {_component = comp;}
void setActiveUAS(UASInterface *uas);
protected: protected:
QAction* startEditAction; QAction* startEditAction;
QAction* stopEditAction; QAction* stopEditAction;
bool isInEditMode; bool isInEditMode;
QString qgcToolWidgetItemName;
UASInterface* uas;
int _component; ///< The MAV component (the process or device ID) int _component; ///< The MAV component (the process or device ID)
void contextMenuEvent (QContextMenuEvent* event); void contextMenuEvent (QContextMenuEvent* event);
......
...@@ -114,18 +114,18 @@ void UASControlWidget::setUAS(UASInterface* uas) ...@@ -114,18 +114,18 @@ void UASControlWidget::setUAS(UASInterface* uas)
// Check if additional controls should be loaded // Check if additional controls should be loaded
UAS* mav = dynamic_cast<UAS*>(uas); UAS* mav = dynamic_cast<UAS*>(uas);
if (mav) if (mav)
{ {
QPushButton* startRecButton = new QPushButton(tr("Record")); QPushButton* startRecButton = new QPushButton(tr("Record"));
connect(startRecButton, SIGNAL(clicked()), mav, SLOT(startDataRecording())); connect(startRecButton, SIGNAL(clicked()), mav, SLOT(startDataRecording()));
ui.gridLayout->addWidget(startRecButton, 10, 0, 0, 2); ui.gridLayout->addWidget(startRecButton, 7, 1);
QPushButton* pauseRecButton = new QPushButton(tr("Pause")); QPushButton* pauseRecButton = new QPushButton(tr("Pause"));
connect(pauseRecButton, SIGNAL(clicked()), mav, SLOT(pauseDataRecording())); connect(pauseRecButton, SIGNAL(clicked()), mav, SLOT(pauseDataRecording()));
ui.gridLayout->addWidget(pauseRecButton, 10, 2, 0, 2); ui.gridLayout->addWidget(pauseRecButton, 7, 3);
QPushButton* stopRecButton = new QPushButton(tr("Stop")); QPushButton* stopRecButton = new QPushButton(tr("Stop"));
connect(stopRecButton, SIGNAL(clicked()), mav, SLOT(stopDataRecording())); connect(stopRecButton, SIGNAL(clicked()), mav, SLOT(stopDataRecording()));
ui.gridLayout->addWidget(stopRecButton, 10, 4, 0, 2); ui.gridLayout->addWidget(stopRecButton, 7, 4);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment