IntelliPhoto 0.6

IntelliTool.cpp
Go to the documentation of this file.
1 #include "IntelliTool.h"
2 #include "Layer/PaintingArea.h"
3 #include "GUI/IntelliPhotoGui.h"
4
5 IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){
6 this->Area = Area;
7 this->colorPicker = colorPicker;
8 this->Toolsettings = Toolsettings;
9 this->isDrawing = false;
10 this->ActiveType = Tooltype::NONE;
11 this->activeLayer = nullptr;
12 this->Canvas = nullptr;
13 }
14
15 IntelliTool::~IntelliTool(){
16
17 }
18
19 void IntelliTool::onMouseRightPressed(int x, int y){
20 if(isDrawing) {
21 isDrawing = false;
22 this->deleteToolLayer();
23 }
24 }
25
26 void IntelliTool::onMouseRightReleased(int x, int y){
27 //optional for tool
28 }
29
30 void IntelliTool::onMouseLeftPressed(int x, int y){
31 this->isDrawing = this->createToolLayer();
32 if(isDrawing) {
33 Canvas->image->calculateVisiblity();
34 }
35 }
36
37 void IntelliTool::onMouseLeftReleased(int x, int y){
38 if(isDrawing) {
39 isDrawing = false;
40 this->mergeToolLayer();
41 this->deleteToolLayer();
42 activeLayer->image->calculateVisiblity();
43
44 }
45 }
46
47 void IntelliTool::onMouseMoved(int x, int y){
48 if(isDrawing)
49 Canvas->image->calculateVisiblity();
50 }
51
52 void IntelliTool::onWheelScrolled(int value){
53 //if needed for future general tasks implement in here
54 Area->guiReference->setToolWidth(value + Toolsettings->getLineWidth());
55 }
56
57 bool IntelliTool::createToolLayer(){
58 if(Area->createTempTopLayer(Area->activeLayer)) {
59 this->activeLayer = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
60 this->Canvas = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer + 1)];
61 return true;
62 }
63 return false;
64 }
65
66 void IntelliTool::mergeToolLayer(){
67 QColor clr_0;
68 QColor clr_1;
69 QImage updatedImage = activeLayer->image->getImageData();
70
71 for(int y = 0; y<activeLayer->height; y++) {
72 for(int x = 0; x<activeLayer->width; x++) {
73 clr_0 = updatedImage.pixelColor(x,y);
74 clr_1 = Canvas->image->imageData.pixelColor(x,y);
75 float t = static_cast<float>(clr_1.alpha()) / 255.f;
76 int r = static_cast<int>(static_cast<float>(clr_1.red()) * (t) + static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
77 int g = static_cast<int>(static_cast<float>(clr_1.green()) * (t) + static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
78 int b = static_cast<int>(static_cast<float>(clr_1.blue()) * (t) + static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
79 int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
80 clr_0.setRed(r);
81 clr_0.setGreen(g);
82 clr_0.setBlue(b);
83 clr_0.setAlpha(a);
84
85 updatedImage.setPixelColor(x, y, clr_0);
86 }
87 }
88 activeLayer->image->setImageData(updatedImage);
89 if(Canvas->image->getPolygonData().size() > 0) {
90 activeLayer->image->setPolygon(Canvas->image->getPolygonData());
91 }
92 Area->guiReference->UpdateGui();
93 Area->historyadd();
94 }
95
96 void IntelliTool::deleteToolLayer(){
97 Area->deleteLayer(Area->activeLayer + 1, true);
98 this->Canvas = nullptr;
99 }
100
101 IntelliTool::Tooltype IntelliTool::getTooltype() const {
102 return ActiveType;
103 }
104
105 bool IntelliTool::getIsDrawing() const {
106 return isDrawing;
107 }
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
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:57
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
Definition: IntelliTool.cpp:105
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:59
IntelliTool::getTooltype
Tooltype getTooltype() const
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:114
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:50
IntelliTool::Tooltype
Tooltype
Definition: IntelliTool.h:20
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:74
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:64
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:69
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)
Definition: IntelliPhotoGui.cpp:886
PaintingArea.h
LayerObject::height
int height
height - Stores the height of a layer in pixels.
Definition: PaintingArea.h:35
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:52
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()
Definition: IntelliPhotoGui.cpp:895
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:47
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
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:52
IntelliToolsettings
Definition: IntelliToolsettings.h:7
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.