1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/map: A map gadget to have something more interesting to look at than the emptygadget.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@339 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-19 17:31:13 +00:00 committed by ephy
parent 7884356cf6
commit 3c15818b3b
10 changed files with 319 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<plugin name="MapGadget" version="1.0.0" compatVersion="1.0.0">
<vendor>The OpenPilot Project</vendor>
<copyright>(C) 2010 OpenPilot Project</copyright>
<license></license>
<description>A map gadget!</description>
<url>http://www.openpilot.org</url>
<dependencyList>
<dependency name="Core" version="1.0.0"/>
</dependencyList>
</plugin>

View File

@ -0,0 +1,18 @@
TEMPLATE = lib
TARGET = MapGadget
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/qmapcontrol/qmapcontrol.pri)
HEADERS += mapplugin.h
HEADERS += mapgadget.h
HEADERS += mapgadgetwidget.h
HEADERS += mapgadgetfactory.h
SOURCES += mapplugin.cpp
SOURCES += mapgadget.cpp
SOURCES += mapgadgetfactory.cpp
SOURCES += mapgadgetwidget.cpp
OTHER_FILES += MapGadget.pluginspec

View File

@ -0,0 +1,21 @@
/*
* mapgadget.cpp
*
* Created on: Mar 11, 2010
* Author: peter
*/
#include "mapgadget.h"
#include "mapgadgetwidget.h"
#include <QtGui/QToolBar>
MapGadget::MapGadget(MapGadgetWidget *widget) :
IUAVGadget(widget),
m_widget(widget),
m_toolbar(new QToolBar())
{
}
MapGadget::~MapGadget()
{
}

View File

@ -0,0 +1,40 @@
/*
* mapgadget.h
*
* Created on: Mar 11, 2010
* Author: peter
*/
#ifndef MAPGADGET_H_
#define MAPGADGET_H_
#include <coreplugin/iuavgadget.h>
class IUAVGadget;
//class QList<int>;
class QWidget;
class QString;
class MapGadgetWidget;
using namespace Core;
class MapGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
MapGadget(MapGadgetWidget *widget = 0);
~MapGadget();
QList<int> context() const { return m_context; }
QWidget *widget() { return m_widget; }
QString contextHelpId() const { return QString(); }
QWidget *toolBar() { return m_toolbar; }
private:
QWidget *m_widget;
QWidget *m_toolbar;
QList<int> m_context;
};
#endif // MAPGADGET_H_

View File

@ -0,0 +1,28 @@
/*
* mapgadgetfactory.cpp
*
* Created on: Mar 11, 2010
* Author: peter
*/
#include "mapgadgetfactory.h"
#include "mapgadgetwidget.h"
#include "mapgadget.h"
#include <coreplugin/iuavgadget.h>
MapGadgetFactory::MapGadgetFactory(QObject *parent) : IUAVGadgetFactory(parent)
{
}
MapGadgetFactory::~MapGadgetFactory()
{
}
Core::IUAVGadget* MapGadgetFactory::createUAVGadget(QWidget *parent) {
MapGadgetWidget* gadgetWidget = new MapGadgetWidget(parent);
return new MapGadget(gadgetWidget);
}
QString MapGadgetFactory::name() {
return QString("MapGadget");
}

View File

@ -0,0 +1,28 @@
/*
* mapgadgetfactory.h
*
* Created on: Mar 6, 2010
* Author: peter
*/
#ifndef MAPGADGETFACTORY_H_
#define MAPGADGETFACTORY_H_
#include <coreplugin/iuavgadgetfactory.h>
using namespace Core;
class IUAVGadget;
class IUAVGadgetFactory;
class MapGadgetFactory : public Core::IUAVGadgetFactory
{
Q_OBJECT
public:
MapGadgetFactory(QObject *parent = 0);
~MapGadgetFactory();
Core::IUAVGadget *createUAVGadget(QWidget *parent);
QString name();
};
#endif // MAPGADGETFACTORY_H_

