Restyled project for uncrustify

This commit is contained in:
2019-12-19 18:27:46 +01:00
parent c415a53c83
commit a838e3869f
30 changed files with 1649 additions and 1650 deletions

View File

@@ -195,7 +195,7 @@ void IntelliPhotoGui::slotSetActiveLayer(){
if (ok1) if (ok1)
{ {
paintingArea->setLayerToActive(layer); paintingArea->setLayerToActive(layer);
} }
} }
void IntelliPhotoGui::slotSetFirstColor(){ void IntelliPhotoGui::slotSetFirstColor(){
@@ -203,7 +203,7 @@ void IntelliPhotoGui::slotSetFirstColor(){
} }
void IntelliPhotoGui::slotSetSecondColor(){ void IntelliPhotoGui::slotSetSecondColor(){
paintingArea->colorPickerSetSecondColor(); paintingArea->colorPickerSetSecondColor();
} }
void IntelliPhotoGui::slotSwitchColor(){ void IntelliPhotoGui::slotSwitchColor(){
@@ -223,19 +223,19 @@ void IntelliPhotoGui::slotCreateLineTool(){
} }
void IntelliPhotoGui::slotCreateRectangleTool(){ void IntelliPhotoGui::slotCreateRectangleTool(){
paintingArea->createRectangleTool(); paintingArea->createRectangleTool();
} }
void IntelliPhotoGui::slotCreateCircleTool(){ void IntelliPhotoGui::slotCreateCircleTool(){
paintingArea->createCircleTool(); paintingArea->createCircleTool();
} }
void IntelliPhotoGui::slotCreatePolygonTool(){ void IntelliPhotoGui::slotCreatePolygonTool(){
paintingArea->createPolygonTool(); paintingArea->createPolygonTool();
} }
void IntelliPhotoGui::slotCreateFloodFillTool(){ void IntelliPhotoGui::slotCreateFloodFillTool(){
paintingArea->createFloodFillTool(); paintingArea->createFloodFillTool();
} }
// Open an about dialog // Open an about dialog
@@ -342,17 +342,17 @@ void IntelliPhotoGui::createActions(){
actionCreateLineTool = new QAction(tr("&Line"), this); actionCreateLineTool = new QAction(tr("&Line"), this);
connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool())); connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
actionCreateCircleTool = new QAction(tr("&Circle"), this); actionCreateCircleTool = new QAction(tr("&Circle"), this);
connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool())); connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool()));
actionCreateRectangleTool = new QAction(tr("&Rectangle"), this); actionCreateRectangleTool = new QAction(tr("&Rectangle"), this);
connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool())); connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool()));
actionCreatePolygonTool = new QAction(tr("&Polygon"), this); actionCreatePolygonTool = new QAction(tr("&Polygon"), this);
connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool())); connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool()));
actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this); actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this);
connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool())); connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
// Create about action and tie to IntelliPhotoGui::about() // Create about action and tie to IntelliPhotoGui::about()
actionAboutDialog = new QAction(tr("&About"), this); actionAboutDialog = new QAction(tr("&About"), this);
@@ -405,10 +405,10 @@ void IntelliPhotoGui::createMenus(){
toolMenu->addAction(actionCreatePenTool); toolMenu->addAction(actionCreatePenTool);
toolMenu->addAction(actionCreatePlainTool); toolMenu->addAction(actionCreatePlainTool);
toolMenu->addAction(actionCreateLineTool); toolMenu->addAction(actionCreateLineTool);
toolMenu->addAction(actionCreateRectangleTool); toolMenu->addAction(actionCreateRectangleTool);
toolMenu->addAction(actionCreateCircleTool); toolMenu->addAction(actionCreateCircleTool);
toolMenu->addAction(actionCreatePolygonTool); toolMenu->addAction(actionCreatePolygonTool);
toolMenu->addAction(actionCreateFloodFillTool); toolMenu->addAction(actionCreateFloodFillTool);
toolMenu->addSeparator(); toolMenu->addSeparator();
toolMenu->addMenu(colorMenu); toolMenu->addMenu(colorMenu);

View File

@@ -19,123 +19,123 @@ class IntelliColorPicker;
/*! /*!
* \brief The IntelliPhotoGui class handles the graphical user interface for the intelliPhoto program * \brief The IntelliPhotoGui class handles the graphical user interface for the intelliPhoto program
*/ */
class IntelliPhotoGui : public QMainWindow{ class IntelliPhotoGui : public QMainWindow {
// Declares our class as a QObject which is the base class // Declares our class as a QObject which is the base class
// for all Qt objects // for all Qt objects
// QObjects handle events // QObjects handle events
Q_OBJECT Q_OBJECT
public: public:
/*! /*!
* \brief The IntelliPhotoGui method is the constructor and is used to create a new instance of the main program window * \brief The IntelliPhotoGui method is the constructor and is used to create a new instance of the main program window
*/ */
IntelliPhotoGui(); IntelliPhotoGui();
protected: protected:
// Function used to close an event // Function used to close an event
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent*event) override;
private slots: private slots:
// meta slots here (need further ) // meta slots here (need further )
void slotOpen(); void slotOpen();
void slotSave(); void slotSave();
// layer slots here // layer slots here
void slotCreateNewLayer(); void slotCreateNewLayer();
void slotDeleteLayer(); void slotDeleteLayer();
void slotClearActiveLayer(); void slotClearActiveLayer();
void slotSetActiveLayer(); void slotSetActiveLayer();
void slotSetActiveAlpha(); void slotSetActiveAlpha();
void slotPositionMoveUp(); void slotPositionMoveUp();
void slotPositionMoveDown(); void slotPositionMoveDown();
void slotPositionMoveLeft(); void slotPositionMoveLeft();
void slotPositionMoveRight(); void slotPositionMoveRight();
void slotMoveLayerUp(); void slotMoveLayerUp();
void slotMoveLayerDown(); void slotMoveLayerDown();
// color Picker slots here // color Picker slots here
void slotSetFirstColor(); void slotSetFirstColor();
void slotSetSecondColor(); void slotSetSecondColor();
void slotSwitchColor(); void slotSwitchColor();
// tool slots here // tool slots here
void slotCreatePenTool(); void slotCreatePenTool();
void slotCreatePlainTool(); void slotCreatePlainTool();
void slotCreateLineTool(); void slotCreateLineTool();
void slotCreateRectangleTool(); void slotCreateRectangleTool();
void slotCreateCircleTool(); void slotCreateCircleTool();
void slotCreatePolygonTool(); void slotCreatePolygonTool();
void slotCreateFloodFillTool(); void slotCreateFloodFillTool();
// slots for dialogs // slots for dialogs
void slotAboutDialog(); void slotAboutDialog();
private: private:
// Will tie user actions to functions // Will tie user actions to functions
void createActions(); void createActions();
void createMenus(); void createMenus();
// setup GUI elements // setup GUI elements
void createGui(); void createGui();
// 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
bool saveFile(const QByteArray &fileFormat); bool saveFile(const QByteArray &fileFormat);
// What we'll draw on // What we'll draw on
PaintingArea* paintingArea; PaintingArea* paintingArea;
// The menu widgets // The menu widgets
QMenu *saveAsMenu; QMenu*saveAsMenu;
QMenu *fileMenu; QMenu*fileMenu;
QMenu *optionMenu; QMenu*optionMenu;
QMenu *layerMenu; QMenu*layerMenu;
QMenu *colorMenu; QMenu*colorMenu;
QMenu *toolMenu; QMenu*toolMenu;
QMenu *helpMenu; QMenu*helpMenu;
// All the actions that can occur // All the actions that can occur
// meta image actions (need further modularisation) // meta image actions (need further modularisation)
QAction *actionOpen; QAction*actionOpen;
QAction *actionExit; QAction*actionExit;
// color Picker actions // color Picker actions
QAction *actionColorPickerFirstColor; QAction*actionColorPickerFirstColor;
QAction *actionColorPickerSecondColor; QAction*actionColorPickerSecondColor;
QAction *actionColorSwitch; QAction*actionColorSwitch;
// tool actions // tool actions
QAction *actionCreatePenTool; QAction*actionCreatePenTool;
QAction *actionCreatePlainTool; QAction*actionCreatePlainTool;
QAction *actionCreateLineTool; QAction*actionCreateLineTool;
QAction *actionCreateRectangleTool; QAction*actionCreateRectangleTool;
QAction *actionCreateCircleTool; QAction*actionCreateCircleTool;
QAction *actionCreatePolygonTool; QAction*actionCreatePolygonTool;
QAction *actionCreateFloodFillTool; QAction*actionCreateFloodFillTool;
// dialog actions // dialog actions
QAction *actionAboutDialog; QAction*actionAboutDialog;
QAction *actionAboutQtDialog; QAction*actionAboutQtDialog;
// layer change actions // layer change actions
QAction *actionCreateNewLayer; QAction*actionCreateNewLayer;
QAction *actionDeleteLayer; QAction*actionDeleteLayer;
QAction* actionSetActiveLayer; QAction* actionSetActiveLayer;
QAction* actionSetActiveAlpha; QAction* actionSetActiveAlpha;
QAction* actionMovePositionUp; QAction* actionMovePositionUp;
QAction* actionMovePositionDown; QAction* actionMovePositionDown;
QAction* actionMovePositionLeft; QAction* actionMovePositionLeft;
QAction* actionMovePositionRight; QAction* actionMovePositionRight;
QAction* actionMoveLayerUp; QAction* actionMoveLayerUp;
QAction* actionMoveLayerDown; QAction* actionMoveLayerDown;
// Actions tied to specific file formats // Actions tied to specific file formats
QList<QAction *> actionSaveAs; QList<QAction*> actionSaveAs;
// main GUI elements // main GUI elements
QWidget* centralGuiWidget; QWidget* centralGuiWidget;
QGridLayout *mainLayout; QGridLayout*mainLayout;
}; };
#endif #endif

View File

@@ -1,10 +1,10 @@
#include"Image/IntelliImage.h" #include "Image/IntelliImage.h"
#include<QSize> #include <QSize>
#include<QPainter> #include <QPainter>
IntelliImage::IntelliImage(int weight, int height) IntelliImage::IntelliImage(int weight, int height)
:imageData(QSize(weight, height), QImage::Format_ARGB32){ : imageData(QSize(weight, height), QImage::Format_ARGB32){
imageData.fill(QColor(255,255,255,255)); imageData.fill(QColor(255,255,255,255));
} }
IntelliImage::~IntelliImage(){ IntelliImage::~IntelliImage(){
@@ -12,71 +12,71 @@ IntelliImage::~IntelliImage(){
} }
bool IntelliImage::loadImage(const QString &fileName){ bool IntelliImage::loadImage(const QString &fileName){
// Holds the image // Holds the image
QImage loadedImage; QImage loadedImage;
// If the image wasn't loaded leave this function // If the image wasn't loaded leave this function
if (!loadedImage.load(fileName)) if (!loadedImage.load(fileName))
return false; return false;
// scaled Image to size of Layer // scaled Image to size of Layer
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32); imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
return true; return true;
} }
void IntelliImage::resizeImage(QImage *image, const QSize &newSize){ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){
// Check if we need to redraw the image // Check if we need to redraw the image
if (image->size() == newSize) if (image->size() == newSize)
return; return;
// Create a new image to display and fill it with white // Create a new image to display and fill it with white
QImage newImage(newSize, QImage::Format_ARGB32); QImage newImage(newSize, QImage::Format_ARGB32);
newImage.fill(qRgb(255, 255, 255)); newImage.fill(qRgb(255, 255, 255));
// Draw the image // Draw the image
QPainter painter(&newImage); QPainter painter(&newImage);
painter.drawImage(QPoint(0, 0), *image); painter.drawImage(QPoint(0, 0), *image);
*image = newImage; *image = newImage;
} }
void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
// Used to draw on the widget // Used to draw on the widget
QPainter painter(&imageData); QPainter painter(&imageData);
// Set the current settings for the pen // Set the current settings for the pen
painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
// Draw a line from the last registered point to the current // Draw a line from the last registered point to the current
painter.drawPoint(p1); painter.drawPoint(p1);
} }
void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
// Used to draw on the widget // Used to draw on the widget
QPainter painter(&imageData); QPainter painter(&imageData);
// Set the current settings for the pen // Set the current settings for the pen
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
// Draw a line from the last registered point to the current // Draw a line from the last registered point to the current
painter.drawPoint(p1); 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);
// Set the current settings for the pen // Set the current settings for the pen
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
// Draw a line from the last registered point to the current // Draw a line from the last registered point to the current
painter.drawLine(p1, p2); painter.drawLine(p1, p2);
} }
void IntelliImage::drawPlain(const QColor& color){ void IntelliImage::drawPlain(const QColor& color){
imageData.fill(color); imageData.fill(color);
} }
QColor IntelliImage::getPixelColor(QPoint& point){ QColor IntelliImage::getPixelColor(QPoint& point){
return imageData.pixelColor(point); return imageData.pixelColor(point);
} }

