From 7e93e69a53b4f67b2f71eae7245a7eb064534b5b Mon Sep 17 00:00:00 2001 From: Sonaion Date: Fri, 7 Feb 2020 10:22:18 +0100 Subject: [PATCH] fixed history tool --- src/GUI/IntelliPhotoGui.cpp | 2 +- src/Image/IntelliRasterImage.cpp | 8 ---- src/Image/IntelliRasterImage.h | 2 - src/Image/IntelliShapedImage.cpp | 10 +--- src/Image/IntelliShapedImage.h | 1 - src/IntelliHelper/IntelliDatamanager.cpp | 1 - src/Layer/PaintingArea.cpp | 59 ++++++++---------------- src/Layer/PaintingArea.h | 12 +---- src/Tool/IntelliTool.cpp | 2 +- 9 files changed, 23 insertions(+), 74 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 9e00641..3ca684f 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -125,7 +125,7 @@ void IntelliPhotoGui::slotCreateNewShapedLayer(){ // Create New Layer if (ok1&&ok2) { paintingArea->addLayer(width, height, 0, 0,255, ImageType::SHAPEDIMAGE); - paintingArea->historyadd(); + paintingArea->historyadd(); UpdateGui(); } } diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index 9891b66..f419986 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -6,17 +6,9 @@ IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) : IntelliImage(width, height, fastRendererOn){ TypeOfImage = ImageType::RASTERIMAGE; - this->fastRenderering = fastRendererOn; } -IntelliRasterImage* IntelliRasterImage::copy(const IntelliRasterImage& image){ - this->TypeOfImage = ImageType::RASTERIMAGE; - IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), this->fastRenderering); - raster->imageData.copy(0,0,image.getWidth(),image.getWidth()); - return raster; -} - IntelliRasterImage::~IntelliRasterImage(){ diff --git a/src/Image/IntelliRasterImage.h b/src/Image/IntelliRasterImage.h index 5b224dc..c97ec8c 100644 --- a/src/Image/IntelliRasterImage.h +++ b/src/Image/IntelliRasterImage.h @@ -26,8 +26,6 @@ public: */ IntelliRasterImage(int width, int height, bool fastRendererOn); -IntelliRasterImage* copy(const IntelliRasterImage& image); - /*! * \brief An Destructor. */ diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 93b2a2b..392f9c6 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -5,16 +5,8 @@ #include IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) - : IntelliRasterImage(width, height, fastRendererOn){ + : IntelliRasterImage(width, height, fastRendererOn){ TypeOfImage = ImageType::SHAPEDIMAGE; - this->fastRenderering = fastRendererOn; -} - -IntelliShapedImage* IntelliShapedImage::copy(const IntelliShapedImage& image){ - this->TypeOfImage = ImageType::SHAPEDIMAGE; - IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), this->fastRenderering); - shaped->imageData.copy(0,0,image.getWidth(),image.getWidth()); - return shaped; } IntelliShapedImage::~IntelliShapedImage(){ diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 6f236ab..781ece5 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -38,7 +38,6 @@ public: */ IntelliShapedImage(int width, int height, bool fastRendererOn); -IntelliShapedImage* copy(const IntelliShapedImage& image); /*! * \brief An Destructor. */ diff --git a/src/IntelliHelper/IntelliDatamanager.cpp b/src/IntelliHelper/IntelliDatamanager.cpp index e465778..e82e378 100644 --- a/src/IntelliHelper/IntelliDatamanager.cpp +++ b/src/IntelliHelper/IntelliDatamanager.cpp @@ -94,7 +94,6 @@ bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ } Canvas->setRenderSettings(static_cast(rendersetting)); openFile.close(); - Canvas->historyadd(); return true; } diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index ece955e..58a0bce 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -26,9 +26,9 @@ LayerObject::LayerObject(){ LayerObject::LayerObject(const LayerObject& layer){ if(layer.image->getTypeOfImage()==ImageType::RASTERIMAGE) { - this->image = new IntelliRasterImage(*dynamic_cast(layer.image)); + this->image = new IntelliRasterImage(*dynamic_cast(layer.image)); }else if(layer.image->getTypeOfImage()==ImageType::SHAPEDIMAGE) { - this->image = new IntelliShapedImage(*dynamic_cast(layer.image)); + this->image = new IntelliShapedImage(*dynamic_cast(layer.image)); } this->width = layer.width; this->height = layer.height; @@ -130,7 +130,7 @@ void PaintingArea::slotDeleteActiveLayer(){ this->layerBundle.erase(layerBundle.begin() + activeLayer); activeLayer--; } - historyadd(); + historyadd(); } void PaintingArea::setLayerActive(int idx){ @@ -205,7 +205,7 @@ void PaintingArea::movePositionActive(int x, int y){ updateTools(); layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; - historyadd(); + historyadd(); } void PaintingArea::moveActiveLayer(int idx){ @@ -216,7 +216,7 @@ void PaintingArea::moveActiveLayer(int idx){ this->selectLayerDown(); } guiReference->UpdateGui(); - historyadd(); + historyadd(); } void PaintingArea::slotActivateLayer(int a){ @@ -509,46 +509,25 @@ void PaintingArea::updateTools(){ void PaintingArea::historyadd(){ - historyPresent++; - if (historyPresent == 100) { - historyPresent = 0; - } - historyMaxFuture = historyPresent; - if (historyPresent == historyMaxPast) { - historyMaxPast++; - if (historyMaxPast == 100) { - historyMaxPast = 0; - } - } - history[static_cast(historyPresent)] = layerBundle; + history.erase(history.begin()+historyPresent+1,history.end()); + historyPresent++; + history.push_back(layerBundle); } void PaintingArea::historyGoBack(){ - if (historyPresent != historyMaxPast) { - if (--historyPresent == -1) - historyPresent = 99; - if (activeLayer == -1) - activeLayer = 0; - if (layerBundle.size() > history[static_cast(historyPresent)].size()) - activeLayer = static_cast(history[static_cast(historyPresent)].size()) - 1; - if (history[static_cast(historyPresent)].size() == 0) - activeLayer = -1; - layerBundle = history[static_cast(historyPresent)]; - } - this->guiReference->UpdateGui(); + historyPresent--; + if( historyPresent<0){ + historyPresent=0; + } + layerBundle = history[static_cast(historyPresent)]; + this->guiReference->UpdateGui(); } void PaintingArea::historyGoForward(){ - if (historyPresent != historyMaxFuture) { - if (++historyPresent == 100) - historyPresent = 0; - if (activeLayer == -1) - activeLayer = 0; - if (layerBundle.size() > history[static_cast(historyPresent)].size()) - activeLayer = static_cast(history[static_cast(historyPresent)].size()) - 1; - if (history[static_cast(historyPresent)].size() == 0) - activeLayer = -1; - layerBundle = history[static_cast(historyPresent)]; - } + historyPresent++; + if(historyPresent>=static_cast(history.size())){ + historyPresent=history.size()-1; + } + layerBundle = history[static_cast(historyPresent)]; this->guiReference->UpdateGui(); } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index be0deb7..2bc1746 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -459,17 +459,7 @@ void updateTools(); /*! * \brief history - an array out of containers to save history actions. */ -std::vector history[100] = {layerBundle}; - -/*! - * \brief historyMaxPast a indicator how many steps you can go into the past. - */ -int historyMaxPast = 0; - -/*! - * \brief historyMaxPast a indicator how many steps you can go into the future. - */ -int historyMaxFuture = 0; +std::vector> history = {layerBundle}; /*! * \brief historyPresent a indicator where the present is. diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 43efb91..2c4fd00 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -40,6 +40,7 @@ void IntelliTool::onMouseLeftReleased(int x, int y){ this->mergeToolLayer(); this->deleteToolLayer(); activeLayer->image->calculateVisiblity(); + Area->historyadd(); } } @@ -90,7 +91,6 @@ void IntelliTool::mergeToolLayer(){ activeLayer->image->setPolygon(Canvas->image->getPolygonData()); } Area->guiReference->UpdateGui(); - Area->historyadd(); } void IntelliTool::deleteToolLayer(){