IntelliPhoto  0.5
IntelliTool.cpp
Go to the documentation of this file.
1 #include "IntelliTool.h"
2 #include "Layer/PaintingArea.h"
3 
5  this->Area = Area;
6  this->colorPicker = colorPicker;
7  this->Toolsettings = Toolsettings;
8  this->isDrawing = false;
10  this->activeLayer = nullptr;
11  this->Canvas = nullptr;
12 }
13 
15 
16 }
17 
19  if(isDrawing) {
20  isDrawing = false;
21  this->deleteToolLayer();
22  }
23 }
24 
26  //optional for tool
27 }
28 
30  this->isDrawing = this->createToolLayer();
31  if(isDrawing) {
33  }
34 }
35 
37  if(isDrawing) {
38  isDrawing = false;
39  this->mergeToolLayer();
40  this->deleteToolLayer();
42 
43  }
44 }
45 
46 void IntelliTool::onMouseMoved(int x, int y){
47  if(isDrawing)
49 }
50 
52  //if needed for future general tasks implement in here
53  Area->DummyGui->setToolWidth(value + Toolsettings->getLineWidth());
54 }
55 
56 bool IntelliTool::createToolLayer(){
57  if(Area->createTempTopLayer(Area->activeLayer)) {
58  this->activeLayer = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
59  this->Canvas = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer + 1)];
60  return true;
61  }
62  return false;
63 }
64 
65 void IntelliTool::mergeToolLayer(){
66  QColor clr_0;
67  QColor clr_1;
68  QImage updatedImage = activeLayer->image->getImageData();
69 
70  for(int y = 0; y<activeLayer->height; y++) {
71  for(int x = 0; x<activeLayer->width; x++) {
72  clr_0 = updatedImage.pixelColor(x,y);
73  clr_1 = Canvas->image->imageData.pixelColor(x,y);
74  float t = static_cast<float>(clr_1.alpha()) / 255.f;
75  int r = static_cast<int>(static_cast<float>(clr_1.red()) * (t) + static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
76  int g = static_cast<int>(static_cast<float>(clr_1.green()) * (t) + static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
77  int b = static_cast<int>(static_cast<float>(clr_1.blue()) * (t) + static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
78  int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
79  clr_0.setRed(r);
80  clr_0.setGreen(g);
81  clr_0.setBlue(b);
82  clr_0.setAlpha(a);
83 
84  updatedImage.setPixelColor(x, y, clr_0);
85  }
86  }
87  activeLayer->image->setImageData(updatedImage);
88  if(Canvas->image->getPolygonData().size() > 0) {
90  }
91  Area->DummyGui->UpdateGui();
92 }
93 
94 void IntelliTool::deleteToolLayer(){
95  Area->deleteLayer(Area->activeLayer + 1, true);
96  this->Canvas = nullptr;
97 }
98 
100  return ActiveType;
101 }
102 
104  return isDrawing;
105 }
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:18
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:36
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:29
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:59
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:81
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:53
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:134
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:25
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::getTooltype
Tooltype getTooltype()
Definition: IntelliTool.cpp:99
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
IntelliImage::getImageData
virtual QImage getImageData()
getImageData returns the data of the current image (Note: It will allways return a ARGB32bit QImage!...
Definition: IntelliImage.cpp:134
IntelliImage::setImageData
virtual void setImageData(const QImage &newData)
setImageData overwrites the old imageData the new imageData.
Definition: IntelliImage.cpp:142
IntelliPhotoGui::setToolWidth
void setToolWidth(int value)
Definition: IntelliPhotoGui.cpp:827
IntelliTool::getIsDrawing
bool getIsDrawing()
Definition: IntelliTool.cpp:103
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:4
IntelliPhotoGui::UpdateGui
void UpdateGui()
Definition: IntelliPhotoGui.cpp:836
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
IntelliToolsettings::getLineWidth
int getLineWidth()
Definition: IntelliToolsettings.cpp:14
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:46
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:51
IntelliToolsettings
Definition: IntelliToolsettings.h:7
IntelliTool::~IntelliTool
virtual ~IntelliTool()=0
An abstract Destructor.
Definition: IntelliTool.cpp:14
IntelliImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData)=0
An abstract function that sets the data of the visible Polygon, if needed.