View File

@@ -1,19 +1,19 @@
#ifndef INTELLIIMAGE_H #ifndef INTELLIIMAGE_H
#define INTELLIIMAGE_H #define INTELLIIMAGE_H
#include<QImage> #include <QImage>
#include<QPoint> #include <QPoint>
#include<QColor> #include <QColor>
#include<QSize> #include <QSize>
#include<QWidget> #include <QWidget>
#include<vector> #include <vector>
/*! /*!
* \brief The Types, which an Image can be. * \brief The Types, which an Image can be.
*/ */
enum class ImageType{ enum class ImageType {
Raster_Image, Raster_Image,
Shaped_Image Shaped_Image
}; };
class IntelliTool; class IntelliTool;
@@ -21,110 +21,112 @@ class IntelliTool;
/*! /*!
* \brief An abstract class which manages the basic IntelliImage operations. * \brief An abstract class which manages the basic IntelliImage operations.
*/ */
class IntelliImage{ class IntelliImage {
friend IntelliTool; friend IntelliTool;
protected: protected:
void resizeImage(QImage *image, const QSize &newSize); void resizeImage(QImage*image, const QSize &newSize);
/*! /*!
* \brief The underlying image data. * \brief The underlying image data.
*/ */
QImage imageData; QImage imageData;
public: public:
/*! /*!
* \brief The Construcor of the IntelliImage. Given the Image dimensions. * \brief The Construcor of the IntelliImage. Given the Image dimensions.
* \param weight - The weight of the Image. * \param weight - The weight of the Image.
* \param height - The height of the Image. * \param height - The height of the Image.
*/ */
IntelliImage(int weight, int height); IntelliImage(int weight, int height);
/*! /*!
* \brief An Abstract Destructor. * \brief An Abstract Destructor.
*/ */
virtual ~IntelliImage() = 0; virtual ~IntelliImage() = 0;
/*! /*!
* \brief A funtcion used to draw a pixel on the Image with the given Color. * \brief A funtcion used to draw a pixel on the Image with the given Color.
* \param p1 - The coordinates of the pixel, which should be drawn. [Top-Left-System] * \param p1 - The coordinates of the pixel, which should be drawn. [Top-Left-System]
* \param color - The color of the pixel. * \param color - The color of the pixel.
*/ */
virtual void drawPixel(const QPoint &p1, const QColor& color); virtual void drawPixel(const QPoint &p1, const QColor& color);
/*! /*!
* \brief A function that draws A Line between two given Points in a given color. * \brief A function that draws A Line between two given Points in a given color.
* \param p1 - The coordinates of the first Point. * \param p1 - The coordinates of the first Point.
* \param p2 - The coordinates of the second Point. * \param p2 - The coordinates of the second Point.
* \param color - The color of the line. * \param color - The color of the line.
* \param penWidth - The width of the line. * \param penWidth - The width of the line.
*/ */
virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth); virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth);
/*! /*!
* \brief A * \brief A
* \param p1 * \param p1
* \param color * \param color
* \param penWidth * \param penWidth
*/ */
virtual void drawPoint(const QPoint &p1, const QColor& color, const int& penWidth); virtual void drawPoint(const QPoint &p1, const QColor& color, const int& penWidth);
/*! /*!
* \brief A function that clears the whole image in a given Color. * \brief A function that clears the whole image in a given Color.
* \param color - The color, in which the image will be filled. * \param color - The color, in which the image will be filled.
*/ */
virtual void drawPlain(const QColor& color); virtual void drawPlain(const QColor& color);
/*! /*!
* \brief A function returning the displayable ImageData in a requested transparence and size. * \brief A function returning the displayable ImageData in a requested transparence and size.
* \param displaySize - The size, in whcih the Image should be displayed. * \param displaySize - The size, in whcih the Image should be displayed.
* \param alpha - The maximum alpha value, a pixel can have. * \param alpha - The maximum alpha value, a pixel can have.
* \return A QImage which is ready to be displayed. * \return A QImage which is ready to be displayed.
*/ */
virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0; virtual QImage getDisplayable(const QSize& displaySize, int alpha) = 0;
/** /**
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size. * @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
* @param alpha - The maximum alpha value, a pixel can have. * @param alpha - The maximum alpha value, a pixel can have.
* @return A QImage which is ready to be displayed. * @return A QImage which is ready to be displayed.
*/ */
virtual QImage getDisplayable(int alpha=255)=0; virtual QImage getDisplayable(int alpha=255) = 0;
/*! /*!
* \brief A function that copys all that returns a [allocated] Image * \brief A function that copys all that returns a [allocated] Image
* \return A [allocated] Image with all the properties of the instance. * \return A [allocated] Image with all the properties of the instance.
*/ */
virtual IntelliImage* getDeepCopy()=0; virtual IntelliImage* getDeepCopy() = 0;
/*! /*!
* \brief An abstract function that calculates the visiblity of the Image data if needed. * \brief An abstract function that calculates the visiblity of the Image data if needed.
*/ */
virtual void calculateVisiblity()=0; virtual void calculateVisiblity() = 0;
/*! /*!
* \brief An abstract function that sets the data of the visible Polygon, if needed. * \brief An abstract function that sets the data of the visible Polygon, if needed.
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed. * \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
*/ */
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0; virtual void setPolygon(const std::vector<QPoint>& polygonData) = 0;
/*! /*!
* \brief A function that returns the Polygondata if existent. * \brief A function that returns the Polygondata if existent.
* \return The Polygondata if existent. * \return The Polygondata if existent.
*/ */
virtual std::vector<QPoint> getPolygonData(){ return std::vector<QPoint>();} virtual std::vector<QPoint> getPolygonData(){
return std::vector<QPoint>();
}
/*! /*!
* \brief A function that loads and sclaes an image to the fitting dimensions. * \brief A function that loads and sclaes an image to the fitting dimensions.
* \param fileName - The path+name of the image which to loaded. * \param fileName - The path+name of the image which to loaded.
* \return True if the image could be loaded, false otherwise. * \return True if the image could be loaded, false otherwise.
*/ */
virtual bool loadImage(const QString &fileName); virtual bool loadImage(const QString &fileName);
/*! /*!
* \brief A function that returns the pixelcolor at a certain point * \brief A function that returns the pixelcolor at a certain point
* \param point - The point from whcih to get the coordinates. * \param point - The point from whcih to get the coordinates.
* \return The color of the Pixel as QColor. * \return The color of the Pixel as QColor.
*/ */
virtual QColor getPixelColor(QPoint& point); virtual QColor getPixelColor(QPoint& point);
}; };
#endif #endif

View File

@@ -1,10 +1,10 @@
#include"Image/IntelliRasterImage.h" #include "Image/IntelliRasterImage.h"
#include<QPainter> #include <QPainter>
#include<QRect> #include <QRect>
#include<QDebug> #include <QDebug>
IntelliRasterImage::IntelliRasterImage(int weight, int height) IntelliRasterImage::IntelliRasterImage(int weight, int height)
:IntelliImage(weight, height){ : IntelliImage(weight, height){
} }
@@ -13,32 +13,32 @@ IntelliRasterImage::~IntelliRasterImage(){
} }
IntelliImage* IntelliRasterImage::getDeepCopy(){ IntelliImage* IntelliRasterImage::getDeepCopy(){
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height()); IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
raster->imageData.fill(Qt::transparent); raster->imageData.fill(Qt::transparent);
return raster; return raster;
} }
void IntelliRasterImage::calculateVisiblity(){ void IntelliRasterImage::calculateVisiblity(){
// not used in raster image // not used in raster image
} }
QImage IntelliRasterImage::getDisplayable(int alpha){ QImage IntelliRasterImage::getDisplayable(int alpha){
return getDisplayable(imageData.size(), alpha); return getDisplayable(imageData.size(), alpha);
} }
QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
QImage copy = imageData; QImage copy = imageData;
for(int y = 0; y<copy.height(); y++){ for(int y = 0; y<copy.height(); y++) {
for(int x = 0; x<copy.width(); x++){ for(int x = 0; x<copy.width(); x++) {
QColor clr = copy.pixelColor(x,y); QColor clr = copy.pixelColor(x,y);
clr.setAlpha(std::min(alpha, clr.alpha())); clr.setAlpha(std::min(alpha, clr.alpha()));
copy.setPixelColor(x,y, clr); copy.setPixelColor(x,y, clr);
} }
} }
return copy.scaled(displaySize,Qt::IgnoreAspectRatio); return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
} }
void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){ void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n"; qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
return; return;
} }

View File

@@ -1,57 +1,57 @@
#ifndef INTELLIRASTER_H #ifndef INTELLIRASTER_H
#define INTELLIRASTER_H #define INTELLIRASTER_H
#include"Image/IntelliImage.h" #include "Image/IntelliImage.h"
/*! /*!
* \brief The IntelliRasterImage manages a Rasterimage. * \brief The IntelliRasterImage manages a Rasterimage.
*/ */
class IntelliRasterImage : public IntelliImage{ class IntelliRasterImage : public IntelliImage {
friend IntelliTool; friend IntelliTool;
protected: protected:
/*! /*!
* \brief A function that calculates the visibility of the image if a polygon is given. [does nothing in Rasterimage] * \brief A function that calculates the visibility of the image if a polygon is given. [does nothing in Rasterimage]
*/ */
virtual void calculateVisiblity() override; virtual void calculateVisiblity() override;
public: public:
/*! /*!
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions. * \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
* \param weight - The weight of the Image. * \param weight - The weight of the Image.
* \param height - The height of the Image. * \param height - The height of the Image.
*/ */
IntelliRasterImage(int weight, int height); IntelliRasterImage(int weight, int height);
/*! /*!
* \brief An Destructor. * \brief An Destructor.
*/ */
virtual ~IntelliRasterImage() override; virtual ~IntelliRasterImage() override;
/*! /*!
* \brief A function returning the displayable ImageData in a requested transparence and size. * \brief A function returning the displayable ImageData in a requested transparence and size.
* \param displaySize - The size, in whcih the Image should be displayed. * \param displaySize - The size, in whcih the Image should be displayed.
* \param alpha - The maximum alpha value, a pixel can have. * \param alpha - The maximum alpha value, a pixel can have.
* \return A QImage which is ready to be displayed. * \return A QImage which is ready to be displayed.
*/ */
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override; virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
/** /**
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size. * @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
* @param alpha - The maximum alpha value, a pixel can have. * @param alpha - The maximum alpha value, a pixel can have.
* @return A QImage which is ready to be displayed. * @return A QImage which is ready to be displayed.
*/ */
virtual QImage getDisplayable(int alpha=255) override; virtual QImage getDisplayable(int alpha=255) override;
/*! /*!
* \brief A function that copys all that returns a [allocated] Image * \brief A function that copys all that returns a [allocated] Image
* \return A [allocated] Image with all the properties of the instance. * \return A [allocated] Image with all the properties of the instance.
*/ */
virtual IntelliImage* getDeepCopy() override; virtual IntelliImage* getDeepCopy() override;
/*! /*!
* \brief An abstract function that sets the data of the visible Polygon, if needed. * \brief An abstract function that sets the data of the visible Polygon, if needed.
* \param polygonData - The Vertices of the Polygon. Nothing happens. * \param polygonData - The Vertices of the Polygon. Nothing happens.
*/ */
virtual void setPolygon(const std::vector<QPoint>& polygonData) override; virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
}; };
#endif #endif

View File

