51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#ifndef GRIDPREVIEW_H
|
|
#define GRIDPREVIEW_H
|
|
|
|
#include <QWidget>
|
|
#include <QPainter>
|
|
#include <QMouseEvent>
|
|
#include <iostream>
|
|
#include "line.h"
|
|
|
|
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;
|
|
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 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);
|
|
|
|
double isPointOccupied(const QPoint& point);
|
|
double pointInBounds(const QPoint& point);
|
|
signals:
|
|
void updatedContents();
|
|
};
|
|
|
|
#endif // GRIDPREVIEW_H
|