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 }
8 
9 
11 
12 }
13 
15  if(drawing) {
16  drawing=false;
17  this->deleteToolLayer();
18  }
19 }
20 
22  //optional for tool
23 }
24 
26  this->drawing=true;
27  //create drawing layer
28  this->createToolLayer();
30 }
31 
33  if(drawing) {
34  drawing=false;
35  this->mergeToolLayer();
36  this->deleteToolLayer();
38  }
39 }
40 
41 void IntelliTool::onMouseMoved(int x, int y){
42  if(drawing)
44 }
45 
47  //if needed for future general tasks implement in here
48 }
49 
50 void IntelliTool::createToolLayer(){
51  Area->createTempLayerAfter(Area->activeLayer);
52  this->Active=&Area->layerBundle[Area->activeLayer];
53  this->Canvas=&Area->layerBundle[Area->activeLayer+1];
54 }
55 
56 void IntelliTool::mergeToolLayer(){
57  QColor clr_0;
58  QColor clr_1;
59  for(int y=0; y<Active->height; y++) {
60  for(int x=0; x<Active->width; x++) {
61  clr_0=Active->image->imageData.pixelColor(x,y);
62  clr_1=Canvas->image->imageData.pixelColor(x,y);
63  float t = static_cast<float>(clr_1.alpha())/255.f;
64  int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
65  int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
66  int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
67  int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
68  clr_0.setRed(r);
69  clr_0.setGreen(g);
70  clr_0.setBlue(b);
71  clr_0.setAlpha(a);
72 
73  Active->image->imageData.setPixelColor(x, y, clr_0);
74  }
75  }
76 }
77 
78 void IntelliTool::deleteToolLayer(){
79  Area->deleteLayer(Area->activeLayer+1);
80  this->Canvas=nullptr;
81 }
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:14
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:32
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:38
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:25
IntelliTool::IntelliTool
IntelliTool(PaintingArea *Area, IntelliColorPicker *colorPicker)
A constructor setting the general Painting Area and colorPicker.
Definition: IntelliTool.cpp:4
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:33
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:36
PaintingArea::deleteLayer
void deleteLayer(int index)
The deleteLayer method removes a layer at a given index.
Definition: PaintingArea.cpp:73
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:21
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:48
LayerObject::width
int width
Definition: PaintingArea.h:26
IntelliTool::drawing
bool drawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:53
PaintingArea.h
LayerObject::height
int height
Definition: PaintingArea.h:27
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:32
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:25
IntelliTool::Active
LayerObject * Active
A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or prev...
Definition: IntelliTool.h:43
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:41
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:46
IntelliTool::~IntelliTool
virtual ~IntelliTool()=0
An abstract Destructor.
Definition: IntelliTool.cpp:10