diff --git a/KShare.pro b/KShare.pro index bb05130..819d55f 100644 --- a/KShare.pro +++ b/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 \ diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index b1e6848..1bac7f8 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -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(); }); diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index f0d5060..7362944 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include 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; diff --git a/cropeditor/cropview.cpp b/cropeditor/cropview.cpp index 5f383bd..6740577 100644 --- a/cropeditor/cropview.cpp +++ b/cropeditor/cropview.cpp @@ -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) diff --git a/cropeditor/drawing/lineitem.cpp b/cropeditor/drawing/lineitem.cpp index 5494a6d..8de1206 100644 --- a/cropeditor/drawing/lineitem.cpp +++ b/cropeditor/drawing/lineitem.cpp @@ -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())); } } diff --git a/cropeditor/drawing/lineitem.hpp b/cropeditor/drawing/lineitem.hpp index 4c48a92..aedaaf7 100644 --- a/cropeditor/drawing/lineitem.hpp +++ b/cropeditor/drawing/lineitem.hpp @@ -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 diff --git a/cropeditor/drawing/pathitem.cpp b/cropeditor/drawing/pathitem.cpp new file mode 100644 index 0000000..a8f933f --- /dev/null +++ b/cropeditor/drawing/pathitem.cpp @@ -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 *) +{ +} diff --git a/cropeditor/drawing/pathitem.hpp b/cropeditor/drawing/pathitem.hpp new file mode 100644 index 0000000..19cafd7 --- /dev/null +++ b/cropeditor/drawing/pathitem.hpp @@ -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 diff --git a/cropeditor/settings/blurdialog.cpp b/cropeditor/settings/blurdialog.cpp index 9b6c131..401bc49 100644 --- a/cropeditor/settings/blurdialog.cpp +++ b/cropeditor/settings/blurdialog.cpp @@ -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()