mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
Typo fix gsc renamed to gcs
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@777 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
a54925b8eb
commit
ea3f3446e2
@ -1,480 +1,480 @@
|
|||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* @file mapgadgetwidget.cpp
|
* @file mapgadgetwidget.cpp
|
||||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
* @brief
|
* @brief
|
||||||
* @see The GNU Public License (GPL) Version 3
|
* @see The GNU Public License (GPL) Version 3
|
||||||
* @defgroup map
|
* @defgroup map
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 3 of the License, or
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
* for more details.
|
* for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License along
|
* 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.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#include "mapgadgetwidget.h"
|
#include "mapgadgetwidget.h"
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QtGui/QVBoxLayout>
|
#include <QtGui/QVBoxLayout>
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
#include "extensionsystem/pluginmanager.h"
|
#include "extensionsystem/pluginmanager.h"
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
// constructor
|
// constructor
|
||||||
|
|
||||||
MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent)
|
MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
int size = 256;
|
int size = 256;
|
||||||
|
|
||||||
gcsButton = NULL;
|
gcsButton = NULL;
|
||||||
uavButton = NULL;
|
uavButton = NULL;
|
||||||
|
|
||||||
follow_uav = false;
|
follow_uav = false;
|
||||||
|
|
||||||
gcs_pixmap.load(QString::fromUtf8(":/map/images/gsc.png"));
|
gcs_pixmap.load(QString::fromUtf8(":/map/images/gcs.png"));
|
||||||
uav_pixmap.load(QString::fromUtf8(":/map/images/uav.png"));
|
uav_pixmap.load(QString::fromUtf8(":/map/images/uav.png"));
|
||||||
waypoint_pixmap.load(QString::fromUtf8(":/map/images/waypoint.png"));
|
waypoint_pixmap.load(QString::fromUtf8(":/map/images/waypoint.png"));
|
||||||
// waypoint_pixmap.load(QCoreApplication::applicationDirPath() + "/images/waypoint.png");
|
// waypoint_pixmap.load(QCoreApplication::applicationDirPath() + "/images/waypoint.png");
|
||||||
|
|
||||||
// test
|
// test
|
||||||
if (gcs_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/gsc.png"));
|
if (gcs_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/gcs.png"));
|
||||||
if (uav_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/uav.png"));
|
if (uav_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/uav.png"));
|
||||||
if (waypoint_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/waypoint.png"));
|
if (waypoint_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/waypoint.png"));
|
||||||
|
|
||||||
// Get required UAVObjects
|
// Get required UAVObjects
|
||||||
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
|
||||||
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
|
||||||
m_positionActual = PositionActual::GetInstance(objManager);
|
m_positionActual = PositionActual::GetInstance(objManager);
|
||||||
|
|
||||||
m_mc = new MapControl(QSize(size, size));
|
m_mc = new MapControl(QSize(size, size));
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
|
|
||||||
// setMouseTracking(true);
|
// setMouseTracking(true);
|
||||||
|
|
||||||
m_mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
m_mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
m_mc->setMinimumSize(64, 64);
|
m_mc->setMinimumSize(64, 64);
|
||||||
m_mc->showScale(true);
|
m_mc->showScale(true);
|
||||||
m_mc->showLatLon(true);
|
m_mc->showLatLon(true);
|
||||||
|
|
||||||
m_osmAdapter = new OSMMapAdapter();
|
m_osmAdapter = new OSMMapAdapter();
|
||||||
m_googleAdapter = new GoogleMapAdapter();
|
m_googleAdapter = new GoogleMapAdapter();
|
||||||
m_googleSatAdapter = new GoogleSatMapAdapter();
|
m_googleSatAdapter = new GoogleSatMapAdapter();
|
||||||
m_yahooAdapter = new YahooMapAdapter();
|
m_yahooAdapter = new YahooMapAdapter();
|
||||||
|
|
||||||
m_osmLayer = new MapLayer("OpenStreetMap", m_osmAdapter);
|
m_osmLayer = new MapLayer("OpenStreetMap", m_osmAdapter);
|
||||||
m_googleLayer = new MapLayer("Google", m_googleAdapter);
|
m_googleLayer = new MapLayer("Google", m_googleAdapter);
|
||||||
m_googleSatLayer = new MapLayer("Google Sat", m_googleSatAdapter);
|
m_googleSatLayer = new MapLayer("Google Sat", m_googleSatAdapter);
|
||||||
m_yahooLayer = new MapLayer("Yahoo", m_yahooAdapter);
|
m_yahooLayer = new MapLayer("Yahoo", m_yahooAdapter);
|
||||||
|
|
||||||
// gcs and uav position layer
|
// gcs and uav position layer
|
||||||
m_positionLayer = new GeometryLayer("PositionsLayer", m_osmAdapter);
|
m_positionLayer = new GeometryLayer("PositionsLayer", m_osmAdapter);
|
||||||
|
|
||||||
// Waypoint layer
|
// Waypoint layer
|
||||||
m_wayPointLayer = new GeometryLayer("WayPointsLayer", m_osmAdapter);
|
m_wayPointLayer = new GeometryLayer("WayPointsLayer", m_osmAdapter);
|
||||||
|
|
||||||
m_osmLayer->setVisible(true);
|
m_osmLayer->setVisible(true);
|
||||||
m_googleLayer->setVisible(false);
|
m_googleLayer->setVisible(false);
|
||||||
m_googleSatLayer->setVisible(false);
|
m_googleSatLayer->setVisible(false);
|
||||||
m_yahooLayer->setVisible(false);
|
m_yahooLayer->setVisible(false);
|
||||||
m_positionLayer->setVisible(true);
|
m_positionLayer->setVisible(true);
|
||||||
m_wayPointLayer->setVisible(true);
|
m_wayPointLayer->setVisible(true);
|
||||||
|
|
||||||
m_mc->addLayer(m_osmLayer);
|
m_mc->addLayer(m_osmLayer);
|
||||||
m_mc->addLayer(m_googleLayer);
|
m_mc->addLayer(m_googleLayer);
|
||||||
m_mc->addLayer(m_googleSatLayer);
|
m_mc->addLayer(m_googleSatLayer);
|
||||||
m_mc->addLayer(m_yahooLayer);
|
m_mc->addLayer(m_yahooLayer);
|
||||||
m_mc->addLayer(m_wayPointLayer);
|
m_mc->addLayer(m_wayPointLayer);
|
||||||
m_mc->addLayer(m_positionLayer);
|
m_mc->addLayer(m_positionLayer);
|
||||||
|
|
||||||
PositionActual::DataFields data = m_positionActual->getData(); // get current position data
|
PositionActual::DataFields data = m_positionActual->getData(); // get current position data
|
||||||
|
|
||||||
heading = data.Heading;
|
heading = data.Heading;
|
||||||
|
|
||||||
addCompass(QPointF(100, 100), 200);
|
addCompass(QPointF(100, 100), 200);
|
||||||
|
|
||||||
// create and add the GCS icon
|
// create and add the GCS icon
|
||||||
gcsPoint = new ImagePoint(data.Longitude, data.Latitude, &gcs_pixmap, "GSC", Point::Middle);
|
gcsPoint = new ImagePoint(data.Longitude, data.Latitude, &gcs_pixmap, "GSC", Point::Middle);
|
||||||
m_positionLayer->addGeometry(gcsPoint);
|
m_positionLayer->addGeometry(gcsPoint);
|
||||||
connect(gcsPoint, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(gcs_uav_ClickEvent(Geometry*, QPoint)));
|
connect(gcsPoint, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(gcs_uav_ClickEvent(Geometry*, QPoint)));
|
||||||
|
|
||||||
// create and add the UAV icon
|
// create and add the UAV icon
|
||||||
uavPoint = new ImagePoint(data.Longitude, data.Latitude, &uav_pixmap, "UAV", Point::Middle);
|
uavPoint = new ImagePoint(data.Longitude, data.Latitude, &uav_pixmap, "UAV", Point::Middle);
|
||||||
m_positionLayer->addGeometry(uavPoint);
|
m_positionLayer->addGeometry(uavPoint);
|
||||||
connect(uavPoint, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(gcs_uav_ClickEvent(Geometry*, QPoint)));
|
connect(uavPoint, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(gcs_uav_ClickEvent(Geometry*, QPoint)));
|
||||||
|
|
||||||
addUserControls();
|
addUserControls();
|
||||||
|
|
||||||
m_mc->setView(gcsPoint->coordinate());
|
m_mc->setView(gcsPoint->coordinate());
|
||||||
m_mc->setZoom(2);
|
m_mc->setZoom(2);
|
||||||
m_mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->addWidget(m_mc);
|
layout->addWidget(m_mc);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
connect(m_mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(coordinateEvent(const QMouseEvent*, const QPointF)));
|
connect(m_mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(coordinateEvent(const QMouseEvent*, const QPointF)));
|
||||||
|
|
||||||
// connect(m_wayPointLayer, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(wayPointClickEvent(Geometry*, QPoint)));
|
// connect(m_wayPointLayer, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(wayPointClickEvent(Geometry*, QPoint)));
|
||||||
|
|
||||||
m_updateTimer = new QTimer();
|
m_updateTimer = new QTimer();
|
||||||
m_updateTimer->setInterval(250);
|
m_updateTimer->setInterval(250);
|
||||||
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePosition()));
|
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePosition()));
|
||||||
m_updateTimer->start();
|
m_updateTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
// destructor
|
// destructor
|
||||||
|
|
||||||
MapGadgetWidget::~MapGadgetWidget()
|
MapGadgetWidget::~MapGadgetWidget()
|
||||||
{
|
{
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::setZoom(int value)
|
void MapGadgetWidget::setZoom(int value)
|
||||||
{
|
{
|
||||||
m_mc->setZoom(value);
|
m_mc->setZoom(value);
|
||||||
m_mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGadgetWidget::setPosition(QPointF pos)
|
void MapGadgetWidget::setPosition(QPointF pos)
|
||||||
{
|
{
|
||||||
m_mc->setView(pos);
|
m_mc->setView(pos);
|
||||||
m_mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGadgetWidget::setMapProvider(QString provider)
|
void MapGadgetWidget::setMapProvider(QString provider)
|
||||||
{
|
{
|
||||||
foreach (QString layerName, m_mc->layers())
|
foreach (QString layerName, m_mc->layers())
|
||||||
{
|
{
|
||||||
Layer *layer = m_mc->layer(layerName);
|
Layer *layer = m_mc->layer(layerName);
|
||||||
MapAdapter *ma = (MapAdapter*)layer->mapadapter();
|
MapAdapter *ma = (MapAdapter*)layer->mapadapter();
|
||||||
|
|
||||||
bool visible = layerName == provider;
|
bool visible = layerName == provider;
|
||||||
|
|
||||||
if (layerName == "WayPointsLayer" || layerName == "PositionsLayer")
|
if (layerName == "WayPointsLayer" || layerName == "PositionsLayer")
|
||||||
{ // leave the way points & positions layers visible
|
{ // leave the way points & positions layers visible
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
layer->setVisible(visible);
|
layer->setVisible(visible);
|
||||||
|
|
||||||
if (visible)
|
if (visible)
|
||||||
{ // move the geomtery layers over to the selected map
|
{ // move the geomtery layers over to the selected map
|
||||||
m_positionLayer->setMapAdapter(ma);
|
m_positionLayer->setMapAdapter(ma);
|
||||||
m_wayPointLayer->setMapAdapter(ma);
|
m_wayPointLayer->setMapAdapter(ma);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_positionLayer->setVisible(true);
|
m_positionLayer->setVisible(true);
|
||||||
m_wayPointLayer->setVisible(true);
|
m_wayPointLayer->setVisible(true);
|
||||||
|
|
||||||
m_mc->updateRequestNew();
|
m_mc->updateRequestNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::updatePosition()
|
void MapGadgetWidget::updatePosition()
|
||||||
{
|
{
|
||||||
PositionActual::DataFields data = m_positionActual->getData(); // get current position data
|
PositionActual::DataFields data = m_positionActual->getData(); // get current position data
|
||||||
|
|
||||||
heading = data.Heading; // save the current UAV heading
|
heading = data.Heading; // save the current UAV heading
|
||||||
|
|
||||||
uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon
|
uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon
|
||||||
|
|
||||||
if (follow_uav)
|
if (follow_uav)
|
||||||
setPosition(uavPoint->coordinate()); // center the map onto the UAV
|
setPosition(uavPoint->coordinate()); // center the map onto the UAV
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGadgetWidget::resizeEvent(QResizeEvent *event)
|
void MapGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
m_mc->resize(QSize(width(), height()));
|
m_mc->resize(QSize(width(), height()));
|
||||||
update();
|
update();
|
||||||
QWidget::resizeEvent(event);
|
QWidget::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::addUserControls()
|
void MapGadgetWidget::addUserControls()
|
||||||
{ // create the user controls
|
{ // create the user controls
|
||||||
|
|
||||||
gcsButton = new QPushButton(tr("GCS"));
|
gcsButton = new QPushButton(tr("GCS"));
|
||||||
gcsButton->setMinimumWidth(50);
|
gcsButton->setMinimumWidth(50);
|
||||||
gcsButton->setMaximumWidth(50);
|
gcsButton->setMaximumWidth(50);
|
||||||
gcsButton->setToolTip(tr("Center onto ground control station"));
|
gcsButton->setToolTip(tr("Center onto ground control station"));
|
||||||
connect(gcsButton, SIGNAL(clicked(bool)), this, SLOT(gcsButtonClick()));
|
connect(gcsButton, SIGNAL(clicked(bool)), this, SLOT(gcsButtonClick()));
|
||||||
|
|
||||||
uavButton = new QPushButton(tr("UAV"));
|
uavButton = new QPushButton(tr("UAV"));
|
||||||
uavButton->setMinimumWidth(50);
|
uavButton->setMinimumWidth(50);
|
||||||
uavButton->setMaximumWidth(50);
|
uavButton->setMaximumWidth(50);
|
||||||
uavButton->setCheckable(true);
|
uavButton->setCheckable(true);
|
||||||
uavButton->setToolTip(tr("Stay centered on the UAV"));
|
uavButton->setToolTip(tr("Stay centered on the UAV"));
|
||||||
connect(uavButton, SIGNAL(clicked(bool)), this, SLOT(uavButtonClick(bool)));
|
connect(uavButton, SIGNAL(clicked(bool)), this, SLOT(uavButtonClick(bool)));
|
||||||
|
|
||||||
QPushButton* zoomin = new QPushButton("+");
|
QPushButton* zoomin = new QPushButton("+");
|
||||||
zoomin->setMinimumWidth(50);
|
zoomin->setMinimumWidth(50);
|
||||||
zoomin->setMaximumWidth(50);
|
zoomin->setMaximumWidth(50);
|
||||||
zoomin->setToolTip(tr("Zoom in"));
|
zoomin->setToolTip(tr("Zoom in"));
|
||||||
connect(zoomin, SIGNAL(clicked(bool)), m_mc, SLOT(zoomIn()));
|
connect(zoomin, SIGNAL(clicked(bool)), m_mc, SLOT(zoomIn()));
|
||||||
|
|
||||||
QPushButton* zoomout = new QPushButton("-");
|
QPushButton* zoomout = new QPushButton("-");
|
||||||
zoomout->setMinimumWidth(50);
|
zoomout->setMinimumWidth(50);
|
||||||
zoomout->setMaximumWidth(50);
|
zoomout->setMaximumWidth(50);
|
||||||
zoomout->setToolTip(tr("Zoom out"));
|
zoomout->setToolTip(tr("Zoom out"));
|
||||||
connect(zoomout, SIGNAL(clicked(bool)), m_mc, SLOT(zoomOut()));
|
connect(zoomout, SIGNAL(clicked(bool)), m_mc, SLOT(zoomOut()));
|
||||||
|
|
||||||
// add zoom buttons to the layout of the MapControl
|
// add zoom buttons to the layout of the MapControl
|
||||||
QVBoxLayout* innerlayout = new QVBoxLayout;
|
QVBoxLayout* innerlayout = new QVBoxLayout;
|
||||||
innerlayout->setSpacing(3);
|
innerlayout->setSpacing(3);
|
||||||
innerlayout->setMargin(2);
|
innerlayout->setMargin(2);
|
||||||
innerlayout->addSpacing(10);
|
innerlayout->addSpacing(10);
|
||||||
innerlayout->addWidget(gcsButton);
|
innerlayout->addWidget(gcsButton);
|
||||||
innerlayout->addWidget(uavButton);
|
innerlayout->addWidget(uavButton);
|
||||||
innerlayout->addSpacing(10);
|
innerlayout->addSpacing(10);
|
||||||
innerlayout->addWidget(zoomin);
|
innerlayout->addWidget(zoomin);
|
||||||
innerlayout->addWidget(zoomout);
|
innerlayout->addWidget(zoomout);
|
||||||
innerlayout->addStretch(0);
|
innerlayout->addStretch(0);
|
||||||
m_mc->setLayout(innerlayout);
|
m_mc->setLayout(innerlayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::gcsButtonClick()
|
void MapGadgetWidget::gcsButtonClick()
|
||||||
{
|
{
|
||||||
follow_uav = false;
|
follow_uav = false;
|
||||||
uavButton->setChecked(follow_uav);
|
uavButton->setChecked(follow_uav);
|
||||||
|
|
||||||
setPosition(gcsPoint->coordinate()); // center the map onto the ground station
|
setPosition(gcsPoint->coordinate()); // center the map onto the ground station
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::uavButtonClick(bool checked)
|
void MapGadgetWidget::uavButtonClick(bool checked)
|
||||||
{
|
{
|
||||||
follow_uav = checked;
|
follow_uav = checked;
|
||||||
|
|
||||||
if (follow_uav)
|
if (follow_uav)
|
||||||
{ // immediately center the map onto the UAV .. rather than waiting for the timer to it
|
{ // immediately center the map onto the UAV .. rather than waiting for the timer to it
|
||||||
// PositionActual::DataFields data = m_positionActual->getData(); // get the current position data
|
// PositionActual::DataFields data = m_positionActual->getData(); // get the current position data
|
||||||
// heading = data.Heading; // save the current UAV heading
|
// heading = data.Heading; // save the current UAV heading
|
||||||
// uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon
|
// uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon
|
||||||
// setPosition(uavPoint->coordinate()); // center the map on the UAV
|
// setPosition(uavPoint->coordinate()); // center the map on the UAV
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::coordinateEvent(const QMouseEvent * evnt, const QPointF coordinate) // cmoss
|
void MapGadgetWidget::coordinateEvent(const QMouseEvent * evnt, const QPointF coordinate) // cmoss
|
||||||
{
|
{
|
||||||
QString coord_str = "lat " + QString::number(coordinate.y(), 'f', 6) + ", lon " + QString::number(coordinate.x(), 'f', 6);
|
QString coord_str = "lat " + QString::number(coordinate.y(), 'f', 6) + ", lon " + QString::number(coordinate.x(), 'f', 6);
|
||||||
|
|
||||||
if (evnt->type() == QEvent::MouseButtonPress)
|
if (evnt->type() == QEvent::MouseButtonPress)
|
||||||
{ // mouse click event
|
{ // mouse click event
|
||||||
if (evnt->buttons() == Qt::RightButton)
|
if (evnt->buttons() == Qt::RightButton)
|
||||||
{
|
{
|
||||||
qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str;
|
qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str;
|
||||||
|
|
||||||
QMessageBox::information(this, "Coordinate Clicked", coord_str);
|
QMessageBox::information(this, "Coordinate Clicked", coord_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // mouse move event
|
{ // mouse move event
|
||||||
qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str;
|
qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
// comes here when the user mouse clicks on the GCS or the UAV
|
// comes here when the user mouse clicks on the GCS or the UAV
|
||||||
|
|
||||||
void MapGadgetWidget::gcs_uav_ClickEvent(Geometry* geom, QPoint)
|
void MapGadgetWidget::gcs_uav_ClickEvent(Geometry* geom, QPoint)
|
||||||
{
|
{
|
||||||
qDebug() << "parent: " << geom->parentGeometry();
|
qDebug() << "parent: " << geom->parentGeometry();
|
||||||
qDebug() << "Element clicked: " << geom->name();
|
qDebug() << "Element clicked: " << geom->name();
|
||||||
|
|
||||||
if (geom->hasClickedPoints())
|
if (geom->hasClickedPoints())
|
||||||
{
|
{
|
||||||
QList<Geometry*> pp = geom->clickedPoints();
|
QList<Geometry*> pp = geom->clickedPoints();
|
||||||
|
|
||||||
qDebug() << "number of child elements: " << pp.size();
|
qDebug() << "number of child elements: " << pp.size();
|
||||||
|
|
||||||
for (int i=0; i<pp.size(); i++)
|
for (int i=0; i<pp.size(); i++)
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, geom->name(), pp.at(i)->name());
|
QMessageBox::information(this, geom->name(), pp.at(i)->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (geom->GeometryType == "Point")
|
if (geom->GeometryType == "Point")
|
||||||
{
|
{
|
||||||
if (geom->name() == "UAV")
|
if (geom->name() == "UAV")
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, geom->name(), tr("The UAV location"));
|
QMessageBox::information(this, geom->name(), tr("The UAV location"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (geom->name() == "GCS")
|
if (geom->name() == "GCS")
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, geom->name(), tr("The GCS location"));
|
QMessageBox::information(this, geom->name(), tr("The GCS location"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
QMessageBox::information(this, geom->name(), tr("just a point"));
|
QMessageBox::information(this, geom->name(), tr("just a point"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
// comes here when the user mouse clicks on a waypoint
|
// comes here when the user mouse clicks on a waypoint
|
||||||
|
|
||||||
void MapGadgetWidget::wayPointClickEvent(Geometry* geom, QPoint)
|
void MapGadgetWidget::wayPointClickEvent(Geometry* geom, QPoint)
|
||||||
{
|
{
|
||||||
qDebug() << "parent: " << geom->parentGeometry();
|
qDebug() << "parent: " << geom->parentGeometry();
|
||||||
qDebug() << "Element clicked: " << geom->name();
|
qDebug() << "Element clicked: " << geom->name();
|
||||||
|
|
||||||
if (geom->hasClickedPoints())
|
if (geom->hasClickedPoints())
|
||||||
{
|
{
|
||||||
QList<Geometry*> pp = geom->clickedPoints();
|
QList<Geometry*> pp = geom->clickedPoints();
|
||||||
|
|
||||||
qDebug() << "number of child elements: " << pp.size();
|
qDebug() << "number of child elements: " << pp.size();
|
||||||
|
|
||||||
for (int i=0; i<pp.size(); i++)
|
for (int i=0; i<pp.size(); i++)
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, geom->name(), pp.at(i)->name());
|
QMessageBox::information(this, geom->name(), pp.at(i)->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (geom->GeometryType == "Point")
|
if (geom->GeometryType == "Point")
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, geom->name(), tr("just a point"));
|
QMessageBox::information(this, geom->name(), tr("just a point"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
// add a way point
|
// add a way point
|
||||||
|
|
||||||
void MapGadgetWidget::addWayPoint(QPointF pos, QString name)
|
void MapGadgetWidget::addWayPoint(QPointF pos, QString name)
|
||||||
{
|
{
|
||||||
if (waypoint_pixmap.isNull()) return;
|
if (waypoint_pixmap.isNull()) return;
|
||||||
|
|
||||||
ImagePoint *waypoint = new ImagePoint(pos.x(), pos.y(), &waypoint_pixmap, name, qmapcontrol::Point::BottomRight);
|
ImagePoint *waypoint = new ImagePoint(pos.x(), pos.y(), &waypoint_pixmap, name, qmapcontrol::Point::BottomRight);
|
||||||
// waypoint->setBaselevel(0);
|
// waypoint->setBaselevel(0);
|
||||||
connect(waypoint, SIGNAL(geometryClicked(Geometry *, QPoint)), this, SLOT(wayPointClickEvent(Geometry *, QPoint)));
|
connect(waypoint, SIGNAL(geometryClicked(Geometry *, QPoint)), this, SLOT(wayPointClickEvent(Geometry *, QPoint)));
|
||||||
|
|
||||||
m_wayPointLayer->addGeometry(waypoint);
|
m_wayPointLayer->addGeometry(waypoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
// add the compass
|
// add the compass
|
||||||
|
|
||||||
void MapGadgetWidget::addCompass(QPointF pos, int size, QString name)
|
void MapGadgetWidget::addCompass(QPointF pos, int size, QString name)
|
||||||
{
|
{
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if (compass_background_pixmap.isNull())
|
// if (compass_background_pixmap.isNull())
|
||||||
{ // create the compass background image
|
{ // create the compass background image
|
||||||
QImage image(size, size, QImage::Format_ARGB32_Premultiplied);
|
QImage image(size, size, QImage::Format_ARGB32_Premultiplied);
|
||||||
if (image.isNull()) return;
|
if (image.isNull()) return;
|
||||||
|
|
||||||
image.fill(QColor(0, 0, 0, 0).rgba());
|
image.fill(QColor(0, 0, 0, 0).rgba());
|
||||||
|
|
||||||
QPainter painter(&image);
|
QPainter painter(&image);
|
||||||
painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true);
|
painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true);
|
||||||
painter.setFont(font());
|
painter.setFont(font());
|
||||||
|
|
||||||
QPen pen = QPen(Qt::NoPen);
|
QPen pen = QPen(Qt::NoPen);
|
||||||
pen.setStyle(Qt::SolidLine);
|
pen.setStyle(Qt::SolidLine);
|
||||||
pen.setWidth(1);
|
pen.setWidth(1);
|
||||||
pen.setBrush(Qt::black);
|
pen.setBrush(Qt::black);
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
|
|
||||||
QRadialGradient gradient(size / 2, size / 2, size / 2);
|
QRadialGradient gradient(size / 2, size / 2, size / 2);
|
||||||
gradient.setColorAt(0.0, QColor(0, 0, 0, 0));
|
gradient.setColorAt(0.0, QColor(0, 0, 0, 0));
|
||||||
gradient.setColorAt(0.05, QColor(0, 0, 0, 160));
|
gradient.setColorAt(0.05, QColor(0, 0, 0, 160));
|
||||||
gradient.setColorAt(1.0, QColor(0, 0, 0, 160));
|
gradient.setColorAt(1.0, QColor(0, 0, 0, 160));
|
||||||
|
|
||||||
// QGradient gradient = QLinearGradient(0, 0, 0, 1);
|
// QGradient gradient = QLinearGradient(0, 0, 0, 1);
|
||||||
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
|
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
|
||||||
gradient.setSpread(QGradient::PadSpread);
|
gradient.setSpread(QGradient::PadSpread);
|
||||||
painter.setBrush(gradient);
|
painter.setBrush(gradient);
|
||||||
|
|
||||||
// painter.drawRect(image.rect());
|
// painter.drawRect(image.rect());
|
||||||
painter.drawEllipse(image.rect());
|
painter.drawEllipse(image.rect());
|
||||||
|
|
||||||
compass_background_pixmap = QPixmap::fromImage(image);
|
compass_background_pixmap = QPixmap::fromImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImagePoint *compass = new ImagePoint(pos.x(), pos.y(), &compass_background_pixmap, name, qmapcontrol::Point::Middle);
|
// ImagePoint *compass = new ImagePoint(pos.x(), pos.y(), &compass_background_pixmap, name, qmapcontrol::Point::Middle);
|
||||||
// connect(compass, SIGNAL(geometryClicked(Geometry *, QPoint)), this, SLOT(compassClickEvent(Geometry *, QPoint)));
|
// connect(compass, SIGNAL(geometryClicked(Geometry *, QPoint)), this, SLOT(compassClickEvent(Geometry *, QPoint)));
|
||||||
|
|
||||||
m_compassImageOverlay = new FixedImageOverlay(0, 0, size, size, &compass_background_pixmap, "compass_background");
|
m_compassImageOverlay = new FixedImageOverlay(0, 0, size, size, &compass_background_pixmap, "compass_background");
|
||||||
// m_compassImageOverlay->setBaselevel(0);
|
// m_compassImageOverlay->setBaselevel(0);
|
||||||
// m_compassImageOverlay->setPen();
|
// m_compassImageOverlay->setPen();
|
||||||
|
|
||||||
m_positionLayer->addGeometry(m_compassImageOverlay);
|
m_positionLayer->addGeometry(m_compassImageOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
|
||||||
void MapGadgetWidget::keyPressEvent(QKeyEvent* event)
|
void MapGadgetWidget::keyPressEvent(QKeyEvent* event)
|
||||||
{
|
{
|
||||||
if (event->key() == Qt::Key_Escape) // ESC
|
if (event->key() == Qt::Key_Escape) // ESC
|
||||||
{
|
{
|
||||||
// emit(close());
|
// emit(close());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_F1) // F1
|
if (event->key() == Qt::Key_F1) // F1
|
||||||
{
|
{
|
||||||
gcsButtonClick();
|
gcsButtonClick();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_F2) // F2
|
if (event->key() == Qt::Key_F2) // F2
|
||||||
{
|
{
|
||||||
follow_uav = !follow_uav;
|
follow_uav = !follow_uav;
|
||||||
uavButton->setChecked(follow_uav);
|
uavButton->setChecked(follow_uav);
|
||||||
uavButtonClick(follow_uav);
|
uavButtonClick(follow_uav);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_Up)
|
if (event->key() == Qt::Key_Up)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_Down)
|
if (event->key() == Qt::Key_Down)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_Left)
|
if (event->key() == Qt::Key_Left)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_Right)
|
if (event->key() == Qt::Key_Right)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_PageUp)
|
if (event->key() == Qt::Key_PageUp)
|
||||||
{
|
{
|
||||||
m_mc->zoomIn();
|
m_mc->zoomIn();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (event->key() == Qt::Key_PageDown)
|
if (event->key() == Qt::Key_PageDown)
|
||||||
{
|
{
|
||||||
m_mc->zoomOut();
|
m_mc->zoomOut();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << event->key() << endl;
|
qDebug() << event->key() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************
|
// *************************************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user