#pragma once #include "mappresent_global.h" #include /// /// 绘制索引 /// struct MAPPRESENT_EXPORT PresentIndex { /// /// 行号 /// int row = INT_MAX; /// /// 列号 /// int col = INT_MAX; bool isValid() const; PresentIndex& operator+=(const PresentIndex& other); bool operator!=(const PresentIndex& other) const; }; /// /// 绘制选项 /// struct PresentOption { /// /// 当前所绘制索引 /// PresentIndex index; /// /// 当前绘制外缘 /// QRectF outline; 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 MAPPRESENT_EXPORT MapPresent : public QWidget { Q_OBJECT private: /// /// 初级区域矩形变长 /// const float _primitive_region_square_len = 100; /// /// 缩放倍数 /// short _scale_times = 1; /// /// 当前瓦片地图中心索引 /// PresentIndex _center_index; // =================================== QList _visible_units; void visibleUnitsTidy(); QList siblingsGet(const PresentIndex& center, uint16_t dist = 1) const; QList itemFills(const PresentIndex& a, const PresentIndex& b) const; public: MapPresent(QWidget* parent = nullptr); /// /// 通过widget上定位获取绘制索引 /// /// /// PresentIndex indexGet(const QPointF& pos) const; /// /// 通过绘制索引获取指定单元外接矩形 /// /// /// QRectF outlineGet(const PresentIndex& idx) const; signals: void mouseEnter(); void mouseOut(); void mouseHover(); protected: void paintEvent(QPaintEvent* ev) override; void resizeEvent(QResizeEvent* event) override; };