IntelliPhoto  0.6
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 #include <cmath>
7 
8 IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon)
9  : IntelliTool(Area, colorPicker, Toolsettings){
10  isPointNearStart = false;
11  drawingOfPolygon = false;
12  isInside = false;
13  this->isSettingPolygon = isSettingPolygon;
14  if(isSettingPolygon) {
16  }
18 }
19 
21  if(drawingOfPolygon) {
23  }
24 }
25 
27  if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
28  if(Area->getPolygonDataOfRealLayer().size()>2) {
29  std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
30  QPoint Point(x,y);
31  isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
32  }
33  else{
34  isInside = true;
35  }
36  if(isSettingPolygon) {
37  isInside = true;
38  }
39  }
40  else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
41  isInside = true;
42  }
43 
44  if(isInside && !drawingOfPolygon) {
46  QPoint drawingPoint = QPoint(x,y);
47 
48  drawingOfPolygon = true;
49  QPointList.push_back(drawingPoint);
50 
51  this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
52  if(!isSettingPolygon) {
54  }
55  }
56  else if(drawingOfPolygon && QPointList.size() > 0 && isNearStart(x,y,QPointList.front())) {
57  if(QPointList.size() > 2) {
58  isPointNearStart = true;
59  this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
60  if(!isSettingPolygon) {
62  }
63  }
64  else{
65  isInside = false;
66  drawingOfPolygon = false;
67  QPointList.clear();
70  }
71 
72  }
73  else if(drawingOfPolygon) {
74  QPoint drawingPoint(x,y);
75  QPointList.push_back(drawingPoint);
76  this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
77  if(!isSettingPolygon) {
79  }
80  }
81 }
82 
84  drawingOfPolygon = false;
85  isInside = false;
86  isPointNearStart = false;
87  QPointList.clear();
89 }
90 
92  if(isPointNearStart) {
93  isInside = false;
94  isPointNearStart = false;
95  drawingOfPolygon = false;
96  if(!isSettingPolygon) {
97  std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
98  QPoint Point;
99  QColor colorTwo(colorPicker->getSecondColor());
100  colorTwo.setAlpha(Toolsettings->getInnerAlpha());
101  for(int i = 0; i < activeLayer->width; i++) {
102  for(int j = 0; j < activeLayer->height; j++) {
103  Point = QPoint(i,j);
104  if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
105  this->Canvas->image->drawPixel(Point, colorTwo);
106  }
107  }
108  }
109  for(int i = 0; i<static_cast<int>(QPointList.size()); i++) {
110  int next = static_cast<int>((i + static_cast<int>(1)) % static_cast<int>(QPointList.size()));
111  this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
112  }
113 
114  }
115  else{
116  Canvas->image->setPolygon(QPointList);
118  }
120  QPointList.clear();
121  }
122 }
123 
126 }
127 
129  if(!isSettingPolygon) {
131  if(!isDrawing) {
133  }
134  }
135 }
136 
138  if(!isSettingPolygon) {
140  }
141 }
142 
143 bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
144  int StartX = Startpoint.x();
145  int StartY = Startpoint.y();
146  int valueToNear = 5;
147 
148  float euklid = sqrt(pow(static_cast<float>(StartX - x),2.f) + pow(static_cast<float>(StartY - y),2.f));
149 
150  return static_cast<int>(euklid)<valueToNear;
151 }
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:19
IntelliColorPicker::getFirstColor
QColor getFirstColor() const
A function to read the primary selected color.
Definition: IntelliColorPicker.cpp:15
ImageType::RASTERIMAGE
@ RASTERIMAGE
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:37
IntelliToolsettings::getLineWidth
int getLineWidth() const
Definition: IntelliToolsettings.cpp:14
IntelliTool::colorPicker
IntelliColorPicker * colorPicker
A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
Definition: IntelliTool.h:57
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:97
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:30
IntelliTool::Toolsettings
IntelliToolsettings * Toolsettings
Definition: IntelliTool.h:59
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:58
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
IntelliToolsettings::getInnerAlpha
int getInnerAlpha() const
Definition: IntelliToolsettings.cpp:28
IntelliTool::Area
PaintingArea * Area
A pointer to the general PaintingArea to interact with.
Definition: IntelliTool.h:50
IntelliToolPolygon::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event.
Definition: IntelliToolPolygon.cpp:137
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:57
IntelliTool::isDrawing
bool isDrawing
A flag checking if the user is currently drawing or not.
Definition: IntelliTool.h:74
IntelliColorPicker::getSecondColor
QColor getSecondColor() const
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:19
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:78
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:26
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:64
IntelliToolPolygon::IntelliToolPolygon
IntelliToolPolygon(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings, bool isSettingPolygon=false)
A constructor setting the general paintingArea and colorPicker.
Definition: IntelliToolPolygon.cpp:8
IntelliTool::Tooltype::POLYGON
@ POLYGON
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:69
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::setImageData
virtual void setImageData(const QImage &newData)
setImageData overwrites the old imageData the new imageData.
Definition: IntelliImage.cpp:143
ImageType::SHAPEDIMAGE
@ SHAPEDIMAGE
PaintingArea::getTypeOfImageRealLayer
ImageType getTypeOfImageRealLayer()
Definition: PaintingArea.cpp:294
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:83
PaintingArea.h
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:472
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:52
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:14
IntelliToolPolygon::~IntelliToolPolygon
~IntelliToolPolygon() override
A Destructor.
Definition: IntelliToolPolygon.cpp:20
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:298
IntelliToolsettings::setLineWidth
void setLineWidth(int LineWidth)
Definition: IntelliToolsettings.cpp:18
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:47
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:26
IntelliToolPolygon::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolPolygon.cpp:124
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:91
IntelliImage::calculateVisiblity
virtual void calculateVisiblity()=0
An abstract function that calculates the visiblity of the Image data if needed.
IntelliTriangulation::isInPolygon
bool isInPolygon(const 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
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:52
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:128
IntelliImage::setPolygon
virtual void setPolygon(const std::vector< QPoint > &polygonData)=0
An abstract function that sets the data of the visible Polygon, if needed.