diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index b265400..6901c10 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -402,13 +402,13 @@ void IntelliPhotoGui::createMenus(){ //Attach all Tool Options toolMenu = new QMenu(tr("&Tools"), this); + toolMenu->addAction(actionCreateCircleTool); + toolMenu->addAction(actionCreateFloodFillTool); + toolMenu->addAction(actionCreateLineTool); toolMenu->addAction(actionCreatePenTool); toolMenu->addAction(actionCreatePlainTool); - toolMenu->addAction(actionCreateLineTool); + toolMenu->addAction(actionCreatePolygonTool); toolMenu->addAction(actionCreateRectangleTool); - toolMenu->addAction(actionCreateCircleTool); - toolMenu->addAction(actionCreatePolygonTool); - toolMenu->addAction(actionCreateFloodFillTool); toolMenu->addSeparator(); toolMenu->addMenu(colorMenu); diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index f4f92f9..638fe99 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -20,7 +20,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ - this->Tool = nullptr; + this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); this->addLayer(200,200,0,0,ImageType::Shaped_Image); layerBundle[0].image->drawPlain(QColor(0,0,255,255)); @@ -145,11 +145,21 @@ void PaintingArea::floodFill(int r, int g, int b, int a){ } void PaintingArea::movePositionActive(int x, int y){ - layerBundle[static_cast(activeLayer)].widthOffset += x; + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } + layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; } void PaintingArea::moveActiveLayer(int idx){ + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } if(idx==1) { this->selectLayerUp(); }else if(idx==-1) { @@ -158,6 +168,11 @@ void PaintingArea::moveActiveLayer(int idx){ } void PaintingArea::slotActivateLayer(int a){ + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } if(a>=0 && a < static_cast(layerBundle.size())) { this->setLayerActive(a); } @@ -262,11 +277,13 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){ } void PaintingArea::wheelEvent(QWheelEvent*event){ - QPoint numDegrees = event->angleDelta() / 8; - if(!numDegrees.isNull()) { - QPoint numSteps = numDegrees / 15; - Tool->onWheelScrolled(numSteps.y()* -1); - } + if(this->Tool != nullptr){ + QPoint numDegrees = event->angleDelta() / 8; + if(!numDegrees.isNull()) { + QPoint numSteps = numDegrees / 15; + Tool->onWheelScrolled(numSteps.y()* -1); + } + } } // QPainter provides functions to draw on the widget @@ -353,3 +370,16 @@ void PaintingArea::createTempTopLayer(int idx){ layerBundle.insert(layerBundle.begin()+idx+1,newLayer); } } + +IntelliTool* PaintingArea::copyActiveTool(){ + switch(Tool->getTooltype()){ + case IntelliTool::Tooltype::CIRCLE: return new IntelliToolCircle(this,&colorPicker); + case IntelliTool::Tooltype::FLOODFILL: return new IntelliToolFloodFill(this,&colorPicker); + case IntelliTool::Tooltype::LINE: return new IntelliToolLine(this,&colorPicker); + case IntelliTool::Tooltype::PEN: return new IntelliToolPen(this,&colorPicker); + case IntelliTool::Tooltype::PLAIN: return new IntelliToolPlainTool(this,&colorPicker); + case IntelliTool::Tooltype::POLYGON: return new IntelliToolPolygon(this,&colorPicker); + case IntelliTool::Tooltype::RECTANGLE: return new IntelliToolRectangle(this,&colorPicker); + default: return nullptr; + } +} diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 05267c8..9719ac0 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -190,6 +190,7 @@ private: void setLayerDimensions(int maxWidth, int maxHeight); void selectLayerUp(); void selectLayerDown(); + IntelliTool* copyActiveTool(); QImage* Canvas; int maxWidth; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index b20c4d1..671a50f 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -79,3 +79,11 @@ void IntelliTool::deleteToolLayer(){ Area->deleteLayer(Area->activeLayer+1); this->Canvas=nullptr; } + +IntelliTool::Tooltype IntelliTool::getTooltype(){ + return ActiveType; +} + +bool IntelliTool::getIsDrawing(){ + return isDrawing; +} diff --git a/src/Tool/IntelliTool.h b/src/Tool/IntelliTool.h index 26b89be..b7d86a5 100644 --- a/src/Tool/IntelliTool.h +++ b/src/Tool/IntelliTool.h @@ -11,6 +11,16 @@ class PaintingArea; * \brief An abstract class that manages the basic events, like mouse clicks or scrolls events. */ class IntelliTool { +public: + enum class Tooltype{ + CIRCLE, + FLOODFILL, + LINE, + PEN, + PLAIN, + POLYGON, + RECTANGLE + }; private: /*! * \brief A function that creates a layer to draw on. @@ -32,6 +42,8 @@ protected: */ PaintingArea* Area; +Tooltype ActiveType; + /*! * \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors. */ @@ -106,6 +118,9 @@ virtual void onWheelScrolled(int value); */ virtual void onMouseMoved(int x, int y); +Tooltype getTooltype(); + +bool getIsDrawing(); }; #endif diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp index 33a5016..67a7e16 100644 --- a/src/Tool/IntelliToolCircle.cpp +++ b/src/Tool/IntelliToolCircle.cpp @@ -7,10 +7,11 @@ IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* col : IntelliTool(Area, colorPicker){ 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; } IntelliToolCircle::~IntelliToolCircle(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolCircle::drawCircle(int radius){ diff --git a/src/Tool/IntelliToolFloodFill.cpp b/src/Tool/IntelliToolFloodFill.cpp index d0dcc34..c91b961 100644 --- a/src/Tool/IntelliToolFloodFill.cpp +++ b/src/Tool/IntelliToolFloodFill.cpp @@ -7,10 +7,11 @@ IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker) : IntelliTool(Area, colorPicker){ + this->ActiveType = Tooltype::FLOODFILL; } IntelliToolFloodFill::~IntelliToolFloodFill(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolFloodFill::onMouseRightPressed(int x, int y){ diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index 71f67c0..e91af5d 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -6,12 +6,13 @@ IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker) : IntelliTool(Area, colorPicker){ this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); + this->ActiveType = Tooltype::LINE; //create checkbox or scroll dialog to get line style this->lineStyle = LineStyle::SOLID_LINE; } IntelliToolLine::~IntelliToolLine(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolLine::onMouseRightPressed(int x, int y){ diff --git a/src/Tool/IntelliToolPen.cpp b/src/Tool/IntelliToolPen.cpp index 30ff5fe..3b9eb09 100644 --- a/src/Tool/IntelliToolPen.cpp +++ b/src/Tool/IntelliToolPen.cpp @@ -7,10 +7,11 @@ IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker) : IntelliTool(Area, colorPicker){ this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1); + this->ActiveType = Tooltype::PEN; } IntelliToolPen::~IntelliToolPen(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolPen::onMouseRightPressed(int x, int y){ diff --git a/src/Tool/IntelliToolPen.h b/src/Tool/IntelliToolPen.h index 1a8985e..32d540a 100644 --- a/src/Tool/IntelliToolPen.h +++ b/src/Tool/IntelliToolPen.h @@ -4,6 +4,7 @@ #include "IntelliTool.h" #include "QColor" #include "QPoint" + /*! * \brief The IntelliToolPen class represents a tool to draw a line. */ diff --git a/src/Tool/IntelliToolPlain.cpp b/src/Tool/IntelliToolPlain.cpp index 092c3c8..f89e01c 100644 --- a/src/Tool/IntelliToolPlain.cpp +++ b/src/Tool/IntelliToolPlain.cpp @@ -4,10 +4,11 @@ IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker) : IntelliTool(Area, colorPicker){ + this->ActiveType = Tooltype::PLAIN; } IntelliToolPlainTool::~IntelliToolPlainTool(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){ diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index e834126..a4a6685 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -5,15 +5,18 @@ #include IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ - 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); + : IntelliTool(Area, colorPicker){ + 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; + this->ActiveType = Tooltype::POLYGON; } IntelliToolPolygon::~IntelliToolPolygon(){ - + if(isDrawing){ + IntelliTool::onMouseRightPressed(0,0); + } } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ @@ -28,9 +31,17 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ this->Canvas->image->calculateVisiblity(); } else if(isDrawing && isNearStart(x,y,QPointList.front())) { - isPointNearStart = true; - this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); - this->Canvas->image->calculateVisiblity(); + if(QPointList.size() > 2){ + isPointNearStart = true; + this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->calculateVisiblity(); + } + else{ + isDrawing = false; + QPointList.clear(); + IntelliTool::onMouseRightPressed(x,y); + } + } else if(isDrawing) { QPoint drawingPoint(x,y); @@ -48,7 +59,7 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){ } void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ - if(isPointNearStart && QPointList.size() > 1) { + if(isPointNearStart) { isPointNearStart = false; isDrawing = false; std::vector Triangles = IntelliHelper::calculateTriangles(QPointList); @@ -96,7 +107,7 @@ bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ bool isNear = false; int StartX = Startpoint.x(); int StartY = Startpoint.y(); - int valueToNear = 10; + int valueToNear = 5; for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) { for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) { diff --git a/src/Tool/IntelliToolRectangle.cpp b/src/Tool/IntelliToolRectangle.cpp index 8a429fa..36f9ba5 100644 --- a/src/Tool/IntelliToolRectangle.cpp +++ b/src/Tool/IntelliToolRectangle.cpp @@ -6,10 +6,11 @@ IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicke : IntelliTool(Area, colorPicker){ 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; } IntelliToolRectangle::~IntelliToolRectangle(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolRectangle::drawRectangle(QPoint otherCorner){