new tools

This commit is contained in:
Sonaion
2019-12-12 11:18:37 +01:00
parent b1895b0c04
commit 5ec4f9f8f9
15 changed files with 141 additions and 47 deletions

View File

@@ -219,8 +219,12 @@ void IntelliPhotoGui::slotCreatePenTool(){
paintingArea->createPenTool();
}
void IntelliPhotoGui::slotCreateFloodFillTool(){
paintingArea->createFloodFillTool();
void IntelliPhotoGui::slotCreatePlainTool(){
paintingArea->createPlainTool();
}
void IntelliPhotoGui::slotCreateLineTool(){
paintingArea->createLineTool();
}
// Open an about dialog
@@ -315,12 +319,14 @@ void IntelliPhotoGui::createActions()
connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown()));
//Create Tool actions down here
actionCreateFloodFillTool = new QAction(tr("&Flood Fill"), this);
connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
actionCreatePlainTool = new QAction(tr("&Plain"), this);
connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool()));
actionCreatePenTool = new QAction(tr("&Pen"),this);
connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool()));
actionCreateLineTool = new QAction(tr("&Line"), this);
connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
// Create about action and tie to IntelliPhotoGui::about()
actionAboutDialog = new QAction(tr("&About"), this);
@@ -366,7 +372,8 @@ void IntelliPhotoGui::createMenus()
//Attach all Tool Options
toolMenu = new QMenu(tr("&Tools"), this);
toolMenu->addAction(actionCreatePenTool);
toolMenu->addAction(actionCreateFloodFillTool);
toolMenu->addAction(actionCreatePlainTool);
toolMenu->addAction(actionCreateLineTool);
// Attach all actions to Help
helpMenu = new QMenu(tr("&Help"), this);

View File

@@ -44,7 +44,8 @@ private slots:
void slotMoveLayerDown();
void slotCreatePenTool();
void slotCreateFloodFillTool();
void slotCreatePlainTool();
void slotCreateLineTool();
void slotAboutDialog();
@@ -83,7 +84,8 @@ private:
QAction *actionDeleteLayer;
QAction *actionCreatePenTool;
QAction *actionCreateFloodFillTool;
QAction *actionCreatePlainTool;
QAction *actionCreateLineTool;
QAction *actionAboutDialog;
QAction *actionAboutQtDialog;

View File

@@ -19,7 +19,6 @@ class IntelliImage{
friend IntelliTool;
protected:
void resizeImage(QImage *image, const QSize &newSize);
virtual void calculateVisiblity()=0;
QImage imageData;
@@ -28,6 +27,7 @@ public:
IntelliImage(int weight, int height);
virtual ~IntelliImage() = 0;
//start on top left
virtual void drawPixel(const QPoint &p1, const QColor& color);
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
@@ -39,12 +39,13 @@ public:
//gets a copy of the image !allocated
virtual IntelliImage* getDeepCopy()=0;
virtual void calculateVisiblity()=0;
//returns the filtered output
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
virtual std::vector<QPoint> getPolygonData(){ return std::vector<QPoint>();}
//loads an image to the ColorBuffer
virtual bool loadImage(const QString &fileName);

View File

@@ -18,8 +18,8 @@ QImage IntelliShapedImage::getDisplayable(int alpha){
IntelliImage* IntelliShapedImage::getDeepCopy(){
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
shaped->setPolygon(this->polygonData);
shaped->imageData.fill(Qt::transparent);
shaped->setPolygon(this->polygonData);
return shaped;
}

View File

@@ -6,18 +6,21 @@
class IntelliShapedImage : public IntelliImage{
friend IntelliTool;
protected:
virtual void calculateVisiblity() override;
std::vector<QPoint> polygonData;
public:
IntelliShapedImage(int weight, int height);
virtual ~IntelliShapedImage() override;
virtual void calculateVisiblity() override;
//returns the filtered output
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
virtual QImage getDisplayable(int alpha=255) override;
//gets a copy of the image !allocated
virtual IntelliImage* getDeepCopy() override;
virtual std::vector<QPoint> getPolygonData() override{return polygonData;}
//sets the data for the visible image
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;

View File

@@ -23,8 +23,9 @@ SOURCES += \
IntelliHelper/IntelliHelper.cpp \
Layer/PaintingArea.cpp \
Tool/IntelliTool.cpp \
Tool/IntelliToolFloodFillTool.cpp \
Tool/IntelliToolLine.cpp \
Tool/IntelliToolPen.cpp \
Tool/IntelliToolPlain.cpp \
main.cpp
HEADERS += \
@@ -35,8 +36,9 @@ HEADERS += \
IntelliHelper/IntelliHelper.h \
Layer/PaintingArea.h \
Tool/IntelliTool.h \
Tool/IntelliToolFloodFillTool.h \
Tool/IntelliToolPen.h
Tool/IntelliToolLine.h \
Tool/IntelliToolPen.h \
Tool/IntelliToolPlain.h
FORMS += \
widget.ui

View File

@@ -11,7 +11,8 @@
#include "Image/IntelliRasterImage.h"
#include "Image/IntelliShapedImage.h"
#include "Tool/IntelliToolPen.h"
#include "Tool/IntelliToolFloodFillTool.h"
#include "Tool/IntelliToolPlain.h"
#include "Tool/IntelliToolLine.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
@@ -32,7 +33,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
layerBundle[1].image->floodFill(QColor(0,255,0,255));
layerBundle[1].alpha=200;
activeLayer=1;
activeLayer=0;
}
@@ -165,9 +166,14 @@ void PaintingArea::createPenTool(){
Tool = new IntelliToolPen(this);
}
void PaintingArea::createFloodFillTool(){
void PaintingArea::createPlainTool(){
delete this->Tool;
Tool = new IntelliToolFloodFillTool(this);
Tool = new IntelliToolPlainTool(this);
}
void PaintingArea::createLineTool(){
delete this->Tool;
Tool = new IntelliToolLine(this);
}
// If a mouse button is pressed check if it was the

View File

@@ -50,7 +50,8 @@ public:
//create tools
void createPenTool();
void createFloodFillTool();
void createPlainTool();
void createLineTool();
public slots:

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;
@@ -69,6 +65,7 @@ void IntelliTool::mergeToolLayer(){
Active->image->imageData.setPixelColor(x, y, clr_0);
}
Active->image->calculateVisiblity();
}
}

View File

@@ -21,7 +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);

View File

@@ -0,0 +1,49 @@
#include "IntelliToolLine.h"
#include "Layer/PaintingArea.h"
#include "QColorDialog"
#include "QInputDialog"
IntelliToolLine::IntelliToolLine(PaintingArea* Area)
:IntelliTool(Area){
this->color = QColorDialog::getColor(Qt::blue, nullptr, "Line Color");
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;
}
IntelliToolLine::~IntelliToolLine(){
}
void IntelliToolLine::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y);
}
void IntelliToolLine::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,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);
}
void IntelliToolLine::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y);
}
void IntelliToolLine::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y);
if(this->drawing){
this->Canvas->image->floodFill(Qt::transparent);
QPoint next(x,y);
switch(lineStyle){
case LineStyle::SOLID_LINE :
this->Canvas->image->drawLine(start,next,color,lineWidth);
break;
}
}
}

View File

@@ -0,0 +1,31 @@
#ifndef INTELLITOOLLINE_H
#define INTELLITOOLLINE_H
#include "IntelliTool.h"
#include "QColor"
#include "QPoint"
enum class LineStyle{
SOLID_LINE
};
class IntelliToolLine : public IntelliTool
{
QPoint start;
QColor color;
int lineWidth;
LineStyle lineStyle;
public:
IntelliToolLine(PaintingArea* Area);
virtual ~IntelliToolLine() override;
virtual void onMouseRightPressed(int x, int y) override;
virtual void onMouseRightReleased(int x, int y) override;
virtual void onMouseLeftPressed(int x, int y) override;
virtual void onMouseLeftReleased(int x, int y) override;
virtual void onMouseMoved(int x, int y) override;
};
#endif // INTELLITOOLLINE_H

View File

@@ -7,9 +7,7 @@
IntelliToolPen::IntelliToolPen(PaintingArea* Area)
:IntelliTool(Area){
this->color = QColorDialog::getColor(Qt::blue,nullptr,"Flood Fill Color");
bool ok;
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Number:", 1,0, 50, 1, &ok);
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Number:", 1,0, 50, 1);
}
IntelliToolPen::~IntelliToolPen(){
@@ -18,22 +16,18 @@ IntelliToolPen::~IntelliToolPen(){
void IntelliToolPen::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y);
//implement in here
}
void IntelliToolPen::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
//implemnt in here
}
void IntelliToolPen::onMouseLeftPressed(int x, int y){
//implement in here
IntelliTool::onMouseLeftPressed(x,y);
this->point=QPoint(x,y);
}
void IntelliToolPen::onMouseLeftReleased(int x, int y){
//implement in here
IntelliTool::onMouseLeftReleased(x,y);
}

View File

@@ -1,30 +1,32 @@
#include "IntelliToolFloodFillTool.h"
#include "IntelliToolPlain.h"
#include "Layer/PaintingArea.h"
#include "QColorDialog"
IntelliToolFloodFillTool::IntelliToolFloodFillTool(PaintingArea* Area)
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area)
:IntelliTool(Area){
this->color = QColorDialog::getColor(Qt::blue,nullptr,"Flood Fill Color");
}
void IntelliToolFloodFillTool::onMouseLeftPressed(int x, int y){
void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y);
this->Canvas->image->floodFill(color);
}
void IntelliToolFloodFillTool::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y);
}
void IntelliToolFloodFillTool::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
}
void IntelliToolFloodFillTool::onMouseLeftReleased(int x, int y){
void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y);
}
void IntelliToolFloodFillTool::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y);
void IntelliToolPlainTool::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y);
}
void IntelliToolPlainTool::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y);
}
void IntelliToolPlainTool::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y);
}

View File

@@ -4,11 +4,11 @@
#include "IntelliTool.h"
#include "QColor"
class IntelliToolFloodFillTool : public IntelliTool
class IntelliToolPlainTool : public IntelliTool
{
QColor color;
public:
IntelliToolFloodFillTool(PaintingArea *Area);
IntelliToolPlainTool(PaintingArea *Area);
void onMouseLeftPressed(int x, int y) override;
void onMouseLeftReleased(int x, int y) override;