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