IntelliPhoto  0.5
IntelliToolFloodFill.cpp
Go to the documentation of this file.
1 #include "IntelliToolFloodFill.h"
2 #include "Layer/PaintingArea.h"
3 #include "QColorDialog"
4 #include "QInputDialog"
5 #include <functional>
6 #include <queue>
7 
9  : IntelliTool(Area, colorPicker){
10 }
11 
13 
14 }
15 
18 }
19 
22 }
23 
25  if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())) {
26  return;
27  }
29 
30  QPoint start(x,y);
31  std::queue<QPoint> Q;
32  Q.push(start);
33 
34  QColor oldColor = this->Active->image->getPixelColor(start);
35  QColor newColor = this->colorPicker->getFirstColor();
36  Canvas->image->drawPixel(start,newColor);
37 
38  QPoint left, right, top, down;
39  while(!Q.empty()) {
40  QPoint Current = Q.front();
41  Q.pop();
42 
43  left = QPoint(Current.x()-1,Current.y() );
44  right = QPoint(Current.x()+1,Current.y() );
45  top = QPoint(Current.x(),Current.y()-1);
46  down = QPoint(Current.x(),Current.y()+1);
47  if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)) {
48  Canvas->image->drawPixel(right,newColor);
49  Q.push(right);
50  }
51  if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)) {
52  Canvas->image->drawPixel(left,newColor);
53  Q.push(left);
54  }
55  if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)) {
56  Canvas->image->drawPixel(top,newColor);
57  Q.push(top);
58  }
59  if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)) {
60  Canvas->image->drawPixel(down,newColor);
61  Q.push(down);
62  }
63  }
64 
66 }
67 
70 }
71 
74 
75 }
76 
79 }
IntelliTool::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y)
A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on....
Definition: IntelliTool.cpp:14
IntelliTool::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y)
A function managing the left click Released of a Mouse. Call this in child classes!
Definition: IntelliTool.cpp:32
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:38
IntelliToolFloodFill::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolFloodFill.cpp:20
IntelliTool::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y)
A function managing the left click Pressed of a Mouse. Resetting the current draw....
Definition: IntelliTool.cpp:25
IntelliImage::drawPixel
virtual void drawPixel(const QPoint &p1, const QColor &color)
A funtcion used to draw a pixel on the Image with the given Color.
Definition: IntelliImage.cpp:44
IntelliToolFloodFill::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click released of a mouse.
Definition: IntelliToolFloodFill.cpp:68
IntelliToolFloodFill::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event.
Definition: IntelliToolFloodFill.cpp:72
IntelliToolFloodFill.h
IntelliToolFloodFill::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y) override
A function managing the left click pressed of a mouse. Sets the point to flood fill around and does t...
Definition: IntelliToolFloodFill.cpp:24
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:36
IntelliToolFloodFill::~IntelliToolFloodFill
virtual ~IntelliToolFloodFill() override
A Destructor.
Definition: IntelliToolFloodFill.cpp:12
IntelliToolFloodFill::IntelliToolFloodFill
IntelliToolFloodFill(PaintingArea *Area, IntelliColorPicker *colorPicker)
A constructor setting the general paintingArea and colorPicker.
Definition: IntelliToolFloodFill.cpp:8
IntelliTool::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y)
A function managing the right click Released of a Mouse. Merging the Canvas to Active....
Definition: IntelliTool.cpp:21
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:48
LayerObject::width
int width
Definition: PaintingArea.h:26
IntelliToolFloodFill::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event.
Definition: IntelliToolFloodFill.cpp:77
IntelliTool
An abstract class that manages the basic events, like mouse clicks or scrolls events.
Definition: IntelliTool.h:13
PaintingArea.h
IntelliColorPicker::getFirstColor
QColor getFirstColor()
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:16
IntelliImage::getPixelColor
virtual QColor getPixelColor(QPoint &point)
A function that returns the pixelcolor at a certain point.
Definition: IntelliImage.cpp:80
LayerObject::height
int height
Definition: PaintingArea.h:27
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliToolFloodFill::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y) override
A function managing the right click pressed of a mouse. Clearing the canvas.
Definition: IntelliToolFloodFill.cpp:16
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:25
IntelliTool::Active
LayerObject * Active
A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or prev...
Definition: IntelliTool.h:43
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:41
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
IntelliTool::onWheelScrolled
virtual void onWheelScrolled(int value)
A function managing the scroll event. A positive value means scrolling outwards. Call this in child c...
Definition: IntelliTool.cpp:46