diff --git a/src/Painting/GUI/IntelliPhotoGui.cpp b/src/Painting/GUI/IntelliPhotoGui.cpp index ca123d4..b624f5a 100644 --- a/src/Painting/GUI/IntelliPhotoGui.cpp +++ b/src/Painting/GUI/IntelliPhotoGui.cpp @@ -119,8 +119,19 @@ void IntelliPhotoGui::slotGetColorbar(){ tr("Number:"), 1,1, 2, 1, &ok1); - Tool = paintingArea->getTool(); - Tool->getColorbar(firstOrSecondColor); + paintingArea->getColorbar(firstOrSecondColor); +} + +void IntelliPhotoGui::slotSwitchColors(){ + paintingArea->switchColors(); +} + +void IntelliPhotoGui::slotCreatePenTool(){ + paintingArea->createPenTool(); +} + +void IntelliPhotoGui::slotCreateFloodFillTool(){ + paintingArea->createFloodFillTool(); } void IntelliPhotoGui::slotSetActiveAlpha(){ @@ -280,9 +291,6 @@ 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())); @@ -316,6 +324,20 @@ void IntelliPhotoGui::createActions() actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down)); connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown())); + //Create Tool actions down here + actionGetColorbar = new QAction(tr("&Set Color"),this); + connect(actionGetColorbar, SIGNAL(triggered()), this, SLOT(slotGetColorbar())); + + actionSwitchColors = new QAction(tr("&Switch Color"),this); + actionSwitchColors->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_C)); + connect(actionSwitchColors, SIGNAL(triggered()),this, SLOT(slotSwitchColors())); + + actionCreateFloodFillTool = new QAction(tr("&Flood Fill"), this); + connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool())); + + actionCreatePenTool = new QAction(tr("&Pen"),this); + connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool())); + // Create about action and tie to IntelliPhotoGui::about() actionAboutDialog = new QAction(tr("&About"), this); connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog())); @@ -361,6 +383,9 @@ void IntelliPhotoGui::createMenus() //Attach all Tool Options toolMenu = new QMenu(tr("&Tools"), this); toolMenu->addAction(actionGetColorbar); + toolMenu->addAction(actionSwitchColors); + toolMenu->addAction(actionCreatePenTool); + toolMenu->addAction(actionCreateFloodFillTool); // 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 10b0e1d..b9c7ffd 100644 --- a/src/Painting/GUI/IntelliPhotoGui.h +++ b/src/Painting/GUI/IntelliPhotoGui.h @@ -14,6 +14,8 @@ class PaintingArea; class IntelliTool; +class IntelliColorPicker; + class IntelliPhotoGui : public QMainWindow { // Declares our class as a QObject which is the base class @@ -35,6 +37,9 @@ private slots: void slotDeleteLayer(); void slotGetColorbar(); + void slotSwitchColors(); + void slotCreatePenTool(); + void slotCreateFloodFillTool(); void slotAboutDialog(); @@ -65,7 +70,6 @@ private: // What we'll draw on PaintingArea* paintingArea; - IntelliTool* Tool; // The menu widgets QMenu *saveAsMenu; @@ -83,6 +87,9 @@ private: QAction *actionDeleteLayer; QAction *actionGetColorbar; + QAction *actionSwitchColors; + QAction *actionCreatePenTool; + QAction *actionCreateFloodFillTool; QAction *actionAboutDialog; QAction *actionAboutQtDialog; diff --git a/src/Painting/IntelliHelper/IntelliColorPicker.cpp b/src/Painting/IntelliHelper/IntelliColorPicker.cpp new file mode 100644 index 0000000..cfd951f --- /dev/null +++ b/src/Painting/IntelliHelper/IntelliColorPicker.cpp @@ -0,0 +1,47 @@ +#include "IntelliColorPicker.h" + +IntelliColorPicker::IntelliColorPicker(PaintingArea* Area){ + firstColor = {255,0,0,255}; + secondColor = {0,0,255,255}; +} + +IntelliColorPicker::~IntelliColorPicker(){ + +} + +void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){ + QString Titel; + QColor newColor; + if(firstOrSecondColor == 1){ + Titel = "Choose first Color"; + newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel); + setFirstColor(newColor); + } + else{ + Titel = "Choose second Color"; + newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel); + setFirstColor(newColor); + } +} + +void IntelliColorPicker::switchColors(){ + QColor temp = this->firstColor; + this->firstColor = this->secondColor; + this->secondColor = temp; +} + +QColor IntelliColorPicker::getFirstColor(){ + return this->firstColor; +} + +QColor IntelliColorPicker::getSecondColor(){ + return this->secondColor; +} + +void IntelliColorPicker::setFirstColor(QColor Color){ + this->firstColor = Color; +} + +void IntelliColorPicker::setSecondColor(QColor Color){ + this->secondColor = Color; +} diff --git a/src/Painting/IntelliHelper/IntelliColorPicker.h b/src/Painting/IntelliHelper/IntelliColorPicker.h new file mode 100644 index 0000000..1eeb28e --- /dev/null +++ b/src/Painting/IntelliHelper/IntelliColorPicker.h @@ -0,0 +1,28 @@ +#ifndef INTELLITOOLSETCOLORTOOL_H +#define INTELLITOOLSETCOLORTOOL_H + +#include"Layer/PaintingArea.h" +#include"QColor" +#include"QPoint" +#include"QColorDialog" + +class IntelliColorPicker{ +public: + IntelliColorPicker(PaintingArea *Area); + virtual ~IntelliColorPicker(); + + void getColorbar(int firstOrSecondColor); + void switchColors(); + + QColor getFirstColor(); + QColor getSecondColor(); + + void setFirstColor(QColor Color); + void setSecondColor(QColor Color); + +private: + QColor firstColor; + QColor secondColor; +}; + +#endif // INTELLITOOLSETCOLORTOOL_H diff --git a/src/Painting/IntelliPhoto.pro b/src/Painting/IntelliPhoto.pro index 9e0d263..5dbb70d 100644 --- a/src/Painting/IntelliPhoto.pro +++ b/src/Painting/IntelliPhoto.pro @@ -20,12 +20,12 @@ SOURCES += \ Image/IntelliImage.cpp \ Image/IntelliRasterImage.cpp \ Image/IntelliShapedImage.cpp \ + IntelliHelper/IntelliColorPicker.cpp \ IntelliHelper/IntelliHelper.cpp \ Layer/PaintingArea.cpp \ Tool/IntelliTool.cpp \ Tool/IntelliToolFloodFillTool.cpp \ Tool/IntelliToolPen.cpp \ - Tool/IntelliToolSetColorTool.cpp \ main.cpp HEADERS += \ @@ -33,12 +33,12 @@ HEADERS += \ Image/IntelliImage.h \ Image/IntelliRasterImage.h \ Image/IntelliShapedImage.h \ + IntelliHelper/IntelliColorPicker.h \ IntelliHelper/IntelliHelper.h \ Layer/PaintingArea.h \ Tool/IntelliTool.h \ Tool/IntelliToolFloodFillTool.h \ - Tool/IntelliToolPen.h \ - Tool/IntelliToolSetColorTool.h + Tool/IntelliToolPen.h FORMS += \ widget.ui diff --git a/src/Painting/Layer/PaintingArea.cpp b/src/Painting/Layer/PaintingArea.cpp index 7186907..1f2cd18 100644 --- a/src/Painting/Layer/PaintingArea.cpp +++ b/src/Painting/Layer/PaintingArea.cpp @@ -8,17 +8,11 @@ #include #include "PaintingArea.h" -#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 IntelliToolFloodFillTool(this); - this->ColorTool = new IntelliToolSetColorTool(this); + this->Tool = new IntelliToolPen(this); + this->ColorTool = new IntelliColorPicker(this); this->setUp(maxWidth, maxHeight); //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); @@ -37,10 +31,30 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) activeLayer=1; } -IntelliToolSetColorTool* PaintingArea::getTool(){ +void PaintingArea::getColorbar(int firstOrSecondColor){ + ColorTool->getColorbar(firstOrSecondColor); +} + +IntelliColorPicker* PaintingArea::getColorTool(){ return ColorTool; } +void PaintingArea::switchColors(){ + ColorTool->switchColors(); +} + +void PaintingArea::createPenTool(){ + IntelliTool *temp = this->Tool; + this->Tool = new IntelliToolPen(this); + delete temp; +} + +void PaintingArea::createFloodFillTool(){ + IntelliTool *temp = this->Tool; + this->Tool = new IntelliToolFloodFillTool(this); + delete temp; +} + 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 abdc990..2fa317a 100644 --- a/src/Painting/Layer/PaintingArea.h +++ b/src/Painting/Layer/PaintingArea.h @@ -8,8 +8,11 @@ #include #include #include "Image/IntelliImage.h" +#include "Image/IntelliRasterImage.h" +#include "Image/IntelliShapedImage.h" #include "Tool/IntelliTool.h" -#include "Tool/IntelliToolSetColorTool.h" +#include "Tool/IntelliToolPen.h" +#include "Tool/IntelliToolFloodFillTool.h" struct LayerObject{ @@ -23,6 +26,8 @@ struct LayerObject{ }; +class IntelliColorPicker; + class PaintingArea : public QWidget { // Declares our class as a QObject which is the base class @@ -33,7 +38,14 @@ 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 + IntelliColorPicker* getColorTool(); + + void getColorbar(int firstOrSecondColor); + void switchColors(); + + //Create Tools + void createPenTool(); + void createFloodFillTool(); // Handles all events bool open(const QString &fileName); @@ -81,7 +93,7 @@ private: int maxHeight; IntelliTool* Tool; - IntelliToolSetColorTool* ColorTool; + IntelliColorPicker* ColorTool; std::vector layerBundle; int activeLayer=-1; diff --git a/src/Painting/Tool/IntelliToolSetColorTool.cpp b/src/Painting/Tool/IntelliColorPicker.cpp similarity index 65% rename from src/Painting/Tool/IntelliToolSetColorTool.cpp rename to src/Painting/Tool/IntelliColorPicker.cpp index 549e0e7..55af5b9 100644 --- a/src/Painting/Tool/IntelliToolSetColorTool.cpp +++ b/src/Painting/Tool/IntelliColorPicker.cpp @@ -1,17 +1,17 @@ -#include "IntelliToolSetColorTool.h" +#include "IntelliColorPicker.h" #include "QDebug" -IntelliToolSetColorTool::IntelliToolSetColorTool(PaintingArea* Area) +IntelliColorPicker::IntelliColorPicker(PaintingArea* Area) :IntelliTool(Area){ firstColor = {255,0,0,255}; secondColor = {0,0,255,255}; } -IntelliToolSetColorTool::~IntelliToolSetColorTool(){ +IntelliColorPicker::~IntelliColorPicker(){ } -void IntelliToolSetColorTool::getColorbar(int firstOrSecondColor = 1){ +void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){ QString Titel; QColor newColor; if(firstOrSecondColor == 1){ @@ -27,10 +27,10 @@ void IntelliToolSetColorTool::getColorbar(int firstOrSecondColor = 1){ } } -QColor IntelliToolSetColorTool::getFirstColor(){ +QColor IntelliColorPicker::getFirstColor(){ return firstColor; } -QColor IntelliToolSetColorTool::getSecondColor(){ +QColor IntelliColorPicker::getSecondColor(){ return secondColor; } diff --git a/src/Painting/Tool/IntelliTool.cpp b/src/Painting/Tool/IntelliTool.cpp index 4aa4403..e2f11ff 100644 --- a/src/Painting/Tool/IntelliTool.cpp +++ b/src/Painting/Tool/IntelliTool.cpp @@ -10,10 +10,6 @@ IntelliTool::~IntelliTool(){ } -void IntelliTool::getColorbar(int firstOrSecondColor){ - //optional for tool -} - void IntelliTool::onMouseRightPressed(int x, int y){ if(drawing){ drawing=false; diff --git a/src/Painting/Tool/IntelliTool.h b/src/Painting/Tool/IntelliTool.h index 75343ce..a519616 100644 --- a/src/Painting/Tool/IntelliTool.h +++ b/src/Painting/Tool/IntelliTool.h @@ -21,8 +21,6 @@ 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 index c7c476e..4a7c34a 100644 --- a/src/Painting/Tool/IntelliToolFloodFillTool.cpp +++ b/src/Painting/Tool/IntelliToolFloodFillTool.cpp @@ -2,9 +2,9 @@ #include "Layer/PaintingArea.h" IntelliToolFloodFillTool::IntelliToolFloodFillTool(PaintingArea* Area) - :IntelliToolSetColorTool(Area) + :IntelliTool(Area) { - Tool = Area->getTool(); + Tool = Area->getColorTool(); isPressed = false; } @@ -12,7 +12,7 @@ void IntelliToolFloodFillTool::onMouseLeftPressed(int x, int y){ if(!isPressed){ isPressed = true; IntelliTool::onMouseLeftPressed(x,y); - Tool = Area->getTool(); + Tool = Area->getColorTool(); this->Canvas->image->floodFill(Tool->getFirstColor()); } } @@ -21,7 +21,7 @@ void IntelliToolFloodFillTool::onMouseRightPressed(int x, int y){ if(!isPressed){ isPressed = true; IntelliTool::onMouseLeftPressed(x,y); - Tool = Area->getTool(); + Tool = Area->getColorTool(); this->Canvas->image->floodFill(Tool->getSecondColor()); } } diff --git a/src/Painting/Tool/IntelliToolFloodFillTool.h b/src/Painting/Tool/IntelliToolFloodFillTool.h index 30b1e95..b706a99 100644 --- a/src/Painting/Tool/IntelliToolFloodFillTool.h +++ b/src/Painting/Tool/IntelliToolFloodFillTool.h @@ -1,21 +1,21 @@ #ifndef INTELLITOOLFLOODFILLTOOL_H #define INTELLITOOLFLOODFILLTOOL_H -#include "IntelliToolSetColorTool.h" +#include "IntelliHelper/IntelliColorPicker.h" -class IntelliToolFloodFillTool : public IntelliToolSetColorTool +class IntelliToolFloodFillTool : public IntelliTool { 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; + void onMouseLeftPressed(int x, int y) override; + void onMouseLeftReleased(int x, int y) override; + void onMouseRightPressed(int x, int y) override; + void onMouseRightReleased(int x, int y) override; + void onMouseMoved(int x, int y) override; private: - IntelliToolSetColorTool* Tool; + IntelliColorPicker* Tool; bool isPressed; }; diff --git a/src/Painting/Tool/IntelliToolPen.cpp b/src/Painting/Tool/IntelliToolPen.cpp index a858908..bbd188f 100644 --- a/src/Painting/Tool/IntelliToolPen.cpp +++ b/src/Painting/Tool/IntelliToolPen.cpp @@ -1,10 +1,9 @@ #include "IntelliToolPen.h" #include "Layer/PaintingArea.h" -#include "QDebug" IntelliToolPen::IntelliToolPen(PaintingArea* Area) - :IntelliToolSetColorTool(Area){ - + :IntelliTool(Area){ + Tool = new IntelliColorPicker(Area); } IntelliToolPen::~IntelliToolPen(){ @@ -35,8 +34,7 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){ void IntelliToolPen::onMouseMoved(int x, int y){ if(this->drawing){ QPoint newPoint(x,y); - Tool = Area->getTool(); - qDebug() << Tool->getFirstColor(); + Tool = Area->getColorTool(); 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 a54d80d..d1d2266 100644 --- a/src/Painting/Tool/IntelliToolPen.h +++ b/src/Painting/Tool/IntelliToolPen.h @@ -1,11 +1,13 @@ #ifndef INTELLITOOLPEN_H #define INTELLITOOLPEN_H -#include"IntelliToolSetColorTool.h" +#include"IntelliTool.h" #include"QColor" #include"QPoint" -class IntelliToolPen : public IntelliToolSetColorTool{ +class IntelliColorPicker; + +class IntelliToolPen : public IntelliTool{ QPoint point; public: IntelliToolPen(PaintingArea* Area); @@ -19,7 +21,7 @@ public: virtual void onMouseMoved(int x, int y) override; private: - IntelliToolSetColorTool* Tool; + IntelliColorPicker* Tool; }; #endif // INTELLITOOLPEN_H diff --git a/src/Painting/Tool/IntelliToolSetColorTool.h b/src/Painting/Tool/IntelliToolSetColorTool.h deleted file mode 100644 index c8c0c1a..0000000 --- a/src/Painting/Tool/IntelliToolSetColorTool.h +++ /dev/null @@ -1,24 +0,0 @@ -#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