Merge branch 'dev-save' into dev-history

This commit is contained in:
Jonas Mucke
2020-01-23 20:22:06 +01:00
13 changed files with 233 additions and 15 deletions

View File

@@ -3,8 +3,10 @@
#include "IntelliPhotoGui.h"
#include "Layer/PaintingArea.h"
#include "QEvent"
#include "QCloseEvent"
#include <QEvent>
#include <QCloseEvent>
#include <QDebug>
#include <string>
// IntelliPhotoGui constructor
IntelliPhotoGui::IntelliPhotoGui(){
@@ -50,10 +52,28 @@ void IntelliPhotoGui::slotOpen(){
// If we have a file name load the image and place
// it in the paintingArea
if (!fileName.isEmpty()) {
paintingArea->open(fileName);
UpdateGui();
}
}
bool rightFileType =true;
if(fileName.size()>=4){
QString endung(".idf");
int length = fileName.size();
for(int i=0; i<4; i++){
if(endung[i]!=fileName[length-4+i]){
rightFileType = false;
break;
}
}
}
if(rightFileType){
IntelliDatamanager::loadProject(paintingArea,fileName);
UpdateGui();
}
else{
paintingArea->open(fileName);
}
}
}
}
// Called when the user clicks Save As in the menu
@@ -82,7 +102,7 @@ void IntelliPhotoGui::slotCreateNewRasterLayer(){
// Create New Layer
if (ok1&&ok2) {
paintingArea->addLayer(width,height,0,0,ImageType::RASTERIMAGE);
paintingArea->addLayer(width,height,0,0,255,ImageType::RASTERIMAGE);
UpdateGui();
}
}
@@ -101,7 +121,7 @@ void IntelliPhotoGui::slotCreateNewShapedLayer(){
// Create New Layer
if (ok1&&ok2) {
paintingArea->addLayer(width, height, 0, 0, ImageType::SHAPEDIMAGE);
paintingArea->addLayer(width, height, 0, 0,255, ImageType::SHAPEDIMAGE);
UpdateGui();
}
}
@@ -364,6 +384,14 @@ void IntelliPhotoGui::createActions(){
actionSaveAs.append(pngSaveAction);
pngSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
QAction*projectSaveAction = new QAction("Projekt", this);
projectSaveAction->setData("idf");
// When clicked call IntelliPhotoGui::save()
connect(projectSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
// Attach each PNG in save Menu
actionSaveAs.append(projectSaveAction);
projectSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
// Create exit action and tie to IntelliPhotoGui::close()
actionExit = new QAction(tr("&Exit"), this);
actionExit->setShortcuts(QKeySequence::Quit);
@@ -835,6 +863,10 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
return false;
} else {
// Call for the file to be saved
if(fileFormat == "idf"){
return IntelliDatamanager::saveProject(paintingArea, fileName);
}
return paintingArea->save(fileName, fileFormat.constData());
}
}

View File

@@ -15,6 +15,7 @@
#include <QLabel>
#include <QLineEdit>
#include "IntelliInputDialog.h"
#include "IntelliHelper/IntelliDatamanager.h"
//for unit testing
class UnitTest;

View File

@@ -32,7 +32,6 @@ friend UnitTest;
friend IntelliTool;
public:
protected:
void resizeImage(QImage*image, const QSize &newSize);

View File

@@ -59,3 +59,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>();
}

View File

@@ -59,6 +59,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

View File

@@ -118,3 +118,7 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
calculateVisiblity();
return;
}
std::vector<QPoint> IntelliShapedImage::getPolygon(){
return polygonData;
}

View File

@@ -78,6 +78,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

View File

@@ -0,0 +1,101 @@
#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->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;
}
return false;
}

View File

@@ -0,0 +1,16 @@
#ifndef INTELLIDATAMANAGER_H
#define INTELLIDATAMANAGER_H
#include <QFile>
#include <QDebug>
class PaintingArea;
namespace IntelliDatamanager{
bool loadProject(PaintingArea* Canvas, QString filePath = "unnamed.idf");
bool saveProject(PaintingArea* Canvas, QString filePath = "unnamed.idf");
}
#endif // INTELLIDATAMANAGER_H

View File

@@ -22,6 +22,7 @@ SOURCES += \
Image/IntelliRasterImage.cpp \
Image/IntelliShapedImage.cpp \
IntelliHelper/IntelliColorPicker.cpp \
IntelliHelper/IntelliDatamanager.cpp \
IntelliHelper/IntelliRenderSettings.cpp \
IntelliHelper/IntelliToolsettings.cpp \
IntelliHelper/IntelliTriangulation.cpp \
@@ -43,6 +44,7 @@ HEADERS += \
Image/IntelliRasterImage.h \
Image/IntelliShapedImage.h \
IntelliHelper/IntelliColorPicker.h \
IntelliHelper/IntelliDatamanager.h \
IntelliHelper/IntelliRenderSettings.h \
IntelliHelper/IntelliToolsettings.h \
IntelliHelper/IntelliTriangulation.h \

View File

@@ -17,6 +17,7 @@
#include "Tool/IntelliToolRectangle.h"
#include "Tool/IntelliToolFloodFill.h"
#include "Tool/IntelliToolPolygon.h"
#include "GUI/IntelliPhotoGui.h"
LayerObject::LayerObject(){
@@ -64,6 +65,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;
@@ -75,19 +80,27 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
}
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, 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;
newLayer.alpha = alpha;
if(type==ImageType::RASTERIMAGE) {
newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering());
}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;
historyadd();
@@ -155,6 +168,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) {
@@ -455,6 +475,10 @@ QImage PaintingArea::getImageDataOfActiveLayer(){
return returnImage;
}
std::vector<LayerObject>* PaintingArea::getLayerBundle(){
return &layerBundle;
}
void PaintingArea::updateTools(){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {

View File

@@ -7,7 +7,6 @@
#include <QPoint>
#include <QWidget>
#include <QList>
#include "GUI/IntelliPhotoGui.h"
#include "Image/IntelliImage.h"
#include "Image/IntelliRasterImage.h"
#include "Image/IntelliShapedImage.h"
@@ -16,7 +15,7 @@
//for unit testing
class UnitTest;
class IntelliPhotoGui;
/*!
* \brief The LayerObject struct holds all the information needed to construct a layer
*/
@@ -83,6 +82,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.
@@ -97,16 +102,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, ImageType type = 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
@@ -202,12 +212,23 @@ IntelliImage* getImageOfActiveLayer();
*/
QImage getImageDataOfActiveLayer();
/*!
* \brief getLayerBundle returns the real active layerbundle (care!)
* \return the reference of the currentLayerBundle
*/
std::vector<LayerObject>* getLayerBundle();
IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker;
void historyGoBack();
void historyGoForward();
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
@@ -229,7 +250,6 @@ void wheelEvent(QWheelEvent*event) override;
void paintEvent(QPaintEvent*event) override;
private:
void setLayerDimensions(int maxWidth, int maxHeight);
void selectLayerUp();
void selectLayerDown();
IntelliTool* copyActiveTool();

View File

@@ -1,5 +1,6 @@
#include "IntelliTool.h"
#include "Layer/PaintingArea.h"
#include "GUI/IntelliPhotoGui.h"
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){
this->Area = Area;