@@ -1,11 +1,11 @@
#include"Image/IntelliShapedImage.h" #include "Image/IntelliShapedImage.h"
#include"IntelliHelper/IntelliHelper.h" #include "IntelliHelper/IntelliHelper.h"
#include<QPainter> #include <QPainter>
#include<QRect> #include <QRect>
#include<QDebug> #include <QDebug>
IntelliShapedImage::IntelliShapedImage(int weight, int height) IntelliShapedImage::IntelliShapedImage(int weight, int height)
:IntelliRasterImage(weight, height){ : IntelliRasterImage(weight, height){
} }
IntelliShapedImage::~IntelliShapedImage(){ IntelliShapedImage::~IntelliShapedImage(){
@@ -13,66 +13,66 @@ IntelliShapedImage::~IntelliShapedImage(){
} }
QImage IntelliShapedImage::getDisplayable(int alpha){ QImage IntelliShapedImage::getDisplayable(int alpha){
return getDisplayable(imageData.size(),alpha); return getDisplayable(imageData.size(),alpha);
} }
IntelliImage* IntelliShapedImage::getDeepCopy(){ IntelliImage* IntelliShapedImage::getDeepCopy(){
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height()); IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
shaped->setPolygon(this->polygonData); shaped->setPolygon(this->polygonData);
shaped->imageData.fill(Qt::transparent); shaped->imageData.fill(Qt::transparent);
return shaped; return shaped;
} }
void IntelliShapedImage::calculateVisiblity(){ void IntelliShapedImage::calculateVisiblity(){
if(polygonData.size()<=2){ if(polygonData.size()<=2) {
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++) {
clr = imageData.pixel(x,y); clr = imageData.pixel(x,y);
clr.setAlpha(255); clr.setAlpha(255);
imageData.setPixelColor(x,y,clr); imageData.setPixelColor(x,y,clr);
} }
} }
return; return;
} }
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++) {
QPoint ptr(x,y); QPoint ptr(x,y);
clr = imageData.pixelColor(x,y); clr = imageData.pixelColor(x,y);
bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr); bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr);
if(isInPolygon){ if(isInPolygon) {
clr.setAlpha(std::min(255, clr.alpha())); clr.setAlpha(std::min(255, clr.alpha()));
}else{ }else{
clr.setAlpha(0); clr.setAlpha(0);
} }
imageData.setPixelColor(x,y,clr); imageData.setPixelColor(x,y,clr);
} }
} }
} }
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
QImage copy = imageData; QImage copy = imageData;
for(int y = 0; y<copy.height(); y++){ for(int y = 0; y<copy.height(); y++) {
for(int x = 0; x<copy.width(); x++){ for(int x = 0; x<copy.width(); x++) {
QColor clr = copy.pixelColor(x,y); QColor clr = copy.pixelColor(x,y);
clr.setAlpha(std::min(alpha,clr.alpha())); clr.setAlpha(std::min(alpha,clr.alpha()));
copy.setPixelColor(x,y, clr); copy.setPixelColor(x,y, clr);
} }
} }
return copy.scaled(displaySize,Qt::IgnoreAspectRatio); return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
} }
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
if(polygonData.size()<3){ if(polygonData.size()<3) {
this->polygonData.clear(); this->polygonData.clear();
}else{ }else{
this->polygonData.clear(); this->polygonData.clear();
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); triangles = IntelliHelper::calculateTriangles(polygonData);
} }
calculateVisiblity(); calculateVisiblity();
return; return;
} }

View File

@@ -1,76 +1,78 @@
#ifndef INTELLISHAPE_H #ifndef INTELLISHAPE_H
#define INTELLISHAPE_H #define INTELLISHAPE_H
#include"Image/IntelliRasterImage.h" #include "Image/IntelliRasterImage.h"
#include<vector> #include <vector>
#include"IntelliHelper/IntelliHelper.h" #include "IntelliHelper/IntelliHelper.h"
/*! /*!
* \brief The IntelliShapedImage manages a Shapedimage. * \brief The IntelliShapedImage manages a Shapedimage.
*/ */
class IntelliShapedImage : public IntelliRasterImage{ class IntelliShapedImage : public IntelliRasterImage {
friend IntelliTool; friend IntelliTool;
private: private:
/*! /*!
* \brief The Triangulation of the Polygon. Saved here for performance reasons. * \brief The Triangulation of the Polygon. Saved here for performance reasons.
*/ */
std::vector<Triangle> triangles; std::vector<Triangle> triangles;
/*! /*!
* \brief Calculates the visibility based on the underlying polygon. * \brief Calculates the visibility based on the underlying polygon.
*/ */
virtual void calculateVisiblity() override; virtual void calculateVisiblity() override;
protected: protected:
/*! /*!
* \brief The Vertices of The Polygon. Needs to be a planar Polygon. * \brief The Vertices of The Polygon. Needs to be a planar Polygon.
*/ */
std::vector<QPoint> polygonData; std::vector<QPoint> polygonData;
public: public:
/*! /*!
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions. * \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
* \param weight - The weight of the Image. * \param weight - The weight of the Image.
* \param height - The height of the Image. * \param height - The height of the Image.
*/ */
IntelliShapedImage(int weight, int height); IntelliShapedImage(int weight, int height);
/*! /*!
* \brief An Destructor. * \brief An Destructor.
*/ */
virtual ~IntelliShapedImage() override; virtual ~IntelliShapedImage() override;
/*! /*!
* \brief A function returning the displayable ImageData in a requested transparence and size. * \brief A function returning the displayable ImageData in a requested transparence and size.
* \param displaySize - The size, in whcih the Image should be displayed. * \param displaySize - The size, in whcih the Image should be displayed.
* \param alpha - The maximum alpha value, a pixel can have. * \param alpha - The maximum alpha value, a pixel can have.
* \return A QImage which is ready to be displayed. * \return A QImage which is ready to be displayed.
*/ */
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override; virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
/** /**
* @brief A function returning the displayable ImageData in a requested transparence and it's standart size. * @brief A function returning the displayable ImageData in a requested transparence and it's standart size.
* @param alpha - The maximum alpha value, a pixel can have. * @param alpha - The maximum alpha value, a pixel can have.
* @return A QImage which is ready to be displayed. * @return A QImage which is ready to be displayed.
*/ */
virtual QImage getDisplayable(int alpha=255) override; virtual QImage getDisplayable(int alpha=255) override;
/*! /*!
* \brief A function that copys all that returns a [allocated] Image * \brief A function that copys all that returns a [allocated] Image
* \return A [allocated] Image with all the properties of the instance. * \return A [allocated] Image with all the properties of the instance.
*/ */
virtual IntelliImage* getDeepCopy() override; virtual IntelliImage* getDeepCopy() override;
/*! /*!
* \brief A function that returns the Polygondata if existent. * \brief A function that returns the Polygondata if existent.
* \return The Polygondata if existent. * \return The Polygondata if existent.
*/ */
virtual std::vector<QPoint> getPolygonData() override{return polygonData;} virtual std::vector<QPoint> getPolygonData() override {
return polygonData;
}
/*! /*!
* \brief A function that sets the data of the visible Polygon. * \brief A function that sets the data of the visible Polygon.
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed. * \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
*/ */
virtual void setPolygon(const std::vector<QPoint>& polygonData) override; virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
}; };
#endif #endif

View File

@@ -1,8 +1,8 @@
#include "IntelliColorPicker.h" #include "IntelliColorPicker.h"
IntelliColorPicker::IntelliColorPicker(){ IntelliColorPicker::IntelliColorPicker(){
firstColor = {255,0,0,255}; firstColor = {255,0,0,255};
secondColor = {0,255,255,255}; secondColor = {0,255,255,255};
} }
IntelliColorPicker::~IntelliColorPicker(){ IntelliColorPicker::~IntelliColorPicker(){
@@ -10,21 +10,21 @@ IntelliColorPicker::~IntelliColorPicker(){
} }
void IntelliColorPicker::switchColors(){ void IntelliColorPicker::switchColors(){
std::swap(firstColor, secondColor); std::swap(firstColor, secondColor);
} }
QColor IntelliColorPicker::getFirstColor(){ QColor IntelliColorPicker::getFirstColor(){
return this->firstColor; return this->firstColor;
} }
QColor IntelliColorPicker::getSecondColor(){ QColor IntelliColorPicker::getSecondColor(){
return this->secondColor; return this->secondColor;
} }
void IntelliColorPicker::setFirstColor(QColor Color){ void IntelliColorPicker::setFirstColor(QColor Color){
this->firstColor = Color; this->firstColor = Color;
} }
void IntelliColorPicker::setSecondColor(QColor Color){ void IntelliColorPicker::setSecondColor(QColor Color){
this->secondColor = Color; this->secondColor = Color;
} }

View File

@@ -1,64 +1,64 @@
#ifndef INTELLITOOLSETCOLORTOOL_H #ifndef INTELLITOOLSETCOLORTOOL_H
#define INTELLITOOLSETCOLORTOOL_H #define INTELLITOOLSETCOLORTOOL_H
#include"QColor" #include "QColor"
#include"QPoint" #include "QPoint"
#include"QColorDialog" #include "QColorDialog"
/*! /*!
* \brief The IntelliColorPicker manages the selected colors for one whole project. * \brief The IntelliColorPicker manages the selected colors for one whole project.
*/ */
class IntelliColorPicker{ class IntelliColorPicker {
public: public:
/*! /*!
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production. * \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
*/ */
IntelliColorPicker(); IntelliColorPicker();
/*! /*!
* \brief IntelliColorPicker destructor clears up his used memory, if there is some. * \brief IntelliColorPicker destructor clears up his used memory, if there is some.
*/ */
virtual ~IntelliColorPicker(); virtual ~IntelliColorPicker();
/*! /*!
* \brief A function switching primary and secondary color. * \brief A function switching primary and secondary color.
*/ */
void switchColors(); void switchColors();
/*! /*!
* \brief A function to read the primary selected color. * \brief A function to read the primary selected color.
* \return Returns the primary color. * \return Returns the primary color.
*/ */
QColor getFirstColor(); QColor getFirstColor();
/*! /*!
* \brief A function to read the secondary selected color. * \brief A function to read the secondary selected color.
* \return Returns the secondary color. * \return Returns the secondary color.
*/ */
QColor getSecondColor(); QColor getSecondColor();
/*! /*!
* \brief A function to set the primary color. * \brief A function to set the primary color.
* \param Color - The color to be set as primary. * \param Color - The color to be set as primary.
*/ */
void setFirstColor(QColor Color); void setFirstColor(QColor Color);
/*! /*!
* \brief A function to set the secondary color. * \brief A function to set the secondary color.
* \param Color - The color to be set as secondary. * \param Color - The color to be set as secondary.
*/ */
void setSecondColor(QColor Color); void setSecondColor(QColor Color);
private: private:
/*! /*!
* \brief The primary color. * \brief The primary color.
*/ */
QColor firstColor; QColor firstColor;
/*! /*!
* \brief The secondary color. * \brief The secondary color.
*/ */
QColor secondColor; QColor secondColor;
}; };
#endif // INTELLITOOLSETCOLORTOOL_H #endif // INTELLITOOLSETCOLORTOOL_H

View File

@@ -1,123 +1,123 @@
#include"IntelliHelper.h" #include "IntelliHelper.h"
#include<algorithm> #include <algorithm>
#include<queue> #include <queue>
#include<cmath> #include <cmath>
std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> polyPoints){ std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> polyPoints){
// helper for managing the triangle vertices and their state // helper for managing the triangle vertices and their state
struct TriangleHelper{ struct TriangleHelper {
QPoint vertex; QPoint vertex;
float interiorAngle; float interiorAngle;
int index; int index;
bool isTip; bool isTip;
}; };
// calculates the inner angle of 'point' // calculates the inner angle of 'point'
auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){ auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){
QPoint AP(point.x()-prev.x(), point.y()-prev.y()); QPoint AP(point.x()-prev.x(), point.y()-prev.y());
QPoint BP(point.x()-post.x(), point.y()-post.y()); QPoint BP(point.x()-post.x(), point.y()-post.y());
float topSclar = AP.x()*BP.x()+AP.y()*BP.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.)); float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.));
return acos(topSclar/absolute); return acos(topSclar/absolute);
}; };
// gets the first element of vec for which element.isTip == true holds // gets the first element of vec for which element.isTip == true holds
auto getTip= [](const std::vector<TriangleHelper>& vec){ auto getTip= [](const std::vector<TriangleHelper>& vec){
size_t min = 0; size_t min = 0;
for(size_t i=0; i<vec.size(); i++){ for(size_t i=0; i<vec.size(); i++) {
if(vec[i].interiorAngle<vec[min].interiorAngle){ if(vec[i].interiorAngle<vec[min].interiorAngle) {
min = i; min = i;
} }
} }
return vec[min]; return vec[min];
}; };
// get the vertex Index bevor index in relation to the container length // get the vertex Index bevor index in relation to the container length
auto getPrev = [](int index, int length){ auto getPrev = [](int index, int length){
return (index-1)>=0?(index-1):(length-1); return (index-1)>=0 ? (index-1) : (length-1);
}; };
// get the vertex Index after index in relation to the container lenght // get the vertex Index after index in relation to the container lenght
auto getPost = [](int index, int length){ auto getPost = [](int index, int length){
return (index+1)%length; return (index+1)%length;
}; };
// return if the vertex is a tip // return if the vertex is a tip
auto isTip = [](float angle){ auto isTip = [](float angle){
return static_cast<double>(angle)<(M_PI/2.); return static_cast<double>(angle)<(M_PI/2.);
}; };
std::vector<TriangleHelper> Vertices; std::vector<TriangleHelper> Vertices;
std::vector<Triangle> Triangles; std::vector<Triangle> Triangles;
// set up all vertices and calculate intirior angle // set up all vertices and calculate intirior angle
for(int i=0; i<static_cast<int>(polyPoints.size()); i++){ for(int i=0; i<static_cast<int>(polyPoints.size()); i++) {
TriangleHelper helper; TriangleHelper helper;
int prev = getPrev(i, static_cast<int>(polyPoints.size())); int prev = getPrev(i, static_cast<int>(polyPoints.size()));
int post = getPost(i, static_cast<int>(polyPoints.size())); int post = getPost(i, static_cast<int>(polyPoints.size()));
helper.vertex = polyPoints[static_cast<size_t>(i)]; helper.vertex = polyPoints[static_cast<size_t>(i)];
helper.index = i; helper.index = i;
helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)], helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)],
polyPoints[static_cast<size_t>(prev)], polyPoints[static_cast<size_t>(prev)],
polyPoints[static_cast<size_t>(post)]); polyPoints[static_cast<size_t>(post)]);
helper.isTip = isTip(helper.interiorAngle); helper.isTip = isTip(helper.interiorAngle);
Vertices.push_back(helper); Vertices.push_back(helper);
} }
// search triangles based on the intirior angles of each vertey // search triangles based on the intirior angles of each vertey
while(Triangles.size() != polyPoints.size()-2){ while(Triangles.size() != polyPoints.size()-2) {
Triangle tri; Triangle tri;
TriangleHelper smallest = getTip(Vertices); TriangleHelper smallest = getTip(Vertices);
int prev = getPrev(smallest.index, static_cast<int>(Vertices.size())); int prev = getPrev(smallest.index, static_cast<int>(Vertices.size()));
int post = getPost(smallest.index, static_cast<int>(Vertices.size())); int post = getPost(smallest.index, static_cast<int>(Vertices.size()));
// set triangle and push it // set triangle and push it
tri.A = Vertices[static_cast<size_t>(prev)].vertex; tri.A = Vertices[static_cast<size_t>(prev)].vertex;
tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex; tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex;
tri.C = Vertices[static_cast<size_t>(post)].vertex; tri.C = Vertices[static_cast<size_t>(post)].vertex;
Triangles.push_back(tri); Triangles.push_back(tri);
// update Vertice array // update Vertice array
Vertices.erase(Vertices.begin()+smallest.index); Vertices.erase(Vertices.begin()+smallest.index);
for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++){ for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++) {
Vertices[i].index-=1; Vertices[i].index-=1;
} }
// update post und prev index // update post und prev index
post = post-1; post = post-1;
prev = prev<smallest.index?prev:(prev-1); prev = prev<smallest.index ? prev : (prev-1);
// calcultae neighboors of prev and post to calculate new interior angles // calcultae neighboors of prev and post to calculate new interior angles
int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size())); int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size()));
int postOfPrev = getPost(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 prevOfPost = getPrev(post, static_cast<int>(Vertices.size()));
int postOfPost = getPost(post, static_cast<int>(Vertices.size())); int postOfPost = getPost(post, static_cast<int>(Vertices.size()));
// update vertices with interior angles // update vertices with interior angles
// updtae prev // updtae prev
Vertices[static_cast<size_t>(prev)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(prev)].vertex, 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>(prevOfPrev)].vertex,
Vertices[static_cast<size_t>(postOfPrev)].vertex); Vertices[static_cast<size_t>(postOfPrev)].vertex);
Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle); Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle);
// update post // update post
Vertices[static_cast<size_t>(post)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(post)].vertex, 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>(prevOfPost)].vertex,
Vertices[static_cast<size_t>(postOfPost)].vertex); Vertices[static_cast<size_t>(postOfPost)].vertex);
Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle); Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle);
} }
return Triangles; return Triangles;
} }
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){ bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
for(auto triangle : triangles){ for(auto triangle : triangles) {
if(IntelliHelper::isInTriangle(triangle, point)){ if(IntelliHelper::isInTriangle(triangle, point)) {
return true; return true;
} }
} }
return false; return false;
} }

