mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-17 13:50:35 +02:00
Merge branch 'dev-tools-seb' into dev-docs
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,5 @@
|
|||||||
# Build folders
|
# Build folders
|
||||||
src/build-*/
|
build-*/
|
||||||
|
|
||||||
# QT Creator Files
|
# QT Creator Files
|
||||||
*.creator.user*
|
*.creator.user*
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ IntelliPhotoGui::IntelliPhotoGui(){
|
|||||||
createMenus();
|
createMenus();
|
||||||
//set style of the gui
|
//set style of the gui
|
||||||
setIntelliStyle();
|
setIntelliStyle();
|
||||||
|
|
||||||
// Size the app
|
// Size the app
|
||||||
showMaximized();
|
showMaximized();
|
||||||
}
|
}
|
||||||
@@ -28,7 +27,6 @@ void IntelliPhotoGui::closeEvent(QCloseEvent *event){
|
|||||||
if (maybeSave()) {
|
if (maybeSave()) {
|
||||||
event->accept();
|
event->accept();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// If there have been changes ignore the event
|
// If there have been changes ignore the event
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
@@ -45,7 +43,7 @@ void IntelliPhotoGui::slotOpen(){
|
|||||||
// tr sets the window title to Open File
|
// tr sets the window title to Open File
|
||||||
// QDir opens the current dirctory
|
// QDir opens the current dirctory
|
||||||
QString fileName = QFileDialog::getOpenFileName(this,
|
QString fileName = QFileDialog::getOpenFileName(this,
|
||||||
tr("Open File"), QDir::currentPath());
|
tr("Open File"), QDir::currentPath(), nullptr, nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
|
|
||||||
// If we have a file name load the image and place
|
// If we have a file name load the image and place
|
||||||
// it in the paintingArea
|
// it in the paintingArea
|
||||||
@@ -234,7 +232,7 @@ void IntelliPhotoGui::slotCreateLineTool(){
|
|||||||
void IntelliPhotoGui::slotAboutDialog(){
|
void IntelliPhotoGui::slotAboutDialog(){
|
||||||
// Window title and text to display
|
// Window title and text to display
|
||||||
QMessageBox::about(this, tr("About Painting"),
|
QMessageBox::about(this, tr("About Painting"),
|
||||||
tr("<p><b>IntelliPhoto</b> Some nice ass looking software</p>"));
|
tr("<p><b>IntelliPhoto</b>Pretty basic editor.</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define menu actions that call functions
|
// Define menu actions that call functions
|
||||||
@@ -276,6 +274,7 @@ void IntelliPhotoGui::createActions(){
|
|||||||
|
|
||||||
// Create New Layer action and tie to IntelliPhotoGui::newLayer()
|
// Create New Layer action and tie to IntelliPhotoGui::newLayer()
|
||||||
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
|
actionCreateNewLayer = new QAction(tr("&New Layer..."), this);
|
||||||
|
actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
|
||||||
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
|
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer()));
|
||||||
|
|
||||||
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
|
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
|
||||||
@@ -317,7 +316,7 @@ void IntelliPhotoGui::createActions(){
|
|||||||
connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
|
connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
|
||||||
|
|
||||||
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
|
actionColorPickerSecondColor = new QAction(tr("&Secondary"), this);
|
||||||
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor()));
|
connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor()));
|
||||||
|
|
||||||
actionColorSwitch = new QAction(tr("&Switch"), this);
|
actionColorSwitch = new QAction(tr("&Switch"), this);
|
||||||
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
|
actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S));
|
||||||
@@ -462,7 +461,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){
|
|||||||
initialPath,
|
initialPath,
|
||||||
tr("%1 Files (*.%2);;All Files (*)")
|
tr("%1 Files (*.%2);;All Files (*)")
|
||||||
.arg(QString::fromLatin1(fileFormat.toUpper()))
|
.arg(QString::fromLatin1(fileFormat.toUpper()))
|
||||||
.arg(QString::fromLatin1(fileFormat)));
|
.arg(QString::fromLatin1(fileFormat)), nullptr, QFileDialog::DontUseNativeDialog);
|
||||||
|
|
||||||
// If no file do nothing
|
// If no file do nothing
|
||||||
if (fileName.isEmpty()) {
|
if (fileName.isEmpty()) {
|
||||||
|
|||||||
@@ -52,6 +52,16 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
|
|||||||
painter.drawPoint(p1);
|
painter.drawPoint(p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
|
||||||
|
// Used to draw on the widget
|
||||||
|
QPainter painter(&imageData);
|
||||||
|
|
||||||
|
// Set the current settings for the pen
|
||||||
|
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
// Draw a line from the last registered point to the current
|
||||||
|
painter.drawPoint(p1);
|
||||||
|
}
|
||||||
|
|
||||||
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
|
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
|
||||||
// Used to draw on the widget
|
// Used to draw on the widget
|
||||||
QPainter painter(&imageData);
|
QPainter painter(&imageData);
|
||||||
|
|||||||
@@ -35,26 +35,18 @@ void IntelliShapedImage::calculateVisiblity(){
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QPoint A = polygonData[0];
|
|
||||||
QColor clr;
|
QColor clr;
|
||||||
for(int y=0; y<imageData.height(); y++){
|
for(int y=0; y<imageData.height(); y++){
|
||||||
for(int x=0; x<imageData.width(); x++){
|
for(int x=0; x<imageData.width(); x++){
|
||||||
int cutNumeber=0;
|
QPoint ptr(x,y);
|
||||||
for(int i=1; i<static_cast<int>(polygonData.size()-1); i++){
|
clr = imageData.pixelColor(x,y);
|
||||||
QPoint B = polygonData[static_cast<size_t>(i)];
|
bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr);
|
||||||
QPoint C = polygonData[static_cast<size_t>(i+1)];
|
if(isInPolygon){
|
||||||
QPoint P(x,y);
|
|
||||||
cutNumeber+=IntelliHelper::isInTriangle(A,B,C,P);
|
|
||||||
}
|
|
||||||
if(cutNumeber%2==0){
|
|
||||||
clr = imageData.pixelColor(x,y);
|
|
||||||
clr.setAlpha(0);
|
|
||||||
imageData.setPixelColor(x,y,clr);
|
|
||||||
}else{
|
|
||||||
clr = imageData.pixelColor(x,y);
|
|
||||||
clr.setAlpha(std::min(255, clr.alpha()));
|
clr.setAlpha(std::min(255, clr.alpha()));
|
||||||
imageData.setPixelColor(x,y,clr);
|
}else{
|
||||||
|
clr.setAlpha(0);
|
||||||
}
|
}
|
||||||
|
imageData.setPixelColor(x,y,clr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,6 +71,7 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
|||||||
for(auto element:polygonData){
|
for(auto element:polygonData){
|
||||||
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||||
}
|
}
|
||||||
|
triangles = IntelliHelper::calculateTriangles(polygonData);
|
||||||
}
|
}
|
||||||
calculateVisiblity();
|
calculateVisiblity();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -2,9 +2,13 @@
|
|||||||
#define INTELLISHAPE_H
|
#define INTELLISHAPE_H
|
||||||
|
|
||||||
#include"Image/IntelliRasterImage.h"
|
#include"Image/IntelliRasterImage.h"
|
||||||
|
#include<vector>
|
||||||
|
#include"IntelliHelper/IntelliHelper.h"
|
||||||
|
|
||||||
class IntelliShapedImage : public IntelliRasterImage{
|
class IntelliShapedImage : public IntelliRasterImage{
|
||||||
friend IntelliTool;
|
friend IntelliTool;
|
||||||
|
private:
|
||||||
|
std::vector<Triangle> triangles;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::vector<QPoint> polygonData;
|
std::vector<QPoint> polygonData;
|
||||||
|
|||||||
@@ -1,2 +1,123 @@
|
|||||||
#include"IntelliHelper.h"
|
#include"IntelliHelper.h"
|
||||||
#include<algorithm>
|
#include<algorithm>
|
||||||
|
#include<queue>
|
||||||
|
#include<cmath>
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> polyPoints){
|
||||||
|
//helper for managing the triangle vertices and their state
|
||||||
|
struct TriangleHelper{
|
||||||
|
QPoint vertex;
|
||||||
|
float interiorAngle;
|
||||||
|
int index;
|
||||||
|
bool isTip;
|
||||||
|
};
|
||||||
|
|
||||||
|
//calculates the inner angle of 'point'
|
||||||
|
auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){
|
||||||
|
QPoint AP(point.x()-prev.x(), point.y()-prev.y());
|
||||||
|
QPoint BP(point.x()-post.x(), point.y()-post.y());
|
||||||
|
|
||||||
|
float topSclar = AP.x()*BP.x()+AP.y()*BP.y();
|
||||||
|
float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.));
|
||||||
|
return acos(topSclar/absolute);
|
||||||
|
};
|
||||||
|
|
||||||
|
//gets the first element of vec for which element.isTip == true holds
|
||||||
|
auto getTip= [](const std::vector<TriangleHelper>& vec){
|
||||||
|
for(auto element:vec){
|
||||||
|
if(element.isTip){
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vec[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
//get the vertex Index bevor index in relation to the container length
|
||||||
|
auto getPrev = [](int index, int length){
|
||||||
|
return (index-1)>0?(index-1):(length-1);
|
||||||
|
};
|
||||||
|
|
||||||
|
//get the vertex Index after index in relation to the container lenght
|
||||||
|
auto getPost = [](int index, int length){
|
||||||
|
return (index+1)%length;
|
||||||
|
};
|
||||||
|
|
||||||
|
//return if the vertex is a tip
|
||||||
|
auto isTip = [](float angle){
|
||||||
|
return angle<180.f;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<TriangleHelper> Vertices;
|
||||||
|
std::vector<Triangle> Triangles;
|
||||||
|
|
||||||
|
//set up all vertices and calculate intirior angle
|
||||||
|
for(int i=0; i<static_cast<int>(polyPoints.size()); i++){
|
||||||
|
TriangleHelper helper;
|
||||||
|
int prev = getPrev(i, static_cast<int>(polyPoints.size()));
|
||||||
|
int post = getPost(i, static_cast<int>(polyPoints.size()));
|
||||||
|
|
||||||
|
helper.vertex = polyPoints[static_cast<size_t>(i)];
|
||||||
|
helper.index = i;
|
||||||
|
|
||||||
|
helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)],
|
||||||
|
polyPoints[static_cast<size_t>(prev)],
|
||||||
|
polyPoints[static_cast<size_t>(post)]);
|
||||||
|
helper.isTip = isTip(helper.interiorAngle);
|
||||||
|
Vertices.push_back(helper);
|
||||||
|
}
|
||||||
|
|
||||||
|
//search triangles based on the intirior angles of each vertey
|
||||||
|
while(Triangles.size() != polyPoints.size()-2){
|
||||||
|
Triangle tri;
|
||||||
|
TriangleHelper smallest = getTip(Vertices);
|
||||||
|
int prev = getPrev(smallest.index, static_cast<int>(Vertices.size()));
|
||||||
|
int post = getPost(smallest.index, static_cast<int>(Vertices.size()));
|
||||||
|
|
||||||
|
//set triangle and push it
|
||||||
|
tri.A = Vertices[static_cast<size_t>(prev)].vertex;
|
||||||
|
tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex;
|
||||||
|
tri.C = Vertices[static_cast<size_t>(post)].vertex;
|
||||||
|
Triangles.push_back(tri);
|
||||||
|
|
||||||
|
//update Vertice array
|
||||||
|
Vertices.erase(Vertices.begin()+smallest.index);
|
||||||
|
for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++){
|
||||||
|
Vertices[i].index-=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//update post und prev index
|
||||||
|
post = post-1;
|
||||||
|
prev = prev<smallest.index?prev:(prev-1);
|
||||||
|
|
||||||
|
//calcultae neighboors of prev and post to calculate new interior angles
|
||||||
|
int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size()));
|
||||||
|
int postOfPrev = getPost(prev, static_cast<int>(Vertices.size()));
|
||||||
|
|
||||||
|
int prevOfPost = getPrev(post, static_cast<int>(Vertices.size()));
|
||||||
|
int postOfPost = getPost(post, static_cast<int>(Vertices.size()));
|
||||||
|
|
||||||
|
//update vertices with interior angles
|
||||||
|
//updtae prev
|
||||||
|
Vertices[static_cast<size_t>(prev)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(prev)].vertex,
|
||||||
|
Vertices[static_cast<size_t>(prevOfPrev)].vertex,
|
||||||
|
Vertices[static_cast<size_t>(postOfPrev)].vertex);
|
||||||
|
Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle);
|
||||||
|
//update post
|
||||||
|
Vertices[static_cast<size_t>(post)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(post)].vertex,
|
||||||
|
Vertices[static_cast<size_t>(prevOfPost)].vertex,
|
||||||
|
Vertices[static_cast<size_t>(postOfPost)].vertex);
|
||||||
|
Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle);
|
||||||
|
|
||||||
|
}
|
||||||
|
return Triangles;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
|
||||||
|
for(auto triangle : triangles){
|
||||||
|
if(IntelliHelper::isInTriangle(triangle.A ,triangle.B, triangle.C, point)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,17 +2,20 @@
|
|||||||
#define INTELLIHELPER_H
|
#define INTELLIHELPER_H
|
||||||
|
|
||||||
#include<QPoint>
|
#include<QPoint>
|
||||||
|
#include<vector>
|
||||||
|
|
||||||
|
struct Triangle{
|
||||||
|
QPoint A,B,C;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace IntelliHelper {
|
||||||
|
|
||||||
|
|
||||||
class IntelliHelper{
|
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
static inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){
|
|
||||||
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
|
return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){
|
inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){
|
||||||
float val1, val2, val3;
|
float val1, val2, val3;
|
||||||
bool neg, pos;
|
bool neg, pos;
|
||||||
|
|
||||||
@@ -25,6 +28,11 @@ public:
|
|||||||
|
|
||||||
return !(neg && pos);
|
return !(neg && pos);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
|
||||||
|
|
||||||
|
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -24,9 +24,11 @@ SOURCES += \
|
|||||||
IntelliHelper/IntelliHelper.cpp \
|
IntelliHelper/IntelliHelper.cpp \
|
||||||
Layer/PaintingArea.cpp \
|
Layer/PaintingArea.cpp \
|
||||||
Tool/IntelliTool.cpp \
|
Tool/IntelliTool.cpp \
|
||||||
|
Tool/IntelliToolCircle.cpp \
|
||||||
Tool/IntelliToolLine.cpp \
|
Tool/IntelliToolLine.cpp \
|
||||||
Tool/IntelliToolPen.cpp \
|
Tool/IntelliToolPen.cpp \
|
||||||
Tool/IntelliToolPlain.cpp \
|
Tool/IntelliToolPlain.cpp \
|
||||||
|
Tool/IntelliToolRectangle.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
@@ -38,9 +40,12 @@ HEADERS += \
|
|||||||
IntelliHelper/IntelliHelper.h \
|
IntelliHelper/IntelliHelper.h \
|
||||||
Layer/PaintingArea.h \
|
Layer/PaintingArea.h \
|
||||||
Tool/IntelliTool.h \
|
Tool/IntelliTool.h \
|
||||||
|
Tool/IntelliToolCircle.h \
|
||||||
Tool/IntelliToolLine.h \
|
Tool/IntelliToolLine.h \
|
||||||
Tool/IntelliToolPen.h \
|
Tool/IntelliToolPen.h \
|
||||||
Tool/IntelliToolPlain.h
|
Tool/IntelliToolPlain.h \
|
||||||
|
Tool/IntelliToolRectangle.h \
|
||||||
|
Tool/intellitoolcircle.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
widget.ui
|
widget.ui
|
||||||
|
|||||||
@@ -13,10 +13,13 @@
|
|||||||
#include "Tool/IntelliToolPen.h"
|
#include "Tool/IntelliToolPen.h"
|
||||||
#include "Tool/IntelliToolPlain.h"
|
#include "Tool/IntelliToolPlain.h"
|
||||||
#include "Tool/IntelliToolLine.h"
|
#include "Tool/IntelliToolLine.h"
|
||||||
|
#include "Tool/IntelliToolCircle.h"
|
||||||
|
#include "Tool/IntelliToolRectangle.h"
|
||||||
|
|
||||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||||
:QWidget(parent){
|
:QWidget(parent){
|
||||||
this->Tool = nullptr;
|
//test yout tool here and reset after accomplished test
|
||||||
|
this->Tool = new IntelliToolRectangle(this, &colorPicker);
|
||||||
this->setUp(maxWidth, maxHeight);
|
this->setUp(maxWidth, maxHeight);
|
||||||
//tetsing
|
//tetsing
|
||||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||||
@@ -32,7 +35,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
|||||||
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
||||||
layerBundle[1].alpha=200;
|
layerBundle[1].alpha=200;
|
||||||
|
|
||||||
activeLayer=0;
|
activeLayer=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintingArea::~PaintingArea(){
|
PaintingArea::~PaintingArea(){
|
||||||
@@ -161,12 +164,12 @@ void PaintingArea::slotActivateLayer(int a){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PaintingArea::colorPickerSetFirstColor(){
|
void PaintingArea::colorPickerSetFirstColor(){
|
||||||
QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color");
|
QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color", QColorDialog::DontUseNativeDialog);
|
||||||
this->colorPicker.setFirstColor(clr);
|
this->colorPicker.setFirstColor(clr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintingArea::colorPickerSetSecondColor(){
|
void PaintingArea::colorPickerSetSecondColor(){
|
||||||
QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color");
|
QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color", QColorDialog::DontUseNativeDialog);
|
||||||
this->colorPicker.setSecondColor(clr);
|
this->colorPicker.setSecondColor(clr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +234,14 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event){
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PaintingArea::wheelEvent(QWheelEvent *event){
|
||||||
|
QPoint numDegrees = event->angleDelta() / 8;
|
||||||
|
if(!numDegrees.isNull()){
|
||||||
|
QPoint numSteps = numDegrees / 15;
|
||||||
|
Tool->onWheelScrolled(numSteps.y()*-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// QPainter provides functions to draw on the widget
|
// QPainter provides functions to draw on the widget
|
||||||
// The QPaintEvent is sent to widgets that need to
|
// The QPaintEvent is sent to widgets that need to
|
||||||
// update themselves
|
// update themselves
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ struct LayerObject{
|
|||||||
int widthOffset;
|
int widthOffset;
|
||||||
int hightOffset;
|
int hightOffset;
|
||||||
int alpha=255;
|
int alpha=255;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PaintingArea : public QWidget
|
class PaintingArea : public QWidget
|
||||||
@@ -70,6 +68,7 @@ protected:
|
|||||||
void mouseMoveEvent(QMouseEvent *event) override;
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
// Updates the painting area where we are painting
|
// Updates the painting area where we are painting
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
@@ -82,7 +81,6 @@ private:
|
|||||||
void activateUpperLayer();
|
void activateUpperLayer();
|
||||||
void activateLowerLayer();
|
void activateLowerLayer();
|
||||||
|
|
||||||
|
|
||||||
QImage* Canvas;
|
QImage* Canvas;
|
||||||
int maxWidth;
|
int maxWidth;
|
||||||
int maxHeight;
|
int maxHeight;
|
||||||
@@ -103,4 +101,3 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ void IntelliTool::onMouseMoved(int x, int y){
|
|||||||
Canvas->image->calculateVisiblity();
|
Canvas->image->calculateVisiblity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntelliTool::onWheelScrolled(int value){
|
||||||
|
//if needed for future general tasks implement in here
|
||||||
|
}
|
||||||
|
|
||||||
void IntelliTool::createToolLayer(){
|
void IntelliTool::createToolLayer(){
|
||||||
Area->createTempLayerAfter(Area->activeLayer);
|
Area->createTempLayerAfter(Area->activeLayer);
|
||||||
this->Active=&Area->layerBundle[Area->activeLayer];
|
this->Active=&Area->layerBundle[Area->activeLayer];
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public:
|
|||||||
virtual void onMouseLeftPressed(int x, int y);
|
virtual void onMouseLeftPressed(int x, int y);
|
||||||
virtual void onMouseLeftReleased(int x, int y);
|
virtual void onMouseLeftReleased(int x, int y);
|
||||||
|
|
||||||
|
virtual void onWheelScrolled(int value);
|
||||||
|
|
||||||
virtual void onMouseMoved(int x, int y);
|
virtual void onMouseMoved(int x, int y);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
88
src/Tool/IntelliToolCircle.cpp
Normal file
88
src/Tool/IntelliToolCircle.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "IntelliToolCircle.h"
|
||||||
|
#include "Layer/PaintingArea.h"
|
||||||
|
#include "QInputDialog"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||||
|
:IntelliTool(Area, colorPicker){
|
||||||
|
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||||
|
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IntelliToolCircle::~IntelliToolCircle(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::drawCyrcle(int radius){
|
||||||
|
int outer = radius+20;
|
||||||
|
QColor inner = this->colorPicker->getSecondColor();
|
||||||
|
inner.setAlpha(alphaInner);
|
||||||
|
int yMin, yMax, xMin, xMax;
|
||||||
|
yMin = Middle.y()-radius;
|
||||||
|
yMax = Middle.y()+radius;
|
||||||
|
// x = x0+-sqrt(r2-(y-y0)2)
|
||||||
|
for(int i=yMin; i<=yMax; i++){
|
||||||
|
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||||
|
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||||
|
this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO implement circle drawing algorithm bresenham
|
||||||
|
radius = radius +(this->edgeWidth/2.)-1.;
|
||||||
|
yMin = (Middle.y()-radius);
|
||||||
|
yMax = (Middle.y()+radius);
|
||||||
|
for(int i=yMin; i<=yMax; i++){
|
||||||
|
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||||
|
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||||
|
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
|
||||||
|
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
xMin = (Middle.x()-radius);
|
||||||
|
xMax = (Middle.x()+radius);
|
||||||
|
for(int i=xMin; i<=xMax; i++){
|
||||||
|
int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2));
|
||||||
|
int yMax = Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2));
|
||||||
|
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
|
||||||
|
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::onMouseRightPressed(int x, int y){
|
||||||
|
IntelliTool::onMouseRightPressed(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::onMouseRightReleased(int x, int y){
|
||||||
|
IntelliTool::onMouseRightReleased(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
|
||||||
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
|
this->Middle=QPoint(x,y);
|
||||||
|
int radius = 1;
|
||||||
|
drawCyrcle(radius);
|
||||||
|
Canvas->image->calculateVisiblity();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::onMouseLeftReleased(int x, int y){
|
||||||
|
IntelliTool::onMouseLeftReleased(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::onWheelScrolled(int value){
|
||||||
|
IntelliTool::onWheelScrolled(value);
|
||||||
|
this->edgeWidth+=value;
|
||||||
|
if(this->edgeWidth<=0){
|
||||||
|
this->edgeWidth=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolCircle::onMouseMoved(int x, int y){
|
||||||
|
IntelliTool::onMouseMoved(x,y);
|
||||||
|
if(this->drawing){
|
||||||
|
this->Canvas->image->drawPlain(Qt::transparent);
|
||||||
|
QPoint next(x,y);
|
||||||
|
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
|
||||||
|
drawCyrcle(radius);
|
||||||
|
}
|
||||||
|
IntelliTool::onMouseMoved(x,y);
|
||||||
|
}
|
||||||
28
src/Tool/IntelliToolCircle.h
Normal file
28
src/Tool/IntelliToolCircle.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef INTELLITOOLCIRCLE_H
|
||||||
|
#define INTELLITOOLCIRCLE_H
|
||||||
|
#include "IntelliTool.h"
|
||||||
|
|
||||||
|
#include "QColor"
|
||||||
|
#include "QPoint"
|
||||||
|
|
||||||
|
class IntelliToolCircle : public IntelliTool{
|
||||||
|
void drawCyrcle(int radius);
|
||||||
|
|
||||||
|
QPoint Middle;
|
||||||
|
int alphaInner;
|
||||||
|
int edgeWidth;
|
||||||
|
public:
|
||||||
|
IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||||
|
virtual ~IntelliToolCircle() override;
|
||||||
|
|
||||||
|
virtual void onMouseRightPressed(int x, int y) override;
|
||||||
|
virtual void onMouseRightReleased(int x, int y) override;
|
||||||
|
virtual void onMouseLeftPressed(int x, int y) override;
|
||||||
|
virtual void onMouseLeftReleased(int x, int y) override;
|
||||||
|
|
||||||
|
virtual void onWheelScrolled(int value) override;
|
||||||
|
|
||||||
|
virtual void onMouseMoved(int x, int y) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INTELLITOOLCIRCLE_H
|
||||||
@@ -34,6 +34,14 @@ void IntelliToolLine::onMouseLeftReleased(int x, int y){
|
|||||||
IntelliTool::onMouseLeftReleased(x,y);
|
IntelliTool::onMouseLeftReleased(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntelliToolLine::onWheelScrolled(int value){
|
||||||
|
IntelliTool::onWheelScrolled(value);
|
||||||
|
this->lineWidth+=value;
|
||||||
|
if(this->lineWidth<=0){
|
||||||
|
this->lineWidth=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IntelliToolLine::onMouseMoved(int x, int y){
|
void IntelliToolLine::onMouseMoved(int x, int y){
|
||||||
IntelliTool::onMouseMoved(x,y);
|
IntelliTool::onMouseMoved(x,y);
|
||||||
if(this->drawing){
|
if(this->drawing){
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public:
|
|||||||
virtual void onMouseLeftPressed(int x, int y) override;
|
virtual void onMouseLeftPressed(int x, int y) override;
|
||||||
virtual void onMouseLeftReleased(int x, int y) override;
|
virtual void onMouseLeftReleased(int x, int y) override;
|
||||||
|
|
||||||
|
virtual void onWheelScrolled(int value) override;
|
||||||
|
|
||||||
virtual void onMouseMoved(int x, int y) override;
|
virtual void onMouseMoved(int x, int y) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -40,3 +40,11 @@ void IntelliToolPen::onMouseMoved(int x, int y){
|
|||||||
}
|
}
|
||||||
IntelliTool::onMouseMoved(x,y);
|
IntelliTool::onMouseMoved(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntelliToolPen::onWheelScrolled(int value){
|
||||||
|
IntelliTool::onWheelScrolled(value);
|
||||||
|
this->penWidth+=value;
|
||||||
|
if(this->penWidth<=0){
|
||||||
|
this->penWidth=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ public:
|
|||||||
virtual void onMouseLeftPressed(int x, int y) override;
|
virtual void onMouseLeftPressed(int x, int y) override;
|
||||||
virtual void onMouseLeftReleased(int x, int y) override;
|
virtual void onMouseLeftReleased(int x, int y) override;
|
||||||
|
|
||||||
|
virtual void onWheelScrolled(int value) override;
|
||||||
|
|
||||||
virtual void onMouseMoved(int x, int y) override;
|
virtual void onMouseMoved(int x, int y) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,3 +28,7 @@ void IntelliToolPlainTool::onMouseRightReleased(int x, int y){
|
|||||||
void IntelliToolPlainTool::onMouseMoved(int x, int y){
|
void IntelliToolPlainTool::onMouseMoved(int x, int y){
|
||||||
IntelliTool::onMouseMoved(x,y);
|
IntelliTool::onMouseMoved(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntelliToolPlainTool::onWheelScrolled(int value){
|
||||||
|
IntelliTool::onWheelScrolled(value);
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ class IntelliToolPlainTool : public IntelliTool{
|
|||||||
public:
|
public:
|
||||||
IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker);
|
IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker);
|
||||||
|
|
||||||
void onMouseLeftPressed(int x, int y) override;
|
virtual void onMouseLeftPressed(int x, int y) override;
|
||||||
void onMouseLeftReleased(int x, int y) override;
|
virtual void onMouseLeftReleased(int x, int y) override;
|
||||||
void onMouseRightPressed(int x, int y) override;
|
virtual void onMouseRightPressed(int x, int y) override;
|
||||||
void onMouseRightReleased(int x, int y) override;
|
virtual void onMouseRightReleased(int x, int y) override;
|
||||||
void onMouseMoved(int x, int y) override;
|
|
||||||
|
virtual void onWheelScrolled(int value) override;
|
||||||
|
|
||||||
|
virtual void onMouseMoved(int x, int y) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
68
src/Tool/IntelliToolRectangle.cpp
Normal file
68
src/Tool/IntelliToolRectangle.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#include"IntelliToolRectangle.h"
|
||||||
|
#include "Layer/PaintingArea.h"
|
||||||
|
#include "QInputDialog"
|
||||||
|
|
||||||
|
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||||
|
:IntelliTool(Area, colorPicker){
|
||||||
|
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||||
|
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
IntelliToolRectangle::~IntelliToolRectangle(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::drawRectangle(QPoint otherCornor){
|
||||||
|
int xMin = std::min(originCornor.x(), otherCornor.x());
|
||||||
|
int xMax = std::max(originCornor.x(), otherCornor.x());
|
||||||
|
|
||||||
|
int yMin = std::min(originCornor.y(), otherCornor.y());
|
||||||
|
int yMax = std::max(originCornor.y(), otherCornor.y());
|
||||||
|
|
||||||
|
QColor clr = colorPicker->getSecondColor();
|
||||||
|
clr.setAlpha(alphaInner);
|
||||||
|
for(int y=yMin; y<=yMax; y++){
|
||||||
|
this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1);
|
||||||
|
}
|
||||||
|
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||||
|
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||||
|
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||||
|
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::onMouseRightPressed(int x, int y){
|
||||||
|
IntelliTool::onMouseRightPressed(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::onMouseRightReleased(int x, int y){
|
||||||
|
IntelliTool::onMouseRightReleased(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::onMouseLeftPressed(int x, int y){
|
||||||
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
|
this->originCornor=QPoint(x,y);
|
||||||
|
drawRectangle(originCornor);
|
||||||
|
Canvas->image->calculateVisiblity();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::onMouseLeftReleased(int x, int y){
|
||||||
|
IntelliTool::onMouseLeftReleased(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::onMouseMoved(int x, int y){
|
||||||
|
IntelliTool::onMouseMoved(x,y);
|
||||||
|
if(this->drawing){
|
||||||
|
this->Canvas->image->drawPlain(Qt::transparent);
|
||||||
|
QPoint next(x,y);
|
||||||
|
drawRectangle(next);
|
||||||
|
}
|
||||||
|
IntelliTool::onMouseMoved(x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IntelliToolRectangle::onWheelScrolled(int value){
|
||||||
|
IntelliTool::onWheelScrolled(value);
|
||||||
|
this->edgeWidth+=value;
|
||||||
|
if(this->edgeWidth<=0){
|
||||||
|
this->edgeWidth=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/Tool/IntelliToolRectangle.h
Normal file
29
src/Tool/IntelliToolRectangle.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef INTELLIRECTANGLETOOL_H
|
||||||
|
#define INTELLIRECTANGLETOOL_H
|
||||||
|
|
||||||
|
#include "IntelliTool.h"
|
||||||
|
|
||||||
|
#include "QColor"
|
||||||
|
#include "QPoint"
|
||||||
|
|
||||||
|
class IntelliToolRectangle : public IntelliTool{
|
||||||
|
void drawRectangle(QPoint otherCornor);
|
||||||
|
|
||||||
|
QPoint originCornor;
|
||||||
|
int alphaInner;
|
||||||
|
int edgeWidth;
|
||||||
|
public:
|
||||||
|
IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||||
|
virtual ~IntelliToolRectangle() override;
|
||||||
|
|
||||||
|
virtual void onMouseRightPressed(int x, int y) override;
|
||||||
|
virtual void onMouseRightReleased(int x, int y) override;
|
||||||
|
virtual void onMouseLeftPressed(int x, int y) override;
|
||||||
|
virtual void onMouseLeftReleased(int x, int y) override;
|
||||||
|
|
||||||
|
virtual void onWheelScrolled(int value) override;
|
||||||
|
|
||||||
|
virtual void onMouseMoved(int x, int y) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // INTELLIRECTANGLETOOL_H
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "GUI/IntelliPhotoGui.h"
|
#include "GUI/IntelliPhotoGui.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "IntelliHelper/IntelliHelper.h"
|
||||||
|
#include<vector>
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
// The main application
|
// The main application
|
||||||
|
|||||||
Reference in New Issue
Block a user