From ca9395901b347253db8aeee90e0138e5c5c96141 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Fri, 13 Dec 2019 13:20:55 +0100 Subject: [PATCH 01/17] Cryle Tool --- .gitignore | 1 + src/Image/IntelliImage.cpp | 10 +++++ src/Image/IntelliImage.h | 1 + src/IntelliPhoto.pro | 5 ++- src/Layer/PaintingArea.cpp | 5 ++- src/Tool/IntelliToolCircle.cpp | 80 ++++++++++++++++++++++++++++++++++ src/Tool/IntelliToolCircle.h | 26 +++++++++++ 7 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 src/Tool/IntelliToolCircle.cpp create mode 100644 src/Tool/IntelliToolCircle.h diff --git a/.gitignore b/.gitignore index f4c35fb..a9a564c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ CMakeLists.txt.user* /share/qtcreator/fonts/ /share/qtcreator/generic-highlighter/ /share/qtcreator/qmldesigner/QtProject/ +/build-*/ app_version.h phony.c diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 74b7891..f5ae7a1 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -52,6 +52,16 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ painter.drawPoint(p1); } +void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ + // Used to draw on the widget + QPainter painter(&imageData); + + // Set the current settings for the pen + painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + // Draw a line from the last registered point to the current + painter.drawPoint(p1); +} + void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ // Used to draw on the widget QPainter painter(&imageData); diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index 14e9ec2..347cae6 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -30,6 +30,7 @@ public: //start on top left virtual void drawPixel(const QPoint &p1, const QColor& color); + virtual void drawPoint(const QPoint &p1, const QColor& color, const int& penWidth); virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth); virtual void drawPlain(const QColor& color); diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index 7d3580d..de708ac 100644 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -24,6 +24,7 @@ SOURCES += \ IntelliHelper/IntelliHelper.cpp \ Layer/PaintingArea.cpp \ Tool/IntelliTool.cpp \ + Tool/IntelliToolCircle.cpp \ Tool/IntelliToolLine.cpp \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ @@ -38,9 +39,11 @@ HEADERS += \ IntelliHelper/IntelliHelper.h \ Layer/PaintingArea.h \ Tool/IntelliTool.h \ + Tool/IntelliToolCircle.h \ Tool/IntelliToolLine.h \ Tool/IntelliToolPen.h \ - Tool/IntelliToolPlain.h + Tool/IntelliToolPlain.h \ + Tool/intellitoolcircle.h FORMS += \ widget.ui diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 7fff2a9..03f7e9c 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -13,11 +13,12 @@ #include "Tool/IntelliToolPen.h" #include "Tool/IntelliToolPlain.h" #include "Tool/IntelliToolLine.h" +#include "Tool/IntelliToolCircle.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ - this->Tool = nullptr; + this->Tool = new IntelliToolCircle(this, &colorPicker); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); @@ -33,7 +34,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) layerBundle[1].image->drawPlain(QColor(0,255,0,255)); layerBundle[1].alpha=200; - activeLayer=0; + activeLayer=1; } PaintingArea::~PaintingArea(){ diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp new file mode 100644 index 0000000..7e16e77 --- /dev/null +++ b/src/Tool/IntelliToolCircle.cpp @@ -0,0 +1,80 @@ +#include "IntelliToolCircle.h" +#include "Layer/PaintingArea.h" +#include "QInputDialog" +#include + +IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker) + :IntelliTool(Area, colorPicker){ + this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); + this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1); +} + +IntelliToolCircle::~IntelliToolCircle(){ + +} + +void IntelliToolCircle::drawCyrcle(int radius){ + int outer = radius+20; + QColor inner = this->colorPicker->getSecondColor(); + inner.setAlpha(alphaInner); + int yMin, yMax, xMin, xMax; + yMin = Middle.y()-radius; + yMax = Middle.y()+radius; + // x = x0+-sqrt(r2-(y-y0)2) + for(int i=yMin; i<=yMax; i++){ + xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)); + xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2)); + this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1); + } + + //TODO implement circle drawing algorithm + radius = radius +(this->edgeWidth/2.)-0.5; + yMin = (Middle.y()-radius); + yMax = (Middle.y()+radius); + for(int i=yMin; i<=yMax; i++){ + xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)); + xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2)); + this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth); + this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth); + } + + xMin = (Middle.x()-radius); + xMax = (Middle.x()+radius); + for(int i=xMin; i<=xMax; i++){ + int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2)); + int yMax = Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2)); + this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth); + this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth); + } +} + +void IntelliToolCircle::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolCircle::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolCircle::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + this->Middle=QPoint(x,y); + int radius = 1; + drawCyrcle(radius); + Canvas->image->calculateVisiblity(); +} + +void IntelliToolCircle::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolCircle::onMouseMoved(int x, int y){ + IntelliTool::onMouseMoved(x,y); + if(this->drawing){ + this->Canvas->image->drawPlain(Qt::transparent); + QPoint next(x,y); + int radius = static_cast(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2))); + drawCyrcle(radius); + } + IntelliTool::onMouseMoved(x,y); +} diff --git a/src/Tool/IntelliToolCircle.h b/src/Tool/IntelliToolCircle.h new file mode 100644 index 0000000..93e7af3 --- /dev/null +++ b/src/Tool/IntelliToolCircle.h @@ -0,0 +1,26 @@ +#ifndef INTELLITOOLCIRCLE_H +#define INTELLITOOLCIRCLE_H +#include "IntelliTool.h" + +#include "QColor" +#include "QPoint" + +class IntelliToolCircle : public IntelliTool{ + void drawCyrcle(int radius); + + QPoint Middle; + int alphaInner; + int edgeWidth; +public: + IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker); + virtual ~IntelliToolCircle() override; + + virtual void onMouseRightPressed(int x, int y); + virtual void onMouseRightReleased(int x, int y); + virtual void onMouseLeftPressed(int x, int y); + virtual void onMouseLeftReleased(int x, int y); + + virtual void onMouseMoved(int x, int y); +}; + +#endif // INTELLITOOLCIRCLE_H From 9da13bc002e653fdd020b2bf7f2015757d01d146 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Fri, 13 Dec 2019 13:21:27 +0100 Subject: [PATCH 02/17] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f4c35fb..a9a564c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ CMakeLists.txt.user* /share/qtcreator/fonts/ /share/qtcreator/generic-highlighter/ /share/qtcreator/qmldesigner/QtProject/ +/build-*/ app_version.h phony.c From ce331cafa8f0f57935f0103e0cd16f049ed63c8c Mon Sep 17 00:00:00 2001 From: Sonaion Date: Fri, 13 Dec 2019 13:24:42 +0100 Subject: [PATCH 03/17] testing for tools --- src/Layer/PaintingArea.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index f38ad31..a5eb6a3 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -17,7 +17,8 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ - this->Tool = new IntelliToolCircle(this, &colorPicker); + //test yout tool here and reset after accomplished test + this->Tool = nullptr; this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); From 1c29d564c796f9c4e1bb1d6ca2cf77d41a7e2a96 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Fri, 13 Dec 2019 13:47:32 +0100 Subject: [PATCH 04/17] rectangle tool --- src/IntelliPhoto.pro | 2 ++ src/Layer/PaintingArea.cpp | 1 + src/Tool/IntelliToolRechteck.cpp | 60 ++++++++++++++++++++++++++++++++ src/Tool/IntelliToolRechteck.h | 27 ++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 src/Tool/IntelliToolRechteck.cpp create mode 100644 src/Tool/IntelliToolRechteck.h diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index de708ac..47bf20e 100644 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -28,6 +28,7 @@ SOURCES += \ Tool/IntelliToolLine.cpp \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ + Tool/IntelliToolRechteck.cpp \ main.cpp HEADERS += \ @@ -43,6 +44,7 @@ HEADERS += \ Tool/IntelliToolLine.h \ Tool/IntelliToolPen.h \ Tool/IntelliToolPlain.h \ + Tool/IntelliToolRechteck.h \ Tool/intellitoolcircle.h FORMS += \ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index a5eb6a3..4ec5ea3 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -14,6 +14,7 @@ #include "Tool/IntelliToolPlain.h" #include "Tool/IntelliToolLine.h" #include "Tool/IntelliToolCircle.h" +#include "Tool/IntelliToolRechteck.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ diff --git a/src/Tool/IntelliToolRechteck.cpp b/src/Tool/IntelliToolRechteck.cpp new file mode 100644 index 0000000..ded8346 --- /dev/null +++ b/src/Tool/IntelliToolRechteck.cpp @@ -0,0 +1,60 @@ +#include"IntelliToolRechteck.h" +#include "Layer/PaintingArea.h" +#include "QInputDialog" + +IntelliToolRechteck::IntelliToolRechteck(PaintingArea* Area, IntelliColorPicker* colorPicker) + :IntelliTool(Area, colorPicker){ + this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); + this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1); +} + +IntelliToolRechteck::~IntelliToolRechteck(){ + +} + +void IntelliToolRechteck::drawRechteck(QPoint otherCornor){ + int xMin = std::min(originCornor.x(), otherCornor.x()); + int xMax = std::max(originCornor.x(), otherCornor.x()); + + int yMin = std::min(originCornor.y(), otherCornor.y()); + int yMax = std::max(originCornor.y(), otherCornor.y()); + + QColor clr = colorPicker->getSecondColor(); + clr.setAlpha(alphaInner); + for(int y=yMin; y<=yMax; y++){ + this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1); + } + this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth); + this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth); + this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth); + this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth); +} + +void IntelliToolRechteck::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolRechteck::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolRechteck::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + this->originCornor=QPoint(x,y); + drawRechteck(originCornor); + Canvas->image->calculateVisiblity(); +} + +void IntelliToolRechteck::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolRechteck::onMouseMoved(int x, int y){ + IntelliTool::onMouseMoved(x,y); + if(this->drawing){ + this->Canvas->image->drawPlain(Qt::transparent); + QPoint next(x,y); + drawRechteck(next); + } + IntelliTool::onMouseMoved(x,y); +} diff --git a/src/Tool/IntelliToolRechteck.h b/src/Tool/IntelliToolRechteck.h new file mode 100644 index 0000000..76886bc --- /dev/null +++ b/src/Tool/IntelliToolRechteck.h @@ -0,0 +1,27 @@ +#ifndef INTELLIRECHTECKTOOL_H +#define INTELLIRECHTECKTOOL_H + +#include "IntelliTool.h" + +#include "QColor" +#include "QPoint" + +class IntelliToolRechteck : public IntelliTool{ + void drawRechteck(QPoint otherCornor); + + QPoint originCornor; + int alphaInner; + int edgeWidth; +public: + IntelliToolRechteck(PaintingArea* Area, IntelliColorPicker* colorPicker); + virtual ~IntelliToolRechteck() override; + + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; + + virtual void onMouseMoved(int x, int y) override; +}; + +#endif // INTELLIRECHTECKTOOL_H From 67a72fe4879f6e26c55dc49df623bc22d195b161 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Mon, 16 Dec 2019 19:23:56 +0100 Subject: [PATCH 05/17] Scroll implemented --- src/Layer/PaintingArea.cpp | 10 +++++++++- src/Layer/PaintingArea.h | 1 + src/Tool/IntelliTool.cpp | 4 ++++ src/Tool/IntelliTool.h | 2 ++ src/Tool/IntelliToolCircle.cpp | 12 ++++++++++-- src/Tool/IntelliToolCircle.h | 12 +++++++----- src/Tool/IntelliToolLine.cpp | 8 ++++++++ src/Tool/IntelliToolLine.h | 2 ++ src/Tool/IntelliToolPen.cpp | 8 ++++++++ src/Tool/IntelliToolPen.h | 2 ++ src/Tool/IntelliToolPlain.cpp | 4 ++++ src/Tool/IntelliToolPlain.h | 13 ++++++++----- src/Tool/IntelliToolRechteck.cpp | 8 ++++++++ src/Tool/IntelliToolRechteck.h | 2 ++ 14 files changed, 75 insertions(+), 13 deletions(-) diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 4ec5ea3..1783a40 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -19,7 +19,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ //test yout tool here and reset after accomplished test - this->Tool = nullptr; + this->Tool = new IntelliToolRechteck(this, &colorPicker); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); @@ -234,6 +234,14 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event){ update(); } +void PaintingArea::wheelEvent(QWheelEvent *event){ + QPoint numDegrees = event->angleDelta() / 8; + if(!numDegrees.isNull()){ + QPoint numSteps = numDegrees / 15; + Tool->onWheelScrolled(numSteps.y()*-1); + } +} + // QPainter provides functions to draw on the widget // The QPaintEvent is sent to widgets that need to // update themselves diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index a4ec3fa..fa85425 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -70,6 +70,7 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; + void wheelEvent(QWheelEvent *event) override; // Updates the painting area where we are painting void paintEvent(QPaintEvent *event) override; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 606459c..608770e 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -43,6 +43,10 @@ void IntelliTool::onMouseMoved(int x, int y){ Canvas->image->calculateVisiblity(); } +void IntelliTool::onWheelScrolled(int value){ + //if needed for future general tasks implement in here +} + void IntelliTool::createToolLayer(){ Area->createTempLayerAfter(Area->activeLayer); this->Active=&Area->layerBundle[Area->activeLayer]; diff --git a/src/Tool/IntelliTool.h b/src/Tool/IntelliTool.h index b534257..2531a55 100644 --- a/src/Tool/IntelliTool.h +++ b/src/Tool/IntelliTool.h @@ -29,6 +29,8 @@ public: virtual void onMouseLeftPressed(int x, int y); virtual void onMouseLeftReleased(int x, int y); + virtual void onWheelScrolled(int value); + virtual void onMouseMoved(int x, int y); }; #endif diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp index 7e16e77..a129d7d 100644 --- a/src/Tool/IntelliToolCircle.cpp +++ b/src/Tool/IntelliToolCircle.cpp @@ -27,8 +27,8 @@ void IntelliToolCircle::drawCyrcle(int radius){ this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1); } - //TODO implement circle drawing algorithm - radius = radius +(this->edgeWidth/2.)-0.5; + //TODO implement circle drawing algorithm bresenham + radius = radius +(this->edgeWidth/2.)-1.; yMin = (Middle.y()-radius); yMax = (Middle.y()+radius); for(int i=yMin; i<=yMax; i++){ @@ -68,6 +68,14 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){ IntelliTool::onMouseLeftReleased(x,y); } +void IntelliToolCircle::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->edgeWidth+=value; + if(this->edgeWidth<=0){ + this->edgeWidth=1; + } +} + void IntelliToolCircle::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); if(this->drawing){ diff --git a/src/Tool/IntelliToolCircle.h b/src/Tool/IntelliToolCircle.h index 93e7af3..488bdb4 100644 --- a/src/Tool/IntelliToolCircle.h +++ b/src/Tool/IntelliToolCircle.h @@ -15,12 +15,14 @@ public: IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker); virtual ~IntelliToolCircle() override; - virtual void onMouseRightPressed(int x, int y); - virtual void onMouseRightReleased(int x, int y); - virtual void onMouseLeftPressed(int x, int y); - virtual void onMouseLeftReleased(int x, int y); + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; - virtual void onMouseMoved(int x, int y); + virtual void onWheelScrolled(int value) override; + + virtual void onMouseMoved(int x, int y) override; }; #endif // INTELLITOOLCIRCLE_H diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index b3f1bf7..0b088cd 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -34,6 +34,14 @@ void IntelliToolLine::onMouseLeftReleased(int x, int y){ IntelliTool::onMouseLeftReleased(x,y); } +void IntelliToolLine::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->lineWidth+=value; + if(this->lineWidth<=0){ + this->lineWidth=1; + } +} + void IntelliToolLine::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); if(this->drawing){ diff --git a/src/Tool/IntelliToolLine.h b/src/Tool/IntelliToolLine.h index ffde866..af1f874 100644 --- a/src/Tool/IntelliToolLine.h +++ b/src/Tool/IntelliToolLine.h @@ -24,6 +24,8 @@ public: virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override; + virtual void onWheelScrolled(int value) override; + virtual void onMouseMoved(int x, int y) override; }; diff --git a/src/Tool/IntelliToolPen.cpp b/src/Tool/IntelliToolPen.cpp index 14db6dd..8012970 100644 --- a/src/Tool/IntelliToolPen.cpp +++ b/src/Tool/IntelliToolPen.cpp @@ -40,3 +40,11 @@ void IntelliToolPen::onMouseMoved(int x, int y){ } IntelliTool::onMouseMoved(x,y); } + +void IntelliToolPen::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->penWidth+=value; + if(this->penWidth<=0){ + this->penWidth=1; + } +} diff --git a/src/Tool/IntelliToolPen.h b/src/Tool/IntelliToolPen.h index a5acc49..c923ddd 100644 --- a/src/Tool/IntelliToolPen.h +++ b/src/Tool/IntelliToolPen.h @@ -17,6 +17,8 @@ public: virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override; + virtual void onWheelScrolled(int value) override; + virtual void onMouseMoved(int x, int y) override; }; diff --git a/src/Tool/IntelliToolPlain.cpp b/src/Tool/IntelliToolPlain.cpp index aaa2a02..34e3c5f 100644 --- a/src/Tool/IntelliToolPlain.cpp +++ b/src/Tool/IntelliToolPlain.cpp @@ -28,3 +28,7 @@ void IntelliToolPlainTool::onMouseRightReleased(int x, int y){ void IntelliToolPlainTool::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); } + +void IntelliToolPlainTool::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); +} diff --git a/src/Tool/IntelliToolPlain.h b/src/Tool/IntelliToolPlain.h index 9ff1b7a..aad7633 100644 --- a/src/Tool/IntelliToolPlain.h +++ b/src/Tool/IntelliToolPlain.h @@ -8,11 +8,14 @@ class IntelliToolPlainTool : public IntelliTool{ public: IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker); - void onMouseLeftPressed(int x, int y) override; - void onMouseLeftReleased(int x, int y) override; - void onMouseRightPressed(int x, int y) override; - void onMouseRightReleased(int x, int y) override; - void onMouseMoved(int x, int y) override; + 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; }; diff --git a/src/Tool/IntelliToolRechteck.cpp b/src/Tool/IntelliToolRechteck.cpp index ded8346..05b1e79 100644 --- a/src/Tool/IntelliToolRechteck.cpp +++ b/src/Tool/IntelliToolRechteck.cpp @@ -58,3 +58,11 @@ void IntelliToolRechteck::onMouseMoved(int x, int y){ } IntelliTool::onMouseMoved(x,y); } + +void IntelliToolRechteck::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + this->edgeWidth+=value; + if(this->edgeWidth<=0){ + this->edgeWidth=1; + } +} diff --git a/src/Tool/IntelliToolRechteck.h b/src/Tool/IntelliToolRechteck.h index 76886bc..f3db883 100644 --- a/src/Tool/IntelliToolRechteck.h +++ b/src/Tool/IntelliToolRechteck.h @@ -21,6 +21,8 @@ public: virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override; + virtual void onWheelScrolled(int value) override; + virtual void onMouseMoved(int x, int y) override; }; From 21ade765631f3a2416f31204915f16e06d0c39a1 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Mon, 16 Dec 2019 19:29:12 +0100 Subject: [PATCH 06/17] Update .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a9a564c..e431211 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # Build folders -src/build-*/ +/build-*/ # QT Creator Files *.creator.user* @@ -13,7 +13,6 @@ CMakeLists.txt.user* /share/qtcreator/fonts/ /share/qtcreator/generic-highlighter/ /share/qtcreator/qmldesigner/QtProject/ -/build-*/ app_version.h phony.c From a025ab5da53c3b51ba69c6afb7a107b06743b06d Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 11:41:52 +0100 Subject: [PATCH 07/17] Removed comment cause it ain't --- src/GUI/IntelliPhotoGui.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index a25999b..c2cae43 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -16,7 +16,6 @@ IntelliPhotoGui::IntelliPhotoGui(){ createMenus(); //set style of the gui setIntelliStyle(); - // Size the app showMaximized(); } @@ -28,7 +27,6 @@ void IntelliPhotoGui::closeEvent(QCloseEvent *event){ if (maybeSave()) { event->accept(); } else { - // If there have been changes ignore the event event->ignore(); } @@ -234,7 +232,7 @@ void IntelliPhotoGui::slotCreateLineTool(){ void IntelliPhotoGui::slotAboutDialog(){ // Window title and text to display QMessageBox::about(this, tr("About Painting"), - tr("