View File

@@ -1,63 +1,63 @@
#ifndef INTELLIHELPER_H #ifndef INTELLIHELPER_H
#define INTELLIHELPER_H #define INTELLIHELPER_H
#include<QPoint> #include <QPoint>
#include<vector> #include <vector>
/*! /*!
* \brief The Triangle struct holds the 3 vertices of a triangle. * \brief The Triangle struct holds the 3 vertices of a triangle.
*/ */
struct Triangle{ struct Triangle {
QPoint A,B,C; QPoint A,B,C;
}; };
namespace IntelliHelper { namespace IntelliHelper {
/*! /*!
* \brief A function to get the 2*area of a traingle, using its determinat. * \brief A function to get the 2*area of a traingle, using its determinat.
* \param p1 - The Point to check its side. * \param p1 - The Point to check its side.
* \param p2 - The first Point of the spanning Line * \param p2 - The first Point of the spanning Line
* \param p3 - The second Point of the spanning line. * \param p3 - The second Point of the spanning line.
* \return Returns the area of the traingle*2 * \return Returns the area of the traingle*2
*/ */
inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){ 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());
} }
/*! /*!
* \brief A function to check if a given point is in a triangle. * \brief A function to check if a given point is in a triangle.
* \param tri - The triangle to check, if it contains the point. * \param tri - The triangle to check, if it contains the point.
* \param P - The point to check if it is in the triangle. * \param P - The point to check if it is in the triangle.
* \return Returns true if the point is in the triangle, false otheriwse * \return Returns true if the point is in the triangle, false otheriwse
*/ */
inline bool isInTriangle(Triangle& tri, QPoint& P){ inline bool isInTriangle(Triangle& tri, QPoint& P){
float val1, val2, val3; float val1, val2, val3;
bool neg, pos; bool neg, pos;
val1 = IntelliHelper::sign(P,tri.A,tri.B); val1 = IntelliHelper::sign(P,tri.A,tri.B);
val2 = IntelliHelper::sign(P,tri.B,tri.C); val2 = IntelliHelper::sign(P,tri.B,tri.C);
val3 = IntelliHelper::sign(P,tri.C,tri.A); val3 = IntelliHelper::sign(P,tri.C,tri.A);
neg = (val1<0.f) || (val2<0.f) || (val3<0.f); neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
pos = (val1>0.f) || (val2>0.f) || (val3>0.f); pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
return !(neg && pos); return !(neg && pos);
} }
/*! /*!
* \brief A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by clipping ears of a planar graph. * \brief A function to split a polygon in its spanning traingles by using Meisters Theorem of graph theory by clipping ears of a planar graph.
* \param polyPoints - The Vertices of the polygon. * \param polyPoints - The Vertices of the polygon.
* \return Returns a Container of disjoint Triangles, which desribe the polygon area. * \return Returns a Container of disjoint Triangles, which desribe the polygon area.
*/ */
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints); std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
/*! /*!
* \brief A function to check if a point lies in a polygon by checking its spanning triangles. * \brief A function to check if a point lies in a polygon by checking its spanning triangles.
* \param triangles - The spanning triangles of the planar polygon. * \param triangles - The spanning triangles of the planar polygon.
* \param point - The point to checl, if it lies in the polygon. * \param point - The point to checl, if it lies in the polygon.
* \return Returns true if the point lies in the üpolygon, otherwise false. * \return Returns true if the point lies in the üpolygon, otherwise false.
*/ */
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point); bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
} }
#endif #endif

View File

@@ -18,338 +18,338 @@
#include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolFloodFill.h"
#include "Tool/IntelliToolPolygon.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){
this->Tool = nullptr; this->Tool = nullptr;
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(0,0,255,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));
polygon.push_back(QPoint(100,200)); polygon.push_back(QPoint(100,200));
polygon.push_back(QPoint(000,100)); polygon.push_back(QPoint(000,100));
layerBundle[0].image->setPolygon(polygon); layerBundle[0].image->setPolygon(polygon);
this->addLayer(200,200,150,150); this->addLayer(200,200,150,150);
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=0;
} }
PaintingArea::~PaintingArea(){ PaintingArea::~PaintingArea(){
delete Tool; delete Tool;
} }
void PaintingArea::setUp(int maxWidth, int maxHeight){ void PaintingArea::setUp(int maxWidth, int maxHeight){
//set standart parameter //set standart parameter
this->maxWidth = maxWidth; this->maxWidth = maxWidth;
this->maxHeight = maxHeight; this->maxHeight = maxHeight;
Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
// Roots the widget to the top left even if resized // Roots the widget to the top left even if resized
setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_StaticContents);
} }
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){
LayerObject newLayer; LayerObject newLayer;
newLayer.width = width; newLayer.width = width;
newLayer.height = height; newLayer.height = height;
newLayer.widthOffset = widthOffset; newLayer.widthOffset = widthOffset;
newLayer.heightOffset = heightOffset; newLayer.heightOffset = heightOffset;
if(type==ImageType::Raster_Image){ if(type==ImageType::Raster_Image) {
newLayer.image = new IntelliRasterImage(width,height); newLayer.image = new IntelliRasterImage(width,height);
}else if(type==ImageType::Shaped_Image){ }else if(type==ImageType::Shaped_Image) {
newLayer.image = new IntelliShapedImage(width, height); newLayer.image = new IntelliShapedImage(width, height);
} }
newLayer.alpha = 255; newLayer.alpha = 255;
this->layerBundle.push_back(newLayer); this->layerBundle.push_back(newLayer);
return static_cast<int>(layerBundle.size())-1; return static_cast<int>(layerBundle.size())-1;
} }
void PaintingArea::deleteLayer(int index){ void PaintingArea::deleteLayer(int index){
if(index<static_cast<int>(layerBundle.size())){ if(index<static_cast<int>(layerBundle.size())) {
this->layerBundle.erase(layerBundle.begin()+index); this->layerBundle.erase(layerBundle.begin()+index);
if(activeLayer>=index){ if(activeLayer>=index) {
activeLayer--; activeLayer--;
} }
} }
} }
void PaintingArea::slotDeleteActiveLayer(){ void PaintingArea::slotDeleteActiveLayer(){
if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())){ if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())) {
this->layerBundle.erase(layerBundle.begin()+activeLayer); this->layerBundle.erase(layerBundle.begin()+activeLayer);
activeLayer--; activeLayer--;
} }
} }
void PaintingArea::setLayerToActive(int index){ void PaintingArea::setLayerToActive(int index){
if(index>=0&&index<static_cast<int>(layerBundle.size())){ if(index>=0&&index<static_cast<int>(layerBundle.size())) {
this->activeLayer=index; this->activeLayer=index;
} }
} }
void PaintingArea::setAlphaOfLayer(int index, int alpha){ void PaintingArea::setAlphaOfLayer(int index, int alpha){
if(index>=0&&index<static_cast<int>(layerBundle.size())){ if(index>=0&&index<static_cast<int>(layerBundle.size())) {
layerBundle[static_cast<size_t>(index)].alpha=alpha; layerBundle[static_cast<size_t>(index)].alpha=alpha;
} }
} }
// Used to load the image and place it in the widget // Used to load the image and place it in the widget
bool PaintingArea::open(const QString &fileName){ bool PaintingArea::open(const QString &fileName){
if(this->activeLayer==-1){ if(this->activeLayer==-1) {
return false; return false;
} }
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image; IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
bool open = active->loadImage(fileName); bool open = active->loadImage(fileName);
active->calculateVisiblity(); active->calculateVisiblity();
update(); update();
return open; return open;
} }
// Save the current image // Save the current image
bool PaintingArea::save(const QString &fileName, const char *fileFormat){ bool PaintingArea::save(const QString &fileName, const char*fileFormat){
if(layerBundle.size()==0){ if(layerBundle.size()==0) {
return false; return false;
} }
this->assembleLayers(true); this->assembleLayers(true);
if(!strcmp(fileFormat,"PNG")){ if(!strcmp(fileFormat,"PNG")) {
QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8); QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
fileFormat = "png"; fileFormat = "png";
if (visibleImage.save(fileName, fileFormat)) { if (visibleImage.save(fileName, fileFormat)) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
if (Canvas->save(fileName, fileFormat)) { if (Canvas->save(fileName, fileFormat)) {
return true; return true;
} else { } else {
return false; return false;
} }
} }
// Color the image area with white // Color the image area with white
void PaintingArea::floodFill(int r, int g, int b, int a){ void PaintingArea::floodFill(int r, int g, int b, int a){
if(this->activeLayer==-1){ if(this->activeLayer==-1) {
return; return;
} }
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image; IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
active->drawPlain(QColor(r, g, b, a)); active->drawPlain(QColor(r, g, b, a));
update(); update();
} }
void PaintingArea::movePositionActive(int x, int y){ void PaintingArea::movePositionActive(int x, int y){
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x; layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y; layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
} }
void PaintingArea::moveActiveLayer(int idx){ void PaintingArea::moveActiveLayer(int idx){
if(idx==1){ if(idx==1) {
this->activateUpperLayer(); this->activateUpperLayer();
}else if(idx==-1){ }else if(idx==-1) {
this->activateLowerLayer(); this->activateLowerLayer();
} }
} }
void PaintingArea::slotActivateLayer(int a){ void PaintingArea::slotActivateLayer(int a){
if(a>=0 && a < static_cast<int>(layerBundle.size())){ if(a>=0 && a < static_cast<int>(layerBundle.size())) {
this->setLayerToActive(a); this->setLayerToActive(a);
} }
} }
void PaintingArea::colorPickerSetFirstColor(){ void PaintingArea::colorPickerSetFirstColor(){
QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color", QColorDialog::DontUseNativeDialog); 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", QColorDialog::DontUseNativeDialog); QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color", QColorDialog::DontUseNativeDialog);
this->colorPicker.setSecondColor(clr); this->colorPicker.setSecondColor(clr);
} }
void PaintingArea::colorPickerSwitchColor(){ void PaintingArea::colorPickerSwitchColor(){
this->colorPicker.switchColors(); this->colorPicker.switchColors();
} }
void PaintingArea::createPenTool(){ void PaintingArea::createPenTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolPen(this, &colorPicker); Tool = new IntelliToolPen(this, &colorPicker);
} }
void PaintingArea::createPlainTool(){ void PaintingArea::createPlainTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolPlainTool(this, &colorPicker); Tool = new IntelliToolPlainTool(this, &colorPicker);
} }
void PaintingArea::createLineTool(){ void PaintingArea::createLineTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolLine(this, &colorPicker); Tool = new IntelliToolLine(this, &colorPicker);
} }
void PaintingArea::createRectangleTool(){ void PaintingArea::createRectangleTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolRectangle(this, &colorPicker); Tool = new IntelliToolRectangle(this, &colorPicker);
} }
void PaintingArea::createCircleTool(){ void PaintingArea::createCircleTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolCircle(this, &colorPicker); Tool = new IntelliToolCircle(this, &colorPicker);
} }
void PaintingArea::createPolygonTool(){ void PaintingArea::createPolygonTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolPolygon(this, &colorPicker); Tool = new IntelliToolPolygon(this, &colorPicker);
} }
void PaintingArea::createFloodFillTool(){ void PaintingArea::createFloodFillTool(){
delete this->Tool; delete this->Tool;
Tool = new IntelliToolFloodFill(this, &colorPicker); Tool = new IntelliToolFloodFill(this, &colorPicker);
} }
int PaintingArea::getWidthOfActive(){ int PaintingArea::getWidthOfActive(){
return this->layerBundle[activeLayer].width; return this->layerBundle[activeLayer].width;
} }
int PaintingArea::getHeightOfActive(){ int PaintingArea::getHeightOfActive(){
return this->layerBundle[activeLayer].height; return this->layerBundle[activeLayer].height;
} }
// 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
void PaintingArea::mousePressEvent(QMouseEvent *event){ void PaintingArea::mousePressEvent(QMouseEvent*event){
if(Tool == nullptr) if(Tool == nullptr)
return; return;
int x = event->x()-layerBundle[activeLayer].widthOffset; int x = event->x()-layerBundle[activeLayer].widthOffset;
int y = event->y()-layerBundle[activeLayer].heightOffset; int y = event->y()-layerBundle[activeLayer].heightOffset;
if(event->button() == Qt::LeftButton){ if(event->button() == Qt::LeftButton) {
Tool->onMouseLeftPressed(x, y); Tool->onMouseLeftPressed(x, y);
}else if(event->button() == Qt::RightButton){ }else if(event->button() == Qt::RightButton) {
Tool->onMouseRightPressed(x, y); Tool->onMouseRightPressed(x, y);
} }
update(); update();
} }
// When the mouse moves if the left button is clicked // When the mouse moves if the left button is clicked
// we call the drawline function which draws a line // we call the drawline function which draws a line
// from the last position to the current // from the last position to the current
void PaintingArea::mouseMoveEvent(QMouseEvent *event){ void PaintingArea::mouseMoveEvent(QMouseEvent*event){
if(Tool == nullptr) if(Tool == nullptr)
return; return;
int x = event->x()-layerBundle[activeLayer].widthOffset; int x = event->x()-layerBundle[activeLayer].widthOffset;
int y = event->y()-layerBundle[activeLayer].heightOffset; int y = event->y()-layerBundle[activeLayer].heightOffset;
Tool->onMouseMoved(x, y); Tool->onMouseMoved(x, y);
update(); update();
} }
// If the button is released we set variables to stop drawing // If the button is released we set variables to stop drawing
void PaintingArea::mouseReleaseEvent(QMouseEvent *event){ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
if(Tool == nullptr) if(Tool == nullptr)
return; return;
int x = event->x()-layerBundle[activeLayer].widthOffset; int x = event->x()-layerBundle[activeLayer].widthOffset;
int y = event->y()-layerBundle[activeLayer].heightOffset; int y = event->y()-layerBundle[activeLayer].heightOffset;
if(event->button() == Qt::LeftButton){ if(event->button() == Qt::LeftButton) {
Tool->onMouseLeftReleased(x, y); Tool->onMouseLeftReleased(x, y);
}else if(event->button() == Qt::RightButton){ }else if(event->button() == Qt::RightButton) {
Tool->onMouseRightReleased(x, y); Tool->onMouseRightReleased(x, y);
} }
update(); update();
} }
void PaintingArea::wheelEvent(QWheelEvent *event){ void PaintingArea::wheelEvent(QWheelEvent*event){
QPoint numDegrees = event->angleDelta() / 8; QPoint numDegrees = event->angleDelta() / 8;
if(!numDegrees.isNull()){ if(!numDegrees.isNull()) {
QPoint numSteps = numDegrees / 15; QPoint numSteps = numDegrees / 15;
Tool->onWheelScrolled(numSteps.y()*-1); 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
void PaintingArea::paintEvent(QPaintEvent *event){ void PaintingArea::paintEvent(QPaintEvent*event){
this->assembleLayers(); this->assembleLayers();
QPainter painter(this); QPainter painter(this);
QRect dirtyRec = event->rect(); QRect dirtyRec = event->rect();
painter.drawImage(dirtyRec, *Canvas, dirtyRec); painter.drawImage(dirtyRec, *Canvas, dirtyRec);
update(); update();
} }
// Resize the image to slightly larger then the main window // Resize the image to slightly larger then the main window
// to cut down on the need to resize the image // to cut down on the need to resize the image
void PaintingArea::resizeEvent(QResizeEvent *event){ void PaintingArea::resizeEvent(QResizeEvent*event){
//TODO wait till tool works //TODO wait till tool works
update(); update();
} }
void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){ void PaintingArea::resizeImage(QImage*image_res, const QSize &newSize){
//TODO implement //TODO implement
} }
void PaintingArea::activateUpperLayer(){ void PaintingArea::activateUpperLayer(){
if(activeLayer!=-1 && activeLayer<layerBundle.size()-1){ if(activeLayer!=-1 && activeLayer<layerBundle.size()-1) {
std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]); std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
activeLayer++; activeLayer++;
} }
} }
void PaintingArea::activateLowerLayer(){ void PaintingArea::activateLowerLayer(){
if(activeLayer!=-1 && activeLayer>0){ if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]); std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
activeLayer--; activeLayer--;
} }
} }
void PaintingArea::assembleLayers(bool forSaving){ void PaintingArea::assembleLayers(bool forSaving){
if(forSaving){ if(forSaving) {
Canvas->fill(Qt::GlobalColor::transparent); Canvas->fill(Qt::GlobalColor::transparent);
}else{ }else{
Canvas->fill(Qt::GlobalColor::black); Canvas->fill(Qt::GlobalColor::black);
} }
for(size_t i=0; i<layerBundle.size(); i++){ for(size_t i=0; i<layerBundle.size(); i++) {
LayerObject layer = layerBundle[i]; LayerObject layer = layerBundle[i];
QImage cpy = layer.image->getDisplayable(layer.alpha); QImage cpy = layer.image->getDisplayable(layer.alpha);
QColor clr_0; QColor clr_0;
QColor clr_1; QColor clr_1;
for(int y=0; y<layer.height; y++){ for(int y=0; y<layer.height; y++) {
if(layer.heightOffset+y<0) continue; if(layer.heightOffset+y<0) continue;
if(layer.heightOffset+y>=maxHeight) break; if(layer.heightOffset+y>=maxHeight) break;
for(int x=0; x<layer.width; x++){ for(int x=0; x<layer.width; x++) {
if(layer.widthOffset+x<0) continue; if(layer.widthOffset+x<0) continue;
if(layer.widthOffset+x>=maxWidth) break; if(layer.widthOffset+x>=maxWidth) break;
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y); clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
clr_1=cpy.pixelColor(x,y); clr_1=cpy.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f; float t = static_cast<float>(clr_1.alpha())/255.f;
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f); int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f); int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f); int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
clr_0.setRed(r); clr_0.setRed(r);
clr_0.setGreen(g); clr_0.setGreen(g);
clr_0.setBlue(b); clr_0.setBlue(b);
clr_0.setAlpha(a); clr_0.setAlpha(a);
Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0); Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0);
} }
} }
} }
} }
void PaintingArea::createTempLayerAfter(int idx){ void PaintingArea::createTempLayerAfter(int idx){
if(idx>=0){ if(idx>=0) {
LayerObject newLayer; LayerObject newLayer;
newLayer.alpha = 255; newLayer.alpha = 255;
newLayer.height = layerBundle[idx].height; newLayer.height = layerBundle[idx].height;
newLayer.width = layerBundle[idx].width; newLayer.width = layerBundle[idx].width;
newLayer.heightOffset = layerBundle[idx].heightOffset; newLayer.heightOffset = layerBundle[idx].heightOffset;
newLayer.widthOffset = layerBundle[idx].widthOffset; newLayer.widthOffset = layerBundle[idx].widthOffset;
newLayer.image = layerBundle[idx].image->getDeepCopy(); newLayer.image = layerBundle[idx].image->getDeepCopy();
layerBundle.insert(layerBundle.begin()+idx+1,newLayer); layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
} }
} }

View File

@@ -2,9 +2,9 @@
#include "QDebug" #include "QDebug"
IntelliColorPicker::IntelliColorPicker(PaintingArea* Area) IntelliColorPicker::IntelliColorPicker(PaintingArea* Area)
:IntelliTool(Area){ : IntelliTool(Area){
firstColor = {255,0,0,255}; firstColor = {255,0,0,255};
secondColor = {0,0,255,255}; secondColor = {0,0,255,255};
} }
IntelliColorPicker::~IntelliColorPicker(){ IntelliColorPicker::~IntelliColorPicker(){
@@ -12,25 +12,25 @@ IntelliColorPicker::~IntelliColorPicker(){
} }
void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){ void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){
QString Titel; QString Titel;
QColor newColor; QColor newColor;
if(firstOrSecondColor == 1){ if(firstOrSecondColor == 1) {
Titel = "Choose first Color"; Titel = "Choose first Color";
newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel); newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel);
this->firstColor = newColor; this->firstColor = newColor;
qDebug() << "Firstcolor" << this->firstColor; qDebug() << "Firstcolor" << this->firstColor;
} }
else{ else{
Titel = "Choose second Color"; Titel = "Choose second Color";
newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel); newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel);
this->secondColor = newColor; this->secondColor = newColor;
} }
} }
QColor IntelliColorPicker::getFirstColor(){ QColor IntelliColorPicker::getFirstColor(){
return firstColor; return firstColor;
} }
QColor IntelliColorPicker::getSecondColor(){ QColor IntelliColorPicker::getSecondColor(){
return secondColor; return secondColor;
} }

View File

@@ -1,9 +1,9 @@
#include"IntelliTool.h" #include "IntelliTool.h"
#include"Layer/PaintingArea.h" #include "Layer/PaintingArea.h"
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){ IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){
this->Area=Area; this->Area=Area;
this->colorPicker=colorPicker; this->colorPicker=colorPicker;
} }
@@ -12,71 +12,70 @@ IntelliTool::~IntelliTool(){
} }
void IntelliTool::onMouseRightPressed(int x, int y){ void IntelliTool::onMouseRightPressed(int x, int y){
if(drawing){ if(drawing) {
drawing=false; drawing=false;
this->deleteToolLayer(); this->deleteToolLayer();
} }
} }
void IntelliTool::onMouseRightReleased(int x, int y){ void IntelliTool::onMouseRightReleased(int x, int y){
//optional for tool //optional for tool
} }
void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftPressed(int x, int y){
this->drawing=true; this->drawing=true;
//create drawing layer //create drawing layer
this->createToolLayer(); this->createToolLayer();
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliTool::onMouseLeftReleased(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){
if(drawing){ if(drawing) {
drawing=false; drawing=false;
this->mergeToolLayer(); this->mergeToolLayer();
this->deleteToolLayer(); this->deleteToolLayer();
Active->image->calculateVisiblity(); Active->image->calculateVisiblity();
} }
} }
void IntelliTool::onMouseMoved(int x, int y){ void IntelliTool::onMouseMoved(int x, int y){
if(drawing) if(drawing)
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliTool::onWheelScrolled(int value){ void IntelliTool::onWheelScrolled(int value){
//if needed for future general tasks implement in here //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];
this->Canvas=&Area->layerBundle[Area->activeLayer+1]; this->Canvas=&Area->layerBundle[Area->activeLayer+1];
} }
void IntelliTool::mergeToolLayer(){ void IntelliTool::mergeToolLayer(){
QColor clr_0; QColor clr_0;
QColor clr_1; QColor clr_1;
for(int y=0; y<Active->height; y++){ for(int y=0; y<Active->height; y++) {
for(int x=0; x<Active->width; x++){ for(int x=0; x<Active->width; x++) {
clr_0=Active->image->imageData.pixelColor(x,y); clr_0=Active->image->imageData.pixelColor(x,y);
clr_1=Canvas->image->imageData.pixelColor(x,y); clr_1=Canvas->image->imageData.pixelColor(x,y);
float t = static_cast<float>(clr_1.alpha())/255.f; float t = static_cast<float>(clr_1.alpha())/255.f;
int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f); int r =static_cast<int>(static_cast<float>(clr_1.red())*(t)+static_cast<float>(clr_0.red())*(1.f-t)+0.5f);
int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f); int g =static_cast<int>(static_cast<float>(clr_1.green())*(t)+static_cast<float>(clr_0.green())*(1.f-t)+0.5f);
int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f); int b =static_cast<int>(static_cast<float>(clr_1.blue())*(t)+static_cast<float>(clr_0.blue()*(1.f-t))+0.5f);
int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); int a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
clr_0.setRed(r); clr_0.setRed(r);
clr_0.setGreen(g); clr_0.setGreen(g);
clr_0.setBlue(b); clr_0.setBlue(b);
clr_0.setAlpha(a); clr_0.setAlpha(a);
Active->image->imageData.setPixelColor(x, y, clr_0); Active->image->imageData.setPixelColor(x, y, clr_0);
} }
} }
} }
void IntelliTool::deleteToolLayer(){ void IntelliTool::deleteToolLayer(){
Area->deleteLayer(Area->activeLayer+1); Area->deleteLayer(Area->activeLayer+1);
this->Canvas=nullptr; this->Canvas=nullptr;
} }

View File

@@ -10,101 +10,101 @@ class PaintingArea;
/*! /*!
* \brief An abstract class that manages the basic events, like mouse clicks or scrolls events. * \brief An abstract class that manages the basic events, like mouse clicks or scrolls events.
*/ */
class IntelliTool{ class IntelliTool {
private: private:
/*! /*!
* \brief A function that creates a layer to draw on. * \brief A function that creates a layer to draw on.
*/ */
void createToolLayer(); void createToolLayer();
/*! /*!
* \brief A function that merges the drawing- and the active- layer. * \brief A function that merges the drawing- and the active- layer.
*/ */
void mergeToolLayer(); void mergeToolLayer();
/*! /*!
* \brief A function that deletes the drawinglayer. * \brief A function that deletes the drawinglayer.
*/ */
void deleteToolLayer(); void deleteToolLayer();
protected: protected:
/*! /*!
* \brief A pointer to the general PaintingArea to interact with. * \brief A pointer to the general PaintingArea to interact with.
*/ */
PaintingArea* Area; PaintingArea* Area;
/*! /*!
* \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors. * \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
*/ */
IntelliColorPicker* colorPicker; IntelliColorPicker* colorPicker;
/*! /*!
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews. * \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
*/ */
LayerObject* Active; LayerObject* Active;
/*! /*!
* \brief A pointer to the drawing canvas of the tool, work on this. * \brief A pointer to the drawing canvas of the tool, work on this.
*/ */
LayerObject* Canvas; LayerObject* Canvas;
/*! /*!
* \brief A flag checking if the user is currently drawing or not. * \brief A flag checking if the user is currently drawing or not.
*/ */
bool drawing = false; bool drawing = false;
public: public:
/*! /*!
* \brief A constructor setting the general Painting Area and colorPicker. * \brief A constructor setting the general Painting Area and colorPicker.
* \param Area - The general PaintingArea used by the project. * \param Area - The general PaintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief An abstract Destructor. * \brief An abstract Destructor.
*/ */
virtual ~IntelliTool() = 0; virtual ~IntelliTool() = 0;
/*! /*!
* \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes! * \brief A function managing the right click Pressed of a Mouse. Constructing the Canvas to draw on. Call this in child classes!
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y); virtual void onMouseRightPressed(int x, int y);
/*! /*!
* \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes! * \brief A function managing the right click Released of a Mouse. Merging the Canvas to Active. Call this in child classes!
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y); virtual void onMouseRightReleased(int x, int y);
/*! /*!
* \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes! * \brief A function managing the left click Pressed of a Mouse. Resetting the current draw. Call this in child classes!
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y); virtual void onMouseLeftPressed(int x, int y);
/*! /*!
* \brief A function managing the left click Released of a Mouse. Call this in child classes! * \brief A function managing the left click Released of a Mouse. Call this in child classes!
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y); virtual void onMouseLeftReleased(int x, int y);
/*! /*!
* \brief A function managing the scroll event. A positive value means scrolling outwards. Call this in child classes! * \brief A function managing the scroll event. A positive value means scrolling outwards. Call this in child classes!
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value); virtual void onWheelScrolled(int value);
/*! /*!
* \brief A function managing the mouse moved event. Call this in child classes! * \brief A function managing the mouse moved event. Call this in child classes!
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y); virtual void onMouseMoved(int x, int y);
}; };

View File

@@ -4,9 +4,9 @@
#include <cmath> #include <cmath>
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); 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); this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
} }
IntelliToolCircle::~IntelliToolCircle(){ IntelliToolCircle::~IntelliToolCircle(){
@@ -14,74 +14,74 @@ IntelliToolCircle::~IntelliToolCircle(){
} }
void IntelliToolCircle::drawCyrcle(int radius){ void IntelliToolCircle::drawCyrcle(int radius){
int outer = radius+20; int outer = radius+20;
QColor inner = this->colorPicker->getSecondColor(); QColor inner = this->colorPicker->getSecondColor();
inner.setAlpha(alphaInner); inner.setAlpha(alphaInner);
int yMin, yMax, xMin, xMax; int yMin, yMax, xMin, xMax;
yMin = Middle.y()-radius; yMin = Middle.y()-radius;
yMax = Middle.y()+radius; yMax = Middle.y()+radius;
// x = x0+-sqrt(r2-(y-y0)2) // x = x0+-sqrt(r2-(y-y0)2)
for(int i=yMin; i<=yMax; i++){ for(int i=yMin; i<=yMax; i++) {
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)); xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
xMax = 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); this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
} }
//TODO implement circle drawing algorithm bresenham //TODO implement circle drawing algorithm bresenham
radius = radius +(this->edgeWidth/2.)-1.; radius = radius +(this->edgeWidth/2.)-1.;
yMin = (Middle.y()-radius); yMin = (Middle.y()-radius);
yMax = (Middle.y()+radius); yMax = (Middle.y()+radius);
for(int i=yMin; i<=yMax; i++){ for(int i=yMin; i<=yMax; i++) {
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2)); xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
xMax = 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(xMin,i), colorPicker->getFirstColor(),edgeWidth);
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth); this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
} }
xMin = (Middle.x()-radius); xMin = (Middle.x()-radius);
xMax = (Middle.x()+radius); xMax = (Middle.x()+radius);
for(int i=xMin; i<=xMax; i++){ for(int i=xMin; i<=xMax; i++) {
int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2)); 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)); 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, yMin), colorPicker->getFirstColor(),edgeWidth);
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth); this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
} }
} }
void IntelliToolCircle::onMouseRightPressed(int x, int y){ void IntelliToolCircle::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolCircle::onMouseRightReleased(int x, int y){ void IntelliToolCircle::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,y);
} }
void IntelliToolCircle::onMouseLeftPressed(int x, int y){ void IntelliToolCircle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
this->Middle=QPoint(x,y); this->Middle=QPoint(x,y);
int radius = 1; int radius = 1;
drawCyrcle(radius); drawCyrcle(radius);
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliToolCircle::onMouseLeftReleased(int x, int y){ void IntelliToolCircle::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
void IntelliToolCircle::onWheelScrolled(int value){ void IntelliToolCircle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value; this->edgeWidth+=value;
if(this->edgeWidth<=0){ if(this->edgeWidth<=0) {
this->edgeWidth=1; this->edgeWidth=1;
} }
} }
void IntelliToolCircle::onMouseMoved(int x, int y){ void IntelliToolCircle::onMouseMoved(int x, int y){
if(this->drawing){ if(this->drawing) {
this->Canvas->image->drawPlain(Qt::transparent); this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y); QPoint next(x,y);
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2))); int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
drawCyrcle(radius); drawCyrcle(radius);
} }
IntelliTool::onMouseMoved(x,y); IntelliTool::onMouseMoved(x,y);
} }

View File

@@ -7,80 +7,80 @@
/*! /*!
* \brief The IntelliToolCircle class represents a tool to draw a circle. * \brief The IntelliToolCircle class represents a tool to draw a circle.
*/ */
class IntelliToolCircle : public IntelliTool{ class IntelliToolCircle : public IntelliTool {
/*! /*!
* \brief A function that implements a circle drawing algorithm. * \brief A function that implements a circle drawing algorithm.
* \param radius - The radius of the circle. * \param radius - The radius of the circle.
*/ */
void drawCyrcle(int radius); void drawCyrcle(int radius);
/*! /*!
* \brief The center of the circle. * \brief The center of the circle.
*/ */
QPoint Middle; QPoint Middle;
/*! /*!
* \brief The alpha value of the inner circle. * \brief The alpha value of the inner circle.
*/ */
int alphaInner; int alphaInner;
/*! /*!
* \brief The width of the outer circle edge. * \brief The width of the outer circle edge.
*/ */
int edgeWidth; int edgeWidth;
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth. * \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
virtual ~IntelliToolCircle() override; virtual ~IntelliToolCircle() override;
/*! /*!
* \brief A function managing the right click pressed of a mouse. Clearing the canvas layer. * \brief A function managing the right click pressed of a mouse. Clearing the canvas layer.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Sets the middle point of the cricle. * \brief A function managing the left click pressed of a mouse. Sets the middle point of the cricle.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. * \brief A function managing the left click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event. Changing the edge Width relative to value. * \brief A function managing the scroll event. Changing the edge Width relative to value.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*! /*!
* \brief A function managing the mouse moved event. Draws a circle with radius of eulerian norm of mouse position and the middle point. * \brief A function managing the mouse moved event. Draws a circle with radius of eulerian norm of mouse position and the middle point.
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };
#endif // INTELLITOOLCIRCLE_H #endif // INTELLITOOLCIRCLE_H

View File

@@ -6,75 +6,74 @@
#include <queue> #include <queue>
IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
} }
IntelliToolFloodFill::~IntelliToolFloodFill(){ IntelliToolFloodFill::~IntelliToolFloodFill(){
} }
void IntelliToolFloodFill::onMouseRightPressed(int x, int y){ void IntelliToolFloodFill::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolFloodFill::onMouseRightReleased(int x, int y){ void IntelliToolFloodFill::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,y);
} }
void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){ void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())){ if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())) {
return; return;
} }
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
QPoint start(x,y); QPoint start(x,y);
std::queue<QPoint> Q; std::queue<QPoint> Q;
Q.push(start); Q.push(start);
QColor oldColor = this->Active->image->getPixelColor(start); QColor oldColor = this->Active->image->getPixelColor(start);
QColor newColor = this->colorPicker->getFirstColor(); QColor newColor = this->colorPicker->getFirstColor();
Canvas->image->drawPixel(start,newColor); Canvas->image->drawPixel(start,newColor);
QPoint left, right, top, down; QPoint left, right, top, down;
while(!Q.empty()){ while(!Q.empty()) {
QPoint Current = Q.front(); QPoint Current = Q.front();
Q.pop(); Q.pop();
left = QPoint(Current.x()-1,Current.y() ); left = QPoint(Current.x()-1,Current.y() );
right = QPoint(Current.x()+1,Current.y() ); right = QPoint(Current.x()+1,Current.y() );
top = QPoint(Current.x() ,Current.y()-1); top = QPoint(Current.x(),Current.y()-1);
down = QPoint(Current.x() ,Current.y()+1); down = QPoint(Current.x(),Current.y()+1);
if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)){ if((right.x() < Canvas->width) && (Canvas->image->getPixelColor(right) != newColor) && (Active->image->getPixelColor(right) == oldColor)) {
Canvas->image->drawPixel(right,newColor); Canvas->image->drawPixel(right,newColor);
Q.push(right); Q.push(right);
} }
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)){ if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)) {
Canvas->image->drawPixel(left,newColor); Canvas->image->drawPixel(left,newColor);
Q.push(left); Q.push(left);
} }
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)){ if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)) {
Canvas->image->drawPixel(top,newColor); Canvas->image->drawPixel(top,newColor);
Q.push(top); Q.push(top);
} }
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)){ if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)) {
Canvas->image->drawPixel(down,newColor); Canvas->image->drawPixel(down,newColor);
Q.push(down); Q.push(down);
} }
} }
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){ void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
void IntelliToolFloodFill::onWheelScrolled(int value){ void IntelliToolFloodFill::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
} }
void IntelliToolFloodFill::onMouseMoved(int x, int y){ void IntelliToolFloodFill::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y); IntelliTool::onMouseMoved(x,y);
} }

View File

@@ -7,61 +7,61 @@
/*! /*!
* \brief The IntelliToolFloodFill class represents a tool to flood FIll a certian area. * \brief The IntelliToolFloodFill class represents a tool to flood FIll a certian area.
*/ */
class IntelliToolFloodFill : public IntelliTool{ class IntelliToolFloodFill : public IntelliTool {
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. * \brief A constructor setting the general paintingArea and colorPicker.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
virtual ~IntelliToolFloodFill() override; virtual ~IntelliToolFloodFill() override;
/*! /*!
* \brief A function managing the right click pressed of a mouse. Clearing the canvas. * \brief A function managing the right click pressed of a mouse. Clearing the canvas.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Sets the point to flood fill around and does this. * \brief A function managing the left click pressed of a mouse. Sets the point to flood fill around and does this.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. * \brief A function managing the left click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event. * \brief A function managing the scroll event.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*! /*!
* \brief A function managing the mouse moved event. * \brief A function managing the mouse moved event.
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };
#endif // INTELLITOOLFLOODFILL_H #endif // INTELLITOOLFLOODFILL_H

View File

@@ -4,60 +4,59 @@
#include "QInputDialog" #include "QInputDialog"
IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
//create checkbox or scroll dialog to get line style //create checkbox or scroll dialog to get line style
this->lineStyle = LineStyle::SOLID_LINE; this->lineStyle = LineStyle::SOLID_LINE;
} }
IntelliToolLine::~IntelliToolLine(){ IntelliToolLine::~IntelliToolLine(){
} }
void IntelliToolLine::onMouseRightPressed(int x, int y){ void IntelliToolLine::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolLine::onMouseRightReleased(int x, int y){ void IntelliToolLine::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,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->drawPoint(start, colorPicker->getFirstColor(),lineWidth); this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliToolLine::onMouseLeftReleased(int x, int y){ void IntelliToolLine::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
void IntelliToolLine::onWheelScrolled(int value){ void IntelliToolLine::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
this->lineWidth+=value; this->lineWidth+=value;
if(this->lineWidth<=0){ if(this->lineWidth<=0) {
this->lineWidth=1; this->lineWidth=1;
} }
} }
void IntelliToolLine::onMouseMoved(int x, int y){ void IntelliToolLine::onMouseMoved(int x, int y){
if(this->drawing){ if(this->drawing) {
this->Canvas->image->drawPlain(Qt::transparent); this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y); QPoint next(x,y);
switch(lineStyle){ switch(lineStyle) {
case LineStyle::SOLID_LINE: case LineStyle::SOLID_LINE:
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth); this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
break; break;
case LineStyle::DOTTED_LINE: case LineStyle::DOTTED_LINE:
QPoint p1 =start.x() <= next.x() ? start : next; QPoint p1 =start.x() <= next.x() ? start : next;
QPoint p2 =start.x() < next.x() ? next : start; QPoint p2 =start.x() < next.x() ? next : start;
int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f; int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f;
int c = start.y()-start.x()*m; int c = start.y()-start.x()*m;
break; break;
} }
} }
IntelliTool::onMouseMoved(x,y); IntelliTool::onMouseMoved(x,y);
} }

View File

@@ -7,83 +7,83 @@
/*! /*!
* \brief The LineStyle enum classifing all ways of drawing a line. * \brief The LineStyle enum classifing all ways of drawing a line.
*/ */
enum class LineStyle{ enum class LineStyle {
SOLID_LINE, SOLID_LINE,
DOTTED_LINE DOTTED_LINE
}; };
/*! /*!
* \brief The IntelliToolFloodFill class represents a tool to draw a line. * \brief The IntelliToolFloodFill class represents a tool to draw a line.
*/ */
class IntelliToolLine : public IntelliTool{ class IntelliToolLine : public IntelliTool {
/*! /*!
* \brief The starting point of the line. * \brief The starting point of the line.
*/ */
QPoint start; QPoint start;
/*! /*!
* \brief The width of the line to draw. * \brief The width of the line to draw.
*/ */
int lineWidth; int lineWidth;
/*! /*!
* \brief The style of the line. Apropriate to LineStyle. * \brief The style of the line. Apropriate to LineStyle.
*/ */
LineStyle lineStyle; LineStyle lineStyle;
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the lineWidth and lineStyle. * \brief A constructor setting the general paintingArea and colorPicker. And reading in the lineWidth and lineStyle.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief An abstract Destructor. * \brief An abstract Destructor.
*/ */
virtual ~IntelliToolLine() override; virtual ~IntelliToolLine() override;
/*! /*!
* \brief A function managing the right click pressed of a mouse. Clearing the canvas. * \brief A function managing the right click pressed of a mouse. Clearing the canvas.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Sets the starting point of the line. * \brief A function managing the left click pressed of a mouse. Sets the starting point of the line.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. * \brief A function managing the left click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event. Changing the lineWidth relative to value. * \brief A function managing the scroll event. Changing the lineWidth relative to value.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*! /*!
* \brief A function managing the mouse moved event. Drawing a Line from the startpoint to the current mouse position. * \brief A function managing the mouse moved event. Drawing a Line from the startpoint to the current mouse position.
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };
#endif // INTELLITOOLLINE_H #endif // INTELLITOOLLINE_H

View File

@@ -5,8 +5,8 @@
#include "QInputDialog" #include "QInputDialog"
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1); this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
} }
IntelliToolPen::~IntelliToolPen(){ IntelliToolPen::~IntelliToolPen(){
@@ -14,37 +14,37 @@ IntelliToolPen::~IntelliToolPen(){
} }
void IntelliToolPen::onMouseRightPressed(int x, int y){ void IntelliToolPen::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolPen::onMouseRightReleased(int x, int y){ void IntelliToolPen::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,y);
} }
void IntelliToolPen::onMouseLeftPressed(int x, int y){ void IntelliToolPen::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
this->point=QPoint(x,y); this->point=QPoint(x,y);
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor()); this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliToolPen::onMouseLeftReleased(int x, int y){ void IntelliToolPen::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
void IntelliToolPen::onMouseMoved(int x, int y){ void IntelliToolPen::onMouseMoved(int x, int y){
if(this->drawing){ if(this->drawing) {
QPoint newPoint(x,y); QPoint newPoint(x,y);
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth); this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
this->point=newPoint; this->point=newPoint;
} }
IntelliTool::onMouseMoved(x,y); IntelliTool::onMouseMoved(x,y);
} }
void IntelliToolPen::onWheelScrolled(int value){ void IntelliToolPen::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
this->penWidth+=value; this->penWidth+=value;
if(this->penWidth<=0){ if(this->penWidth<=0) {
this->penWidth=1; this->penWidth=1;
} }
} }

View File

@@ -1,73 +1,73 @@
#ifndef INTELLITOOLPEN_H #ifndef INTELLITOOLPEN_H
#define INTELLITOOLPEN_H #define INTELLITOOLPEN_H
#include"IntelliTool.h" #include "IntelliTool.h"
#include"QColor" #include "QColor"
#include"QPoint" #include "QPoint"
/*! /*!
* \brief The IntelliToolPen class represents a tool to draw a line. * \brief The IntelliToolPen class represents a tool to draw a line.
*/ */
class IntelliToolPen : public IntelliTool{ class IntelliToolPen : public IntelliTool {
/*! /*!
* \brief penWidth - The width of the Pen while drawing. * \brief penWidth - The width of the Pen while drawing.
*/ */
int penWidth; int penWidth;
/*! /*!
* \brief point - Represents the previous point to help drawing a line. * \brief point - Represents the previous point to help drawing a line.
*/ */
QPoint point; QPoint point;
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth. * \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth.
* \param Area - The general PaintingArea used by the project. * \param Area - The general PaintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
virtual ~IntelliToolPen() override; virtual ~IntelliToolPen() override;
/*! /*!
* \brief A function managing the right click pressed of a mouse. Resetting the current draw. * \brief A function managing the right click pressed of a mouse. Resetting the current draw.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Starting the drawing procedure. * \brief A function managing the left click pressed of a mouse. Starting the drawing procedure.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. Merging the drawing to the active layer. * \brief A function managing the left click released of a mouse. Merging the drawing to the active layer.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event. Changing penWidth relativ to value. * \brief A function managing the scroll event. Changing penWidth relativ to value.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*! /*!
* \brief A function managing the mouse moved event. To draw the line. * \brief A function managing the mouse moved event. To draw the line.
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };
#endif // INTELLITOOLPEN_H #endif // INTELLITOOLPEN_H

View File

@@ -3,7 +3,7 @@
#include "QColorDialog" #include "QColorDialog"
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
} }
IntelliToolPlainTool::~IntelliToolPlainTool(){ IntelliToolPlainTool::~IntelliToolPlainTool(){
@@ -11,28 +11,27 @@ IntelliToolPlainTool::~IntelliToolPlainTool(){
} }
void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){ void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
this->Canvas->image->drawPlain(colorPicker->getFirstColor()); this->Canvas->image->drawPlain(colorPicker->getFirstColor());
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){ void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
void IntelliToolPlainTool::onMouseRightPressed(int x, int y){ void IntelliToolPlainTool::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolPlainTool::onMouseRightReleased(int x, int y){ void IntelliToolPlainTool::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,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){ void IntelliToolPlainTool::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
} }

View File

@@ -6,59 +6,59 @@
/*! /*!
* \brief The IntelliToolPlainTool class represents a tool to fill the whole canvas with one color. * \brief The IntelliToolPlainTool class represents a tool to fill the whole canvas with one color.
*/ */
class IntelliToolPlainTool : public IntelliTool{ class IntelliToolPlainTool : public IntelliTool {
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. * \brief A constructor setting the general paintingArea and colorPicker.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker); IntelliToolPlainTool(PaintingArea*Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
virtual ~IntelliToolPlainTool() override; virtual ~IntelliToolPlainTool() override;
/*! /*!
* \brief A function managing the right click pressed of a mouse. Resetting the current fill. * \brief A function managing the right click pressed of a mouse. Resetting the current fill.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Filling the whole canvas. * \brief A function managing the left click pressed of a mouse. Filling the whole canvas.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. Merging the fill to the active layer. * \brief A function managing the left click released of a mouse. Merging the fill to the active layer.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event. * \brief A function managing the scroll event.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*! /*!
* \brief A function managing the mouse moved event. * \brief A function managing the mouse moved event.
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };

View File

@@ -5,11 +5,11 @@
#include <QInputDialog> #include <QInputDialog>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);; lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);;
PointIsNearStart = false; PointIsNearStart = false;
isDrawing = false; isDrawing = false;
} }
IntelliToolPolygon::~IntelliToolPolygon(){ IntelliToolPolygon::~IntelliToolPolygon(){
@@ -17,93 +17,93 @@ IntelliToolPolygon::~IntelliToolPolygon(){
} }
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){ if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
QPoint drawingPoint = QPoint(x,y); QPoint drawingPoint = QPoint(x,y);
isDrawing = true; isDrawing = true;
QPointList.push_back(drawingPoint); QPointList.push_back(drawingPoint);
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
else if(isDrawing && isNearStart(x,y,QPointList.front())){ else if(isDrawing && isNearStart(x,y,QPointList.front())) {
PointIsNearStart = true; PointIsNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
else if(isDrawing){ else if(isDrawing) {
QPoint drawingPoint(x,y); QPoint drawingPoint(x,y);
QPointList.push_back(drawingPoint); QPointList.push_back(drawingPoint);
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth); this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth);
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
} }
void IntelliToolPolygon::onMouseRightPressed(int x, int y){ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
isDrawing = false; isDrawing = false;
PointIsNearStart = false; PointIsNearStart = false;
QPointList.clear(); QPointList.clear();
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(PointIsNearStart && QPointList.size() > 1){ if(PointIsNearStart && QPointList.size() > 1) {
PointIsNearStart = false; PointIsNearStart = false;
isDrawing = false; isDrawing = false;
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList); std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
QPoint Point; QPoint Point;
QColor colorTwo(colorPicker->getSecondColor()); QColor colorTwo(colorPicker->getSecondColor());
colorTwo.setAlpha(alphaInner); colorTwo.setAlpha(alphaInner);
for(int i = 0; i < Active->width; i++){ for(int i = 0; i < Active->width; i++) {
for(int j = 0; j < Active->height; j++){ for(int j = 0; j < Active->height; j++) {
Point = QPoint(i,j); Point = QPoint(i,j);
if(IntelliHelper::isInPolygon(Triangles,Point)){ if(IntelliHelper::isInPolygon(Triangles,Point)) {
this->Canvas->image->drawPixel(Point, colorTwo); this->Canvas->image->drawPixel(Point, colorTwo);
} }
} }
} }
for(int i=0; i<QPointList.size(); i++){ for(int i=0; i<QPointList.size(); i++) {
int next = (i+1)%QPointList.size(); int next = (i+1)%QPointList.size();
this->Canvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth); this->Canvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth);
} }
QPointList.clear(); QPointList.clear();
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
} }
void IntelliToolPolygon::onMouseRightReleased(int x, int y){ void IntelliToolPolygon::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,y);
} }
void IntelliToolPolygon::onWheelScrolled(int value){ void IntelliToolPolygon::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
if(!isDrawing){ if(!isDrawing) {
if(lineWidth + value < 10){ if(lineWidth + value < 10) {
lineWidth += value; lineWidth += value;
} }
if(lineWidth < 1){ if(lineWidth < 1) {
lineWidth = 1; lineWidth = 1;
} }
} }
} }
void IntelliToolPolygon::onMouseMoved(int x, int y){ void IntelliToolPolygon::onMouseMoved(int x, int y){
IntelliTool::onMouseMoved(x,y); IntelliTool::onMouseMoved(x,y);
} }
bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){
bool isNear = false; bool isNear = false;
int StartX = Startpoint.x(); int StartX = Startpoint.x();
int StartY = Startpoint.y(); int StartY = Startpoint.y();
int valueToNear = 10; int valueToNear = 10;
for(int i = StartX - valueToNear; i < StartX + valueToNear; i++){ for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) {
for(int j = StartY - valueToNear; j < StartY + valueToNear; j++){ for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) {
if((i == x) && (j == y)){ if((i == x) && (j == y)) {
isNear = true; isNear = true;
} }
} }
} }
return isNear; return isNear;
} }

View File

@@ -10,92 +10,91 @@
*/ */
class IntelliToolPolygon : public IntelliTool class IntelliToolPolygon : public IntelliTool
{ {
/*! /*!
* \brief Checks if the given Point lies near the starting Point. * \brief Checks if the given Point lies near the starting Point.
* \param x - x coordinate of a point. * \param x - x coordinate of a point.
* \param y - y coordinate of a point. * \param y - y coordinate of a point.
* \param Startpoint - The startingpoint to check for. * \param Startpoint - The startingpoint to check for.
* \return Returns true if the (x,y) point is near to the startpoint, otherwise false. * \return Returns true if the (x,y) point is near to the startpoint, otherwise false.
*/ */
bool isNearStart(int x, int y, QPoint Startpoint); bool isNearStart(int x, int y, QPoint Startpoint);
/*! /*!
* \brief LineWidth of the drawing polygon. * \brief LineWidth of the drawing polygon.
*/ */
int lineWidth; int lineWidth;
/*! /*!
* \brief IsDrawing true while drawing, else false. * \brief IsDrawing true while drawing, else false.
*/ */
bool isDrawing; bool isDrawing;
/*! /*!
* \brief PointIsNearStart true, when last click near startpoint, else false. * \brief PointIsNearStart true, when last click near startpoint, else false.
*/ */
bool PointIsNearStart; bool PointIsNearStart;
/*! /*!
* \brief The alpha value of the inner circle. * \brief The alpha value of the inner circle.
*/ */
int alphaInner; int alphaInner;
/*! /*!
* \brief QPointList list of all points of the polygon. * \brief QPointList list of all points of the polygon.
*/ */
std::vector<QPoint> QPointList; std::vector<QPoint> QPointList;
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. * \brief A constructor setting the general paintingArea and colorPicker.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
~IntelliToolPolygon() override; ~IntelliToolPolygon() override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Setting polygon points. * \brief A function managing the left click pressed of a mouse. Setting polygon points.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. Merging the fill to the active layer. * \brief A function managing the left click released of a mouse. Merging the fill to the active layer.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the right click pressed of a mouse. Resetting the current fill. * \brief A function managing the right click pressed of a mouse. Resetting the current fill.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event. CHanging the lineWidth relative to value. * \brief A function managing the scroll event. CHanging the lineWidth relative to value.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*!
* \brief A function managing the mouse moved event.
* \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position.
*/
virtual void onMouseMoved(int x, int y) override;
/*!
* \brief A function managing the mouse moved event.
* \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position.
*/
virtual void onMouseMoved(int x, int y) override;
}; };

View File

@@ -1,11 +1,11 @@
#include"IntelliToolRectangle.h" #include "IntelliToolRectangle.h"
#include "Layer/PaintingArea.h" #include "Layer/PaintingArea.h"
#include "QInputDialog" #include "QInputDialog"
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker) IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker)
:IntelliTool(Area, colorPicker){ : IntelliTool(Area, colorPicker){
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); 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); this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
} }
IntelliToolRectangle::~IntelliToolRectangle(){ IntelliToolRectangle::~IntelliToolRectangle(){
@@ -13,55 +13,55 @@ IntelliToolRectangle::~IntelliToolRectangle(){
} }
void IntelliToolRectangle::drawRectangle(QPoint otherCornor){ void IntelliToolRectangle::drawRectangle(QPoint otherCornor){
int xMin = std::min(originCornor.x(), otherCornor.x()); int xMin = std::min(originCornor.x(), otherCornor.x());
int xMax = std::max(originCornor.x(), otherCornor.x()); int xMax = std::max(originCornor.x(), otherCornor.x());
int yMin = std::min(originCornor.y(), otherCornor.y()); int yMin = std::min(originCornor.y(), otherCornor.y());
int yMax = std::max(originCornor.y(), otherCornor.y()); int yMax = std::max(originCornor.y(), otherCornor.y());
QColor clr = colorPicker->getSecondColor(); QColor clr = colorPicker->getSecondColor();
clr.setAlpha(alphaInner); clr.setAlpha(alphaInner);
for(int y=yMin; y<=yMax; y++){ 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,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(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(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(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), 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){ void IntelliToolRectangle::onMouseRightPressed(int x, int y){
IntelliTool::onMouseRightPressed(x,y); IntelliTool::onMouseRightPressed(x,y);
} }
void IntelliToolRectangle::onMouseRightReleased(int x, int y){ void IntelliToolRectangle::onMouseRightReleased(int x, int y){
IntelliTool::onMouseRightReleased(x,y); IntelliTool::onMouseRightReleased(x,y);
} }
void IntelliToolRectangle::onMouseLeftPressed(int x, int y){ void IntelliToolRectangle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
this->originCornor=QPoint(x,y); this->originCornor=QPoint(x,y);
drawRectangle(originCornor); drawRectangle(originCornor);
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
void IntelliToolRectangle::onMouseLeftReleased(int x, int y){ void IntelliToolRectangle::onMouseLeftReleased(int x, int y){
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
} }
void IntelliToolRectangle::onMouseMoved(int x, int y){ void IntelliToolRectangle::onMouseMoved(int x, int y){
if(this->drawing){ if(this->drawing) {
this->Canvas->image->drawPlain(Qt::transparent); this->Canvas->image->drawPlain(Qt::transparent);
QPoint next(x,y); QPoint next(x,y);
drawRectangle(next); drawRectangle(next);
} }
IntelliTool::onMouseMoved(x,y); IntelliTool::onMouseMoved(x,y);
} }
void IntelliToolRectangle::onWheelScrolled(int value){ void IntelliToolRectangle::onWheelScrolled(int value){
IntelliTool::onWheelScrolled(value); IntelliTool::onWheelScrolled(value);
this->edgeWidth+=value; this->edgeWidth+=value;
if(this->edgeWidth<=0){ if(this->edgeWidth<=0) {
this->edgeWidth=1; this->edgeWidth=1;
} }
} }

View File

@@ -8,77 +8,77 @@
/*! /*!
* \brief The IntelliToolRectangle class represents a tool to draw a rectangle. * \brief The IntelliToolRectangle class represents a tool to draw a rectangle.
*/ */
class IntelliToolRectangle : public IntelliTool{ class IntelliToolRectangle : public IntelliTool {
/*! /*!
* \brief A function that implements a rectagle drawing algorithm. * \brief A function that implements a rectagle drawing algorithm.
* \param otherCornor - The second corner point of the rectangle. * \param otherCornor - The second corner point of the rectangle.
*/ */
void drawRectangle(QPoint otherCornor); void drawRectangle(QPoint otherCornor);
/*! /*!
* \brief originCornor - The first corner point of the rectangle. * \brief originCornor - The first corner point of the rectangle.
*/ */
QPoint originCornor; QPoint originCornor;
/*! /*!
* \brief alphaInner- Represents the alpha value of the inside. * \brief alphaInner- Represents the alpha value of the inside.
*/ */
int alphaInner; int alphaInner;
/*! /*!
* \brief edgeWidth - The width of the rectangle edges. * \brief edgeWidth - The width of the rectangle edges.
*/ */
int edgeWidth; int edgeWidth;
public: public:
/*! /*!
* \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth. * \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
*/ */
IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker); IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
virtual ~IntelliToolRectangle() override; virtual ~IntelliToolRectangle() override;
/*! /*!
* \brief A function managing the right click pressed of a mouse.Resetting the current draw. * \brief A function managing the right click pressed of a mouse.Resetting the current draw.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightPressed(int x, int y) override; virtual void onMouseRightPressed(int x, int y) override;
/*! /*!
* \brief A function managing the right click released of a mouse. * \brief A function managing the right click released of a mouse.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseRightReleased(int x, int y) override; virtual void onMouseRightReleased(int x, int y) override;
/*! /*!
* \brief A function managing the left click pressed of a mouse. Setting the originCorner and draws a rectangle. * \brief A function managing the left click pressed of a mouse. Setting the originCorner and draws a rectangle.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftPressed(int x, int y) override; virtual void onMouseLeftPressed(int x, int y) override;
/*! /*!
* \brief A function managing the left click released of a mouse. Merging the draw to the active layer. * \brief A function managing the left click released of a mouse. Merging the draw to the active layer.
* \param x - The x coordinate relative to the active/canvas layer. * \param x - The x coordinate relative to the active/canvas layer.
* \param y - The y coordinate relative to the active/canvas layer. * \param y - The y coordinate relative to the active/canvas layer.
*/ */
virtual void onMouseLeftReleased(int x, int y) override; virtual void onMouseLeftReleased(int x, int y) override;
/*! /*!
* \brief A function managing the scroll event.Changing edgeWidth relativ to value. * \brief A function managing the scroll event.Changing edgeWidth relativ to value.
* \param value - The absolute the scroll has changed. * \param value - The absolute the scroll has changed.
*/ */
virtual void onWheelScrolled(int value) override; virtual void onWheelScrolled(int value) override;
/*! /*!
* \brief A function managing the mouse moved event.Drawing a rectangle to currrent mouse position. * \brief A function managing the mouse moved event.Drawing a rectangle to currrent mouse position.
* \param x - The x coordinate of the new mouse position. * \param x - The x coordinate of the new mouse position.
* \param y - The y coordinate of the new mouse position. * \param y - The y coordinate of the new mouse position.
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };
#endif // INTELLIRECTANGLETOOL_H #endif // INTELLIRECTANGLETOOL_H