71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
#ifndef GRIDPREVIEW_H
|
|
#define GRIDPREVIEW_H
|
|
|
|
#include <QWidget>
|
|
#include <QPainter>
|
|
#include <QMouseEvent>
|
|
#include <iostream>
|
|
#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
|
|
int width = 5, height = 5;
|
|
QVector<Line> lines {};
|
|
QMap<QString, QColor> colorMap;
|
|
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, QString color);
|
|
void setLineStartPoint(int index, QPoint point);
|
|
void setLineEndPoint(int index, QPoint point);
|
|
|
|
int getWidth();
|
|
int getHeight();
|
|
const Line& getLine(int index);
|
|
const PointProbe& getCapturedProbe();
|
|
|
|
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
|