File indexing completed on 2024-11-24 04:15:38

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KOSMINDOORMAP_HITDETECTOR_H
0008 #define KOSMINDOORMAP_HITDETECTOR_H
0009 
0010 #include "kosmindoormap_export.h"
0011 
0012 #include <vector>
0013 
0014 class QPointF;
0015 
0016 namespace KOSMIndoorMap {
0017 
0018 class LabelItem;
0019 class MultiPolygonItem;
0020 class PolygonItem;
0021 class PolylineItem;
0022 class SceneGraph;
0023 class SceneGraphItem;
0024 class View;
0025 
0026 /** Picking hit detector.
0027  *  Ie. find scene graph items at a given screen position.
0028  */
0029 class KOSMINDOORMAP_EXPORT HitDetector
0030 {
0031 public:
0032     /** Highest (in z-order) item at the given screen position. */
0033     const SceneGraphItem* itemAt(QPointF pos, const SceneGraph &sg, const View *view) const;
0034 
0035     /** All items (in z-order) at the given screen position. */
0036     std::vector<const SceneGraphItem*> itemsAt(QPointF pos, const SceneGraph &sg, const View *view) const;
0037 
0038 private:
0039     /** Precise bounds check for @p item. */
0040     bool itemContainsPoint(const SceneGraphItem &item, QPointF screenPos, const View *view) const;
0041     bool itemContainsPoint(const MultiPolygonItem *item, QPointF scenePos) const;
0042     bool itemContainsPoint(const PolygonItem *item, QPointF scenePos) const;
0043     bool itemContainsPoint(const PolylineItem *item, QPointF scenePos, const View *view) const;
0044     bool itemContainsPoint(const LabelItem *item, QPointF screenPos, const View *view) const;
0045 
0046     float itemFillAlpha(const SceneGraphItem *item) const;
0047 };
0048 
0049 }
0050 
0051 #endif // KOSMINDOORMAP_HITDETECTOR_H