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