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 }
9 
10 
12 
13 }
14 
16  if(isDrawing) {
17  isDrawing = false;
18  this->deleteToolLayer();
19  }
20 }
21 
23  //optional for tool
24 }
25 
27  this->isDrawing = this->createToolLayer();
28  if(isDrawing) {
30  }
31 }
32 
34  if(isDrawing) {
35  isDrawing = false;
36  this->mergeToolLayer();
37  this->deleteToolLayer();
39 
40  }
41 }
42 
43 void IntelliTool::onMouseMoved(int x, int y){
44  if(isDrawing)
46 }
47 
49  //if needed for future general tasks implement in here
50  Area->DummyGui->setToolWidth(value + Toolsettings->getLineWidth());
51 }
52 
53 bool IntelliTool::createToolLayer(){
54  if(Area->createTempTopLayer(Area->activeLayer)) {
55  this->activeLayer = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
56  this->Canvas = &Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer + 1)];
57  return true;
58  }
59  return false;
60 }
61 
62 void IntelliTool::mergeToolLayer(){
63  QColor clr_0;
64  QColor clr_1;
65  QImage updatedImage = activeLayer->image->getImageData();
66 
67  for(int y = 0; y<activeLayer->height; y++) {
68  for(int x = 0; x<activeLayer->width; x++) {
69  clr_0 = updatedImage.pixelColor(x,y);
70  clr_1 = Canvas->image->imageData.pixelColor(x,y);
71  float t = static_cast<float>(clr_1.alpha()) / 255.f;
72  int r = static_cast<int>(static_cast<float>(clr_1.red()) * (t) + static_cast<float>(clr_0.red()) * (1.f - t) + 0.5f);
73  int g = static_cast<int>(static_cast<float>(clr_1.green()) * (t) + static_cast<float>(clr_0.green()) * (1.f - t) + 0.5f);
74  int b = static_cast<int>(static_cast<float>(clr_1.blue()) * (t) + static_cast<float>(clr_0.blue() * (1.f - t)) + 0.5f);
75  int a = std::min(clr_0.alpha() + clr_1.alpha(), 255);
76  clr_0.setRed(r);
77  clr_0.setGreen(g);
78  clr_0.setBlue(b);
79  clr_0.setAlpha(a);
80 
81  updatedImage.setPixelColor(x, y, clr_0);
82  }
83  }
84  activeLayer->image->setImageData(updatedImage);
85  if(Canvas->image->getPolygonData().size() > 0) {
87  }
88  Area->DummyGui->UpdateGui();
89 }
90 
91 void IntelliTool::deleteToolLayer(){
92  Area->deleteLayer(Area->activeLayer + 1, true);
93  this->Canvas = nullptr;
94 }
95 
97  return ActiveType;
98 }
99 
101  return isDrawing;
102 }
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:15
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:33
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:52
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:26
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:54
PaintingArea::deleteLayer
void deleteLayer(int idx, bool isTool=false)
The deleteLayer method removes a layer at a given idx.
Definition: PaintingArea.cpp:73
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:45
IntelliTool::Tooltype
Tooltype
Definition: IntelliTool.h:16
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:37
IntelliTool::isDrawing
bool isDrawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:69
IntelliImage::getPolygonData
virtual std::vector< QPoint > getPolygonData()
A function that returns the Polygondata if existent.
Definition: IntelliImage.h:130
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:22
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:59
IntelliTool::getTooltype
Tooltype getTooltype()
Definition: IntelliTool.cpp:96
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:64
LayerObject::width
int width
Definition: PaintingArea.h:27
IntelliImage::getImageData
virtual QImage getImageData()
getImageData returns the data of the current image (Note: It will allways return a ARGB32bit QImage!...
Definition: IntelliImage.cpp:125
IntelliImage::setImageData
virtual void setImageData(const QImage &newData)
setImageData overwrites the old imageData the new imageData.
Definition: IntelliImage.cpp:133
IntelliPhotoGui::setToolWidth
void setToolWidth(int value)
Definition: IntelliPhotoGui.cpp:790
IntelliTool::getIsDrawing
bool getIsDrawing()
Definition: IntelliTool.cpp:100
PaintingArea.h
LayerObject::height
int height
Definition: PaintingArea.h:28
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:47
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
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:799
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:37
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:26
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:43
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:48
IntelliToolsettings
Definition: IntelliToolsettings.h:4
IntelliTool::~IntelliTool
virtual ~IntelliTool()=0
An abstract Destructor.
Definition: IntelliTool.cpp:11
IntelliImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData)=0
An abstract function that sets the data of the visible Polygon, if needed.