changed 3D rendering

added pan/zoom gesture
This commit is contained in:
2018-02-04 17:02:14 +01:00
parent 3b62f23c0e
commit 076c0e9157
32 changed files with 446 additions and 484 deletions

View File

@@ -9,6 +9,8 @@
#include "../Painter.h"
class QPinchGesture;
class QPanGesture;
class MapView2D;
/**
@@ -46,6 +48,9 @@ public:
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) { (void) m; (void) e; return false; }
virtual bool pinchTriggered(MapView2D* m, QPinchGesture* g) { (void) m; (void) g; return false; }
virtual bool panTriggered(MapView2D* m, QPanGesture* g) { (void) m; (void) g; return false; }
virtual void paintBefore(MapView2D* m, Painter& p) { (void) m; (void) p; }
virtual void paintAfter(MapView2D* m, Painter& p) { (void) m; (void) p; }

View File

@@ -9,6 +9,8 @@
*/
class ToolMapZoom : public Tool {
float startScale = NAN;
public:
const std::string getName() const override {
@@ -32,6 +34,34 @@ public:
}
virtual bool pinchTriggered(MapView2D *m, QPinchGesture* g) override {
Scaler& s = m->getScaler();
// https://doc.qt.io/qt-5/qtwidgets-gestures-imagegestures-example.html
QPinchGesture::ChangeFlags changeFlags = g->changeFlags();
if (changeFlags & QPinchGesture::RotationAngleChanged) {
// qreal rotationDelta = gesture->rotationAngle() - gesture->lastRotationAngle();
// rotationAngle += rotationDelta;
// qCDebug(lcExample) << "pinchTriggered(): rotate by" <<
// rotationDelta << "->" << rotationAngle;
}
if (changeFlags & QPinchGesture::ScaleFactorChanged) {
if (startScale != startScale) {startScale = s.getScale();}
s.setScale(startScale * g->totalScaleFactor());
}
if (g->state() == Qt::GestureFinished) {
startScale = NAN;
}
if (s.getScale() > 1000) {s.setScale(1000);}
if (s.getScale() < 5) {s.setScale(5);}
return true;
}
};
#endif // TOOLMAPZOOM_H

View File

@@ -4,6 +4,8 @@
#include "Tool.h"
#include "../MapView2D.h"
#include <QPanGesture>
/**
* this tool allows moving the 2D map
* using the mouse
@@ -48,6 +50,11 @@ public:
return false;
}
virtual bool panTriggered(MapView2D *m, QPanGesture *g) override {
m->getScaler().addOffset(g->delta().x(), g->delta().y());
return true;
}
// virtual void keyPressEvent(MapView2D* m, QKeyEvent* e) override {
// (void) m;
// (void) e;

View File

@@ -67,25 +67,23 @@ public:
// the visible map-rect
const Rect r = p.getScaler().getMapVisible(w, h, step);
QRect rx(rs,0,w-1-rs,rs);
QRect rx(rs,0,w-0-rs,rs);
QRect ry(0,rs,rs,h-1-rs);
// background
{
// samller font
QFont f = p.p->font(); f.setPointSize(8);
p.p->setFont(f);
// outline
p.setPen(Qt::darkGray);
p.setBrush(QColor(240,240,240));
// x-axis
QLinearGradient gx(0,0,0,rs); gx.setColorAt(0, c1); gx.setColorAt(1, c2); p.setBrush(gx);
//QLinearGradient gx(0,0,0,rs); gx.setColorAt(0, c1); gx.setColorAt(1, c2); p.setBrush(gx);
p.p->drawRect(rx);
// y-axis
QLinearGradient gy(0,0,rs,0); gy.setColorAt(0, c2); gy.setColorAt(1, c1); p.setBrush(gy);
//QLinearGradient gy(0,0,rs,0); gy.setColorAt(0, c2); gy.setColorAt(1, c1); p.setBrush(gy);
p.p->drawRect(ry);
}
@@ -101,6 +99,10 @@ public:
p.setPenBrush(Qt::black, Qt::NoBrush);
char buf[128];
// samller font
QFont f = p.p->font(); f.setPointSize(8);
p.p->setFont(f);
// coordinates
QRect ru(0,0,rs-1,rs-1);
p.p->fillRect(ru, Qt::white);

View File

@@ -5,6 +5,8 @@
#include "../../../fixC11.h"
#include "Tool.h"
class QPinchGesture;
/**
* combine several tools under the interface for one tool
*/
@@ -118,6 +120,17 @@ public:
return false;
}
virtual bool pinchTriggered(MapView2D* m, QPinchGesture* g) {//override {
if (mainTool) {mainTool->pinchTriggered(m, g);}
for (Tool* t : backgroundTools) { if(t->pinchTriggered(m, g)) {return true;} }
return false;
}
virtual bool panTriggered(MapView2D* m, QPanGesture* g) {//override {
if (mainTool) {mainTool->panTriggered(m, g);}
for (Tool* t : backgroundTools) { if(t->panTriggered(m, g)) {return true;} }
return false;
}
virtual void paintBefore(MapView2D* m, Painter& p) {//override {
for (Tool* t : backgroundTools) {t->paintBefore(m, p);}