IntelliPhoto Some nice ass looking software

")); + tr("

IntelliPhotoPretty basic editor.

")); } // Define menu actions that call functions From 9e4cf9a07f21fef3d484d594bd0720030ef3cd30 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 12:44:00 +0100 Subject: [PATCH 08/17] Removed blank lines --- src/Layer/PaintingArea.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index fa85425..b6cebc1 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -21,8 +21,6 @@ struct LayerObject{ int widthOffset; int hightOffset; int alpha=255; - - }; class PaintingArea : public QWidget @@ -83,7 +81,6 @@ private: void activateUpperLayer(); void activateLowerLayer(); - QImage* Canvas; int maxWidth; int maxHeight; @@ -104,4 +101,3 @@ private: }; #endif - From a0f1203fb1465ee9a0e6b6d3ef3dd3b524e10a50 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 13:02:25 +0100 Subject: [PATCH 09/17] Fixed a bug where the system dialogs wouldn't show up on linux Thx to @Jan for this contribution and testing --- src/GUI/IntelliPhotoGui.cpp | 2 +- src/Layer/PaintingArea.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index c2cae43..4be552e 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -460,7 +460,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){ initialPath, tr("%1 Files (*.%2);;All Files (*)") .arg(QString::fromLatin1(fileFormat.toUpper())) - .arg(QString::fromLatin1(fileFormat))); + .arg(QString::fromLatin1(fileFormat)), nullptr, QFileDialog::DontUseNativeDialog); // If no file do nothing if (fileName.isEmpty()) { diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 1783a40..2009465 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -164,12 +164,12 @@ void PaintingArea::slotActivateLayer(int a){ } void PaintingArea::colorPickerSetFirstColor(){ - QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color"); + QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color", QColorDialog::DontUseNativeDialog); this->colorPicker.setFirstColor(clr); } void PaintingArea::colorPickerSetSecondColor(){ - QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color"); + QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color", QColorDialog::DontUseNativeDialog); this->colorPicker.setSecondColor(clr); } From 325d1925aca738b8025c07e05a2b2cfe9ee02037 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 13:08:21 +0100 Subject: [PATCH 10/17] Fixed a bug where the File Dialog wouldn't show up correctly on linux --- src/GUI/IntelliPhotoGui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 4be552e..a5dde2f 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -43,7 +43,7 @@ void IntelliPhotoGui::slotOpen(){ // tr sets the window title to Open File // QDir opens the current dirctory QString fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), QDir::currentPath()); + tr("Open File"), QDir::currentPath(), "", nullptr, QFileDialog::DontUseNativeDialog); // If we have a file name load the image and place // it in the paintingArea From bbc733a8b5733c69e83748a74774cfa95f776eda Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 13:11:50 +0100 Subject: [PATCH 11/17] Replaced empty string with nullpointer to dodge warning --- src/GUI/IntelliPhotoGui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index a5dde2f..1de336a 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -43,7 +43,7 @@ void IntelliPhotoGui::slotOpen(){ // tr sets the window title to Open File // QDir opens the current dirctory QString fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), QDir::currentPath(), "", nullptr, QFileDialog::DontUseNativeDialog); + tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog); // If we have a file name load the image and place // it in the paintingArea From 56dfdcc5339f87ba9a6e7c751f579052b8348552 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 18 Dec 2019 12:16:37 +0100 Subject: [PATCH 12/17] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e431211..a86d544 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Build folders +src/build-*/ /build-*/ # QT Creator Files From d193dc3b978e494fde94f3920beae0b5e9a24148 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 18 Dec 2019 12:31:03 +0100 Subject: [PATCH 13/17] Edited the dialogs to work as intendet on linux and also fixed set second color --- src/GUI/IntelliPhotoGui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 1de336a..283170c 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -43,7 +43,7 @@ void IntelliPhotoGui::slotOpen(){ // tr sets the window title to Open File // QDir opens the current dirctory QString fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog); + tr("Open File"), QDir::currentPath(),"", nullptr, QFileDialog::DontUseNativeDialog); // If we have a file name load the image and place // it in the paintingArea @@ -274,6 +274,7 @@ void IntelliPhotoGui::createActions(){ // Create New Layer action and tie to IntelliPhotoGui::newLayer() actionCreateNewLayer = new QAction(tr("&New Layer..."), this); + actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer())); // Delete New Layer action and tie to IntelliPhotoGui::deleteLayer() @@ -315,7 +316,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)); From d1d3599daa74e3b6a2f1f1e786db420c611ebf26 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 13:28:41 +0100 Subject: [PATCH 14/17] Merged gitignore statements --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a86d544..e8e6a7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Build folders -src/build-*/ -/build-*/ +build-*/ # QT Creator Files *.creator.user* From 55345224406cc500385c0ed770ad8cc88b9a5b41 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 12:42:10 +0100 Subject: [PATCH 15/17] Refractoring of "Rechteck" to "rectangle" --- src/IntelliPhoto.pro | 4 ++-- src/Layer/PaintingArea.cpp | 4 ++-- ...lRechteck.cpp => IntelliToolRectangle.cpp} | 24 +++++++++---------- ...iToolRechteck.h => IntelliToolRectangle.h} | 14 +++++------ 4 files changed, 23 insertions(+), 23 deletions(-) rename src/Tool/{IntelliToolRechteck.cpp => IntelliToolRectangle.cpp} (73%) rename src/Tool/{IntelliToolRechteck.h => IntelliToolRectangle.h} (61%) diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index 47bf20e..9b0956d 100644 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -28,7 +28,7 @@ SOURCES += \ Tool/IntelliToolLine.cpp \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ - Tool/IntelliToolRechteck.cpp \ + Tool/IntelliToolRectangle.cpp \ main.cpp HEADERS += \ @@ -44,7 +44,7 @@ HEADERS += \ Tool/IntelliToolLine.h \ Tool/IntelliToolPen.h \ Tool/IntelliToolPlain.h \ - Tool/IntelliToolRechteck.h \ + Tool/IntelliToolRectangle.h \ Tool/intellitoolcircle.h FORMS += \ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 1783a40..95ef554 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -14,12 +14,12 @@ #include "Tool/IntelliToolPlain.h" #include "Tool/IntelliToolLine.h" #include "Tool/IntelliToolCircle.h" -#include "Tool/IntelliToolRechteck.h" +#include "Tool/IntelliToolRectangle.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 IntelliToolRectangle(this, &colorPicker); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); diff --git a/src/Tool/IntelliToolRechteck.cpp b/src/Tool/IntelliToolRectangle.cpp similarity index 73% rename from src/Tool/IntelliToolRechteck.cpp rename to src/Tool/IntelliToolRectangle.cpp index 05b1e79..0c89762 100644 --- a/src/Tool/IntelliToolRechteck.cpp +++ b/src/Tool/IntelliToolRectangle.cpp @@ -1,18 +1,18 @@ -#include"IntelliToolRechteck.h" +#include"IntelliToolRectangle.h" #include "Layer/PaintingArea.h" #include "QInputDialog" -IntelliToolRechteck::IntelliToolRechteck(PaintingArea* Area, IntelliColorPicker* colorPicker) +IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker) :IntelliTool(Area, colorPicker){ this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1); } -IntelliToolRechteck::~IntelliToolRechteck(){ +IntelliToolRectangle::~IntelliToolRectangle(){ } -void IntelliToolRechteck::drawRechteck(QPoint otherCornor){ +void IntelliToolRectangle::drawRectangle(QPoint otherCornor){ int xMin = std::min(originCornor.x(), otherCornor.x()); int xMax = std::max(originCornor.x(), otherCornor.x()); @@ -30,36 +30,36 @@ void IntelliToolRechteck::drawRechteck(QPoint otherCornor){ this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth); } -void IntelliToolRechteck::onMouseRightPressed(int x, int y){ +void IntelliToolRectangle::onMouseRightPressed(int x, int y){ IntelliTool::onMouseRightPressed(x,y); } -void IntelliToolRechteck::onMouseRightReleased(int x, int y){ +void IntelliToolRectangle::onMouseRightReleased(int x, int y){ IntelliTool::onMouseRightReleased(x,y); } -void IntelliToolRechteck::onMouseLeftPressed(int x, int y){ +void IntelliToolRectangle::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->originCornor=QPoint(x,y); - drawRechteck(originCornor); + drawRectangle(originCornor); Canvas->image->calculateVisiblity(); } -void IntelliToolRechteck::onMouseLeftReleased(int x, int y){ +void IntelliToolRectangle::onMouseLeftReleased(int x, int y){ IntelliTool::onMouseLeftReleased(x,y); } -void IntelliToolRechteck::onMouseMoved(int x, int y){ +void IntelliToolRectangle::onMouseMoved(int x, int y){ IntelliTool::onMouseMoved(x,y); if(this->drawing){ this->Canvas->image->drawPlain(Qt::transparent); QPoint next(x,y); - drawRechteck(next); + drawRectangle(next); } IntelliTool::onMouseMoved(x,y); } -void IntelliToolRechteck::onWheelScrolled(int value){ +void IntelliToolRectangle::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); this->edgeWidth+=value; if(this->edgeWidth<=0){ diff --git a/src/Tool/IntelliToolRechteck.h b/src/Tool/IntelliToolRectangle.h similarity index 61% rename from src/Tool/IntelliToolRechteck.h rename to src/Tool/IntelliToolRectangle.h index f3db883..2b59629 100644 --- a/src/Tool/IntelliToolRechteck.h +++ b/src/Tool/IntelliToolRectangle.h @@ -1,20 +1,20 @@ -#ifndef INTELLIRECHTECKTOOL_H -#define INTELLIRECHTECKTOOL_H +#ifndef INTELLIRECTANGLETOOL_H +#define INTELLIRECTANGLETOOL_H #include "IntelliTool.h" #include "QColor" #include "QPoint" -class IntelliToolRechteck : public IntelliTool{ - void drawRechteck(QPoint otherCornor); +class IntelliToolRectangle : public IntelliTool{ + void drawRectangle(QPoint otherCornor); QPoint originCornor; int alphaInner; int edgeWidth; public: - IntelliToolRechteck(PaintingArea* Area, IntelliColorPicker* colorPicker); - virtual ~IntelliToolRechteck() override; + IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker); + virtual ~IntelliToolRectangle() override; virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override; @@ -26,4 +26,4 @@ public: virtual void onMouseMoved(int x, int y) override; }; -#endif // INTELLIRECHTECKTOOL_H +#endif // INTELLIRECTANGLETOOL_H From 3ad975a297c84d4d3c00c0af04eea067541deee8 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 18 Dec 2019 13:48:53 +0100 Subject: [PATCH 16/17] Changed empty string to nullpointer for file options --- src/GUI/IntelliPhotoGui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 283170c..16c8074 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -43,7 +43,7 @@ void IntelliPhotoGui::slotOpen(){ // tr sets the window title to Open File // QDir opens the current dirctory QString fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), QDir::currentPath(),"", nullptr, QFileDialog::DontUseNativeDialog); + tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog); // If we have a file name load the image and place // it in the paintingArea From 4953abc791d1b43b9d82251200228cb439acf797 Mon Sep 17 00:00:00 2001 From: Sonaion Date: Wed, 18 Dec 2019 16:32:11 +0100 Subject: [PATCH 17/17] Integrated Polygon Test Use calculate traingles and the isInPolygon with theese triangles, this is done because of performance reasons --- src/Image/IntelliShapedImage.cpp | 23 ++---- src/Image/IntelliShapedImage.h | 4 + src/IntelliHelper/IntelliHelper.cpp | 121 ++++++++++++++++++++++++++++ src/IntelliHelper/IntelliHelper.h | 22 +++-- src/main.cpp | 2 + 5 files changed, 150 insertions(+), 22 deletions(-) diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 0dbc807..dbf6e48 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -35,26 +35,18 @@ void IntelliShapedImage::calculateVisiblity(){ } return; } - QPoint A = polygonData[0]; QColor clr; for(int y=0; y(polygonData.size()-1); i++){ - QPoint B = polygonData[static_cast(i)]; - QPoint C = polygonData[static_cast(i+1)]; - QPoint P(x,y); - cutNumeber+=IntelliHelper::isInTriangle(A,B,C,P); - } - if(cutNumeber%2==0){ - clr = imageData.pixelColor(x,y); - clr.setAlpha(0); - imageData.setPixelColor(x,y,clr); - }else{ - clr = imageData.pixelColor(x,y); + QPoint ptr(x,y); + clr = imageData.pixelColor(x,y); + bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr); + if(isInPolygon){ clr.setAlpha(std::min(255, clr.alpha())); - imageData.setPixelColor(x,y,clr); + }else{ + clr.setAlpha(0); } + imageData.setPixelColor(x,y,clr); } } } @@ -79,6 +71,7 @@ void IntelliShapedImage::setPolygon(const std::vector& polygonData){ for(auto element:polygonData){ this->polygonData.push_back(QPoint(element.x(), element.y())); } + triangles = IntelliHelper::calculateTriangles(polygonData); } calculateVisiblity(); return; diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 0a3598e..9e9518f 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -2,9 +2,13 @@ #define INTELLISHAPE_H #include"Image/IntelliRasterImage.h" +#include +#include"IntelliHelper/IntelliHelper.h" class IntelliShapedImage : public IntelliRasterImage{ friend IntelliTool; +private: + std::vector triangles; protected: std::vector polygonData; diff --git a/src/IntelliHelper/IntelliHelper.cpp b/src/IntelliHelper/IntelliHelper.cpp index cb5d6a8..42b8aab 100644 --- a/src/IntelliHelper/IntelliHelper.cpp +++ b/src/IntelliHelper/IntelliHelper.cpp @@ -1,2 +1,123 @@ #include"IntelliHelper.h" #include +#include +#include + + +std::vector IntelliHelper::calculateTriangles(std::vector polyPoints){ + //helper for managing the triangle vertices and their state + struct TriangleHelper{ + QPoint vertex; + float interiorAngle; + int index; + bool isTip; + }; + + //calculates the inner angle of 'point' + auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){ + QPoint AP(point.x()-prev.x(), point.y()-prev.y()); + QPoint BP(point.x()-post.x(), point.y()-post.y()); + + float topSclar = AP.x()*BP.x()+AP.y()*BP.y(); + float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.)); + return acos(topSclar/absolute); + }; + + //gets the first element of vec for which element.isTip == true holds + auto getTip= [](const std::vector& vec){ + for(auto element:vec){ + if(element.isTip){ + return element; + } + } + return vec[0]; + }; + + //get the vertex Index bevor index in relation to the container length + auto getPrev = [](int index, int length){ + return (index-1)>0?(index-1):(length-1); + }; + + //get the vertex Index after index in relation to the container lenght + auto getPost = [](int index, int length){ + return (index+1)%length; + }; + + //return if the vertex is a tip + auto isTip = [](float angle){ + return angle<180.f; + }; + + std::vector Vertices; + std::vector Triangles; + + //set up all vertices and calculate intirior angle + for(int i=0; i(polyPoints.size()); i++){ + TriangleHelper helper; + int prev = getPrev(i, static_cast(polyPoints.size())); + int post = getPost(i, static_cast(polyPoints.size())); + + helper.vertex = polyPoints[static_cast(i)]; + helper.index = i; + + helper.interiorAngle = calculateInner(polyPoints[static_cast(i)], + polyPoints[static_cast(prev)], + polyPoints[static_cast(post)]); + helper.isTip = isTip(helper.interiorAngle); + Vertices.push_back(helper); + } + + //search triangles based on the intirior angles of each vertey + while(Triangles.size() != polyPoints.size()-2){ + Triangle tri; + TriangleHelper smallest = getTip(Vertices); + int prev = getPrev(smallest.index, static_cast(Vertices.size())); + int post = getPost(smallest.index, static_cast(Vertices.size())); + + //set triangle and push it + tri.A = Vertices[static_cast(prev)].vertex; + tri.B = Vertices[static_cast(smallest.index)].vertex; + tri.C = Vertices[static_cast(post)].vertex; + Triangles.push_back(tri); + + //update Vertice array + Vertices.erase(Vertices.begin()+smallest.index); + for(size_t i=static_cast(smallest.index); i(Vertices.size())); + int postOfPrev = getPost(prev, static_cast(Vertices.size())); + + int prevOfPost = getPrev(post, static_cast(Vertices.size())); + int postOfPost = getPost(post, static_cast(Vertices.size())); + + //update vertices with interior angles + //updtae prev + Vertices[static_cast(prev)].interiorAngle = calculateInner(Vertices[static_cast(prev)].vertex, + Vertices[static_cast(prevOfPrev)].vertex, + Vertices[static_cast(postOfPrev)].vertex); + Vertices[static_cast(prev)].isTip = isTip(Vertices[static_cast(prev)].interiorAngle); + //update post + Vertices[static_cast(post)].interiorAngle = calculateInner(Vertices[static_cast(post)].vertex, + Vertices[static_cast(prevOfPost)].vertex, + Vertices[static_cast(postOfPost)].vertex); + Vertices[static_cast(post)].isTip = isTip(Vertices[static_cast(post)].interiorAngle); + + } + return Triangles; +} + +bool IntelliHelper::isInPolygon(std::vector &triangles, QPoint &point){ + for(auto triangle : triangles){ + if(IntelliHelper::isInTriangle(triangle.A ,triangle.B, triangle.C, point)){ + return true; + } + } + return false; +} diff --git a/src/IntelliHelper/IntelliHelper.h b/src/IntelliHelper/IntelliHelper.h index 1bad2b9..e01aff9 100644 --- a/src/IntelliHelper/IntelliHelper.h +++ b/src/IntelliHelper/IntelliHelper.h @@ -2,17 +2,20 @@ #define INTELLIHELPER_H #include +#include + +struct Triangle{ + QPoint A,B,C; +}; + +namespace IntelliHelper { -class IntelliHelper{ - -public: - - static inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){ + inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){ return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y()); } - static inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){ + inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){ float val1, val2, val3; bool neg, pos; @@ -25,6 +28,11 @@ public: return !(neg && pos); } -}; + + std::vector calculateTriangles(std::vector polyPoints); + + bool isInPolygon(std::vector &triangles, QPoint &point); + +} #endif diff --git a/src/main.cpp b/src/main.cpp index 771a872..c8e501c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include "GUI/IntelliPhotoGui.h" #include #include +#include "IntelliHelper/IntelliHelper.h" +#include int main(int argc, char *argv[]){ // The main application