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/elements/MV2DElementBeacon.h
2016-06-06 22:08:53 +02:00

100 lines
2.2 KiB
C++

#ifndef MV2DELEMENTBEACON_H
#define MV2DELEMENTBEACON_H
#include "MV2DElement.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
class MV2DElementBeacon : public MV2DElement {
private:
bool sel = false;
Floorplan::Beacon* b;
public:
/** ctor with the Beacon to render/edit */
MV2DElementBeacon(Floorplan::Beacon* b) : b(b) {;}
/** get the element's 3D bounding box */
BBox2 getBoundingBox() const override {
BBox2 bbox;
bbox.add(Point2(b->pos.x, b->pos.y));
bbox.grow(Point2(0.1, 0.1));
return bbox;
}
/** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override {
return p.getDistance(b->pos.xy());
}
/** repaint me */
void paint(Painter& p) override {
if (sel) {
p.setPenBrush(Qt::black, CFG::SEL_COLOR);
p.drawCircle(b->pos.xy());
} else if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(b->pos.xy());
} else {
p.setPenBrush(Qt::gray, Qt::NoBrush);
p.drawCircle(b->pos.xy());
}
// label
p.setPenBrush(Qt::black, Qt::NoBrush);
if (p.getScaler().getScale() >= 25) {
const std::string str = b->name + " (" + b->mac + ")";
p.p->drawText(p.getScaler().xms(b->pos.x) + 10, p.getScaler().yms(b->pos.y) + 5, str.c_str());
} else if (p.getScaler().getScale() >= 10) {
const std::string str = b->name;
p.p->drawText(p.getScaler().xms(b->pos.x) + 10, p.getScaler().yms(b->pos.y) + 5, str.c_str());
}
}
virtual void onFocus() override {
;
}
virtual void onUnfocus() override {
sel = false;
}
/** mouse pressed at the given point */
virtual void mousePressed(MapView2D* v, const Point2 p) override {
(void) v;
(void) p;
}
/** mouse moved to the given point */
virtual void mouseMove(MapView2D* v, const Point2 _p) override {
(void) v;
if (sel) {
const Point2 p = Scaler::snap(_p, CFG::MOVE_SNAP_SIZE_M);
b->pos.x = p.x;
b->pos.y = p.y;
}
}
/** mouse released */
virtual void mouseReleased(MapView2D* v, const Point2 p) override {
(void) v;
(void) p;
sel = true;
}
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
(void) v;
(void) e;
return false;
}
};
#endif // MV2DELEMENTBEACON_H