Änderung der Vererbung der Tools und einfügen des ColorPickers (Farbmanager)

This commit is contained in:
AshBastian
2019-12-12 10:22:20 +01:00
parent 72bde027ed
commit e8d8223cc2
15 changed files with 180 additions and 77 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,17 +8,11 @@
#include <QRect>
#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;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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