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
root e5e19779d5 worked on android port
opengl1 -> es
2018-01-31 17:15:11 +01:00

141 lines
3.4 KiB
C++

#ifndef TOOLS_H
#define TOOLS_H
#include <vector>
#include "../../../fixC11.h"
#include "Tool.h"
/**
* 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 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