IntelliPhoto  0.5
IntelliToolPolygon.cpp
Go to the documentation of this file.
1 #include "IntelliToolPolygon.h"
2 #include "Layer/PaintingArea.h"
3 #include <QCursor>
4 #include <QInputDialog>
5 #include <QDebug>
6 
7 IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon)
8  : IntelliTool(Area, colorPicker, Toolsettings){
9  isPointNearStart = false;
10  drawingOfPolygon = false;
11  isInside = false;
12  this->isSettingPolygon = isSettingPolygon;
13  if(isSettingPolygon) {
15  }
17 }
18 
20  if(drawingOfPolygon) {
22  }
23 }
24 
26  if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
27  if(Area->getPolygonDataOfRealLayer().size()>2) {
28  std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
29  QPoint Point(x,y);
30  isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
31  }
32  else{
33  isInside = true;
34  }
35  if(isSettingPolygon) {
36  isInside = true;
37  }
38  }
39  else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
40  isInside = true;
41  }
42 
43  if(isInside && !drawingOfPolygon) {
45  QPoint drawingPoint = QPoint(x,y);
46 
47  drawingOfPolygon = true;
48  QPointList.push_back(drawingPoint);
49 
50  this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
51  if(!isSettingPolygon) {
53  }
54  }
55  else if(drawingOfPolygon && QPointList.size() > 0 && isNearStart(x,y,QPointList.front())) {
56  if(QPointList.size() > 2) {
57  isPointNearStart = true;
58  this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
59  if(!isSettingPolygon) {
61  }
62  }
63  else{
64  isInside = false;
65  drawingOfPolygon = false;
66  QPointList.clear();
69  }
70 
71  }
72  else if(drawingOfPolygon) {
73  QPoint drawingPoint(x,y);
74  QPointList.push_back(drawingPoint);
75  this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
76  if(!isSettingPolygon) {
78  }
79  }
80 }
81 
83  drawingOfPolygon = false;
84  isInside = false;
85  isPointNearStart = false;
86  QPointList.clear();
88 }
89 
91  if(isPointNearStart) {
92  isInside = false;
93  isPointNearStart = false;
94  drawingOfPolygon = false;
95  if(!isSettingPolygon) {
96  std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
97  QPoint Point;
98  QColor colorTwo(colorPicker->getSecondColor());
99  colorTwo.setAlpha(Toolsettings->getInnerAlpha());
100  for(int i = 0; i < activeLayer->width; i++) {
101  for(int j = 0; j < activeLayer->height; j++) {
102  Point = QPoint(i,j);
103  if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
104  this->Canvas->image->drawPixel(Point, colorTwo);
105  }
106  }
107  }
108  for(int i = 0; i<static_cast<int>(QPointList.size()); i++) {
109  int next = static_cast<int>((i + static_cast<int>(1)) % static_cast<int>(QPointList.size()));
110  this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
111  }
112 
113  }
114  else{
115  Canvas->image->setPolygon(QPointList);
117  }
119  QPointList.clear();
120  }
121 }
122 
125 }
126 
128  if(!isSettingPolygon) {
130  if(!isDrawing) {
132  }
133  }
134 }
135 
137  if(!isSettingPolygon) {
139  }
140 }
141 
142 bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
143  int StartX = Startpoint.x();
144  int StartY = Startpoint.y();
145  int valueToNear = 5;
146 
147  float euklid = sqrt(pow(static_cast<float>(StartX-x),2.f)+pow(static_cast<float>(StartY-y),2.f));
148 
149  return static_cast<int>(euklid)<valueToNear;
150 }
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:56
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:96
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:26
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:58
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:57
IntelliTriangulation::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: IntelliTriangulation.cpp:7
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:49
IntelliColorPicker::getSecondColor
QColor getSecondColor()
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:20
IntelliToolPolygon::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event.
Definition: IntelliToolPolygon.cpp:136
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:73
IntelliToolsettings::getInnerAlpha
int getInnerAlpha()
Definition: IntelliToolsettings.cpp:28
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A function that draws a point between on a given point in a given color.
Definition: IntelliImage.cpp:77
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:63
IntelliToolPolygon::IntelliToolPolygon
IntelliToolPolygon(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings, bool isSettingPolygon=false)
A constructor setting the general paintingArea and colorPicker.
Definition: IntelliToolPolygon.cpp:7
IntelliTool::Tooltype::POLYGON
@ POLYGON
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:68
PaintingArea::getTypeOfImageRealLayer
IntelliImage::ImageType getTypeOfImageRealLayer()
Definition: PaintingArea.cpp:251
LayerObject::width
int width
width - Stores the width of a layer in pixels.
Definition: PaintingArea.h:31
IntelliTool
An abstract class that manages the basic events, like mouse clicks or scrolls events.
Definition: IntelliTool.h:17
IntelliImage::ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
IntelliImage::setImageData
virtual void setImageData(const QImage &newData)
setImageData overwrites the old imageData the new imageData.
Definition: IntelliImage.cpp:142
IntelliTriangulation::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: IntelliTriangulation.cpp:116
IntelliToolPolygon::onMouseRightPressed
virtual void onMouseRightPressed(int x, int y) override
A function managing the right click pressed of a mouse. Resetting the current fill.
Definition: IntelliToolPolygon.cpp:82
PaintingArea.h
IntelliColorPicker::getFirstColor
QColor getFirstColor()
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:16
LayerObject::height
int height
height - Stores the height of a layer in pixels.
Definition: PaintingArea.h:35
PaintingArea::getImageDataOfActiveLayer
QImage getImageDataOfActiveLayer()
getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer ...
Definition: PaintingArea.cpp:434
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:51
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:14
IntelliToolPolygon::~IntelliToolPolygon
~IntelliToolPolygon() override
A Destructor.
Definition: IntelliToolPolygon.cpp:19
IntelliImage::ImageType::RASTERIMAGE
@ RASTERIMAGE
LayerObject::image
IntelliImage * image
image - Stores the imageData of the current LayerObject.
Definition: PaintingArea.h:27
PaintingArea::getPolygonDataOfRealLayer
std::vector< QPoint > getPolygonDataOfRealLayer()
Definition: PaintingArea.cpp:255
IntelliToolsettings::setLineWidth
void setLineWidth(int LineWidth)
Definition: IntelliToolsettings.cpp:18
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
IntelliToolPolygon::onMouseLeftPressed
virtual void onMouseLeftPressed(int x, int y) override
A function managing the left click pressed of a mouse. Setting polygon points.
Definition: IntelliToolPolygon.cpp:25
IntelliToolPolygon::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolPolygon.cpp:123
IntelliToolPolygon::onMouseLeftReleased
virtual void onMouseLeftReleased(int x, int y) override
A function managing the left click released of a mouse. Merging the fill to the active layer.
Definition: IntelliToolPolygon.cpp:90
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:7
IntelliToolPolygon::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event. CHanging the lineWidth relative to value.
Definition: IntelliToolPolygon.cpp:127
IntelliImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData)=0
An abstract function that sets the data of the visible Polygon, if needed.