mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-15 04:40:37 +02:00
Moved up src/ one level
This commit is contained in:
36
src/Tool/IntelliColorPicker.cpp
Normal file
36
src/Tool/IntelliColorPicker.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "IntelliColorPicker.h"
|
||||
#include "QDebug"
|
||||
|
||||
IntelliColorPicker::IntelliColorPicker(PaintingArea* Area)
|
||||
:IntelliTool(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);
|
||||
this->firstColor = newColor;
|
||||
qDebug() << "Firstcolor" << this->firstColor;
|
||||
}
|
||||
else{
|
||||
Titel = "Choose second Color";
|
||||
newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel);
|
||||
this->secondColor = newColor;
|
||||
}
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getFirstColor(){
|
||||
return firstColor;
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getSecondColor(){
|
||||
return secondColor;
|
||||
}
|
||||
77
src/Tool/IntelliTool.cpp
Normal file
77
src/Tool/IntelliTool.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include"IntelliTool.h"
|
||||
#include"Layer/PaintingArea.h"
|
||||
|
||||
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){
|
||||
this->Area=Area;
|
||||
this->colorPicker=colorPicker;
|
||||
}
|
||||
|
||||
|
||||
IntelliTool::~IntelliTool(){
|
||||
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseRightPressed(int x, int y){
|
||||
if(drawing){
|
||||
drawing=false;
|
||||
this->deleteToolLayer();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseRightReleased(int x, int y){
|
||||
//optional for tool
|
||||
}
|
||||
|
||||
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){
|
||||
if(drawing){
|
||||
drawing=false;
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
Active->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseMoved(int x, int y){
|
||||
if(drawing)
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliTool::createToolLayer(){
|
||||
Area->createTempLayerAfter(Area->activeLayer);
|
||||
this->Active=&Area->layerBundle[Area->activeLayer];
|
||||
this->Canvas=&Area->layerBundle[Area->activeLayer+1];
|
||||
}
|
||||
|
||||
void IntelliTool::mergeToolLayer(){
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<Active->hight; y++){
|
||||
for(int x=0; x<Active->width; x++){
|
||||
clr_0=Active->image->imageData.pixelColor(x,y);
|
||||
clr_1=Canvas->image->imageData.pixelColor(x,y);
|
||||
float t = static_cast<float>(clr_1.alpha())/255.f;
|
||||
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
|
||||
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
|
||||
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
|
||||
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
|
||||
Active->image->imageData.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::deleteToolLayer(){
|
||||
Area->deleteLayer(Area->activeLayer+1);
|
||||
this->Canvas=nullptr;
|
||||
}
|
||||
34
src/Tool/IntelliTool.h
Normal file
34
src/Tool/IntelliTool.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef Intelli_Tool_H
|
||||
#define Intelli_Tool_H
|
||||
|
||||
#include "IntelliHelper/IntelliColorPicker.h"
|
||||
#include <vector>
|
||||
|
||||
class LayerObject;
|
||||
class PaintingArea;
|
||||
|
||||
class IntelliTool{
|
||||
private:
|
||||
void createToolLayer();
|
||||
void mergeToolLayer();
|
||||
void deleteToolLayer();
|
||||
protected:
|
||||
PaintingArea* Area;
|
||||
IntelliColorPicker* colorPicker;
|
||||
|
||||
LayerObject* Active;
|
||||
LayerObject* Canvas;
|
||||
bool drawing = false;
|
||||
|
||||
public:
|
||||
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
virtual ~IntelliTool() = 0;
|
||||
|
||||
virtual void onMouseRightPressed(int x, int y);
|
||||
virtual void onMouseRightReleased(int x, int y);
|
||||
virtual void onMouseLeftPressed(int x, int y);
|
||||
virtual void onMouseLeftReleased(int x, int y);
|
||||
|
||||
virtual void onMouseMoved(int x, int y);
|
||||
};
|
||||
#endif
|
||||
56
src/Tool/IntelliToolLine.cpp
Normal file
56
src/Tool/IntelliToolLine.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "IntelliToolLine.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QColorDialog"
|
||||
#include "QInputDialog"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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, colorPicker->getFirstColor(),lineWidth);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
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->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
switch(lineStyle){
|
||||
case LineStyle::SOLID_LINE:
|
||||
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
|
||||
break;
|
||||
case LineStyle::DOTTED_LINE:
|
||||
QPoint p1 =start.x() <= next.x() ? start : next;
|
||||
QPoint p2 =start.x() < next.x() ? next : start;
|
||||
int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f;
|
||||
int c = start.y()-start.x()*m;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
31
src/Tool/IntelliToolLine.h
Normal file
31
src/Tool/IntelliToolLine.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef INTELLITOOLLINE_H
|
||||
#define INTELLITOOLLINE_H
|
||||
#include "IntelliTool.h"
|
||||
|
||||
#include "QColor"
|
||||
#include "QPoint"
|
||||
|
||||
enum class LineStyle{
|
||||
SOLID_LINE,
|
||||
DOTTED_LINE
|
||||
};
|
||||
|
||||
class IntelliToolLine : public IntelliTool
|
||||
{
|
||||
QPoint start;
|
||||
int lineWidth;
|
||||
LineStyle lineStyle;
|
||||
public:
|
||||
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
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
|
||||
42
src/Tool/IntelliToolPen.cpp
Normal file
42
src/Tool/IntelliToolPen.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "IntelliToolPen.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QDebug"
|
||||
#include "QColorDialog"
|
||||
#include "QInputDialog"
|
||||
|
||||
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
|
||||
}
|
||||
|
||||
IntelliToolPen::~IntelliToolPen(){
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,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){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseMoved(int x, int y){
|
||||
if(this->drawing){
|
||||
QPoint newPoint(x,y);
|
||||
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
|
||||
this->point=newPoint;
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
23
src/Tool/IntelliToolPen.h
Normal file
23
src/Tool/IntelliToolPen.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef INTELLITOOLPEN_H
|
||||
#define INTELLITOOLPEN_H
|
||||
|
||||
#include"IntelliTool.h"
|
||||
#include"QColor"
|
||||
#include"QPoint"
|
||||
|
||||
class IntelliToolPen : public IntelliTool{
|
||||
int penWidth;
|
||||
QPoint point;
|
||||
public:
|
||||
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
virtual ~IntelliToolPen() 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 // INTELLITOOLPEN_H
|
||||
30
src/Tool/IntelliToolPlain.cpp
Normal file
30
src/Tool/IntelliToolPlain.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "IntelliToolPlain.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QColorDialog"
|
||||
|
||||
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Canvas->image->drawPlain(colorPicker->getFirstColor());
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(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);
|
||||
}
|
||||
20
src/Tool/IntelliToolPlain.h
Normal file
20
src/Tool/IntelliToolPlain.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef INTELLITOOLFLOODFILLTOOL_H
|
||||
#define INTELLITOOLFLOODFILLTOOL_H
|
||||
|
||||
#include "IntelliTool.h"
|
||||
#include "QColor"
|
||||
|
||||
class IntelliToolPlainTool : public IntelliTool
|
||||
{
|
||||
public:
|
||||
IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker);
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLFLOODFILLTOOL_H
|
||||
Reference in New Issue
Block a user