IntelliPhoto 0.7

IntelliDatamanager.cpp
Go to the documentation of this file.
1 #include "IntelliDatamanager.h"
2 #include "Layer/PaintingArea.h"
3
4 bool IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){
5 QFile openFile(filePath);
6
7 if(openFile.open(QIODevice::WriteOnly)) {
8
9 QTextStream out(&openFile);
10 std::vector<LayerObject>* layerBundle = Canvas->getLayerBundle();
11 size_t numberOfLayers = layerBundle->size();
12 out << 7 << endl; //version tag
13 out << Canvas->getRenderSettings() << " ";
14 out << Canvas->getMaxWidth() << " " << Canvas->getMaxHeight() << endl; //dimensions of canvas
15 out << numberOfLayers << endl; //number of layers
16 for(size_t i = 0; i<numberOfLayers; i++) {
17 int width = layerBundle->at(i).width;
18 int height = layerBundle->at(i).height;
19 out << width << endl; //width
20 out << height << endl; //height
21 out << layerBundle->at(i).widthOffset << endl; //widthOffset
22 out << layerBundle->at(i).heightOffset << endl; //HeightOffset
23 out << layerBundle->at(i).alpha << endl; //alpha of layer
24 if(layerBundle->at(i).image->getTypeOfImage() == ImageType::RASTERIMAGE) {
25 out << 0 << " ";
26 }else{
27 out << 1 << " ";
28 }
29 std::vector<QPoint> points = layerBundle->at(i).image->getPolygonData();
30 out << points.size() << " ";
31 for(size_t j = 0; j<points.size(); j++) {
32 out << points.at(j).x() << " " << points.at(j).y() << " ";
33 }
34 for(int j = 0; j<height; j++) {
35 for(int k = 0; k<width; k++) {
36 QColor pixColor = layerBundle->at(i).image->getImageData().pixelColor(j,k);
37 out << pixColor.red() << " " << pixColor.green() << " " << pixColor.blue() << " " << pixColor.alpha() << " ";
38 }
39 }
40
41 }
42 out << "\nFormat designed and approved by IntelliPhoto Team 7. All rigths reserved.";
43 openFile.close();
44 return true;
45 }
46
47 return false;
48 }
49
50 bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){
51 QFile openFile(filePath);
52 Canvas->deleteAllLayers();
53 if(openFile.open(QIODevice::ReadOnly)) {
54 QTextStream in(&openFile);
55
56 float version;
57 int rendersetting;
58 int widthCanvas, heightCanvas, numberOffLayers;
59 in >> version;
60 in >> rendersetting;
61 in >> widthCanvas >> heightCanvas;
62 in >> numberOffLayers;
63
64 Canvas->setCanvasDimensions(widthCanvas, heightCanvas);
65 for(int i = 0; i<numberOffLayers; i++) {
66 int width, height, widthOffset, heightOffset, alpha;
67 in >> width >> height >> widthOffset >> heightOffset >> alpha;
68
69 int typeFlag;
70 size_t numberOfPoints;
71 std::vector<QPoint> polyPoints;
72
73 in >> typeFlag >> numberOfPoints;
74 if(typeFlag==0) {
75 Canvas->addLayer(width, height, widthOffset, heightOffset, alpha, ImageType::RASTERIMAGE);
76 }else{
77 Canvas->addLayer(width, height, widthOffset, heightOffset, alpha, ImageType::SHAPEDIMAGE);
78 }
79 polyPoints.reserve(numberOfPoints);
80 for(size_t j = 0; j<numberOfPoints; j++) {
81 int x, y;
82 in >> x >> y;
83 polyPoints.push_back(QPoint(x,y));
84 }
85 Canvas->setPolygonDataToActive(polyPoints);
86
87 for(int j = 0; j<height; j++) {
88 for(int k = 0; k<width; k++) {
89 int red, green, blue, alpha;
90 in >> red >> green >> blue >> alpha;
91 Canvas->drawPixelOntoActive(QColor(red, green, blue, alpha), QPoint(j, k));
92 }
93 }
94 }
95 Canvas->setRenderSettings(static_cast<bool>(rendersetting));
96 openFile.close();
97 Canvas->historyadd();
98 return true;
99 }
100
101 return false;
102 }
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::historyadd
void historyadd()
historyadd adds an hisotry step
Definition: PaintingArea.cpp:510
PaintingArea::setPolygonDataToActive
void setPolygonDataToActive(std::vector< QPoint > points)
setPolygonDataToActive sets polygondata to the active Layer.
Definition: PaintingArea.cpp:90
IntelliDatamanager.h