IntelliDatamanager.cpp
Go to the documentation of this file.
#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<LayerObject>* 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; i<numberOfLayers; i++) {
int width = layerBundle->at(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<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 << "\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->setCanvasDimensions(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->drawPixelOntoActive(QColor(red, green, blue, alpha), QPoint(j, k));
}
}
}
Canvas->setRenderSettings(static_cast<bool>(rendersetting));
openFile.close();
return true;
}
return false;
}
ImageType::RASTERIMAGE
@ RASTERIMAGE
PaintingArea::setRenderSettings
void setRenderSettings(bool isFastRenderingOn)
setRenderSettings updates all Images to the new Rendersetting.
Definition: PaintingArea.cpp:51
PaintingArea::getMaxWidth
int getMaxWidth()
getMaxWidth gets the max width of the Canvas.
Definition: PaintingArea.cpp:290
IntelliDatamanager::loadProject
bool loadProject(PaintingArea *Canvas, QString filePath="unnamed.idf")
loadProject loads a project from a file, closes current project.
Definition: IntelliDatamanager.cpp:50
PaintingArea::getMaxHeight
int getMaxHeight()
getMaxHeight gets the max height of the Canvas.
Definition: PaintingArea.cpp:294
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:57
PaintingArea::drawPixelOntoActive
void drawPixelOntoActive(QColor color, QPoint point)
drawPixelOntoActive draws a pixel onto the image data of the active Layer.
Definition: PaintingArea.cpp:86
PaintingArea::getLayerBundle
std::vector< LayerObject > * getLayerBundle()
getLayerBundle returns the real active layerbundle (care!)
Definition: PaintingArea.cpp:491
ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
PaintingArea.h
PaintingArea::deleteAllLayers
void deleteAllLayers()
deleteAllLayers deletes all layers
Definition: PaintingArea.cpp:173
PaintingArea::setCanvasDimensions
void setCanvasDimensions(int maxWidth, int maxHeight)
setCanvasDimensions sets the dimension of the Canvas
Definition: PaintingArea.cpp:72
IntelliDatamanager::saveProject
bool saveProject(PaintingArea *Canvas, QString filePath="unnamed.idf")
saveProject saves the current project to a file.
Definition: IntelliDatamanager.cpp:4
PaintingArea::getRenderSettings
bool getRenderSettings()
getRenderSettings updates all Images to the new Rendersetting.
Definition: PaintingArea.cpp:68
PaintingArea::addLayer
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, int alpha=255, ImageType type=ImageType::RASTERIMAGE)
The addLayer adds a layer to the current project/ painting area.
Definition: PaintingArea.cpp:94
PaintingArea::setPolygonDataToActive
void setPolygonDataToActive(std::vector< QPoint > points)
setPolygonDataToActive sets polygondata to the active Layer.
Definition: PaintingArea.cpp:90
IntelliDatamanager.h