mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-14 20:30:32 +02:00
Merge branch 'dev' into dev-docs
This commit is contained in:
@@ -17,11 +17,13 @@ IntelliPhotoGui::IntelliPhotoGui(){
|
|||||||
// set style of the gui
|
// set style of the gui
|
||||||
setIntelliStyle();
|
setIntelliStyle();
|
||||||
// Size the app
|
// Size the app
|
||||||
|
resize(600,600);
|
||||||
showMaximized();
|
showMaximized();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// User tried to close the app
|
// User tried to close the app
|
||||||
void IntelliPhotoGui::closeEvent(QCloseEvent *event){
|
void IntelliPhotoGui::closeEvent(QCloseEvent*event){
|
||||||
// If they try to close maybeSave() returns true
|
// If they try to close maybeSave() returns true
|
||||||
// if no changes have been made and the app closes
|
// if no changes have been made and the app closes
|
||||||
if (maybeSave()) {
|
if (maybeSave()) {
|
||||||
@@ -55,7 +57,7 @@ void IntelliPhotoGui::slotOpen(){
|
|||||||
// Called when the user clicks Save As in the menu
|
// Called when the user clicks Save As in the menu
|
||||||
void IntelliPhotoGui::slotSave(){
|
void IntelliPhotoGui::slotSave(){
|
||||||
// A QAction represents the action of the user clicking
|
// A QAction represents the action of the user clicking
|
||||||
QAction *action = qobject_cast<QAction *>(sender());
|
QAction*action = qobject_cast<QAction*>(sender());
|
||||||
|
|
||||||
// Stores the array of bytes of the users data
|
// Stores the array of bytes of the users data
|
||||||
QByteArray fileFormat = action->data().toByteArray();
|
QByteArray fileFormat = action->data().toByteArray();
|
||||||
@@ -102,14 +104,6 @@ void IntelliPhotoGui::slotDeleteLayer(){
|
|||||||
paintingArea->deleteLayer(layerNumber);
|
paintingArea->deleteLayer(layerNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
void slotCreatePenTool(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void slotCreateFloodFillTool(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSetActiveAlpha(){
|
void IntelliPhotoGui::slotSetActiveAlpha(){
|
||||||
// Stores button value
|
// Stores button value
|
||||||
bool ok1, ok2;
|
bool ok1, ok2;
|
||||||
@@ -202,7 +196,7 @@ void IntelliPhotoGui::slotSetActiveLayer(){
|
|||||||
{
|
{
|
||||||
paintingArea->setLayerToActive(layer);
|
paintingArea->setLayerToActive(layer);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
void IntelliPhotoGui::slotSetFirstColor(){
|
void IntelliPhotoGui::slotSetFirstColor(){
|
||||||
paintingArea->colorPickerSetFirstColor();
|
paintingArea->colorPickerSetFirstColor();
|
||||||
@@ -243,7 +237,7 @@ void IntelliPhotoGui::createActions(){
|
|||||||
QString text = tr("%1...").arg(QString(format).toUpper());
|
QString text = tr("%1...").arg(QString(format).toUpper());
|
||||||
|
|
||||||
// Create an action for each file format
|
// Create an action for each file format
|
||||||
QAction *action = new QAction(text, this);
|
QAction*action = new QAction(text, this);
|
||||||
|
|
||||||
// Set an action for each file format
|
// Set an action for each file format
|
||||||
action->setData(format);
|
action->setData(format);
|
||||||
@@ -256,7 +250,7 @@ void IntelliPhotoGui::createActions(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//set exporter to actions
|
//set exporter to actions
|
||||||
QAction *pngSaveAction = new QAction("PNG-8", this);
|
QAction*pngSaveAction = new QAction("PNG-8", this);
|
||||||
pngSaveAction->setData("PNG");
|
pngSaveAction->setData("PNG");
|
||||||
// When clicked call IntelliPhotoGui::save()
|
// When clicked call IntelliPhotoGui::save()
|
||||||
connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
|
connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave()));
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ private:
|
|||||||
// set style of the GUI
|
// set style of the GUI
|
||||||
void setIntelliStyle();
|
void setIntelliStyle();
|
||||||
|
|
||||||
|
|
||||||
// Will check if changes have occurred since last save
|
// Will check if changes have occurred since last save
|
||||||
bool maybeSave();
|
bool maybeSave();
|
||||||
// Opens the Save dialog and saves
|
// Opens the Save dialog and saves
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ SOURCES += \
|
|||||||
Tool/IntelliToolLine.cpp \
|
Tool/IntelliToolLine.cpp \
|
||||||
Tool/IntelliToolPen.cpp \
|
Tool/IntelliToolPen.cpp \
|
||||||
Tool/IntelliToolPlain.cpp \
|
Tool/IntelliToolPlain.cpp \
|
||||||
|
Tool/IntelliToolPolygon.cpp \
|
||||||
Tool/IntelliToolRectangle.cpp \
|
Tool/IntelliToolRectangle.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
@@ -46,11 +47,11 @@ HEADERS += \
|
|||||||
Tool/IntelliToolLine.h \
|
Tool/IntelliToolLine.h \
|
||||||
Tool/IntelliToolPen.h \
|
Tool/IntelliToolPen.h \
|
||||||
Tool/IntelliToolPlain.h \
|
Tool/IntelliToolPlain.h \
|
||||||
Tool/IntelliToolRectangle.h \
|
Tool/IntelliToolPolygon.h \
|
||||||
Tool/intellitoolcircle.h
|
Tool/IntelliToolRectangle.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
widget.ui
|
mainwindow.ui
|
||||||
|
|
||||||
QMAKE_CXXFLAGS
|
QMAKE_CXXFLAGS
|
||||||
QMAKE_LFLAGS
|
QMAKE_LFLAGS
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Tool/IntelliToolCircle.h"
|
#include "Tool/IntelliToolCircle.h"
|
||||||
#include "Tool/IntelliToolRectangle.h"
|
#include "Tool/IntelliToolRectangle.h"
|
||||||
#include "Tool/IntelliToolFloodFill.h"
|
#include "Tool/IntelliToolFloodFill.h"
|
||||||
|
#include "Tool/IntelliToolPolygon.h"
|
||||||
|
|
||||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||||
:QWidget(parent){
|
:QWidget(parent){
|
||||||
@@ -24,7 +25,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
|||||||
this->Tool = new IntelliToolFloodFill(this, &colorPicker);
|
this->Tool = new IntelliToolFloodFill(this, &colorPicker);
|
||||||
this->setUp(maxWidth, maxHeight);
|
this->setUp(maxWidth, maxHeight);
|
||||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||||
layerBundle[0].image->drawPlain(QColor(255,0,0,255));
|
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
||||||
std::vector<QPoint> polygon;
|
std::vector<QPoint> polygon;
|
||||||
polygon.push_back(QPoint(100,000));
|
polygon.push_back(QPoint(100,000));
|
||||||
polygon.push_back(QPoint(200,100));
|
polygon.push_back(QPoint(200,100));
|
||||||
@@ -36,7 +37,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=1;
|
activeLayer=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintingArea::~PaintingArea(){
|
PaintingArea::~PaintingArea(){
|
||||||
@@ -193,6 +194,14 @@ void PaintingArea::createLineTool(){
|
|||||||
Tool = new IntelliToolLine(this, &colorPicker);
|
Tool = new IntelliToolLine(this, &colorPicker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PaintingArea::getWidthActiveLayer(){
|
||||||
|
return layerBundle.operator[](activeLayer).width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int PaintingArea::getHeightActiveLayer(){
|
||||||
|
return layerBundle.operator[](activeLayer).hight;
|
||||||
|
}
|
||||||
|
|
||||||
// If a mouse button is pressed check if it was the
|
// If a mouse button is pressed check if it was the
|
||||||
// left button and if so store the current position
|
// left button and if so store the current position
|
||||||
// Set that we are currently drawing
|
// Set that we are currently drawing
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public:
|
|||||||
void createPlainTool();
|
void createPlainTool();
|
||||||
void createLineTool();
|
void createLineTool();
|
||||||
|
|
||||||
|
//get Width and Height of active Layer
|
||||||
|
int getWidthActiveLayer();
|
||||||
|
int getHeightActiveLayer();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Events to handle
|
// Events to handle
|
||||||
void slotActivateLayer(int a);
|
void slotActivateLayer(int a);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){
|
|||||||
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
||||||
IntelliTool::onMouseLeftPressed(x,y);
|
IntelliTool::onMouseLeftPressed(x,y);
|
||||||
this->start=QPoint(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();
|
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
|
||||||
23
src/mainwindow.ui
Normal file
23
src/mainwindow.ui
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>MainWindow</class>
|
||||||
|
<widget class="QMainWindow" name="MainWindow">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>542</width>
|
||||||
|
<height>459</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>IntelliPhoto</string>
|
||||||
|
</property>
|
||||||
|
<property name="animated">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget"/>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>Widget</class>
|
|
||||||
<widget class="QWidget" name="Widget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>360</width>
|
|
||||||
<height>206</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Widget</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
||||||
Reference in New Issue
Block a user