mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 04:10:31 +02:00
Merge branch 'dev' into dev-docs
This commit is contained in:
@@ -26,7 +26,7 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
|
||||
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->start=QPoint(x,y);
|
||||
this->Canvas->image->drawLine(start, start, colorPicker->getFirstColor(),lineWidth);
|
||||
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
|
||||
106
src/Tool/IntelliToolPolygon.cpp
Normal file
106
src/Tool/IntelliToolPolygon.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "IntelliToolPolygon.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include <QDebug>
|
||||
#include <QCursor>
|
||||
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
lineWidth = 5;
|
||||
isDrawing = false;
|
||||
PointIsNearStart = false;
|
||||
drawingPoint.setX(0);
|
||||
drawingPoint.setY(0);
|
||||
Point.setX(0);
|
||||
Point.setY(0);
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
if(!isDrawing){
|
||||
width = Area->getWidthActiveLayer();
|
||||
height = Area->getHeightActiveLayer();
|
||||
}
|
||||
if(!isDrawing && x > 0 && y > 0 && x < width && y < height){
|
||||
isDrawing = true;
|
||||
drawingPoint.setX(x);
|
||||
drawingPoint.setY(y);
|
||||
QPointList.push_back(drawingPoint);
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing && isNearStart(x,y,QPointList.front())){
|
||||
PointIsNearStart = isNearStart(x,y,QPointList.front());
|
||||
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing){
|
||||
drawingPoint.setX(x);
|
||||
drawingPoint.setY(y);
|
||||
QPointList.push_back(drawingPoint);
|
||||
this->Canvas->image->drawLine(QPointList.operator[](QPointList.size() - 2), QPointList.back(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
||||
isDrawing = false;
|
||||
PointIsNearStart = false;
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
if(PointIsNearStart && QPointList.size() > 1){
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
PointIsNearStart = false;
|
||||
isDrawing = false;
|
||||
Triangles = IntelliHelper::calculateTriangles(QPointList);
|
||||
for(int i = 0; i < width; i++){
|
||||
for(int j = 0; j < height; j++){
|
||||
Point.setX(i);
|
||||
Point.setY(j);
|
||||
if(IntelliHelper::isInPolygon(Triangles,Point)){
|
||||
this->Canvas->image->drawPixel(QPoint(i,j), colorPicker->getFirstColor());
|
||||
}
|
||||
}
|
||||
}
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseRightReleased(int x, int y){
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onWheelScrolled(int value){
|
||||
if(!isDrawing){
|
||||
if(lineWidth + value < 10){
|
||||
lineWidth += value;
|
||||
}
|
||||
if(lineWidth < 1){
|
||||
lineWidth = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseMoved(int x, int y){
|
||||
|
||||
}
|
||||
|
||||
bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
|
||||
bool isNear = false;
|
||||
int StartX = Startpoint.x();
|
||||
int StartY = Startpoint.y();
|
||||
int valueToNear = 10;
|
||||
|
||||
for(int i = StartX - valueToNear; i < StartX + valueToNear; i++){
|
||||
for(int j = StartY - valueToNear; j < StartY + valueToNear; j++){
|
||||
if((i == x) && (j == y)){
|
||||
isNear = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isNear;
|
||||
}
|
||||
79
src/Tool/IntelliToolPolygon.h
Normal file
79
src/Tool/IntelliToolPolygon.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#ifndef INTELLITOOLPOLYGON_H
|
||||
#define INTELLITOOLPOLYGON_H
|
||||
|
||||
#include "IntelliTool.h"
|
||||
#include "IntelliHelper/IntelliHelper.h"
|
||||
#include <vector>
|
||||
#include <QPoint>
|
||||
/*!
|
||||
* \brief The IntelliToolPolygon managed the Drawing of Polygonforms
|
||||
*/
|
||||
class IntelliToolPolygon : public IntelliTool
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief IntelliToolPolygon Constructor Define the Tool-intern Parameters
|
||||
* \param Area
|
||||
* \param colorPicker
|
||||
*/
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
virtual void onMouseLeftReleased(int x, int y) override;
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
virtual void onMouseRightReleased(int x, int y) override;
|
||||
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
|
||||
virtual void onMouseMoved(int x, int y) override;
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief isNearStart
|
||||
* \param x
|
||||
* \param y
|
||||
* \param Startpoint
|
||||
* \return true : Near Startpoint, else false
|
||||
*/
|
||||
bool isNearStart(int x, int y, QPoint Startpoint);
|
||||
|
||||
/*!
|
||||
* \brief lineWidth of the Drawing Polygon
|
||||
*/
|
||||
int lineWidth;
|
||||
/*!
|
||||
* \brief width of the active Layer
|
||||
*/
|
||||
int width;
|
||||
/*!
|
||||
* \brief height of the active Layer
|
||||
*/
|
||||
int height;
|
||||
/*!
|
||||
* \brief isDrawing true while drawing, else false
|
||||
*/
|
||||
bool isDrawing;
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near Startpoint, else false
|
||||
*/
|
||||
bool PointIsNearStart;
|
||||
/*!
|
||||
* \brief drawingPoint Current Point after Left-Click
|
||||
*/
|
||||
QPoint drawingPoint;
|
||||
/*!
|
||||
* \brief Point Needed to look, if Point is in Polygon
|
||||
*/
|
||||
QPoint Point;
|
||||
/*!
|
||||
* \brief QPointList List of all Points of the Polygon
|
||||
*/
|
||||
std::vector<QPoint> QPointList;
|
||||
/*!
|
||||
* \brief Triangles Transformed QPointList into triangulated Form of the Polygon
|
||||
*/
|
||||
std::vector<Triangle> Triangles;
|
||||
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLPOLYGON_H
|
||||
Reference in New Issue
Block a user