SetColorTool, PenTool und FloodFillTool

LoL
This commit is contained in:
AshBastian
2019-12-11 16:29:11 +01:00
parent 10fba8c454
commit 72bde027ed
13 changed files with 184 additions and 13 deletions

View File

@@ -10,6 +10,9 @@ IntelliTool::~IntelliTool(){
}
void IntelliTool::getColorbar(int firstOrSecondColor){
//optional for tool
}
void IntelliTool::onMouseRightPressed(int x, int y){
if(drawing){

View File

@@ -1,7 +1,7 @@
#ifndef Intelli_Tool_H
#define Intelli_Tool_H
#include<vector>
#include <vector>
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);

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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