Refractoring Update 2

- Adjusted variable names to naming conventions
- Concluded header files
This commit is contained in:
2019-12-20 10:05:57 +01:00
parent 52292ebfe7
commit d81afbb8ee
17 changed files with 93 additions and 157 deletions

View File

@@ -23,7 +23,7 @@ virtual ~IntelliColorPicker();
/*!
* \brief A function switching primary and secondary color.
*/
void switchColors();
void swapColors();
/*!
* \brief A function to read the primary selected color.

View File

@@ -1,64 +0,0 @@
#ifndef INTELLITOOLSETCOLORTOOL_H
#define INTELLITOOLSETCOLORTOOL_H
#include "QColor"
#include "QPoint"
#include "QColorDialog"
/*!
* \brief The IntelliColorPicker manages the selected colors for one whole project.
*/
class IntelliColorPicker {
public:
/*!
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
*/
IntelliColorPicker();
/*!
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
*/
virtual ~IntelliColorPicker();
/*!
* \brief A function switching primary and secondary color.
*/
void swapColors();
/*!
* \brief A function to read the primary selected color.
* \return Returns the primary color.
*/
QColor getFirstColor();
/*!
* \brief A function to read the secondary selected color.
* \return Returns the secondary color.
*/
QColor getSecondColor();
/*!
* \brief A function to set the primary color.
* \param Color - The color to be set as primary.
*/
void setFirstColor(QColor Color);
/*!
* \brief A function to set the secondary color.
* \param Color - The color to be set as secondary.
*/
void setSecondColor(QColor Color);
private:
/*!
* \brief The primary color.
*/
QColor firstColor;
/*!
* \brief The secondary color.
*/
QColor secondColor;
};
#endif // INTELLITOOLSETCOLORTOOL_H

View File

