Polygon Update

This commit is contained in:
AshBastian
2019-12-17 17:45:42 +01:00
parent 21ade76563
commit 3525261e1e
7 changed files with 128 additions and 3 deletions

View File

@@ -18,7 +18,8 @@ IntelliPhotoGui::IntelliPhotoGui(){
setIntelliStyle();
// Size the app
showMaximized();
resize(600,600);
//showMaximized();
}
// User tried to close the app

View File

@@ -123,6 +123,7 @@ private:
//main GUI elements
QWidget* centralGuiWidget;
QPushButton* Toolmanager;
QGridLayout *mainLayout;
};

View File

@@ -28,6 +28,7 @@ SOURCES += \
Tool/IntelliToolLine.cpp \
Tool/IntelliToolPen.cpp \
Tool/IntelliToolPlain.cpp \
Tool/IntelliToolPolygon.cpp \
Tool/IntelliToolRechteck.cpp \
main.cpp
@@ -44,6 +45,7 @@ HEADERS += \
Tool/IntelliToolLine.h \
Tool/IntelliToolPen.h \
Tool/IntelliToolPlain.h \
Tool/IntelliToolPolygon.h \
Tool/IntelliToolRechteck.h \
Tool/intellitoolcircle.h

View File

@@ -15,11 +15,12 @@
#include "Tool/IntelliToolLine.h"
#include "Tool/IntelliToolCircle.h"
#include "Tool/IntelliToolRechteck.h"
#include "Tool/IntelliToolPolygon.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
:QWidget(parent){
//test yout tool here and reset after accomplished test
this->Tool = new IntelliToolRechteck(this, &colorPicker);
this->Tool = new IntelliToolPolygon(this, &colorPicker);
this->setUp(maxWidth, maxHeight);
//tetsing
this->addLayer(200,200,0,0,ImageType::Shaped_Image);

View File

@@ -34,7 +34,7 @@ class PaintingArea : public QWidget
friend IntelliTool;
public:
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr);
~PaintingArea();
~PaintingArea() override;
// Handles all events
bool open(const QString &fileName);

View File

@@ -0,0 +1,87 @@
#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);
}
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
qDebug() << x << y;
if(!isDrawing && x > 0 && y > 0){
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);
}
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);s
}
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);
}
}
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){
PointIsNearStart = false;
isDrawing = false;
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;
}

View File

@@ -0,0 +1,33 @@
#ifndef INTELLITOOLPOLYGON_H
#define INTELLITOOLPOLYGON_H
#include "IntelliTool.h"
#include <vector>
#include <QPoint>
class IntelliToolPolygon : public IntelliTool
{
public:
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:
bool isNearStart(int x, int y, QPoint Startpoint);
int lineWidth;
bool isDrawing;
bool PointIsNearStart;
QPoint drawingPoint;
std::vector<QPoint> QPointList;
};
#endif // INTELLITOOLPOLYGON_H