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/ToolMoveMap.h
2018-10-25 12:23:40 +02:00

78 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef TOOLMOVEMAP_H
#define TOOLMOVEMAP_H
#include "Tool.h"
#include "../MapView2D.h"
#include <QPanGesture>
/**
* this tool allows moving the 2D map
* using the mouse
*/
class ToolMoveMap : public Tool {
private:
bool mouseIsDown = false;
Point3 startOffset;
int sx;
int sy;
const std::string getName() const override {
return "MapMove";
}
public:
virtual bool mousePressEvent(MapView2D* m, QMouseEvent* e) override {
if (e->button() == Qt::MouseButton::MidButton) {
mouseIsDown = true;
this->sx = e->x();
this->sy = e->y();
this->startOffset = m->getScaler().getOffset();
return true;
}
return false;
}
virtual bool mouseMoveEvent(MapView2D* m, QMouseEvent* e) override {
if (!mouseIsDown) {return false;}
m->getScaler().setOffset(startOffset);
m->getScaler().addOffset(e->x()-sx, e->y()-sy);
return true;
}
virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) override {
(void) m;
(void) e;
mouseIsDown = false;
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;
// // TODO: move on arrow keys?
// }
};
#endif // TOOLMOVEMAP_H