IntelliPhoto  0.4
IntelliToolPolygon.cpp
Go to the documentation of this file.
1 #include "IntelliToolPolygon.h"
2 #include "Layer/PaintingArea.h"
3 #include <QDebug>
4 #include <QCursor>
5 
7  :IntelliTool(Area, colorPicker){
8  lineWidth = 5;
9  isDrawing = false;
10  PointIsNearStart = false;
11  drawingPoint.setX(0);
12  drawingPoint.setY(0);
13  Point.setX(0);
14  Point.setY(0);
15 }
16 
18  if(!isDrawing){
19  width = Area->getWidthActiveLayer();
20  height = Area->getHeightActiveLayer();
21  }
22  if(!isDrawing && x > 0 && y > 0 && x < width && y < height){
23  isDrawing = true;
24  drawingPoint.setX(x);
25  drawingPoint.setY(y);
26  QPointList.push_back(drawingPoint);
28  this->Canvas->image->drawPlain(Qt::transparent);
29  this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
31  }
32  else if(isDrawing && isNearStart(x,y,QPointList.front())){
33  PointIsNearStart = isNearStart(x,y,QPointList.front());
34  this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
36  }
37  else if(isDrawing){
38  drawingPoint.setX(x);
39  drawingPoint.setY(y);
40  QPointList.push_back(drawingPoint);
41  this->Canvas->image->drawLine(QPointList.operator[](QPointList.size() - 2), QPointList.back(), colorPicker->getFirstColor(), lineWidth);
43  }
44 }
45 
47  isDrawing = false;
48  PointIsNearStart = false;
49  QPointList.clear();
51 }
52 
54  if(PointIsNearStart && QPointList.size() > 1){
56  PointIsNearStart = false;
57  isDrawing = false;
58  Triangles = IntelliHelper::calculateTriangles(QPointList);
59  for(int i = 0; i < width; i++){
60  for(int j = 0; j < height; j++){
61  Point.setX(i);
62  Point.setY(j);
63  if(IntelliHelper::isInPolygon(Triangles,Point)){
64  this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor());
65  }
66  }
67  }
68  QPointList.clear();
70  }
71 }
72 
74 
75 }
76 
78  if(!isDrawing){
79  if(lineWidth + value < 10){
80  lineWidth += value;
81  }
82  if(lineWidth < 1){
83  lineWidth = 1;
84  }
85  }
86 }
87 
89 
90 }
91 
92 bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
93  bool isNear = false;
94  int StartX = Startpoint.x();
95  int StartY = Startpoint.y();
96  int valueToNear = 10;
97 
98  for(int i = StartX - valueToNear; i < StartX + valueToNear; i++){
99  for(int j = StartY - valueToNear; j < StartY + valueToNear; j++){
100  if((i == x) && (j == y)){
101  isNear = true;
102  }
103  }
104  }
105  return isNear;
106 }
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
PaintingArea::getWidthActiveLayer
int getWidthActiveLayer()
Definition: PaintingArea.cpp:197
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:38
IntelliImage::drawLine
virtual void drawLine(const QPoint &p1, const QPoint &p2, const QColor &color, const int &penWidth)
A function that draws A Line between two given Points in a given color.
Definition: IntelliImage.cpp:65
IntelliToolPolygon.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
IntelliImage::drawPixel
virtual void drawPixel(const QPoint &p1, const QColor &color)
A funtcion used to draw a pixel on the Image with the given Color.
Definition: IntelliImage.cpp:44
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:33
PaintingArea::getHeightActiveLayer
int getHeightActiveLayer()
Definition: PaintingArea.cpp:201
IntelliToolPolygon::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliToolPolygon.cpp:88
PaintingArea
Definition: PaintingArea.h:25
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:55
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:48
IntelliTool
An abstract class that manages the basic events, like mouse clicks or scrolls events.
Definition: IntelliTool.h:13
IntelliHelper::isInPolygon
bool isInPolygon(std::vector< Triangle > &triangles, QPoint &point)
A function to check if a point lies in a polygon by checking its spanning triangles.
Definition: IntelliHelper.cpp:115
IntelliToolPolygon::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y) override
A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on....
Definition: IntelliToolPolygon.cpp:46
PaintingArea.h
IntelliColorPicker::getFirstColor
QColor getFirstColor()
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:16
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliHelper::calculateTriangles
std::vector< Triangle > calculateTriangles(std::vector< QPoint > polyPoints)
A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by ...
Definition: IntelliHelper.cpp:7
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:17
IntelliToolPolygon::IntelliToolPolygon
IntelliToolPolygon(PaintingArea *Area, IntelliColorPicker *colorPicker)
IntelliToolPolygon Constructor Define the Tool-intern Parameters.
Definition: IntelliToolPolygon.cpp:6
IntelliToolPolygon::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y) override
A function managing the left click Pressed of a Mouse. Resetting the current draw....
Definition: IntelliToolPolygon.cpp:17
IntelliToolPolygon::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click Released of a Mouse. Merging the Canvas to Active....
Definition: IntelliToolPolygon.cpp:73
IntelliToolPolygon::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click Released of a Mouse. Call this in child classes!
Definition: IntelliToolPolygon.cpp:53
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
IntelliToolPolygon::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event. A positive value means scrolling outwards. Call this in child c...
Definition: IntelliToolPolygon.cpp:77
IntelliImage::drawPlain
virtual void drawPlain(const QColor &color)
A function that clears the whole image in a given Color.
Definition: IntelliImage.cpp:76