From 9bd202354bd5d520fdb45772048fcd181f793787 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Mon, 26 Jun 2017 18:27:38 +0200 Subject: [PATCH] Add ellipses --- KShare.pro | 6 ++++-- cropeditor/cropscene.cpp | 2 ++ cropeditor/drawing/ellipseitem.cpp | 12 ++++++++++++ cropeditor/drawing/ellipseitem.hpp | 24 ++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 cropeditor/drawing/ellipseitem.cpp create mode 100644 cropeditor/drawing/ellipseitem.hpp diff --git a/KShare.pro b/KShare.pro index 1662f36..4fce963 100644 --- a/KShare.pro +++ b/KShare.pro @@ -61,7 +61,8 @@ SOURCES += main.cpp\ settingsdialog.cpp \ aboutbox.cpp \ cropeditor/drawing/eraseritem.cpp \ - cropeditor/drawing/rectitem.cpp + cropeditor/drawing/rectitem.cpp \ + cropeditor/drawing/ellipseitem.cpp HEADERS += mainwindow.hpp \ cropeditor/cropeditor.hpp \ @@ -101,7 +102,8 @@ HEADERS += mainwindow.hpp \ settingsdialog.hpp \ aboutbox.hpp \ cropeditor/drawing/eraseritem.hpp \ - cropeditor/drawing/rectitem.hpp + cropeditor/drawing/rectitem.hpp \ + cropeditor/drawing/ellipseitem.hpp LIBS += -lavcodec -lavformat -lavutil -lswscale -lavutil diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index fb860db..b720cb5 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -32,6 +33,7 @@ CropScene::CropScene(QObject *parent, QPixmap *pixmap) addDrawingAction(menu, "Straight line", [] { return new LineItem; }); addDrawingAction(menu, "Text", [] { return new TextItem; }); addDrawingAction(menu, "Rectangle", [] { return new RectItem; }); + addDrawingAction(menu, "Ellipse", [] { return new EllipseItem; }); menu.addSeparator(); addDrawingAction(menu, "Eraser", [] { return new EraserItem; }); diff --git a/cropeditor/drawing/ellipseitem.cpp b/cropeditor/drawing/ellipseitem.cpp new file mode 100644 index 0000000..ff1cfce --- /dev/null +++ b/cropeditor/drawing/ellipseitem.cpp @@ -0,0 +1,12 @@ +#include "ellipseitem.hpp" + +void EllipseItem::mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) { + if (!ellie) { + ellie = scene->addEllipse(e->scenePos().x(), e->scenePos().y(), 0, 0, scene->pen(), scene->brush()); + initPos = e->scenePos(); + } else { + auto p = e->scenePos(); + ellie->setRect(QRectF(qMin(initPos.x(), p.x()), qMin(initPos.y(), p.y()), qAbs(initPos.x() - p.x()), + qAbs(initPos.y() - p.y()))); + } +} diff --git a/cropeditor/drawing/ellipseitem.hpp b/cropeditor/drawing/ellipseitem.hpp new file mode 100644 index 0000000..116da7c --- /dev/null +++ b/cropeditor/drawing/ellipseitem.hpp @@ -0,0 +1,24 @@ +#ifndef ELLIPSEITEM_HPP +#define ELLIPSEITEM_HPP + +#include "drawitem.hpp" + +class EllipseItem : public DrawItem { +public: + EllipseItem() { + } + QString name() { + return "Blur"; + } + ~EllipseItem() { + } + void mouseDragEvent(QGraphicsSceneMouseEvent *e, CropScene *scene) override; + void mouseDragEndEvent(QGraphicsSceneMouseEvent *, CropScene *) override { + } + +private: + QGraphicsEllipseItem *ellie = nullptr; + QPointF initPos; +}; + +#endif // ELLIPSEITEM_HPP