ToolSettings

This commit is contained in:
AshBastian
2020-01-08 15:47:16 +01:00
parent dd55a7158d
commit 52a72c05c5
26 changed files with 111 additions and 77 deletions

View File

@@ -8,7 +8,7 @@
#include <QWidget>
#include <vector>
#include "IntelliHelper/IntelliHelper.h"
#include "IntelliHelper/IntelliTriangulation.h"
class IntelliTool;

View File

@@ -1,5 +1,5 @@
#include "Image/IntelliShapedImage.h"
#include "IntelliHelper/IntelliHelper.h"
#include "IntelliHelper/IntelliTriangulation.h"
#include <QPainter>
#include <QRect>
#include <QDebug>
@@ -42,7 +42,7 @@ void IntelliShapedImage::calculateVisiblity(){
for(int x=0; x<imageData.width(); x++) {
QPoint ptr(x,y);
clr = imageData.pixelColor(x,y);
bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr);
bool isInPolygon = IntelliTriangulation::isInPolygon(triangles, ptr);
if(isInPolygon) {
clr.setAlpha(std::min(255, clr.alpha()));
}else{
@@ -73,7 +73,7 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
for(auto element:polygonData) {
this->polygonData.push_back(QPoint(element.x(), element.y()));
}
triangles = IntelliHelper::calculateTriangles(polygonData);
triangles = IntelliTriangulation::calculateTriangles(polygonData);
}
calculateVisiblity();
return;

View File

@@ -0,0 +1,19 @@
#include "IntelliToolsettings.h"
IntelliToolsettings::IntelliToolsettings()
{
lineWidth = 1;
innerAlpha = 255;
}
int IntelliToolsettings::getLineWidth(){
return lineWidth;
}
int IntelliToolsettings::getInnerAlpha(){
return innerAlpha;
}
IntelliToolsettings::LineStyle IntelliToolsettings::getLinestyle(){
return Linestyle;
}

View File

@@ -0,0 +1,24 @@
#ifndef INTELLITOOLSETTINGS_H
#define INTELLITOOLSETTINGS_H
class IntelliToolsettings {
public:
/*!
* \brief The LineStyle enum classifing all ways of drawing a line.
*/
enum class LineStyle {
SOLID_LINE,
DOTTED_LINE
};
IntelliToolsettings();
int getLineWidth();
int getInnerAlpha();
LineStyle getLinestyle();
private:
int lineWidth;
int innerAlpha;
LineStyle Linestyle;
};
#endif // INTELLITOOLSETTINGS_H

View File

@@ -1,10 +1,10 @@
#include "IntelliHelper.h"
#include "IntelliTriangulation.h"
#include <algorithm>
#include <queue>
#include <cmath>
#define pi 3.1415926535897932384626433832795
std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> polyPoints){
std::vector<Triangle> IntelliTriangulation::calculateTriangles(std::vector<QPoint> polyPoints){
// helper for managing the triangle vertices and their state
struct TriangleHelper {
QPoint vertex;
@@ -113,9 +113,9 @@ std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> poly
return Triangles;
}
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
bool IntelliTriangulation::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
for(auto triangle : triangles) {
if(IntelliHelper::isInTriangle(triangle, point)) {
if(IntelliTriangulation::isInTriangle(triangle, point)) {
return true;
}
}

View File

@@ -1,5 +1,5 @@
#ifndef INTELLIHELPER_H
#define INTELLIHELPER_H
#ifndef INTELLITRIANGULATION_H
#define INTELLITRIANGULATION_H
#include <QPoint>
#include <vector>
@@ -11,7 +11,7 @@ struct Triangle {
QPoint A,B,C;
};
namespace IntelliHelper {
namespace IntelliTriangulation {
/*!
* \brief A function to get the 2*area of a traingle, using its determinat.
@@ -34,9 +34,9 @@ inline bool isInTriangle(Triangle& tri, QPoint& P){
float val1, val2, val3;
bool neg, pos;
val1 = IntelliHelper::sign(P,tri.A,tri.B);
val2 = IntelliHelper::sign(P,tri.B,tri.C);
val3 = IntelliHelper::sign(P,tri.C,tri.A);
val1 = IntelliTriangulation::sign(P,tri.A,tri.B);
val2 = IntelliTriangulation::sign(P,tri.B,tri.C);
val3 = IntelliTriangulation::sign(P,tri.C,tri.A);
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);

View File

@@ -21,7 +21,8 @@ SOURCES += \
Image/IntelliRasterImage.cpp \
Image/IntelliShapedImage.cpp \
IntelliHelper/IntelliColorPicker.cpp \
IntelliHelper/IntelliHelper.cpp \
IntelliHelper/IntelliToolsettings.cpp \
IntelliHelper/IntelliTriangulation.cpp \
Layer/PaintingArea.cpp \
Tool/IntelliTool.cpp \
Tool/IntelliToolCircle.cpp \
@@ -39,7 +40,8 @@ HEADERS += \
Image/IntelliRasterImage.h \
Image/IntelliShapedImage.h \
IntelliHelper/IntelliColorPicker.h \
IntelliHelper/IntelliHelper.h \
IntelliHelper/IntelliToolsettings.h \
IntelliHelper/IntelliTriangulation.h \
Layer/PaintingArea.h \
Tool/IntelliTool.h \
Tool/IntelliToolCircle.h \

View File

@@ -194,36 +194,36 @@ void PaintingArea::colorPickerSwapColors(){
void PaintingArea::createPenTool(){
delete this->Tool;
Tool = new IntelliToolPen(this, &colorPicker);
Tool = new IntelliToolPen(this, &colorPicker, &Toolsettings);
}
void PaintingArea::createPlainTool(){
delete this->Tool;
Tool = new IntelliToolPlainTool(this, &colorPicker);
Tool = new IntelliToolPlainTool(this, &colorPicker, &Toolsettings);
}
void PaintingArea::createLineTool(){
delete this->Tool;
Tool = new IntelliToolLine(this, &colorPicker);
Tool = new IntelliToolLine(this, &colorPicker, &Toolsettings);
}
void PaintingArea::createRectangleTool(){
delete this->Tool;
Tool = new IntelliToolRectangle(this, &colorPicker);
Tool = new IntelliToolRectangle(this, &colorPicker, &Toolsettings);
}
void PaintingArea::createCircleTool(){
delete this->Tool;
Tool = new IntelliToolCircle(this, &colorPicker);
Tool = new IntelliToolCircle(this, &colorPicker, &Toolsettings);
}
void PaintingArea::createPolygonTool(){
delete this->Tool;
Tool = new IntelliToolPolygon(this, &colorPicker);
Tool = new IntelliToolPolygon(this, &colorPicker, &Toolsettings);
}
void PaintingArea::createFloodFillTool(){
delete this->Tool;
Tool = new IntelliToolFloodFill(this, &colorPicker);
Tool = new IntelliToolFloodFill(this, &colorPicker, &Toolsettings);
}
int PaintingArea::getWidthOfActive(){
@@ -381,13 +381,13 @@ void PaintingArea::createTempTopLayer(int idx){
IntelliTool* PaintingArea::copyActiveTool(){
switch(Tool->getTooltype()){
case IntelliTool::Tooltype::CIRCLE: return new IntelliToolCircle(this,&colorPicker);
case IntelliTool::Tooltype::FLOODFILL: return new IntelliToolFloodFill(this,&colorPicker);
case IntelliTool::Tooltype::LINE: return new IntelliToolLine(this,&colorPicker);
case IntelliTool::Tooltype::PEN: return new IntelliToolPen(this,&colorPicker);
case IntelliTool::Tooltype::PLAIN: return new IntelliToolPlainTool(this,&colorPicker);
case IntelliTool::Tooltype::POLYGON: return new IntelliToolPolygon(this,&colorPicker);
case IntelliTool::Tooltype::RECTANGLE: return new IntelliToolRectangle(this,&colorPicker);
case IntelliTool::Tooltype::CIRCLE: return new IntelliToolCircle(this,&colorPicker, &Toolsettings);
case IntelliTool::Tooltype::FLOODFILL: return new IntelliToolFloodFill(this,&colorPicker, &Toolsettings);
case IntelliTool::Tooltype::LINE: return new IntelliToolLine(this,&colorPicker, &Toolsettings);
case IntelliTool::Tooltype::PEN: return new IntelliToolPen(this,&colorPicker, &Toolsettings);
case IntelliTool::Tooltype::PLAIN: return new IntelliToolPlainTool(this,&colorPicker, &Toolsettings);
case IntelliTool::Tooltype::POLYGON: return new IntelliToolPolygon(this,&colorPicker, &Toolsettings);
case IntelliTool::Tooltype::RECTANGLE: return new IntelliToolRectangle(this,&colorPicker, &Toolsettings);
default: return nullptr;
}
}

View File

@@ -202,6 +202,7 @@ private:
IntelliTool* Tool;
IntelliColorPicker colorPicker;
IntelliToolsettings Toolsettings;
std::vector<LayerObject> layerBundle;
int activeLayer=-1;

View File

@@ -1,9 +1,10 @@
#include "IntelliTool.h"
#include "Layer/PaintingArea.h"
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){
this->Area=Area;
this->colorPicker=colorPicker;
this->Toolsettings=Toolsettings;
}

View File

@@ -2,6 +2,7 @@
#define Intelli_Tool_H
#include "IntelliHelper/IntelliColorPicker.h"
#include "IntelliHelper/IntelliToolsettings.h"
#include <vector>
struct LayerObject;
@@ -49,6 +50,8 @@ Tooltype ActiveType;
*/
IntelliColorPicker* colorPicker;
IntelliToolsettings* Toolsettings;
/*!
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
*/
@@ -70,7 +73,7 @@ public:
* \param Area - The general PaintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief An abstract Destructor.

View File

@@ -3,8 +3,8 @@
#include "QInputDialog"
#include <cmath>
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
this->ActiveType = Tooltype::CIRCLE;

View File

@@ -34,7 +34,7 @@ public:
* \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief A Destructor.

View File

@@ -5,8 +5,8 @@
#include <functional>
#include <queue>
IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->ActiveType = Tooltype::FLOODFILL;
}

View File

@@ -14,7 +14,7 @@ public:
* \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief A Destructor.

View File

@@ -3,12 +3,10 @@
#include "QColorDialog"
#include "QInputDialog"
IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
this->ActiveType = Tooltype::LINE;
//create checkbox or scroll dialog to get line style
this->lineStyle = LineStyle::SOLID_LINE;
}
IntelliToolLine::~IntelliToolLine(){
@@ -46,11 +44,11 @@ void IntelliToolLine::onMouseMoved(int x, int y){
if(this->isDrawing) {
this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y);
switch(lineStyle) {
case LineStyle::SOLID_LINE:
switch(Toolsettings->getLinestyle()) {
case IntelliToolsettings::LineStyle::SOLID_LINE:
this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),lineWidth);
break;
case LineStyle::DOTTED_LINE:
case IntelliToolsettings::LineStyle::DOTTED_LINE:
QPoint p1 =lineStartingPoint.x() <= next.x() ? lineStartingPoint : next;
QPoint p2 =lineStartingPoint.x() < next.x() ? next : lineStartingPoint;
int m = static_cast<int>(static_cast<float>(p2.y()-p1.y())/static_cast<float>(p2.x()-p1.x())+0.5f);

View File

@@ -4,14 +4,6 @@
#include "QPoint"
/*!
* \brief The LineStyle enum classifing all ways of drawing a line.
*/
enum class LineStyle {
SOLID_LINE,
DOTTED_LINE
};
/*!
* \brief The IntelliToolFloodFill class represents a tool to draw a line.
*/
@@ -25,11 +17,6 @@ QPoint lineStartingPoint;
* \brief The width of the line to draw.
*/
int lineWidth;
/*!
* \brief The style of the line. Apropriate to LineStyle.
*/
LineStyle lineStyle;
public:
/*!
@@ -37,7 +24,7 @@ public:
* \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief An abstract Destructor.

View File

@@ -4,8 +4,8 @@
#include "QColorDialog"
#include "QInputDialog"
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
this->ActiveType = Tooltype::PEN;
}

View File

@@ -23,7 +23,7 @@ public:
* \param Area - The general PaintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief A Destructor.
*/

View File

@@ -2,8 +2,8 @@
#include "Layer/PaintingArea.h"
#include "QColorDialog"
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->ActiveType = Tooltype::PLAIN;
}

View File

@@ -13,7 +13,7 @@ public:
* \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolPlainTool(PaintingArea*Area, IntelliColorPicker* colorPicker);
IntelliToolPlainTool(PaintingArea*Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief A Destructor.
*/

View File

@@ -4,8 +4,8 @@
#include <QInputDialog>
#include <QDebug>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 255,0,255,1);
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",5,1,10,1);
isPointNearStart = false;
@@ -22,9 +22,9 @@ IntelliToolPolygon::~IntelliToolPolygon(){
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Shaped_Image && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(Area->getPolygonDataOfRealLayer());
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y);
isInside = IntelliHelper::isInPolygon(Triangles,Point);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
}
else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::Raster_Image && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
isInside = true;
@@ -75,14 +75,14 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
isInside = false;
isPointNearStart = false;
isDrawing = false;
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
QPoint Point;
QColor colorTwo(colorPicker->getSecondColor());
colorTwo.setAlpha(innerAlpha);
for(int i = 0; i < activeLayer->width; i++) {
for(int j = 0; j < activeLayer->height; j++) {
Point = QPoint(i,j);
if(IntelliHelper::isInPolygon(Triangles,Point)) {
if(IntelliTriangulation::isInPolygon(Triangles,Point)) {
this->Canvas->image->drawPixel(Point, colorTwo);
}
}

View File

@@ -2,7 +2,7 @@
#define INTELLITOOLPOLYGON_H
#include "IntelliTool.h"
#include "IntelliHelper/IntelliHelper.h"
#include "IntelliHelper/IntelliTriangulation.h"
#include <vector>
#include <QPoint>
/*!
@@ -54,7 +54,7 @@ public:
* \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief A Destructor.
*/

View File

@@ -2,8 +2,8 @@
#include "Layer/PaintingArea.h"
#include "QInputDialog"
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker)
: IntelliTool(Area, colorPicker){
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings)
: IntelliTool(Area, colorPicker, Toolsettings){
this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
this->ActiveType = Tooltype::RECTANGLE;

View File

@@ -33,7 +33,7 @@ public:
* \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project.
*/
IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker);
IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings);
/*!
* \brief A Destructor.
*/

View File

@@ -1,7 +1,6 @@
#include "GUI/IntelliPhotoGui.h"
#include <QApplication>
#include <QDebug>
#include "IntelliHelper/IntelliHelper.h"
#include <vector>
int main(int argc, char*argv[]){