Merge branch 'dev' into UnitTesting

This commit is contained in:
2020-01-16 10:45:23 +01:00
14 changed files with 717 additions and 621 deletions

View File

@@ -18,10 +18,13 @@
#include "Tool/IntelliToolFloodFill.h"
#include "Tool/IntelliToolPolygon.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){
this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight);
activeLayer=-1;
}
PaintingArea::~PaintingArea(){
@@ -29,12 +32,12 @@ PaintingArea::~PaintingArea(){
}
void PaintingArea::setRenderSettings(bool isFastRenderingOn){
if(isFastRenderingOn != renderSettings.isFastRenderering()){
renderSettings.setFastRendering(isFastRenderingOn);
for(auto& layer : layerBundle){
layer.image->updateRendererSetting(isFastRenderingOn);
}
}
if(isFastRenderingOn != renderSettings.isFastRenderering()) {
renderSettings.setFastRendering(isFastRenderingOn);
for(auto& layer : layerBundle) {
layer.image->updateRendererSetting(isFastRenderingOn);
}
}
}
void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
@@ -50,14 +53,15 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){
LayerObject newLayer;
updateTools();
newLayer.width = width;
newLayer.height = height;
newLayer.widthOffset = widthOffset;
newLayer.heightOffset = heightOffset;
if(type==IntelliImage::ImageType::RASTERIMAGE) {
newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering());
}else if(type==IntelliImage::ImageType::SHAPEDIMAGE) {
newLayer.image = new IntelliShapedImage(width, height, renderSettings.isFastRenderering());
if(type==IntelliImage::ImageType::RASTERIMAGE) {
newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering());
}else if(type==IntelliImage::ImageType::SHAPEDIMAGE) {
newLayer.image = new IntelliShapedImage(width, height, renderSettings.isFastRenderering());
}
newLayer.alpha = 255;
this->layerBundle.push_back(newLayer);
@@ -66,15 +70,18 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
}
void PaintingArea::deleteLayer(int idx){
if(idx < static_cast<int>(layerBundle.size())&&idx>=0) {
void PaintingArea::deleteLayer(int idx, bool isTool){
if(!isTool) {
updateTools();
}
if(idx<static_cast<int>(layerBundle.size())&&idx>=0) {
this->layerBundle.erase(layerBundle.begin()+idx);
if(activeLayer>=idx) {
if(activeLayer>=idx) {
activeLayer--;
}
if(activeLayer < 0 && layerBundle.size()){
activeLayer=0;
}
if(activeLayer < 0 && layerBundle.size()) {
activeLayer=0;
}
}
}
@@ -86,6 +93,7 @@ void PaintingArea::slotDeleteActiveLayer(){
}
void PaintingArea::setLayerActive(int idx){
updateTools();
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
this->activeLayer=idx;
}
@@ -93,9 +101,18 @@ void PaintingArea::setLayerActive(int idx){
void PaintingArea::setLayerAlpha(int idx, int alpha){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
if(alpha>=0 && alpha<=255) {
layerBundle[static_cast<size_t>(idx)].alpha=alpha;
}
if(alpha>=0 && alpha<=255) {
layerBundle[static_cast<size_t>(idx)].alpha=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) {
delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true;
}
}
}
@@ -135,42 +152,14 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){
}
}
// Color the image area with white
void PaintingArea::floodFill(int r, int g, int b, int a){
if(this->activeLayer==-1) {
return;
}
if(r >255 || g>255|| b>255 || a>255){
return;
}
if(r < 0 || g < 0|| b < 0 || a < 0){
return;
}
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
active->drawPlain(QColor(r, g, b, a));
update();
}
void PaintingArea::movePositionActive(int x, int y){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
}
void PaintingArea::moveActiveLayer(int idx){
if(Tool != nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
if(idx==1) {
this->selectLayerUp();
}else if(idx==-1) {
@@ -179,13 +168,7 @@ void PaintingArea::moveActiveLayer(int idx){
}
void PaintingArea::slotActivateLayer(int a){
if(Tool != nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
updateTools();
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
this->setLayerActive(a);
}
@@ -259,9 +242,9 @@ std::vector<QPoint> PaintingArea::getPolygonDataOfRealLayer(){
// left button and if so store the current position
// Set that we are currently drawing
void PaintingArea::mousePressEvent(QMouseEvent*event){
if(this->activeLayer < 0){
return;
}
if(this->activeLayer < 0) {
return;
}
if(Tool == nullptr)
return;
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
@@ -278,9 +261,9 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){
// we call the drawline function which draws a line
// from the last position to the current
void PaintingArea::mouseMoveEvent(QMouseEvent*event){
if(this->activeLayer < 0){
return;
}
if(this->activeLayer < 0) {
return;
}
if(Tool == nullptr)
return;
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
@@ -291,9 +274,9 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){
// If the button is released we set variables to stop drawing
void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
if(this->activeLayer < 0)
return;
if(Tool == nullptr)
if(this->activeLayer < 0)
return;
if(Tool == nullptr)
return;
int x = event->x()-layerBundle[static_cast<unsigned long long>(activeLayer)].widthOffset;
int y = event->y()-layerBundle[static_cast<unsigned long long>(activeLayer)].heightOffset;
@@ -306,9 +289,9 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
}
void PaintingArea::wheelEvent(QWheelEvent*event){
if(this->activeLayer < 0)
return;
if(this->Tool != nullptr) {
if(this->activeLayer < 0)
return;
if(this->Tool != nullptr) {
QPoint numDegrees = event->angleDelta() / 8;
if(!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15;
@@ -329,7 +312,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){
update();
}
// Resize the image to slightly larger then the main window
//TODOJ Resize the image to slightly larger then the main window
// to cut down on the need to resize the image
void PaintingArea::resizeEvent(QResizeEvent*event){
//TODO wait till tool works
@@ -341,6 +324,7 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
}
void PaintingArea::selectLayerUp(){
updateTools();
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]);
activeLayer++;
@@ -348,6 +332,7 @@ void PaintingArea::selectLayerUp(){
}
void PaintingArea::selectLayerDown(){
updateTools();
if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
activeLayer--;
@@ -399,9 +384,9 @@ bool PaintingArea::createTempTopLayer(int idx){
newLayer.widthOffset = layerBundle[static_cast<unsigned long long>(idx)].widthOffset;
newLayer.image = layerBundle[static_cast<unsigned long long>(idx)].image->getDeepCopy();
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
return true;
return true;
}
return false;
return false;
}
IntelliTool* PaintingArea::copyActiveTool(){
@@ -422,8 +407,38 @@ int PaintingArea::getNumberOfActiveLayer(){
}
IntelliImage* PaintingArea::getImageOfActiveLayer(){
if(activeLayer<0){
return nullptr;
}
return layerBundle[activeLayer].image;
if(activeLayer<0) {
return nullptr;
}
return layerBundle[static_cast<size_t>(activeLayer)].image;
}
QImage PaintingArea::getImageDataOfActiveLayer(){
QImage returnImage;
if(activeLayer<0) {
returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
returnImage.fill(QColor(255,255,255,255));
}
else{
returnImage = layerBundle[static_cast<size_t>(activeLayer)].image->getImageData();
if(renderSettings.isFastRenderering()) {
returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
}
}
return returnImage;
}
void PaintingArea::updateTools(){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
if(isSettingPolygon) {
delete this->Tool;
this->Tool = nullptr;
isSettingPolygon = false;
}
}
}

View File

@@ -39,7 +39,7 @@ struct LayerObject {
*/
class PaintingArea : public QWidget
{
friend UnitTest;
friend UnitTest;
// Declares our class as a QObject which is the base class
// for all Qt objects
// QObjects handle events
@@ -47,142 +47,146 @@ 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 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 This deconstructor is used to clear up the memory and remove the currently active window
*/
~PaintingArea() override;
// Handles all events
// Handles all events
/*!
* \brief setRenderSettings updates all Images to the new Rendersetting.
* \param isFastRenderingOn is the new given flag for the FastRenderer.
*/
void setRenderSettings(bool isFastRenderingOn);
/*!
* \brief setRenderSettings updates all Images to the new Rendersetting.
* \param isFastRenderingOn is the new given flag for the FastRenderer.
*/
void setRenderSettings(bool isFastRenderingOn);
/*!
* \brief The open method is used for loading a picture into the current layer
* \param fileName - Path and filename 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 fileName
* \param fileFormat
* \return Returns a boolean variable, true if the file was saved successfully, false if not
*/
bool save(const QString &filePath, const char *fileFormat);
/*!
* \brief The open method is used for loading a picture into the current layer
* \param fileName - Path and filename 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 fileName
* \param fileFormat
* \return Returns a boolean variable, true if the file was saved successfully, false if not
*/
bool save(const QString &filePath, const char*fileFormat);
/*!
* \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 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);
/*!
* \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, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
/*!
* \brief The deleteLayer method removes a layer at a given idx
* \param idx - The index of the layer to be removed
*/
void deleteLayer(int idx);
/*!
* \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 The floodFill method fills a the active layer with a given color
* \param r - Red value of the color the layer should be filled with
* \param g - Green value of the color the layer should be filled with
* \param b - Blue value of the color the layer should be filled with
* \param a - Alpha value of the color the layer should be filled with
*/
void floodFill(int r, int g, int b, int a);
/*!
* \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 direction the layer should move
*/
void moveActiveLayer(int idx);
/*!
* \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 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);
/*!
* \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, IntelliImage::ImageType type = IntelliImage::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);
//change properties of colorPicker
/*!
* \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();
//change properties of colorPicker
/*!
* \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();
// Create tools
void createPenTool();
void createPlainTool();
void createLineTool();
void createRectangleTool();
void createCircleTool();
void createPolygonTool();
void createFloodFillTool();
// Create tools
void createPenTool();
void createPlainTool();
void createLineTool();
void createRectangleTool();
void createCircleTool();
void createPolygonTool();
void createFloodFillTool();
/*!
* \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 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();
IntelliImage::ImageType getTypeOfImageRealLayer();
IntelliImage::ImageType getTypeOfImageRealLayer();
std::vector<QPoint> getPolygonDataOfRealLayer();
std::vector<QPoint> getPolygonDataOfRealLayer();
int getNumberOfActiveLayer();
int getNumberOfActiveLayer();
IntelliImage* getImageOfActiveLayer();
IntelliImage* getImageOfActiveLayer();
IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker;
/*!
* \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();
IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker;
public slots:
// Events to handle
@@ -219,6 +223,8 @@ QImage* Canvas;
int maxWidth;
int maxHeight;
bool isSettingPolygon = false;
IntelliRenderSettings renderSettings;
IntelliTool* Tool;
IntelliPhotoGui* DummyGui;
@@ -230,8 +236,11 @@ void drawLayers(bool forSaving=false);
void resizeLayer(QImage*image_res, const QSize &newSize);
// Helper for Tool
bool createTempTopLayer(int idx);
// Helper for Tool
bool createTempTopLayer(int idx);
//this function is needed to avoid errors in inputhandeling if a layer has changed
void updateTools();
};
#endif