From 083368dcabeb0b8d4667b6d24928f3568f26e76d Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Thu, 23 Jan 2020 14:15:22 +0100 Subject: [PATCH] Bug with getting the filetype --- src/GUI/IntelliPhotoGui.cpp | 27 +++++++++++++++++++++-- src/GUI/IntelliPhotoGui.h | 1 + src/IntelliHelper/IntelliDatamanager.cpp | 28 +++++++++++++++++------- src/IntelliHelper/IntelliDatamanager.h | 17 +++++++------- src/Layer/PaintingArea.cpp | 1 + src/Layer/PaintingArea.h | 3 +-- src/Tool/IntelliTool.cpp | 1 + 7 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 5734d47..e5af83b 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -3,8 +3,10 @@ #include "IntelliPhotoGui.h" #include "Layer/PaintingArea.h" -#include "QEvent" -#include "QCloseEvent" +#include +#include +#include +#include // IntelliPhotoGui constructor IntelliPhotoGui::IntelliPhotoGui(){ @@ -50,6 +52,15 @@ void IntelliPhotoGui::slotOpen(){ // If we have a file name load the image and place // it in the paintingArea if (!fileName.isEmpty()) { + if(fileName.length()>3){ + if(*(fileName.rend()+1)==QChar('f') && + *(fileName.rend()+2)==QChar('d') && + *(fileName.rend()+3)==QChar('i') && + *(fileName.rend()+4)==QChar('.')){ + qDebug() << "works."; + IntelliDatamanager::loadProject(paintingArea,fileName); + } + } paintingArea->open(fileName); UpdateGui(); } @@ -356,6 +367,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); @@ -817,6 +836,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()); } } diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 8d164a4..b3f3641 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -15,6 +15,7 @@ #include #include #include "IntelliInputDialog.h" +#include "IntelliHelper/IntelliDatamanager.h" //for unit testing class UnitTest; diff --git a/src/IntelliHelper/IntelliDatamanager.cpp b/src/IntelliHelper/IntelliDatamanager.cpp index 38996c2..aed051e 100644 --- a/src/IntelliHelper/IntelliDatamanager.cpp +++ b/src/IntelliHelper/IntelliDatamanager.cpp @@ -1,16 +1,28 @@ #include "IntelliDatamanager.h" +#include "Layer/PaintingArea.h" -IntelliDatamanager::IntelliDatamanager() -{ +bool IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){ + QFile openFile(filePath); + + if(openFile.open(QIODevice::WriteOnly)){ + qDebug() << "works."; + openFile.write("Hahaha"); + openFile.close(); + return true; + } + + return false; } -void IntelliDatamanager::saveProject(PaintingArea* Canvas, QString filePath){ +bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ + QFile openFile(filePath); + if(openFile.open(QIODevice::ReadOnly)){ + qDebug() << openFile.readAll(); + openFile.close(); + return true; + } - return; -} - -void IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ - return; + return false; } diff --git a/src/IntelliHelper/IntelliDatamanager.h b/src/IntelliHelper/IntelliDatamanager.h index a70fbe5..eb121d9 100644 --- a/src/IntelliHelper/IntelliDatamanager.h +++ b/src/IntelliHelper/IntelliDatamanager.h @@ -1,17 +1,16 @@ #ifndef INTELLIDATAMANAGER_H #define INTELLIDATAMANAGER_H -#include "Layer/PaintingArea.h" #include +#include -class IntelliDatamanager -{ -private: +class PaintingArea; -public: - void loadProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); - void saveProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); - IntelliDatamanager(); -}; +namespace IntelliDatamanager{ + + bool loadProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); + bool saveProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); + +} #endif // INTELLIDATAMANAGER_H diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index b471da0..f3c676f 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -17,6 +17,7 @@ #include "Tool/IntelliToolRectangle.h" #include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolPolygon.h" +#include "GUI/IntelliPhotoGui.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 58eb411..107c6b9 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -7,7 +7,6 @@ #include #include #include -#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 */ diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 11ed60b..a6d3343 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -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;