2017-06-29 16:28:26 +02:00
|
|
|
#include "arrowitem.hpp"
|
|
|
|
#include <QtMath>
|
|
|
|
#include <settings.hpp>
|
|
|
|
|
2017-07-08 21:40:09 +02:00
|
|
|
void ArrowItem::mouseDragEvent(QGraphicsSceneMouseEvent *, CropScene *scene) {
|
2017-06-29 16:28:26 +02:00
|
|
|
if (init.isNull()) {
|
2017-07-08 21:40:09 +02:00
|
|
|
init = scene->cursorPosition();
|
2017-06-29 16:28:26 +02:00
|
|
|
line = scene->addLine(QLineF(init, init), scene->pen());
|
|
|
|
QPainterPath poly;
|
|
|
|
qreal w = settings::settings().value("arrow/width", 20).toDouble() / 2;
|
|
|
|
qreal h = settings::settings().value("arrow/height", 10).toDouble();
|
|
|
|
poly.lineTo(QPoint(-w, h));
|
|
|
|
poly.lineTo(QPoint(0, 0));
|
|
|
|
poly.lineTo(QPoint(w, h));
|
|
|
|
head = scene->addPath(poly, scene->pen(), scene->brush());
|
|
|
|
} else {
|
2017-07-08 21:40:09 +02:00
|
|
|
line->setLine(QLineF(init, scene->cursorPosition()));
|
|
|
|
head->setRotation(
|
|
|
|
270 + qRadiansToDegrees(qAtan2((init.y() - scene->cursorPosition().y()), (init.x() - scene->cursorPosition().x()))));
|
2017-06-29 16:28:26 +02:00
|
|
|
}
|
2017-07-08 21:40:09 +02:00
|
|
|
head->setPos(scene->cursorPosition());
|
2017-06-29 16:28:26 +02:00
|
|
|
}
|