mirror of
https://github.com/mapmapteam/mapmap.git
synced 2026-06-16 12:33:19 +02:00
Merge branch 'develop' into statesaving
Conflicts: DestinationGLCanvas.cpp MainWindow.cpp MainWindow.h Mapper.h MappingManager.cpp MappingManager.h Paint.h Shape.h SourceGLCanvas.cpp Util.cpp libremapping.pro main.cpp
This commit is contained in:
+74
-5
@@ -23,7 +23,7 @@
|
||||
#include "MainWindow.h"
|
||||
|
||||
MapperGLCanvas::MapperGLCanvas(QWidget* parent, const QGLWidget * shareWidget)
|
||||
: QGLWidget(parent, shareWidget), _mousepressed(false), _active_vertex(0)
|
||||
: QGLWidget(parent, shareWidget), _mousepressed(false), _active_vertex(NO_VERTEX)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,6 +96,11 @@ void MapperGLCanvas::enterDraw()
|
||||
//// glLoadIdentity (); // FIXME? is this needed here?
|
||||
}
|
||||
|
||||
Shape* MapperGLCanvas::getCurrentShape()
|
||||
{
|
||||
return getShapeFromMappingId(MainWindow::getInstance().getCurrentMappingId());
|
||||
}
|
||||
|
||||
void MapperGLCanvas::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
int i, dist, maxdist, mindist;
|
||||
@@ -120,12 +125,22 @@ void MapperGLCanvas::mousePressEvent(QMouseEvent* event)
|
||||
_mousepressed = true;
|
||||
}
|
||||
}
|
||||
if (event->buttons() & Qt::RightButton)
|
||||
{
|
||||
Shape* shape = getCurrentShape();
|
||||
if (shape->includesPoint(xmouse, ymouse))
|
||||
{
|
||||
_shapegrabbed = true;
|
||||
_shapefirstgrab = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapperGLCanvas::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
// std::cout << "Mouse Release event " << std::endl;
|
||||
_mousepressed = false;
|
||||
_shapegrabbed = false;
|
||||
}
|
||||
|
||||
void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
@@ -135,17 +150,39 @@ void MapperGLCanvas::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
// std::cout << "Move event " << std::endl;
|
||||
Shape* shape = getCurrentShape();
|
||||
if (shape)
|
||||
if (shape && _active_vertex != NO_VERTEX)
|
||||
{
|
||||
Point *p = shape->getVertex(_active_vertex);
|
||||
p->setX(event->x());
|
||||
p->setY(event->y());
|
||||
|
||||
glueVertex(shape, &p);
|
||||
shape->setVertex(_active_vertex, p);
|
||||
|
||||
update();
|
||||
emit quadChanged();
|
||||
emit shapeChanged(getCurrentShape());
|
||||
}
|
||||
}
|
||||
else if (_shapegrabbed)
|
||||
{
|
||||
// std::cout << "Move event " << std::endl;
|
||||
Shape* shape = getCurrentShape();
|
||||
static Point p(0,0);
|
||||
if (shape)
|
||||
{
|
||||
if (_shapefirstgrab == false)
|
||||
{
|
||||
shape->translate(event->x() - p.x, event->y() - p.y);
|
||||
update();
|
||||
emit shapeChanged(getCurrentShape());
|
||||
}
|
||||
else
|
||||
_shapefirstgrab = false;
|
||||
}
|
||||
p.x = event->x();
|
||||
p.y = event->y();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
@@ -194,7 +231,6 @@ void MapperGLCanvas::keyPressEvent(QKeyEvent* event)
|
||||
|
||||
void MapperGLCanvas::paintEvent(QPaintEvent* /* event */)
|
||||
{
|
||||
std::cout << "Paint event" << std::endl;
|
||||
updateGL();
|
||||
}
|
||||
|
||||
@@ -222,6 +258,39 @@ void MapperGLCanvas::exitDraw()
|
||||
|
||||
void MapperGLCanvas::updateCanvas()
|
||||
{
|
||||
std::cout << "Update me!" << std::endl;
|
||||
update();
|
||||
}
|
||||
|
||||
/* Stick vertex p of Shape orig to another Shape's vertex, if the 2 vertices are
|
||||
* close enough. The distance per coordinate is currently set in dist_stick
|
||||
* variable. Perhaps the sticky-sensitivity should be configurable through GUI */
|
||||
void MapperGLCanvas::glueVertex(Shape *orig, Point *p)
|
||||
{
|
||||
MappingManager m = MainWindow::getInstance().getMappingManager();
|
||||
int dist_stick = 10; /*this parameter may*/
|
||||
for (int mappingId = 0; mappingId < m.nMappings(); mappingId++)
|
||||
{
|
||||
Shape *shape = getShapeFromMappingId(mappingId);
|
||||
if (shape != orig)
|
||||
{
|
||||
for (int vertex = 0; vertex < shape->nVertices(); vertex++)
|
||||
{
|
||||
Point v = shape->getVertex(vertex);
|
||||
if ((abs(v.x - p->x) < dist_stick) &&
|
||||
(abs(v.y - p->y) < dist_stick))
|
||||
{
|
||||
p->x = v.x;
|
||||
p->y = v.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapperGLCanvas::deselectAll()
|
||||
{
|
||||
_active_vertex = NO_VERTEX;
|
||||
_shapegrabbed = false;
|
||||
_shapefirstgrab = false;
|
||||
_mousepressed = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user