diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index d3ab832..7166490 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -141,7 +141,7 @@ void IntelliPhotoGui::slotChangeDim(){ // Change dimension if (ok1&&ok2) { - paintingArea->setLayerDimensions(width,height); + paintingArea->setCanvasDimensions(width,height); UpdateGui(); } } @@ -153,7 +153,7 @@ void IntelliPhotoGui::slotDeleteLayer(){ // "delete Layer" is the title of the window // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int layerNumber = IntelliInputDialog::getInt("Delete Layer", "Number:", paintingArea->getNumberOfActiveLayer() + 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); + int layerNumber = IntelliInputDialog::getInt("Delete Layer", "Number:", paintingArea->getIndexOfActiveLayer() + 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); // Create New Layer if(ok1) { @@ -169,7 +169,7 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer() + 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); + int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getIndexOfActiveLayer() + 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); // "New Alpha" is the title of the window int alpha = IntelliInputDialog::getInt("Layer to set on", "Alpha:", 255, 0, 255, 1, &ok2); @@ -188,7 +188,7 @@ void IntelliPhotoGui::slotSetPolygon(){ // "Layer to set on" is the title of the window // the next tr is the text to display // Define the standard Value, min, max, step and ok button - int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getNumberOfActiveLayer() + 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); + int layer = IntelliInputDialog::getInt("Layer to set on", "Layer:", paintingArea->getIndexOfActiveLayer() + 1, 1, static_cast(paintingArea->layerBundle.size()), 1, &ok1); if (ok1) { @@ -784,7 +784,7 @@ void IntelliPhotoGui::createGui(){ SwitchColorButton->setIconSize(QSize(Buttonsize.width() * 2,Buttonsize.height())); ActiveLayerLine = new QLabel(); - QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1); + QString string = QString("Active Layer: %1").arg(paintingArea->getIndexOfActiveLayer() + 1); ActiveLayerLine->setText(string); ActiveLayerLine->setFixedSize(Buttonsize.width() * 2 + 10,(Buttonsize.height() * 2) / 3); @@ -922,7 +922,7 @@ void IntelliPhotoGui::setToolWidth(int value){ } void IntelliPhotoGui::UpdateGui(){ - QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1); + QString string = QString("Active Layer: %1").arg(paintingArea->getIndexOfActiveLayer() + 1); ActiveLayerLine->setText(string); IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); @@ -947,8 +947,8 @@ void IntelliPhotoGui::UpdateGui(){ if(paintingArea->layerBundle.size() != 0) { string = QString("%1x%2").arg(paintingArea->layerBundle[static_cast - (paintingArea->getNumberOfActiveLayer())].width).arg(paintingArea->layerBundle[static_cast - (paintingArea->getNumberOfActiveLayer())].height); + (paintingArea->getIndexOfActiveLayer())].width).arg(paintingArea->layerBundle[static_cast + (paintingArea->getIndexOfActiveLayer())].height); dimActive->setText(string); } else{ diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index ac6c3bc..1c114ca 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -171,10 +171,22 @@ virtual QImage getImageData(); */ virtual void setImageData(const QImage& newData); +/*! + * \brief getWidth returns the width of the Image. + * \return The width of the Image in pixel. + */ virtual int getWidth() const; +/*! + * \brief getHeight returns the height of the Image. + * \return The height of the Image in pixel. + */ virtual int getHeight() const; +/*! + * \brief isFastRendering returns if the Image is in fast rendering mode. + * \return True if the Image is fast rendered, flase otherwiese. + */ virtual bool isFastRendering() const; }; diff --git a/src/IntelliHelper/IntelliDatamanager.cpp b/src/IntelliHelper/IntelliDatamanager.cpp index a704f64..e82e378 100644 --- a/src/IntelliHelper/IntelliDatamanager.cpp +++ b/src/IntelliHelper/IntelliDatamanager.cpp @@ -61,7 +61,7 @@ bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ in >> widthCanvas >> heightCanvas; in >> numberOffLayers; - Canvas->setLayerDimensions(widthCanvas, heightCanvas); + Canvas->setCanvasDimensions(widthCanvas, heightCanvas); for(int i = 0; i> width >> height >> widthOffset >> heightOffset >> alpha; @@ -88,7 +88,7 @@ bool IntelliDatamanager::loadProject(PaintingArea* Canvas, QString filePath){ for(int k = 0; k> red >> green >> blue >> alpha; - Canvas->setPixelToActive(QColor(red, green, blue, alpha), QPoint(j, k)); + Canvas->drawPixelOntoActive(QColor(red, green, blue, alpha), QPoint(j, k)); } } } diff --git a/src/IntelliHelper/IntelliDatamanager.h b/src/IntelliHelper/IntelliDatamanager.h index 777e591..9da93a4 100644 --- a/src/IntelliHelper/IntelliDatamanager.h +++ b/src/IntelliHelper/IntelliDatamanager.h @@ -8,7 +8,20 @@ class PaintingArea; namespace IntelliDatamanager { +/*! + * \brief loadProject loads a project from a file, closes current project. + * \param Canvas - Reference to the used Canvas. + * \param filePath - Filepath to the project which should be opened. + * \return True if everything worked, false otherwise. + */ bool loadProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); + +/*! + * \brief saveProject saves the current project to a file. + * \param Canvas - Reference to the used Canvas. + * \param filePath - Filepath to the project which should be saved. + * \return True if everything worked, false otherwise. + */ bool saveProject(PaintingArea* Canvas, QString filePath = "unnamed.idf"); } diff --git a/src/IntelliHelper/IntelliRenderSettings.h.autosave b/src/IntelliHelper/IntelliRenderSettings.h.autosave new file mode 100644 index 0000000..2fc3afb --- /dev/null +++ b/src/IntelliHelper/IntelliRenderSettings.h.autosave @@ -0,0 +1,34 @@ +#ifndef INTELLIRENDERSETTINGS_H +#define INTELLIRENDERSETTINGS_H + +//for unit testing +class UnitTest; + +/*! + * \brief The IntelliRenderSettings class which manages the render Settings. + */ +class IntelliRenderSettings +{ +friend UnitTest; +public: +IntelliRenderSettings(); + +/*! + * \brief setFastRendering sets fastRendering to Updatedsetting. + * \param Updatedsetting - Represents the new value for the Fast Rendering Flag. + */ +void setFastRendering(bool Updatedsetting); +/*! + * \brief The getfastRenderer gets the value of the flag for the fastRenderer setting. + * \return Returns true if fastRenderer is active else false + */ +bool isFastRenderering() const; + +private: +/*! + * \brief fastRenderering the state of the project, in relation the the render setting. + */ +bool fastRenderering = true; +}; + +#endif diff --git a/src/IntelliHelper/IntelliToolsettings.h.autosave b/src/IntelliHelper/IntelliToolsettings.h.autosave new file mode 100644 index 0000000..b251aa9 --- /dev/null +++ b/src/IntelliHelper/IntelliToolsettings.h.autosave @@ -0,0 +1,59 @@ +#ifndef INTELLITOOLSETTINGS_H +#define INTELLITOOLSETTINGS_H + +//for unit testing +class UnitTest; +/*! + * \brief The IntelliToolsettings class managing the settings of the tools, independent of an existing tool. + */ +class IntelliToolsettings { +friend UnitTest; +public: +/*! + * \brief IntelliToolsettings - basic constructor of the IntelliToolsettings, initializing the basics. + */ +IntelliToolsettings(); + +/*! + * \brief ~IntelliToolsettings - basic destructor. + */ +virtual ~IntelliToolsettings(); + +/*! + * \brief getLineWidth returns the width attribute of the line. + * \return returns the width attribute as integer. + */ +int getLineWidth() const; + +/*! + * \brief setLineWidth sets the width attribute of the line. + * \param LineWidth - the future width of the line + */ +void setLineWidth(int LineWidth); + +/*! + * \brief getInnerAlpha returns the inner alpha value. + * \return returns the inner alpha attribute as integer. + */ +int getInnerAlpha() const; + +/*! + * \brief setInnerAlpha sets the inner alpha attribute of the Tool. + * \param innerAlpha - the future inner alpha of the Tool. + */ +void setInnerAlpha(int innerAlpha); + +private: + +/*! + * \brief lineWidth attribute of a Tool. + */ +int lineWidth; + +/*! + * \brief innerAlpha aattribute of a Tool. + */ +int innerAlpha; +}; + +#endif diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 1b4236b..64f6134 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -40,7 +40,7 @@ LayerObject::LayerObject(const LayerObject& layer){ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QLabel(parent){ this->Tool = nullptr; - this->setLayerDimensions(maxWidth, maxHeight); + this->setCanvasDimensions(maxWidth, maxHeight); activeLayer = -1; } @@ -69,7 +69,7 @@ bool PaintingArea::getRenderSettings(){ return this->renderSettings.isFastRenderering(); } -void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ +void PaintingArea::setCanvasDimensions(int maxWidth, int maxHeight){ //set standart parameter this->maxWidth = maxWidth; this->maxHeight = maxHeight; @@ -83,7 +83,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ } -void PaintingArea::setPixelToActive(QColor color, QPoint point){ +void PaintingArea::drawPixelOntoActive(QColor color, QPoint point){ layerBundle[static_cast(activeLayer)].image->drawPixel(point, color); } @@ -296,11 +296,11 @@ int PaintingArea::getMaxHeight(){ return this->maxHeight; } -ImageType PaintingArea::getTypeOfImageRealLayer(){ +ImageType PaintingArea::getTypeOfImageActiveLayer(){ return this->layerBundle[static_cast(activeLayer)].image->getTypeOfImage(); } -std::vector PaintingArea::getPolygonDataOfRealLayer(){ +std::vector PaintingArea::getPolygonDataOfActiveLayer(){ return this->layerBundle[static_cast(activeLayer)].image->getPolygonData(); } @@ -463,7 +463,7 @@ IntelliTool* PaintingArea::copyActiveTool(){ } } -int PaintingArea::getNumberOfActiveLayer(){ +int PaintingArea::getIndexOfActiveLayer(){ return activeLayer; } @@ -510,14 +510,18 @@ void PaintingArea::updateTools(){ void PaintingArea::historyadd(){ - if (++historyPresent == 100) { + historyPresent++; + if (historyPresent == 100) { historyPresent = 0; } historyMaxFuture = historyPresent; - if (historyPresent == historyMaxPast) - if (++historyMaxPast == 100) + if (historyPresent == historyMaxPast){ + historyMaxPast++; + if (historyMaxPast == 100){ historyMaxPast = 0; - history[static_cast(historyPresent)] = layerBundle; + } + } + history[static_cast(historyPresent)] = layerBundle; } void PaintingArea::historyGoBack(){ diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 6aafff1..9dd6799 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -176,36 +176,91 @@ void colorPickerSetSecondColor(); */ void colorPickerSwapColors(); +/*! + * \brief createPenTool creates a Pen Tool. + */ void createPenTool(); + +/*! + * \brief createPlainTool creates a Plain Tool. + */ void createPlainTool(); + +/*! + * \brief createLineTool creates a Line Tool. + */ void createLineTool(); + +/*! + * \brief createRectangleTool creates a Rectangle Tool. + */ void createRectangleTool(); + +/*! + * \brief createCircleTool creates a Circle Tool. + */ void createCircleTool(); + +/*! + * \brief createPolygonTool creates a Polygon Tool. + */ void createPolygonTool(); + +/*! + * \brief createFloodFillTool creates a Floodfill Tool. + */ void createFloodFillTool(); + +/*! + * \brief createGradientTool creates a Gradient Tool. + */ void createGradientTool(); /*! - * \brief The getWidthOfActive gets the horizontal dimensions of the active layer - * \return Returns the horizontal pixle count of the active layer + * \brief The getWidthOfActive gets the horizontal dimensions of the active layer. + * \return Returns the horizontal pixle count of the active layer. */ int getWidthOfActive(); /*! - * \brief The getHeightOfActive gets the vertical dimensions of the active layer - * \return Returns the vertical pixle count of the active layer + * \brief The getHeightOfActive gets the vertical dimensions of the active layer. + * \return Returns the vertical pixle count of the active layer. */ int getHeightOfActive(); +/*! + * \brief getMaxWidth gets the max width of the Canvas. + * \return return the width of the Canvas. + */ int getMaxWidth(); +/*! + * \brief getMaxHeight gets the max height of the Canvas. + * \return return the height of the Canvas. + */ int getMaxHeight(); -ImageType getTypeOfImageRealLayer(); +/*! + * \brief getTypeOfImageActiveLayer get the type of the active Layer. + * \return returns the image type of the active layer. + */ +ImageType getTypeOfImageActiveLayer(); -std::vector getPolygonDataOfRealLayer(); +/*! + * \brief getPolygonDataOfActiveLayer get the polygon data of the active Layer. + * \return return the polygon data of the active Layer. + */ +std::vector getPolygonDataOfActiveLayer(); -int getNumberOfActiveLayer(); +/*! + * \brief getIndexOfActiveLayer returns the index of athe active Layer. + * \return return the index of the active Layer. + */ +int getIndexOfActiveLayer(); +/*! + * \brief getImageOfActiveLayer returns the image of the active Layer. + * \return return the image of the active Layer. + */ IntelliImage* getImageOfActiveLayer(); /*! @@ -220,16 +275,44 @@ QImage getImageDataOfActiveLayer(); */ std::vector* getLayerBundle(); +/*! + * \brief Toolsettings - a class to manage Tool settings. + */ IntelliToolsettings Toolsettings; + +/*! + * \brief colorPicker a class to manage Tool color. + */ IntelliColorPicker colorPicker; +/*! + * \brief historyGoBack a function to return the previous state of the project. + */ void historyGoBack(); + +/*! + * \brief historyGoForward a function to undo the return of the previous state of the project. + */ void historyGoForward(); -void setLayerDimensions(int maxWidth, int maxHeight); +/*! + * \brief setCanvasDimensions sets the dimension of the Canvas + * \param maxWidth - the width of the Canvas. + * \param maxHeight - the height of the Canvas. + */ +void setCanvasDimensions(int maxWidth, int maxHeight); -void setPixelToActive(QColor color, QPoint point); +/*! + * \brief drawPixelOntoActive draws a pixel onto the image data of the active Layer. + * \param color - the color of the Pixel, which should be created. + * \param point - the Pixelposition. + */ +void drawPixelOntoActive(QColor color, QPoint point); +/*! + * \brief setPolygonDataToActive sets polygondata to the active Layer. + * \param points - the points of the polygon data. + */ void setPolygonDataToActive(std::vector points); public slots: /*! diff --git a/src/Layer/PaintingArea.h.autosave b/src/Layer/PaintingArea.h.autosave new file mode 100644 index 0000000..41d98db --- /dev/null +++ b/src/Layer/PaintingArea.h.autosave @@ -0,0 +1,481 @@ + +#ifndef PaintingArea_H +#define PaintingArea_H + +#include +#include +#include +#include +#include +#include +#include "Image/IntelliImage.h" +#include "Image/IntelliRasterImage.h" +#include "Image/IntelliShapedImage.h" +#include "Tool/IntelliTool.h" +#include "IntelliHelper/IntelliColorPicker.h" + +//for unit testing +class UnitTest; +class IntelliPhotoGui; +/*! + * \brief The LayerObject struct holds all the information needed to construct a layer + */ +struct LayerObject { + /*! + * \brief image - Stores the imageData of the current LayerObject. + */ + IntelliImage* image; + /*! + * \brief width - Stores the width of a layer in pixels. + */ + int width; + /*! + * \brief height - Stores the height of a layer in pixels. + */ + int height; + /*! + * \brief widthOffset - Stores the number of pixles from the left side of the painting area. + */ + int widthOffset; + /*! + * \brief heightOffset - Stores the number of pixles from the top of the painting area. + */ + int heightOffset; + /*! + * \brief alpha - Stores the alpha value of the layer (default=255). + */ + int alpha = 255; + + LayerObject(); + + LayerObject(const LayerObject& layer); +}; + +/*! + * \brief The PaintingArea class manages the methods and stores information about the current painting area, which is the currently opened project + */ +class PaintingArea : public QLabel +{ +friend UnitTest; +// Declares our class as a QObject which is the base class +// for all Qt objects +// QObjects handle events +Q_OBJECT +friend IntelliTool; +friend IntelliPhotoGui; +public: +/*! + * \brief PaintingArea is the constructor of the PaintingArea class, which initiates the working environment + * \param maxWidth - The maximum amount of pixles that are inside painting area from left to right (default=600px) + * \param maxHeight - The maximum amount of pixles that are inside painting area from top to bottom (default=600px) + * \param parent - The parent window of the main window (default=nullptr) + */ +PaintingArea(int maxWidth = 600, int maxHeight = 600, QWidget*parent = nullptr); + +/*! + * \brief This deconstructor is used to clear up the memory and remove the currently active window + */ +~PaintingArea() override; + +/*! + * \brief setRenderSettings updates all Images to the new Rendersetting. + * \param isFastRenderingOn is the new given flag for the FastRenderer. + */ +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. + * \return Returns a boolean variable whether the file was successfully opened or not. + */ +bool open(const QString &filePath); +/*! + * \brief The save method is used for exporting the current project as one picture + * \param filePath - Specifies the path and name of the file to create. + * \param fileFormat - Specifies the format of the file to create. + * \return Returns a boolean variable, true if the file was saved successfully, false if not + */ +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, 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 + * \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 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, 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 + * \param isTool - Is the flag for when a tool uses this function. + */ +void deleteLayer(int idx, bool isTool = false); +/*! + * \brief The setLayerToActive method marks a specific layer as active + * \param idx - The index of the layer to be active + */ +void setLayerActive(int idx); +/*! + * \brief The setAlphaOfLayer method sets the alpha value of a specific layer + * \param idx - The index of the layer where the change should be applied + * \param alpha - New alpha value of the layer + */ +void setLayerAlpha(int idx, int alpha); +/*! + * \brief setPolygon is used for setting polygondata, it only works on RASTER images + * \param idx - represents the number of the layer with should be transformed + */ +void setPolygon(int idx); +/*! + * \brief The movePositionActive method moves the active layer to certain position + * \param x - The x value the new center of the layer should be at + * \param y - The y value the new center of the layer should be at + */ +void movePositionActive(int x, int y); +/*! + * \brief The moveActiveLayer moves the active layer to a specific position in the layer stack + * \param idx - The index of the new position the layer should be in + */ +void moveActiveLayer(int idx); + +/*! + * \brief The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color + */ +void colorPickerSetFirstColor(); +/*! + * \brief The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color + */ +void colorPickerSetSecondColor(); +/*! + * \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color + */ +void colorPickerSwapColors(); + +/*! + * \brief createPenTool creates a Pen Tool. + */ +void createPenTool(); + +/*! + * \brief createPlainTool creates a Plain Tool. + */ +void createPlainTool(); + +/*! + * \brief createLineTool creates a Line Tool. + */ +void createLineTool(); + +/*! + * \brief createRectangleTool creates a Rectangle Tool. + */ +void createRectangleTool(); + +/*! + * \brief createCircleTool creates a Circle Tool. + */ +void createCircleTool(); + +/*! + * \brief createPolygonTool creates a Polygon Tool. + */ +void createPolygonTool(); + +/*! + * \brief createFloodFillTool creates a Floodfill Tool. + */ +void createFloodFillTool(); + +/*! + * \brief createGradientTool creates a Gradient Tool. + */ +void createGradientTool(); + +/*! + * \brief The getWidthOfActive gets the horizontal dimensions of the active layer. + * \return Returns the horizontal pixle count of the active layer. + */ +int getWidthOfActive(); +/*! + * \brief The getHeightOfActive gets the vertical dimensions of the active layer. + * \return Returns the vertical pixle count of the active layer. + */ +int getHeightOfActive(); + +/*! + * \brief getMaxWidth gets the max width of the Canvas. + * \return return the width of the Canvas. + */ +int getMaxWidth(); + +/*! + * \brief getMaxHeight gets the max height of the Canvas. + * \return return the height of the Canvas. + */ +int getMaxHeight(); + +/*! + * \brief getTypeOfImageActiveLayer get the type of the active Layer. + * \return returns the image type of the active layer. + */ +ImageType getTypeOfImageActiveLayer(); + +/*! + * \brief getPolygonDataOfActiveLayer get the polygon data of the active Layer. + * \return return the polygon data of the active Layer. + */ +std::vector getPolygonDataOfActiveLayer(); + +/*! + * \brief getIndexOfActiveLayer returns the index of athe active Layer. + * \return return the index of the active Layer. + */ +int getIndexOfActiveLayer(); + +/*! + * \brief getImageOfActiveLayer returns the image of the active Layer. + * \return return the image of the active Layer. + */ +IntelliImage* getImageOfActiveLayer(); + +/*! + * \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture) + * \return return the image as an rgba32bit qImage + */ +QImage getImageDataOfActiveLayer(); + +/*! + * \brief getLayerBundle returns the real active layerbundle (care!) + * \return the reference of the currentLayerBundle + */ +std::vector* getLayerBundle(); + +/*! + * \brief Toolsettings - a class to manage Tool settings. + */ +IntelliToolsettings Toolsettings; + +/*! + * \brief colorPicker a class to manage Tool color. + */ +IntelliColorPicker colorPicker; + +/*! + * \brief historyGoBack a function to return the previous state of the project. + */ +void historyGoBack(); + +/*! + * \brief historyGoForward a function to undo the return of the previous state of the project. + */ +void historyGoForward(); + +/*! + * \brief setCanvasDimensions sets the dimension of the Canvas + * \param maxWidth - the width of the Canvas. + * \param maxHeight - the height of the Canvas. + */ +void setCanvasDimensions(int maxWidth, int maxHeight); + +/*! + * \brief drawPixelOntoActive draws a pixel onto the image data of the active Layer. + * \param color - the color of the Pixel, which should be created. + * \param point - the Pixelposition. + */ +void drawPixelOntoActive(QColor color, QPoint point); + +/*! + * \brief setPolygonDataToActive sets polygondata to the active Layer. + * \param points - the points of the polygon data. + */ +void setPolygonDataToActive(std::vector points); +public slots: +/*! + * \brief The slotActivateLayer method handles the event of selecting one layer as active + * \param a - idx of the layer to be active + */ +void slotActivateLayer(int a); +/*! + * \brief The slotDeleteActiveLayer method handles the deletion of the active layer + */ +void slotDeleteActiveLayer(); + +protected: +/*! + * \brief mousePressEvent handles a mouse pressed event. + * \param event - the specific mouse event. + */ +void mousePressEvent(QMouseEvent*event) override; + +/*! + * \brief mouseMoveEvent handles a mouse moved event + * \param event - the specific mouse event. + */ +void mouseMoveEvent(QMouseEvent*event) override; + +/*! + * \brief mouseReleaseEvent handles a mouse released event + * \param event - the specific mouse event. + */ +void mouseReleaseEvent(QMouseEvent*event) override; + +/*! + * \brief wheelEvent handles a mouse wheel event + * \param event - the specific mouse event. + */ +void wheelEvent(QWheelEvent*event) override; + +/*! + * \brief paintEvent handles a painting event + * \param event - the specific paint event. + */ +void paintEvent(QPaintEvent*event) override; + +private: +/*! + * \brief offsetXDimension - Offset for drawing the image. + */ +int offsetXDimension; + +/*! + * \brief offsetYDimension - Offset for drawing the image. + */ +int offsetYDimension; + +/*! + * \brief selectLayerUp moves the active Layer one Up. + */ +void selectLayerUp(); + +/*! + * \brief selectLayerDown moves the active Layer one Down. + */ +void selectLayerDown(); + +/*! + * \brief copyActiveTool copys the activ tool [allocated]. + * \return returns a allocates copy of the current tool. + */ +IntelliTool* copyActiveTool(); + +/*! + * \brief Canvas the underlying Image to display on. + */ +QImage* Canvas; + +/*! + * \brief ScaledCanvas the Canvas saved for output + */ +QImage ScaledCanvas; + +/*! + * \brief maxWidth is the width of the canvas + */ +int maxWidth; + +/*! + * \brief maxHeight is the height of the canvas + */ +int maxHeight; + +/*! + * \brief isSettingPolygon for checking the state of the drawing. + */ +bool isSettingPolygon = false; + +/*! + * \brief renderSettings a class to manage the render settings. + */ +IntelliRenderSettings renderSettings; + +/*! + * \brief Tool a class to manage the Tool. + */ +IntelliTool* Tool; + +/*! + * \brief guiReference to manage communication with the gui. + */ +IntelliPhotoGui* guiReference; + +/*! + * \brief layerBundle a container to save all layers. + */ +std::vector layerBundle; + +/*! + * \brief activeLayer the index of the active Layer. + */ +int activeLayer = -1; + +/*! + * \brief drawLayers draws the Layers to the Canvas + * \param forSaving an indecate if drawing for saving. + */ +void drawLayers(bool forSaving = false); + +/*! + * \brief createTempTopLayer creates a temporary Layer on top of the Layer. + * \param idx - the Layer which should get a temp Layer. + * \return True if it workes, false otherwise. + */ +bool createTempTopLayer(int idx); + +/*! + * \brief updateTools resets the Tools. + */ +void updateTools(); + +/*! + * \brief history - an array out of containers to save history actions. + */ +std::vector history[100] = {layerBundle}; + +/*! + * \brief historyMaxPast a indicator how many steps you can go into the past. + */ +int historyMaxPast = 0; + +/*! + * \brief historyMaxPast a indicator how many steps you can go into the future. + */ +int historyMaxFuture = 0; + +/*! + * \brief historyPresent a indicator where the present is. + */ +int historyPresent = 0; + +/*! + * \brief historyadd adds an past version to the history + */ +void historyadd(); + +}; + +#endif diff --git a/src/Tool/IntelliTool.h b/src/Tool/IntelliTool.h index 40901f0..07abb46 100644 --- a/src/Tool/IntelliTool.h +++ b/src/Tool/IntelliTool.h @@ -17,9 +17,13 @@ class PaintingArea; class IntelliTool { friend UnitTest; public: +/*! + * \brief The Tooltype enum categorising the toosl. + */ enum class Tooltype { CIRCLE, FLOODFILL, + GRADIENT, LINE, PEN, PLAIN, @@ -49,6 +53,9 @@ protected: */ PaintingArea* Area; +/*! + * \brief ActiveType the type of the active tool. + */ Tooltype ActiveType; /*! @@ -56,6 +63,9 @@ Tooltype ActiveType; */ IntelliColorPicker* colorPicker; +/*! + * \brief Toolsettings a refrence to the tool settings + */ IntelliToolsettings* Toolsettings; /*! @@ -127,8 +137,16 @@ virtual void onWheelScrolled(int value); */ virtual void onMouseMoved(int x, int y); +/*! + * \brief getTooltype returns the tools type + * \return returns the tool type of the current tool. + */ Tooltype getTooltype() const; +/*! + * \brief getIsDrawing returns if the tool is currently drawing + * \return returns if the tool is currently drawing + */ bool getIsDrawing() const; }; diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp index 8f33fb4..25cb503 100644 --- a/src/Tool/IntelliToolGradient.cpp +++ b/src/Tool/IntelliToolGradient.cpp @@ -5,6 +5,7 @@ IntelliToolGradient::IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::GRADIENT; this->LineColor = QColor(0,0,0,255); this->hasMoved = false; } diff --git a/src/Tool/IntelliToolGradient.cpp.autosave b/src/Tool/IntelliToolGradient.cpp.autosave new file mode 100644 index 0000000..eb90ea9 --- /dev/null +++ b/src/Tool/IntelliToolGradient.cpp.autosave @@ -0,0 +1,131 @@ +#include "IntelliToolGradient.h" +#include "Layer/PaintingArea.h" +#include "math.h" +#include + +IntelliToolGradient::IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::GRADIENT; + this->LineColor = QColor(0,0,0,255); + this->hasMoved = false; +} + +IntelliToolGradient::~IntelliToolGradient(){ + IntelliTool::onMouseRightPressed(0,0); +} + +void IntelliToolGradient::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + startPoint_double[0] = static_cast(x); + startPoint_double[1] = static_cast(y); + startPoint = QPoint(x,y); + endPoint = QPoint(x,y); + endPoint_double[0] = 0; + endPoint_double[1] = 0; + Canvas->image->drawPixel(startPoint,LineColor); +} + +void IntelliToolGradient::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolGradient::onMouseLeftReleased(int x, int y){ + if(hasMoved && this->isDrawing){ + computeGradientLayer(); + IntelliTool::onMouseLeftReleased(x,y); + } +} + +void IntelliToolGradient::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolGradient::onMouseMoved(int x, int y){ + if(this->isDrawing){ + hasMoved = true; + endPoint = QPoint(x,y); + endPoint_double[0] = static_cast(endPoint.x() - startPoint.x()); + endPoint_double[1] = static_cast(endPoint.y() - startPoint.y()); + NormalVector[0] = endPoint_double[1]; + NormalVector[1] = (-1*endPoint_double[0]); + NormalDotNormal = dotProduct(NormalVector,NormalVector); + this->Canvas->image->drawPlain(Qt::transparent); + computeGradientLayer(); + Canvas->image->drawLine(startPoint,endPoint,LineColor,1); + } + IntelliTool::onMouseMoved(x,y); +} + +void IntelliToolGradient::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); +} + +void IntelliToolGradient::computeAndDrawPixelColor(QPoint Point){ + double doublePoint[2]; + doublePoint[0] = static_cast(Point.x()); + doublePoint[1] = static_cast(Point.y()); + double doublePointSubA[2]; + doublePointSubA[0] = doublePoint[0] - startPoint_double[0]; + doublePointSubA[1] = doublePoint[1] - startPoint_double[1]; + double Perpendicular[2]; + double PointSubADotNormal = dotProduct(doublePointSubA,NormalVector); + Perpendicular[0] = doublePoint[0] - (PointSubADotNormal / NormalDotNormal) * NormalVector[0]; + Perpendicular[1] = doublePoint[1] - (PointSubADotNormal / NormalDotNormal) * NormalVector[1]; + double VectorAPoint[2]; + VectorAPoint[0] = static_cast(Perpendicular[0] - startPoint_double[0]); + VectorAPoint[1] = static_cast(Perpendicular[1] - startPoint_double[1]); + double ratio; + if(((VectorAPoint[0] < 0 && endPoint_double[0] < 0) || (VectorAPoint[0] > 0 && endPoint_double[0] > 0)) && ((VectorAPoint[1] < 0 && endPoint_double[1] < 0) || (VectorAPoint[1] > 0 && endPoint_double[1] > 0))) + ratio = lenghtVector(VectorAPoint)/lenghtVector(endPoint_double); + else{ + ratio = -1; + } + QColor computedColor; + if(ratio < 0){ + computedColor = colorPicker->getFirstColor(); + } + else if(ratio > 1){ + computedColor = colorPicker->getSecondColor(); + } + else{ + int red; + int green; + int blue; + int alpha; + int red2; + int green2; + int blue2; + int alpha2; + colorPicker->getFirstColor().getRgb(&red,&green,&blue,&alpha); + colorPicker->getSecondColor().getRgb(&red2,&green2,&blue2,&alpha2); + computedColor.setRed(static_cast(ratio * red2 + (1 - ratio) * red)); + computedColor.setGreen(static_cast(ratio * green2 + (1 - ratio) * green)); + computedColor.setBlue(static_cast(ratio * blue2 + (1 - ratio) * blue)); + computedColor.setAlpha(static_cast(ratio * alpha2 + (1 - ratio) * alpha)); + } + Canvas->image->drawPixel(Point,computedColor); +} + +double IntelliToolGradient::dotProduct(double Vector1[2], double Vector2[2]){ + return static_cast(Vector1[0]*Vector2[0]+Vector1[1]*Vector2[1]); +} + +double IntelliToolGradient::lenghtVector(double Vector[2]){ + return static_cast((sqrt(Vector[0] * Vector[0] + Vector[1] * Vector[1]))); +} + +void IntelliToolGradient::computeGradientLayer(){ + bool switched = false; + if(Canvas->image->isFastRendering()){ + switched = true; + Canvas->image->updateRendererSetting(false); + } + for(int i = 0; i < activeLayer->height; i++){ + for(int j = 0; j < activeLayer->width; j++){ + computeAndDrawPixelColor(QPoint(j,i)); + } + } + if(switched){ + Canvas->image->updateRendererSetting(true); + } +} diff --git a/src/Tool/IntelliToolGradient.h b/src/Tool/IntelliToolGradient.h index 01b0159..caf9b81 100644 --- a/src/Tool/IntelliToolGradient.h +++ b/src/Tool/IntelliToolGradient.h @@ -1,12 +1,23 @@ #ifndef INTELLITOOLGRADIENT_H #define INTELLITOOLGRADIENT_H #include "IntelliTool.h" - +/*! + * \brief The IntelliToolGradient class that represents a gradient call + */ class IntelliToolGradient : public IntelliTool{ public: + /*! + * \brief IntelliToolGradient basic constructor of the gradient tool. + * \param Area - a reference to the paintingArea + * \param colorPicker - a reference to the colorpicker + * \param Toolsettings - a regerence to the Toolsettings + */ IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); + /*! + * \brief ~IntelliToolGradient basic destructor. + */ virtual ~IntelliToolGradient() override; /*! @@ -51,21 +62,70 @@ public: virtual void onMouseMoved(int x, int y) override; private: - QPoint A; - QPoint B; - double doubleA[2]; - double VectorAB[2]; + + /*! + * \brief startPoint of the line + */ + QPoint startPoint; + + /*! + * \brief endPoint of the line + */ + QPoint endPoint; + /*! + * \brief doubleStartPoint startPoint as double Values + */ + double doubleStartPoint[2]; + + /*! + * \brief VectorStartEnd a vector between start and end point. + */ + double VectorStartEnd[2]; + + /*! + * \brief NormalVector of the VectorStartEnd + */ double NormalVector[2]; + + /*! + * \brief NormalDotNormal dot product of Normal*Normal + */ double NormalDotNormal; + + /*! + * \brief LineColor color of th line. + */ QColor LineColor; + + /*! + * \brief hasMoved indicates a movement + */ bool hasMoved; - void computePixelColor(QPoint Point); + /*! + * \brief computeAndDrawPixelColor computes the pixelcolor for a given point and sets it to the image. + * \param Point the point which shoud be computed + */ + void computeAndDrawPixelColor(QPoint Point); + /*! + * \brief dotProduct calculates the dot product of 2 vetors. + * \param Vector1 - first argument + * \param Vector2 - second argument + * \return returns the dot product. + */ double dotProduct(double Vector1[2], double Vector2[2]); + /*! + * \brief lenghtVector returns the length of a vector + * \param Vector - Vector to calculate the length + * \return returns the length of the vector + */ double lenghtVector(double Vector[2]); + /*! + * \brief computeGradientLayer computes the gradient over all pixels in the image. + */ void computeGradientLayer(); }; diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 3efd0d5..b6d8b4e 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -24,9 +24,9 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { - if(Area->getPolygonDataOfRealLayer().size()>2) { - std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); + if(!drawingOfPolygon && Area->getTypeOfImageActiveLayer() == ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(Area->getPolygonDataOfActiveLayer().size()>2) { + std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfActiveLayer()); QPoint Point(x,y); isInside = IntelliTriangulation::isInPolygon(Triangles,Point); } @@ -37,7 +37,7 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ isInside = true; } } - else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + else if(!drawingOfPolygon && Area->getTypeOfImageActiveLayer() == ImageType::RASTERIMAGE && x >= 0 && y >= 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; }