IntelliPhoto  0.5
IntelliToolCircle.cpp
Go to the documentation of this file.
1 #include "IntelliToolCircle.h"
2 #include "Layer/PaintingArea.h"
3 #include "QInputDialog"
4 #include <cmath>
5 
7  : IntelliTool(Area, colorPicker, Toolsettings){
9 }
10 
13 }
14 
15 void IntelliToolCircle::drawCircle(int radius){
16  int outer = radius+20;
17  QColor inner = this->colorPicker->getSecondColor();
18  inner.setAlpha(Toolsettings->getInnerAlpha());
19  int yMin, yMax, xMin, xMax;
20  yMin = centerPoint.y()-radius;
21  yMax = centerPoint.y()+radius;
22  // x = x0+-sqrt(r2-(y-y0)2)
23  for(int i=yMin; i<=yMax; i++) {
24  xMin = static_cast<int>(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
25  xMax = static_cast<int>(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
26  this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
27  }
28 
29  //TODO implement circle drawing algorithm bresenham
30  radius = static_cast<int>(radius +(Toolsettings->getLineWidth()/2.)-1.);
31  yMin = (centerPoint.y()-radius);
32  yMax = (centerPoint.y()+radius);
33  for(int i=yMin; i<=yMax; i++) {
34  xMin = static_cast<int>(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
35  xMax = static_cast<int>(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2)));
38  }
39 
40  xMin = (centerPoint.x()-radius);
41  xMax = (centerPoint.x()+radius);
42  for(int i=xMin; i<=xMax; i++) {
43  int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
44  int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
47  }
48 }
49 
52 }
53 
56 }
57 
60  this->centerPoint=QPoint(x,y);
61  int radius = 1;
62  drawCircle(radius);
64 }
65 
68 }
69 
73 }
74 
76  if(this->isDrawing) {
77  this->Canvas->image->drawPlain(Qt::transparent);
78  QPoint next(x,y);
79  int radius = static_cast<int>(sqrt(pow((centerPoint.x()-x),2)+pow((centerPoint.y()-y),2)));
80  drawCircle(radius);
81  }
83 }
IntelliToolCircle::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y) override
A function managing the right click pressed of a mouse. Clearing the canvas layer.
Definition: IntelliToolCircle.cpp:50
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
IntelliToolCircle::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolCircle.cpp:54
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:51
IntelliImage::drawLine
virtual void drawLine(const QPoint &p1, const QPoint &p2, const QColor &color, const int &penWidth)
A function that draws A Line between two given Points in a given color.
Definition: IntelliImage.cpp:88
IntelliToolCircle::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event. Changing the edge Width relative to value.
Definition: IntelliToolCircle.cpp:70
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
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:53
IntelliToolsettings::setLineWidth
void setLineWidth()
Definition: IntelliToolsettings.cpp:19
IntelliColorPicker::getSecondColor
QColor getSecondColor()
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:20
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:37
IntelliTool::isDrawing
bool isDrawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:68
IntelliToolsettings::getInnerAlpha
int getInnerAlpha()
Definition: IntelliToolsettings.cpp:33
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:72
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::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:63
IntelliToolCircle::IntelliToolCircle
IntelliToolCircle(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings)
A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and ed...
Definition: IntelliToolCircle.cpp:6
IntelliToolCircle::~IntelliToolCircle
virtual ~IntelliToolCircle() override
A Destructor.
Definition: IntelliToolCircle.cpp:11
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
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:46
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliToolCircle::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event. Draws a circle with radius of eulerian norm of mouse posit...
Definition: IntelliToolCircle.cpp:75
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:26
IntelliToolCircle::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click released of a mouse.
Definition: IntelliToolCircle.cpp:66
IntelliToolsettings::getLineWidth
int getLineWidth()
Definition: IntelliToolsettings.cpp:15
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
IntelliToolCircle.h
IntelliToolsettings
Definition: IntelliToolsettings.h:4
IntelliImage::drawPlain
virtual void drawPlain(const QColor &color)
A function that clears the whole image in a given Color.
Definition: IntelliImage.cpp:105
IntelliTool::Tooltype::CIRCLE
IntelliToolCircle::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y) override
A function managing the left click pressed of a mouse. Sets the middle point of the cricle.
Definition: IntelliToolCircle.cpp:58