IntelliPhoto  0.7
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, Toolsettings){
11 }
12 
15 }
16 
19 }
20 
23 }
24 
26  if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())) {
27  return;
28  }
30 
31  QPoint start(x,y);
32  std::queue<QPoint> Q;
33  Q.push(start);
34 
35  QColor oldColor = this->activeLayer->image->getPixelColor(start);
36  QColor newColor = this->colorPicker->getFirstColor();
37  if(newColor == oldColor) {
38  return;
39  }
40  Canvas->image->drawPixel(start,newColor);
41 
42  QPoint left, right, top, down;
43  while(!Q.empty()) {
44  QPoint Current = Q.front();
45  Q.pop();
46 
47  left = QPoint(Current.x() - 1,Current.y() );
48  right = QPoint(Current.x() + 1,Current.y() );
49  top = QPoint(Current.x(),Current.y() - 1);
50  down = QPoint(Current.x(),Current.y() + 1);
51  if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) {
52  Canvas->image->drawPixel(right,newColor);
53  Q.push(right);
54  }
55  if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) {
56  Canvas->image->drawPixel(left,newColor);
57  Q.push(left);
58  }
59  if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) {
60  Canvas->image->drawPixel(top,newColor);
61  Q.push(top);
62  }
63  if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) {
64  Canvas->image->drawPixel(down,newColor);
65  Q.push(down);
66  }
67  }
68 
70 }
71 
74 }
75 
78 
79 }
80 
83 }
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:19
IntelliColorPicker::getFirstColor
QColor getFirstColor() const
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:15
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:37
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:64
IntelliToolFloodFill::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolFloodFill.cpp:21
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:30
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:58
IntelliTool::Tooltype::FLOODFILL
@ FLOODFILL
IntelliToolFloodFill::IntelliToolFloodFill
IntelliToolFloodFill(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings)
A constructor setting the general paintingArea and colorPicker.
Definition: IntelliToolFloodFill.cpp:8
IntelliToolFloodFill::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click released of a mouse.
Definition: IntelliToolFloodFill.cpp:72
IntelliToolFloodFill::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event.
Definition: IntelliToolFloodFill.cpp:76
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:25
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:57
IntelliToolFloodFill::~IntelliToolFloodFill
virtual ~IntelliToolFloodFill() override
A Destructor.
Definition: IntelliToolFloodFill.cpp:13
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:26
IntelliTool::activeLayer
LayerObject * activeLayer
A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or prev...
Definition: IntelliTool.h:74
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:79
LayerObject::width
int width
width - Stores the width of a layer in pixels.
Definition: PaintingArea.h:31
IntelliToolFloodFill::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event.
Definition: IntelliToolFloodFill.cpp:81
IntelliTool
An abstract class that manages the basic events, like mouse clicks or scrolls events.
Definition: IntelliTool.h:17
PaintingArea.h
IntelliImage::getPixelColor
virtual QColor getPixelColor(QPoint &point)
A function that returns the pixelcolor at a certain point.
Definition: IntelliImage.cpp:127
LayerObject::height
int height
height - Stores the height of a layer in pixels.
Definition: PaintingArea.h:35
IntelliTool::ActiveType
Tooltype ActiveType
ActiveType the type of the active tool.
Definition: IntelliTool.h:59
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:14
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:17
LayerObject::image
IntelliImage * image
image - Stores the imageData of the current LayerObject.
Definition: PaintingArea.h:27
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:47
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:52
IntelliToolsettings
The IntelliToolsettings class managing the settings of the tools, independent of an existing tool.
Definition: IntelliToolsettings.h:9