From 9651dd98e36bdaf36b565915f03fe61e258dc498 Mon Sep 17 00:00:00 2001 From: Mienek Date: Thu, 23 Jan 2020 13:13:31 +0100 Subject: [PATCH] start of history --- src/GUI/IntelliPhotoGui.cpp | 22 +++- src/GUI/IntelliPhotoGui.h | 9 +- src/Image/IntelliImage.cpp | 15 ++- src/Image/IntelliImage.h | 22 ++-- src/Image/IntelliRasterImage.cpp | 16 ++- src/Image/IntelliRasterImage.cpp.autosave | 61 +++++++++++ src/Image/IntelliRasterImage.h | 2 + src/Image/IntelliShapedImage.cpp | 15 ++- src/Image/IntelliShapedImage.cpp.autosave | 120 ++++++++++++++++++++++ src/Image/IntelliShapedImage.h | 1 + src/Layer/PaintingArea.cpp | 57 +++++++++- src/Layer/PaintingArea.h | 21 +++- src/Tool/IntelliTool.cpp | 1 + src/Tool/IntelliToolPolygon.cpp | 4 +- 14 files changed, 339 insertions(+), 27 deletions(-) create mode 100644 src/Image/IntelliRasterImage.cpp.autosave create mode 100644 src/Image/IntelliShapedImage.cpp.autosave diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 5734d47..a031e00 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -82,7 +82,7 @@ void IntelliPhotoGui::slotCreateNewRasterLayer(){ // Create New Layer if (ok1&&ok2) { - paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::RASTERIMAGE); + paintingArea->addLayer(width,height,0,0,ImageType::RASTERIMAGE); UpdateGui(); } } @@ -101,7 +101,7 @@ void IntelliPhotoGui::slotCreateNewShapedLayer(){ // Create New Layer if (ok1&&ok2) { - paintingArea->addLayer(width, height, 0, 0, IntelliImage::ImageType::SHAPEDIMAGE); + paintingArea->addLayer(width, height, 0, 0, ImageType::SHAPEDIMAGE); UpdateGui(); } } @@ -327,6 +327,14 @@ void IntelliPhotoGui::slotSetInnerAlpha(){ } } +void IntelliPhotoGui::slotGoBack(){ + paintingArea->historyGoBack(); +} + +void IntelliPhotoGui::slotGoForward(){ + paintingArea->historyGoForward(); +} + // Define menu actions that call functions void IntelliPhotoGui::createActions(){ // Get a list of the supported file formats @@ -525,6 +533,14 @@ void IntelliPhotoGui::createActions(){ actionSetInnerAlpha = new QAction(tr("&Set Inner Alpha"),this); actionSetInnerAlpha->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A)); connect(actionSetInnerAlpha, SIGNAL(triggered()), this, SLOT(slotSetInnerAlpha())); + + actionGoBack = new QAction(tr("&Go back"),this); + actionGoBack->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z)); + connect(actionGoBack, SIGNAL(triggered()), this, SLOT(slotGoBack())); + + actionGoForward = new QAction(tr("&Go forward"),this); + actionGoForward->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Y)); + connect(actionGoForward, SIGNAL(triggered()), this, SLOT(slotGoForward())); } // Create the menubar @@ -597,6 +613,8 @@ void IntelliPhotoGui::createMenus(){ // Attach all actions to Options optionMenu = new QMenu(tr("&Options"), this); + optionMenu->addAction(actionGoBack); + optionMenu->addAction(actionGoForward); optionMenu->addMenu(layerMenu); optionMenu->addMenu(toolMenu); optionMenu->addSeparator(); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 8d164a4..2f177aa 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -95,6 +95,9 @@ void slotSetInnerAlpha(); void slotResetTools(); +void slotGoBack(); +void slotGoForward(); + private: void createActions(); void createMenus(); @@ -195,12 +198,16 @@ QAction* actionMovePositionRight; QAction* actionMoveLayerUp; QAction* actionMoveLayerDown; -// Actions tied to specific file formats +// actions tied to specific file formats QList actionSaveAs; QAction* actionSetWidth; QAction* actionSetInnerAlpha; +// history actions +QAction* actionGoBack; +QAction* actionGoForward; + // main GUI elements QWidget* centralGuiWidget; QGridLayout* mainLayout; diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 0017877..446997d 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -2,7 +2,7 @@ #include #include -IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) +IntelliImage:: IntelliImage(int width, int height, bool fastRendererOn) : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ if(fastRendererOn) { imageData = imageData.convertToFormat(QImage::Format_ARGB32); @@ -15,6 +15,7 @@ IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) } + IntelliImage::~IntelliImage(){ } @@ -158,3 +159,15 @@ void IntelliImage::updateRendererSetting(bool fastRendererOn){ this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); } } + +int IntelliImage::getWidth() const{ + return imageData.width(); +} + +int IntelliImage::getHeight() const{ + return imageData.height(); +} + +bool IntelliImage::isFastRendering() const{ + return this->fastRenderering; +} diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index 5c19186..3d14259 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -16,6 +16,14 @@ class UnitTest; class IntelliTool; +/*! + * \brief The Types, which an Image can be. + */ +enum class ImageType { + RASTERIMAGE, + SHAPEDIMAGE +}; + /*! * \brief An abstract class which manages the basic IntelliImage operations. */ @@ -24,13 +32,6 @@ friend UnitTest; friend IntelliTool; public: -/*! - * \brief The Types, which an Image can be. - */ -enum class ImageType { - RASTERIMAGE, - SHAPEDIMAGE -}; protected: void resizeImage(QImage*image, const QSize &newSize); @@ -59,6 +60,7 @@ public: */ IntelliImage(int width, int height, bool fastRendererOn); + /*! * \brief An Abstract Destructor. */ @@ -170,6 +172,12 @@ virtual QImage getImageData(); */ virtual void setImageData(const QImage& newData); +virtual int getWidth() const; + +virtual int getHeight() const; + +virtual bool isFastRendering() const; + }; #endif diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index 3106e36..c70583c 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -5,18 +5,28 @@ IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) : IntelliImage(width, height, fastRendererOn){ - TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; + TypeOfImage = ImageType::RASTERIMAGE; this->fastRenderering = fastRendererOn; } +/* +IntelliRasterImage::IntelliRasterImage(const IntelliRasterImage& image) + : IntelliImage(image.getWidth(), image.getHeight(), image.isFastRendering()){ + this->TypeOfImage = ImageType::RASTERIMAGE; + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), this->fastRenderering); + raster->imageData.copy(0,0,image.getWidth(),image.getWidth()); +} +*/ + + IntelliRasterImage::~IntelliRasterImage(){ } IntelliImage* IntelliRasterImage::getDeepCopy(){ - IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), false); + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), this->fastRenderering); raster->imageData.fill(Qt::transparent); - raster->TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; + raster->TypeOfImage = ImageType::RASTERIMAGE; return raster; } diff --git a/src/Image/IntelliRasterImage.cpp.autosave b/src/Image/IntelliRasterImage.cpp.autosave new file mode 100644 index 0000000..9626f59 --- /dev/null +++ b/src/Image/IntelliRasterImage.cpp.autosave @@ -0,0 +1,61 @@ +#include "Image/IntelliRasterImage.h" +#include +#include +#include + +IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) + : IntelliImage(width, height, fastRendererOn){ + TypeOfImage = ImageType::RASTERIMAGE; + this->fastRenderering = fastRendererOn; +} + + +IntelliRasterImage::Copy(const IntelliRasterImage& image) + : IntelliImage(image.getWidth(), image.getHeight(), image.isFastRendering()){ + this->TypeOfImage = ImageType::RASTERIMAGE; + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), this->fastRenderering); + raster->imageData.copy(0,0,image.getWidth(),image.getWidth()); +} + + + +IntelliRasterImage::~IntelliRasterImage(){ + +} + +IntelliImage* IntelliRasterImage::getDeepCopy(){ + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), this->fastRenderering); + raster->imageData.fill(Qt::transparent); + raster->TypeOfImage = ImageType::RASTERIMAGE; + return raster; +} + +void IntelliRasterImage::calculateVisiblity(){ + // not used in raster image +} + +QImage IntelliRasterImage::getDisplayable(int alpha){ + return getDisplayable(imageData.size(), alpha); +} + +QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ + QImage copy = imageData; + if(fastRenderering) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } + for(int y = 0; y& polygonData){ + return; +} diff --git a/src/Image/IntelliRasterImage.h b/src/Image/IntelliRasterImage.h index a67472a..8f3eb71 100644 --- a/src/Image/IntelliRasterImage.h +++ b/src/Image/IntelliRasterImage.h @@ -26,6 +26,8 @@ public: */ IntelliRasterImage(int width, int height, bool fastRendererOn); +//IntelliRasterImage(const IntelliRasterImage& image); + /*! * \brief An Destructor. */ diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 14c7b71..9e73d2c 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -6,10 +6,19 @@ IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) : IntelliRasterImage(width, height, fastRendererOn){ - TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; + TypeOfImage = ImageType::SHAPEDIMAGE; this->fastRenderering = fastRendererOn; } +/* +IntelliShapedImage::IntelliShapedImage(const IntelliShapedImage& image) + : IntelliRasterImage(image.getWidth(), image.getHeight(), image.isFastRendering()){ + this->TypeOfImage = ImageType::SHAPEDIMAGE; + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), this->fastRenderering); + shaped->imageData.copy(0,0,image.getWidth(),image.getWidth()); +} +*/ + IntelliShapedImage::~IntelliShapedImage(){ } @@ -19,10 +28,10 @@ QImage IntelliShapedImage::getDisplayable(int alpha){ } IntelliImage* IntelliShapedImage::getDeepCopy(){ - IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false); + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), this->fastRenderering); shaped->setPolygon(this->polygonData); shaped->imageData.fill(Qt::transparent); - shaped->TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; + shaped->TypeOfImage = ImageType::SHAPEDIMAGE; return shaped; } diff --git a/src/Image/IntelliShapedImage.cpp.autosave b/src/Image/IntelliShapedImage.cpp.autosave new file mode 100644 index 0000000..bfaa053 --- /dev/null +++ b/src/Image/IntelliShapedImage.cpp.autosave @@ -0,0 +1,120 @@ +#include "Image/IntelliShapedImage.h" +#include "IntelliHelper/IntelliTriangulation.h" +#include +#include +#include + +IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) + : IntelliRasterImage(width, height, fastRendererOn){ + TypeOfImage = ImageType::SHAPEDIMAGE; + this->fastRenderering = fastRendererOn; +} + +IntelliShapedImage::Copy(const IntelliShapedImage& image) + : IntelliRasterImage(image.getWidth(), image.getHeight(), image.isFastRendering()){ + this->TypeOfImage = ImageType::SHAPEDIMAGE; + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), this->fastRenderering); + shaped->imageData.copy(0,0,image.getWidth(),image.getWidth()); +} + +IntelliShapedImage::~IntelliShapedImage(){ + +} + +QImage IntelliShapedImage::getDisplayable(int alpha){ + return getDisplayable(imageData.size(),alpha); +} + +IntelliImage* IntelliShapedImage::getDeepCopy(){ + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), this->fastRenderering); + shaped->setPolygon(this->polygonData); + shaped->imageData.fill(Qt::transparent); + shaped->TypeOfImage = ImageType::SHAPEDIMAGE; + return shaped; +} + +void IntelliShapedImage::calculateVisiblity(){ + if(polygonData.size()<2) { + return; + } + if(fastRenderering) { + this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + + if(polygonData.size()<=2) { + QColor clr; + for(int y = 0; yimageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } + return; + } + QColor clr; + for(int y = 0; yimageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } +} + +QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ + QImage copy = imageData; + if(fastRenderering) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } + for(int y = 0; y& polygonData){ + if(polygonData.size()<3) { + this->polygonData.clear(); + }else{ + this->polygonData.clear(); + for(auto element:polygonData) { + this->polygonData.push_back(QPoint(element.x(), element.y())); + } + triangles = IntelliTriangulation::calculateTriangles(polygonData); + if(fastRenderering) { + imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + for(int y = 0; ygetTypeOfImage()==ImageType::RASTERIMAGE){ + this->image = new IntelliRasterImage(*dynamic_cast(layer.image)); + }else if(layer.image->getTypeOfImage()==ImageType::SHAPEDIMAGE){ + this->image = new IntelliShapedImage(*dynamic_cast(layer.image)); + } + this->width = layer.width; + this->height = layer.height; + this->widthOffset = layer.widthOffset; + this->heightOffset = layer.heightOffset; + this->alpha = layer.alpha; +} PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ @@ -59,21 +75,22 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ } -int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ +int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){ LayerObject newLayer; updateTools(); newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; newLayer.heightOffset = heightOffset; - if(type==IntelliImage::ImageType::RASTERIMAGE) { + if(type==ImageType::RASTERIMAGE) { newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering()); - }else if(type==IntelliImage::ImageType::SHAPEDIMAGE) { + }else if(type==ImageType::SHAPEDIMAGE) { newLayer.image = new IntelliShapedImage(width, height, renderSettings.isFastRenderering()); } newLayer.alpha = 255; this->layerBundle.push_back(newLayer); activeLayer = static_cast(layerBundle.size()) - 1; + historyadd(); return activeLayer; } @@ -98,6 +115,7 @@ void PaintingArea::slotDeleteActiveLayer(){ this->layerBundle.erase(layerBundle.begin() + activeLayer); activeLayer--; } + historyadd(); } void PaintingArea::setLayerActive(int idx){ @@ -116,7 +134,7 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){ } void PaintingArea::setPolygon(int idx){ if(idx>=0&&idx(layerBundle.size())) { - if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE) { + if(layerBundle[static_cast(idx)].image->getTypeOfImage()==ImageType::SHAPEDIMAGE) { delete this->Tool; this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); isSettingPolygon = true; @@ -165,6 +183,7 @@ void PaintingArea::movePositionActive(int x, int y){ updateTools(); layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; + historyadd(); } void PaintingArea::moveActiveLayer(int idx){ @@ -175,6 +194,7 @@ void PaintingArea::moveActiveLayer(int idx){ this->selectLayerDown(); } DummyGui->UpdateGui(); + historyadd(); } void PaintingArea::slotActivateLayer(int a){ @@ -248,7 +268,7 @@ int PaintingArea::getMaxHeight(){ return this->maxHeight; } -IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){ +ImageType PaintingArea::getTypeOfImageRealLayer(){ return this->layerBundle[static_cast(activeLayer)].image->getTypeOfImage(); } @@ -449,3 +469,30 @@ void PaintingArea::updateTools(){ } } } + +void PaintingArea::historyadd(){ + /* + if (++historyPresent == 100) historyPresent = 0; + historyMaxFuture = historyPresent; + if (historyPresent == historyMaxPast) if (++historyMaxPast == 100) historyMaxPast = 0; + history[static_cast(historyPresent)] = layerBundle; + + for (unsigned long long i=0;i < layerBundle.size();i++) { + + }*/ + +} + +void PaintingArea::historyGoBack(){ + if (historyPresent != historyMaxPast){ + if (--historyPresent == -1) historyPresent = 99; + layerBundle = history[static_cast(historyPresent)]; + } +} + +void PaintingArea::historyGoForward(){ + if (historyPresent != historyMaxFuture){ + if (++historyPresent == 100) historyPresent = 0; + layerBundle = history[static_cast(historyPresent)]; + } +} diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 58eb411..a48d4e6 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -45,6 +45,10 @@ struct LayerObject { * \brief alpha - Stores the alpha value of the layer (default=255). */ int alpha = 255; + + LayerObject(); + + LayerObject(const LayerObject& layer); }; /*! @@ -102,7 +106,7 @@ bool save(const QString &filePath, const char*fileFormat); * \param type - Defining the ImageType of the new layer * \return Returns the number of layers in the project */ -int addLayer(int width, int height, int widthOffset = 0, int heightOffset = 0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE); +int addLayer(int width, int height, int widthOffset = 0, int heightOffset = 0, ImageType type = ImageType::RASTERIMAGE); /*! * \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack * \param idx - Index of the position the new layer should be added @@ -113,7 +117,7 @@ int addLayer(int width, int height, int widthOffset = 0, int heightOffset = 0, I * \param type - Defining the ImageType of the new layer * \return Returns the id of the layer position */ -int addLayerAt(int idx, int width, int height, int widthOffset = 0, int heightOffset = 0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE); +int addLayerAt(int idx, int width, int height, int widthOffset = 0, int heightOffset = 0, ImageType type = ImageType::RASTERIMAGE); /*! * \brief The deleteLayer method removes a layer at a given idx * \param idx - The index of the layer to be removed @@ -184,7 +188,7 @@ int getMaxWidth(); int getMaxHeight(); -IntelliImage::ImageType getTypeOfImageRealLayer(); +ImageType getTypeOfImageRealLayer(); std::vector getPolygonDataOfRealLayer(); @@ -201,6 +205,9 @@ QImage getImageDataOfActiveLayer(); IntelliToolsettings Toolsettings; IntelliColorPicker colorPicker; +void historyGoBack(); +void historyGoForward(); + public slots: /*! * \brief The slotActivateLayer method handles the event of selecting one layer as active @@ -245,6 +252,14 @@ void drawLayers(bool forSaving = false); bool createTempTopLayer(int idx); void updateTools(); + +std::vector history[100] = {layerBundle}; +int historyMaxPast = 0; +int historyMaxFuture = 0; +int historyPresent = 0; + +void historyadd(); + }; #endif diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 11ed60b..55afd45 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -89,6 +89,7 @@ void IntelliTool::mergeToolLayer(){ activeLayer->image->setPolygon(Canvas->image->getPolygonData()); } Area->DummyGui->UpdateGui(); + Area->historyadd(); } void IntelliTool::deleteToolLayer(){ diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 507ffb7..d8dc357 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -24,7 +24,7 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { if(Area->getPolygonDataOfRealLayer().size()>2) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); @@ -37,7 +37,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ isInside = true; } } - else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; }