diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 01913b4..d7b207b 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -202,35 +202,6 @@ void IntelliPhotoGui::slotMoveLayerDown(){ update(); } -void IntelliPhotoGui::slotClearActiveLayer(){ - // Stores button value - bool ok1, ok2, ok3, ok4; - - // "Red Input" is the title of the window - // the next tr is the text to display - // Define the standard Value, min, max, step and ok button - int red = QInputDialog::getInt(this, tr("Red Input"), - tr("Red:"), - 255,0, 255,1, &ok1); - // "Green Input" is the title of the window - int green = QInputDialog::getInt(this, tr("Green Input"), - tr("Green:"), - 255,0, 255, 1, &ok2); - // "Blue Input" is the title of the window - int blue = QInputDialog::getInt(this, tr("Blue Input"), - tr("Blue:"), - 255,0, 255, 1, &ok3); - // "Alpha Input" is the title of the window - int alpha = QInputDialog::getInt(this, tr("Alpha Input"), - tr("Alpha:"), - 255,0, 255, 1, &ok4); - if (ok1&&ok2&&ok3&&ok4) - { - paintingArea->floodFill(red, green, blue, alpha); - UpdateGui(); - } -} - void IntelliPhotoGui::slotSetActiveLayer(){ // Stores button value bool ok1; @@ -788,6 +759,7 @@ void IntelliPhotoGui::setIntelliStyle(){ this->helpMenu->setPalette(Palette); this->renderMenu->setPalette(Palette); this->toolMenu->setPalette(Palette); + this->layerCreationMenu->setPalette(Palette); this->layerMenu->setPalette(Palette); this->colorMenu->setPalette(Palette); this->toolCreationMenu->setPalette(Palette); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 6d32933..52a022a 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -47,7 +47,6 @@ void slotSave(); void slotCreateNewRasterLayer(); void slotCreateNewShapedLayer(); void slotDeleteLayer(); -void slotClearActiveLayer(); void slotSetActiveLayer(); void slotSetActiveAlpha(); void slotSetPolygon(); diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index a9faacf..9a99f78 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -18,24 +18,13 @@ #include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolPolygon.h" + PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); - this->addLayer(200,200,0,0,IntelliImage::ImageType::SHAPEDIMAGE); - layerBundle[0].image->drawPlain(QColor(0,0,255,255)); - std::vector polygon; - polygon.push_back(QPoint(100,000)); - polygon.push_back(QPoint(200,100)); - polygon.push_back(QPoint(100,200)); - polygon.push_back(QPoint(000,100)); - layerBundle[0].image->setPolygon(polygon); - this->addLayer(200,200,150,150,IntelliImage::ImageType::RASTERIMAGE); - layerBundle[1].image->drawPlain(QColor(0,255,0,255)); - layerBundle[1].alpha=200; - - activeLayer=0; + activeLayer=-1; } PaintingArea::~PaintingArea(){ @@ -64,6 +53,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ LayerObject newLayer; + updateTools(); newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; @@ -80,7 +70,10 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff } -void PaintingArea::deleteLayer(int idx){ +void PaintingArea::deleteLayer(int idx, bool isTool){ + if(!isTool){ + updateTools(); + } if(idx(layerBundle.size())) { this->layerBundle.erase(layerBundle.begin()+idx); if(activeLayer>=idx) { @@ -100,7 +93,8 @@ void PaintingArea::slotDeleteActiveLayer(){ } void PaintingArea::setLayerActive(int idx){ - if(idx>=0&&idx(layerBundle.size())) { + updateTools(); + if(idx>=0&&idx(layerBundle.size())) { this->activeLayer=idx; } } @@ -115,6 +109,7 @@ void PaintingArea::setPolygon(int idx){ if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ delete this->Tool; this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); + isSettingPolygon = true; } } } @@ -155,36 +150,14 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){ } } -// Color the image area with white -void PaintingArea::floodFill(int r, int g, int b, int a){ - if(this->activeLayer==-1) { - return; - } - IntelliImage* active = layerBundle[static_cast(activeLayer)].image; - active->drawPlain(QColor(r, g, b, a)); - update(); -} - void PaintingArea::movePositionActive(int x, int y){ - if(Tool!=nullptr) { - if(Tool->getIsDrawing()) { - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } - } + updateTools(); layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; } void PaintingArea::moveActiveLayer(int idx){ - if(Tool != nullptr) { - if(Tool->getIsDrawing()) { - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } - } + updateTools(); if(idx==1) { this->selectLayerUp(); }else if(idx==-1) { @@ -193,14 +166,8 @@ void PaintingArea::moveActiveLayer(int idx){ } void PaintingArea::slotActivateLayer(int a){ - if(Tool != nullptr) { - if(Tool->getIsDrawing()) { - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } - } - if(a>=0 && a < static_cast(layerBundle.size())) { + updateTools(); + if(a>=0 && a < static_cast(layerBundle.size())) { this->setLayerActive(a); } } @@ -343,7 +310,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){ update(); } -// Resize the image to slightly larger then the main window +//TODOJ Resize the image to slightly larger then the main window // to cut down on the need to resize the image void PaintingArea::resizeEvent(QResizeEvent*event){ //TODO wait till tool works @@ -355,14 +322,16 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){ } void PaintingArea::selectLayerUp(){ - if(activeLayer!=-1 && static_cast(activeLayer)(activeLayer)(activeLayer)], layerBundle[static_cast(activeLayer+1)]); activeLayer++; } } void PaintingArea::selectLayerDown(){ - if(activeLayer!=-1 && activeLayer>0) { + updateTools(); + if(activeLayer!=-1 && activeLayer>0) { std::swap(layerBundle[static_cast(activeLayer)], layerBundle[static_cast(activeLayer-1)]); activeLayer--; } @@ -456,3 +425,18 @@ QImage PaintingArea::getImageDataOfActiveLayer(){ } return returnImage; } + +void PaintingArea::updateTools(){ + if(Tool!=nullptr) { + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } + if(isSettingPolygon){ + delete this->Tool; + this->Tool = nullptr; + isSettingPolygon = false; + } + } +} diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index ac394f5..782a1b7 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -102,8 +102,9 @@ int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffs /*! * \brief The deleteLayer method removes a layer at a given idx * \param idx - The index of the layer to be removed + * \param isTool - Is the flag for when a tool uses this function. */ -void deleteLayer(int idx); +void deleteLayer(int idx, bool isTool = false); /*! * \brief The setLayerToActive method marks a specific layer as active * \param idx - The index of the layer to be active @@ -120,14 +121,6 @@ void setLayerAlpha(int idx, int alpha); * \param idx - represents the number of the layer with should be transformed */ void setPolygon(int idx); -/*! - * \brief The floodFill method fills a the active layer with a given color - * \param r - Red value of the color the layer should be filled with - * \param g - Green value of the color the layer should be filled with - * \param b - Blue value of the color the layer should be filled with - * \param a - Alpha value of the color the layer should be filled with - */ -void floodFill(int r, int g, int b, int a); /*! * \brief The movePositionActive method moves the active layer to certain position * \param x - The x value the new center of the layer should be at @@ -226,6 +219,8 @@ QImage* Canvas; int maxWidth; int maxHeight; +bool isSettingPolygon = false; + IntelliRenderSettings renderSettings; IntelliTool* Tool; IntelliPhotoGui* DummyGui; @@ -239,6 +234,9 @@ void resizeLayer(QImage*image_res, const QSize &newSize); // Helper for Tool bool createTempTopLayer(int idx); + +//this function is needed to avoid errors in inputhandeling if a layer has changed +void updateTools(); }; #endif diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 1ec2d0c..a41ee21 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -32,10 +32,11 @@ void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){ if(isDrawing) { - isDrawing=false; + isDrawing=false; this->mergeToolLayer(); this->deleteToolLayer(); activeLayer->image->calculateVisiblity(); + } } @@ -87,7 +88,7 @@ void IntelliTool::mergeToolLayer(){ } void IntelliTool::deleteToolLayer(){ - Area->deleteLayer(Area->activeLayer+1); + Area->deleteLayer(Area->activeLayer+1, true); this->Canvas=nullptr; } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 32c416f..f4f5105 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -21,9 +21,14 @@ IntelliToolPolygon::~IntelliToolPolygon(){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { - std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); - QPoint Point(x,y); - isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + if(Area->getPolygonDataOfRealLayer().size()>2){ + std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); + QPoint Point(x,y); + isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + } + else{ + isInside = true; + } if(isSettingPolygon){ isInside = true; }