IntelliPhoto  1
IntelliTool.cpp
Go to the documentation of this file.
1 #include "IntelliTool.h"
2 #include "Layer/PaintingArea.h"
3 #include "GUI/IntelliPhotoGui.h"
4 
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 
16 
17 }
18 
20  if(isDrawing) {
21  isDrawing = false;
22  this->deleteToolLayer();
23  }
24 }
25 
27  //optional for tool
28 }
29 
31  this->isDrawing = this->createToolLayer();
32  if(isDrawing) {
34  }
35 }
36 
38  if(isDrawing) {
39  isDrawing = false;
40  this->mergeToolLayer();
41  this->deleteToolLayer();
43  Area->historyadd();
44 
45  }
46 }
47 
48 void IntelliTool::onMouseMoved(int x, int y){
49  if(isDrawing)
51 }
52 
54  //if needed for future general tasks implement in here
55  Area->guiReference->setToolWidth(value + Toolsettings->getLineWidth());
56 }
57 
58 bool IntelliTool::createToolLayer(){
59  if(Area->createTempTopLayer(Area->activeLayer)) {
60  this->activeLayer = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
61  this->Canvas = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer + 1)];
62  return true;
63  }
64  return false;
65 }
66 
67 void IntelliTool::mergeToolLayer(){
68  QColor clr_0;
69  QColor clr_1;
70  QImage updatedImage = activeLayer->image->getImageData();
71 
72  for(int y = 0; y<activeLayer->height; y++) {
73  for(int x = 0; x<activeLayer->width; x++) {
74  clr_0 = updatedImage.pixelColor(x,y);
75  clr_1 = Canvas->image->imageData.pixelColor(x,y);
76  float t = static_cast<float>(clr_1.alpha()) / 255.f;
77  int r = static_cast<int>(static_cast<float>(clr_1.red()) * (t) + static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
78  int g = static_cast<int>(static_cast<float>(clr_1.green()) * (t) + static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
79  int b = static_cast<int>(static_cast<float>(clr_1.blue()) * (t) + static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
80  int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
81  clr_0.setRed(r);
82  clr_0.setGreen(g);
83  clr_0.setBlue(b);
84  clr_0.setAlpha(a);
85 
86  updatedImage.setPixelColor(x, y, clr_0);
87  }
88  }
89  activeLayer->image->setImageData(updatedImage);
90  if(Canvas->image->getPolygonData().size() > 0) {
92  }
93  Area->guiReference->UpdateGui();
94 }
95 
96 void IntelliTool::deleteToolLayer(){
97  Area->deleteLayer(Area->activeLayer + 1, true);
98  this->Canvas = nullptr;
99 }
100 
102  return ActiveType;
103 }
104 
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
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:510
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.