diff --git a/src/Painting/GUI/IntelliPhotoGui.cpp b/src/Painting/GUI/IntelliPhotoGui.cpp index d51a8bb..ca123d4 100644 --- a/src/Painting/GUI/IntelliPhotoGui.cpp +++ b/src/Painting/GUI/IntelliPhotoGui.cpp @@ -111,6 +111,17 @@ void IntelliPhotoGui::slotDeleteLayer() paintingArea->deleteLayer(layerNumber); } +void IntelliPhotoGui::slotGetColorbar(){ + + bool ok1; + + int firstOrSecondColor = QInputDialog::getInt(this, tr("Which Color"), + tr("Number:"), + 1,1, 2, 1, &ok1); + + Tool = paintingArea->getTool(); + Tool->getColorbar(firstOrSecondColor); +} void IntelliPhotoGui::slotSetActiveAlpha(){ // Stores button value @@ -269,6 +280,9 @@ void IntelliPhotoGui::createActions() actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer())); + actionGetColorbar = new QAction(tr("&Set Color"),this); + connect(actionGetColorbar, SIGNAL(triggered()), this, SLOT(slotGetColorbar())); + actionFloodFill = new QAction(tr("&clear Image"), this); connect(actionFloodFill, SIGNAL(triggered()), this, SLOT(slotClearActiveLayer())); @@ -346,6 +360,7 @@ void IntelliPhotoGui::createMenus() //Attach all Tool Options toolMenu = new QMenu(tr("&Tools"), this); + toolMenu->addAction(actionGetColorbar); // Attach all actions to Help helpMenu = new QMenu(tr("&Help"), this); diff --git a/src/Painting/GUI/IntelliPhotoGui.h b/src/Painting/GUI/IntelliPhotoGui.h index 9a8241c..10b0e1d 100644 --- a/src/Painting/GUI/IntelliPhotoGui.h +++ b/src/Painting/GUI/IntelliPhotoGui.h @@ -12,6 +12,8 @@ // PaintingArea used to paint the image class PaintingArea; +class IntelliTool; + class IntelliPhotoGui : public QMainWindow { // Declares our class as a QObject which is the base class @@ -31,6 +33,9 @@ private slots: void slotSave(); void slotCreateNewLayer(); void slotDeleteLayer(); + + void slotGetColorbar(); + void slotAboutDialog(); void slotClearActiveLayer(); @@ -60,6 +65,7 @@ private: // What we'll draw on PaintingArea* paintingArea; + IntelliTool* Tool; // The menu widgets QMenu *saveAsMenu; @@ -76,6 +82,8 @@ private: QAction *actionCreateNewLayer; QAction *actionDeleteLayer; + QAction *actionGetColorbar; + QAction *actionAboutDialog; QAction *actionAboutQtDialog; diff --git a/src/Painting/IntelliPhoto.pro b/src/Painting/IntelliPhoto.pro index b61b9b8..45e293d 100644 --- a/src/Painting/IntelliPhoto.pro +++ b/src/Painting/IntelliPhoto.pro @@ -23,7 +23,9 @@ SOURCES += \ IntelliHelper/IntelliHelper.cpp \ Layer/PaintingArea.cpp \ Tool/IntelliTool.cpp \ + Tool/IntelliToolFloodFillTool.cpp \ Tool/IntelliToolPen.cpp \ + Tool/IntelliToolSetColorTool.cpp \ main.cpp HEADERS += \ @@ -34,7 +36,9 @@ HEADERS += \ IntelliHelper/IntelliHelper.h \ Layer/PaintingArea.h \ Tool/IntelliTool.h \ - Tool/IntelliToolPen.h + Tool/IntelliToolFloodFillTool.h \ + Tool/IntelliToolPen.h \ + Tool/IntelliToolSetColorTool.h FORMS += \ widget.ui diff --git a/src/Painting/Layer/PaintingArea.cpp b/src/Painting/Layer/PaintingArea.cpp index 6177989..7186907 100644 --- a/src/Painting/Layer/PaintingArea.cpp +++ b/src/Painting/Layer/PaintingArea.cpp @@ -11,11 +11,14 @@ #include "Image/IntelliRasterImage.h" #include "Image/IntelliShapedImage.h" #include "Tool/IntelliToolPen.h" +#include "Tool/IntelliToolSetColorTool.h" +#include "Tool/IntelliToolFloodFillTool.h" PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ - this->Tool = new IntelliToolPen(this); + this->Tool = new IntelliToolFloodFillTool(this); + this->ColorTool = new IntelliToolSetColorTool(this); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); @@ -34,6 +37,10 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) activeLayer=1; } +IntelliToolSetColorTool* PaintingArea::getTool(){ + return ColorTool; +} + void PaintingArea::setUp(int maxWidth, int maxHeight){ //set standart parameter this->maxWidth = maxWidth; diff --git a/src/Painting/Layer/PaintingArea.h b/src/Painting/Layer/PaintingArea.h index 7623551..abdc990 100644 --- a/src/Painting/Layer/PaintingArea.h +++ b/src/Painting/Layer/PaintingArea.h @@ -7,8 +7,9 @@ #include #include #include -#include"Image/IntelliImage.h" -#include"Tool/IntelliTool.h" +#include "Image/IntelliImage.h" +#include "Tool/IntelliTool.h" +#include "Tool/IntelliToolSetColorTool.h" struct LayerObject{ @@ -32,6 +33,8 @@ class PaintingArea : public QWidget public: PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr); + IntelliToolSetColorTool* getTool(); //TODO: rename function, when there are more Tools + // Handles all events bool open(const QString &fileName); bool save(const QString &fileName, const char *fileFormat); @@ -78,6 +81,7 @@ private: int maxHeight; IntelliTool* Tool; + IntelliToolSetColorTool* ColorTool; std::vector layerBundle; int activeLayer=-1; diff --git a/src/Painting/Tool/IntelliTool.cpp b/src/Painting/Tool/IntelliTool.cpp index 404250d..4aa4403 100644 --- a/src/Painting/Tool/IntelliTool.cpp +++ b/src/Painting/Tool/IntelliTool.cpp @@ -10,6 +10,9 @@ IntelliTool::~IntelliTool(){ } +void IntelliTool::getColorbar(int firstOrSecondColor){ + //optional for tool +} void IntelliTool::onMouseRightPressed(int x, int y){ if(drawing){ diff --git a/src/Painting/Tool/IntelliTool.h b/src/Painting/Tool/IntelliTool.h index 7c17366..75343ce 100644 --- a/src/Painting/Tool/IntelliTool.h +++ b/src/Painting/Tool/IntelliTool.h @@ -1,7 +1,7 @@ #ifndef Intelli_Tool_H #define Intelli_Tool_H -#include +#include class LayerObject; class PaintingArea; @@ -16,10 +16,13 @@ protected: LayerObject* Active; LayerObject* Canvas; bool drawing = false; + public: IntelliTool(PaintingArea* Area); virtual ~IntelliTool() = 0; + virtual void getColorbar(int firstOrSecondColor); + virtual void onMouseRightPressed(int x, int y); virtual void onMouseRightReleased(int x, int y); virtual void onMouseLeftPressed(int x, int y); diff --git a/src/Painting/Tool/IntelliToolFloodFillTool.cpp b/src/Painting/Tool/IntelliToolFloodFillTool.cpp new file mode 100644 index 0000000..c7c476e --- /dev/null +++ b/src/Painting/Tool/IntelliToolFloodFillTool.cpp @@ -0,0 +1,41 @@ +#include "IntelliToolFloodFillTool.h" +#include "Layer/PaintingArea.h" + +IntelliToolFloodFillTool::IntelliToolFloodFillTool(PaintingArea* Area) + :IntelliToolSetColorTool(Area) +{ + Tool = Area->getTool(); + isPressed = false; +} + +void IntelliToolFloodFillTool::onMouseLeftPressed(int x, int y){ + if(!isPressed){ + isPressed = true; + IntelliTool::onMouseLeftPressed(x,y); + Tool = Area->getTool(); + this->Canvas->image->floodFill(Tool->getFirstColor()); + } +} + +void IntelliToolFloodFillTool::onMouseRightPressed(int x, int y){ + if(!isPressed){ + isPressed = true; + IntelliTool::onMouseLeftPressed(x,y); + Tool = Area->getTool(); + this->Canvas->image->floodFill(Tool->getSecondColor()); + } +} + +void IntelliToolFloodFillTool::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); + if(isPressed) isPressed = false; +} + +void IntelliToolFloodFillTool::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); + if(isPressed) isPressed = false; +} + +void IntelliToolFloodFillTool::onMouseMoved(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} diff --git a/src/Painting/Tool/IntelliToolFloodFillTool.h b/src/Painting/Tool/IntelliToolFloodFillTool.h new file mode 100644 index 0000000..30b1e95 --- /dev/null +++ b/src/Painting/Tool/IntelliToolFloodFillTool.h @@ -0,0 +1,22 @@ +#ifndef INTELLITOOLFLOODFILLTOOL_H +#define INTELLITOOLFLOODFILLTOOL_H + +#include "IntelliToolSetColorTool.h" + +class IntelliToolFloodFillTool : public IntelliToolSetColorTool +{ +public: + IntelliToolFloodFillTool(PaintingArea *Area); + + void IntelliToolFloodFillTool::onMouseLeftPressed(int x, int y) override; + void IntelliToolFloodFillTool::onMouseLeftReleased(int x, int y) override; + void IntelliToolFloodFillTool::onMouseRightPressed(int x, int y) override; + void IntelliToolFloodFillTool::onMouseRightReleased(int x, int y) override; + void IntelliToolFloodFillTool::onMouseMoved(int x, int y) override; + +private: + IntelliToolSetColorTool* Tool; + bool isPressed; +}; + +#endif // INTELLITOOLFLOODFILLTOOL_H diff --git a/src/Painting/Tool/IntelliToolPen.cpp b/src/Painting/Tool/IntelliToolPen.cpp index 36ae08d..a858908 100644 --- a/src/Painting/Tool/IntelliToolPen.cpp +++ b/src/Painting/Tool/IntelliToolPen.cpp @@ -1,9 +1,9 @@ -#include"IntelliToolPen.h" -#include"Layer/PaintingArea.h" -#include"QDebug" +#include "IntelliToolPen.h" +#include "Layer/PaintingArea.h" +#include "QDebug" IntelliToolPen::IntelliToolPen(PaintingArea* Area) - :IntelliTool(Area){ + :IntelliToolSetColorTool(Area){ } @@ -35,7 +35,9 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){ void IntelliToolPen::onMouseMoved(int x, int y){ if(this->drawing){ QPoint newPoint(x,y); - this->Canvas->image->drawLine(this->point, newPoint, QColor(255,0,0,255), 2); + Tool = Area->getTool(); + qDebug() << Tool->getFirstColor(); + this->Canvas->image->drawLine(this->point, newPoint, Tool->getFirstColor(), 2); this->point=newPoint; } } diff --git a/src/Painting/Tool/IntelliToolPen.h b/src/Painting/Tool/IntelliToolPen.h index a08ecc6..a54d80d 100644 --- a/src/Painting/Tool/IntelliToolPen.h +++ b/src/Painting/Tool/IntelliToolPen.h @@ -1,12 +1,11 @@ #ifndef INTELLITOOLPEN_H #define INTELLITOOLPEN_H -#include"IntelliTool.h" +#include"IntelliToolSetColorTool.h" #include"QColor" #include"QPoint" -class IntelliToolPen : public IntelliTool{ - QColor clr; +class IntelliToolPen : public IntelliToolSetColorTool{ QPoint point; public: IntelliToolPen(PaintingArea* Area); @@ -18,6 +17,9 @@ public: virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseMoved(int x, int y) override; + +private: + IntelliToolSetColorTool* Tool; }; #endif // INTELLITOOLPEN_H diff --git a/src/Painting/Tool/IntelliToolSetColorTool.cpp b/src/Painting/Tool/IntelliToolSetColorTool.cpp new file mode 100644 index 0000000..549e0e7 --- /dev/null +++ b/src/Painting/Tool/IntelliToolSetColorTool.cpp @@ -0,0 +1,36 @@ +#include "IntelliToolSetColorTool.h" +#include "QDebug" + +IntelliToolSetColorTool::IntelliToolSetColorTool(PaintingArea* Area) + :IntelliTool(Area){ + firstColor = {255,0,0,255}; + secondColor = {0,0,255,255}; +} + +IntelliToolSetColorTool::~IntelliToolSetColorTool(){ + +} + +void IntelliToolSetColorTool::getColorbar(int firstOrSecondColor = 1){ + QString Titel; + QColor newColor; + if(firstOrSecondColor == 1){ + Titel = "Choose first Color"; + newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel); + this->firstColor = newColor; + qDebug() << "Firstcolor" << this->firstColor; + } + else{ + Titel = "Choose second Color"; + newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel); + this->secondColor = newColor; + } +} + +QColor IntelliToolSetColorTool::getFirstColor(){ + return firstColor; +} + +QColor IntelliToolSetColorTool::getSecondColor(){ + return secondColor; +} diff --git a/src/Painting/Tool/IntelliToolSetColorTool.h b/src/Painting/Tool/IntelliToolSetColorTool.h new file mode 100644 index 0000000..c8c0c1a --- /dev/null +++ b/src/Painting/Tool/IntelliToolSetColorTool.h @@ -0,0 +1,24 @@ +#ifndef INTELLITOOLSETCOLORTOOL_H +#define INTELLITOOLSETCOLORTOOL_H + +#include"IntelliTool.h" +#include"QColor" +#include"QPoint" +#include"QColorDialog" + +class IntelliToolSetColorTool: public IntelliTool{ +public: + IntelliToolSetColorTool(PaintingArea *Area); + virtual ~IntelliToolSetColorTool() override; + + void getColorbar(int firstOrSecondColor) override; + + QColor IntelliToolSetColorTool::getFirstColor(); + QColor IntelliToolSetColorTool::getSecondColor(); + +protected: + QColor firstColor; + QColor secondColor; +}; + +#endif // INTELLITOOLSETCOLORTOOL_H