#ifndef GRIDPREVIEW_H #define GRIDPREVIEW_H #include #include #include #include #include "line.h" struct PointProbe { int ownerIndex = -1; bool isStart = true; bool inBounds = true; PointProbe() {} PointProbe(int owner, bool start = true, bool bounds = true): ownerIndex(owner), isStart(start), inBounds(bounds) {} }; class GridPreview : public QWidget { Q_OBJECT QMap colorMap; int width = 5, height = 5; QVector lines {}; const QString tableTemplate = "return {\n width = %1,\n height = %2,\n lines = {\n%3\n }\n}"; bool mouseCaptured = false; PointProbe capturedProbe, lastProbe; public: explicit GridPreview(QWidget *parent = nullptr); void setSize(int newWidth, int newHeight); void addLine(Line &line); void removeLine(int index); void setLineColor(int index, const QString &color); void setLineStartPoint(int index, const QPoint &point); void setLineEndPoint(int index, const QPoint &point); void setColorMap(QMap &map); int getWidth(); int getHeight(); const Line& getLine(int index) const; const PointProbe& getCapturedProbe() const; PointProbe& getCapturedProbe(); const QList& getLines() const; const QString toLuaTable(); void paintEvent(QPaintEvent* event); const QColor colorFromString(const QString color); void mouseMoveEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); const QPoint localMousePosition(QMouseEvent* event); const QPoint snapToGrid(const QPoint& global); bool isPointOccupied(const QPoint& point); bool pointInBounds(const QPoint& point); bool pointIsFree(PointProbe &pp); int getPointOwner(const QPoint& point); const PointProbe probePoint(const QPoint& point); signals: void updatedContents(); }; #endif // GRIDPREVIEW_H