1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Added some basic user controls to the new map plug-in

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@797 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2010-06-17 14:57:37 +00:00 committed by pip
parent e4b09f8f21
commit 933cedee56
4 changed files with 559 additions and 36 deletions

View File

@ -17,5 +17,6 @@ SOURCES += opmapplugin.cpp \
opmapgadgetconfiguration.cpp \
opmapgadget.cpp
OTHER_FILES += OPMapGadget.pluginspec
FORMS += opmapgadgetoptionspage.ui
FORMS += opmapgadgetoptionspage.ui \
opmap_controlpanel.ui
RESOURCES += opmap.qrc

View File

@ -0,0 +1,409 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OPMapControlPanel</class>
<widget class="QWidget" name="OPMapControlPanel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>588</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="windowTitle">
<string>OPMap Control Panel</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>5</x>
<y>7</y>
<width>309</width>
<height>561</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>5</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>MapType</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Goto Place</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="pushButtonGO">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>GO</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>GeoCoderStatusCode</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Way Points</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="pushButtonAddWayPoint">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDeleteWayPoint">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListView" name="listViewWayPoints">
<property name="frameShape">
<enum>QFrame::WinPanel</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Rotate</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QPushButton" name="pushButtonRL">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonRC">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>Center</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonRR">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Zoom</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButtonZoomP">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonZoomM">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>-</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>ZoomIncrement</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>CurrentZoom=</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Misc</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="topMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>ShowGridLines</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>UseOpenGL</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="cursor">
<cursorShape>OpenHandCursor</cursorShape>
</property>
<property name="text">
<string>ReloadMap</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>10</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -26,41 +26,78 @@
*/
#include "opmapgadgetwidget.h"
#include <QStringList>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include "extensionsystem/pluginmanager.h"
#include "ui_opmap_controlpanel.h"
// *************************************************************************************
// constructor
OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
{
int size = 256;
// **************
map = NULL;
controlpanel_ui = NULL;
follow_uav = false;
// **************
// Get required UAVObjects
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
m_positionActual = PositionActual::GetInstance(objManager);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
// **************
// create the user control panel
controlpanel_ui = new Ui::OPMapControlPanel();
controlpanel_ui->setupUi(this);
// **************
// create the map display
map = NULL;
map = new mapcontrol::OPMapWidget();
map->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
// map->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
map->setMinimumSize(64, 64);
PositionActual::DataFields data = m_positionActual->getData(); // get current position data
// **************
// set the user control options
QVBoxLayout *layout = new QVBoxLayout;
controlpanel_ui->comboBox->addItems(mapcontrol::Helper::MapTypes());
controlpanel_ui->comboBox->setCurrentIndex(mapcontrol::Helper::MapTypes().indexOf("GoogleHybrid"));
// **************
map->SetShowTileGridLines(controlpanel_ui->checkBox->isChecked());
// get current position data
PositionActual::DataFields data = m_positionActual->getData();
// set the default map position
map->SetCurrentPosition(internals::PointLatLng(data.Latitude, data.Longitude));
// **************
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
QHBoxLayout *layout = new QHBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(controlpanel_ui->layoutWidget);
layout->addWidget(map);
setLayout(layout);
// m_updateTimer = new QTimer();
// m_updateTimer->setInterval(250);
// connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePosition()));
// m_updateTimer->start();
// **************
m_updateTimer = new QTimer();
m_updateTimer->setInterval(250);
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePosition()));
m_updateTimer->start();
// **************
}
// *************************************************************************************
@ -69,7 +106,7 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
OPMapGadgetWidget::~OPMapGadgetWidget()
{
if (map) delete map;
// Do nothing
if (controlpanel_ui) delete controlpanel_ui;
}
// *************************************************************************************
@ -78,8 +115,7 @@ void OPMapGadgetWidget::setZoom(int value)
{
if (map)
{
// map->setZoom(value);
// map->updateRequestNew();
map->SetZoom(value);
}
}
@ -87,36 +123,35 @@ void OPMapGadgetWidget::setPosition(QPointF pos)
{
if (map)
{
// map->setView(pos);
// map->updateRequestNew();
map->SetCurrentPosition(internals::PointLatLng(pos.y(), pos.x()));
}
}
void OPMapGadgetWidget::setMapProvider(QString provider)
{
if (map)
{
// map->
}
// if (map)
// if (map->isStarted())
// map->SetMapType(mapcontrol::Helper::MapTypeFromString(provider));
}
// *************************************************************************************
void OPMapGadgetWidget::updatePosition()
{
PositionActual::DataFields data = m_positionActual->getData(); // get current position data
// get current position data
PositionActual::DataFields data = m_positionActual->getData();
// uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon
//
// if (follow_uav)
// setPosition(uavPoint->coordinate()); // center the map onto the UAV
if (map && follow_uav)
{ // center the map onto the UAV
map->SetCurrentPosition(internals::PointLatLng(data.Latitude, data.Longitude));
}
}
// *************************************************************************************
void OPMapGadgetWidget::resizeEvent(QResizeEvent *event)
{
if (map) map->resize(QSize(width(), height()));
// if (map) map->resize(QSize(width(), height()));
update();
QWidget::resizeEvent(event);
}
@ -167,3 +202,72 @@ void OPMapGadgetWidget::keyPressEvent(QKeyEvent* event)
}
// *************************************************************************************
void OPMapGadgetWidget::zoomChanged(double zoom)
{
controlpanel_ui->label_5->setText("CurrentZoom=" + QString::number(zoom));
}
void OPMapGadgetWidget::on_checkBox_clicked(bool checked)
{
if (map)
map->SetShowTileGridLines(checked);
}
void OPMapGadgetWidget::on_comboBox_currentIndexChanged(QString value)
{
if (map)
if (map->isStarted())
map->SetMapType(mapcontrol::Helper::MapTypeFromString(value));
}
void OPMapGadgetWidget::on_pushButtonGO_clicked()
{
if (map)
{
core::GeoCoderStatusCode::Types x = map->SetCurrentPositionByKeywords(controlpanel_ui->lineEdit->text());
controlpanel_ui->label->setText(mapcontrol::Helper::StrFromGeoCoderStatusCode(x));
}
}
void OPMapGadgetWidget::on_pushButtonRL_clicked()
{
if (map)
map->SetRotate(map->Rotate() - 1);
}
void OPMapGadgetWidget::on_pushButtonRC_clicked()
{
if (map)
map->SetRotate(0);
}
void OPMapGadgetWidget::on_pushButtonRR_clicked()
{
if (map)
map->SetRotate(map->Rotate() + 1);
}
void OPMapGadgetWidget::on_pushButtonZoomP_clicked()
{
if (map)
{
double x = map->Zoom();
double y = controlpanel_ui->doubleSpinBox->value();
map->SetZoom(map->Zoom() + controlpanel_ui->doubleSpinBox->value());
}
}
void OPMapGadgetWidget::on_pushButtonZoomM_clicked()
{
if (map)
map->SetZoom(map->Zoom() - controlpanel_ui->doubleSpinBox->value());
}
void OPMapGadgetWidget::on_checkBox_2_clicked(bool checked)
{
if (map)
map->SetUseOpenGL(checked);
}
// *************************************************************************************

