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/MV2DElement.h
kazu 5d002c3f2b added more cpp files for faster compile speeds
removed many obsolte elements
many improvements and fixes
2018-07-20 15:00:43 +02:00

92 lines
1.9 KiB
C++

#ifndef MV2DELEMENT_H
#define MV2DELEMENT_H
#include <QKeyEvent>
#include "../2D/MapView2D.h"
#include "../2D/Painter.h"
#include <Indoor/geo/BBox2.h>
#include <Indoor/geo/Line2.h>
#include "ClickDist.h"
#include "HasMoveableNodes.h"
/**
* represents one drawable, selectable, editable, ...
* element shown within the MapView2D
*/
class MV2DElement {
private:
bool _focused = false;
public:
/** dtor */
virtual ~MV2DElement() {;}
/** get the element's 2D bounding box */
virtual BBox2 getBoundingBox() const = 0;
/** get the element's minimal distance (nearest whatsoever) to the given point */
virtual ClickDist getMinDistanceXY(const Point2 p) const = 0;
/** repaint me */
virtual void paint(Painter& p) = 0;
/** repaint me, 2nd layer (e.g. moveable nodes) */
virtual void paintAfter(Painter& p) {
// HasMoveableNodes? -> paint them here
HasMoveableNodes* e = dynamic_cast<HasMoveableNodes*>(this);
if (e) {
for (const MoveableNode& n : e->getMoveableNodes()) {
const bool sel = e->getSelectedNode() == n.userIdx; // node is selected
const bool foc = hasFocus(); // element (with nodes) currently focused
p.drawNode(n.pos, foc, sel);
}
}
}
/** got focus */
void focus() {
_focused = true;
onFocus();
}
/** lost focus */
void unfocus() {
_focused = false;
onUnfocus();
}
bool hasFocus() {return _focused;}
/** mouse pressed at the given point */
virtual void mousePressed(MapView2D* v, const Point2 p) {(void) v; (void) p;}
/** mouse moved to the given point */
virtual void mouseMove(MapView2D* v, const Point2 p) {(void) v; (void) p;}
/** mouse released */
virtual void mouseReleased(MapView2D* v, const Point2 p) {(void) v; (void) p;}
/** key pressed. NOTE: return true when consumed. */
virtual bool keyPressEvent(MapView2D* v, QKeyEvent* e) {(void) v; (void) e; return false;}
protected:
virtual void onFocus() = 0;
virtual void onUnfocus() = 0;
};
#endif // MV2DELEMENT_H