fixed history tool

This commit is contained in:
Sonaion
2020-02-07 10:22:18 +01:00
parent 5787b065c5
commit 7e93e69a53
9 changed files with 23 additions and 74 deletions

View File

@@ -125,7 +125,7 @@ void IntelliPhotoGui::slotCreateNewShapedLayer(){
// Create New Layer // Create New Layer
if (ok1&&ok2) { if (ok1&&ok2) {
paintingArea->addLayer(width, height, 0, 0,255, ImageType::SHAPEDIMAGE); paintingArea->addLayer(width, height, 0, 0,255, ImageType::SHAPEDIMAGE);
paintingArea->historyadd(); paintingArea->historyadd();
UpdateGui(); UpdateGui();
} }
} }

View File

@@ -6,17 +6,9 @@
IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn)
: IntelliImage(width, height, fastRendererOn){ : IntelliImage(width, height, fastRendererOn){
TypeOfImage = ImageType::RASTERIMAGE; 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(){ IntelliRasterImage::~IntelliRasterImage(){

View File

@@ -26,8 +26,6 @@ public:
*/ */
IntelliRasterImage(int width, int height, bool fastRendererOn); IntelliRasterImage(int width, int height, bool fastRendererOn);
IntelliRasterImage* copy(const IntelliRasterImage& image);
/*! /*!
* \brief An Destructor. * \brief An Destructor.
*/ */

View File

@@ -5,16 +5,8 @@
#include <QDebug> #include <QDebug>
IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn)
: IntelliRasterImage(width, height, fastRendererOn){ : IntelliRasterImage(width, height, fastRendererOn){
TypeOfImage = ImageType::SHAPEDIMAGE; 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(){ IntelliShapedImage::~IntelliShapedImage(){

View File

@@ -38,7 +38,6 @@ public:
*/ */
IntelliShapedImage(int width, int height, bool fastRendererOn); IntelliShapedImage(int width, int height, bool fastRendererOn);
IntelliShapedImage* copy(const IntelliShapedImage& image);
/*! /*!
* \brief An Destructor. * \brief An Destructor.
*/ */

View File

@@ -94,7 +94,6 @@ bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){
} }
Canvas->setRenderSettings(static_cast<bool>(rendersetting)); Canvas->setRenderSettings(static_cast<bool>(rendersetting));
openFile.close(); openFile.close();
Canvas->historyadd();
return true; return true;
} }

View File

@@ -26,9 +26,9 @@ LayerObject::LayerObject(){
LayerObject::LayerObject(const LayerObject& layer){ LayerObject::LayerObject(const LayerObject& layer){
if(layer.image->getTypeOfImage()==ImageType::RASTERIMAGE) { if(layer.image->getTypeOfImage()==ImageType::RASTERIMAGE) {
this->image = new IntelliRasterImage(*dynamic_cast<IntelliRasterImage*>(layer.image)); this->image = new IntelliRasterImage(*dynamic_cast<IntelliRasterImage*>(layer.image));
}else if(layer.image->getTypeOfImage()==ImageType::SHAPEDIMAGE) { }else if(layer.image->getTypeOfImage()==ImageType::SHAPEDIMAGE) {
this->image = new IntelliShapedImage(*dynamic_cast<IntelliShapedImage*>(layer.image)); this->image = new IntelliShapedImage(*dynamic_cast<IntelliShapedImage*>(layer.image));
} }
this->width = layer.width; this->width = layer.width;
this->height = layer.height; this->height = layer.height;
@@ -130,7 +130,7 @@ void PaintingArea::slotDeleteActiveLayer(){
this->layerBundle.erase(layerBundle.begin() + activeLayer); this->layerBundle.erase(layerBundle.begin() + activeLayer);
activeLayer--; activeLayer--;
} }
historyadd(); historyadd();
} }
void PaintingArea::setLayerActive(int idx){ void PaintingArea::setLayerActive(int idx){
@@ -205,7 +205,7 @@ void PaintingArea::movePositionActive(int x, int y){
updateTools(); updateTools();
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x; layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y; layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
historyadd(); historyadd();
} }
void PaintingArea::moveActiveLayer(int idx){ void PaintingArea::moveActiveLayer(int idx){
@@ -216,7 +216,7 @@ void PaintingArea::moveActiveLayer(int idx){
this->selectLayerDown(); this->selectLayerDown();
} }
guiReference->UpdateGui(); guiReference->UpdateGui();
historyadd(); historyadd();
} }
void PaintingArea::slotActivateLayer(int a){ void PaintingArea::slotActivateLayer(int a){
@@ -509,46 +509,25 @@ void PaintingArea::updateTools(){
void PaintingArea::historyadd(){ void PaintingArea::historyadd(){
historyPresent++; history.erase(history.begin()+historyPresent+1,history.end());
if (historyPresent == 100) { historyPresent++;
historyPresent = 0; history.push_back(layerBundle);
}
historyMaxFuture = historyPresent;
if (historyPresent == historyMaxPast) {
historyMaxPast++;
if (historyMaxPast == 100) {
historyMaxPast = 0;
}
}
history[static_cast<size_t>(historyPresent)] = layerBundle;
} }
void PaintingArea::historyGoBack(){ void PaintingArea::historyGoBack(){
if (historyPresent != historyMaxPast) { historyPresent--;
if (--historyPresent == -1) if( historyPresent<0){
historyPresent = 99; historyPresent=0;
if (activeLayer == -1) }
activeLayer = 0; layerBundle = history[static_cast<size_t>(historyPresent)];
if (layerBundle.size() > history[static_cast<size_t>(historyPresent)].size()) this->guiReference->UpdateGui();
activeLayer = static_cast<int>(history[static_cast<size_t>(historyPresent)].size()) - 1;
if (history[static_cast<size_t>(historyPresent)].size() == 0)
activeLayer = -1;
layerBundle = history[static_cast<size_t>(historyPresent)];
}
this->guiReference->UpdateGui();
} }
void PaintingArea::historyGoForward(){ void PaintingArea::historyGoForward(){
if (historyPresent != historyMaxFuture) { historyPresent++;
if (++historyPresent == 100) if(historyPresent>=static_cast<int>(history.size())){
historyPresent = 0; historyPresent=history.size()-1;
if (activeLayer == -1) }
activeLayer = 0; layerBundle = history[static_cast<size_t>(historyPresent)];
if (layerBundle.size() > history[static_cast<size_t>(historyPresent)].size())
activeLayer = static_cast<int>(history[static_cast<size_t>(historyPresent)].size()) - 1;
if (history[static_cast<size_t>(historyPresent)].size() == 0)
activeLayer = -1;
layerBundle = history[static_cast<size_t>(historyPresent)];
}
this->guiReference->UpdateGui(); this->guiReference->UpdateGui();
} }

View File

@@ -459,17 +459,7 @@ void updateTools();
/*! /*!
* \brief history - an array out of containers to save history actions. * \brief history - an array out of containers to save history actions.
*/ */
std::vector<LayerObject> history[100] = {layerBundle}; std::vector<std::vector<LayerObject>> history = {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;
/*! /*!
* \brief historyPresent a indicator where the present is. * \brief historyPresent a indicator where the present is.

View File

@@ -40,6 +40,7 @@ void IntelliTool::onMouseLeftReleased(int x, int y){
this->mergeToolLayer(); this->mergeToolLayer();
this->deleteToolLayer(); this->deleteToolLayer();
activeLayer->image->calculateVisiblity(); activeLayer->image->calculateVisiblity();
Area->historyadd();
} }
} }
@@ -90,7 +91,6 @@ void IntelliTool::mergeToolLayer(){
activeLayer->image->setPolygon(Canvas->image->getPolygonData()); activeLayer->image->setPolygon(Canvas->image->getPolygonData());
} }
Area->guiReference->UpdateGui(); Area->guiReference->UpdateGui();
Area->historyadd();
} }
void IntelliTool::deleteToolLayer(){ void IntelliTool::deleteToolLayer(){