@@ -341,7 +341,7 @@ void PaintingArea::drawLayers(bool forSaving){
}
}
void PaintingArea::createTempLayerAfter(int idx){
void PaintingArea::createTempTopLayer(int idx){
if(idx>=0) {
LayerObject newLayer;
newLayer.alpha = 255;

View File

@@ -90,7 +90,7 @@ public:
* \param type - Defining the ImageType of the new layer
* \return Returns the id of the layer position
*/
int addLayerAt(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image, int idx);
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
/*!
* \brief The deleteLayer method removes a layer at a given index
* \param index - The index of the layer to be removed

View File

@@ -12,8 +12,8 @@ IntelliTool::~IntelliTool(){
}
void IntelliTool::onMouseRightPressed(int x, int y){
if(drawing) {
drawing=false;
if(isDrawing) {
isDrawing=false;
this->deleteToolLayer();
}
}
@@ -23,23 +23,23 @@ void IntelliTool::onMouseRightReleased(int x, int y){
}
void IntelliTool::onMouseLeftPressed(int x, int y){
this->drawing=true;
this->isDrawing=true;
//create drawing layer
this->createToolLayer();
Canvas->image->calculateVisiblity();
}
void IntelliTool::onMouseLeftReleased(int x, int y){
if(drawing) {
drawing=false;
if(isDrawing) {
isDrawing=false;
this->mergeToolLayer();
this->deleteToolLayer();
Active->image->calculateVisiblity();
activeLayer->image->calculateVisiblity();
}
}
void IntelliTool::onMouseMoved(int x, int y){
if(drawing)
if(isDrawing)
Canvas->image->calculateVisiblity();
}
@@ -49,16 +49,16 @@ void IntelliTool::onWheelScrolled(int value){
void IntelliTool::createToolLayer(){
Area->createTempTopLayer(Area->activeLayer);
this->Active=&Area->layerBundle[Area->activeLayer];
this->activeLayer=&Area->layerBundle[Area->activeLayer];
this->Canvas=&Area->layerBundle[Area->activeLayer+1];
}
void IntelliTool::mergeToolLayer(){
QColor clr_0;
QColor clr_1;
for(int y=0; y<Active->height; y++) {
for(int x=0; x<Active->width; x++) {
clr_0=Active->image->imageData.pixelColor(x,y);
for(int y=0; y<activeLayer->height; y++) {
for(int x=0; x<activeLayer->width; x++) {
clr_0=activeLayer->image->imageData.pixelColor(x,y);
clr_1=Canvas->image->imageData.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f;
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
@@ -70,7 +70,7 @@ void IntelliTool::mergeToolLayer(){
clr_0.setBlue(b);
clr_0.setAlpha(a);
Active->image->imageData.setPixelColor(x, y, clr_0);
activeLayer->image->imageData.setPixelColor(x, y, clr_0);
}
}
}

View File

@@ -40,7 +40,7 @@ IntelliColorPicker* colorPicker;
/*!
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
*/
LayerObject* Active;
LayerObject* activeLayer;
/*!
* \brief A pointer to the drawing canvas of the tool, work on this.
@@ -50,7 +50,7 @@ LayerObject* Canvas;
/*!
* \brief A flag checking if the user is currently drawing or not.
*/
bool drawing = false;
bool isDrawing = false;
public:
/*!

View File

@@ -5,46 +5,46 @@
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);
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
}
IntelliToolCircle::~IntelliToolCircle(){
}
void IntelliToolCircle::drawCyrcle(int radius){
void IntelliToolCircle::drawCircle(int radius){
int outer = radius+20;
QColor inner = this->colorPicker->getSecondColor();
inner.setAlpha(alphaInner);
inner.setAlpha(innerAlpha);
int yMin, yMax, xMin, xMax;
yMin = Middle.y()-radius;
yMax = Middle.y()+radius;
yMin = centerPoint.y()-radius;
yMax = centerPoint.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));
xMin = centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2));
xMax = centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.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);
radius = radius +(this->borderWidth/2.)-1.;
yMin = (centerPoint.y()-radius);
yMax = (centerPoint.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 = centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2));
xMax = centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2));
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),borderWidth);
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),borderWidth);
}
xMin = (Middle.x()-radius);
xMax = (Middle.x()+radius);
xMin = (centerPoint.x()-radius);
xMax = (centerPoint.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);
int yMin = centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2));
int yMax = centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2));
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),borderWidth);
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),borderWidth);
}
}
@@ -58,9 +58,9 @@ void IntelliToolCircle::onMouseRightReleased(int x, int y){
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->Middle=QPoint(x,y);
this->centerPoint=QPoint(x,y);
int radius = 1;
drawCyrcle(radius);
drawCircle(radius);
Canvas->image->calculateVisiblity();
}
@@ -70,18 +70,18 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){
void IntelliToolCircle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value;
if(this->edgeWidth<=0) {
this->edgeWidth=1;
this->borderWidth+=value;
if(this->borderWidth<=0) {
this->borderWidth=1;
}
}
void IntelliToolCircle::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
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);
int radius = static_cast<int>(sqrt(pow((centerPoint.x()-x),2)+pow((centerPoint.y()-y),2)));
drawCircle(radius);
}
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -12,22 +12,22 @@ class IntelliToolCircle : public IntelliTool {
* \brief A function that implements a circle drawing algorithm.
* \param radius - The radius of the circle.
*/
void drawCyrcle(int radius);
void drawCircle(int radius);
/*!
* \brief The center of the circle.
*/
QPoint Middle;
QPoint centerPoint;
/*!
* \brief The alpha value of the inner circle.
*/
int alphaInner;
int innerAlpha;
/*!
* \brief The width of the outer circle edge.
*/
int edgeWidth;
int borderWidth;
public:
/*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth.

View File

@@ -31,7 +31,7 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
std::queue<QPoint> Q;
Q.push(start);
QColor oldColor = this->Active->image->getPixelColor(start);
QColor oldColor = this->activeLayer->image->getPixelColor(start);
QColor newColor = this->colorPicker->getFirstColor();
Canvas->image->drawPixel(start,newColor);
@@ -44,19 +44,19 @@ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
right = QPoint(Current.x()+1,Current.y() );
top = QPoint(Current.x(),Current.y()-1);
down = QPoint(Current.x(),Current.y()+1);
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)) {
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (activeLayer->image->getPixelColor(right) == oldColor)) {
Canvas->image->drawPixel(right,newColor);
Q.push(right);
}
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)) {
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (activeLayer->image->getPixelColor(left) == oldColor)) {
Canvas->image->drawPixel(left,newColor);
Q.push(left);
}
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)) {
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (activeLayer->image->getPixelColor(top) == oldColor)) {
Canvas->image->drawPixel(top,newColor);
Q.push(top);
}
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)) {
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (activeLayer->image->getPixelColor(down) == oldColor)) {
Canvas->image->drawPixel(down,newColor);
Q.push(down);
}

View File

@@ -24,8 +24,8 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
void IntelliToolLine::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->start=QPoint(x,y);
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
this->lineStartingPoint=QPoint(x,y);
this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),lineWidth);
Canvas->image->calculateVisiblity();
}
@@ -42,18 +42,18 @@ void IntelliToolLine::onWheelScrolled(int value){
}
void IntelliToolLine::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
switch(lineStyle) {
case LineStyle::SOLID_LINE:
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),lineWidth);
break;
case LineStyle::DOTTED_LINE:
QPoint p1 =start.x() <= next.x() ? start : next;
QPoint p2 =start.x() < next.x() ? next : start;
QPoint p1 =lineStartingPoint.x() <= next.x() ? lineStartingPoint : next;
QPoint p2 =lineStartingPoint.x() < next.x() ? next : lineStartingPoint;
int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f;
int c = start.y()-start.x()*m;
int c = lineStartingPoint.y()-lineStartingPoint.x()*m;
break;
}

View File

@@ -19,7 +19,7 @@ class IntelliToolLine : public IntelliTool {
/*!
* \brief The starting point of the line.
*/
QPoint start;
QPoint lineStartingPoint;
/*!
* \brief The width of the line to draw.

View File

@@ -23,8 +23,8 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){
void IntelliToolPen::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->point=QPoint(x,y);
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
this->previousPoint=QPoint(x,y);
this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor());
Canvas->image->calculateVisiblity();
}
@@ -33,10 +33,10 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){
}
void IntelliToolPen::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
QPoint newPoint(x,y);
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
this->point=newPoint;
this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), penWidth);
this->previousPoint=newPoint;
}
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -15,7 +15,7 @@ int penWidth;
/*!
* \brief point - Represents the previous point to help drawing a line.
*/
QPoint point;
QPoint previousPoint;
public:
/*!
* \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth.

View File

@@ -6,9 +6,9 @@
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);;
PointIsNearStart = false;
isPointNearStart = false;
isDrawing = false;
}
@@ -28,7 +28,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
this->Canvas->image->calculateVisiblity();
}
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
PointIsNearStart = true;
isPointNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity();
}
@@ -42,21 +42,21 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
isDrawing = false;
PointIsNearStart = false;
isPointNearStart = false;
QPointList.clear();
IntelliTool::onMouseRightPressed(x,y);
}
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(PointIsNearStart && QPointList.size() > 1) {
PointIsNearStart = false;
if(isPointNearStart && QPointList.size() > 1) {
isPointNearStart = false;
isDrawing = false;
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
QPoint Point;
QColor colorTwo(colorPicker->getSecondColor());
colorTwo.setAlpha(alphaInner);
for(int i = 0; i < Active->width; i++) {
for(int j = 0; j < Active->height; j++) {
colorTwo.setAlpha(innerAlpha);
for(int i = 0; i < activeLayer->width; i++) {
for(int j = 0; j < activeLayer->height; j++) {
Point = QPoint(i,j);
if(IntelliHelper::isInPolygon(Triangles,Point)) {
this->Canvas->image->drawPixel(Point, colorTwo);

View File

@@ -32,12 +32,12 @@ bool isDrawing;
/*!
* \brief PointIsNearStart true, when last click near startpoint, else false.
*/
bool PointIsNearStart;
bool isPointNearStart;
/*!
* \brief The alpha value of the inner circle.
*/
int alphaInner;
int innerAlpha;
/*!
* \brief QPointList list of all points of the polygon.

View File

@@ -4,8 +4,8 @@
IntelliToolRectangle::IntelliToolRectangle(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);
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
}
IntelliToolRectangle::~IntelliToolRectangle(){
@@ -20,14 +20,14 @@ void IntelliToolRectangle::drawRectangle(QPoint otherCorner){
int yMax = std::max(originCorner.y(), otherCorner.y());
QColor clr = colorPicker->getSecondColor();
clr.setAlpha(alphaInner);
clr.setAlpha(innerAlpha);
for(int y=yMin; y<=yMax; y++) {
this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1);
}
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth);
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth);
}
void IntelliToolRectangle::onMouseRightPressed(int x, int y){
@@ -50,7 +50,7 @@ void IntelliToolRectangle::onMouseLeftReleased(int x, int y){
}
void IntelliToolRectangle::onMouseMoved(int x, int y){
if(this->drawing) {
if(this->isDrawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
drawRectangle(next);
@@ -60,8 +60,8 @@ void IntelliToolRectangle::onMouseMoved(int x, int y){
void IntelliToolRectangle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value;
if(this->edgeWidth<=0) {
this->edgeWidth=1;
this->borderWidth+=value;
if(this->borderWidth<=0) {
this->borderWidth=1;
}
}

View File

@@ -22,11 +22,11 @@ QPoint originCorner;
/*!
* \brief alphaInner- Represents the alpha value of the inside.
*/
int alphaInner;
int innerAlpha;
/*!
* \brief edgeWidth - The width of the rectangle edges.
*/
int edgeWidth;
int borderWidth;
public:
/*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth.