1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

Corrected GUI widget spacers, added OpenGL rendering.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2617 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-01-28 22:41:34 +00:00 committed by pip
parent f6805de71e
commit 7c73f9c2c8
5 changed files with 325 additions and 299 deletions

View File

@ -1,6 +1,7 @@
TEMPLATE = lib
TARGET = GCSControl
QT += svg
QT += opengl
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)

View File

@ -1,125 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GCSControl</class>
<widget class="QWidget" name="GCSControl">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>295</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBoxGcsControl">
<property name="text">
<string>GCS Control</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxArmed">
<property name="text">
<string>Armed</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Flight Mode:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxFlightMode"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0">
<property name="horizontalSpacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="JoystickControl" name="widgetLeftStick" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="JoystickControl" name="widgetRightStick" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>JoystickControl</class>
<extends>QWidget</extends>
<header>joystickcontrol.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GCSControl</class>
<widget class="QWidget" name="GCSControl">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>295</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>5</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBoxGcsControl">
<property name="text">
<string>GCS Control</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxArmed">
<property name="text">
<string>Armed</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Flight Mode:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxFlightMode"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0">
<property name="horizontalSpacing">
<number>10</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="JoystickControl" name="widgetLeftStick" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="JoystickControl" name="widgetRightStick" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>2</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>JoystickControl</class>
<extends>QWidget</extends>
<header>joystickcontrol.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,174 +1,177 @@
/**
******************************************************************************
*
* @file GCSControlgadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "gcscontrolgadgetwidget.h"
#include "ui_gcscontrol.h"
#include <QDebug>
#include <QStringList>
#include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include "uavobject.h"
#include "uavobjectmanager.h"
#include "manualcontrolcommand.h"
#include "extensionsystem/pluginmanager.h"
GCSControlGadgetWidget::GCSControlGadgetWidget(QWidget *parent) : QLabel(parent)
{
m_gcscontrol = new Ui_GCSControl();
m_gcscontrol->setupUi(this);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
UAVObject::Metadata mdata = obj->getMetadata();
m_gcscontrol->checkBoxGcsControl->setChecked(mdata.flightAccess == UAVObject::ACCESS_READONLY);
// Set up the drop down box for the flightmode
m_gcscontrol->comboBoxFlightMode->addItems(obj->getField("FlightMode")->getOptions());
// Set up slots and signals for joysticks
connect(m_gcscontrol->widgetLeftStick,SIGNAL(positionClicked(double,double)),this,SLOT(leftStickClicked(double,double)));
connect(m_gcscontrol->widgetRightStick,SIGNAL(positionClicked(double,double)),this,SLOT(rightStickClicked(double,double)));
// Connect misc controls
connect(m_gcscontrol->checkBoxGcsControl, SIGNAL(stateChanged(int)), this, SLOT(toggleControl(int)));
connect(m_gcscontrol->checkBoxArmed, SIGNAL(stateChanged(int)), this, SLOT(toggleArmed(int)));
connect(m_gcscontrol->comboBoxFlightMode, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFlightMode(int)));
// Connect object updated event from UAVObject to also update check boxes and dropdown
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(mccChanged(UAVObject*)));
leftX = 0;
leftY = 0;
rightX = 0;
rightY = 0;
}
GCSControlGadgetWidget::~GCSControlGadgetWidget()
{
// Do nothing
}
void GCSControlGadgetWidget::updateSticks(double nleftX, double nleftY, double nrightX, double nrightY) {
leftX = nleftX;
leftY = nleftY;
rightX = nrightX;
rightY = nrightY;
m_gcscontrol->widgetLeftStick->changePosition(leftX,leftY);
m_gcscontrol->widgetRightStick->changePosition(rightX,rightY);
}
void GCSControlGadgetWidget::leftStickClicked(double X, double Y) {
leftX = X;
leftY = Y;
emit sticksChanged(leftX,leftY,rightX,rightY);
}
void GCSControlGadgetWidget::rightStickClicked(double X, double Y) {
rightX = X;
rightY = Y;
emit sticksChanged(leftX,leftY,rightX,rightY);
}
/*!
\brief Called when the gcs control is toggled and enabled or disables flight write access to manual control command
*/
void GCSControlGadgetWidget::toggleControl(int state)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
UAVObject::Metadata mdata = obj->getMetadata();
if (state)
{
mccInitialData = mdata;
mdata.flightAccess = UAVObject::ACCESS_READONLY;
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
mdata.gcsTelemetryAcked = false;
mdata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
mdata.gcsTelemetryUpdatePeriod = 100;
}
else
{
mdata = mccInitialData;
}
obj->setMetadata(mdata);
}
void GCSControlGadgetWidget::toggleArmed(int state)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
if(state)
obj->getField("Armed")->setValue("True");
else
obj->getField("Armed")->setValue("False");
obj->updated();
}
void GCSControlGadgetWidget::mccChanged(UAVObject * obj)
{
m_gcscontrol->checkBoxArmed->setChecked(obj->getField("Armed")->getValue() == "True");
m_gcscontrol->comboBoxFlightMode->setCurrentIndex(m_gcscontrol->comboBoxFlightMode->findText(obj->getField("FlightMode")->getValue().toString()));
}
/*!
\brief Called when the flight mode drop down is changed and sets the ManualControlCommand->FlightMode accordingly
*/
void GCSControlGadgetWidget::selectFlightMode(int state)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
UAVObjectField * field = obj->getField("FlightMode");
field->setValue(field->getOptions()[state]);
obj->updated();
}
void GCSControlGadgetWidget::setGCSControl(bool newState)
{
m_gcscontrol->checkBoxGcsControl->setChecked(newState);
};
bool GCSControlGadgetWidget::getGCSControl(void)
{
return m_gcscontrol->checkBoxGcsControl->isChecked();
};
/**
* @}
* @}
*/
/**
******************************************************************************
*
* @file GCSControlgadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A gadget to control the UAV, either from the keyboard or a joystick
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "gcscontrolgadgetwidget.h"
#include "ui_gcscontrol.h"
#include <QDebug>
#include <QStringList>
#include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include "uavobject.h"
#include "uavobjectmanager.h"
#include "manualcontrolcommand.h"
#include "extensionsystem/pluginmanager.h"
GCSControlGadgetWidget::GCSControlGadgetWidget(QWidget *parent) : QLabel(parent)
{
m_gcscontrol = new Ui_GCSControl();
m_gcscontrol->setupUi(this);
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
UAVObject::Metadata mdata = obj->getMetadata();
m_gcscontrol->checkBoxGcsControl->setChecked(mdata.flightAccess == UAVObject::ACCESS_READONLY);
// Set up the drop down box for the flightmode
m_gcscontrol->comboBoxFlightMode->addItems(obj->getField("FlightMode")->getOptions());
// Set up slots and signals for joysticks
connect(m_gcscontrol->widgetLeftStick,SIGNAL(positionClicked(double,double)),this,SLOT(leftStickClicked(double,double)));
connect(m_gcscontrol->widgetRightStick,SIGNAL(positionClicked(double,double)),this,SLOT(rightStickClicked(double,double)));
// Connect misc controls
connect(m_gcscontrol->checkBoxGcsControl, SIGNAL(stateChanged(int)), this, SLOT(toggleControl(int)));
connect(m_gcscontrol->checkBoxArmed, SIGNAL(stateChanged(int)), this, SLOT(toggleArmed(int)));
connect(m_gcscontrol->comboBoxFlightMode, SIGNAL(currentIndexChanged(int)), this, SLOT(selectFlightMode(int)));
// Connect object updated event from UAVObject to also update check boxes and dropdown
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(mccChanged(UAVObject*)));
leftX = 0;
leftY = 0;
rightX = 0;
rightY = 0;
m_gcscontrol->widgetLeftStick->enableOpenGL(true);
m_gcscontrol->widgetRightStick->enableOpenGL(true);
}
GCSControlGadgetWidget::~GCSControlGadgetWidget()
{
// Do nothing
}
void GCSControlGadgetWidget::updateSticks(double nleftX, double nleftY, double nrightX, double nrightY) {
leftX = nleftX;
leftY = nleftY;
rightX = nrightX;
rightY = nrightY;
m_gcscontrol->widgetLeftStick->changePosition(leftX,leftY);
m_gcscontrol->widgetRightStick->changePosition(rightX,rightY);
}
void GCSControlGadgetWidget::leftStickClicked(double X, double Y) {
leftX = X;
leftY = Y;
emit sticksChanged(leftX,leftY,rightX,rightY);
}
void GCSControlGadgetWidget::rightStickClicked(double X, double Y) {
rightX = X;
rightY = Y;
emit sticksChanged(leftX,leftY,rightX,rightY);
}
/*!
\brief Called when the gcs control is toggled and enabled or disables flight write access to manual control command
*/
void GCSControlGadgetWidget::toggleControl(int state)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
UAVObject::Metadata mdata = obj->getMetadata();
if (state)
{
mccInitialData = mdata;
mdata.flightAccess = UAVObject::ACCESS_READONLY;
mdata.flightTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
mdata.gcsTelemetryAcked = false;
mdata.gcsTelemetryUpdateMode = UAVObject::UPDATEMODE_ONCHANGE;
mdata.gcsTelemetryUpdatePeriod = 100;
}
else
{
mdata = mccInitialData;
}
obj->setMetadata(mdata);
}
void GCSControlGadgetWidget::toggleArmed(int state)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
if(state)
obj->getField("Armed")->setValue("True");
else
obj->getField("Armed")->setValue("False");
obj->updated();
}
void GCSControlGadgetWidget::mccChanged(UAVObject * obj)
{
m_gcscontrol->checkBoxArmed->setChecked(obj->getField("Armed")->getValue() == "True");
m_gcscontrol->comboBoxFlightMode->setCurrentIndex(m_gcscontrol->comboBoxFlightMode->findText(obj->getField("FlightMode")->getValue().toString()));
}
/*!
\brief Called when the flight mode drop down is changed and sets the ManualControlCommand->FlightMode accordingly
*/
void GCSControlGadgetWidget::selectFlightMode(int state)
{
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(QString("ManualControlCommand")) );
UAVObjectField * field = obj->getField("FlightMode");
field->setValue(field->getOptions()[state]);
obj->updated();
}
void GCSControlGadgetWidget::setGCSControl(bool newState)
{
m_gcscontrol->checkBoxGcsControl->setChecked(newState);
};
bool GCSControlGadgetWidget::getGCSControl(void)
{
return m_gcscontrol->checkBoxGcsControl->isChecked();
};
/**
* @}
* @}
*/

View File

@ -35,6 +35,7 @@
#include <QtGui/QPushButton>
#include <QtGui/QMessageBox>
#include <QMouseEvent>
#include <QtOpenGL/QGLWidget>
#include <QtGlobal>
/**
@ -73,6 +74,17 @@ JoystickControl::~JoystickControl()
}
/*!
\brief Enables/Disables OpenGL
*/
void JoystickControl::enableOpenGL(bool flag)
{
if (flag)
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
else
setViewport(new QWidget);
}
/**
* @brief Update the displayed position based on an MCC update
*/

View File

@ -46,6 +46,7 @@ class JoystickControl : public QGraphicsView
public:
explicit JoystickControl(QWidget *parent = 0);
~JoystickControl();
void enableOpenGL(bool flag);
void paint();
protected: