Bug free tool strucute - try me bitch

This commit is contained in:
Sonaion
2019-12-12 13:03:08 +01:00
parent 8f615c26b1
commit 84ea429b2a
15 changed files with 111 additions and 76 deletions

View File

@@ -214,6 +214,17 @@ void IntelliPhotoGui::slotSetActiveLayer(){
}
};
void IntelliPhotoGui::slotSetFirstColor(){
paintingArea->colorPickerSetFirstColor();
}
void IntelliPhotoGui::slotSetSecondColor(){
paintingArea->colorPickerSetSecondColor();
}
void IntelliPhotoGui::slotSwitchColor(){
paintingArea->colorPickerSwitchColor();
}
void IntelliPhotoGui::slotCreatePenTool(){
paintingArea->createPenTool();
@@ -318,6 +329,17 @@ void IntelliPhotoGui::createActions()
actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down));
connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
//Create Color Actions here
actionColorPickerFirstColor = new QAction(tr("&Main"), this);
connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
actionColorSwitch = new QAction(tr("&Switch"), this);
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
connect(actionColorSwitch, SIGNAL(triggered()), this, SLOT(slotSwitchColor()));
//Create Tool actions down here
actionCreatePlainTool = new QAction(tr("&Plain"), this);
connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool()));
@@ -369,11 +391,19 @@ void IntelliPhotoGui::createMenus()
layerMenu->addAction(actionCreateNewLayer);
layerMenu->addAction(actionDeleteLayer);
//Attach all Color Options
colorMenu = new QMenu(tr("&Color"), this);
colorMenu->addAction(actionColorPickerFirstColor);
colorMenu->addAction(actionColorPickerSecondColor);
colorMenu->addAction(actionColorSwitch);
//Attach all Tool Options
toolMenu = new QMenu(tr("&Tools"), this);
toolMenu->addAction(actionCreatePenTool);
toolMenu->addAction(actionCreatePlainTool);
toolMenu->addAction(actionCreateLineTool);
toolMenu->addSeparator();
toolMenu->addMenu(colorMenu);
// Attach all actions to Help
helpMenu = new QMenu(tr("&Help"), this);

View File

@@ -29,10 +29,12 @@ protected:
// Function used to close an event
void closeEvent(QCloseEvent *event) override;
// The events that can be triggered
private slots:
//meta slots here (need further )
void slotOpen();
void slotSave();
//layer slots here
void slotCreateNewLayer();
void slotDeleteLayer();
void slotClearActiveLayer();
@@ -45,10 +47,17 @@ private slots:
void slotMoveLayerUp();
void slotMoveLayerDown();
//color Picker slots here
void slotSetFirstColor();
void slotSetSecondColor();
void slotSwitchColor();
//tool slots here
void slotCreatePenTool();
void slotCreatePlainTool();
void slotCreateLineTool();
//slots for dialogs
void slotAboutDialog();
private:
@@ -74,23 +83,33 @@ private:
QMenu *fileMenu;
QMenu *optionMenu;
QMenu *layerMenu;
QMenu *colorMenu;
QMenu *toolMenu;
QMenu *helpMenu;
// All the actions that can occur
//meta image actions (need further modularisation)
QAction *actionOpen;
QAction *actionExit;
QAction *actionCreateNewLayer;
QAction *actionDeleteLayer;
//color Picker actions
QAction *actionColorPickerFirstColor;
QAction *actionColorPickerSecondColor;
QAction *actionColorSwitch;
//tool actions
QAction *actionCreatePenTool;
QAction *actionCreatePlainTool;
QAction *actionCreateLineTool;
//dialog actions
QAction *actionAboutDialog;
QAction *actionAboutQtDialog;
//layer change actions
QAction *actionCreateNewLayer;
QAction *actionDeleteLayer;
QAction* actionSetActiveLayer;
QAction* actionSetActiveAlpha;
QAction* actionMovePositionUp;

View File

@@ -18,8 +18,8 @@ QImage IntelliShapedImage::getDisplayable(int alpha){
IntelliImage* IntelliShapedImage::getDeepCopy(){
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
shaped->imageData.fill(Qt::transparent);
shaped->setPolygon(this->polygonData);
shaped->imageData.fill(Qt::transparent);
return shaped;
}
@@ -52,7 +52,7 @@ void IntelliShapedImage::calculateVisiblity(){
imageData.setPixelColor(x,y,clr);
}else{
clr = imageData.pixelColor(x,y);
clr.setAlpha(255);
clr.setAlpha(std::min(255, clr.alpha()));
imageData.setPixelColor(x,y,clr);
}
}

View File

@@ -1,6 +1,6 @@
#include "IntelliColorPicker.h"
IntelliColorPicker::IntelliColorPicker(PaintingArea* Area){
IntelliColorPicker::IntelliColorPicker(){
firstColor = {255,0,0,255};
secondColor = {0,0,255,255};
}
@@ -9,25 +9,8 @@ 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;
std::swap(firstColor, secondColor);
}
QColor IntelliColorPicker::getFirstColor(){

View File

@@ -1,17 +1,15 @@
#ifndef INTELLITOOLSETCOLORTOOL_H
#define INTELLITOOLSETCOLORTOOL_H
#include"Layer/PaintingArea.h"
#include"QColor"
#include"QPoint"
#include"QColorDialog"
class IntelliColorPicker{
public:
IntelliColorPicker(PaintingArea *Area);
IntelliColorPicker();
virtual ~IntelliColorPicker();
void getColorbar(int firstOrSecondColor);
void switchColors();
QColor getFirstColor();

View File

@@ -37,22 +37,6 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
}
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;
@@ -177,19 +161,33 @@ void PaintingArea::slotActivateLayer(int a){
}
}
void PaintingArea::colorPickerSetFirstColor(){
QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color");
this->colorPicker.setFirstColor(clr);
}
void PaintingArea::colorPickerSetSecondColor(){
QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color");
this->colorPicker.setSecondColor(clr);
}
void PaintingArea::colorPickerSwitchColor(){
this->colorPicker.switchColors();
}
void PaintingArea::createPenTool(){
delete this->Tool;
Tool = new IntelliToolPen(this);
Tool = new IntelliToolPen(this, &colorPicker);
}
void PaintingArea::createPlainTool(){
delete this->Tool;
Tool = new IntelliToolPlainTool(this);
Tool = new IntelliToolPlainTool(this, &colorPicker);
}
void PaintingArea::createLineTool(){
delete this->Tool;
Tool = new IntelliToolLine(this);
Tool = new IntelliToolLine(this, &colorPicker);
}
// If a mouse button is pressed check if it was the

View File

@@ -11,6 +11,7 @@
#include "Image/IntelliRasterImage.h"
#include "Image/IntelliShapedImage.h"
#include "Tool/IntelliTool.h"
#include "IntelliHelper/IntelliColorPicker.h"
struct LayerObject{
@@ -24,8 +25,6 @@ struct LayerObject{
};
class IntelliColorPicker;
class PaintingArea : public QWidget
{
// Declares our class as a QObject which is the base class
@@ -52,6 +51,11 @@ public:
// Has the image been modified since last save
bool isModified() const { return modified; }
//change properties of colorPicker
void colorPickerSetFirstColor();
void colorPickerSetSecondColor();
void colorPickerSwitchColor();
//create tools
void createPenTool();
void createPlainTool();
@@ -86,6 +90,7 @@ private:
int maxHeight;
IntelliTool* Tool;
IntelliColorPicker colorPicker;
std::vector<LayerObject> layerBundle;
int activeLayer=-1;

View File

@@ -1,8 +1,9 @@
#include"IntelliTool.h"
#include"Layer/PaintingArea.h"
IntelliTool::IntelliTool(PaintingArea* Area){
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){
this->Area=Area;
this->colorPicker=colorPicker;
}
@@ -25,7 +26,7 @@ void IntelliTool::onMouseLeftPressed(int x, int y){
this->drawing=true;
//create drawing layer
this->createToolLayer();
Canvas->image->calculateVisiblity();
}
void IntelliTool::onMouseLeftReleased(int x, int y){
@@ -33,11 +34,13 @@ void IntelliTool::onMouseLeftReleased(int x, int y){
drawing=false;
this->mergeToolLayer();
this->deleteToolLayer();
Active->image->calculateVisiblity();
}
}
void IntelliTool::onMouseMoved(int x, int y){
//optional for tool
if(drawing)
Canvas->image->calculateVisiblity();
}
void IntelliTool::createToolLayer(){
@@ -65,7 +68,6 @@ void IntelliTool::mergeToolLayer(){
Active->image->imageData.setPixelColor(x, y, clr_0);
}
Active->image->calculateVisiblity();
}
}

View File

@@ -1,6 +1,7 @@
#ifndef Intelli_Tool_H
#define Intelli_Tool_H
#include "IntelliHelper/IntelliColorPicker.h"
#include <vector>
class LayerObject;
@@ -13,12 +14,14 @@ private:
void deleteToolLayer();
protected:
PaintingArea* Area;
IntelliColorPicker* colorPicker;
LayerObject* Active;
LayerObject* Canvas;
bool drawing = false;
public:
IntelliTool(PaintingArea* Area);
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
virtual ~IntelliTool() = 0;
virtual void onMouseRightPressed(int x, int y);

View File

@@ -3,9 +3,8 @@
#include "QColorDialog"
#include "QInputDialog"
IntelliToolLine::IntelliToolLine(PaintingArea* Area)
:IntelliTool(Area){
this->color = QColorDialog::getColor(Qt::blue, nullptr, "Line Color");
IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){
this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
//create checkbox or scroll dialog to get line style
this->lineStyle = LineStyle::SOLID_LINE;
@@ -27,7 +26,8 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
void IntelliToolLine::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->start=QPoint(x,y);
this->Canvas->image->drawLine(start, start, this->color, this->lineWidth);
this->Canvas->image->drawLine(start, start, colorPicker->getFirstColor(),lineWidth);
Canvas->image->calculateVisiblity();
}
void IntelliToolLine::onMouseLeftReleased(int x, int y){
@@ -41,9 +41,9 @@ void IntelliToolLine::onMouseMoved(int x, int y){
QPoint next(x,y);
switch(lineStyle){
case LineStyle::SOLID_LINE :
this->Canvas->image->drawLine(start,next,color,lineWidth);
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
break;
}
}
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -12,11 +12,10 @@ enum class LineStyle{
class IntelliToolLine : public IntelliTool
{
QPoint start;
QColor color;
int lineWidth;
LineStyle lineStyle;
public:
IntelliToolLine(PaintingArea* Area);
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker);
virtual ~IntelliToolLine() override;

View File

@@ -4,10 +4,9 @@
#include "QColorDialog"
#include "QInputDialog"
IntelliToolPen::IntelliToolPen(PaintingArea* Area)
:IntelliTool(Area){
this->color = QColorDialog::getColor(Qt::blue,nullptr,"Flood Fill Color");
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Number:", 1,0, 50, 1);
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
}
IntelliToolPen::~IntelliToolPen(){
@@ -25,6 +24,8 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){
void IntelliToolPen::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->point=QPoint(x,y);
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
Canvas->image->calculateVisiblity();
}
void IntelliToolPen::onMouseLeftReleased(int x, int y){
@@ -34,7 +35,8 @@ 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, color, penWidth);
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
this->point=newPoint;
}
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -6,11 +6,10 @@
#include"QPoint"
class IntelliToolPen : public IntelliTool{
QColor color;
int penWidth;
QPoint point;
public:
IntelliToolPen(PaintingArea* Area);
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker);
virtual ~IntelliToolPen() override;
virtual void onMouseRightPressed(int x, int y) override;

View File

@@ -2,15 +2,14 @@
#include "Layer/PaintingArea.h"
#include "QColorDialog"
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area)
:IntelliTool(Area){
this->color = QColorDialog::getColor(Qt::blue,nullptr,"Flood Fill Color");
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){
}
void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->Canvas->image->floodFill(color);
this->Canvas->image->floodFill(colorPicker->getFirstColor());
Canvas->image->calculateVisiblity();
}
void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){
@@ -28,5 +27,4 @@ void IntelliToolPlainTool::onMouseRightReleased(int x, int y){
void IntelliToolPlainTool::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -6,9 +6,8 @@
class IntelliToolPlainTool : public IntelliTool
{
QColor color;
public:
IntelliToolPlainTool(PaintingArea *Area);
IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker);
void onMouseLeftPressed(int x, int y) override;
void onMouseLeftReleased(int x, int y) override;