mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-15 04:40:37 +02:00
Recht unschöne Modularität der Tools
This commit is contained in:
@@ -29,15 +29,17 @@ public:
|
|||||||
virtual ~IntelliImage() = 0;
|
virtual ~IntelliImage() = 0;
|
||||||
|
|
||||||
//start on top left
|
//start on top left
|
||||||
//TODO give tool refrence of image, -> funtkions will not be needed
|
virtual void drawPixel(const QPoint &p1, const QColor& color);
|
||||||
virtual void drawPixel(const QPoint &p1, const QColor& color);
|
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
|
||||||
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
|
virtual void floodFill(const QColor& color);
|
||||||
virtual void floodFill(const QColor& color);
|
|
||||||
|
|
||||||
//returns the filtered output
|
//returns the filtered output
|
||||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0;
|
virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0;
|
||||||
virtual QImage getDisplayable(int alpha=255)=0;
|
virtual QImage getDisplayable(int alpha=255)=0;
|
||||||
|
|
||||||
|
//gets a copy of the image !allocated
|
||||||
|
virtual IntelliImage* getDeepCopy()=0;
|
||||||
|
|
||||||
//returns the filtered output
|
//returns the filtered output
|
||||||
|
|
||||||
//sets the data for the visible image
|
//sets the data for the visible image
|
||||||
|
|||||||
@@ -12,8 +12,14 @@ IntelliRasterImage::~IntelliRasterImage(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliRasterImage::calculateVisiblity(){
|
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
||||||
|
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||||
|
raster->imageData.fill(Qt::transparent);
|
||||||
|
return raster;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliRasterImage::calculateVisiblity(){
|
||||||
|
//not used in raster image
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage IntelliRasterImage::getDisplayable(int alpha){
|
QImage IntelliRasterImage::getDisplayable(int alpha){
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include"Image/IntelliImage.h"
|
#include"Image/IntelliImage.h"
|
||||||
|
|
||||||
class IntelliRasterImage : public IntelliImage{
|
class IntelliRasterImage : public IntelliImage{
|
||||||
|
friend IntelliTool;
|
||||||
protected:
|
protected:
|
||||||
virtual void calculateVisiblity() override;
|
virtual void calculateVisiblity() override;
|
||||||
public:
|
public:
|
||||||
@@ -14,6 +15,8 @@ public:
|
|||||||
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
|
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
|
||||||
virtual QImage getDisplayable(int alpha=255) override;
|
virtual QImage getDisplayable(int alpha=255) override;
|
||||||
|
|
||||||
|
//gets a copy of the image !allocated
|
||||||
|
virtual IntelliImage* getDeepCopy() override;
|
||||||
|
|
||||||
//sets the data for the visible image
|
//sets the data for the visible image
|
||||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ QImage IntelliShapedImage::getDisplayable(int alpha){
|
|||||||
return getDisplayable(imageData.size(),alpha);
|
return getDisplayable(imageData.size(),alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||||
|
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||||
|
shaped->setPolygon(this->polygonData);
|
||||||
|
shaped->imageData.fill(Qt::transparent);
|
||||||
|
return shaped;
|
||||||
|
}
|
||||||
|
|
||||||
void IntelliShapedImage::calculateVisiblity(){
|
void IntelliShapedImage::calculateVisiblity(){
|
||||||
if(polygonData.size()<=2){
|
if(polygonData.size()<=2){
|
||||||
QColor clr;
|
QColor clr;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include"Image/IntelliImage.h"
|
#include"Image/IntelliImage.h"
|
||||||
|
|
||||||
class IntelliShapedImage : public IntelliImage{
|
class IntelliShapedImage : public IntelliImage{
|
||||||
|
friend IntelliTool;
|
||||||
protected:
|
protected:
|
||||||
virtual void calculateVisiblity() override;
|
virtual void calculateVisiblity() override;
|
||||||
std::vector<QPoint> polygonData;
|
std::vector<QPoint> polygonData;
|
||||||
@@ -16,6 +16,9 @@ public:
|
|||||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
|
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
|
||||||
virtual QImage getDisplayable(int alpha=255) override;
|
virtual QImage getDisplayable(int alpha=255) override;
|
||||||
|
|
||||||
|
//gets a copy of the image !allocated
|
||||||
|
virtual IntelliImage* getDeepCopy() override;
|
||||||
|
|
||||||
//sets the data for the visible image
|
//sets the data for the visible image
|
||||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ SOURCES += \
|
|||||||
Image/IntelliShapedImage.cpp \
|
Image/IntelliShapedImage.cpp \
|
||||||
IntelliHelper/IntelliHelper.cpp \
|
IntelliHelper/IntelliHelper.cpp \
|
||||||
Layer/PaintingArea.cpp \
|
Layer/PaintingArea.cpp \
|
||||||
|
Tool/IntelliTool.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
|
|||||||
return static_cast<int>(layerBundle.size())-1;
|
return static_cast<int>(layerBundle.size())-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PaintingArea::deleteLayer(int index){
|
void PaintingArea::deleteLayer(int index){
|
||||||
if(index<static_cast<int>(layerBundle.size())){
|
if(index<static_cast<int>(layerBundle.size())){
|
||||||
this->layerBundle.erase(layerBundle.begin()+index);
|
this->layerBundle.erase(layerBundle.begin()+index);
|
||||||
@@ -217,6 +218,7 @@ void PaintingArea::activateLowerLayer(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PaintingArea::assembleLayers(bool forSaving){
|
void PaintingArea::assembleLayers(bool forSaving){
|
||||||
if(forSaving){
|
if(forSaving){
|
||||||
Canvas->fill(Qt::GlobalColor::transparent);
|
Canvas->fill(Qt::GlobalColor::transparent);
|
||||||
@@ -251,3 +253,16 @@ void PaintingArea::assembleLayers(bool forSaving){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaintingArea::createTempLayerAfter(int idx){
|
||||||
|
if(idx>=0){
|
||||||
|
LayerObject newLayer;
|
||||||
|
newLayer.alpha = layerBundle[idx].alpha;
|
||||||
|
newLayer.hight = layerBundle[idx].hight;
|
||||||
|
newLayer.width = layerBundle[idx].width;
|
||||||
|
newLayer.hightOffset = layerBundle[idx].hightOffset;
|
||||||
|
newLayer.widthOffset = layerBundle[idx].widthOffset;
|
||||||
|
newLayer.image = layerBundle[idx].image->getDeepCopy();
|
||||||
|
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include"Image/IntelliImage.h"
|
#include"Image/IntelliImage.h"
|
||||||
|
#include"Tool/IntelliTool.h"
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
|
||||||
struct LayerObject{
|
struct LayerObject{
|
||||||
IntelliImage* image;
|
IntelliImage* image;
|
||||||
int width;
|
int width;
|
||||||
@@ -16,6 +18,8 @@ struct LayerObject{
|
|||||||
int widthOffset;
|
int widthOffset;
|
||||||
int hightOffset;
|
int hightOffset;
|
||||||
int alpha=255;
|
int alpha=255;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PaintingArea : public QWidget
|
class PaintingArea : public QWidget
|
||||||
@@ -24,7 +28,7 @@ class PaintingArea : public QWidget
|
|||||||
// for all Qt objects
|
// for all Qt objects
|
||||||
// QObjects handle events
|
// QObjects handle events
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
friend IntelliTool;
|
||||||
public:
|
public:
|
||||||
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr);
|
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr);
|
||||||
|
|
||||||
@@ -33,6 +37,7 @@ public:
|
|||||||
bool save(const QString &fileName, const char *fileFormat);
|
bool save(const QString &fileName, const char *fileFormat);
|
||||||
|
|
||||||
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
|
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
|
||||||
|
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image);
|
||||||
void deleteLayer(int index);
|
void deleteLayer(int index);
|
||||||
void setLayerToActive(int index);
|
void setLayerToActive(int index);
|
||||||
void setAlphaOfLayer(int index, int alpha);
|
void setAlphaOfLayer(int index, int alpha);
|
||||||
@@ -43,6 +48,7 @@ public:
|
|||||||
// Has the image been modified since last save
|
// Has the image been modified since last save
|
||||||
bool isModified() const { return modified; }
|
bool isModified() const { return modified; }
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
// Events to handle
|
// Events to handle
|
||||||
@@ -66,6 +72,7 @@ private:
|
|||||||
void activateUpperLayer();
|
void activateUpperLayer();
|
||||||
void activateLowerLayer();
|
void activateLowerLayer();
|
||||||
|
|
||||||
|
|
||||||
QImage* Canvas;
|
QImage* Canvas;
|
||||||
int maxWidth;
|
int maxWidth;
|
||||||
int maxHeight;
|
int maxHeight;
|
||||||
@@ -80,6 +87,9 @@ private:
|
|||||||
// Will be marked true or false depending on if
|
// Will be marked true or false depending on if
|
||||||
// we have saved after a change
|
// we have saved after a change
|
||||||
bool modified=false;
|
bool modified=false;
|
||||||
|
|
||||||
|
//Helper for Tool
|
||||||
|
void createTempLayerAfter(int idx);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
74
src/Painting/Tool/IntelliTool.cpp
Normal file
74
src/Painting/Tool/IntelliTool.cpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#include"IntelliTool.h"
|
||||||
|
#include"Layer/PaintingArea.h"
|
||||||
|
|
||||||
|
IntelliTool::IntelliTool(PaintingArea* Area){
|
||||||
|
this->Area=Area;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IntelliTool::~IntelliTool(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IntelliTool::onMouseRightPressed(int x, int y){
|
||||||
|
this->drawing=true;
|
||||||
|
//create drawing layer
|
||||||
|
this->createToolLayer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliTool::onMouseRightReleased(int x, int y){
|
||||||
|
if(drawing){
|
||||||
|
drawing=false;
|
||||||
|
this->mergeToolLayer();
|
||||||
|
this->deleteToolLayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliTool::onMouseLeftPressed(int x, int y){
|
||||||
|
if(drawing){
|
||||||
|
drawing=false;
|
||||||
|
this->deleteToolLayer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||||
|
//optional for tool
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliTool::onMouseMoved(int x, int y){
|
||||||
|
//optional for tool
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,18 +1,30 @@
|
|||||||
#ifndef Intelli_Tool_H
|
#ifndef Intelli_Tool_H
|
||||||
#define Intelli_Tool_H
|
#define Intelli_Tool_H
|
||||||
|
|
||||||
#include"Layer/PaintingArea.h"
|
#include<vector>
|
||||||
|
|
||||||
|
class LayerObject;
|
||||||
|
class PaintingArea;
|
||||||
|
|
||||||
class IntelliTool{
|
class IntelliTool{
|
||||||
private:
|
private:
|
||||||
LayerObject* DataValue;
|
void createToolLayer();
|
||||||
LayerObject* Preview;
|
void mergeToolLayer();
|
||||||
|
void deleteToolLayer();
|
||||||
|
protected:
|
||||||
|
PaintingArea* Area;
|
||||||
|
LayerObject* Active;
|
||||||
|
LayerObject* Canvas;
|
||||||
|
bool drawing = false;
|
||||||
public:
|
public:
|
||||||
IntelliTool(LayerObject* DataValue, LayerObject* Preview);
|
IntelliTool(PaintingArea* Area);
|
||||||
virtual ~IntelliTool() = 0;
|
virtual ~IntelliTool() = 0;
|
||||||
|
|
||||||
virtual void onMousePressed(QMouseEvent *event) = 0;
|
virtual void onMouseRightPressed(int x, int y);
|
||||||
virtual void onMouseMoved(QMouseEvent* event)=0;
|
virtual void onMouseRightReleased(int x, int y);
|
||||||
virtual void onMouseReleased(QMouseEvent* event)=0;
|
virtual void onMouseLeftPressed(int x, int y);
|
||||||
|
virtual void onMouseLeftReleased(int x, int y);
|
||||||
|
|
||||||
|
virtual void onMouseMoved(int x, int y);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user