This commit is contained in:
ArsenArsen 2017-05-01 11:28:54 +02:00
parent ba0fdc664e
commit ae46699b95
12 changed files with 272 additions and 15 deletions

View File

@ -41,7 +41,10 @@ SOURCES += main.cpp\
hotkeying.cpp \
cropeditor/drawing/dotitem.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 \
cropeditor/cropeditor.hpp \
@ -62,10 +65,14 @@ HEADERS += mainwindow.hpp \
cropeditor/drawing/drawitem.hpp \
cropeditor/drawing/dotitem.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 \
cropeditor/settings/brushpenselection.ui
cropeditor/settings/brushpenselection.ui \
cropeditor/settings/blurdialog.ui
DISTFILES += \
README.md \

View File

@ -9,7 +9,7 @@
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent)
{
scene = new CropScene(parent);
scene = new CropScene(parent, image);
view = new CropView(scene);
pixmapItem = new QGraphicsPixmapItem(*image);

View File

@ -6,12 +6,14 @@
#include <QGraphicsView>
#include <QMenu>
#include <QTimer>
#include <cropeditor/drawing/bluritem.hpp>
#include <cropeditor/drawing/dotitem.hpp>
#include <cropeditor/drawing/lineitem.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, [&] {
QPolygonF poly;
poly.append(sceneRect().topLeft());
@ -38,6 +40,7 @@ QBrush &CropScene::brush()
void CropScene::setDrawingSelection(DrawItem *drawAction)
{
drawingSelection = drawAction;
drawAction->init(this);
}
void CropScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
@ -116,7 +119,7 @@ void CropScene::addDrawingAction(QMenu &menu, DrawItem *item)
{
QAction *action = new QAction;
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);
}
@ -126,6 +129,7 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
addDrawingAction(menu, new DotItem);
addDrawingAction(menu, new LineItem);
addDrawingAction(menu, new BlurItem);
menu.addSeparator();
QAction *settings = new QAction;

View File

@ -15,10 +15,14 @@ class CropScene : public QGraphicsScene
{
Q_OBJECT
public:
CropScene(QObject *parent);
CropScene(QObject *parent, QPixmap *pixmap);
QPen &pen();
QBrush &brush();
void setDrawingSelection(DrawItem *drawAction);
QPixmap *pixmap()
{
return _pixmap;
}
signals:
void closedWithRect(QRect rect);
@ -34,6 +38,7 @@ class CropScene : public QGraphicsScene
private:
void addDrawingAction(QMenu &menu, DrawItem *item);
void done();
QPixmap *_pixmap;
QFlags<Qt::MouseButton> prevButtons;
QGraphicsRectItem *rect = nullptr;
QPointF initPos;

View 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);
}

View 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

View File

@ -1,6 +1,8 @@
#ifndef DRAWITEM_HPP
#define DRAWITEM_HPP
class DrawItem;
#include <QString>
#include <cropeditor/cropscene.hpp>
@ -11,6 +13,10 @@ class DrawItem
{
}
virtual QString name() = 0;
virtual void init(CropScene *scene)
{
Q_UNUSED(scene)
}
virtual void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
virtual void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) = 0;
};

View File

@ -18,7 +18,7 @@ void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene)
}
else
{
path->lineTo(e->scenePos());
path->quadTo(path->currentPosition(), e->scenePos());
pathItem->setPath(*path);
}
}

View 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.);
}

View 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

View 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>&lt;a href=&quot;http://doc.qt.io/qt-5/qgraphicsblureffect.html#BlurHint-enum&quot;&gt;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>

View File

@ -7,26 +7,25 @@
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();
switch (type)
{
case QtDebugMsg:
if (verbose)
fprintf(stdout, "DEBUG %s:%s(%d): %s\n", context.file, context.function, context.line, localMsg.constData());
if (verbose) fprintf(stderr, "DEBUG: %s\n", localMsg.constData());
break;
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;
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;
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;
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;
}
}