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

102 lines
2.3 KiB
C++
Raw 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 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