IntelliTool.cpp
Go to the documentation of this file.
#include "IntelliTool.h"
#include "Layer/PaintingArea.h"
#include "GUI/IntelliPhotoGui.h"
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){
this->Area = Area;
this->colorPicker = colorPicker;
this->Toolsettings = Toolsettings;
this->isDrawing = false;
this->ActiveType = Tooltype::NONE;
this->activeLayer = nullptr;
this->Canvas = nullptr;
}
IntelliTool::~IntelliTool(){
}
void IntelliTool::onMouseRightPressed(int x, int y){
if(isDrawing) {
isDrawing = false;
this->deleteToolLayer();
}
}
void IntelliTool::onMouseRightReleased(int x, int y){
//optional for tool
}
void IntelliTool::onMouseLeftPressed(int x, int y){
this->isDrawing = this->createToolLayer();
if(isDrawing) {
Canvas->image->calculateVisiblity();
}
}
void IntelliTool::onMouseLeftReleased(int x, int y){
if(isDrawing) {
isDrawing = false;
this->mergeToolLayer();
this->deleteToolLayer();
activeLayer->image->calculateVisiblity();
Area->historyadd();
}
}
void IntelliTool::onMouseMoved(int x, int y){
if(isDrawing)
Canvas->image->calculateVisiblity();
}
void IntelliTool::onWheelScrolled(int value){
//if needed for future general tasks implement in here
Area->guiReference->setToolWidth(value + Toolsettings->getLineWidth());
}
bool IntelliTool::createToolLayer(){
if(Area->createTempTopLayer(Area->activeLayer)) {
this->activeLayer = &Area->layerBundle[static_cast<size_t>(Area->activeLayer)];
this->Canvas = &Area->layerBundle[static_cast<size_t>(Area->activeLayer + 1)];
return true;
}
return false;
}
void IntelliTool::mergeToolLayer(){
QColor clr_0;
QColor clr_1;
QImage updatedImage = activeLayer->image->getImageData();
for(int y = 0; y<activeLayer->height; y++) {
for(int x = 0; x<activeLayer->width; x++) {
clr_0 = updatedImage.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);
updatedImage.setPixelColor(x, y, clr_0);
}
}
activeLayer->image->setImageData(updatedImage);
if(Canvas->image->getPolygonData().size() > 0) {
activeLayer->image->setPolygon(Canvas->image->getPolygonData());
}
Area->guiReference->UpdateGui();
}
void IntelliTool::deleteToolLayer(){
Area->deleteLayer(Area->activeLayer + 1, true);
this->Canvas = nullptr;
}
IntelliTool::Tooltype IntelliTool::getTooltype() const {
return ActiveType;
}
bool IntelliTool::getIsDrawing() const {
return isDrawing;
}
IntelliTool::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y)
A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on....
Definition: IntelliTool.cpp:19
IntelliTool::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y)
A function managing the left click Released of a Mouse. Call this in child classes!
Definition: IntelliTool.cpp:37
IntelliToolsettings::getLineWidth
int getLineWidth() const
getLineWidth returns the width attribute of the line.
Definition: IntelliToolsettings.cpp:14
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:64
IntelliTool.h
IntelliTool::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y)
A function managing the left click Pressed of a Mouse. Resetting the current draw....
Definition: IntelliTool.cpp:30
IntelliTool::getIsDrawing
bool getIsDrawing() const
getIsDrawing returns if the tool is currently drawing
Definition: IntelliTool.cpp:105
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Toolsettings a refrence to the tool settings.
Definition: IntelliTool.h:69
IntelliTool::getTooltype
Tooltype getTooltype() const
getTooltype returns the tools type
Definition: IntelliTool.cpp:101
IntelliTool::Tooltype::NONE
@ NONE
PaintingArea::deleteLayer
void deleteLayer(int idx, bool isTool=false)
The deleteLayer method removes a layer at a given idx.
Definition: PaintingArea.cpp:113
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:54
IntelliTool::Tooltype
Tooltype
The Tooltype enum categorising the toosl.
Definition: IntelliTool.h:23
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:57
IntelliTool::isDrawing
bool isDrawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:84
IntelliImage::getPolygonData
virtual std::vector< QPoint > getPolygonData()
A function that returns the Polygondata if existent.
Definition: IntelliImage.h:135
IntelliTool::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y)
A function managing the right click Released of a Mouse. Merging the Canvas to Active....
Definition: IntelliTool.cpp:26
IntelliTool::activeLayer
LayerObject * activeLayer
A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or prev...
Definition: IntelliTool.h:74
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:79
LayerObject::width
int width
width - Stores the width of a layer in pixels.
Definition: PaintingArea.h:31
IntelliPhotoGui.h
IntelliImage::getImageData
virtual QImage getImageData()
getImageData returns the data of the current image (Note: It will allways return a ARGB32bit QImage!...
Definition: IntelliImage.cpp:135
IntelliImage::setImageData
virtual void setImageData(const QImage &newData)
setImageData overwrites the old imageData the new imageData.
Definition: IntelliImage.cpp:143
IntelliPhotoGui::setToolWidth
void setToolWidth(int value)
setToolWidth stes a width to the tool
Definition: IntelliPhotoGui.cpp:923
PaintingArea.h
LayerObject::height
int height
height - Stores the height of a layer in pixels.
Definition: PaintingArea.h:35
IntelliTool::ActiveType
Tooltype ActiveType
ActiveType the type of the active tool.
Definition: IntelliTool.h:59
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:14
IntelliTool::IntelliTool
IntelliTool(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings)
A constructor setting the general Painting Area and colorPicker.
Definition: IntelliTool.cpp:5
IntelliPhotoGui::UpdateGui
void UpdateGui()
UpdateGui a function to update all gui elements.
Definition: IntelliPhotoGui.cpp:932
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:41
LayerObject::image
IntelliImage * image
image - Stores the imageData of the current LayerObject.
Definition: PaintingArea.h:27
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:48
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
PaintingArea::historyadd
void historyadd()
historyadd adds an hisotry step
Definition: PaintingArea.cpp:512
IntelliTool::onWheelScrolled
virtual void onWheelScrolled(int value)
A function managing the scroll event. A positive value means scrolling outwards. Call this in child c...
Definition: IntelliTool.cpp:53
IntelliToolsettings
The IntelliToolsettings class managing the settings of the tools, independent of an existing tool.
Definition: IntelliToolsettings.h:9
IntelliTool::~IntelliTool
virtual ~IntelliTool()=0
An abstract Destructor.
Definition: IntelliTool.cpp:15
IntelliImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData)=0
An abstract function that sets the data of the visible Polygon, if needed.