IntelliPhoto 0.7

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
6 IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
7 : IntelliTool(Area, colorPicker, Toolsettings){
8 this->ActiveType = Tooltype::CIRCLE;
9 }
10
11 IntelliToolCircle::~IntelliToolCircle(){
12 IntelliTool::onMouseRightPressed(0,0);
13 }
14
15 void IntelliToolCircle::drawCircle(int radius){
16 QColor inner = this->colorPicker->getSecondColor();
17 inner.setAlpha(Toolsettings->getInnerAlpha());
18 int yMinimum, yMaximum, xMinimum, xMaximum;
19 yMinimum = centerPoint.y() - radius;
20 yMaximum = centerPoint.y() + radius;
21 // x = x0+-sqrt(r2-(y-y0)2)
22 for(int i = yMinimum; i<=yMaximum; i++) {
23 xMinimum = static_cast<int>(centerPoint.x() - sqrt(pow(radius,2) - pow(i - centerPoint.y(),2)));
24 xMaximum = static_cast<int>(centerPoint.x() + sqrt(pow(radius,2) - pow(i - centerPoint.y(),2)));
25 this->Canvas->image->drawLine(QPoint(xMinimum,i), QPoint(xMaximum,i),inner,1);
26 }
27
28 //TODO implement circle drawing algorithm bresenham
29 radius = static_cast<int>(radius + (Toolsettings->getLineWidth() / 2.));
30 yMinimum = (centerPoint.y() - radius);
31 yMaximum = (centerPoint.y() + radius);
32 for(int i = yMinimum; i<=yMaximum; i++) {
33 xMinimum = static_cast<int>(centerPoint.x() - sqrt(pow(radius,2) - pow(i - centerPoint.y(),2)));
34 xMaximum = static_cast<int>(centerPoint.x() + sqrt(pow(radius,2) - pow(i - centerPoint.y(),2)));
35 this->Canvas->image->drawPoint(QPoint(xMinimum,i), colorPicker->getFirstColor(),Toolsettings->getLineWidth());
36 this->Canvas->image->drawPoint(QPoint(xMaximum,i), colorPicker->getFirstColor(),Toolsettings->getLineWidth());
37 }
38
39 xMinimum = (centerPoint.x() - radius);
40 xMaximum = (centerPoint.x() + radius);
41 for(int i = xMinimum; i<=xMaximum; i++) {
42 int yMin = static_cast<int>(centerPoint.y() - sqrt(pow(radius,2) - pow(i - centerPoint.x(),2)));
43 int yMax = static_cast<int>(centerPoint.y() + sqrt(pow(radius,2) - pow(i - centerPoint.x(),2)));
44 this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),Toolsettings->getLineWidth());
45 this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),Toolsettings->getLineWidth());
46 }
47 }
48
49 void IntelliToolCircle::onMouseRightPressed(int x, int y){
50 IntelliTool::onMouseRightPressed(x,y);
51 }
52
53 void IntelliToolCircle::onMouseRightReleased(int x, int y){
54 IntelliTool::onMouseRightReleased(x,y);
55 }
56
57 void IntelliToolCircle::onMouseLeftPressed(int x, int y){
58 IntelliTool::onMouseLeftPressed(x,y);
59 if(this->isDrawing) {
60 this->centerPoint = QPoint(x,y);
61 int radius = 1;
62 drawCircle(radius);
63 Canvas->image->calculateVisiblity();
64 }
65 }
66
67 void IntelliToolCircle::onMouseLeftReleased(int x, int y){
68 IntelliTool::onMouseLeftReleased(x,y);
69 }
70
71 void IntelliToolCircle::onWheelScrolled(int value){
72 IntelliTool::onWheelScrolled(value);
73 Toolsettings->setLineWidth(Toolsettings->getLineWidth() + value);
74 }
75
76 void IntelliToolCircle::onMouseMoved(int x, int y){
77 if(this->isDrawing) {
78 this->Canvas->image->drawPlain(Qt::transparent);
79 QPoint next(x,y);
80 int radius = static_cast<int>(sqrt(pow((centerPoint.x() - x),2) + pow((centerPoint.y() - y),2)));
81 drawCircle(radius);
82 }
83 IntelliTool::onMouseMoved(x,y);
84 }
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:49
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
IntelliToolsettings::getLineWidth
int getLineWidth() const
getLineWidth returns the width attribute of the line.
Definition: IntelliToolsettings.cpp:14
IntelliToolCircle::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolCircle.cpp:53
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:64
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:97
IntelliToolCircle::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event. Changing the edge Width relative to value.
Definition: IntelliToolCircle.cpp:71
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
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Toolsettings a refrence to the tool settings.
Definition: IntelliTool.h:69
IntelliToolsettings::getInnerAlpha
int getInnerAlpha() const
getInnerAlpha returns the inner alpha value.
Definition: IntelliToolsettings.cpp:28
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:57
IntelliTool::isDrawing
bool isDrawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:84
IntelliColorPicker::getSecondColor
QColor getSecondColor() const
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:19
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A function that draws a point between on a given point in a given color.
Definition: IntelliImage.cpp:78
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::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:79
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:17
PaintingArea.h
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
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:76
LayerObject::image
IntelliImage * image
image - Stores the imageData of the current LayerObject.
Definition: PaintingArea.h:27
IntelliToolCircle::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click released of a mouse.
Definition: IntelliToolCircle.cpp:67
IntelliToolsettings::setLineWidth
void setLineWidth(int LineWidth)
setLineWidth sets the width attribute of the line.
Definition: IntelliToolsettings.cpp:18
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
IntelliToolCircle.h
IntelliToolsettings
The IntelliToolsettings class managing the settings of the tools, independent of an existing tool.
Definition: IntelliToolsettings.h:9
IntelliImage::drawPlain
virtual void drawPlain(const QColor &color)
A function that clears the whole image in a given Color.
Definition: IntelliImage.cpp:117
IntelliTool::Tooltype::CIRCLE
@ 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:57