diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index a031e00..e41caa0 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -3,8 +3,10 @@ #include "IntelliPhotoGui.h" #include "Layer/PaintingArea.h" -#include "QEvent" -#include "QCloseEvent" +#include +#include +#include +#include // IntelliPhotoGui constructor IntelliPhotoGui::IntelliPhotoGui(){ @@ -50,10 +52,28 @@ void IntelliPhotoGui::slotOpen(){ // If we have a file name load the image and place // it in the paintingArea if (!fileName.isEmpty()) { - paintingArea->open(fileName); - UpdateGui(); - } - } + bool rightFileType =true; + if(fileName.size()>=4){ + QString endung(".idf"); + int length = fileName.size(); + for(int i=0; i<4; i++){ + if(endung[i]!=fileName[length-4+i]){ + rightFileType = false; + break; + } + } + } + + if(rightFileType){ + IntelliDatamanager::loadProject(paintingArea,fileName); + UpdateGui(); + + } + else{ + paintingArea->open(fileName); + } + } + } } // Called when the user clicks Save As in the menu @@ -82,7 +102,7 @@ void IntelliPhotoGui::slotCreateNewRasterLayer(){ // Create New Layer if (ok1&&ok2) { - paintingArea->addLayer(width,height,0,0,ImageType::RASTERIMAGE); + paintingArea->addLayer(width,height,0,0,255,ImageType::RASTERIMAGE); UpdateGui(); } } @@ -101,7 +121,7 @@ void IntelliPhotoGui::slotCreateNewShapedLayer(){ // Create New Layer if (ok1&&ok2) { - paintingArea->addLayer(width, height, 0, 0, ImageType::SHAPEDIMAGE); + paintingArea->addLayer(width, height, 0, 0,255, ImageType::SHAPEDIMAGE); UpdateGui(); } } @@ -364,6 +384,14 @@ void IntelliPhotoGui::createActions(){ actionSaveAs.append(pngSaveAction); pngSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)); + QAction*projectSaveAction = new QAction("Projekt", this); + projectSaveAction->setData("idf"); + // When clicked call IntelliPhotoGui::save() + connect(projectSaveAction, SIGNAL(triggered()), this, SLOT(slotSave())); + // Attach each PNG in save Menu + actionSaveAs.append(projectSaveAction); + projectSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); + // Create exit action and tie to IntelliPhotoGui::close() actionExit = new QAction(tr("&Exit"), this); actionExit->setShortcuts(QKeySequence::Quit); @@ -835,6 +863,10 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){ return false; } else { // Call for the file to be saved + if(fileFormat == "idf"){ + return IntelliDatamanager::saveProject(paintingArea, fileName); + + } return paintingArea->save(fileName, fileFormat.constData()); } } diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 2f177aa..272307c 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -15,6 +15,7 @@ #include #include #include "IntelliInputDialog.h" +#include "IntelliHelper/IntelliDatamanager.h" //for unit testing class UnitTest; diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index 3d14259..a767c54 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -32,7 +32,6 @@ friend UnitTest; friend IntelliTool; public: - protected: void resizeImage(QImage*image, const QSize &newSize); diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index 59466f9..de9412f 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -59,3 +59,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ void IntelliRasterImage::setPolygon(const std::vector& polygonData){ return; } + +std::vector IntelliRasterImage::getPolygon(){ + return std::vector(); +} diff --git a/src/Image/IntelliRasterImage.h b/src/Image/IntelliRasterImage.h index dd65d69..5b224dc 100644 --- a/src/Image/IntelliRasterImage.h +++ b/src/Image/IntelliRasterImage.h @@ -59,6 +59,12 @@ virtual IntelliImage* getDeepCopy() override; * \param polygonData - The Vertices of the Polygon. Nothing happens. */ virtual void setPolygon(const std::vector& polygonData) override; + +/*! + * \brief getPolygon + * \return returns the points of the polygon + */ +virtual std::vector getPolygon(); }; #endif diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 0202577..6aca975 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -118,3 +118,7 @@ void IntelliShapedImage::setPolygon(const std::vector& polygonData){ calculateVisiblity(); return; } + +std::vector IntelliShapedImage::getPolygon(){ + return polygonData; +} diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 3292211..6f236ab 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -78,6 +78,14 @@ virtual std::vector getPolygonData() override { * \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed. */ virtual void setPolygon(const std::vector& polygonData) override; + + +/*! + * \brief getPolygon + * \return returns the data of the polygon as points + */ +virtual std::vector getPolygon() override; }; + #endif diff --git a/src/IntelliHelper/IntelliDatamanager.cpp b/src/IntelliHelper/IntelliDatamanager.cpp new file mode 100644 index 0000000..bce95f6 --- /dev/null +++ b/src/IntelliHelper/IntelliDatamanager.cpp @@ -0,0 +1,101 @@ +#include "IntelliDatamanager.h" +#include "Layer/PaintingArea.h" + +bool IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){ + QFile openFile(filePath); + + if(openFile.open(QIODevice::WriteOnly)){ + + QTextStream out(&openFile); + std::vector* layerBundle = Canvas->getLayerBundle(); + size_t numberOfLayers = layerBundle->size(); + out << 7 << endl; //version tag + out << Canvas->getRenderSettings() << " "; + out << Canvas->getMaxWidth() << " " << Canvas->getMaxHeight() << endl; //dimensions of canvas + out << numberOfLayers << endl; //number of layers + for(size_t i = 0; iat(i).width; + int height = layerBundle->at(i).height; + out << width << endl; //width + out << height << endl; //height + out << layerBundle->at(i).widthOffset << endl; //widthOffset + out << layerBundle->at(i).heightOffset << endl; //HeightOffset + out << layerBundle->at(i).alpha << endl; //alpha of layer + if(layerBundle->at(i).image->getTypeOfImage() == ImageType::RASTERIMAGE){ + out << 0 << " "; + }else{ + out << 1 << " "; + } + std::vector points = layerBundle->at(i).image->getPolygonData(); + out << points.size() << " "; + for(size_t j = 0; jat(i).image->getImageData().pixelColor(j,k); + out << pixColor.red() << " " << pixColor.green() << " " << pixColor.blue() << " " << pixColor.alpha() << " "; + } + } + + } + out << "\nFormat designed and approved by IntelliPhoto Team 7. All rigths reserved."; + openFile.close(); + return true; + } + + return false; +} + +bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ + QFile openFile(filePath); + Canvas->deleteAllLayers(); + if(openFile.open(QIODevice::ReadOnly)){ + QTextStream in(&openFile); + + float version; + int rendersetting; + int widthCanvas, heightCanvas, numberOffLayers; + in >> version; + in >> rendersetting; + in >> widthCanvas >> heightCanvas; + in >> numberOffLayers; + + Canvas->setLayerDimensions(widthCanvas, heightCanvas); + for(int i=0; i> width >> height >> widthOffset >> heightOffset >> alpha; + + int typeFlag; + size_t numberOfPoints; + std::vector polyPoints; + + in >> typeFlag >> numberOfPoints; + if(typeFlag==0){ + Canvas->addLayer(width, height, widthOffset, heightOffset, alpha, ImageType::RASTERIMAGE); + }else{ + Canvas->addLayer(width, height, widthOffset, heightOffset, alpha, ImageType::SHAPEDIMAGE); + } + polyPoints.reserve(numberOfPoints); + for(size_t j=0; j> x >> y; + polyPoints.push_back(QPoint(x,y)); + } + Canvas->setPolygonDataToActive(polyPoints); + + for(int j=0; j> red >> green >> blue >> alpha; + Canvas->setPixelToActive(QColor(red, green, blue, alpha), QPoint(j, k)); + } + } + } + Canvas->setRenderSettings(static_cast(rendersetting)); + openFile.close(); + return true; + } + + return false; +} diff --git a/src/IntelliHelper/IntelliDatamanager.h b/src/IntelliHelper/IntelliDatamanager.h new file mode 100644 index 0000000..eb121d9 --- /dev/null +++ b/src/IntelliHelper/IntelliDatamanager.h @@ -0,0 +1,16 @@ +#ifndef INTELLIDATAMANAGER_H +#define INTELLIDATAMANAGER_H + +#include +#include + +class PaintingArea; + +namespace IntelliDatamanager{ + + bool loadProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); + bool saveProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); + +} + +#endif // INTELLIDATAMANAGER_H diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index faf6c86..2b1d4d5 100755 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -22,6 +22,7 @@ SOURCES += \ Image/IntelliRasterImage.cpp \ Image/IntelliShapedImage.cpp \ IntelliHelper/IntelliColorPicker.cpp \ + IntelliHelper/IntelliDatamanager.cpp \ IntelliHelper/IntelliRenderSettings.cpp \ IntelliHelper/IntelliToolsettings.cpp \ IntelliHelper/IntelliTriangulation.cpp \ @@ -43,6 +44,7 @@ HEADERS += \ Image/IntelliRasterImage.h \ Image/IntelliShapedImage.h \ IntelliHelper/IntelliColorPicker.h \ + IntelliHelper/IntelliDatamanager.h \ IntelliHelper/IntelliRenderSettings.h \ IntelliHelper/IntelliToolsettings.h \ IntelliHelper/IntelliTriangulation.h \ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 3398d72..ec22b78 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -17,6 +17,7 @@ #include "Tool/IntelliToolRectangle.h" #include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolPolygon.h" +#include "GUI/IntelliPhotoGui.h" LayerObject::LayerObject(){ @@ -64,6 +65,10 @@ void PaintingArea::setRenderSettings(bool isFastRenderingOn){ } } +bool PaintingArea::getRenderSettings(){ + return this->renderSettings.isFastRenderering(); +} + void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ //set standart parameter this->maxWidth = maxWidth; @@ -75,19 +80,27 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ } -int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){ +void PaintingArea::setPixelToActive(QColor color, QPoint point){ + layerBundle[static_cast(activeLayer)].image->drawPixel(point, color); +} + +void PaintingArea::setPolygonDataToActive(std::vector points){ + layerBundle[static_cast(activeLayer)].image->setPolygon(points); +} + +int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset,int alpha, ImageType type){ LayerObject newLayer; updateTools(); newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; newLayer.heightOffset = heightOffset; + newLayer.alpha = alpha; if(type==ImageType::RASTERIMAGE) { newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering()); }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(); @@ -155,6 +168,13 @@ bool PaintingArea::open(const QString &filePath){ return open; } +void PaintingArea::deleteAllLayers(){ + for(auto layer: layerBundle){ + delete layer.image; + } + layerBundle.clear(); +} + // Save the current image bool PaintingArea::save(const QString &filePath, const char*fileFormat){ if(layerBundle.size()==0) { @@ -455,6 +475,10 @@ QImage PaintingArea::getImageDataOfActiveLayer(){ return returnImage; } +std::vector* PaintingArea::getLayerBundle(){ + return &layerBundle; +} + void PaintingArea::updateTools(){ if(Tool!=nullptr) { if(Tool->getIsDrawing()) { diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index a48d4e6..883285a 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -7,7 +7,6 @@ #include #include #include -#include "GUI/IntelliPhotoGui.h" #include "Image/IntelliImage.h" #include "Image/IntelliRasterImage.h" #include "Image/IntelliShapedImage.h" @@ -16,7 +15,7 @@ //for unit testing class UnitTest; - +class IntelliPhotoGui; /*! * \brief The LayerObject struct holds all the information needed to construct a layer */ @@ -83,6 +82,12 @@ PaintingArea(int maxWidth = 600, int maxHeight = 600, QWidget*parent = nullptr); */ void setRenderSettings(bool isFastRenderingOn); +/*! + * \brief getRenderSettings updates all Images to the new Rendersetting. + * \param isFastRenderingOn is the new given flag for the FastRenderer. + */ +bool getRenderSettings(); + /*! * \brief The open method is used for loading a picture into the current layer. * \param filePath - Path and Name which are used to determine where the to-be-opened file is stored. @@ -97,16 +102,21 @@ bool open(const QString &filePath); */ bool save(const QString &filePath, const char*fileFormat); +/*! + * \brief deleteAllLayers deletes all layers + */ +void deleteAllLayers(); /*! * \brief The addLayer adds a layer to the current project/ painting area * \param width - Width of the layer in pixles * \param height - Height of the layer in pixles * \param widthOffset - Offset of the layer measured to the left border of the painting area in pixles * \param heightOffset - Offset of the layer measured to the top border of the painting area in pixles + * \param alpha - Transparence of the layer * \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, ImageType type = ImageType::RASTERIMAGE); +int addLayer(int width, int height, int widthOffset = 0, int heightOffset = 0, int alpha=255, 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 @@ -202,12 +212,23 @@ IntelliImage* getImageOfActiveLayer(); */ QImage getImageDataOfActiveLayer(); +/*! + * \brief getLayerBundle returns the real active layerbundle (care!) + * \return the reference of the currentLayerBundle + */ +std::vector* getLayerBundle(); + IntelliToolsettings Toolsettings; IntelliColorPicker colorPicker; void historyGoBack(); void historyGoForward(); +void setLayerDimensions(int maxWidth, int maxHeight); + +void setPixelToActive(QColor color, QPoint point); + +void setPolygonDataToActive(std::vector points); public slots: /*! * \brief The slotActivateLayer method handles the event of selecting one layer as active @@ -229,7 +250,6 @@ void wheelEvent(QWheelEvent*event) override; void paintEvent(QPaintEvent*event) override; private: -void setLayerDimensions(int maxWidth, int maxHeight); void selectLayerUp(); void selectLayerDown(); IntelliTool* copyActiveTool(); diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 55afd45..66cea50 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -1,5 +1,6 @@ #include "IntelliTool.h" #include "Layer/PaintingArea.h" +#include "GUI/IntelliPhotoGui.h" IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){ this->Area = Area;