Merge branch 'dev_FormTool' into 'dev'

SetColorTool, PenTool und FloodFillTool

See merge request creyd/intelliphoto!17
This commit is contained in:
Jonas Mucke
2019-12-11 16:57:43 +00:00
13 changed files with 184 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -7,8 +7,9 @@
#include <QPoint>
#include <QWidget>
#include <QList>
#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<LayerObject> layerBundle;
int activeLayer=-1;

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