project load and export

This commit is contained in:
Jonas Mucke
2020-01-23 20:13:43 +01:00
parent 48747c1e8a
commit 8692ccd8a3
10 changed files with 146 additions and 39 deletions

View File

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

View File

@@ -16,6 +16,14 @@ class UnitTest;
class IntelliTool; 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. * \brief An abstract class which manages the basic IntelliImage operations.
*/ */
@@ -24,14 +32,6 @@ friend UnitTest;
friend IntelliTool; friend IntelliTool;
public: public:
/*!
* \brief The Types, which an Image can be.
*/
enum class ImageType {
RASTERIMAGE,
SHAPEDIMAGE
};
protected: protected:
void resizeImage(QImage*image, const QSize &newSize); void resizeImage(QImage*image, const QSize &newSize);

View File

@@ -5,7 +5,7 @@
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 = IntelliImage::ImageType::RASTERIMAGE; TypeOfImage = ImageType::RASTERIMAGE;
this->fastRenderering = fastRendererOn; this->fastRenderering = fastRendererOn;
} }
@@ -16,7 +16,7 @@ IntelliRasterImage::~IntelliRasterImage(){
IntelliImage* IntelliRasterImage::getDeepCopy(){ IntelliImage* IntelliRasterImage::getDeepCopy(){
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), false); IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), false);
raster->imageData.fill(Qt::transparent); raster->imageData.fill(Qt::transparent);
raster->TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; raster->TypeOfImage = ImageType::RASTERIMAGE;
return raster; return raster;
} }
@@ -49,3 +49,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){ void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){
return; return;
} }
std::vector<QPoint> IntelliRasterImage::getPolygon(){
return std::vector<QPoint>();
}

View File

@@ -57,6 +57,12 @@ virtual IntelliImage* getDeepCopy() override;
* \param polygonData - The Vertices of the Polygon. Nothing happens. * \param polygonData - The Vertices of the Polygon. Nothing happens.
*/ */
virtual void setPolygon(const std::vector<QPoint>& polygonData) override; virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
/*!
* \brief getPolygon
* \return returns the points of the polygon
*/
virtual std::vector<QPoint> getPolygon();
}; };
#endif #endif

View File

@@ -6,7 +6,7 @@
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 = IntelliImage::ImageType::SHAPEDIMAGE; TypeOfImage = ImageType::SHAPEDIMAGE;
this->fastRenderering = fastRendererOn; this->fastRenderering = fastRendererOn;
} }
@@ -22,7 +22,7 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false); IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false);
shaped->setPolygon(this->polygonData); shaped->setPolygon(this->polygonData);
shaped->imageData.fill(Qt::transparent); shaped->imageData.fill(Qt::transparent);
shaped->TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; shaped->TypeOfImage = ImageType::SHAPEDIMAGE;
return shaped; return shaped;
} }
@@ -111,3 +111,7 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
calculateVisiblity(); calculateVisiblity();
return; return;
} }
std::vector<QPoint> IntelliShapedImage::getPolygon(){
return polygonData;
}

View File

@@ -77,6 +77,14 @@ virtual std::vector<QPoint> getPolygonData() override {
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed. * \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
*/ */
virtual void setPolygon(const std::vector<QPoint>& polygonData) override; virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
/*!
* \brief getPolygon
* \return returns the data of the polygon as points
*/
virtual std::vector<QPoint> getPolygon() override;
}; };
#endif #endif

View File

@@ -5,27 +5,37 @@ bool IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){
QFile openFile(filePath); QFile openFile(filePath);
if(openFile.open(QIODevice::WriteOnly)){ if(openFile.open(QIODevice::WriteOnly)){
QTextStream out(&openFile); QTextStream out(&openFile);
std::vector<LayerObject>* layerBundle = Canvas->getLayerBundle(); std::vector<LayerObject>* layerBundle = Canvas->getLayerBundle();
size_t numberOfLayers = layerBundle->size(); size_t numberOfLayers = layerBundle->size();
out << 7 << endl; //version tag
out << "Format: idf\n" << "Version: 0.7\n" << endl; out << Canvas->getRenderSettings() << " ";
out << "Resolution: " << Canvas->getMaxWidth() << "x" << Canvas->getMaxHeight() << endl; out << Canvas->getMaxWidth() << " " << Canvas->getMaxHeight() << endl; //dimensions of canvas
out << "Layers: " << numberOfLayers << endl; out << numberOfLayers << endl; //number of layers
for(size_t i = 0; i<numberOfLayers; i++){ for(size_t i = 0; i<numberOfLayers; i++){
int width = layerBundle->at(i).width; int width = layerBundle->at(i).width;
int height = layerBundle->at(i).height; int height = layerBundle->at(i).height;
out << "width: " << width << endl; out << width << endl; //width
out << "height: " << height << endl; out << height << endl; //height
out << "xoffset: " << layerBundle->at(i).widthOffset << endl; out << layerBundle->at(i).widthOffset << endl; //widthOffset
out << "yoffset: " << layerBundle->at(i).heightOffset << endl; out << layerBundle->at(i).heightOffset << endl; //HeightOffset
out << "alpha: " << layerBundle->at(i).alpha << endl; out << layerBundle->at(i).alpha << endl; //alpha of layer
if(layerBundle->at(i).image->getTypeOfImage() == ImageType::RASTERIMAGE){
out << 0 << " ";
}else{
out << 1 << " ";
}
std::vector<QPoint> points = layerBundle->at(i).image->getPolygonData();
out << points.size() << " ";
for(size_t j = 0; j<points.size(); j++){
out << points.at(j).x() << " " << points.at(j).y() << " ";
}
for(int j=0; j<height; j++){ for(int j=0; j<height; j++){
for(int k = 0; k<width; k++){ for(int k = 0; k<width; k++){
QColor pixColor = layerBundle->at(i).image->getImageData().pixelColor(j,k); QColor pixColor = layerBundle->at(i).image->getImageData().pixelColor(j,k);
out << pixColor.red() << " " << pixColor.green() << " " << pixColor.blue() << " " << pixColor.alpha() << ":"; out << pixColor.red() << " " << pixColor.green() << " " << pixColor.blue() << " " << pixColor.alpha() << " ";
} }
out << endl;
} }
} }
@@ -39,9 +49,50 @@ bool IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){
bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){
QFile openFile(filePath); QFile openFile(filePath);
Canvas->deleteAllLayers();
if(openFile.open(QIODevice::ReadOnly)){ if(openFile.open(QIODevice::ReadOnly)){
qDebug() << openFile.readLine(); 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<numberOffLayers; i++){
int width, height, widthOffset, heightOffset, alpha;
in >> width >> height >> widthOffset >> heightOffset >> alpha;
int typeFlag;
size_t numberOfPoints;
std::vector<QPoint> 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<numberOfPoints; j++){
int x, y;
in >> x >> y;
polyPoints.push_back(QPoint(x,y));
}
Canvas->setPolygonDataToActive(polyPoints);
for(int j=0; j<height; j++){
for(int k = 0; k<width; k++){
int red, green, blue, alpha;
in >> red >> green >> blue >> alpha;
Canvas->setPixelToActive(QColor(red, green, blue, alpha), QPoint(j, k));
}
}
}
Canvas->setRenderSettings(static_cast<bool>(rendersetting));
openFile.close(); openFile.close();
return true; return true;
} }

View File

@@ -49,6 +49,10 @@ void PaintingArea::setRenderSettings(bool isFastRenderingOn){
} }
} }
bool PaintingArea::getRenderSettings(){
return this->renderSettings.isFastRenderering();
}
void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
//set standart parameter //set standart parameter
this->maxWidth = maxWidth; this->maxWidth = maxWidth;
@@ -60,19 +64,27 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
} }
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ void PaintingArea::setPixelToActive(QColor color, QPoint point){
layerBundle[static_cast<size_t>(activeLayer)].image->drawPixel(point, color);
}
void PaintingArea::setPolygonDataToActive(std::vector<QPoint> points){
layerBundle[static_cast<size_t>(activeLayer)].image->setPolygon(points);
}
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset,int alpha, ImageType type){
LayerObject newLayer; LayerObject newLayer;
updateTools(); updateTools();
newLayer.width = width; newLayer.width = width;
newLayer.height = height; newLayer.height = height;
newLayer.widthOffset = widthOffset; newLayer.widthOffset = widthOffset;
newLayer.heightOffset = heightOffset; newLayer.heightOffset = heightOffset;
if(type==IntelliImage::ImageType::RASTERIMAGE) { newLayer.alpha = alpha;
if(type==ImageType::RASTERIMAGE) {
newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering()); 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.image = new IntelliShapedImage(width, height, renderSettings.isFastRenderering());
} }
newLayer.alpha = 255;
this->layerBundle.push_back(newLayer); this->layerBundle.push_back(newLayer);
activeLayer = static_cast<int>(layerBundle.size()) - 1; activeLayer = static_cast<int>(layerBundle.size()) - 1;
return activeLayer; return activeLayer;
@@ -117,7 +129,7 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
} }
void PaintingArea::setPolygon(int idx){ void PaintingArea::setPolygon(int idx){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) { if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE) { if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==ImageType::SHAPEDIMAGE) {
delete this->Tool; delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true; isSettingPolygon = true;
@@ -138,6 +150,13 @@ bool PaintingArea::open(const QString &filePath){
return open; return open;
} }
void PaintingArea::deleteAllLayers(){
for(auto layer: layerBundle){
delete layer.image;
}
layerBundle.clear();
}
// Save the current image // Save the current image
bool PaintingArea::save(const QString &filePath, const char*fileFormat){ bool PaintingArea::save(const QString &filePath, const char*fileFormat){
if(layerBundle.size()==0) { if(layerBundle.size()==0) {
@@ -249,7 +268,7 @@ int PaintingArea::getMaxHeight(){
return this->maxHeight; return this->maxHeight;
} }
IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){ ImageType PaintingArea::getTypeOfImageRealLayer(){
return this->layerBundle[static_cast<size_t>(activeLayer)].image->getTypeOfImage(); return this->layerBundle[static_cast<size_t>(activeLayer)].image->getTypeOfImage();
} }

View File

@@ -78,6 +78,12 @@ PaintingArea(int maxWidth = 600, int maxHeight = 600, QWidget*parent = nullptr);
*/ */
void setRenderSettings(bool isFastRenderingOn); 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. * \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. * \param filePath - Path and Name which are used to determine where the to-be-opened file is stored.
@@ -92,16 +98,21 @@ bool open(const QString &filePath);
*/ */
bool save(const QString &filePath, const char*fileFormat); 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 * \brief The addLayer adds a layer to the current project/ painting area
* \param width - Width of the layer in pixles * \param width - Width of the layer in pixles
* \param height - Height 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 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 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 * \param type - Defining the ImageType of the new layer
* \return Returns the number of layers in the project * \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, 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 * \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 * \param idx - Index of the position the new layer should be added
@@ -112,7 +123,7 @@ int addLayer(int width, int height, int widthOffset = 0, int heightOffset = 0, I
* \param type - Defining the ImageType of the new layer * \param type - Defining the ImageType of the new layer
* \return Returns the id of the layer position * \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 * \brief The deleteLayer method removes a layer at a given idx
* \param idx - The index of the layer to be removed * \param idx - The index of the layer to be removed
@@ -183,7 +194,7 @@ int getMaxWidth();
int getMaxHeight(); int getMaxHeight();
IntelliImage::ImageType getTypeOfImageRealLayer(); ImageType getTypeOfImageRealLayer();
std::vector<QPoint> getPolygonDataOfRealLayer(); std::vector<QPoint> getPolygonDataOfRealLayer();
@@ -206,6 +217,11 @@ std::vector<LayerObject>* getLayerBundle();
IntelliToolsettings Toolsettings; IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker; IntelliColorPicker colorPicker;
void setLayerDimensions(int maxWidth, int maxHeight);
void setPixelToActive(QColor color, QPoint point);
void setPolygonDataToActive(std::vector<QPoint> points);
public slots: public slots:
/*! /*!
* \brief The slotActivateLayer method handles the event of selecting one layer as active * \brief The slotActivateLayer method handles the event of selecting one layer as active
@@ -227,7 +243,6 @@ void wheelEvent(QWheelEvent*event) override;
void paintEvent(QPaintEvent*event) override; void paintEvent(QPaintEvent*event) override;
private: private:
void setLayerDimensions(int maxWidth, int maxHeight);
void selectLayerUp(); void selectLayerUp();
void selectLayerDown(); void selectLayerDown();
IntelliTool* copyActiveTool(); IntelliTool* copyActiveTool();

View File

@@ -24,7 +24,7 @@ IntelliToolPolygon::~IntelliToolPolygon(){
} }
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) { if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
if(Area->getPolygonDataOfRealLayer().size()>2) { if(Area->getPolygonDataOfRealLayer().size()>2) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y); QPoint Point(x,y);
@@ -37,7 +37,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
isInside = true; isInside = true;
} }
} }
else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) { else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
isInside = true; isInside = true;
} }