From 3525261e1e578bdc6e60598596e1eec84682e01a Mon Sep 17 00:00:00 2001 From: AshBastian Date: Tue, 17 Dec 2019 17:45:42 +0100 Subject: [PATCH 1/4] 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 From 89b9e4467739201d5ea8b1ee83b0991a61ce7d16 Mon Sep 17 00:00:00 2001 From: AshBastian Date: Wed, 18 Dec 2019 15:47:23 +0100 Subject: [PATCH 2/4] PolygonTool fertig --- src/GUI/IntelliPhotoGui.cpp | 16 +++++----------- src/GUI/IntelliPhotoGui.h | 2 -- src/IntelliPhoto.pro | 5 ++--- src/Layer/PaintingArea.cpp | 12 ++++++++++-- src/Layer/PaintingArea.h | 4 ++++ src/Tool/IntelliToolLine.cpp | 3 +-- src/Tool/IntelliToolPolygon.cpp | 21 ++++++++++++++++++--- src/Tool/IntelliToolPolygon.h | 2 ++ src/mainwindow.ui | 23 +++++++++++++++++++++++ src/widget.ui | 19 ------------------- 10 files changed, 65 insertions(+), 42 deletions(-) create mode 100644 src/mainwindow.ui delete mode 100644 src/widget.ui diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 7611b30..ce6af70 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -8,6 +8,7 @@ // IntelliPhotoGui constructor IntelliPhotoGui::IntelliPhotoGui(){ + //create Gui elements and lay them out createGui(); // Create actions @@ -19,7 +20,8 @@ IntelliPhotoGui::IntelliPhotoGui(){ // Size the app resize(600,600); - //showMaximized(); + showMaximized(); + } // User tried to close the app @@ -105,14 +107,6 @@ void IntelliPhotoGui::slotDeleteLayer(){ paintingArea->deleteLayer(layerNumber); } -void slotCreatePenTool(){ - -} - -void slotCreateFloodFillTool(){ - -} - void IntelliPhotoGui::slotSetActiveAlpha(){ // Stores button value bool ok1, ok2; @@ -205,7 +199,7 @@ void IntelliPhotoGui::slotSetActiveLayer(){ { paintingArea->setLayerToActive(layer); } -}; +} void IntelliPhotoGui::slotSetFirstColor(){ paintingArea->colorPickerSetFirstColor(); @@ -318,7 +312,7 @@ void IntelliPhotoGui::createActions(){ connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor())); actionColorPickerSecondColor = new QAction(tr("&Secondary"), this); - connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor())); + connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor())); actionColorSwitch = new QAction(tr("&Switch"), this); actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index c074d85..ad8250a 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -68,7 +68,6 @@ private: //set style of the GUI void setIntelliStyle(); - // Will check if changes have occurred since last save bool maybeSave(); // Opens the Save dialog and saves @@ -123,7 +122,6 @@ private: //main GUI elements QWidget* centralGuiWidget; - QPushButton* Toolmanager; QGridLayout *mainLayout; }; diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index d1fe9fa..21210e8 100644 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -46,11 +46,10 @@ HEADERS += \ Tool/IntelliToolPen.h \ Tool/IntelliToolPlain.h \ Tool/IntelliToolPolygon.h \ - Tool/IntelliToolRechteck.h \ - Tool/intellitoolcircle.h + Tool/IntelliToolRechteck.h FORMS += \ - widget.ui + mainwindow.ui QMAKE_CXXFLAGS QMAKE_LFLAGS diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index dd53f0b..bca41f0 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -24,7 +24,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); - layerBundle[0].image->drawPlain(QColor(255,0,0,255)); + layerBundle[0].image->drawPlain(QColor(0,0,255,255)); std::vector polygon; polygon.push_back(QPoint(100,000)); polygon.push_back(QPoint(200,100)); @@ -36,7 +36,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) layerBundle[1].image->drawPlain(QColor(0,255,0,255)); layerBundle[1].alpha=200; - activeLayer=1; + activeLayer=0; } PaintingArea::~PaintingArea(){ @@ -193,6 +193,14 @@ void PaintingArea::createLineTool(){ Tool = new IntelliToolLine(this, &colorPicker); } +int PaintingArea::getWidthActiveLayer(){ + return layerBundle.operator[](activeLayer).width; +} + +int PaintingArea::getHeightActiveLayer(){ + return layerBundle.operator[](activeLayer).hight; +} + // If a mouse button is pressed check if it was the // left button and if so store the current position // Set that we are currently drawing diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index e598774..547b6f3 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -59,6 +59,10 @@ public: void createPlainTool(); void createLineTool(); + //get Width and Height of active Layer + int getWidthActiveLayer(); + int getHeightActiveLayer(); + public slots: // Events to handle diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index 0b088cd..83ed0c7 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -26,7 +26,7 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){ void IntelliToolLine::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->start=QPoint(x,y); - this->Canvas->image->drawLine(start, start, colorPicker->getFirstColor(),lineWidth); + this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth); Canvas->image->calculateVisiblity(); } @@ -43,7 +43,6 @@ void IntelliToolLine::onWheelScrolled(int value){ } void IntelliToolLine::onMouseMoved(int x, int y){ - IntelliTool::onMouseMoved(x,y); if(this->drawing){ this->Canvas->image->drawPlain(Qt::transparent); QPoint next(x,y); diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 3c297ac..8d3e26d 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -13,8 +13,11 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - qDebug() << x << y; - if(!isDrawing && x > 0 && y > 0){ + if(!isDrawing){ + width = Area->getWidthActiveLayer(); + height = Area->getHeightActiveLayer(); + } + if(!isDrawing && x > 0 && y > 0 && x < width && y < height){ isDrawing = true; drawingPoint.setX(x); drawingPoint.setY(y); @@ -22,16 +25,19 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->Canvas->image->drawPlain(Qt::transparent); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->calculateVisiblity(); } 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 + this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->calculateVisiblity(); } 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); + this->Canvas->image->calculateVisiblity(); } } @@ -44,8 +50,17 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ if(PointIsNearStart && QPointList.size() > 1){ + this->Canvas->image->calculateVisiblity(); PointIsNearStart = false; isDrawing = false; + for(int i = 0; i < width; i++){ + for(int j = 0; j < height; j++){ + if(/*funktion(QPointList,i,j)*/false){ + this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor()); + continue; + } + } + } QPointList.clear(); IntelliTool::onMouseLeftReleased(x,y); } diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index c8496e9..fc51ec6 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -23,6 +23,8 @@ private: bool isNearStart(int x, int y, QPoint Startpoint); int lineWidth; + int width; + int height; bool isDrawing; bool PointIsNearStart; QPoint drawingPoint; diff --git a/src/mainwindow.ui b/src/mainwindow.ui new file mode 100644 index 0000000..433b697 --- /dev/null +++ b/src/mainwindow.ui @@ -0,0 +1,23 @@ + + + MainWindow + + + + 0 + 0 + 542 + 459 + + + + IntelliPhoto + + + true + + + + + + diff --git a/src/widget.ui b/src/widget.ui deleted file mode 100644 index b1d4c7b..0000000 --- a/src/widget.ui +++ /dev/null @@ -1,19 +0,0 @@ - - - Widget - - - - 0 - 0 - 360 - 206 - - - - Widget - - - - - From c6151b1bbf04fc798d3ae057cf90f3797b4e0595 Mon Sep 17 00:00:00 2001 From: Mienek Date: Thu, 19 Dec 2019 11:47:33 +0100 Subject: [PATCH 3/4] Update IntelliToolPolygon.cpp --- src/Tool/IntelliToolPolygon.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 8d3e26d..9088d31 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -1,5 +1,6 @@ #include "IntelliToolPolygon.h" #include "Layer/PaintingArea.h" +#include "IntelliHelper/IntelliHelper.h" #include #include @@ -53,11 +54,14 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ this->Canvas->image->calculateVisiblity(); PointIsNearStart = false; isDrawing = false; + std::vector Triangles = IntelliHelper::calculateTriangles(QPointList); + QPoint Point(0,0); for(int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ - if(/*funktion(QPointList,i,j)*/false){ + Point.setX(i); + Point.setY(j); + if(IntelliHelper::isInPolygon(Triangles,Point)){ this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor()); - continue; } } } From 1de2f55e856e4963f91375e2312e1a6fb8e875c9 Mon Sep 17 00:00:00 2001 From: Mienek Date: Thu, 19 Dec 2019 12:05:31 +0100 Subject: [PATCH 4/4] Documentation --- src/Tool/IntelliToolPolygon.cpp | 6 ++--- src/Tool/IntelliToolPolygon.h | 46 ++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 9088d31..d075529 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -1,6 +1,5 @@ #include "IntelliToolPolygon.h" #include "Layer/PaintingArea.h" -#include "IntelliHelper/IntelliHelper.h" #include #include @@ -11,6 +10,8 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c PointIsNearStart = false; drawingPoint.setX(0); drawingPoint.setY(0); + Point.setX(0); + Point.setY(0); } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ @@ -54,8 +55,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ this->Canvas->image->calculateVisiblity(); PointIsNearStart = false; isDrawing = false; - std::vector Triangles = IntelliHelper::calculateTriangles(QPointList); - QPoint Point(0,0); + Triangles = IntelliHelper::calculateTriangles(QPointList); for(int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ Point.setX(i); diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index fc51ec6..da9fa7c 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -2,12 +2,20 @@ #define INTELLITOOLPOLYGON_H #include "IntelliTool.h" +#include "IntelliHelper/IntelliHelper.h" #include #include - +/*! + * \brief The IntelliToolPolygon managed the Drawing of Polygonforms + */ class IntelliToolPolygon : public IntelliTool { public: + /*! + * \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters + * \param Area + * \param colorPicker + */ IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker); virtual void onMouseLeftPressed(int x, int y) override; @@ -20,15 +28,51 @@ public: virtual void onMouseMoved(int x, int y) override; private: + /*! + * \brief isNearStart + * \param x + * \param y + * \param Startpoint + * \return true : Near Startpoint, else false + */ bool isNearStart(int x, int y, QPoint Startpoint); + /*! + * \brief lineWidth of the Drawing Polygon + */ int lineWidth; + /*! + * \brief width of the active Layer + */ int width; + /*! + * \brief height of the active Layer + */ int height; + /*! + * \brief isDrawing true while drawing, else false + */ bool isDrawing; + /*! + * \brief PointIsNearStart true, when last click near Startpoint, else false + */ bool PointIsNearStart; + /*! + * \brief drawingPoint Current Point after Left-Click + */ QPoint drawingPoint; + /*! + * \brief Point Needed to look, if Point is in Polygon + */ + QPoint Point; + /*! + * \brief QPointList List of all Points of the Polygon + */ std::vector QPointList; + /*! + * \brief Triangles Transformed QPointList into triangulated Form of the Polygon + */ + std::vector Triangles; };