# IntelliPhoto: intelliphoto/src/Tool/IntelliToolCircle.cpp Source File

IntelliToolCircle.cpp
Go to the documentation of this file.
#include "IntelliToolCircle.h"
#include "Layer/PaintingArea.h"
#include "QInputDialog"
#include <cmath>
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
}
IntelliToolCircle::~IntelliToolCircle(){
}
void IntelliToolCircle::drawCyrcle(int radius){
int outer = radius+20;
QColor inner = this->colorPicker->getSecondColor();
inner.setAlpha(alphaInner);
int yMin, yMax, xMin, xMax;
yMin = Middle.y()-radius;
yMax = Middle.y()+radius;
// x = x0+-sqrt(r2-(y-y0)2)
for(int i=yMin; i<=yMax; i++) {
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
}
//TODO implement circle drawing algorithm bresenham
radius = radius +(this->edgeWidth/2.)-1.;
yMin = (Middle.y()-radius);
yMax = (Middle.y()+radius);
for(int i=yMin; i<=yMax; i++) {
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
}
xMin = (Middle.x()-radius);
xMax = (Middle.x()+radius);
for(int i=xMin; i<=xMax; i++) {
int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2));
int yMax = Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2));
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
}
}
void IntelliToolCircle::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y);
}
void IntelliToolCircle::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
}
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->Middle=QPoint(x,y);
int radius = 1;
drawCyrcle(radius);
Canvas->image->calculateVisiblity();
}
void IntelliToolCircle::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y);
}
void IntelliToolCircle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value;
if(this->edgeWidth<=0) {
this->edgeWidth=1;
}
}
void IntelliToolCircle::onMouseMoved(int x, int y){
if(this->drawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
drawCyrcle(radius);
}
IntelliTool::onMouseMoved(x,y);
}
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