12 changed files with 272 additions and 15 deletions
@ -0,0 +1,36 @@
|
||||
#include "bluritem.hpp" |
||||
|
||||
#include <QDebug> |
||||
#include <cropeditor/settings/blurdialog.hpp> |
||||
#include <effects.hpp> |
||||
|
||||
void BlurItem::init(CropScene *) |
||||
{ |
||||
effect = new QGraphicsBlurEffect; |
||||
BlurDialog(effect).exec(); |
||||
} |
||||
|
||||
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()); |
||||
} |
||||
} |
||||
|
||||
void BlurItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) |
||||
{ |
||||
if (rect != nullptr) rect->setPen(Qt::NoPen); |
||||
} |
@ -0,0 +1,30 @@
|
||||
#ifndef BLURITEM_HPP |
||||
#define BLURITEM_HPP |
||||
|
||||
#include "drawitem.hpp" |
||||
|
||||
#include <QGraphicsEffect> |
||||
|
||||
class BlurItem : public DrawItem |
||||
{ |
||||
public: |
||||
QString name() |
||||
{ |
||||
return "Blur"; |
||||
} |
||||
~BlurItem() |
||||
{ |
||||
} |
||||
|
||||
void init(CropScene *) override; |
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override; |
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override; |
||||
|
||||
private: |
||||
QGraphicsBlurEffect *effect; |
||||
QPointF pos; |
||||
QGraphicsRectItem *rect; |
||||
QGraphicsPixmapItem *pixmap; |
||||
}; |
||||
|
||||
#endif // BLURITEM_HPP
|
@ -0,0 +1,43 @@
|
||||
#include "blurdialog.hpp" |
||||
#include "ui_blurdialog.h" |
||||
|
||||
#include <QCheckBox> |
||||
#include <QDialogButtonBox> |
||||
#include <QDoubleSpinBox> |
||||
#include <QSlider> |
||||
|
||||
BlurDialog::BlurDialog(QGraphicsBlurEffect *e, QWidget *parent) : QDialog(parent), ui(new Ui::BlurDialog) |
||||
{ |
||||
effect = e; |
||||
ui->setupUi(this); |
||||
ui->animated->setChecked(effect->blurHints().testFlag(QGraphicsBlurEffect::AnimationHint)); |
||||
ui->performance->setChecked(effect->blurHints().testFlag(QGraphicsBlurEffect::PerformanceHint)); |
||||
ui->quality->setChecked(effect->blurHints().testFlag(QGraphicsBlurEffect::QualityHint)); |
||||
ui->radSlider->setValue(effect->blurRadius() * 100); |
||||
ui->radSpinner->setValue(effect->blurRadius()); |
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] { |
||||
QFlags<QGraphicsBlurEffect::BlurHint> hints; |
||||
hints.setFlag(QGraphicsBlurEffect::AnimationHint, ui->animated->isChecked()); |
||||
hints.setFlag(QGraphicsBlurEffect::PerformanceHint, ui->performance->isChecked()); |
||||
hints.setFlag(QGraphicsBlurEffect::QualityHint, ui->quality->isChecked()); |
||||
effect->setBlurHints(hints); |
||||
effect->setBlurRadius(ui->radSpinner->value()); |
||||
close(); |
||||
}); |
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] { close(); }); |
||||
} |
||||
|
||||
BlurDialog::~BlurDialog() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void BlurDialog::on_radSpinner_valueChanged(double arg1) |
||||
{ |
||||
ui->radSlider->setValue(arg1 * 100); |
||||
} |
||||
|
||||
void BlurDialog::on_radSlider_sliderMoved(int position) |
||||
{ |
||||
ui->radSpinner->setValue(position / 100.); |
||||
} |
@ -0,0 +1,29 @@
|
||||
#ifndef BLURDIALOG_HPP |
||||
#define BLURDIALOG_HPP |
||||
|
||||
#include <QDialog> |
||||
#include <QGraphicsBlurEffect> |
||||
|
||||
namespace Ui |
||||
{ |
||||
class BlurDialog; |
||||
} |
||||
|
||||
class BlurDialog : public QDialog |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit BlurDialog(QGraphicsBlurEffect *effect, QWidget *parent = 0); |
||||
~BlurDialog(); |
||||
|
||||
private slots: |
||||
void on_radSpinner_valueChanged(double arg1); |
||||
void on_radSlider_sliderMoved(int position); |
||||
|
||||
private: |
||||
Ui::BlurDialog *ui; |
||||
QGraphicsBlurEffect *effect; |
||||
}; |
||||
|
||||
#endif // BLURDIALOG_HPP
|
@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>BlurDialog</class> |
||||
<widget class="QDialog" name="BlurDialog"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>400</width> |
||||
<height>222</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Blur Settings</string> |
||||
</property> |
||||
<layout class="QGridLayout" name="gridLayout"> |
||||
<item row="1" column="1"> |
||||
<widget class="QSlider" name="radSlider"> |
||||
<property name="maximum"> |
||||
<number>3000</number> |
||||
</property> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="1" column="2"> |
||||
<widget class="QDoubleSpinBox" name="radSpinner"> |
||||
<property name="suffix"> |
||||
<string>px</string> |
||||
</property> |
||||
<property name="maximum"> |
||||
<double>30.000000000000000</double> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="2" column="0" colspan="3"> |
||||
<widget class="QLabel" name="label_2"> |
||||
<property name="whatsThis"> |
||||
<string>http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum</string> |
||||
</property> |
||||
<property name="text"> |
||||
<string><a href="http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum">Blur Hints</string> |
||||
</property> |
||||
<property name="openExternalLinks"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="textInteractionFlags"> |
||||
<set>Qt::TextBrowserInteraction</set> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="0" colspan="3"> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="text"> |
||||
<string>Blur Radius</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="3" column="0" colspan="3"> |
||||
<widget class="QCheckBox" name="performance"> |
||||
<property name="text"> |
||||
<string>Performance Hint</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="4" column="0" colspan="3"> |
||||
<widget class="QCheckBox" name="animated"> |
||||
<property name="text"> |
||||
<string>Animated Hint</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="5" column="0" colspan="3"> |
||||
<widget class="QCheckBox" name="quality"> |
||||
<property name="text"> |
||||
<string>Quality Hint</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
<item row="6" column="0" colspan="3"> |
||||
<widget class="QDialogButtonBox" name="buttonBox"> |
||||
<property name="orientation"> |
||||
<enum>Qt::Horizontal</enum> |
||||
</property> |
||||
<property name="standardButtons"> |
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> |
||||
</property> |
||||
<property name="centerButtons"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
Loading…
Reference in new issue