diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 36fce1f..fe1028b 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -78,6 +78,6 @@ void IntelliImage::drawPlain(const QColor& color){ imageData.fill(color); } -QColor IntelliImage::getPixelColor(int x, int y){ - return imageData.pixelColor(x,y); +QColor IntelliImage::getPixelColor(QPoint& point){ + return imageData.pixelColor(point); } diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index 6eeaa72..cf25e9b 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -121,11 +121,10 @@ public: /*! * \brief A function that returns the pixelcolor at a certain point - * \param x - The x-coordinate of the point. - * \param y - The y-coordintae of the point. + * \param point - The point from whcih to get the coordinates. * \return The color of the Pixel as QColor. */ - virtual QColor getPixelColor(int x, int y); + virtual QColor getPixelColor(QPoint& point); }; #endif diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index af9be56..0275c00 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/IntelliToolRectangle.h" +#include "Tool/IntelliToolFloodFill.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ //test yout tool here and reset after accomplished test - this->Tool = new IntelliToolRectangle(this, &colorPicker); + this->Tool = new IntelliToolFloodFill(this, &colorPicker); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); diff --git a/src/Tool/IntelliToolFloodFill.cpp b/src/Tool/IntelliToolFloodFill.cpp new file mode 100644 index 0000000..6d655ea --- /dev/null +++ b/src/Tool/IntelliToolFloodFill.cpp @@ -0,0 +1,77 @@ +#include "IntelliToolFloodFill.h" +#include "Layer/PaintingArea.h" +#include "QColorDialog" +#include "QInputDialog" +#include +#include + +IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker) + :IntelliTool(Area, colorPicker){ +} + +IntelliToolFloodFill::~IntelliToolFloodFill(){ + +} + + +void IntelliToolFloodFill::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolFloodFill::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + + QPoint start(x,y); + std::queue Q; + Q.push(start); + + QColor oldColor = this->Active->image->getPixelColor(start); + QColor newColor = this->colorPicker->getFirstColor(); + Canvas->image->drawPixel(start,newColor); + + QPoint left, right, top, down; + while(!Q.empty()){ + QPoint Current = Q.front(); + Q.pop(); + + left = QPoint(Current.x()-1,Current.y() ); + right = QPoint(Current.x()+1,Current.y() ); + top = QPoint(Current.x() ,Current.y()-1); + down = QPoint(Current.x() ,Current.y()+1); + if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)){ + Canvas->image->drawPixel(right,newColor); + Q.push(right); + } + if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)){ + Canvas->image->drawPixel(left,newColor); + Q.push(left); + } + if((top.y() < Canvas->hight) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)){ + Canvas->image->drawPixel(top,newColor); + Q.push(top); + } + if((down.y() >= 0) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)){ + Canvas->image->drawPixel(down,newColor); + Q.push(down); + } + } + + Canvas->image->calculateVisiblity(); +} + +void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolFloodFill::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); + +} + +void IntelliToolFloodFill::onMouseMoved(int x, int y){ + IntelliTool::onMouseMoved(x,y); +}