130 lines
3.0 KiB
C++
130 lines
3.0 KiB
C++
#ifndef MV2DELEMENTPOI_H
|
|
#define MV2DELEMENTPOI_H
|
|
|
|
#include "MV2DElement.h"
|
|
#include "HasMoveableNodes.h"
|
|
#include "MapViewElementHelper.h"
|
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
|
|
|
#include "../../UIHelper.h"
|
|
|
|
class MV2DElementPOI : public MV2DElement, public HasMoveableNodes {
|
|
|
|
private:
|
|
|
|
//bool sel = false;
|
|
Floorplan::POI* poi;
|
|
|
|
public:
|
|
|
|
/** ctor with the AP to render/edit */
|
|
MV2DElementPOI(Floorplan::POI* poi) : poi(poi) {;}
|
|
|
|
|
|
/** get the element's 3D bounding box */
|
|
BBox2 getBoundingBox() const override {
|
|
BBox2 bbox;
|
|
bbox.add(Point2(poi->pos.x, poi->pos.y));
|
|
bbox.grow(Point2(0.1, 0.1));
|
|
return bbox;
|
|
}
|
|
|
|
/** get the element's minimal distance (nearest whatsoever) to the given point */
|
|
ClickDist getMinDistanceXY(const Point2 p) const override {
|
|
return ClickDist(p.getDistance(poi->pos), ClickDistType::DIRECT);
|
|
}
|
|
|
|
/** repaint me */
|
|
void paint(Painter& p) override {
|
|
|
|
// invisible? -> leave
|
|
if (!p.isVisible(poi->pos)) {
|
|
return;
|
|
}
|
|
|
|
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("poi", CFG::UNFOCUS_COLOR, 16);
|
|
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("poi", CFG::FOCUS_COLOR, 16);
|
|
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("poi", CFG::SEL_COLOR, 16);
|
|
|
|
|
|
if (selectedUserIdx == 0) {
|
|
// p.setPenBrush(Qt::black, CFG::SEL_COLOR);
|
|
// p.drawCircle(poi->pos);
|
|
p.drawPixmap(poi->pos, pixmapSel);
|
|
} else if (hasFocus()) {
|
|
// p.setPenBrush(Qt::black, Qt::NoBrush);
|
|
// p.drawCircle(poi->pos);
|
|
p.drawPixmap(poi->pos, pixmapFocused);
|
|
} else {
|
|
// p.setPenBrush(Qt::gray, Qt::NoBrush);
|
|
// p.drawCircle(poi->pos);
|
|
p.drawPixmap(poi->pos, pixmapUnfocused);
|
|
}
|
|
|
|
// label
|
|
p.setPenBrush(Qt::black, Qt::NoBrush);
|
|
p.drawDot(poi->pos);
|
|
if (p.getScaler().getScale() >= 10) {
|
|
const std::string str = poi->name;
|
|
p.p->drawText(p.getScaler().xms(poi->pos.x) + 10, p.getScaler().yms(poi->pos.y) + 5, str.c_str());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
virtual std::vector<MoveableNode> getMoveableNodes() const override {
|
|
return { MoveableNode(0, poi->pos) };
|
|
}
|
|
|
|
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
|
|
(void) v;
|
|
if (userIdx == 0) {poi->pos = newPos;}
|
|
}
|
|
|
|
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
|
|
(void) userIdx;
|
|
(void) newPos;
|
|
emit v->onElementChange(this);
|
|
}
|
|
|
|
/** 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;
|
|
(void) p;
|
|
// if (sel) {
|
|
// const Point2 p = v->getScaler().snap(_p);
|
|
// poi->pos.x = p.x;
|
|
// poi->pos.y = p.y;
|
|
// }
|
|
}
|
|
|
|
/** mouse released */
|
|
virtual void mouseReleased(MapView2D* v, const Point2 p) override {
|
|
(void) v;
|
|
(void) p;
|
|
}
|
|
|
|
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override {
|
|
(void) v;
|
|
(void) e;
|
|
return false;
|
|
}
|
|
|
|
virtual void onFocus() override {
|
|
;
|
|
}
|
|
|
|
virtual void onUnfocus() override {
|
|
;
|
|
}
|
|
|
|
};
|
|
|
|
#endif // MV2DELEMENTPOI_H
|