Commit 0533e34c authored by Leander Schulten's avatar Leander Schulten
Browse files

Added Map View and Editor

parent 48c47ef9
#include "mapeditor.h"
MapEditor::MapEditor()
{
setAcceptedMouseButtons(Qt::AllButtons);
setKeepMouseGrab(true);
}
void MapEditor::mousePressEvent(QMouseEvent *event){
qDebug()<<event->x()<<'\n';
for(auto i = stonework->points.begin();i!=stonework->points.end();++i){
if(i->isNear(event->x(),event->y(),20)){
currentPressedPoint = &*i;
event->accept();
}
}
}
void MapEditor::mouseMoveEvent(QMouseEvent *event){
if(currentPressedPoint){
currentPressedPoint->x = event->x();
currentPressedPoint->y = event->y();
stonework->update();
event->accept();
}
}
#ifndef MAPEDITOR_H
#define MAPEDITOR_H
#include "mapview.h"
class MapEditor : public MapView
{
private:
Polygon::Point * currentPressedPoint = nullptr;
public:
MapEditor();
protected:
virtual void mouseMoveEvent(QMouseEvent *event)override;
virtual void mousePressEvent(QMouseEvent *event)override;
};
#endif // MAPEDITOR_H
#include "mapview.h"
MapView::MapView()
{
stonework = new Polygon();
stonework->setParentItem(this);
surfaces = new Polygon();
surfaces->setParentItem(this);
surfaces->setColor(QColor(255, 153, 0));
surfaces->addRectangle(200,250,10,40);
stonework->addPoint(Polygon::Point(1.f,2.f));
stonework->addPoint(Polygon::Point(50.f,7.f));
stonework->addPoint(Polygon::Point(4.f,80.f));
stonework->addPoint(Polygon::Point(80.f,100.f));
stonework->addTriangle(0,1,2);
stonework->addTriangle(1,2,3);
stonework->setColor(QColor(0,128,255));
//stonework->addRectangle(100,200,200,300);
stonework->addArc(200,170,200,200,230,200);
stonework->addArc(230,200,200,200,200,230);
//stonework->addArc(70,200,100,200,100,170);
}
#ifndef MAPVIEW_H
#define MAPVIEW_H
#include "polygon.h"
#include "gridbackground.h"
class MapView : public GridBackground
{
Q_OBJECT
protected:
Polygon * stonework = new Polygon();
Polygon * surfaces = new Polygon();
public:
MapView();
signals:
public slots:
};
#endif // MAPVIEW_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment