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
6 IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
7 : IntelliTool(Area, colorPicker){
8 this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
9 this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
10 }
11
12 IntelliToolCircle::~IntelliToolCircle(){
13
14 }
15
16 void IntelliToolCircle::drawCyrcle(int radius){
17 int outer = radius+20;
18 QColor inner = this->colorPicker->getSecondColor();
19 inner.setAlpha(alphaInner);
20 int yMin, yMax, xMin, xMax;
21 yMin = Middle.y()-radius;
22 yMax = Middle.y()+radius;
23 // x = x0+-sqrt(r2-(y-y0)2)
24 for(int i=yMin; i<=yMax; i++) {
25 xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
26 xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
27 this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
28 }
29
30 //TODO implement circle drawing algorithm bresenham
31 radius = radius +(this->edgeWidth/2.)-1.;
32 yMin = (Middle.y()-radius);
33 yMax = (Middle.y()+radius);
34 for(int i=yMin; i<=yMax; i++) {
35 xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
36 xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
37 this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
38 this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
39 }
40
41 xMin = (Middle.x()-radius);
42 xMax = (Middle.x()+radius);
43 for(int i=xMin; i<=xMax; i++) {
44 int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2));
45 int yMax = Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2));
46 this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
47 this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
48 }
49 }
50
51 void IntelliToolCircle::onMouseRightPressed(int x, int y){
52 IntelliTool::onMouseRightPressed(x,y);
53 }
54
55 void IntelliToolCircle::onMouseRightReleased(int x, int y){
56 IntelliTool::onMouseRightReleased(x,y);
57 }
58
59 void IntelliToolCircle::onMouseLeftPressed(int x, int y){
60 IntelliTool::onMouseLeftPressed(x,y);
61 this->Middle=QPoint(x,y);
62 int radius = 1;
63 drawCyrcle(radius);
64 Canvas->image->calculateVisiblity();
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 this->edgeWidth+=value;
74 if(this->edgeWidth<=0) {
75 this->edgeWidth=1;
76 }
77 }
78
79 void IntelliToolCircle::onMouseMoved(int x, int y){
80 if(this->drawing) {
81 this->Canvas->image->drawPlain(Qt::transparent);
82 QPoint next(x,y);
83 int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
84 drawCyrcle(radius);
85 }
86 IntelliTool::onMouseMoved(x,y);
87 }
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:51
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
IntelliToolCircle::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolCircle.cpp:55
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:38
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:65
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:25
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:36
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:55
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
IntelliToolCircle::~IntelliToolCircle
virtual ~IntelliToolCircle() override
A Destructor.
Definition: IntelliToolCircle.cpp:12
IntelliTool::drawing
bool drawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:53
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
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:79
IntelliToolCircle::IntelliToolCircle
IntelliToolCircle(PaintingArea *Area, IntelliColorPicker *colorPicker)
A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and ed...
Definition: IntelliToolCircle.cpp:6
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:25
IntelliToolCircle::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click released of a mouse.
Definition: IntelliToolCircle.cpp:67
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
IntelliToolCircle.h
IntelliImage::drawPlain
virtual void drawPlain(const QColor &color)
A function that clears the whole image in a given Color.
Definition: IntelliImage.cpp:76
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:59