78 lines
1.6 KiB
C++
78 lines
1.6 KiB
C++
/*
|
||
* © 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
|