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

164 lines
4.2 KiB
C++
Raw Permalink 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 TOOLS_H
#define TOOLS_H
#include <vector>
#include "../../../fixC11.h"
#include "Tool.h"
class QPinchGesture;
/**
* combine several tools under the interface for one tool
*/
class Tools : public QObject { //public Tool {
Q_OBJECT
private:
/** all added tools */
std::vector<Tool*> backgroundTools;
Tool* mainTool = nullptr;
/** the main tool to use whenever other tools are done: usually the select tool */
Tool* defaultMainTool = nullptr;
signals:
void mainToolChanged();
void onHelpTextChange(QString str);
public:
Tools() {
;
}
virtual ~Tools() {
;
}
const std::string getName() const {//override {
return (mainTool) ? (mainTool->getName()) : ("");
}
/** add a new background-helper-tool (ruler, grid, ..) those are always processed! */
void addBackground(Tool* t) {
backgroundTools.push_back(t);
}
/** remove this tool */
void removeBackground(Tool* t) {
backgroundTools.erase(std::remove(backgroundTools.begin(), backgroundTools.end(), t));
}
/** set the currently active main tool. there is only one that can be active! (e.g. selector, new wall, new polygon, ..) */
void setMain(Tool* t) {
if (this->mainTool) {
this->mainTool->becomesInactive();
disconnect(this->mainTool, &Tool::onHelpTextChange, this, &Tools::onHelpTextChange);
}
this->mainTool = t;
emit mainToolChanged();
if (this->mainTool) {
connect(this->mainTool, &Tool::onHelpTextChange, this, &Tools::onHelpTextChange);
this->mainTool->becomesActive();
}
}
/** set the currently active main tool back to the default */
void setMainDefault() {
setMain(defaultMainTool);
}
/** get the current main tool */
Tool* getMain() {
return this->mainTool;
}
/** set the default main tool to use whenever other tools are done */
void setDefaultMainTool(Tool* t) {
this->defaultMainTool = t;
}
virtual bool mousePressEvent(MapView2D* m, QMouseEvent* e) {//override {
if (mainTool) {mainTool->mousePressEvent(m, e);}
for (Tool* t : backgroundTools) { if(t->mousePressEvent(m, e)) {return true;} }
return false;
}
virtual bool mouseMoveEvent(MapView2D* m, QMouseEvent* e) {//override {
if (mainTool) {mainTool->mouseMoveEvent(m, e);}
for (Tool* t : backgroundTools) { if(t->mouseMoveEvent(m, e)) {return true;} }
return false;
}
virtual bool mouseReleaseEvent(MapView2D* m, QMouseEvent* e) {//override {
if (mainTool) {mainTool->mouseReleaseEvent(m, e);}
for (Tool* t : backgroundTools) { if(t->mouseReleaseEvent(m, e)) {return true;} }
return false;
}
virtual bool wheelEvent(MapView2D* m, QWheelEvent* e) {//override {
if (mainTool) {mainTool->wheelEvent(m, e);}
for (Tool* t : backgroundTools) { if(t->wheelEvent(m, e)) {return true;} }
return false;
}
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) {//override {
if (mainTool) {mainTool->keyPressEvent(m, e);}
for (Tool* t : backgroundTools) { if(t->keyPressEvent(m, e)) {return true;} }
return false;
}
virtual bool pinchTriggered(MapView2D* m, QPinchGesture* g) {//override {
if (mainTool) {mainTool->pinchTriggered(m, g);}
for (Tool* t : backgroundTools) { if(t->pinchTriggered(m, g)) {return true;} }
return false;
}
virtual bool panTriggered(MapView2D* m, QPanGesture* g) {//override {
if (mainTool) {mainTool->panTriggered(m, g);}
for (Tool* t : backgroundTools) { if(t->panTriggered(m, g)) {return true;} }
return false;
}
virtual void paintBefore(MapView2D* m, Painter& p) {//override {
for (Tool* t : backgroundTools) {t->paintBefore(m, p);}
if (mainTool) {mainTool->paintBefore(m, p);}
}
virtual void paintAfter(MapView2D* m, Painter& p) {//override {
for (Tool* t : backgroundTools) {t->paintAfter(m, p);}
if (mainTool) {mainTool->paintAfter(m, p);}
}
virtual void layerChange(MapView2D* m) {//override {
for (Tool* t : backgroundTools) {t->layerChange(m);}
if (mainTool) {mainTool->layerChange(m);}
}
};
#endif // TOOLS_H