diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index 2b1d4d5..a0adaac 100755 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -30,6 +30,7 @@ SOURCES += \ Tool/IntelliTool.cpp \ Tool/IntelliToolCircle.cpp \ Tool/IntelliToolFloodFill.cpp \ + Tool/IntelliToolGradient.cpp \ Tool/IntelliToolLine.cpp \ Tool/IntelliToolPen.cpp \ Tool/IntelliToolPlain.cpp \ @@ -52,6 +53,7 @@ HEADERS += \ Tool/IntelliTool.h \ Tool/IntelliToolCircle.h \ Tool/IntelliToolFloodFill.h \ + Tool/IntelliToolGradient.h \ Tool/IntelliToolLine.h \ Tool/IntelliToolPen.h \ Tool/IntelliToolPlain.h \ diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 6534aab..8df8ffe 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -17,6 +17,7 @@ #include "Tool/IntelliToolRectangle.h" #include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolPolygon.h" +#include "Tool/IntelliToolGradient.h" #include "GUI/IntelliPhotoGui.h" LayerObject::LayerObject(){ @@ -38,9 +39,8 @@ LayerObject::LayerObject(const LayerObject& layer){ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QLabel(parent){ - this->Tool = nullptr; + this->Tool = new IntelliToolGradient(this,&colorPicker,&Toolsettings); this->setLayerDimensions(maxWidth, maxHeight); - activeLayer = -1; } diff --git a/src/Tool/IntelliToolGradient.cpp b/src/Tool/IntelliToolGradient.cpp new file mode 100644 index 0000000..4ab3699 --- /dev/null +++ b/src/Tool/IntelliToolGradient.cpp @@ -0,0 +1,61 @@ +#include "IntelliToolGradient.h" +#include + +IntelliToolGradient::IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->LineColor = QColor(0,0,0,255); + this->hasMoved = false; + + A = QPoint(0,0); + B = QPoint(0,3); + VectorAB = QPoint(0,3); + computePixelColor(QPoint(2,1)); +} + +IntelliToolGradient::~IntelliToolGradient(){ + IntelliTool::onMouseRightPressed(0,0); +} + +void IntelliToolGradient::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + A = QPoint(x,y); + B = QPoint(x,y); + VectorAB = QPoint(0,0); + //Canvas->image->drawPlain(colorPicker->getFirstColor); + //Canvas->image->drawPixel(A,LineColor); +} + +void IntelliToolGradient::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolGradient::onMouseLeftReleased(int x, int y){ + if(!hasMoved && A != B){ + //Canvas->image->drawPlain(colorPicker->getFirstColor); + } + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolGradient::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolGradient::onMouseMoved(int x, int y){ + hasMoved = true; + B = QPoint(x,y); + IntelliTool::onMouseMoved(x,y); +} + +void IntelliToolGradient::onWheelScrolled(int value){ + IntelliTool::onWheelScrolled(value); +} + +void IntelliToolGradient::computePixelColor(QPoint Point){ + QPoint NormalVector = QPoint(VectorAB.y(),(-1*VectorAB.x())); + Point = Point - (dotProduct((Point - A),NormalVector) / dotProduct(NormalVector,NormalVector)) * NormalVector; + qDebug() << Point.y(); +} + +float IntelliToolGradient::dotProduct(QPoint Vector1, QPoint Vector2){ + return static_cast(Vector1.x()*Vector2.x()+Vector1.y()*Vector2.y()); +} diff --git a/src/Tool/IntelliToolGradient.h b/src/Tool/IntelliToolGradient.h new file mode 100644 index 0000000..80424a1 --- /dev/null +++ b/src/Tool/IntelliToolGradient.h @@ -0,0 +1,64 @@ +#ifndef INTELLITOOLGRADIENT_H +#define INTELLITOOLGRADIENT_H +#include "IntelliTool.h" + +class IntelliToolGradient : public IntelliTool{ +private: + QPoint A; + QPoint B; + QPoint VectorAB; + QColor LineColor; + bool hasMoved; + +public: + IntelliToolGradient(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); + + ~IntelliToolGradient(); + + /*! + * \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseRightPressed(int x, int y); + + /*! + * \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseRightReleased(int x, int y); + + /*! + * \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseLeftPressed(int x, int y); + + /*! + * \brief A function managing the left click Released of a Mouse. Call this in child classes! + * \param x - The x coordinate relative to the active/canvas layer. + * \param y - The y coordinate relative to the active/canvas layer. + */ + virtual void onMouseLeftReleased(int x, int y); + + /*! + * \brief A function managing the scroll event. A positive value means scrolling outwards. Call this in child classes! + * \param value - The absolute the scroll has changed. + */ + virtual void onWheelScrolled(int value); + + /*! + * \brief A function managing the mouse moved event. Call this in child classes! + * \param x - The x coordinate of the new mouse position. + * \param y - The y coordinate of the new mouse position. + */ + virtual void onMouseMoved(int x, int y); + + void computePixelColor(QPoint Point); + + float dotProduct(QPoint Vector1, QPoint Vector2); +}; + +#endif // INTELLITOOLGRADIENT_H