KShare/cropeditor/drawing/textitem.cpp

32 lines
966 B
C++
Raw Normal View History

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