major api and quality of life changes
This commit is contained in:
parent
4148d42bfb
commit
67e63561c4
7 changed files with 113 additions and 24 deletions
|
|
@ -1,12 +1,7 @@
|
||||||
#include "gridpreview.h"
|
#include "gridpreview.h"
|
||||||
|
|
||||||
GridPreview::GridPreview(QWidget *parent)
|
GridPreview::GridPreview(QWidget *parent)
|
||||||
: QWidget{parent}
|
: QWidget{parent} {}
|
||||||
{
|
|
||||||
colorMap.insert(QString("red"), Qt::red);
|
|
||||||
colorMap.insert(QString("green"), Qt::green);
|
|
||||||
colorMap.insert(QString("blue"), Qt::blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GridPreview::setSize(int newWidth, int newHeight)
|
void GridPreview::setSize(int newWidth, int newHeight)
|
||||||
{
|
{
|
||||||
|
|
@ -30,27 +25,32 @@ void GridPreview::removeLine(int index)
|
||||||
emit updatedContents();
|
emit updatedContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridPreview::setLineColor(int index, QString color)
|
void GridPreview::setLineColor(int index, const QString &color)
|
||||||
{
|
{
|
||||||
lines[index].setColor(color);
|
lines[index].setColor(color);
|
||||||
|
|
||||||
emit updatedContents();
|
emit updatedContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridPreview::setLineStartPoint(int index, QPoint point)
|
void GridPreview::setLineStartPoint(int index, const QPoint &point)
|
||||||
{
|
{
|
||||||
lines[index].setStartPoint(point);
|
lines[index].setStartPoint(point);
|
||||||
|
|
||||||
emit updatedContents();
|
emit updatedContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridPreview::setLineEndPoint(int index, QPoint point)
|
void GridPreview::setLineEndPoint(int index, const QPoint &point)
|
||||||
{
|
{
|
||||||
lines[index].setEndPoint(point);
|
lines[index].setEndPoint(point);
|
||||||
|
|
||||||
emit updatedContents();
|
emit updatedContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridPreview::setColorMap(QMap<QString, QColor> &map)
|
||||||
|
{
|
||||||
|
colorMap = map;
|
||||||
|
}
|
||||||
|
|
||||||
int GridPreview::getWidth()
|
int GridPreview::getWidth()
|
||||||
{
|
{
|
||||||
return width;
|
return width;
|
||||||
|
|
@ -61,12 +61,22 @@ int GridPreview::getHeight()
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Line &GridPreview::getLine(int index)
|
const QList<Line> &GridPreview::getLines() const
|
||||||
|
{
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Line &GridPreview::getLine(int index) const
|
||||||
{
|
{
|
||||||
return lines.at(index);
|
return lines.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PointProbe &GridPreview::getCapturedProbe()
|
const PointProbe &GridPreview::getCapturedProbe() const
|
||||||
|
{
|
||||||
|
return capturedProbe;
|
||||||
|
}
|
||||||
|
|
||||||
|
PointProbe &GridPreview::getCapturedProbe()
|
||||||
{
|
{
|
||||||
return capturedProbe;
|
return capturedProbe;
|
||||||
}
|
}
|
||||||
|
|
@ -199,11 +209,15 @@ void GridPreview::mousePressEvent(QMouseEvent *event)
|
||||||
|
|
||||||
capturedProbe.ownerIndex = lines.size() - 1;
|
capturedProbe.ownerIndex = lines.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emit updatedContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridPreview::mouseReleaseEvent(QMouseEvent *event)
|
void GridPreview::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
mouseCaptured = false;
|
mouseCaptured = false;
|
||||||
|
QPoint gridPos = localMousePosition(event);
|
||||||
|
PointProbe probe = probePoint(gridPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QPoint GridPreview::localMousePosition(QMouseEvent *event)
|
const QPoint GridPreview::localMousePosition(QMouseEvent *event)
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ struct PointProbe
|
||||||
class GridPreview : public QWidget
|
class GridPreview : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
QMap<QString, QColor> colorMap;
|
||||||
int width = 5, height = 5;
|
int width = 5, height = 5;
|
||||||
QVector<Line> lines {};
|
QVector<Line> lines {};
|
||||||
QMap<QString, QColor> colorMap;
|
|
||||||
const QString tableTemplate = "return {\n width = %1,\n height = %2,\n lines = {\n%3\n }\n}";
|
const QString tableTemplate = "return {\n width = %1,\n height = %2,\n lines = {\n%3\n }\n}";
|
||||||
|
|
||||||
bool mouseCaptured = false;
|
bool mouseCaptured = false;
|
||||||
|
|
@ -38,14 +38,17 @@ public:
|
||||||
void addLine(Line &line);
|
void addLine(Line &line);
|
||||||
void removeLine(int index);
|
void removeLine(int index);
|
||||||
|
|
||||||
void setLineColor(int index, QString color);
|
void setLineColor(int index, const QString &color);
|
||||||
void setLineStartPoint(int index, QPoint point);
|
void setLineStartPoint(int index, const QPoint &point);
|
||||||
void setLineEndPoint(int index, QPoint point);
|
void setLineEndPoint(int index, const QPoint &point);
|
||||||
|
void setColorMap(QMap<QString, QColor> &map);
|
||||||
|
|
||||||
int getWidth();
|
int getWidth();
|
||||||
int getHeight();
|
int getHeight();
|
||||||
const Line& getLine(int index);
|
const Line& getLine(int index) const;
|
||||||
const PointProbe& getCapturedProbe();
|
const PointProbe& getCapturedProbe() const;
|
||||||
|
PointProbe& getCapturedProbe();
|
||||||
|
const QList<Line>& getLines() const;
|
||||||
|
|
||||||
const QString toLuaTable();
|
const QString toLuaTable();
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
|
|
|
||||||
4
line.cpp
4
line.cpp
|
|
@ -17,12 +17,12 @@ void Line::setColor(QString newColor)
|
||||||
color = newColor;
|
color = newColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QPoint &Line::getStart()
|
const QPoint &Line::getStart() const
|
||||||
{
|
{
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QPoint &Line::getEnd()
|
const QPoint &Line::getEnd() const
|
||||||
{
|
{
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
line.h
4
line.h
|
|
@ -14,8 +14,8 @@ public:
|
||||||
void setStartPoint(QPoint newPoint);
|
void setStartPoint(QPoint newPoint);
|
||||||
void setEndPoint(QPoint newPoint);
|
void setEndPoint(QPoint newPoint);
|
||||||
void setColor(QString color);
|
void setColor(QString color);
|
||||||
const QPoint& getStart();
|
const QPoint& getStart() const;
|
||||||
const QPoint& getEnd();
|
const QPoint& getEnd() const;
|
||||||
QString getColor();
|
QString getColor();
|
||||||
QString toLuaTable();
|
QString toLuaTable();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,14 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
QObject::connect(ui->gridPreview, &GridPreview::updatedContents,
|
QObject::connect(ui->gridPreview, &GridPreview::updatedContents,
|
||||||
this, &MainWindow::onGridUpdated);
|
this, &MainWindow::onGridUpdated);
|
||||||
ui->gridPreview->updatedContents();
|
colorMap.insert(QString("red"), Qt::red);
|
||||||
|
colorMap.insert(QString("green"), Qt::green);
|
||||||
|
colorMap.insert(QString("blue"), Qt::blue);
|
||||||
|
|
||||||
|
ui->gridPreview->setColorMap(colorMap);
|
||||||
|
emit ui->gridPreview->updatedContents();
|
||||||
|
|
||||||
|
ui->comboLineColor->addItems(colorMap.keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
@ -24,6 +31,15 @@ void MainWindow::onGridUpdated()
|
||||||
|
|
||||||
ui->spinGridWidth->setValue(ui->gridPreview->getWidth());
|
ui->spinGridWidth->setValue(ui->gridPreview->getWidth());
|
||||||
ui->spinGridHeight->setValue(ui->gridPreview->getHeight());
|
ui->spinGridHeight->setValue(ui->gridPreview->getHeight());
|
||||||
|
|
||||||
|
ui->listLines->clear();
|
||||||
|
|
||||||
|
for (int i = 0; i< ui->gridPreview->getLines().size(); i++)
|
||||||
|
ui->listLines->addItem(QString("Line #%1").arg(i + 1));
|
||||||
|
|
||||||
|
PointProbe pp = ui->gridPreview->getCapturedProbe();
|
||||||
|
|
||||||
|
ui->listLines->setCurrentRow(pp.ownerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_spinGridWidth_valueChanged(int arg1)
|
void MainWindow::on_spinGridWidth_valueChanged(int arg1)
|
||||||
|
|
@ -37,3 +53,40 @@ void MainWindow::on_spinGridHeight_valueChanged(int arg1)
|
||||||
ui->gridPreview->setSize(ui->gridPreview->getWidth(), arg1);
|
ui->gridPreview->setSize(ui->gridPreview->getWidth(), arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_comboLineColor_currentTextChanged(const QString&)
|
||||||
|
{
|
||||||
|
int selected = ui->listLines->currentRow();
|
||||||
|
|
||||||
|
if (!isSelectedLineCorrect(selected))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ui->gridPreview->setLineColor(selected, ui->comboLineColor->currentText());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_listLines_currentRowChanged(int currentRow)
|
||||||
|
{
|
||||||
|
if (!isSelectedLineCorrect(currentRow))
|
||||||
|
return;
|
||||||
|
|
||||||
|
PointProbe &probe = ui->gridPreview->getCapturedProbe();
|
||||||
|
|
||||||
|
probe.ownerIndex = currentRow;
|
||||||
|
|
||||||
|
Line line = ui->gridPreview->getLine(currentRow);
|
||||||
|
|
||||||
|
int startX = line.getStart().x(), startY = line.getStart().y(),
|
||||||
|
endX = line.getEnd().x(), endY = line.getEnd().y();
|
||||||
|
ui->spinLineStartPointX->setValue(startX);
|
||||||
|
ui->spinLineStartPointY->setValue(startY);
|
||||||
|
ui->spinLineEndPointX->setValue(endX);
|
||||||
|
ui->spinLineEndPointY->setValue(endY);
|
||||||
|
ui->comboLineColor->setCurrentIndex(ui->comboLineColor->findText(line.getColor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::isSelectedLineCorrect(int line)
|
||||||
|
{
|
||||||
|
int size = ui->gridPreview->getLines().size();
|
||||||
|
return line >= 0 && line < size && size > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ class MainWindow : public QMainWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
QMap<QString, QColor> colorMap;
|
||||||
|
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
|
@ -22,10 +24,15 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_spinGridWidth_valueChanged(int arg1);
|
void on_spinGridWidth_valueChanged(int arg1);
|
||||||
|
|
||||||
void on_spinGridHeight_valueChanged(int arg1);
|
void on_spinGridHeight_valueChanged(int arg1);
|
||||||
|
|
||||||
|
void on_comboLineColor_currentTextChanged(const QString &arg1);
|
||||||
|
void on_listLines_currentRowChanged(int currentRow);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
int lastEditedLine = -1;
|
||||||
|
|
||||||
|
bool isSelectedLineCorrect(int line);
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,9 @@
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="5" column="1">
|
<item row="5" column="1">
|
||||||
<widget class="QSpinBox" name="spinLineEndPointX">
|
<widget class="QSpinBox" name="spinLineEndPointX">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -210,6 +213,9 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="5" column="3">
|
<item row="5" column="3">
|
||||||
<widget class="QSpinBox" name="spinLineEndPointY">
|
<widget class="QSpinBox" name="spinLineEndPointY">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -220,6 +226,9 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="3">
|
<item row="4" column="3">
|
||||||
<widget class="QSpinBox" name="spinLineStartPointY">
|
<widget class="QSpinBox" name="spinLineStartPointY">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -324,6 +333,9 @@
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QSpinBox" name="spinLineStartPointX">
|
<widget class="QSpinBox" name="spinLineStartPointX">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -390,7 +402,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="listLines">
|
<widget class="QListWidget" name="listLines">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue