This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/2D/MapView2D.cpp
root e5e19779d5 worked on android port
opengl1 -> es
2018-01-31 17:15:11 +01:00

95 lines
1.9 KiB
C++

#include "../../fixC11.h"
#include "MapView2D.h"
#include <QPainter>
#include <QOpenGLFunctions>
#include <QMouseEvent>
#include <QKeyEvent>
#include <iostream>
#include "../model/MapModelElement.h"
#include "../model/MapModel.h"
MapView2D::MapView2D(QWidget* parent) : QOpenGLWidget(parent) {
// openGL params
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSamples(1);
// format.setVersion(3, 2);
format.setProfile(QSurfaceFormat::CoreProfile);
setFormat(format);
// receive mouse-move even when mouse is not down
setMouseTracking(true);
setFocusPolicy(Qt::StrongFocus);
// defaults
s.setScale(5);
}
void MapView2D::paintGL() {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClear(GL_COLOR_BUFFER_BIT);
QPainter qp(this);
Painter p(s, &qp, width(), height());
s.setScreenSize(width(), height());
// background tools
tools.paintBefore(this, p);
// render all visible elements
qp.setRenderHint( QPainter::Antialiasing, true );
for (MapModelElement* el : getModel()->getVisibleElements()) {
if (el->getMV2D()) {el->getMV2D()->paint(p);}
}
qp.setRenderHint( QPainter::Antialiasing, false );
// foreground tools
tools.paintAfter(this, p);
}
void MapView2D::initializeGL() {
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
f->glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
}
void MapView2D::resizeGL() {
// TODO ?
}
void MapView2D::keyPressEvent(QKeyEvent *e) {
tools.keyPressEvent(this, e);
update();
}
void MapView2D::wheelEvent(QWheelEvent* e) {
tools.wheelEvent(this, e);
update();
}
void MapView2D::mousePressEvent(QMouseEvent* e) {
tools.mousePressEvent(this, e);
update();
}
void MapView2D::mouseMoveEvent(QMouseEvent* e) {
tools.mouseMoveEvent(this, e);
update();
}
void MapView2D::mouseReleaseEvent(QMouseEvent* e) {
tools.mouseReleaseEvent(this, e);
update();
}