View File

@ -30,9 +30,12 @@
#include "opmapcontrol/opmapcontrol.h"
#include <QtGui/QWidget>
#include <QtGui/QMainWindow>
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/positionactual.h"
namespace Ui { class OPMapControlPanel; }
using namespace mapcontrol;
class OPMapGadgetWidget : public QWidget
@ -48,8 +51,6 @@ public:
void setMapProvider(QString provider);
public slots:
// void gcsButtonClick();
// void uavButtonClick(bool checked);
protected:
void resizeEvent(QResizeEvent *event);
@ -58,21 +59,29 @@ protected:
private slots:
void updatePosition();
private:
// void addUserControls();
// control panel slots
void on_checkBox_clicked(bool checked);
void on_comboBox_currentIndexChanged(QString );
void on_pushButtonGO_clicked();
void on_pushButtonRR_clicked();
void on_pushButtonRC_clicked();
void on_pushButtonRL_clicked();
void on_pushButtonZoomM_clicked();
void on_pushButtonZoomP_clicked();
void zoomChanged(double zoom);
void on_checkBox_2_clicked(bool checked);
private:
bool follow_uav; // true if the map is to stay centered on the UAV
double heading; // compass/uav heading
mapcontrol::OPMapWidget *map;
QTimer *m_updateTimer;
PositionActual *m_positionActual;
QPushButton *gcsButton;
QPushButton *uavButton;
Ui::OPMapControlPanel *controlpanel_ui;
mapcontrol::OPMapWidget *map;
};
#endif /* OPMAP_GADGETWIDGET_H_ */