Straight line drawing + antialiasing
This commit is contained in:
parent
92219c3a35
commit
ef08209c17
10
KShare.pro
10
KShare.pro
@ -40,10 +40,11 @@ SOURCES += main.cpp\
|
||||
notifications.cpp \
|
||||
hotkeying.cpp \
|
||||
cropeditor/drawing/dotitem.cpp \
|
||||
cropeditor/drawing/lineitem.cpp \
|
||||
cropeditor/settings/brushpenselection.cpp \
|
||||
cropeditor/drawing/bluritem.cpp \
|
||||
cropeditor/settings/blurdialog.cpp
|
||||
cropeditor/settings/blurdialog.cpp \
|
||||
cropeditor/drawing/pathitem.cpp \
|
||||
cropeditor/drawing/lineitem.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -63,10 +64,11 @@ HEADERS += mainwindow.hpp \
|
||||
hotkeying.hpp \
|
||||
cropeditor/drawing/drawitem.hpp \
|
||||
cropeditor/drawing/dotitem.hpp \
|
||||
cropeditor/drawing/lineitem.hpp \
|
||||
cropeditor/settings/brushpenselection.hpp \
|
||||
cropeditor/drawing/bluritem.hpp \
|
||||
cropeditor/settings/blurdialog.hpp
|
||||
cropeditor/settings/blurdialog.hpp \
|
||||
cropeditor/drawing/pathitem.hpp \
|
||||
cropeditor/drawing/lineitem.hpp
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
cropeditor/settings/brushpenselection.ui \
|
||||
|
@ -11,11 +11,14 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent)
|
||||
{
|
||||
scene = new CropScene(parent, image);
|
||||
view = new CropView(scene);
|
||||
|
||||
QPixmap *scaled = new QPixmap();
|
||||
image->scaled(view->width(), view->height()).swap(*scaled);
|
||||
pixmapItem = new QGraphicsPixmapItem(*image);
|
||||
pixmapItem->setZValue(-1);
|
||||
scene->addItem(pixmapItem);
|
||||
scene->setSceneRect(image->rect());
|
||||
view->setGeometry(0, 0, image->width(), image->height());
|
||||
view->showFullScreen();
|
||||
|
||||
QTimer::singleShot(0, [&] { view->showFullScreen(); });
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <cropeditor/drawing/bluritem.hpp>
|
||||
#include <cropeditor/drawing/dotitem.hpp>
|
||||
#include <cropeditor/drawing/lineitem.hpp>
|
||||
#include <cropeditor/drawing/pathitem.hpp>
|
||||
#include <cropeditor/settings/brushpenselection.hpp>
|
||||
|
||||
CropScene::CropScene(QObject *parent, QPixmap *pixmap) : QGraphicsScene(parent), prevButtons(Qt::NoButton)
|
||||
@ -123,8 +124,9 @@ void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
|
||||
QMenu menu(e->widget());
|
||||
|
||||
addDrawingAction(menu, new DotItem);
|
||||
addDrawingAction(menu, new LineItem);
|
||||
addDrawingAction(menu, new PathItem);
|
||||
addDrawingAction(menu, new BlurItem);
|
||||
addDrawingAction(menu, new LineItem);
|
||||
|
||||
menu.addSeparator();
|
||||
QAction *settings = new QAction;
|
||||
|
@ -5,7 +5,8 @@ CropView::CropView(QGraphicsScene *scene) : QGraphicsView(scene)
|
||||
setFrameShape(QFrame::NoFrame); // Time taken to solve: A george99g and 38 minutes.
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
|
||||
setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint);
|
||||
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
||||
}
|
||||
|
||||
void CropView::keyPressEvent(QKeyEvent *e)
|
||||
|
@ -4,22 +4,16 @@ LineItem::LineItem()
|
||||
{
|
||||
}
|
||||
|
||||
LineItem::~LineItem()
|
||||
{
|
||||
delete path;
|
||||
}
|
||||
|
||||
void LineItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene)
|
||||
{
|
||||
if (path == nullptr)
|
||||
if (init.isNull())
|
||||
{
|
||||
path = new QPainterPath(e->scenePos());
|
||||
pathItem = scene->addPath(*path, scene->pen(), scene->brush());
|
||||
init = e->scenePos();
|
||||
line = scene->addLine(QLineF(init, init), scene->pen());
|
||||
}
|
||||
else
|
||||
{
|
||||
path->quadTo(path->currentPosition(), e->scenePos());
|
||||
pathItem->setPath(*path);
|
||||
line->setLine(QLineF(init, e->scenePos()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,22 @@
|
||||
#ifndef LINEITEM_HPP
|
||||
#define LINEITEM_HPP
|
||||
|
||||
#include "../cropscene.hpp"
|
||||
#include "drawitem.hpp"
|
||||
|
||||
class LineItem : public DrawItem
|
||||
{
|
||||
public:
|
||||
LineItem();
|
||||
~LineItem();
|
||||
QString name()
|
||||
QString name() override
|
||||
{
|
||||
return "Line";
|
||||
return "Straight line";
|
||||
}
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override;
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override;
|
||||
|
||||
private:
|
||||
QPainterPath *path = nullptr;
|
||||
QGraphicsPathItem *pathItem = nullptr;
|
||||
QPointF init;
|
||||
QGraphicsLineItem *line;
|
||||
};
|
||||
|
||||
#endif // LINEITEM_HPP
|
||||
|
28
cropeditor/drawing/pathitem.cpp
Normal file
28
cropeditor/drawing/pathitem.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "pathitem.hpp"
|
||||
|
||||
PathItem::PathItem()
|
||||
{
|
||||
}
|
||||
|
||||
PathItem::~PathItem()
|
||||
{
|
||||
delete path;
|
||||
}
|
||||
|
||||
void PathItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene)
|
||||
{
|
||||
if (path == nullptr)
|
||||
{
|
||||
path = new QPainterPath(e->scenePos());
|
||||
pathItem = scene->addPath(*path, scene->pen(), scene->brush());
|
||||
}
|
||||
else
|
||||
{
|
||||
path->quadTo(path->currentPosition(), e->scenePos());
|
||||
pathItem->setPath(*path);
|
||||
}
|
||||
}
|
||||
|
||||
void PathItem::mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *)
|
||||
{
|
||||
}
|
24
cropeditor/drawing/pathitem.hpp
Normal file
24
cropeditor/drawing/pathitem.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef PATHITEM_HPP
|
||||
#define PATHITEM_HPP
|
||||
|
||||
#include "../cropscene.hpp"
|
||||
#include "drawitem.hpp"
|
||||
|
||||
class PathItem : public DrawItem
|
||||
{
|
||||
public:
|
||||
PathItem();
|
||||
~PathItem();
|
||||
QString name()
|
||||
{
|
||||
return "Path";
|
||||
}
|
||||
void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
void mouseDragEndEvent(QGraphicsSceneMouseEvent *e, CropScene *scene);
|
||||
|
||||
private:
|
||||
QPainterPath *path = nullptr;
|
||||
QGraphicsPathItem *pathItem = nullptr;
|
||||
};
|
||||
|
||||
#endif // PATHITEM_HPP
|
@ -24,7 +24,7 @@ BlurDialog::BlurDialog(QGraphicsBlurEffect *e, QWidget *parent) : QDialog(parent
|
||||
effect->setBlurRadius(ui->radSpinner->value());
|
||||
close();
|
||||
});
|
||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, [&] { close(); });
|
||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, [&] { close(); });
|
||||
}
|
||||
|
||||
BlurDialog::~BlurDialog()
|
||||
|
Loading…
Reference in New Issue
Block a user