From c321a181b1c60dd73b1966347724c259a21f640c Mon Sep 17 00:00:00 2001 From: AshBastian Date: Wed, 8 Jan 2020 16:41:56 +0100 Subject: [PATCH] Linenverwaltung --- src/GUI/IntelliPhotoGui.cpp | 4 ++- src/GUI/IntelliPhotoGui.h | 4 ++- src/IntelliHelper/IntelliToolsettings.cpp | 31 ++++++++++++++++++++++- src/IntelliHelper/IntelliToolsettings.h | 4 +++ src/Tool/IntelliToolCircle.cpp | 19 +++++--------- src/Tool/IntelliToolCircle.h | 9 ------- src/Tool/IntelliToolLine.cpp | 10 +++----- src/Tool/IntelliToolLine.h | 4 --- src/Tool/IntelliToolPen.cpp | 10 +++----- src/Tool/IntelliToolPen.h | 4 --- src/Tool/IntelliToolPolygon.cpp | 19 +++++--------- src/Tool/IntelliToolPolygon.h | 10 -------- src/Tool/IntelliToolRectangle.cpp | 17 +++++-------- src/Tool/IntelliToolRectangle.h | 8 ------ 14 files changed, 65 insertions(+), 88 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 6901c10..f605ad3 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -436,9 +436,11 @@ void IntelliPhotoGui::createGui(){ // create Gui elements paintingArea = new PaintingArea(); + Push // set gui elements - mainLayout->addWidget(paintingArea); + mainLayout->addWidget(paintingArea,1,1,10,10); + mainLayout->addWiget(); } void IntelliPhotoGui::setIntelliStyle(){ diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index e76485c..6d478be 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -86,6 +86,8 @@ bool saveFile(const QByteArray &fileFormat); // What we'll draw on PaintingArea* paintingArea; +QPushButton* PushButton; + // The menu widgets QMenu*saveAsMenu; QMenu*fileMenu; @@ -135,7 +137,7 @@ QList actionSaveAs; // main GUI elements QWidget* centralGuiWidget; -QGridLayout*mainLayout; +QGridLayout* mainLayout; }; #endif diff --git a/src/IntelliHelper/IntelliToolsettings.cpp b/src/IntelliHelper/IntelliToolsettings.cpp index 9c8254d..6f95d1c 100644 --- a/src/IntelliHelper/IntelliToolsettings.cpp +++ b/src/IntelliHelper/IntelliToolsettings.cpp @@ -1,4 +1,5 @@ #include "IntelliToolsettings.h" +#include IntelliToolsettings::IntelliToolsettings() { @@ -15,8 +16,36 @@ int IntelliToolsettings::getLineWidth(){ return lineWidth; } +void IntelliToolsettings::setLineWidth(){ + lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); +} + +void IntelliToolsettings::setLineWidth(int LineWidth){ + if(LineWidth < 1){ + LineWidth = 1; + } + else if(LineWidth > 50){ + LineWidth = 50; + } + lineWidth = LineWidth; +} + int IntelliToolsettings::getInnerAlpha(){ - return innerAlpha; + return this->innerAlpha; +} + +void IntelliToolsettings::setInnerAlpha(){ + this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Aplha Input", "Value",0,0,255,1); +} + +void IntelliToolsettings::setInnerAlpha(int innerAlpha){ + if(innerAlpha < 0){ + innerAlpha = 0; + } + else if(innerAlpha > 255){ + innerAlpha = 255; + } + this->innerAlpha = innerAlpha; } IntelliToolsettings::LineStyle IntelliToolsettings::getLinestyle(){ diff --git a/src/IntelliHelper/IntelliToolsettings.h b/src/IntelliHelper/IntelliToolsettings.h index f8618f1..3907bb1 100644 --- a/src/IntelliHelper/IntelliToolsettings.h +++ b/src/IntelliHelper/IntelliToolsettings.h @@ -13,7 +13,11 @@ public: IntelliToolsettings(); virtual ~IntelliToolsettings(); int getLineWidth(); + void setLineWidth(); + void setLineWidth(int LineWidth); int getInnerAlpha(); + void setInnerAlpha(); + void setInnerAlpha(int innerAlpha); LineStyle getLinestyle(); private: diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp index 3ff93b3..6d22618 100644 --- a/src/Tool/IntelliToolCircle.cpp +++ b/src/Tool/IntelliToolCircle.cpp @@ -5,8 +5,6 @@ IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ - 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); this->ActiveType = Tooltype::CIRCLE; } @@ -17,7 +15,7 @@ IntelliToolCircle::~IntelliToolCircle(){ void IntelliToolCircle::drawCircle(int radius){ int outer = radius+20; QColor inner = this->colorPicker->getSecondColor(); - inner.setAlpha(innerAlpha); + inner.setAlpha(Toolsettings->getInnerAlpha()); int yMin, yMax, xMin, xMax; yMin = centerPoint.y()-radius; yMax = centerPoint.y()+radius; @@ -29,14 +27,14 @@ void IntelliToolCircle::drawCircle(int radius){ } //TODO implement circle drawing algorithm bresenham - radius = static_cast(radius +(this->borderWidth/2.)-1.); + radius = static_cast(radius +(Toolsettings->getLineWidth()/2.)-1.); yMin = (centerPoint.y()-radius); yMax = (centerPoint.y()+radius); for(int i=yMin; i<=yMax; i++) { xMin = static_cast(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); xMax = static_cast(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); + this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); + this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); } xMin = (centerPoint.x()-radius); @@ -44,8 +42,8 @@ void IntelliToolCircle::drawCircle(int radius){ for(int i=xMin; i<=xMax; i++) { int yMin = static_cast(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); int yMax = static_cast(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); + this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); + this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); } } @@ -71,10 +69,7 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){ void IntelliToolCircle::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->borderWidth+=value; - if(this->borderWidth<=0) { - this->borderWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } void IntelliToolCircle::onMouseMoved(int x, int y){ diff --git a/src/Tool/IntelliToolCircle.h b/src/Tool/IntelliToolCircle.h index a774f1b..d75665d 100644 --- a/src/Tool/IntelliToolCircle.h +++ b/src/Tool/IntelliToolCircle.h @@ -19,15 +19,6 @@ void drawCircle(int radius); */ QPoint centerPoint; -/*! - * \brief The alpha value of the inner circle. - */ -int innerAlpha; - -/*! - * \brief The width of the outer circle edge. - */ -int borderWidth; public: /*! * \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth. diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index ceac201..0ccd9a1 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -5,7 +5,6 @@ IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ - this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); this->ActiveType = Tooltype::LINE; } @@ -24,7 +23,7 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){ void IntelliToolLine::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->lineStartingPoint=QPoint(x,y); - this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),lineWidth); + this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),Toolsettings->getLineWidth()); Canvas->image->calculateVisiblity(); } @@ -34,10 +33,7 @@ void IntelliToolLine::onMouseLeftReleased(int x, int y){ void IntelliToolLine::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->lineWidth+=value; - if(this->lineWidth<=0) { - this->lineWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } void IntelliToolLine::onMouseMoved(int x, int y){ @@ -46,7 +42,7 @@ void IntelliToolLine::onMouseMoved(int x, int y){ QPoint next(x,y); switch(Toolsettings->getLinestyle()) { case IntelliToolsettings::LineStyle::SOLID_LINE: - this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),lineWidth); + this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),Toolsettings->getLineWidth()); break; case IntelliToolsettings::LineStyle::DOTTED_LINE: QPoint p1 =lineStartingPoint.x() <= next.x() ? lineStartingPoint : next; diff --git a/src/Tool/IntelliToolLine.h b/src/Tool/IntelliToolLine.h index f40178a..1bae946 100644 --- a/src/Tool/IntelliToolLine.h +++ b/src/Tool/IntelliToolLine.h @@ -13,10 +13,6 @@ class IntelliToolLine : public IntelliTool { */ QPoint lineStartingPoint; -/*! - * \brief The width of the line to draw. - */ -int lineWidth; public: /*! diff --git a/src/Tool/IntelliToolPen.cpp b/src/Tool/IntelliToolPen.cpp index 811984f..61af1c4 100644 --- a/src/Tool/IntelliToolPen.cpp +++ b/src/Tool/IntelliToolPen.cpp @@ -6,7 +6,6 @@ IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ - this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1); this->ActiveType = Tooltype::PEN; } @@ -25,7 +24,7 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){ void IntelliToolPen::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->previousPoint=QPoint(x,y); - this->Canvas->image->drawPoint(previousPoint, colorPicker->getFirstColor(), penWidth); + this->Canvas->image->drawPoint(previousPoint, colorPicker->getFirstColor(), Toolsettings->getLineWidth()); Canvas->image->calculateVisiblity(); } @@ -36,7 +35,7 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){ void IntelliToolPen::onMouseMoved(int x, int y){ if(this->isDrawing) { QPoint newPoint(x,y); - this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), penWidth); + this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->previousPoint=newPoint; } IntelliTool::onMouseMoved(x,y); @@ -44,8 +43,5 @@ void IntelliToolPen::onMouseMoved(int x, int y){ void IntelliToolPen::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->penWidth+=value; - if(this->penWidth<=0) { - this->penWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } diff --git a/src/Tool/IntelliToolPen.h b/src/Tool/IntelliToolPen.h index b55ffa1..39aab9e 100644 --- a/src/Tool/IntelliToolPen.h +++ b/src/Tool/IntelliToolPen.h @@ -9,10 +9,6 @@ * \brief The IntelliToolPen class represents a tool to draw a line. */ class IntelliToolPen : public IntelliTool { -/*! - * \brief penWidth - The width of the Pen while drawing. - */ -int penWidth; /*! * \brief point - Represents the previous point to help drawing a line. */ diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index ca8eced..28dfd31 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -6,8 +6,6 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ - this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 255,0,255,1); - lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1); isPointNearStart = false; isDrawing = false; isInside = false; @@ -37,13 +35,13 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ isDrawing = true; QPointList.push_back(drawingPoint); - this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->calculateVisiblity(); } else if(isDrawing && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2){ isPointNearStart = true; - this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->calculateVisiblity(); } else{ @@ -57,7 +55,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ else if(isDrawing) { QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); - this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->calculateVisiblity(); } } @@ -78,7 +76,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; QColor colorTwo(colorPicker->getSecondColor()); - colorTwo.setAlpha(innerAlpha); + colorTwo.setAlpha(Toolsettings->getInnerAlpha()); for(int i = 0; i < activeLayer->width; i++) { for(int j = 0; j < activeLayer->height; j++) { Point = QPoint(i,j); @@ -89,7 +87,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ } for(int i=0; i(QPointList.size()); i++) { int next = static_cast((i+static_cast(1))%static_cast(QPointList.size())); - this->Canvas->image->drawLine(QPointList[static_cast(i)], QPointList[static_cast(next)], colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawLine(QPointList[static_cast(i)], QPointList[static_cast(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); } QPointList.clear(); IntelliTool::onMouseLeftReleased(x,y); @@ -103,12 +101,7 @@ void IntelliToolPolygon::onMouseRightReleased(int x, int y){ void IntelliToolPolygon::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); if(!isDrawing) { - if(lineWidth + value < 10) { - lineWidth += value; - } - if(lineWidth < 1) { - lineWidth = 1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth() + value); } } diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index c6a5641..920a556 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -19,11 +19,6 @@ class IntelliToolPolygon : public IntelliTool */ bool isNearStart(int x, int y, QPoint Startpoint); -/*! - * \brief LineWidth of the drawing polygon. - */ -int lineWidth; - /*! * \brief IsDrawing true while drawing, else false. */ @@ -39,11 +34,6 @@ bool isInside; */ bool isPointNearStart; -/*! - * \brief The alpha value of the inner circle. - */ -int innerAlpha; - /*! * \brief QPointList list of all points of the polygon. */ diff --git a/src/Tool/IntelliToolRectangle.cpp b/src/Tool/IntelliToolRectangle.cpp index 2bb1133..e92eb10 100644 --- a/src/Tool/IntelliToolRectangle.cpp +++ b/src/Tool/IntelliToolRectangle.cpp @@ -4,8 +4,6 @@ IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ - 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); this->ActiveType = Tooltype::RECTANGLE; } @@ -21,14 +19,14 @@ void IntelliToolRectangle::drawRectangle(QPoint otherCorner){ int yMax = std::max(originCorner.y(), otherCorner.y()); QColor clr = colorPicker->getSecondColor(); - clr.setAlpha(innerAlpha); + clr.setAlpha(Toolsettings->getInnerAlpha()); 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(), 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); + this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); } void IntelliToolRectangle::onMouseRightPressed(int x, int y){ @@ -61,8 +59,5 @@ void IntelliToolRectangle::onMouseMoved(int x, int y){ void IntelliToolRectangle::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->borderWidth+=value; - if(this->borderWidth<=0) { - this->borderWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } diff --git a/src/Tool/IntelliToolRectangle.h b/src/Tool/IntelliToolRectangle.h index 41f36f5..041e860 100644 --- a/src/Tool/IntelliToolRectangle.h +++ b/src/Tool/IntelliToolRectangle.h @@ -19,14 +19,6 @@ void drawRectangle(QPoint otherCorner); * \brief origincorner - The first corner point of the rectangle. */ QPoint originCorner; -/*! - * \brief alphaInner- Represents the alpha value of the inside. - */ -int innerAlpha; -/*! - * \brief edgeWidth - The width of the rectangle edges. - */ -int borderWidth; public: /*! * \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth.