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

@@ -5,27 +5,37 @@ bool IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){
QFile openFile(filePath);
if(openFile.open(QIODevice::WriteOnly)){
QTextStream out(&openFile);
std::vector<LayerObject>* layerBundle = Canvas->getLayerBundle();
size_t numberOfLayers = layerBundle->size();
out << "Format: idf\n" << "Version: 0.7\n" << endl;
out << "Resolution: " << Canvas->getMaxWidth() << "x" << Canvas->getMaxHeight() << endl;
out << "Layers: " << numberOfLayers << endl;
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; i<numberOfLayers; i++){
int width = layerBundle->at(i).width;
int height = layerBundle->at(i).height;
out << "width: " << width << endl;
out << "height: " << height << endl;
out << "xoffset: " << layerBundle->at(i).widthOffset << endl;
out << "yoffset: " << layerBundle->at(i).heightOffset << endl;
out << "alpha: " << layerBundle->at(i).alpha << endl;
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<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 k = 0; k<width; 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){
QFile openFile(filePath);
Canvas->deleteAllLayers();
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();
return true;
}