View File

@ -0,0 +1,66 @@
/*
* mapgadgetwidget.cpp
*
* Created on: Mar 6, 2010
* Author: peter
*/
#include "mapgadgetwidget.h"
#include <QStringList>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent)
{
int size = 256;
mc = new MapControl(QSize(size, size));
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
mc->setMinimumSize(64, 64);
mc->showScale(true);
mapadapter = new OSMMapAdapter();
mainlayer = new MapLayer("OpenStreetMap-Layer", mapadapter);
mc->addLayer(mainlayer);
addZoomButtons();
mc->setView(QPointF(5.718888888888, 58.963333333333));
mc->setZoom(10);
mc->updateRequestNew();
QVBoxLayout *layout = new QVBoxLayout;
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(mc);
setLayout(layout);
}
MapGadgetWidget::~MapGadgetWidget()
{
// Do nothing
}
void MapGadgetWidget::resizeEvent(QResizeEvent *event)
{
mc->resize(QSize(width(), height()));
update();
QWidget::resizeEvent(event);
}
void MapGadgetWidget::addZoomButtons()
{
// create buttons as controls for zoom
QPushButton* zoomin = new QPushButton("+");
QPushButton* zoomout = new QPushButton("-");
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
// add zoom buttons to the layout of the MapControl
QVBoxLayout* innerlayout = new QVBoxLayout;
innerlayout->addWidget(zoomin);
innerlayout->addWidget(zoomout);
mc->setLayout(innerlayout);
}

View File

@ -0,0 +1,35 @@
/*
* mapgadgetwidget.h
*
* Created on: Mar 6, 2010
* Author: peter
*/
#ifndef MAPGADGETWIDGET_H_
#define MAPGADGETWIDGET_H_
#include "qmapcontrol/qmapcontrol.h"
#include <QtGui/QWidget>
using namespace qmapcontrol;
class MapGadgetWidget : public QWidget
{
Q_OBJECT
public:
MapGadgetWidget(QWidget *parent = 0);
~MapGadgetWidget();
protected:
void resizeEvent(QResizeEvent *event);
private:
MapControl *mc;
MapAdapter *mapadapter;
Layer *mainlayer;
void addZoomButtons();
};
#endif /* MAPGADGETWIDGET_H_ */

View File

@ -0,0 +1,46 @@
/*
* mapplugin.cpp
*
* Created on: Mar 6, 2010
* Author: peter
*/
#include "mapplugin.h"
#include "mapgadgetfactory.h"
#include <QDebug>
#include <QtPlugin>
#include <QStringList>
#include <extensionsystem/pluginmanager.h>
MapPlugin::MapPlugin()
{
// Do nothing
}
MapPlugin::~MapPlugin()
{
// Do nothing
}
bool MapPlugin::initialize(const QStringList& args, QString *errMsg)
{
Q_UNUSED(args);
Q_UNUSED(errMsg);
mf = new MapGadgetFactory(this);
addAutoReleasedObject(mf);
qDebug() << "MapPlugin::initialize()";
return true;
}
void MapPlugin::extensionsInitialized()
{
// Do nothing
}
void MapPlugin::shutdown()
{
// Do nothing
}
Q_EXPORT_PLUGIN(MapPlugin)

View File

@ -0,0 +1,27 @@
/*
* mapplugin.h
*
* Created on: Mar 6, 2010
* Author: peter
*/
#ifndef MAPPLUGIN_H_
#define MAPPLUGIN_H_
#include <extensionsystem/iplugin.h>
class MapGadgetFactory;
class MapPlugin : public ExtensionSystem::IPlugin
{
public:
MapPlugin();
~MapPlugin();
void extensionsInitialized();
bool initialize(const QStringList & arguments, QString * errorString);
void shutdown();
private:
MapGadgetFactory *mf;
};
#endif /* MAPPLUGIN_H_ */