#include "mwnd.h"
mwnd::mwnd()
{
QSize mapMcSize
= sets.
value("/mwnd/size",
QSize(800,
600)).
value<QSize>
();
this->resize( mapMcSize );
QPoint mapMcPos
= sets.
value("/mwnd/pos",
QPoint(100,
100)).
value<QPoint>
();
this->move( mapMcPos );
mc = new MapControl( mapMcSize );
mc->showScale(true);
mapadapter = new TileMapAdapter("robots.local", "/maps/maps/%1/%2/%3.png", 256, 0, 17);
// create a layer with the mapadapter and type MapLayer
l = new MapLayer("Custom Layer", mapadapter);
mc->addLayer(l);
// Add the Points and the QPen to a LineString
LineString* ls = new LineString();
// Add the LineString to the layer
l->addGeometry(ls);
connect(l,
SIGNAL( geometryClicked
(Geometry
*,
QPoint) ),
this,
SLOT( geometryClicked
(Geometry
*,
QPoint) ));
// create buttons as controls for zoom
zoomin->setMaximumWidth(50);
zoomout->setMaximumWidth(50);
zoomslider->setMaximum(17);
zoomslider->setMinimum(0);
zoomslider->setMaximumHeight( 170 );
connect(zoomin, SIGNAL(clicked(bool)), mc, SLOT(zoomIn()));
connect(zoomout, SIGNAL(clicked(bool)),mc, SLOT(zoomOut()));
connect(zoomslider, SIGNAL(valueChanged(int)), mc, SLOT(setZoom(int)));
connect(mc,SIGNAL(zoomChanged(int)), zoomslider, SLOT(setValue(int)));
// add zoom buttons to the layout of the MapControl
plusminusbtn->addWidget(zoomin);
plusminusbtn->addWidget(zoomslider);
plusminusbtn->addWidget(zoomout);
// MapControl layout
innerlayout->addLayout(plusminusbtn);
mc->setLayout(innerlayout);
//mc->setView(QPointF(0.00656,0.01929));
// 55.809952,37.500973
//GPS_Position pos = GPS_Position(1234567890 ,37.500973,"W",55.809952,"N");
QPointF coord
= sets.
value("/mwnd/mc/pos",
QPointF( 55.81 ,
37.501 )).
value<QPointF>
();
mc->setView( coord );
int zoom = sets.value("/mwnd/mc/zoom", 15).value<int>();
mc->setZoom(zoom);
ls->addPoint( new CirclePoint( coord.x(), coord.y(),"Start location", Point::Middle) );
//QLabel* point;
//innerlayout->addWidget( point );
tabs->addTab(mc, "Map");
//layout->addWidget(mc);
layout->setSpacing(0);
layout->setContentsMargins(0,0,0,0);
layout->addWidget( tabs );
this->setLayout(layout);
}
mwnd::~mwnd()
{
sets.setValue("/mwnd/size",this->size());
sets.setValue("/mwnd/pos",this->pos());
sets.setValue("/mwnd/mc/pos", mc->currentCoordinate() );
sets.setValue("/mwnd/mc/zoom",mc->currentZoom() );
}
// Protected methods
{
//mc->resize( (int) this->size().width(), (int) this->size().height() );
//qDebug( QString("W: %1 H: %2").arg(this->size().width()).arg(this->size().height()).toAscii() );
//mc->update();
event->accept();
//QWidget::resizeEvent(event);
}
{
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15;
if (event->orientation() == Qt::Horizontal) {
// Change view
} else {
if(numSteps > 0)
{
if(mc->currentZoom()<17)
{
mc->zoomIn();
}
}
else
{
if(mc->currentZoom()>0)
{
mc->zoomOut();
}
}
}
event->accept();
}
void mwnd
::geometryClicked(Geometry
*geom,
QPoint) {
if (geom->hasClickedPoints())
{
QList<Geometry*> pp = geom->clickedPoints();
for (int i=0; i<pp.size(); i++)
{
QMessageBox::information(this, geom
->name
(), pp.
at(i
)->name
());
}
}
else if (geom->GeometryType == "Point")
{
QMessageBox::information(this, geom
->name
(),
"just a point");
}
}
{
event->accept();
}