Blur!
This commit is contained in:
parent
ba0fdc664e
commit
ae46699b95
13
KShare.pro
13
KShare.pro
@ -41,7 +41,10 @@ SOURCES += main.cpp\
|
|||||||
hotkeying.cpp \
|
hotkeying.cpp \
|
||||||
cropeditor/drawing/dotitem.cpp \
|
cropeditor/drawing/dotitem.cpp \
|
||||||
cropeditor/drawing/lineitem.cpp \
|
cropeditor/drawing/lineitem.cpp \
|
||||||
cropeditor/settings/brushpenselection.cpp
|
cropeditor/settings/brushpenselection.cpp \
|
||||||
|
effects.cpp \
|
||||||
|
cropeditor/drawing/bluritem.cpp \
|
||||||
|
cropeditor/settings/blurdialog.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.hpp \
|
HEADERS += mainwindow.hpp \
|
||||||
cropeditor/cropeditor.hpp \
|
cropeditor/cropeditor.hpp \
|
||||||
@ -62,10 +65,14 @@ HEADERS += mainwindow.hpp \
|
|||||||
cropeditor/drawing/drawitem.hpp \
|
cropeditor/drawing/drawitem.hpp \
|
||||||
cropeditor/drawing/dotitem.hpp \
|
cropeditor/drawing/dotitem.hpp \
|
||||||
cropeditor/drawing/lineitem.hpp \
|
cropeditor/drawing/lineitem.hpp \
|
||||||
cropeditor/settings/brushpenselection.hpp
|
cropeditor/settings/brushpenselection.hpp \
|
||||||
|
effects.hpp \
|
||||||
|
cropeditor/drawing/bluritem.hpp \
|
||||||
|
cropeditor/settings/blurdialog.hpp
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
cropeditor/settings/brushpenselection.ui
|
cropeditor/settings/brushpenselection.ui \
|
||||||
|
cropeditor/settings/blurdialog.ui
|
||||||
|
|
||||||
DISTFILES += \
|
DISTFILES += \
|
||||||
README.md \
|
README.md \
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent)
|
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
scene = new CropScene(parent);
|
scene = new CropScene(parent, image);
|
||||||
view = new CropView(scene);
|
view = new CropView(scene);
|
||||||
|
|
||||||
pixmapItem = new QGraphicsPixmapItem(*image);
|
pixmapItem = new QGraphicsPixmapItem(*image);
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <cropeditor/drawing/bluritem.hpp>
|
||||||
#include <cropeditor/drawing/dotitem.hpp>
|
#include <cropeditor/drawing/dotitem.hpp>
|
||||||
#include <cropeditor/drawing/lineitem.hpp>
|
#include <cropeditor/drawing/lineitem.hpp>
|
||||||
#include <cropeditor/settings/brushpenselection.hpp>
|
#include <cropeditor/settings/brushpenselection.hpp>
|
||||||
|
|
||||||
CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::NoButton)
|
CropScene::CropScene(QObject *parent, QPixmap *pixmap) : QGraphicsScene(parent), prevButtons(Qt::NoButton)
|
||||||
{
|
{
|
||||||
|
_pixmap = pixmap;
|
||||||
QTimer::singleShot(0, [&] {
|
QTimer::singleShot(0, [&] {
|
||||||
QPolygonF poly;
|
QPolygonF poly;
|
||||||
poly.append(sceneRect().topLeft());
|
poly.append(sceneRect().topLeft());
|
||||||
@ -38,6 +40,7 @@ QBrush &CropScene::brush()
|
|||||||
void CropScene::setDrawingSelection(DrawItem *drawAction)
|
void CropScene::setDrawingSelection(DrawItem *drawAction)
|
||||||
{
|
{
|
||||||
drawingSelection = drawAction;
|
drawingSelection = drawAction;
|
||||||
|
drawAction->init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||||
@ -116,7 +119,7 @@ void CropScene::addDrawingAction(QMenu &menu, DrawItem *item)
|
|||||||
{
|
{
|
||||||
QAction *action = new QAction;
|
QAction *action = new QAction;
|
||||||
action->setText(item->name());
|
action->setText(item->name());
|
||||||
QObject::connect(action, &QAction::triggered, [this, item](bool) { setDrawingSelection(item); });
|
connect(action, &QAction::triggered, [this, item](bool) { setDrawingSelection(item); });
|
||||||
menu.addAction(action);
|
menu.addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +129,7 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
|
|||||||
|
|
||||||
addDrawingAction(menu, new DotItem);
|
addDrawingAction(menu, new DotItem);
|
||||||
addDrawingAction(menu, new LineItem);
|
addDrawingAction(menu, new LineItem);
|
||||||
|
addDrawingAction(menu, new BlurItem);
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QAction *settings = new QAction;
|
QAction *settings = new QAction;
|
||||||
|
@ -15,10 +15,14 @@ class CropScene : public QGraphicsScene
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CropScene(QObject *parent);
|
CropScene(QObject *parent, QPixmap *pixmap);
|
||||||
QPen &pen();
|
QPen &pen();
|
||||||
QBrush &brush();
|
QBrush &brush();
|
||||||
void setDrawingSelection(DrawItem *drawAction);
|
void setDrawingSelection(DrawItem *drawAction);
|
||||||
|
QPixmap *pixmap()
|
||||||
|
{
|
||||||
|
return _pixmap;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closedWithRect(QRect rect);
|
void closedWithRect(QRect rect);
|
||||||
@ -34,6 +38,7 @@ class CropScene : public QGraphicsScene
|
|||||||
private:
|
private:
|
||||||
void addDrawingAction(QMenu &menu, DrawItem *item);
|
void addDrawingAction(QMenu &menu, DrawItem *item);
|
||||||
void done();
|
void done();
|
||||||
|
QPixmap *_pixmap;
|
||||||
QFlags<Qt::MouseButton> prevButtons;
|
QFlags<Qt::MouseButton> prevButtons;
|
||||||
QGraphicsRectItem *rect = nullptr;
|
QGraphicsRectItem *rect = nullptr;
|
||||||
QPointF initPos;
|
QPointF initPos;
|
||||||
|
36
cropeditor/drawing/bluritem.cpp
Normal file
36
cropeditor/drawing/bluritem.cpp
Normal file
@ -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);
|
||||||
|
}
|
30
cropeditor/drawing/bluritem.hpp
Normal file
30
cropeditor/drawing/bluritem.hpp
Normal file
@ -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
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef DRAWITEM_HPP
|
#ifndef DRAWITEM_HPP
|
||||||
#define DRAWITEM_HPP
|
#define DRAWITEM_HPP
|
||||||
|
|
||||||
|
class DrawItem;
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <cropeditor/cropscene.hpp>
|
#include <cropeditor/cropscene.hpp>
|
||||||
|
|
||||||
@ -11,6 +13,10 @@ class DrawItem
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual QString name() = 0;
|
virtual QString name() = 0;
|
||||||
|
virtual void init(CropScene *scene)
|
||||||
|
{
|
||||||
|
Q_UNUSED(scene)
|
||||||
|
}
|
||||||
virtual void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
|
virtual void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
|
||||||
virtual void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
|
virtual void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@ void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
path->lineTo(e->scenePos());
|
path->quadTo(path->currentPosition(), e->scenePos());
|
||||||
pathItem->setPath(*path);
|
pathItem->setPath(*path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
cropeditor/settings/blurdialog.cpp
Normal file
43
cropeditor/settings/blurdialog.cpp
Normal file
@ -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.);
|
||||||
|
}
|
29
cropeditor/settings/blurdialog.hpp
Normal file
29
cropeditor/settings/blurdialog.hpp
Normal file
@ -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
|
98
cropeditor/settings/blurdialog.ui
Normal file
98
cropeditor/settings/blurdialog.ui
Normal file
@ -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>
|
13
main.cpp
13
main.cpp
@ -7,26 +7,25 @@
|
|||||||
|
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
|
||||||
void handler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
void handler(QtMsgType type, const QMessageLogContext &, const QString &msg)
|
||||||
{
|
{
|
||||||
QByteArray localMsg = msg.toLocal8Bit();
|
QByteArray localMsg = msg.toLocal8Bit();
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
if (verbose)
|
if (verbose) fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
|
||||||
fprintf(stdout, "DEBUG %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData());
|
|
||||||
break;
|
break;
|
||||||
case QtInfoMsg:
|
case QtInfoMsg:
|
||||||
fprintf(stdout, "INFO %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData());
|
fprintf(stderr, "INFO: %s\n", localMsg.constData());
|
||||||
break;
|
break;
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
fprintf(stdout, "WARN %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData());
|
fprintf(stderr, "WARN: %s\n", localMsg.constData());
|
||||||
break;
|
break;
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
fprintf(stdout, "CRIT %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData());
|
fprintf(stderr, "CRIT: %s\n", localMsg.constData());
|
||||||
break;
|
break;
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
fprintf(stdout, "FATAL %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData());
|
fprintf(stderr, "FATAL: %s\n", localMsg.constData());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user