KShare/cropeditor/drawing/textitem.cpp

26 lines
799 B
C++
Raw Normal View History

2017-05-05 23:59:39 +02:00
#include "textitem.hpp"
#include <QInputDialog>
#include <QtMath>
void TextItem::init(CropScene *) {
2017-05-06 13:21:12 +02:00
text = QInputDialog::getText(nullptr, "Text to add", "Input");
2017-05-05 23:59:39 +02:00
}
void TextItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
2017-05-06 13:21:12 +02:00
if (!textItem) {
textItem = scene->addSimpleText(text, scene->font());
textItem->setPos(e->scenePos());
textItem->setPen(scene->pen());
textItem->setBrush(scene->brush());
} else {
auto ee = 180 + qRadiansToDegrees(
qAtan2((textItem->pos().y() - e->scenePos().y()),
(textItem->pos().x() - e->scenePos().x())));
textItem->setRotation(ee);
}
2017-05-05 23:59:39 +02:00
}
2017-05-06 13:21:12 +02:00
void TextItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {}
2017-05-05 23:59:39 +02:00
2017-05-06 13:21:12 +02:00
QString TextItem::name() { return "Text"; }