IntelliPhoto 0.5

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 #include <QInputDialog>
6
7 IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
8 : IntelliTool(Area, colorPicker){
9 this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
10 lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);;
11 PointIsNearStart = false;
12 isDrawing = false;
13 }
14
15 IntelliToolPolygon::~IntelliToolPolygon(){
16
17 }
18
19 void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
20 if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
21 IntelliTool::onMouseLeftPressed(x,y);
22 QPoint drawingPoint = QPoint(x,y);
23
24 isDrawing = true;
25 QPointList.push_back(drawingPoint);
26
27 this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
28 this->Canvas->image->calculateVisiblity();
29 }
30 else if(isDrawing && isNearStart(x,y,QPointList.front())) {
31 PointIsNearStart = true;
32 this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
33 this->Canvas->image->calculateVisiblity();
34 }
35 else if(isDrawing) {
36 QPoint drawingPoint(x,y);
37 QPointList.push_back(drawingPoint);
38 this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth);
39 this->Canvas->image->calculateVisiblity();
40 }
41 }
42
43 void IntelliToolPolygon::onMouseRightPressed(int x, int y){
44 isDrawing = false;
45 PointIsNearStart = false;
46 QPointList.clear();
47 IntelliTool::onMouseRightPressed(x,y);
48 }
49
50 void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
51 if(PointIsNearStart && QPointList.size() > 1) {
52 PointIsNearStart = false;
53 isDrawing = false;
54 std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
55 QPoint Point;
56 QColor colorTwo(colorPicker->getSecondColor());
57 colorTwo.setAlpha(alphaInner);
58 for(int i = 0; i < Active->width; i++) {
59 for(int j = 0; j < Active->height; j++) {
60 Point = QPoint(i,j);
61 if(IntelliHelper::isInPolygon(Triangles,Point)) {
62 this->Canvas->image->drawPixel(Point, colorTwo);
63 }
64 }
65 }
66 for(int i=0; i<QPointList.size(); i++) {
67 int next = (i+1)%QPointList.size();
68 this->Canvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth);
69 }
70 QPointList.clear();
71 IntelliTool::onMouseLeftReleased(x,y);
72 }
73 }
74
75 void IntelliToolPolygon::onMouseRightReleased(int x, int y){
76 IntelliTool::onMouseRightReleased(x,y);
77 }
78
79 void IntelliToolPolygon::onWheelScrolled(int value){
80 IntelliTool::onWheelScrolled(value);
81 if(!isDrawing) {
82 if(lineWidth + value < 10) {
83 lineWidth += value;
84 }
85 if(lineWidth < 1) {
86 lineWidth = 1;
87 }
88 }
89 }
90
91 void IntelliToolPolygon::onMouseMoved(int x, int y){
92 IntelliTool::onMouseMoved(x,y);
93 }
94
95 bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
96 bool isNear = false;
97 int StartX = Startpoint.x();
98 int StartY = Startpoint.y();
99 int valueToNear = 10;
100
101 for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) {
102 for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) {
103 if((i == x) && (j == y)) {
104 isNear = true;
105 }
106 }
107 }
108 return isNear;
109 }
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
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
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:91
PaintingArea
The PaintingArea class manages the methods and stores information about the current painting area,...
Definition: PaintingArea.h:36
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:55
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:21
IntelliTool::Canvas
LayerObject * Canvas
A pointer to the drawing canvas of the tool, work on this.
Definition: IntelliTool.h:48
LayerObject::width
int width
Definition: PaintingArea.h:26
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: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:43
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:27
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
IntelliToolPolygon::~IntelliToolPolygon
~IntelliToolPolygon() override
A Destructor.
Definition: IntelliToolPolygon.cpp:15
LayerObject::image
IntelliImage * image
Definition: PaintingArea.h:25
IntelliTool::Active
LayerObject * Active
A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or prev...
Definition: IntelliTool.h:43
IntelliToolPolygon::IntelliToolPolygon
IntelliToolPolygon(PaintingArea *Area, IntelliColorPicker *colorPicker)
A constructor setting the general paintingArea and colorPicker.
Definition: IntelliToolPolygon.cpp:7
IntelliTool::onMouseMoved
virtual void onMouseMoved(int x, int y)
A function managing the mouse moved event. Call this in child classes!
Definition: IntelliTool.cpp:41
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:19
IntelliToolPolygon::onMouseRightReleased
virtual void onMouseRightReleased(int x, int y) override
A function managing the right click released of a mouse.
Definition: IntelliToolPolygon.cpp:75
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:50
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:46
IntelliToolPolygon::onWheelScrolled
virtual void onWheelScrolled(int value) override
A function managing the scroll event. CHanging the lineWidth relative to value.
Definition: IntelliToolPolygon.cpp:79