#ifndef MV2DELEMENTACCESSPOINT_H #define MV2DELEMENTACCESSPOINT_H #include "MV2DElement.h" #include "MapViewElementHelper.h" #include class MV2DElementAccessPoint : public MV2DElement { private: bool sel = false; Floorplan::AccessPoint* ap; public: /** ctor with the AP to render/edit */ MV2DElementAccessPoint(Floorplan::AccessPoint* ap) : ap(ap) {;} /** get the element's 3D bounding box */ BBox2 getBoundingBox() const override { BBox2 bbox; bbox.add(Point2(ap->pos.x, ap->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(ap->pos.xy()); } /** repaint me */ void paint(Painter& p) override { if (sel) { p.setPenBrush(Qt::black, CFG::SEL_COLOR); p.drawCircle(ap->pos.xy()); } else if (hasFocus()) { p.setPenBrush(Qt::black, Qt::NoBrush); p.drawCircle(ap->pos.xy()); } else { p.setPenBrush(Qt::gray, Qt::NoBrush); p.drawCircle(ap->pos.xy()); } // label p.setPenBrush(Qt::black, Qt::NoBrush); if (p.getScaler().getScale() >= 25) { const std::string str = ap->name + " (" + ap->name + ")"; p.p->drawText(p.getScaler().xms(ap->pos.x) + 10, p.getScaler().yms(ap->pos.y) + 5, str.c_str()); } else if (p.getScaler().getScale() >= 10) { const std::string str = ap->name; p.p->drawText(p.getScaler().xms(ap->pos.x) + 10, p.getScaler().yms(ap->pos.y) + 5, str.c_str()); } } /** 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); ap->pos.x = p.x; ap->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; } virtual void onFocus() override { } virtual void onUnfocus() override { sel = false; } }; #endif // MV2DELEMENTACCESSPOINT_H