146 lines
3.2 KiB
C++
146 lines
3.2 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 TOOLNEWELEMENT_H
|
||
#define TOOLNEWELEMENT_H
|
||
|
||
#include "Tool.h"
|
||
#include "Tools.h"
|
||
#include "../../model/MapLayer.h"
|
||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||
|
||
/**
|
||
* this is a helper class
|
||
* for all tools within the toolbox,
|
||
* that create new elements: new door, new wall, ...
|
||
*/
|
||
template <typename FloorplanElement, typename MapModelElement> class ToolNewElement : public Tool {
|
||
|
||
protected:
|
||
|
||
/** add another line after this one? */
|
||
bool addAnother = true;
|
||
|
||
/** register this tool into the given tools-queue */
|
||
Tools& tools;
|
||
|
||
/** the layer to add the new element to */
|
||
MapLayer* layer = nullptr;
|
||
|
||
/** currently edited element */
|
||
FloorplanElement* foEL = nullptr;
|
||
MapModelElement* mmEL = nullptr;
|
||
|
||
public:
|
||
|
||
ToolNewElement(Tools& tools, MapLayer* layer) : tools(tools), layer(layer) {
|
||
|
||
}
|
||
|
||
virtual ~ToolNewElement() {
|
||
tools.setMainDefault();
|
||
}
|
||
|
||
virtual bool mousePressEvent(MapView2D* m, QMouseEvent* e) override {
|
||
if (e->button() == Qt::MouseButton::LeftButton) {
|
||
(void) m; (void) e;
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
virtual bool mouseMoveEvent(MapView2D* m, QMouseEvent* e) override {
|
||
|
||
// get location on screen and within map
|
||
const Point2 onScreen(e->x(), e->y());
|
||
Point2 onMap = m->getScaler().sm(onScreen);
|
||
onMap = m->getScaler().snap(onMap);
|
||
|
||
moving(onMap);
|
||
return true;
|
||
|
||
}
|
||
|
||
virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) override {
|
||
|
||
// get location on screen and within map
|
||
const Point2 onScreen(e->x(), e->y());
|
||
Point2 onMap = m->getScaler().sm(onScreen);
|
||
onMap = m->getScaler().snap(onMap);
|
||
|
||
if (e->button() == Qt::MouseButton::LeftButton) {
|
||
leftMouse(onMap);
|
||
return true;
|
||
} else if (e->button() == Qt::MouseButton::RightButton) {
|
||
rightMouse(onMap);
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
|
||
}
|
||
|
||
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
|
||
(void) m;
|
||
if (e->key() == Qt::Key_Escape) {
|
||
deleteCurrent();
|
||
disableMe();
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
protected:
|
||
|
||
/** all subclasses must create a new, empty element here */
|
||
//virtual void createEmptyElement() = 0;
|
||
|
||
/** mouse is currently moved */
|
||
virtual void moving(const Point2 mapPoint) = 0;
|
||
|
||
/** left mouse: usually: next part */
|
||
virtual void leftMouse(const Point2 mapPoint) = 0;
|
||
|
||
/** right mouse: usually: done */
|
||
virtual void rightMouse(const Point2 mapPoint) = 0;
|
||
|
||
protected:
|
||
|
||
void create() {
|
||
//createEmptyElement();
|
||
//mmEL->getMV2D()->focus();
|
||
}
|
||
|
||
/** delete the currently edited element */
|
||
void deleteCurrent() {
|
||
if (mmEL) {mmEL->deleteMe();}
|
||
}
|
||
|
||
/** finalize the current element (if any) */
|
||
void finalizeCurrent() {
|
||
if (!mmEL) {return;}
|
||
layer->changed(); // update the UI
|
||
mmEL->getMV2D()->unfocus();
|
||
mmEL = nullptr;
|
||
layer->changed(); // update the UI
|
||
}
|
||
|
||
/** finish creating new elements */
|
||
void disableMe() {
|
||
//finalizeCurrent();
|
||
deleteCurrent();
|
||
delete this; // see dtor!
|
||
}
|
||
|
||
};
|
||
|
||
#endif // TOOLNEWELEMENT_H
|