diff --git a/IntelliPhoto/Painting/GUI/IntelliPhotoGui.cpp b/IntelliPhoto/Painting/GUI/IntelliPhotoGui.cpp index 5518272..4b65d13 100644 --- a/IntelliPhoto/Painting/GUI/IntelliPhotoGui.cpp +++ b/IntelliPhoto/Painting/GUI/IntelliPhotoGui.cpp @@ -1,6 +1,7 @@ // ---------- IntelliPhotoGui.cpp ---------- #include +#include #include "IntelliPhotoGui.h" #include "Layer/PaintingArea.h" @@ -110,11 +111,85 @@ void IntelliPhotoGui::about() tr("

IntelliPhoto Some nice ass looking software

")); } +void IntelliPhotoGui::onSetAlpha(){ + int a = this->setAlphaEdit->text().toInt(); + emit this->sendAlpha(a); +} + +void IntelliPhotoGui::onMoveUp(){ + int a = 5; + emit this->moveUp(a); +} + +void IntelliPhotoGui::onMoveDown(){ + int a = 5; + emit this->moveDown(a); +} + +void IntelliPhotoGui::onMoveLeft(){ + int a = 5; + emit this->moveLeft(a); +} + +void IntelliPhotoGui::onMoveRight(){ + int a = 5; + emit this->moveRight(a); +} + +void IntelliPhotoGui::onMoveLayerUp(){ + emit this->moveLayerUp(); +} + +void IntelliPhotoGui::onMoveLayerDown(){ + emit this->moveLayerDown(); +} + +void IntelliPhotoGui::onClearedPressed(){ + int r = this->RedEdit->text().toInt(); + int g = this->GreenEdit->text().toInt(); + int b = this->BlueEdit->text().toInt(); + emit this->sendClearColor(r,g,b); +} + +void IntelliPhotoGui::onActivePressed(){ + int a = this->selectActiveEdit->text().toInt(); + emit this->sendActiveLayer(a); +}; + + + // Define menu actions that call functions void IntelliPhotoGui::createActions() { //connect signal and slots of gui element - connect(this->clearButton, SIGNAL(clicked()), paintingArea, SLOT(clearImage())); + connect(this->clearButton, SIGNAL(clicked()), this, SLOT(onClearedPressed())); + connect(this, SIGNAL(sendClearColor(int,int,int)), paintingArea, SLOT(clearImage(int, int, int))); + + connect(this->selectActiveButton, SIGNAL(clicked()), this, SLOT(onActivePressed())); + connect(this, SIGNAL(sendActiveLayer(int)),paintingArea, SLOT(activate(int))); + + connect(this->setAlphaButton, SIGNAL(clicked()), this, SLOT(onSetAlpha())); + connect(this, SIGNAL(sendAlpha(int)), paintingArea, SLOT(setAlpha(int))); + + connect(this->moveActiveUpButton, SIGNAL(clicked()), this, SLOT(onMoveUp())); + connect(this, SIGNAL(moveUp(int)), paintingArea, SLOT(getMoveUp(int))); + + connect(this->moveActiveDownButton, SIGNAL(clicked()), this, SLOT(onMoveDown())); + connect(this, SIGNAL(moveDown(int)), paintingArea, SLOT(getMoveDown(int))); + + connect(this->moveActiveLeftButton, SIGNAL(clicked()), this, SLOT(onMoveLeft())); + connect(this, SIGNAL(moveLeft(int)), paintingArea, SLOT(getMoveLeft(int))); + + connect(this->moveActiveRightButton, SIGNAL(clicked()), this, SLOT(onMoveRight())); + connect(this, SIGNAL(moveRight(int)), paintingArea, SLOT(getMoveRight(int))); + + connect(this->layerMoveActiveDownButton, SIGNAL(clicked()), this, SLOT(onMoveLayerDown())); + connect(this, SIGNAL(moveLayerDown()), paintingArea, SLOT(getMoveLayerDown())); + + connect(this->layerMoveActiveUpButton, SIGNAL(clicked()), this, SLOT(onMoveLayerUp())); + connect(this, SIGNAL(moveLayerUp()), paintingArea, SLOT(getMoveLayerUp())); + + // Create the action tied to the menu openAct = new QAction(tr("&Open..."), this); @@ -228,12 +303,67 @@ void IntelliPhotoGui::createGui(){ centralGuiWidget->setLayout(mainLayout); //create Gui elements - clearButton = new QPushButton("Clear"); + clearButton = new QPushButton("set Color"); paintingArea = new PaintingArea(); + + RedLabel = new QLabel("Red:"); + GreenLabel = new QLabel("Green"); + BlueLabel = new QLabel("Blue:"); + RedEdit = new QLineEdit("255"); + GreenEdit = new QLineEdit("255"); + BlueEdit = new QLineEdit("255");; + RedEdit->setMaximumSize(150,20); + GreenEdit->setMaximumSize(150,20); + BlueEdit->setMaximumSize(150,20); + + selectActiveButton = new QPushButton("select Active"); + selectActiveLabel = new QLabel("Active:"); + selectActiveEdit = new QLineEdit("0"); + selectActiveLabel->setMaximumSize(150,20); + selectActiveEdit->setMaximumSize(150,20); + + setAlphaButton = new QPushButton("set Alpha"); + setAlphaLabel = new QLabel("Alpha:"); + setAlphaEdit = new QLineEdit("255"); + setAlphaEdit->setMaximumSize(150,20); + + moveActiveUpButton = new QPushButton("move 5 Up"); + moveActiveDownButton = new QPushButton("move 5 Down"); + moveActiveLeftButton = new QPushButton("move 5 Left"); + moveActiveRightButton = new QPushButton("move 5 Right"); + + layerMoveActiveDownButton = new QPushButton("Active Layer Down"); + layerMoveActiveUpButton = new QPushButton("Active Layer Up"); + //set gui elemtns position - mainLayout->addWidget(paintingArea,0,0,10,10); - mainLayout->addWidget(clearButton,0,10,1,1); + mainLayout->addWidget(clearButton,0,25,1,1); + mainLayout->addWidget(paintingArea,0,0,25,25); + + mainLayout->addWidget(RedLabel,1,25,1,1); + mainLayout->addWidget(RedEdit,2,25,1,1); + mainLayout->addWidget(GreenLabel,3,25,1,1); + mainLayout->addWidget(GreenEdit,4,25,1,1); + mainLayout->addWidget(BlueLabel,5,25,1,1); + mainLayout->addWidget(BlueEdit,6,25,1,1); + + mainLayout->addWidget(selectActiveButton,7,25,1,1); + mainLayout->addWidget(selectActiveLabel,8,25,1,1); + mainLayout->addWidget(selectActiveEdit,9,25,1,1); + + mainLayout->addWidget(setAlphaButton,10,25,1,1); + mainLayout->addWidget(setAlphaLabel,11,25,1,1); + mainLayout->addWidget(setAlphaEdit,12,25,1,1); + + mainLayout->addWidget(moveActiveUpButton,13,25,1,1); + mainLayout->addWidget(moveActiveDownButton,14,25,1,1); + mainLayout->addWidget(moveActiveLeftButton,15,25,1,1); + mainLayout->addWidget(moveActiveRightButton,16,25,1,1); + + mainLayout->addWidget(layerMoveActiveDownButton,17,25,1,1); + mainLayout->addWidget(layerMoveActiveUpButton,18,25,1,1); + + } void IntelliPhotoGui::setIntelliStyle(){ diff --git a/IntelliPhoto/Painting/GUI/IntelliPhotoGui.h b/IntelliPhoto/Painting/GUI/IntelliPhotoGui.h index 7e77cef..79f2cf9 100644 --- a/IntelliPhoto/Painting/GUI/IntelliPhotoGui.h +++ b/IntelliPhoto/Painting/GUI/IntelliPhotoGui.h @@ -3,8 +3,11 @@ #include #include -#include -#include +#include +#include +#include +#include +#include // PaintingArea used to paint the image class PaintingArea; @@ -15,6 +18,16 @@ class IntelliPhotoGui : public QMainWindow // for all Qt objects // QObjects handle events Q_OBJECT +signals: + void sendClearColor(int r, int g, int b); + void sendActiveLayer(int a); + void sendAlpha(int a); + void moveUp(int a); + void moveDown(int a); + void moveRight(int a); + void moveLeft(int a); + void moveLayerUp(); + void moveLayerDown(); public: IntelliPhotoGui(); @@ -30,6 +43,16 @@ private slots: void penWidth(); void about(); + void onClearedPressed(); + void onActivePressed(); + void onSetAlpha(); + void onMoveUp(); + void onMoveDown(); + void onMoveLeft(); + void onMoveRight(); + void onMoveLayerUp(); + void onMoveLayerDown(); + private: // Will tie user actions to functions void createActions(); @@ -56,6 +79,7 @@ private: QMenu *optionMenu; QMenu *helpMenu; + // All the actions that can occur QAction *openAct; @@ -72,6 +96,30 @@ private: QWidget* centralGuiWidget; QGridLayout *mainLayout; QPushButton *clearButton; + + QLabel *RedLabel; + QLabel *GreenLabel; + QLabel *BlueLabel; + QLineEdit *RedEdit; + QLineEdit *GreenEdit; + QLineEdit *BlueEdit; + + QPushButton *selectActiveButton; + QLabel *selectActiveLabel; + QLineEdit *selectActiveEdit; + + QPushButton *setAlphaButton; + QLabel *setAlphaLabel; + QLineEdit *setAlphaEdit; + + QPushButton *moveActiveUpButton; + QPushButton *moveActiveDownButton; + QPushButton *moveActiveLeftButton; + QPushButton *moveActiveRightButton; + + QPushButton *layerMoveActiveDownButton; + QPushButton *layerMoveActiveUpButton; + }; #endif diff --git a/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp b/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp index 9b9abb1..5b32037 100644 --- a/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp +++ b/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp @@ -16,7 +16,18 @@ QImage IntelliShapedImage::getDisplayable(){ return getDisplayable(imageData.size()); } -QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){ +QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ + if(polygonData.size()==0){ + QImage copy = imageData; + for(int y = 0; y& polygonData){ + if(polygonData.size()<3){ + return; + } for(auto element:polygonData){ this->polygonData.push_back(QPoint(element.x(), element.y())); } diff --git a/IntelliPhoto/Painting/IntelliPhoto.pro.user b/IntelliPhoto/Painting/IntelliPhoto.pro.user index 87f6eae..1486bb9 100644 --- a/IntelliPhoto/Painting/IntelliPhoto.pro.user +++ b/IntelliPhoto/Painting/IntelliPhoto.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {d22feba4-9460-41e9-9ac3-cddcd407714c} + {426164d9-3771-4235-8f83-cb0b49423ffc} ProjectExplorer.Project.ActiveTarget @@ -59,19 +59,24 @@ -fno-delayed-template-parsing true + true + + + + true ProjectExplorer.Project.Target.0 - Desktop (x86-windows-msvc2017-pe-64bit) - Desktop (x86-windows-msvc2017-pe-64bit) - {39c3549a-728d-484f-a9ec-e2904e3853e7} - 0 + Desktop Qt 5.12.5 MinGW 64-bit + Desktop Qt 5.12.5 MinGW 64-bit + qt.qt5.5125.win64_mingw73_kit + 1 0 0 - Z:/Uni/ws 19_20/softwaretechnologie/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_x86_windows_msvc2017_pe_64bit-Debug + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug true @@ -127,7 +132,7 @@ true - Z:/Uni/ws 19_20/softwaretechnologie/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_x86_windows_msvc2017_pe_64bit-Release + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release true @@ -183,7 +188,7 @@ true - Z:/Uni/ws 19_20/softwaretechnologie/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_x86_windows_msvc2017_pe_64bit-Profile + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Profile true @@ -307,7 +312,7 @@ IntelliPhoto - Qt4ProjectManager.Qt4RunConfiguration:Z:/Uni/ws 19_20/softwaretechnologie/intelliphoto/IntelliPhoto/Painting/IntelliPhoto.pro + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/Painting/IntelliPhoto.pro 3768 false @@ -317,7 +322,7 @@ false true - Z:/Uni/ws 19_20/softwaretechnologie/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_x86_windows_msvc2017_pe_64bit-Debug + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release 1 diff --git a/IntelliPhoto/Painting/IntelliPhoto.pro.user.87de10b b/IntelliPhoto/Painting/IntelliPhoto.pro.user.87de10b new file mode 100644 index 0000000..fe52988 --- /dev/null +++ b/IntelliPhoto/Painting/IntelliPhoto.pro.user.87de10b @@ -0,0 +1,337 @@ + + + + + + EnvironmentId + {87de10b7-9dd6-4379-8674-fd04613e186e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.5 MinGW 64-bit + Desktop Qt 5.12.5 MinGW 64-bit + qt.qt5.5125.win64_mingw73_kit + 0 + 0 + 0 + + C:/Users/Jonas/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Erstellen + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Bereinigen + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Jonas/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Erstellen + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Bereinigen + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Jonas/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Erstellen + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Bereinigen + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deployment + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deployment-Konfiguration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + IntelliPhoto + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Jonas/Documents/GitHub/intelliphoto/IntelliPhoto/Painting/IntelliPhoto.pro + + 3768 + false + true + true + false + false + true + + C:/Users/Jonas/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/IntelliPhoto/Painting/Layer/PaintingArea.cpp b/IntelliPhoto/Painting/Layer/PaintingArea.cpp index 4404a0f..cf0ef5e 100644 --- a/IntelliPhoto/Painting/Layer/PaintingArea.cpp +++ b/IntelliPhoto/Painting/Layer/PaintingArea.cpp @@ -21,7 +21,20 @@ PaintingArea::PaintingArea(QWidget *parent) poly.push_back(QPoint(200,0)); image->setPolygon(poly); - this->setUp(); + //tetsing + this->addLayer(200,200,0,0,ImageType::Shaped_Image); + layerStructure[0].image->floodFill(QColor(255,0,0,255)); + std::vector polygon; + polygon.push_back(QPoint(100,0)); + polygon.push_back(QPoint(200,200)); + polygon.push_back(QPoint(0,200)); + polygon.push_back(QPoint(100,0)); + layerStructure[0].image->setPolygon(polygon); + + this->addLayer(200,200,150,150); + layerStructure[1].image->floodFill(QColor(0,255,0,255)); + layerStructure[1].alpha=200; + activeLayer=1; } void PaintingArea::setUp(){ @@ -40,15 +53,29 @@ PaintingArea::PaintingArea(int width, int height, ImageType type, QWidget *paren if(type==ImageType::Raster_Image){ this->image = new IntelliRasterImage(width, height); }else if(type==ImageType::Shaped_Image){ - this->image = new IntelliShapedImage(width, height); - }else{ - qDebug() << "No valid Image type error"; - return; + newLayer.image = new IntelliShapedImage(width, height); + } + newLayer.alpha = 255; + this->layerStructure.push_back(newLayer); + +} + +void PaintingArea::deleteLayer(int index){ + if(indexlayerStructure.erase(layerStructure.begin()+index); + if(activeLayer>=index){ + activeLayer--; + } } this->setUp(); } +QPixmap PaintingArea::getAsPixmap(){ + assembleLayers(); + return QPixmap::fromImage(*Canvas); +} + // Used to load the image and place it in the widget bool PaintingArea::openImage(const QString &fileName) { @@ -60,15 +87,12 @@ bool PaintingArea::openImage(const QString &fileName) // Save the current image bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) { - // Created to hold the image - QImage visibleImage = image->getDisplayable(); - - if(!std::strcmp(fileFormat,"PNG")){ - visibleImage = visibleImage.convertToFormat(QImage::Format_Indexed8); - fileFormat = "png"; + if(layerStructure.size()==0){ + return false; } + this->assembleLayers(true); - if (visibleImage.save(fileName, fileFormat)) { + if (Canvas->save(fileName, fileFormat)) { return true; } else { return false; @@ -88,20 +112,70 @@ void PaintingArea::setPenWidth(int newWidth) } // Color the image area with white -void PaintingArea::clearImage() -{ - image->floodFill(qRgb(255, 255, 255)); +void PaintingArea::clearImage(int r, int g, int b){ + if(this->activeLayer==-1){ + return; + } + IntelliImage* active = layerStructure[activeLayer].image; + active->floodFill(QColor(r, g, b, 255)); + update(); } +void PaintingArea::activate(int a){ + this->setLayerToActive(a); +} + +void PaintingArea::setAlpha(int a){ + if(activeLayer>=0){ + layerStructure[activeLayer].alpha=a; + } +} + +void PaintingArea::getMoveUp(int a){ + layerStructure[activeLayer].heightOffset-=a; +} + +void PaintingArea::getMoveDown(int a){ + layerStructure[activeLayer].heightOffset+=a; +} + +void PaintingArea::getMoveRight(int a){ + layerStructure[activeLayer].widthOffset+=a; +} + +void PaintingArea::getMoveLeft(int a){ + layerStructure[activeLayer].widthOffset-=a; +} + +void PaintingArea::getMoveLayerUp(){ + if(activeLayer=0){ + std::swap(layerStructure[activeLayer], layerStructure[activeLayer+1]); + activeLayer++; + } +} + +void PaintingArea::getMoveLayerDown(){ + if(activeLayer>0){ + std::swap(layerStructure[activeLayer], layerStructure[activeLayer-1]); + activeLayer--; + } +} + // If a mouse button is pressed check if it was the // left button and if so store the current position // Set that we are currently drawing void PaintingArea::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { - int x = event->x()*(float)image->x()/(float)size().width(); - int y = event->y()*(float)image->y()/(float)size().height(); + if(this->activeLayer==-1){ + return; + } + LayerObject& active = layerStructure[activeLayer]; + + int x = event->x()-active.widthOffset; + int y = event->y()-active.heightOffset; + //TODO CALCULATE LAST POINT lastPoint=QPoint(x,y); scribbling = true; } @@ -114,8 +188,15 @@ void PaintingArea::mousePressEvent(QMouseEvent *event) void PaintingArea::mouseMoveEvent(QMouseEvent *event) { if ((event->buttons() & Qt::LeftButton) && scribbling){ - int x = event->x()*(float)image->x()/(float)size().width(); - int y = event->y()*(float)image->y()/(float)size().height(); + if(this->activeLayer==-1){ + return; + } + LayerObject& active = layerStructure[activeLayer]; + + int x = event->x()-active.widthOffset; + int y = event->y()-active.heightOffset; + + //TODO CALCULATE NEW POINT drawLineTo(QPoint(x,y)); update(); } @@ -125,8 +206,15 @@ void PaintingArea::mouseMoveEvent(QMouseEvent *event) void PaintingArea::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton && scribbling) { - int x = event->x()*(float)image->x()/(float)size().width(); - int y = event->y()*(float)image->y()/(float)size().height(); + if(this->activeLayer==-1){ + return; + } + LayerObject& active = layerStructure[activeLayer]; + + int x = event->x()-active.widthOffset; + int y = event->y()-active.heightOffset; + + //TODO CALCULATE NEW POINT drawLineTo(QPoint(x,y)); update(); scribbling = false; @@ -138,9 +226,11 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event) // update themselves void PaintingArea::paintEvent(QPaintEvent *event) { + this->assembleLayers(); + QPainter painter(this); QRect dirtyRec = event->rect(); - painter.drawImage(dirtyRec, image->getDisplayable(dirtyRec.size()), dirtyRec); + painter.drawImage(dirtyRec, *Canvas, dirtyRec); update(); } @@ -167,3 +257,35 @@ void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){ image_res->scaled(newSize,Qt::IgnoreAspectRatio); } +void PaintingArea::assembleLayers(bool forSaving){ + if(forSaving){ + Canvas->fill(Qt::GlobalColor::transparent); + }else{ + Canvas->fill(Qt::GlobalColor::black); + } + //TODO interpolation of alpha for saving + for(size_t i=0; igetDisplayable(layer.alpha); + QColor clr_0; + QColor clr_1; + for(int y=0; ypixelColor(layer.widthOffset+x, layer.heightOffset+y); + clr_1=cpy.pixelColor(x,y); + float t = (float)clr_1.alpha()/255.f; + int r =(float)clr_1.red()*(t)+(float)clr_0.red()*(1.-t); + int g =(float)clr_1.green()*(t)+(float)clr_0.green()*(1.-t); + int b =(float)clr_1.blue()*(t)+(float)clr_0.blue()*(1.-t); + int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); + clr_0.setRed(r); + clr_0.setGreen(g); + clr_0.setBlue(b); + clr_0.setAlpha(a); + + Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0); + } + } + } +} + diff --git a/IntelliPhoto/Painting/Layer/PaintingArea.h b/IntelliPhoto/Painting/Layer/PaintingArea.h index c3e1ea9..62fd3cd 100644 --- a/IntelliPhoto/Painting/Layer/PaintingArea.h +++ b/IntelliPhoto/Painting/Layer/PaintingArea.h @@ -31,11 +31,21 @@ public: QColor penColor() const { return myPenColor; } int penWidth() const { return myPenWidth; } + + QPixmap getAsPixmap(); public slots: // Events to handle - void clearImage(); + void clearImage(int r, int g, int b); + void activate(int a); + void setAlpha(int a); + void getMoveUp(int a); + void getMoveDown(int a); + void getMoveRight(int a); + void getMoveLeft(int a); + void getMoveLayerUp(); + void getMoveLayerDown(); //void setUp helper for konstruktor void setUp(); protected: @@ -51,6 +61,24 @@ protected: void resizeEvent(QResizeEvent *event) override; private: + struct LayerObject{ + IntelliImage* image; + int width; + int height; + int widthOffset; + int heightOffset; + int alpha=255; + }; + + QImage* Canvas; + int maxWidth; + int maxHeight; + + std::vector layerStructure; + int activeLayer=-1; + + void assembleLayers(bool forSaving=false); + void drawLineTo(const QPoint &endPoint); void resizeImage(QImage *image_res, const QSize &newSize);