mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-12 19:40:28 +02:00
project load and export
This commit is contained in:
@@ -102,7 +102,7 @@ void IntelliPhotoGui::slotCreateNewRasterLayer(){
|
||||
|
||||
// Create New Layer
|
||||
if (ok1&&ok2) {
|
||||
paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::RASTERIMAGE);
|
||||
paintingArea->addLayer(width,height,0,0,255,ImageType::RASTERIMAGE);
|
||||
UpdateGui();
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ void IntelliPhotoGui::slotCreateNewShapedLayer(){
|
||||
|
||||
// Create New Layer
|
||||
if (ok1&&ok2) {
|
||||
paintingArea->addLayer(width, height, 0, 0, IntelliImage::ImageType::SHAPEDIMAGE);
|
||||
paintingArea->addLayer(width, height, 0, 0,255, ImageType::SHAPEDIMAGE);
|
||||
UpdateGui();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@ class UnitTest;
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -24,14 +32,6 @@ friend UnitTest;
|
||||
friend IntelliTool;
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief The Types, which an Image can be.
|
||||
*/
|
||||
enum class ImageType {
|
||||
RASTERIMAGE,
|
||||
SHAPEDIMAGE
|
||||
};
|
||||
|
||||
protected:
|
||||
void resizeImage(QImage*image, const QSize &newSize);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn)
|
||||
: IntelliImage(width, height, fastRendererOn){
|
||||
TypeOfImage = IntelliImage::ImageType::RASTERIMAGE;
|
||||
TypeOfImage = ImageType::RASTERIMAGE;
|
||||
this->fastRenderering = fastRendererOn;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ IntelliRasterImage::~IntelliRasterImage(){
|
||||
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), false);
|
||||
raster->imageData.fill(Qt::transparent);
|
||||
raster->TypeOfImage = IntelliImage::ImageType::RASTERIMAGE;
|
||||
raster->TypeOfImage = ImageType::RASTERIMAGE;
|
||||
return raster;
|
||||
}
|
||||
|
||||
@@ -49,3 +49,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<QPoint> IntelliRasterImage::getPolygon(){
|
||||
return std::vector<QPoint>();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,12 @@ virtual IntelliImage* getDeepCopy() override;
|
||||
* \param polygonData - The Vertices of the Polygon. Nothing happens.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
|
||||
/*!
|
||||
* \brief getPolygon
|
||||
* \return returns the points of the polygon
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygon();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn)
|
||||
: IntelliRasterImage(width, height, fastRendererOn){
|
||||
TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE;
|
||||
TypeOfImage = ImageType::SHAPEDIMAGE;
|
||||
this->fastRenderering = fastRendererOn;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false);
|
||||
shaped->setPolygon(this->polygonData);
|
||||
shaped->imageData.fill(Qt::transparent);
|
||||
shaped->TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE;
|
||||
shaped->TypeOfImage = ImageType::SHAPEDIMAGE;
|
||||
return shaped;
|
||||
}
|
||||
|
||||
@@ -111,3 +111,7 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
calculateVisiblity();
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<QPoint> IntelliShapedImage::getPolygon(){
|
||||
return polygonData;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,14 @@ virtual std::vector<QPoint> getPolygonData() override {
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,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;
|
||||
@@ -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;
|
||||
updateTools();
|
||||
newLayer.width = width;
|
||||
newLayer.height = height;
|
||||
newLayer.widthOffset = widthOffset;
|
||||
newLayer.heightOffset = heightOffset;
|
||||
if(type==IntelliImage::ImageType::RASTERIMAGE) {
|
||||
newLayer.alpha = alpha;
|
||||
if(type==ImageType::RASTERIMAGE) {
|
||||
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.alpha = 255;
|
||||
this->layerBundle.push_back(newLayer);
|
||||
activeLayer = static_cast<int>(layerBundle.size()) - 1;
|
||||
return activeLayer;
|
||||
@@ -117,7 +129,7 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
|
||||
}
|
||||
void PaintingArea::setPolygon(int idx){
|
||||
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;
|
||||
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
|
||||
isSettingPolygon = true;
|
||||
@@ -138,6 +150,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) {
|
||||
@@ -249,7 +268,7 @@ int PaintingArea::getMaxHeight(){
|
||||
return this->maxHeight;
|
||||
}
|
||||
|
||||
IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){
|
||||
ImageType PaintingArea::getTypeOfImageRealLayer(){
|
||||
return this->layerBundle[static_cast<size_t>(activeLayer)].image->getTypeOfImage();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,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.
|
||||
@@ -92,16 +98,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, 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
|
||||
* \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
|
||||
* \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
|
||||
* \param idx - The index of the layer to be removed
|
||||
@@ -183,7 +194,7 @@ int getMaxWidth();
|
||||
|
||||
int getMaxHeight();
|
||||
|
||||
IntelliImage::ImageType getTypeOfImageRealLayer();
|
||||
ImageType getTypeOfImageRealLayer();
|
||||
|
||||
std::vector<QPoint> getPolygonDataOfRealLayer();
|
||||
|
||||
@@ -206,6 +217,11 @@ std::vector<LayerObject>* getLayerBundle();
|
||||
IntelliToolsettings Toolsettings;
|
||||
IntelliColorPicker colorPicker;
|
||||
|
||||
void setLayerDimensions(int maxWidth, int maxHeight);
|
||||
|
||||
void setPixelToActive(QColor color, QPoint point);
|
||||
|
||||
void setPolygonDataToActive(std::vector<QPoint> points);
|
||||
public slots:
|
||||
/*!
|
||||
* \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;
|
||||
|
||||
private:
|
||||
void setLayerDimensions(int maxWidth, int maxHeight);
|
||||
void selectLayerUp();
|
||||
void selectLayerDown();
|
||||
IntelliTool* copyActiveTool();
|
||||
|
||||
@@ -24,7 +24,7 @@ IntelliToolPolygon::~IntelliToolPolygon(){
|
||||
}
|
||||
|
||||
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) {
|
||||
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
|
||||
QPoint Point(x,y);
|
||||
@@ -37,7 +37,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user