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  isDrawing = false;
11  isInside = false;
12  this->isSettingPolygon = isSettingPolygon;
13  if(isSettingPolygon) {
15  }
17 }
18 
20  if(isDrawing) {
22  }
23 }
24 
26  if(!isDrawing && 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(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
40  isInside = true;
41  }
42 
43  if(isInside && !isDrawing) {
45  QPoint drawingPoint = QPoint(x,y);
46 
47  isDrawing = 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(isDrawing && 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  isDrawing = false;
66  QPointList.clear();
68  }
69 
70  }
71  else if(isDrawing) {
72  QPoint drawingPoint(x,y);
73  QPointList.push_back(drawingPoint);
74  this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
75  if(!isSettingPolygon) {
77  }
78  }
79 }
80 
82  isInside = false;
83  isDrawing = false;
84  isPointNearStart = false;
85  QPointList.clear();
87 }
88 
90  if(isPointNearStart) {
91  isInside = false;
92  isPointNearStart = false;
93  isDrawing = false;
94  if(!isSettingPolygon) {
95  std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
96  QPoint Point;
97  QColor colorTwo(colorPicker->getSecondColor());
98  colorTwo.setAlpha(Toolsettings->getInnerAlpha());
99  for(int i = 0; i < activeLayer->width; i++) {
100  for(int j = 0; j < activeLayer->height; j++) {
101  Point = QPoint(i,j);
102  if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
103  this->Canvas->image->drawPixel(Point, colorTwo);
104  }
105  }
106  }
107  for(int i = 0; i<static_cast<int>(QPointList.size()); i++) {
108  int next = static_cast<int>((i + static_cast<int>(1)) % static_cast<int>(QPointList.size()));
109  this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
110  }
111 
112  }
113  else{
114  Canvas->image->setPolygon(QPointList);
116  }
118  QPointList.clear();
119  }
120 }
121 
124 }
125 
127  if(!isSettingPolygon) {
129  if(!isDrawing) {
131  }
132  }
133 }
134 
136  if(!isSettingPolygon) {
138  }
139 }
140 
141 bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
142  bool isNear = false;
143  int StartX = Startpoint.x();
144  int StartY = Startpoint.y();
145  int valueToNear = 5;
146 
147  for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) {
148  for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) {
149  if((i == x) && (j == y)) {
150  isNear = true;
151  }
152  }
153  }
154  return isNear;
155 }
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
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:90
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:54
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:45
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:135
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:37
IntelliToolsettings::getInnerAlpha
int getInnerAlpha()
Definition: IntelliToolsettings.cpp:28
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:74
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
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:64
PaintingArea::getTypeOfImageRealLayer
IntelliImage::ImageType getTypeOfImageRealLayer()
Definition: PaintingArea.cpp:241
LayerObject::width
int width
Definition: PaintingArea.h:27
IntelliTool
An abstract class that manages the basic events, like mouse clicks or scrolls events.
Definition: IntelliTool.h:14
IntelliImage::ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
IntelliImage::setImageData
virtual void setImageData(const QImage &newData)
setImageData overwrites the old imageData the new imageData.
Definition: IntelliImage.cpp:133
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:81
PaintingArea.h
IntelliColorPicker::getFirstColor
QColor getFirstColor()
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:16
LayerObject::height
int height
Definition: PaintingArea.h:28
PaintingArea::getImageDataOfActiveLayer
QImage getImageDataOfActiveLayer()
getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer ...
Definition: PaintingArea.cpp:424
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:47
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliToolPolygon::~IntelliToolPolygon
~IntelliToolPolygon() override
A Destructor.
Definition: IntelliToolPolygon.cpp:19
IntelliImage::ImageType::RASTERIMAGE
@ RASTERIMAGE
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:26
PaintingArea::getPolygonDataOfRealLayer
std::vector< QPoint > getPolygonDataOfRealLayer()
Definition: PaintingArea.cpp:245
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:122
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:89
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
IntelliToolPolygon::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event. CHanging the lineWidth relative to value.
Definition: IntelliToolPolygon.cpp:126
IntelliImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData)=0
An abstract function that sets the data of the visible Polygon, if needed.