From 6fdda34d682bd8a9c33bca6721c6d638cb1dd4aa Mon Sep 17 00:00:00 2001 From: AshBastian Date: Thu, 9 Jan 2020 02:43:43 +0100 Subject: [PATCH] Gui Endprodukt --- src/GUI/IntelliPhotoGui.cpp | 45 +++++++++++++++++++++++++------------ src/GUI/IntelliPhotoGui.h | 3 +++ src/Image/IntelliImage.cpp | 4 ++++ src/Image/IntelliImage.h | 2 ++ src/Layer/PaintingArea.cpp | 29 +++++++++++++++--------- src/Layer/PaintingArea.h | 5 +++++ src/Tool/IntelliTool.cpp | 1 + 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index d11563d..6fb1e81 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -81,7 +81,7 @@ void IntelliPhotoGui::slotCreateNewLayer(){ if (ok1&&ok2) { int layer = paintingArea->addLayer(width,height,0,0); - paintingArea->slotActivateLayer(layer); + UpdateGui(); } } @@ -95,12 +95,11 @@ void IntelliPhotoGui::slotDeleteLayer(){ // Define the standard Value, min, max, step and ok button int layerNumber = QInputDialog::getInt(this, tr("delete Layer"), tr("Number:"), - 1,0, 500, 1, &ok); + paintingArea->getNumberOfActiveLayer(),0, 500, 1, &ok); // Create New Layer if (ok){ paintingArea->deleteLayer(layerNumber); - QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer()); - ActiveLayerLine->setText(string); + UpdateGui(); } } @@ -121,6 +120,7 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ if (ok1&&ok2) { paintingArea->setLayerAlpha(layer,alpha); + UpdateGui(); } } @@ -179,6 +179,7 @@ void IntelliPhotoGui::slotClearActiveLayer(){ if (ok1&&ok2&&ok3&&ok4) { paintingArea->floodFill(red, green, blue, alpha); + UpdateGui(); } } @@ -195,29 +196,23 @@ void IntelliPhotoGui::slotSetActiveLayer(){ if (ok1) { paintingArea->setLayerActive(layer); - QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer()); - ActiveLayerLine->setText(string); + UpdateGui(); } } void IntelliPhotoGui::slotSetFirstColor(){ paintingArea->colorPickerSetFirstColor(); - QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); - FirstColorButton->setStyleSheet(string); + UpdateGui(); } void IntelliPhotoGui::slotSetSecondColor(){ paintingArea->colorPickerSetSecondColor(); - QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name()); - SecondColorButton->setStyleSheet(string); + UpdateGui(); } void IntelliPhotoGui::slotSwapColor(){ paintingArea->colorPickerSwapColors(); - QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); - FirstColorButton->setStyleSheet(string); - string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name()); - SecondColorButton->setStyleSheet(string); + UpdateGui(); } void IntelliPhotoGui::slotCreatePenTool(){ @@ -511,6 +506,7 @@ void IntelliPhotoGui::createGui(){ // create Gui elements paintingArea = new PaintingArea(); + paintingArea->DumpyGui = this; p = QPixmap(":/Icons/Buttons/icons/circle-tool.svg"); CircleButton = new QPushButton(); @@ -602,6 +598,13 @@ void IntelliPhotoGui::createGui(){ ActiveLayerLine->setText(string); ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3); + p = p.fromImage(paintingArea->getImageOfActiveLayer()->getImageData()); + + ActiveLayerImageButton = new QPushButton(); + ActiveLayerImageButton->setFixedSize(Buttonsize); + ActiveLayerImageButton->setIcon(p); + ActiveLayerImageButton->setIconSize(Buttonsize); + // set gui elements mainLayout->addWidget(paintingArea,1,1,20,1); @@ -620,6 +623,7 @@ void IntelliPhotoGui::createGui(){ mainLayout->addWidget(SecondColorButton,12,3,1,1); mainLayout->addWidget(SwitchColorButton,13,2,1,2); mainLayout->addWidget(ActiveLayerLine,14,2,1,2); + mainLayout->addWidget(ActiveLayerImageButton,15,2,1,2); } void IntelliPhotoGui::setIntelliStyle(){ @@ -686,3 +690,16 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){ void IntelliPhotoGui::setDefaultToolValue(){ slotEnterPressed(); } + +void IntelliPhotoGui::UpdateGui(){ + QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer()); + ActiveLayerLine->setText(string); + p = p.fromImage(paintingArea->getImageOfActiveLayer()->getImageData()); + ActiveLayerImageButton->setIcon(p); + ActiveLayerImageButton->setIconSize(Buttonsize); + + string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); + FirstColorButton->setStyleSheet(string); + string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name()); + SecondColorButton->setStyleSheet(string); +} diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 4985534..3b478b6 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -32,6 +32,8 @@ public: */ IntelliPhotoGui(); +void UpdateGui(); + protected: // Function used to close an event void closeEvent(QCloseEvent*event) override; @@ -115,6 +117,7 @@ QPushButton* SecondColorButton; QPushButton* SwitchColorButton; QLabel* ActiveLayerLine; +QPushButton* ActiveLayerImageButton; // The menu widgets QMenu*saveAsMenu; diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 0a4b919..48deb91 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -81,3 +81,7 @@ void IntelliImage::drawPlain(const QColor& color){ QColor IntelliImage::getPixelColor(QPoint& point){ return imageData.pixelColor(point); } + +QImage IntelliImage::getImageData(){ + return imageData; +} diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index ee14476..06edc4b 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -141,6 +141,8 @@ virtual bool loadImage(const QString &filePath); * \return The color of the Pixel as QColor. */ virtual QColor getPixelColor(QPoint& point); + +QImage getImageData(); }; #endif diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 9740b9a..0550c0d 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -66,14 +66,15 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff } newLayer.alpha = 255; this->layerBundle.push_back(newLayer); - return static_cast(layerBundle.size())-1; + activeLayer = static_cast(layerBundle.size())-1; + return activeLayer; } void PaintingArea::deleteLayer(int index){ if(index(layerBundle.size())) { this->layerBundle.erase(layerBundle.begin()+index); - if(activeLayer>=index) { + if(activeLayer>=index && activeLayer != 0) { activeLayer--; } } @@ -145,10 +146,12 @@ void PaintingArea::floodFill(int r, int g, int b, int a){ } void PaintingArea::movePositionActive(int x, int y){ - if(Tool->getIsDrawing()){ - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; + if(Tool!=nullptr){ + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } } layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; @@ -168,10 +171,12 @@ void PaintingArea::moveActiveLayer(int idx){ } void PaintingArea::slotActivateLayer(int a){ - if(Tool->getIsDrawing()){ - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; + if(Tool != nullptr){ + if(Tool->getIsDrawing()){ + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } } if(a>=0 && a < static_cast(layerBundle.size())) { this->setLayerActive(a); @@ -395,3 +400,7 @@ IntelliTool* PaintingArea::copyActiveTool(){ int PaintingArea::getNumberOfActiveLayer(){ return activeLayer; } + +IntelliImage* PaintingArea::getImageOfActiveLayer(){ + return layerBundle[activeLayer].image; +} diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index d095bc8..10d9ce2 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -7,6 +7,7 @@ #include #include #include +#include "GUI/IntelliPhotoGui.h" #include "Image/IntelliImage.h" #include "Image/IntelliRasterImage.h" #include "Image/IntelliShapedImage.h" @@ -40,6 +41,7 @@ class PaintingArea : public QWidget // QObjects handle events Q_OBJECT friend IntelliTool; + friend IntelliPhotoGui; public: /*! * \brief PaintingArea is the constructor of the PaintingArea class, which initiates the working environment @@ -167,6 +169,8 @@ public: int getNumberOfActiveLayer(); + IntelliImage* getImageOfActiveLayer(); + IntelliToolsettings Toolsettings; IntelliColorPicker colorPicker; @@ -207,6 +211,7 @@ private: IntelliRenderSettings renderSettings; IntelliTool* Tool; + IntelliPhotoGui* DumpyGui; std::vector layerBundle; int activeLayer=-1; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 8a1cbbb..e75abdb 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -74,6 +74,7 @@ void IntelliTool::mergeToolLayer(){ activeLayer->image->imageData.setPixelColor(x, y, clr_0); } } + Area->DumpyGui->UpdateGui(); } void IntelliTool::deleteToolLayer(){