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)
8 : IntelliTool(Area, colorPicker, Toolsettings){
9 isPointNearStart = false;
10 isDrawing = false;
11 isInside = false;
12 this->ActiveType = Tooltype::POLYGON;
13 }
14
15 IntelliToolPolygon::~IntelliToolPolygon(){
16 if(isDrawing) {
17 IntelliTool::onMouseRightPressed(0,0);
18 }
19 }
20
21 void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
22 if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
23 std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
24 QPoint Point(x,y);
25 isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
26 }
27 else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
28 isInside = true;
29 }
30
31 if(isInside && !isDrawing) {
32 IntelliTool::onMouseLeftPressed(x,y);
33 QPoint drawingPoint = QPoint(x,y);
34
35 isDrawing = true;
36 QPointList.push_back(drawingPoint);
37
38 this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
39 this->Canvas->image->calculateVisiblity();
40 }
41 else if(isDrawing && isNearStart(x,y,QPointList.front())) {
42 if(QPointList.size() > 2) {
43 isPointNearStart = true;
44 this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
45 this->Canvas->image->calculateVisiblity();
46 }
47 else{
48 isInside = false;
49 isDrawing = false;
50 QPointList.clear();
51 IntelliTool::onMouseRightPressed(x,y);
52 }
53
54 }
55 else if(isDrawing) {
56 QPoint drawingPoint(x,y);
57 QPointList.push_back(drawingPoint);
58 this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
59 this->Canvas->image->calculateVisiblity();
60 }
61 }
62
63 void IntelliToolPolygon::onMouseRightPressed(int x, int y){
64 isInside = false;
65 isDrawing = false;
66 isPointNearStart = false;
67 QPointList.clear();
68 IntelliTool::onMouseRightPressed(x,y);
69 }
70
71 void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
72 if(isPointNearStart) {
73 isInside = false;
74 isPointNearStart = false;
75 isDrawing = false;
76 std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
77 QPoint Point;
78 QColor colorTwo(colorPicker->getSecondColor());
79 colorTwo.setAlpha(Toolsettings->getInnerAlpha());
80 for(int i = 0; i < activeLayer->width; i++) {
81 for(int j = 0; j < activeLayer->height; j++) {
82 Point = QPoint(i,j);
83 if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
84 this->Canvas->image->drawPixel(Point, colorTwo);
85 }
86 }
87 }
88 for(int i=0; i<static_cast<int>(QPointList.size()); i++) {
89 int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size()));
90 this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
91 }
92 QPointList.clear();
93 IntelliTool::onMouseLeftReleased(x,y);
94 }
95 }
96
97 void IntelliToolPolygon::onMouseRightReleased(int x, int y){
98 IntelliTool::onMouseRightReleased(x,y);
99 }
100
101 void IntelliToolPolygon::onWheelScrolled(int value){
102 IntelliTool::onWheelScrolled(value);
103 if(!isDrawing) {
104 Toolsettings->setLineWidth(Toolsettings->getLineWidth() + value);
105 }
106 }
107
108 void IntelliToolPolygon::onMouseMoved(int x, int y){
109 IntelliTool::onMouseMoved(x,y);
110 }
111
112 bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
113 bool isNear = false;
114 int StartX = Startpoint.x();
115 int StartY = Startpoint.y();
116 int valueToNear = 5;
117
118 for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) {
119 for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) {
120 if((i == x) && (j == y)) {
121 isNear = true;
122 }
123 }
124 }
125 return isNear;
126 }
PaintingArea::getWidthOfActive
int getWidthOfActive()
The getWidthOfActive gets the horizontal dimensions of the active layer.
Definition: PaintingArea.cpp:236
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:51
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:88
IntelliToolPolygon::IntelliToolPolygon
IntelliToolPolygon(PaintingArea *Area, IntelliColorPicker *colorPicker, IntelliToolsettings *Toolsettings)
A constructor setting the general paintingArea and colorPicker.
Definition: IntelliToolPolygon.cpp:7
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:53
IntelliToolsettings::setLineWidth
void setLineWidth()
Definition: IntelliToolsettings.cpp:19
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:55
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:44
IntelliColorPicker::getSecondColor
QColor getSecondColor()
A function to read the secondary selected color.
Definition: IntelliColorPicker.cpp:20
PaintingArea::getHeightOfActive
int getHeightOfActive()
The getHeightOfActive gets the vertical dimensions of the active layer.
Definition: PaintingArea.cpp:240
IntelliToolPolygon::onMouseMoved
virtual void onMouseMoved(int x, int y) override
A function managing the mouse moved event.
Definition: IntelliToolPolygon.cpp:108
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:33
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:72
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:58
IntelliTool::Tooltype::POLYGON
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:63
PaintingArea::getTypeOfImageRealLayer
IntelliImage::ImageType getTypeOfImageRealLayer()
Definition: PaintingArea.cpp:244
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
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:63
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
IntelliTool::ActiveType
Tooltype ActiveType
Definition: IntelliTool.h:46
IntelliColorPicker
The IntelliColorPicker manages the selected colors for one whole project.
Definition: IntelliColorPicker.h:11
IntelliToolPolygon::~IntelliToolPolygon
~IntelliToolPolygon() override
A Destructor.
Definition: IntelliToolPolygon.cpp:15
IntelliImage::ImageType::RASTERIMAGE
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:26
PaintingArea::getPolygonDataOfRealLayer
std::vector< QPoint > getPolygonDataOfRealLayer()
Definition: PaintingArea.cpp:248
IntelliToolsettings::getLineWidth
int getLineWidth()
Definition: IntelliToolsettings.cpp:15
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:42
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:21
IntelliToolPolygon::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolPolygon.cpp:97
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:71
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:47
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:101