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/tools/ToolMapZoom.h
kazu 076c0e9157 changed 3D rendering
added pan/zoom gesture
2018-02-04 17:02:14 +01:00

68 lines
1.5 KiB
C++

#ifndef TOOLMAPZOOM_H
#define TOOLMAPZOOM_H
#include "Tool.h"
#include "../MapView2D.h"
/**
* this tool allows zooming in and out of the map
*/
class ToolMapZoom : public Tool {
float startScale = NAN;
public:
const std::string getName() const override {
return "MapZoom";
}
virtual bool wheelEvent(MapView2D* m, QWheelEvent* e) override {
Scaler& s = m->getScaler();
if (e->delta() < 0) {
s.setScale(s.getScale() * 0.75);
} else {
s.setScale(s.getScale() / 0.75);
}
if (s.getScale() > 1000) {s.setScale(1000);}
if (s.getScale() < 5) {s.setScale(5);}
return true;
}
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