Browse Source

Add ellipses

tags/v5.0.0
ArsenArsen 5 years ago
parent
commit
9bd202354b
  1. 6
      KShare.pro
  2. 2
      cropeditor/cropscene.cpp
  3. 12
      cropeditor/drawing/ellipseitem.cpp
  4. 24
      cropeditor/drawing/ellipseitem.hpp

6
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

2
cropeditor/cropscene.cpp

@ -9,6 +9,7 @@
#include <QTimer>
#include <cropeditor/drawing/bluritem.hpp>
#include <cropeditor/drawing/dotitem.hpp>
#include <cropeditor/drawing/ellipseitem.hpp>
#include <cropeditor/drawing/eraseritem.hpp>
#include <cropeditor/drawing/lineitem.hpp>
#include <cropeditor/drawing/pathitem.hpp>
@ -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; });

12
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())));
}
}

24
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
Loading…
Cancel
Save