KShare/cropeditor/drawing/bluritem.cpp

35 lines
1.5 KiB
C++
Raw Normal View History

2017-05-01 11:28:54 +02:00
#include "bluritem.hpp"
#include <settings.hpp>
2017-05-01 11:28:54 +02:00
bool BlurItem::init(CropScene *) {
effect = new QGraphicsBlurEffect;
QFlags<QGraphicsBlurEffect::BlurHint> blurHints;
blurHints.setFlag(QGraphicsBlurEffect::AnimationHint, settings::settings().value("blur/animatedHint", false).toBool());
blurHints.setFlag(QGraphicsBlurEffect::PerformanceHint, settings::settings().value("blur/performanceHint", true).toBool());
blurHints.setFlag(QGraphicsBlurEffect::QualityHint, settings::settings().value("blur/qualityHint", false).toBool());
effect->setBlurHints(blurHints);
effect->setBlurRadius(settings::settings().value("blurRadius", 5.).toDouble());
return true;
2017-05-01 11:28:54 +02:00
}
2017-05-06 13:21:12 +02:00
void BlurItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) {
if (pos.isNull()) {
pos = e->scenePos();
rect = scene->addRect(QRect(e->scenePos().toPoint(), QSize(1, 1)), QPen(Qt::cyan), Qt::NoBrush);
pixmap = scene->addPixmap(scene->pixmap().copy(rect->rect().toRect()));
pixmap->setPos(e->scenePos());
pixmap->setZValue(rect->zValue() - 0.1);
pixmap->setGraphicsEffect(effect);
} else {
QPointF p = e->scenePos();
rect->setRect(QRect(qMin(pos.x(), p.x()), qMin(pos.y(), p.y()), qAbs(pos.x() - p.x()), qAbs(pos.y() - p.y())));
pixmap->setPixmap(scene->pixmap().copy(rect->rect().toRect()));
pixmap->setPos(rect->rect().topLeft());
}
2017-05-01 11:28:54 +02:00
}
2017-05-06 13:21:12 +02:00
void BlurItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) {
if (rect != nullptr) rect->setPen(Qt::NoPen);
2017-05-01 11:28:54 +02:00
}