124 lines
2.6 KiB
C++
124 lines
2.6 KiB
C++
#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 {
|
|
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 {
|
|
(void) m;
|
|
if (e->button() == Qt::MouseButton::LeftButton) {
|
|
leftMouse();
|
|
return true;
|
|
} else if (e->button() == Qt::MouseButton::RightButton) {
|
|
rightMouse();
|
|
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() = 0;
|
|
|
|
/** right mouse: usually: done */
|
|
virtual void rightMouse() = 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;}
|
|
mmEL->getMV2D()->unfocus();
|
|
mmEL = nullptr;
|
|
}
|
|
|
|
/** finish creating new elements */
|
|
void disableMe() {
|
|
//finalizeCurrent();
|
|
deleteCurrent();
|
|
delete this; // see dtor!
|
|
}
|
|
|
|
};
|
|
|
|
#endif // TOOLNEWELEMENT_H
|