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

102 lines
2.8 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 MV2DELEMENTBEACON_H
#define MV2DELEMENTBEACON_H
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include "../../UIHelper.h"
class MV2DElementBeacon : public MV2DElement, public HasMoveableNodes {
private:
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 */
ClickDist getMinDistanceXY(const Point2 p) const override {
return ClickDist(p.getDistance(b->pos.xy()), ClickDistType::DIRECT);
}
/** repaint me */
void paint(Painter& p) override {
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("beacon", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("beacon", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("beacon", CFG::SEL_COLOR, 16);
if (selectedUserIdx == 0) {
p.drawPixmap(b->pos.xy(), pixmapSel);
} else if (hasFocus()) {
p.drawPixmap(b->pos.xy(), pixmapFocused);
} else {
p.drawPixmap(b->pos.xy(), pixmapUnfocused);
}
// label
//p.setPenBrush(Qt::black, Qt::NoBrush);
//p.drawDot(b->pos.xy());
if (p.getScaler().getScale() >= 25) {
p.setPenBrush(Qt::black, Qt::NoBrush);
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() >= 12) {
p.setPenBrush(Qt::black, Qt::NoBrush);
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 std::vector<MoveableNode> getMoveableNodes() const override {
return { MoveableNode(0, b->pos.xy()) };
}
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) v;
if (userIdx == 0) {b->pos.x = newPos.x; b->pos.y = newPos.y;}
}
void onNodeMoved(MapView2D* v, const int userIdx, const Point2 newPos) override {
(void) userIdx;
(void) newPos;
emit v->onElementChange(this);
}
virtual void onFocus() override {
;
}
virtual void onUnfocus() override {
;
}
};
#endif // MV2DELEMENTBEACON_H