Commit b8d0c44e authored by ucart's avatar ucart

draws actual path also and compiles list of flight points

parent 075bc1b1
......@@ -4,6 +4,8 @@
#include <QImage>
#include <QMouseEvent>
#include <QDesktopWidget>
#include <math.h>
#include <QDebug>
DrawingPad::DrawingPad(QWidget *parent) :
QWidget(parent),
......@@ -35,6 +37,8 @@ void DrawingPad::mousePressEvent(QMouseEvent *e)
{
enabled = true;
begin = e->pos();
rBegin = mapToGrid(begin);
addToFlightPath(rBegin);
e->accept();
}
......@@ -46,18 +50,28 @@ void DrawingPad::mouseMoveEvent(QMouseEvent *e)
}
if(!isNewLine) {
begin = end;
rBegin = rEnd;
} else {
isNewLine = false;
}
end = e->pos();
rEnd = mapToGrid(end);
addToFlightPath(rEnd);
QPen pen(Qt::black);
pen.setCapStyle(Qt::RoundCap);
pen.setWidth(7);
QPen penRed(Qt::red);
penRed.setCapStyle(Qt::RoundCap);
penRed.setWidth(7);
painter->setPen(pen);
painter->drawLine(begin, end);
painter->setPen(penRed);
painter->drawLine(rBegin, rEnd);
update();
e->accept();
}
......@@ -68,13 +82,35 @@ void DrawingPad::mouseReleaseEvent(QMouseEvent *e)
e->accept();
}
void DrawingPad::on_pushButton_released()
void DrawingPad::on_clearButton_released()
{
flightPath.clear();
QPainter painter(this);
image->fill(Qt::white);
painter.fillRect(image->rect(), Qt::white);
painter.drawImage(0, 0, *image);
isNewLine = true;
update();
}
void DrawingPad::on_sendButton_released()
{
}
QPoint DrawingPad::mapToGrid(QPoint p) {
int x = round(p.x() * (24) / (800)) * 800 / 24;
int y = round(p.y() * (20) / (500)) * 500 / 20;
return QPoint(x, y);
}
int DrawingPad::round(double d)
{
return floor(d + 0.5);
}
void DrawingPad::addToFlightPath(QPoint p) {
if(flightPath.last() != p) {
flightPath.append(p);
}
}
......@@ -21,7 +21,14 @@ private slots:
void mouseMoveEvent(QMouseEvent *e) override;
void mouseReleaseEvent(QMouseEvent *e) override;
void on_pushButton_released();
void on_clearButton_released();
void on_sendButton_released();
QPoint mapToGrid(QPoint p);
int round(double d);
void addToFlightPath(QPoint p);
private:
Ui::DrawingPad *ui;
......@@ -31,6 +38,9 @@ private:
QPoint end;
bool isNewLine;
bool enabled;
QPoint rBegin;
QPoint rEnd;
QList<QPoint> flightPath;
};
#endif // DRAWINGPAD_H
......
......@@ -6,17 +6,35 @@
<rect>
<x>0</x>
<y>0</y>
<width>831</width>
<height>535</height>
<width>800</width>
<height>500</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>800</width>
<height>500</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>500</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="clearButton">
<property name="geometry">
<rect>
<x>730</x>
<x>700</x>
<y>10</y>
<width>92</width>
<height>36</height>
......@@ -26,6 +44,25 @@
<string>Clear</string>
</property>
</widget>
<widget class="QPushButton" name="sendButton">
<property name="geometry">
<rect>
<x>700</x>
<y>50</y>
<width>92</width>
<height>36</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Send</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment