2017-05-05 23:59:39 +02:00
|
|
|
#include "textitem.hpp"
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QtMath>
|
|
|
|
|
2017-06-29 19:09:39 +02:00
|
|
|
bool TextItem::init(CropScene *s) {
|
2017-05-09 17:26:00 +02:00
|
|
|
bool ok;
|
2017-06-29 19:09:39 +02:00
|
|
|
s->hide();
|
2017-05-09 17:26:00 +02:00
|
|
|
text = QInputDialog::getText(nullptr, "Text to add", "Input", QLineEdit::Normal, QString(), &ok);
|
2017-06-29 19:09:39 +02:00
|
|
|
s->show();
|
2017-05-09 17:26:00 +02:00
|
|
|
return ok;
|
2017-05-05 23:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
|
2017-05-09 17:26:00 +02:00
|
|
|
if (!textItem) {
|
|
|
|
textItem = scene->addSimpleText(text, scene->font());
|
|
|
|
textItem->setPos(e->scenePos());
|
2017-06-26 15:43:12 +02:00
|
|
|
textItem->setPen(scene->pen().color());
|
|
|
|
textItem->setBrush(scene->pen().color());
|
2017-05-09 17:26:00 +02:00
|
|
|
} else {
|
2017-06-14 23:34:58 +02:00
|
|
|
auto ee
|
|
|
|
= 180 + qRadiansToDegrees(qAtan2((textItem->pos().y() - e->scenePos().y()), (textItem->pos().x() - e->scenePos().x())));
|
2017-05-09 17:26:00 +02:00
|
|
|
textItem->setRotation(ee);
|
|
|
|
}
|
2017-05-05 23:59:39 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
void TextItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
|
|
|
|
}
|
2017-05-05 23:59:39 +02:00
|
|
|
|
2017-05-09 17:26:00 +02:00
|
|
|
QString TextItem::name() {
|
|
|
|
return "Text";
|
|
|
|
}
|