From 3525261e1e578bdc6e60598596e1eec84682e01a Mon Sep 17 00:00:00 2001 From: AshBastian Date: Tue, 17 Dec 2019 17:45:42 +0100 Subject: [PATCH] Polygon Update --- src/GUI/IntelliPhotoGui.cpp | 3 +- src/GUI/IntelliPhotoGui.h | 1 + src/IntelliPhoto.pro | 2 + src/Layer/PaintingArea.cpp | 3 +- src/Layer/PaintingArea.h | 2 +- src/Tool/IntelliToolPolygon.cpp | 87 +++++++++++++++++++++++++++++++++ src/Tool/IntelliToolPolygon.h | 33 +++++++++++++ 7 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 src/Tool/IntelliToolPolygon.cpp create mode 100644 src/Tool/IntelliToolPolygon.h diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index a25999b..7611b30 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -18,7 +18,8 @@ IntelliPhotoGui::IntelliPhotoGui(){ setIntelliStyle(); // Size the app - showMaximized(); + resize(600,600); + //showMaximized(); } // User tried to close the app diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 3865c1f..c074d85 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -123,6 +123,7 @@ private: //main GUI elements QWidget* centralGuiWidget; + QPushButton* Toolmanager; QGridLayout *mainLayout; }; diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index 47bf20e..d1fe9fa 100644 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -28,6 +28,7 @@ SOURCES += \ Tool/IntelliToolLine.cpp \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ + Tool/IntelliToolPolygon.cpp \ Tool/IntelliToolRechteck.cpp \ main.cpp @@ -44,6 +45,7 @@ HEADERS += \ Tool/IntelliToolLine.h \ Tool/IntelliToolPen.h \ Tool/IntelliToolPlain.h \ + Tool/IntelliToolPolygon.h \ Tool/IntelliToolRechteck.h \ Tool/intellitoolcircle.h diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 1783a40..dd53f0b 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -15,11 +15,12 @@ #include "Tool/IntelliToolLine.h" #include "Tool/IntelliToolCircle.h" #include "Tool/IntelliToolRechteck.h" +#include "Tool/IntelliToolPolygon.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ //test yout tool here and reset after accomplished test - this->Tool = new IntelliToolRechteck(this, &colorPicker); + this->Tool = new IntelliToolPolygon(this, &colorPicker); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index fa85425..e598774 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -34,7 +34,7 @@ class PaintingArea : public QWidget friend IntelliTool; public: PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr); - ~PaintingArea(); + ~PaintingArea() override; // Handles all events bool open(const QString &fileName); diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp new file mode 100644 index 0000000..3c297ac --- /dev/null +++ b/src/Tool/IntelliToolPolygon.cpp @@ -0,0 +1,87 @@ +#include "IntelliToolPolygon.h" +#include "Layer/PaintingArea.h" +#include +#include + +IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) + :IntelliTool(Area, colorPicker){ + lineWidth = 5; + isDrawing = false; + PointIsNearStart = false; + drawingPoint.setX(0); + drawingPoint.setY(0); +} + +void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ + qDebug() << x << y; + if(!isDrawing && x > 0 && y > 0){ + isDrawing = true; + drawingPoint.setX(x); + drawingPoint.setY(y); + QPointList.push_back(drawingPoint); + IntelliTool::onMouseLeftPressed(x,y); + this->Canvas->image->drawPlain(Qt::transparent); + this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth); + } + else if(isDrawing && isNearStart(x,y,QPointList.front())){ + PointIsNearStart = isNearStart(x,y,QPointList.front()); + this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);s + } + else if(isDrawing){ + drawingPoint.setX(x); + drawingPoint.setY(y); + QPointList.push_back(drawingPoint); + this->Canvas->image->drawLine(QPointList.operator[](QPointList.size() - 2), QPointList.back(), colorPicker->getFirstColor(), lineWidth); + } +} + +void IntelliToolPolygon::onMouseRightPressed(int x, int y){ + isDrawing = false; + PointIsNearStart = false; + QPointList.clear(); + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ + if(PointIsNearStart && QPointList.size() > 1){ + PointIsNearStart = false; + isDrawing = false; + QPointList.clear(); + IntelliTool::onMouseLeftReleased(x,y); + } +} + +void IntelliToolPolygon::onMouseRightReleased(int x, int y){ + +} + +void IntelliToolPolygon::onWheelScrolled(int value){ + if(!isDrawing){ + if(lineWidth + value < 10){ + lineWidth += value; + } + if(lineWidth < 1){ + lineWidth = 1; + } + } +} + +void IntelliToolPolygon::onMouseMoved(int x, int y){ + +} + +bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ + bool isNear = false; + int StartX = Startpoint.x(); + int StartY = Startpoint.y(); + int valueToNear = 10; + + for(int i = StartX - valueToNear; i < StartX + valueToNear; i++){ + for(int j = StartY - valueToNear; j < StartY + valueToNear; j++){ + if((i == x) && (j == y)){ + isNear = true; + } + } + } + return isNear; +} diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h new file mode 100644 index 0000000..c8496e9 --- /dev/null +++ b/src/Tool/IntelliToolPolygon.h @@ -0,0 +1,33 @@ +#ifndef INTELLITOOLPOLYGON_H +#define INTELLITOOLPOLYGON_H + +#include "IntelliTool.h" +#include +#include + +class IntelliToolPolygon : public IntelliTool +{ +public: + IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker); + + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + + virtual void onWheelScrolled(int value) override; + + virtual void onMouseMoved(int x, int y) override; + +private: + bool isNearStart(int x, int y, QPoint Startpoint); + + int lineWidth; + bool isDrawing; + bool PointIsNearStart; + QPoint drawingPoint; + std::vector QPointList; + +}; + +#endif // INTELLITOOLPOLYGON_H