#pragma once #include "mappresent_global.h" #include /// /// 绘制索引 /// struct PresentIndex { /// /// 行号 /// int row = 0; /// /// 列号 /// int col = 0; PresentIndex& operator+=(const PresentIndex& other); bool operator!=(const PresentIndex& other) const; }; /// /// 绘制选项 /// struct PresentOption { /// /// 当前所绘制索引 /// PresentIndex selfIndex; /// /// 当前绘制外缘 /// QRectF selfOutline; bool isMouseOver = false; bool isSelected = false; }; /// /// 单元绘制委托 /// class UnitPresentDelegate { public: virtual ~UnitPresentDelegate() = default; /// /// 匹配单元类型 /// /// virtual int unitType() const = 0; /// /// 绘制本单元瓦片 /// /// /// virtual void paint(QPainter* p, const PresentOption& option) = 0; }; class BasicUnitDelegate : public UnitPresentDelegate { public: int unitType() const override; void paint(QPainter* p, const PresentOption& option) override; QList endPointsGet(const QRectF &rect); }; /// /// 基础地图绘制 /// class MAPPRESENT_EXPORT MapPresent : public QWidget { Q_OBJECT private: /// /// 初级区域矩形变长 /// const float _primitive_region_square_len = 100; /// /// 缩放倍数 /// short _scale_times = 1; /// /// 当前瓦片地图中心索引 /// PresentIndex _center_index; public: MapPresent(QWidget* parent = nullptr); /// /// 通过widget上定位获取绘制索引 /// /// /// PresentIndex indexGet(const QPointF& pos) const; /// /// 通过绘制索引获取指定单元外接矩形 /// /// /// QRectF outlineGet(const PresentIndex& idx) const; protected: void paintEvent(QPaintEvent* ev) override; private: QList siblingsGet(const PresentIndex ¢er, uint16_t dist=1) const; QList itemFills(const PresentIndex &a, const PresentIndex &b) const; };