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

User controls added to the new map plug-in.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@843 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2010-06-21 12:16:25 +00:00 committed by pip
parent 3bc938d45e
commit c5bde18926
4 changed files with 545 additions and 95 deletions

View File

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

View File

@ -0,0 +1,443 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OPMap_Widget</class>
<widget class="QWidget" name="OPMap_Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>732</width>
<height>372</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="layoutWidget">
<property name="spacing">
<number>8</number>
</property>
<property name="leftMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<item>
<widget class="QToolButton" name="toolButtonReload">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Reload map</string>
</property>
<property name="text">
<string>Reload</string>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonFindPlace">
<property name="toolTip">
<string>Find place</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/find.png</normaloff>:/core/images/find.png</iconset>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonZoomM">
<property name="toolTip">
<string>Zoom out</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/minus.png</normaloff>:/core/images/minus.png</iconset>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonZoomP">
<property name="toolTip">
<string>Zoom in</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/plus.png</normaloff>:/core/images/plus.png</iconset>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelZoom">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Zoom</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonRL">
<property name="toolTip">
<string>Rotate anticlockwise</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/undo.png</normaloff>:/core/images/undo.png</iconset>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonRC">
<property name="toolTip">
<string>Reset rotation</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/clear.png</normaloff>:/core/images/clear.png</iconset>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonRR">
<property name="toolTip">
<string>Rotate clockwise</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../coreplugin/core.qrc">
<normaloff>:/core/images/redo.png</normaloff>:/core/images/redo.png</iconset>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelRotate">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Rotate</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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>
<widget class="QProgressBar" name="progressBarMap">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>14</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>10</height>
</size>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">QProgressBar {
/*border: 1px solid black;*/
border: none;
padding: 1px;
/*border-top-left-radius: 7px;
border-bottom-left-radius: 7px;*/
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(0, 0, 0, 255), stop:1 rgba(100, 100, 100, 255));
/*width: 15px;*/
color: rgb(255, 255, 255);
}
QProgressBar::chunk {
background-color: rgb(85, 85, 255);
border: none;
}</string>
</property>
<property name="value">
<number>50</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="format">
<string>%v</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelMapPos">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>labelMapPos</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelStatus">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<kerning>true</kerning>
</font>
</property>
<property name="text">
<string>labelStatus</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="mapWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(0, 0, 0);</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../coreplugin/core.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -24,15 +24,16 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "opmapgadgetwidget.h"
#include "ui_opmap_widget.h"
#include <QStringList>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QDir>
#include "extensionsystem/pluginmanager.h"
#include "ui_opmap_controlpanel.h"
// *************************************************************************************
// constructor
@ -40,7 +41,7 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
{
// **************
controlpanel_ui = NULL;
m_widget = NULL;
m_map = NULL;
setMouseTracking(true);
@ -48,55 +49,38 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
// **************
// Get required UAVObjects
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager* objManager = pm->getObject<UAVObjectManager>();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
m_positionActual = PositionActual::GetInstance(objManager);
// **************
// create the user control panel
// controlpanel_ui = new Ui::OPMapControlPanel();
// controlpanel_ui->setupUi(this);
m_widget = new Ui_OPMap_Widget();
m_widget->setupUi(this);
/*
QWidget *dialog = new QWidget(this, Qt::Dialog);
controlpanel_ui = new Ui::OPMapControlPanel();
controlpanel_ui->setupUi(dialog);
QHBoxLayout *d_layout = new QHBoxLayout(dialog);
d_layout->setSpacing(0);
d_layout->setContentsMargins(0, 0, 0, 0);
d_layout->addWidget(controlpanel_ui->layoutWidget);
dialog->setLayout(d_layout);
dialog->show();
*/
// **************
// create the map display
m_map = new mapcontrol::OPMapWidget();
// m_map = new mapcontrol::OPMapWidget(widget->mapWidget);
if (m_map)
{
m_map->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_map->setMinimumSize(64, 64);
m_map->configuration->DragButton = Qt::LeftButton;
m_map->configuration->DragButton = Qt::LeftButton; // use the left mouse button for map dragging
}
// **************
// set the user control options
if (controlpanel_ui)
{
controlpanel_ui->labelZoom->setText(" " + QString::number(m_map->Zoom()));
controlpanel_ui->labelRotate->setText(" " + QString::number(m_map->Rotate()));
// controlpanel_ui->labelNumTilesToLoad->setText(" 0");
controlpanel_ui->labelStatus->setText("");
controlpanel_ui->progressBarMap->setMaximum(1);
}
m_widget->labelZoom->setText(" " + QString::number(m_map->Zoom()));
m_widget->labelRotate->setText(" " + QString::number(m_map->Rotate()));
// m_widget->labelNumTilesToLoad->setText(" 0");
m_widget->labelMapPos->setText("");
m_widget->labelStatus->setText("");
m_widget->progressBarMap->setMaximum(1);
// **************
@ -108,6 +92,8 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
// get current UAV data
PositionActual::DataFields data = m_positionActual->getData();
if (m_map)
{
connect(m_map, SIGNAL(zoomChanged(double)), this, SLOT(zoomChanged(double))); // map zoom change signals
connect(m_map, SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)), this, SLOT(OnCurrentPositionChanged(internals::PointLatLng))); // map poisition change signals
connect(m_map, SIGNAL(OnTileLoadComplete()), this, SLOT(OnTileLoadComplete())); // tile loading stop signals
@ -124,6 +110,7 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
m_map->SetUseOpenGL(openGLAct->isChecked()); // enable/disable openGL
m_map->SetShowTileGridLines(gridLinesAct->isChecked()); // map grid lines on/off
m_map->SetCurrentPosition(internals::PointLatLng(data.Latitude, data.Longitude)); // set the default map position
}
// **************
@ -132,9 +119,8 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
//if (controlpanel_ui) layout->addWidget(controlpanel_ui->layoutWidget);
layout->addWidget(m_map);
setLayout(layout);
m_widget->mapWidget->setLayout(layout);
// **************
// create the user controls overlayed onto the map
@ -163,7 +149,7 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
OPMapGadgetWidget::~OPMapGadgetWidget()
{
if (m_map) delete m_map;
if (controlpanel_ui) delete controlpanel_ui;
if (m_widget) delete m_widget;
}
// *************************************************************************************
@ -185,10 +171,10 @@ void OPMapGadgetWidget::mouseMoveEvent(QMouseEvent *event)
// { // the mouse has moved
// mouse_lat_lon = lat_lon;
//
// QString coord_str = " " + QString::number(mouse_lat_lon.Lat(), 'f', 6) + " " + QString::number(mouse_lat_lon.Lng(), 'f', 6);
// QString coord_str = " " + QString::number(mouse_lat_lon.Lat(), 'f', 6) + " " + QString::number(mouse_lat_lon.Lng(), 'f', 6) + " ";
//
// statusLabel.setText(coord_str);
// controlpanel_ui->labelStatus->setText(coord_str);
// widget->labelStatus->setText(coord_str);
// }
}
@ -336,7 +322,7 @@ void OPMapGadgetWidget::statusUpdate()
QString coord_str = " " + QString::number(mouse_lat_lon.Lat(), 'f', 6) + " " + QString::number(mouse_lat_lon.Lng(), 'f', 6);
statusLabel.setText(coord_str);
if (controlpanel_ui) controlpanel_ui->labelStatus->setText(coord_str);
if (m_widget) m_widget->labelStatus->setText(coord_str);
}
}
@ -347,8 +333,8 @@ void OPMapGadgetWidget::zoomChanged(double zoom)
{
int i_zoom = (int)(zoom + 0.5);
if (controlpanel_ui)
controlpanel_ui->labelZoom->setText(" " + QString::number(zoom));
if (m_widget)
m_widget->labelZoom->setText(" " + QString::number(zoom));
switch (i_zoom)
{
@ -381,28 +367,33 @@ void OPMapGadgetWidget::OnMapDrag()
void OPMapGadgetWidget::OnCurrentPositionChanged(internals::PointLatLng point)
{
if (m_widget)
{
QString coord_str = " " + QString::number(point.Lat(), 'f', 6) + " " + QString::number(point.Lng(), 'f', 6) + " ";
m_widget->labelMapPos->setText(coord_str);
}
}
void OPMapGadgetWidget::OnTilesStillToLoad(int number)
{
if (controlpanel_ui)
if (m_widget)
{
if (controlpanel_ui->progressBarMap->maximum() < number)
controlpanel_ui->progressBarMap->setMaximum(number); // update the maximum number of tiles used
controlpanel_ui->progressBarMap->setValue(controlpanel_ui->progressBarMap->maximum() - number); // update the progress bar
if (m_widget->progressBarMap->maximum() < number)
m_widget->progressBarMap->setMaximum(number); // update the maximum number of tiles used
m_widget->progressBarMap->setValue(m_widget->progressBarMap->maximum() - number); // update the progress bar
// controlpanel_ui->labelNumTilesToLoad->setText(" " + QString::number(number));
// m_widget->labelNumTilesToLoad->setText(" " + QString::number(number));
}
}
void OPMapGadgetWidget::OnTileLoadStart()
{
if (controlpanel_ui) controlpanel_ui->progressBarMap->setVisible(true);
if (m_widget) m_widget->progressBarMap->setVisible(true);
}
void OPMapGadgetWidget::OnTileLoadComplete()
{
if (controlpanel_ui) controlpanel_ui->progressBarMap->setVisible(false);
if (m_widget) m_widget->progressBarMap->setVisible(false);
}
void OPMapGadgetWidget::OnMapZoomChanged()
@ -420,12 +411,23 @@ void OPMapGadgetWidget::OnEmptyTileError(int zoom, core::Point pos)
// *************************************************************************************
// user control panel signals
void OPMapGadgetWidget::on_toolButtonReload_clicked()
{
if (m_map)
m_map->ReloadMap();
}
void OPMapGadgetWidget::on_toolButtonFindPlace_clicked()
{
findPlace();
}
void OPMapGadgetWidget::on_toolButtonRL_clicked()
{
if (m_map)
{
m_map->SetRotate(m_map->Rotate() - 1);
if (controlpanel_ui) controlpanel_ui->labelRotate->setText(" " + QString::number(m_map->Rotate()));
if (m_widget) m_widget->labelRotate->setText(" " + QString::number(m_map->Rotate()));
}
}
@ -434,7 +436,7 @@ void OPMapGadgetWidget::on_toolButtonRC_clicked()
if (m_map)
{
m_map->SetRotate(0);
if (controlpanel_ui) controlpanel_ui->labelRotate->setText(" " + QString::number(m_map->Rotate()));
if (m_widget) m_widget->labelRotate->setText(" " + QString::number(m_map->Rotate()));
}
}
@ -443,7 +445,7 @@ void OPMapGadgetWidget::on_toolButtonRR_clicked()
if (m_map)
{
m_map->SetRotate(m_map->Rotate() + 1);
if (controlpanel_ui) controlpanel_ui->labelRotate->setText(" " + QString::number(m_map->Rotate()));
if (m_widget) m_widget->labelRotate->setText(" " + QString::number(m_map->Rotate()));
}
}
@ -459,37 +461,39 @@ void OPMapGadgetWidget::on_toolButtonZoomM_clicked()
void OPMapGadgetWidget::on_pushButtonGeoFenceM_clicked()
{
if (controlpanel_ui)
if (m_widget)
{
int geo_fence_distance = controlpanel_ui->spinBoxGeoFenceDistance->value();
int step = controlpanel_ui->spinBoxGeoFenceDistance->singleStep();
controlpanel_ui->spinBoxGeoFenceDistance->setValue(geo_fence_distance - step);
// int geo_fence_distance = m_widget->spinBoxGeoFenceDistance->value();
// int step = m_widget->spinBoxGeoFenceDistance->singleStep();
// m_widget->spinBoxGeoFenceDistance->setValue(geo_fence_distance - step);
// geo_fence_distance = m_widget->spinBoxGeoFenceDistance->value();
geo_fence_distance = controlpanel_ui->spinBoxGeoFenceDistance->value();
}
// to do
}
}
void OPMapGadgetWidget::on_pushButtonGeoFenceP_clicked()
{
if (controlpanel_ui)
if (m_widget)
{
int geo_fence_distance = controlpanel_ui->spinBoxGeoFenceDistance->value();
int step = controlpanel_ui->spinBoxGeoFenceDistance->singleStep();
controlpanel_ui->spinBoxGeoFenceDistance->setValue(geo_fence_distance + step);
// int geo_fence_distance = m_widget->spinBoxGeoFenceDistance->value();
// int step = m_widget->spinBoxGeoFenceDistance->singleStep();
// m_widget->spinBoxGeoFenceDistance->setValue(geo_fence_distance + step);
// geo_fence_distance = m_widget->spinBoxGeoFenceDistance->value();
geo_fence_distance = controlpanel_ui->spinBoxGeoFenceDistance->value();
}
// to do
}
}
// *************************************************************************************

View File

@ -34,7 +34,7 @@
#include "uavobjects/uavobjectmanager.h"
#include "uavobjects/positionactual.h"
namespace Ui { class OPMapControlPanel; }
class Ui_OPMap_Widget;
using namespace mapcontrol;
@ -69,6 +69,8 @@ private slots:
void zoomOut();
// control panel signals
void on_toolButtonReload_clicked();
void on_toolButtonFindPlace_clicked();
void on_toolButtonRR_clicked();
void on_toolButtonRC_clicked();
void on_toolButtonRL_clicked();
@ -132,7 +134,7 @@ private:
PositionActual *m_positionActual;
Ui::OPMapControlPanel *controlpanel_ui;
Ui_OPMap_Widget *m_widget;
mapcontrol::OPMapWidget *m_map;