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
8 IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
9 : IntelliTool(Area, colorPicker, Toolsettings){
10 this->ActiveType = Tooltype::FLOODFILL;
11 }
12
13 IntelliToolFloodFill::~IntelliToolFloodFill(){
14 IntelliTool::onMouseRightPressed(0,0);
15 }
16
17 void IntelliToolFloodFill::onMouseRightPressed(int x, int y){
18 IntelliTool::onMouseRightPressed(x,y);
19 }
20
21 void IntelliToolFloodFill::onMouseRightReleased(int x, int y){
22 IntelliTool::onMouseRightReleased(x,y);
23 }
24
25 void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
26 if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())) {
27 return;
28 }
29 IntelliTool::onMouseLeftPressed(x,y);
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 Canvas->image->drawPixel(start,newColor);
38
39 QPoint left, right, top, down;
40 while(!Q.empty()) {
41 QPoint Current = Q.front();
42 Q.pop();
43
44 left = QPoint(Current.x()-1,Current.y() );
45 right = QPoint(Current.x()+1,Current.y() );
46 top = QPoint(Current.x(),Current.y()-1);
47 down = QPoint(Current.x(),Current.y()+1);
48 if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) {
49 Canvas->image->drawPixel(right,newColor);
50 Q.push(right);
51 }
52 if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) {
53 Canvas->image->drawPixel(left,newColor);
54 Q.push(left);
55 }
56 if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) {
57 Canvas->image->drawPixel(top,newColor);
58 Q.push(top);
59 }
60 if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) {
61 Canvas->image->drawPixel(down,newColor);
62 Q.push(down);
63 }
64 }
65
66 Canvas->image->calculateVisiblity();
67 }
68
69 void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){
70 IntelliTool::onMouseLeftReleased(x,y);
71 }
72
73 void IntelliToolFloodFill::onWheelScrolled(int value){
74 IntelliTool::onWheelScrolled(value);
75
76 }
77
78 void IntelliToolFloodFill::onMouseMoved(int x, int y){
79 IntelliTool::onMouseMoved(x,y);
80 }
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: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:33
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:51
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:26
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:55
IntelliTool::Tooltype::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:69
IntelliToolFloodFill::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event.
Definition: IntelliToolFloodFill.cpp:73
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:37
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:22
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:58
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:63
LayerObject::width
int width
Definition: PaintingArea.h:27
IntelliToolFloodFill::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event.
Definition: IntelliToolFloodFill.cpp:78
IntelliTool
An abstract class that manages the basic events, like mouse clicks or scrolls events.
Definition: IntelliTool.h:14
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:115
LayerObject::height
int height
Definition: PaintingArea.h:28
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:46
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:17
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:26
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:42
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:47
IntelliToolsettings
Definition: IntelliToolsettings.h:4