mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-12 19:40:28 +02:00
Restyled project for uncrustify
This commit is contained in:
@@ -195,7 +195,7 @@ void IntelliPhotoGui::slotSetActiveLayer(){
|
||||
if (ok1)
|
||||
{
|
||||
paintingArea->setLayerToActive(layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotSetFirstColor(){
|
||||
@@ -203,7 +203,7 @@ void IntelliPhotoGui::slotSetFirstColor(){
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotSetSecondColor(){
|
||||
paintingArea->colorPickerSetSecondColor();
|
||||
paintingArea->colorPickerSetSecondColor();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotSwitchColor(){
|
||||
@@ -223,19 +223,19 @@ void IntelliPhotoGui::slotCreateLineTool(){
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotCreateRectangleTool(){
|
||||
paintingArea->createRectangleTool();
|
||||
paintingArea->createRectangleTool();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotCreateCircleTool(){
|
||||
paintingArea->createCircleTool();
|
||||
paintingArea->createCircleTool();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotCreatePolygonTool(){
|
||||
paintingArea->createPolygonTool();
|
||||
paintingArea->createPolygonTool();
|
||||
}
|
||||
|
||||
void IntelliPhotoGui::slotCreateFloodFillTool(){
|
||||
paintingArea->createFloodFillTool();
|
||||
paintingArea->createFloodFillTool();
|
||||
}
|
||||
|
||||
// Open an about dialog
|
||||
@@ -342,17 +342,17 @@ void IntelliPhotoGui::createActions(){
|
||||
actionCreateLineTool = new QAction(tr("&Line"), this);
|
||||
connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool()));
|
||||
|
||||
actionCreateCircleTool = new QAction(tr("&Circle"), this);
|
||||
connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool()));
|
||||
actionCreateCircleTool = new QAction(tr("&Circle"), this);
|
||||
connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool()));
|
||||
|
||||
actionCreateRectangleTool = new QAction(tr("&Rectangle"), this);
|
||||
connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool()));
|
||||
actionCreateRectangleTool = new QAction(tr("&Rectangle"), this);
|
||||
connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool()));
|
||||
|
||||
actionCreatePolygonTool = new QAction(tr("&Polygon"), this);
|
||||
connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool()));
|
||||
actionCreatePolygonTool = new QAction(tr("&Polygon"), this);
|
||||
connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool()));
|
||||
|
||||
actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this);
|
||||
connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
|
||||
actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this);
|
||||
connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool()));
|
||||
|
||||
// Create about action and tie to IntelliPhotoGui::about()
|
||||
actionAboutDialog = new QAction(tr("&About"), this);
|
||||
@@ -405,10 +405,10 @@ void IntelliPhotoGui::createMenus(){
|
||||
toolMenu->addAction(actionCreatePenTool);
|
||||
toolMenu->addAction(actionCreatePlainTool);
|
||||
toolMenu->addAction(actionCreateLineTool);
|
||||
toolMenu->addAction(actionCreateRectangleTool);
|
||||
toolMenu->addAction(actionCreateCircleTool);
|
||||
toolMenu->addAction(actionCreatePolygonTool);
|
||||
toolMenu->addAction(actionCreateFloodFillTool);
|
||||
toolMenu->addAction(actionCreateRectangleTool);
|
||||
toolMenu->addAction(actionCreateCircleTool);
|
||||
toolMenu->addAction(actionCreatePolygonTool);
|
||||
toolMenu->addAction(actionCreateFloodFillTool);
|
||||
toolMenu->addSeparator();
|
||||
toolMenu->addMenu(colorMenu);
|
||||
|
||||
|
||||
@@ -19,123 +19,123 @@ class IntelliColorPicker;
|
||||
/*!
|
||||
* \brief The IntelliPhotoGui class handles the graphical user interface for the intelliPhoto program
|
||||
*/
|
||||
class IntelliPhotoGui : public QMainWindow{
|
||||
// Declares our class as a QObject which is the base class
|
||||
// for all Qt objects
|
||||
// QObjects handle events
|
||||
Q_OBJECT
|
||||
class IntelliPhotoGui : public QMainWindow {
|
||||
// Declares our class as a QObject which is the base class
|
||||
// for all Qt objects
|
||||
// QObjects handle events
|
||||
Q_OBJECT
|
||||
public:
|
||||
/*!
|
||||
* \brief The IntelliPhotoGui method is the constructor and is used to create a new instance of the main program window
|
||||
*/
|
||||
IntelliPhotoGui();
|
||||
/*!
|
||||
* \brief The IntelliPhotoGui method is the constructor and is used to create a new instance of the main program window
|
||||
*/
|
||||
IntelliPhotoGui();
|
||||
|
||||
protected:
|
||||
// Function used to close an event
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
// Function used to close an event
|
||||
void closeEvent(QCloseEvent*event) override;
|
||||
|
||||
private slots:
|
||||
// meta slots here (need further )
|
||||
void slotOpen();
|
||||
void slotSave();
|
||||
// meta slots here (need further )
|
||||
void slotOpen();
|
||||
void slotSave();
|
||||
|
||||
// layer slots here
|
||||
void slotCreateNewLayer();
|
||||
void slotDeleteLayer();
|
||||
void slotClearActiveLayer();
|
||||
void slotSetActiveLayer();
|
||||
void slotSetActiveAlpha();
|
||||
void slotPositionMoveUp();
|
||||
void slotPositionMoveDown();
|
||||
void slotPositionMoveLeft();
|
||||
void slotPositionMoveRight();
|
||||
void slotMoveLayerUp();
|
||||
void slotMoveLayerDown();
|
||||
// layer slots here
|
||||
void slotCreateNewLayer();
|
||||
void slotDeleteLayer();
|
||||
void slotClearActiveLayer();
|
||||
void slotSetActiveLayer();
|
||||
void slotSetActiveAlpha();
|
||||
void slotPositionMoveUp();
|
||||
void slotPositionMoveDown();
|
||||
void slotPositionMoveLeft();
|
||||
void slotPositionMoveRight();
|
||||
void slotMoveLayerUp();
|
||||
void slotMoveLayerDown();
|
||||
|
||||
// color Picker slots here
|
||||
void slotSetFirstColor();
|
||||
void slotSetSecondColor();
|
||||
void slotSwitchColor();
|
||||
// color Picker slots here
|
||||
void slotSetFirstColor();
|
||||
void slotSetSecondColor();
|
||||
void slotSwitchColor();
|
||||
|
||||
// tool slots here
|
||||
void slotCreatePenTool();
|
||||
void slotCreatePlainTool();
|
||||
void slotCreateLineTool();
|
||||
void slotCreateRectangleTool();
|
||||
void slotCreateCircleTool();
|
||||
void slotCreatePolygonTool();
|
||||
void slotCreateFloodFillTool();
|
||||
// tool slots here
|
||||
void slotCreatePenTool();
|
||||
void slotCreatePlainTool();
|
||||
void slotCreateLineTool();
|
||||
void slotCreateRectangleTool();
|
||||
void slotCreateCircleTool();
|
||||
void slotCreatePolygonTool();
|
||||
void slotCreateFloodFillTool();
|
||||
|
||||
// slots for dialogs
|
||||
void slotAboutDialog();
|
||||
// slots for dialogs
|
||||
void slotAboutDialog();
|
||||
|
||||
private:
|
||||
// Will tie user actions to functions
|
||||
void createActions();
|
||||
void createMenus();
|
||||
// setup GUI elements
|
||||
void createGui();
|
||||
// set style of the GUI
|
||||
void setIntelliStyle();
|
||||
// Will tie user actions to functions
|
||||
void createActions();
|
||||
void createMenus();
|
||||
// setup GUI elements
|
||||
void createGui();
|
||||
// set style of the GUI
|
||||
void setIntelliStyle();
|
||||
|
||||
// Will check if changes have occurred since last save
|
||||
bool maybeSave();
|
||||
// Opens the Save dialog and saves
|
||||
bool saveFile(const QByteArray &fileFormat);
|
||||
// Will check if changes have occurred since last save
|
||||
bool maybeSave();
|
||||
// Opens the Save dialog and saves
|
||||
bool saveFile(const QByteArray &fileFormat);
|
||||
|
||||
// What we'll draw on
|
||||
PaintingArea* paintingArea;
|
||||
// What we'll draw on
|
||||
PaintingArea* paintingArea;
|
||||
|
||||
// The menu widgets
|
||||
QMenu *saveAsMenu;
|
||||
QMenu *fileMenu;
|
||||
QMenu *optionMenu;
|
||||
QMenu *layerMenu;
|
||||
QMenu *colorMenu;
|
||||
QMenu *toolMenu;
|
||||
QMenu *helpMenu;
|
||||
// The menu widgets
|
||||
QMenu*saveAsMenu;
|
||||
QMenu*fileMenu;
|
||||
QMenu*optionMenu;
|
||||
QMenu*layerMenu;
|
||||
QMenu*colorMenu;
|
||||
QMenu*toolMenu;
|
||||
QMenu*helpMenu;
|
||||
|
||||
// All the actions that can occur
|
||||
// meta image actions (need further modularisation)
|
||||
QAction *actionOpen;
|
||||
QAction *actionExit;
|
||||
// All the actions that can occur
|
||||
// meta image actions (need further modularisation)
|
||||
QAction*actionOpen;
|
||||
QAction*actionExit;
|
||||
|
||||
// color Picker actions
|
||||
QAction *actionColorPickerFirstColor;
|
||||
QAction *actionColorPickerSecondColor;
|
||||
QAction *actionColorSwitch;
|
||||
// color Picker actions
|
||||
QAction*actionColorPickerFirstColor;
|
||||
QAction*actionColorPickerSecondColor;
|
||||
QAction*actionColorSwitch;
|
||||
|
||||
// tool actions
|
||||
QAction *actionCreatePenTool;
|
||||
QAction *actionCreatePlainTool;
|
||||
QAction *actionCreateLineTool;
|
||||
QAction *actionCreateRectangleTool;
|
||||
QAction *actionCreateCircleTool;
|
||||
QAction *actionCreatePolygonTool;
|
||||
QAction *actionCreateFloodFillTool;
|
||||
// tool actions
|
||||
QAction*actionCreatePenTool;
|
||||
QAction*actionCreatePlainTool;
|
||||
QAction*actionCreateLineTool;
|
||||
QAction*actionCreateRectangleTool;
|
||||
QAction*actionCreateCircleTool;
|
||||
QAction*actionCreatePolygonTool;
|
||||
QAction*actionCreateFloodFillTool;
|
||||
|
||||
// dialog actions
|
||||
QAction *actionAboutDialog;
|
||||
QAction *actionAboutQtDialog;
|
||||
// dialog actions
|
||||
QAction*actionAboutDialog;
|
||||
QAction*actionAboutQtDialog;
|
||||
|
||||
// layer change actions
|
||||
QAction *actionCreateNewLayer;
|
||||
QAction *actionDeleteLayer;
|
||||
QAction* actionSetActiveLayer;
|
||||
QAction* actionSetActiveAlpha;
|
||||
QAction* actionMovePositionUp;
|
||||
QAction* actionMovePositionDown;
|
||||
QAction* actionMovePositionLeft;
|
||||
QAction* actionMovePositionRight;
|
||||
QAction* actionMoveLayerUp;
|
||||
QAction* actionMoveLayerDown;
|
||||
// layer change actions
|
||||
QAction*actionCreateNewLayer;
|
||||
QAction*actionDeleteLayer;
|
||||
QAction* actionSetActiveLayer;
|
||||
QAction* actionSetActiveAlpha;
|
||||
QAction* actionMovePositionUp;
|
||||
QAction* actionMovePositionDown;
|
||||
QAction* actionMovePositionLeft;
|
||||
QAction* actionMovePositionRight;
|
||||
QAction* actionMoveLayerUp;
|
||||
QAction* actionMoveLayerDown;
|
||||
|
||||
// Actions tied to specific file formats
|
||||
QList<QAction *> actionSaveAs;
|
||||
// Actions tied to specific file formats
|
||||
QList<QAction*> actionSaveAs;
|
||||
|
||||
// main GUI elements
|
||||
QWidget* centralGuiWidget;
|
||||
QGridLayout *mainLayout;
|
||||
// main GUI elements
|
||||
QWidget* centralGuiWidget;
|
||||
QGridLayout*mainLayout;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include"Image/IntelliImage.h"
|
||||
#include<QSize>
|
||||
#include<QPainter>
|
||||
#include "Image/IntelliImage.h"
|
||||
#include <QSize>
|
||||
#include <QPainter>
|
||||
|
||||
IntelliImage::IntelliImage(int weight, int height)
|
||||
:imageData(QSize(weight, height), QImage::Format_ARGB32){
|
||||
imageData.fill(QColor(255,255,255,255));
|
||||
: imageData(QSize(weight, height), QImage::Format_ARGB32){
|
||||
imageData.fill(QColor(255,255,255,255));
|
||||
}
|
||||
|
||||
IntelliImage::~IntelliImage(){
|
||||
@@ -12,71 +12,71 @@ IntelliImage::~IntelliImage(){
|
||||
}
|
||||
|
||||
bool IntelliImage::loadImage(const QString &fileName){
|
||||
// Holds the image
|
||||
QImage loadedImage;
|
||||
// Holds the image
|
||||
QImage loadedImage;
|
||||
|
||||
// If the image wasn't loaded leave this function
|
||||
if (!loadedImage.load(fileName))
|
||||
return false;
|
||||
// If the image wasn't loaded leave this function
|
||||
if (!loadedImage.load(fileName))
|
||||
return false;
|
||||
|
||||
// scaled Image to size of Layer
|
||||
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
|
||||
// scaled Image to size of Layer
|
||||
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
|
||||
|
||||
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
|
||||
return true;
|
||||
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
|
||||
return true;
|
||||
}
|
||||
|
||||
void IntelliImage::resizeImage(QImage *image, const QSize &newSize){
|
||||
// Check if we need to redraw the image
|
||||
if (image->size() == newSize)
|
||||
return;
|
||||
void IntelliImage::resizeImage(QImage*image, const QSize &newSize){
|
||||
// Check if we need to redraw the image
|
||||
if (image->size() == newSize)
|
||||
return;
|
||||
|
||||
// Create a new image to display and fill it with white
|
||||
QImage newImage(newSize, QImage::Format_ARGB32);
|
||||
newImage.fill(qRgb(255, 255, 255));
|
||||
// Create a new image to display and fill it with white
|
||||
QImage newImage(newSize, QImage::Format_ARGB32);
|
||||
newImage.fill(qRgb(255, 255, 255));
|
||||
|
||||
// Draw the image
|
||||
QPainter painter(&newImage);
|
||||
painter.drawImage(QPoint(0, 0), *image);
|
||||
*image = newImage;
|
||||
// Draw the image
|
||||
QPainter painter(&newImage);
|
||||
painter.drawImage(QPoint(0, 0), *image);
|
||||
*image = newImage;
|
||||
}
|
||||
|
||||
void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
}
|
||||
|
||||
void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawPoint(p1);
|
||||
}
|
||||
|
||||
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
// Used to draw on the widget
|
||||
QPainter painter(&imageData);
|
||||
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
// Set the current settings for the pen
|
||||
painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawLine(p1, p2);
|
||||
// Draw a line from the last registered point to the current
|
||||
painter.drawLine(p1, p2);
|
||||
}
|
||||
|
||||
void IntelliImage::drawPlain(const QColor& color){
|
||||
imageData.fill(color);
|
||||
imageData.fill(color);
|
||||
}
|
||||
|
||||
QColor IntelliImage::getPixelColor(QPoint& point){
|
||||
return imageData.pixelColor(point);
|
||||
return imageData.pixelColor(point);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
#ifndef INTELLIIMAGE_H
|
||||
#define INTELLIIMAGE_H
|
||||
|
||||
#include<QImage>
|
||||
#include<QPoint>
|
||||
#include<QColor>
|
||||
#include<QSize>
|
||||
#include<QWidget>
|
||||
#include<vector>
|
||||
#include <QImage>
|
||||
#include <QPoint>
|
||||
#include <QColor>
|
||||
#include <QSize>
|
||||
#include <QWidget>
|
||||
#include <vector>
|
||||
|
||||
/*!
|
||||
* \brief The Types, which an Image can be.
|
||||
*/
|
||||
enum class ImageType{
|
||||
Raster_Image,
|
||||
Shaped_Image
|
||||
enum class ImageType {
|
||||
Raster_Image,
|
||||
Shaped_Image
|
||||
};
|
||||
|
||||
class IntelliTool;
|
||||
@@ -21,110 +21,112 @@ class IntelliTool;
|
||||
/*!
|
||||
* \brief An abstract class which manages the basic IntelliImage operations.
|
||||
*/
|
||||
class IntelliImage{
|
||||
friend IntelliTool;
|
||||
class IntelliImage {
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
void resizeImage(QImage *image, const QSize &newSize);
|
||||
void resizeImage(QImage*image, const QSize &newSize);
|
||||
|
||||
/*!
|
||||
* \brief The underlying image data.
|
||||
*/
|
||||
QImage imageData;
|
||||
/*!
|
||||
* \brief The underlying image data.
|
||||
*/
|
||||
QImage imageData;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliImage(int weight, int height);
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliImage(int weight, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliImage() = 0;
|
||||
/*!
|
||||
* \brief An Abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliImage() = 0;
|
||||
|
||||
|
||||
/*!
|
||||
* \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 color - The color of the pixel.
|
||||
*/
|
||||
virtual void drawPixel(const QPoint &p1, const QColor& 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 color - The color of the pixel.
|
||||
*/
|
||||
virtual void drawPixel(const QPoint &p1, const QColor& 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 p2 - The coordinates of the second Point.
|
||||
* \param color - The color 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);
|
||||
/*!
|
||||
* \brief A function that draws A Line between two given Points in a given color.
|
||||
* \param p1 - The coordinates of the first Point.
|
||||
* \param p2 - The coordinates of the second Point.
|
||||
* \param color - The color 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);
|
||||
|
||||
/*!
|
||||
* \brief A
|
||||
* \param p1
|
||||
* \param color
|
||||
* \param penWidth
|
||||
*/
|
||||
virtual void drawPoint(const QPoint &p1, const QColor& color, const int& penWidth);
|
||||
/*!
|
||||
* \brief A
|
||||
* \param p1
|
||||
* \param color
|
||||
* \param 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.
|
||||
* \param color - The color, in which the image will be filled.
|
||||
*/
|
||||
virtual void drawPlain(const QColor& color);
|
||||
/*!
|
||||
* \brief A function that clears the whole image in a given Color.
|
||||
* \param color - The color, in which the image will be filled.
|
||||
*/
|
||||
virtual void drawPlain(const QColor& color);
|
||||
|
||||
/*!
|
||||
* \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 alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0;
|
||||
/*!
|
||||
* \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 alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
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.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255)=0;
|
||||
/**
|
||||
* @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.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) = 0;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy()=0;
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() = 0;
|
||||
|
||||
/*!
|
||||
* \brief An abstract function that calculates the visiblity of the Image data if needed.
|
||||
*/
|
||||
virtual void calculateVisiblity()=0;
|
||||
/*!
|
||||
* \brief An abstract function that calculates the visiblity of the Image data if needed.
|
||||
*/
|
||||
virtual void calculateVisiblity() = 0;
|
||||
|
||||
/*!
|
||||
* \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.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
|
||||
/*!
|
||||
* \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.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) = 0;
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData(){ return std::vector<QPoint>();}
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData(){
|
||||
return std::vector<QPoint>();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
||||
* \param fileName - The path+name of the image which to loaded.
|
||||
* \return True if the image could be loaded, false otherwise.
|
||||
*/
|
||||
virtual bool loadImage(const QString &fileName);
|
||||
/*!
|
||||
* \brief A function that loads and sclaes an image to the fitting dimensions.
|
||||
* \param fileName - The path+name of the image which to loaded.
|
||||
* \return True if the image could be loaded, false otherwise.
|
||||
*/
|
||||
virtual bool loadImage(const QString &fileName);
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the pixelcolor at a certain point
|
||||
* \param point - The point from whcih to get the coordinates.
|
||||
* \return The color of the Pixel as QColor.
|
||||
*/
|
||||
virtual QColor getPixelColor(QPoint& point);
|
||||
/*!
|
||||
* \brief A function that returns the pixelcolor at a certain point
|
||||
* \param point - The point from whcih to get the coordinates.
|
||||
* \return The color of the Pixel as QColor.
|
||||
*/
|
||||
virtual QColor getPixelColor(QPoint& point);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include"Image/IntelliRasterImage.h"
|
||||
#include<QPainter>
|
||||
#include<QRect>
|
||||
#include<QDebug>
|
||||
#include "Image/IntelliRasterImage.h"
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <QDebug>
|
||||
|
||||
IntelliRasterImage::IntelliRasterImage(int weight, int height)
|
||||
:IntelliImage(weight, height){
|
||||
: IntelliImage(weight, height){
|
||||
|
||||
}
|
||||
|
||||
@@ -13,32 +13,32 @@ IntelliRasterImage::~IntelliRasterImage(){
|
||||
}
|
||||
|
||||
IntelliImage* IntelliRasterImage::getDeepCopy(){
|
||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||
raster->imageData.fill(Qt::transparent);
|
||||
return raster;
|
||||
IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height());
|
||||
raster->imageData.fill(Qt::transparent);
|
||||
return raster;
|
||||
}
|
||||
|
||||
void IntelliRasterImage::calculateVisiblity(){
|
||||
// not used in raster image
|
||||
// not used in raster image
|
||||
}
|
||||
|
||||
QImage IntelliRasterImage::getDisplayable(int alpha){
|
||||
return getDisplayable(imageData.size(), alpha);
|
||||
return getDisplayable(imageData.size(), alpha);
|
||||
}
|
||||
|
||||
QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
QImage copy = imageData;
|
||||
for(int y = 0; y<copy.height(); y++){
|
||||
for(int x = 0; x<copy.width(); x++){
|
||||
QColor clr = copy.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(alpha, clr.alpha()));
|
||||
copy.setPixelColor(x,y, clr);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
QImage copy = imageData;
|
||||
for(int y = 0; y<copy.height(); y++) {
|
||||
for(int x = 0; x<copy.width(); x++) {
|
||||
QColor clr = copy.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(alpha, clr.alpha()));
|
||||
copy.setPixelColor(x,y, clr);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
}
|
||||
|
||||
void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
|
||||
return;
|
||||
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
#ifndef INTELLIRASTER_H
|
||||
#define INTELLIRASTER_H
|
||||
|
||||
#include"Image/IntelliImage.h"
|
||||
#include "Image/IntelliImage.h"
|
||||
|
||||
/*!
|
||||
* \brief The IntelliRasterImage manages a Rasterimage.
|
||||
*/
|
||||
class IntelliRasterImage : public IntelliImage{
|
||||
friend IntelliTool;
|
||||
class IntelliRasterImage : public IntelliImage {
|
||||
friend IntelliTool;
|
||||
protected:
|
||||
/*!
|
||||
* \brief A function that calculates the visibility of the image if a polygon is given. [does nothing in Rasterimage]
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
/*!
|
||||
* \brief A function that calculates the visibility of the image if a polygon is given. [does nothing in Rasterimage]
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliRasterImage(int weight, int height);
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliRasterImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliRasterImage(int weight, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliRasterImage() override;
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliRasterImage() override;
|
||||
|
||||
/*!
|
||||
* \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 alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize,int alpha) override;
|
||||
/*!
|
||||
* \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 alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
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.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
/**
|
||||
* @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.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
|
||||
/*!
|
||||
* \brief An abstract function that sets the data of the visible Polygon, if needed.
|
||||
* \param polygonData - The Vertices of the Polygon. Nothing happens.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
/*!
|
||||
* \brief An abstract function that sets the data of the visible Polygon, if needed.
|
||||
* \param polygonData - The Vertices of the Polygon. Nothing happens.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include"Image/IntelliShapedImage.h"
|
||||
#include"IntelliHelper/IntelliHelper.h"
|
||||
#include<QPainter>
|
||||
#include<QRect>
|
||||
#include<QDebug>
|
||||
#include "Image/IntelliShapedImage.h"
|
||||
#include "IntelliHelper/IntelliHelper.h"
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <QDebug>
|
||||
|
||||
IntelliShapedImage::IntelliShapedImage(int weight, int height)
|
||||
:IntelliRasterImage(weight, height){
|
||||
: IntelliRasterImage(weight, height){
|
||||
}
|
||||
|
||||
IntelliShapedImage::~IntelliShapedImage(){
|
||||
@@ -13,66 +13,66 @@ IntelliShapedImage::~IntelliShapedImage(){
|
||||
}
|
||||
|
||||
QImage IntelliShapedImage::getDisplayable(int alpha){
|
||||
return getDisplayable(imageData.size(),alpha);
|
||||
return getDisplayable(imageData.size(),alpha);
|
||||
}
|
||||
|
||||
IntelliImage* IntelliShapedImage::getDeepCopy(){
|
||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||
shaped->setPolygon(this->polygonData);
|
||||
shaped->imageData.fill(Qt::transparent);
|
||||
return shaped;
|
||||
IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height());
|
||||
shaped->setPolygon(this->polygonData);
|
||||
shaped->imageData.fill(Qt::transparent);
|
||||
return shaped;
|
||||
}
|
||||
|
||||
void IntelliShapedImage::calculateVisiblity(){
|
||||
if(polygonData.size()<=2){
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++){
|
||||
for(int x=0; x<imageData.width(); x++){
|
||||
clr = imageData.pixel(x,y);
|
||||
clr.setAlpha(255);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++){
|
||||
for(int x=0; x<imageData.width(); x++){
|
||||
QPoint ptr(x,y);
|
||||
clr = imageData.pixelColor(x,y);
|
||||
bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr);
|
||||
if(isInPolygon){
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
}else{
|
||||
clr.setAlpha(0);
|
||||
}
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
if(polygonData.size()<=2) {
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++) {
|
||||
for(int x=0; x<imageData.width(); x++) {
|
||||
clr = imageData.pixel(x,y);
|
||||
clr.setAlpha(255);
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
QColor clr;
|
||||
for(int y=0; y<imageData.height(); y++) {
|
||||
for(int x=0; x<imageData.width(); x++) {
|
||||
QPoint ptr(x,y);
|
||||
clr = imageData.pixelColor(x,y);
|
||||
bool isInPolygon = IntelliHelper::isInPolygon(triangles, ptr);
|
||||
if(isInPolygon) {
|
||||
clr.setAlpha(std::min(255, clr.alpha()));
|
||||
}else{
|
||||
clr.setAlpha(0);
|
||||
}
|
||||
imageData.setPixelColor(x,y,clr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
|
||||
QImage copy = imageData;
|
||||
for(int y = 0; y<copy.height(); y++){
|
||||
for(int x = 0; x<copy.width(); x++){
|
||||
QColor clr = copy.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(alpha,clr.alpha()));
|
||||
copy.setPixelColor(x,y, clr);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
QImage copy = imageData;
|
||||
for(int y = 0; y<copy.height(); y++) {
|
||||
for(int x = 0; x<copy.width(); x++) {
|
||||
QColor clr = copy.pixelColor(x,y);
|
||||
clr.setAlpha(std::min(alpha,clr.alpha()));
|
||||
copy.setPixelColor(x,y, clr);
|
||||
}
|
||||
}
|
||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||
}
|
||||
|
||||
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||
if(polygonData.size()<3){
|
||||
this->polygonData.clear();
|
||||
}else{
|
||||
this->polygonData.clear();
|
||||
for(auto element:polygonData){
|
||||
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||
}
|
||||
triangles = IntelliHelper::calculateTriangles(polygonData);
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
if(polygonData.size()<3) {
|
||||
this->polygonData.clear();
|
||||
}else{
|
||||
this->polygonData.clear();
|
||||
for(auto element:polygonData) {
|
||||
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||
}
|
||||
triangles = IntelliHelper::calculateTriangles(polygonData);
|
||||
}
|
||||
calculateVisiblity();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,76 +1,78 @@
|
||||
#ifndef INTELLISHAPE_H
|
||||
#define INTELLISHAPE_H
|
||||
|
||||
#include"Image/IntelliRasterImage.h"
|
||||
#include<vector>
|
||||
#include"IntelliHelper/IntelliHelper.h"
|
||||
#include "Image/IntelliRasterImage.h"
|
||||
#include <vector>
|
||||
#include "IntelliHelper/IntelliHelper.h"
|
||||
|
||||
/*!
|
||||
* \brief The IntelliShapedImage manages a Shapedimage.
|
||||
*/
|
||||
class IntelliShapedImage : public IntelliRasterImage{
|
||||
friend IntelliTool;
|
||||
class IntelliShapedImage : public IntelliRasterImage {
|
||||
friend IntelliTool;
|
||||
private:
|
||||
/*!
|
||||
* \brief The Triangulation of the Polygon. Saved here for performance reasons.
|
||||
*/
|
||||
std::vector<Triangle> triangles;
|
||||
/*!
|
||||
* \brief The Triangulation of the Polygon. Saved here for performance reasons.
|
||||
*/
|
||||
std::vector<Triangle> triangles;
|
||||
|
||||
/*!
|
||||
* \brief Calculates the visibility based on the underlying polygon.
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
/*!
|
||||
* \brief Calculates the visibility based on the underlying polygon.
|
||||
*/
|
||||
virtual void calculateVisiblity() override;
|
||||
protected:
|
||||
|
||||
/*!
|
||||
* \brief The Vertices of The Polygon. Needs to be a planar Polygon.
|
||||
*/
|
||||
std::vector<QPoint> polygonData;
|
||||
/*!
|
||||
* \brief The Vertices of The Polygon. Needs to be a planar Polygon.
|
||||
*/
|
||||
std::vector<QPoint> polygonData;
|
||||
public:
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliShapedImage(int weight, int height);
|
||||
/*!
|
||||
* \brief The Construcor of the IntelliShapedImage. Given the Image dimensions.
|
||||
* \param weight - The weight of the Image.
|
||||
* \param height - The height of the Image.
|
||||
*/
|
||||
IntelliShapedImage(int weight, int height);
|
||||
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliShapedImage() override;
|
||||
/*!
|
||||
* \brief An Destructor.
|
||||
*/
|
||||
virtual ~IntelliShapedImage() override;
|
||||
|
||||
/*!
|
||||
* \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 alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override;
|
||||
/*!
|
||||
* \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 alpha - The maximum alpha value, a pixel can have.
|
||||
* \return A QImage which is ready to be displayed.
|
||||
*/
|
||||
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.
|
||||
* @param alpha - The maximum alpha value, a pixel can have.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
/**
|
||||
* @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.
|
||||
* @return A QImage which is ready to be displayed.
|
||||
*/
|
||||
virtual QImage getDisplayable(int alpha=255) override;
|
||||
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
/*!
|
||||
* \brief A function that copys all that returns a [allocated] Image
|
||||
* \return A [allocated] Image with all the properties of the instance.
|
||||
*/
|
||||
virtual IntelliImage* getDeepCopy() override;
|
||||
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData() override{return polygonData;}
|
||||
/*!
|
||||
* \brief A function that returns the Polygondata if existent.
|
||||
* \return The Polygondata if existent.
|
||||
*/
|
||||
virtual std::vector<QPoint> getPolygonData() override {
|
||||
return polygonData;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief A function that sets the data of the visible Polygon.
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
/*!
|
||||
* \brief A function that sets the data of the visible Polygon.
|
||||
* \param polygonData - The Vertices of the Polygon. Just Planar Polygons are allowed.
|
||||
*/
|
||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "IntelliColorPicker.h"
|
||||
|
||||
IntelliColorPicker::IntelliColorPicker(){
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,255,255,255};
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,255,255,255};
|
||||
}
|
||||
|
||||
IntelliColorPicker::~IntelliColorPicker(){
|
||||
@@ -10,21 +10,21 @@ IntelliColorPicker::~IntelliColorPicker(){
|
||||
}
|
||||
|
||||
void IntelliColorPicker::switchColors(){
|
||||
std::swap(firstColor, secondColor);
|
||||
std::swap(firstColor, secondColor);
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getFirstColor(){
|
||||
return this->firstColor;
|
||||
return this->firstColor;
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getSecondColor(){
|
||||
return this->secondColor;
|
||||
return this->secondColor;
|
||||
}
|
||||
|
||||
void IntelliColorPicker::setFirstColor(QColor Color){
|
||||
this->firstColor = Color;
|
||||
this->firstColor = Color;
|
||||
}
|
||||
|
||||
void IntelliColorPicker::setSecondColor(QColor Color){
|
||||
this->secondColor = Color;
|
||||
this->secondColor = Color;
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
#ifndef INTELLITOOLSETCOLORTOOL_H
|
||||
#define INTELLITOOLSETCOLORTOOL_H
|
||||
|
||||
#include"QColor"
|
||||
#include"QPoint"
|
||||
#include"QColorDialog"
|
||||
#include "QColor"
|
||||
#include "QPoint"
|
||||
#include "QColorDialog"
|
||||
|
||||
/*!
|
||||
* \brief The IntelliColorPicker manages the selected colors for one whole project.
|
||||
*/
|
||||
class IntelliColorPicker{
|
||||
class IntelliColorPicker {
|
||||
public:
|
||||
/*!
|
||||
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
|
||||
*/
|
||||
IntelliColorPicker();
|
||||
/*!
|
||||
* \brief IntelliColorPicker constructor, setting 2 preset colors, be careful, theese color may change in production.
|
||||
*/
|
||||
IntelliColorPicker();
|
||||
|
||||
/*!
|
||||
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
|
||||
*/
|
||||
virtual ~IntelliColorPicker();
|
||||
/*!
|
||||
* \brief IntelliColorPicker destructor clears up his used memory, if there is some.
|
||||
*/
|
||||
virtual ~IntelliColorPicker();
|
||||
|
||||
/*!
|
||||
* \brief A function switching primary and secondary color.
|
||||
*/
|
||||
void switchColors();
|
||||
/*!
|
||||
* \brief A function switching primary and secondary color.
|
||||
*/
|
||||
void switchColors();
|
||||
|
||||
/*!
|
||||
* \brief A function to read the primary selected color.
|
||||
* \return Returns the primary color.
|
||||
*/
|
||||
QColor getFirstColor();
|
||||
/*!
|
||||
* \brief A function to read the primary selected color.
|
||||
* \return Returns the primary color.
|
||||
*/
|
||||
QColor getFirstColor();
|
||||
|
||||
/*!
|
||||
* \brief A function to read the secondary selected color.
|
||||
* \return Returns the secondary color.
|
||||
*/
|
||||
QColor getSecondColor();
|
||||
/*!
|
||||
* \brief A function to read the secondary selected color.
|
||||
* \return Returns the secondary color.
|
||||
*/
|
||||
QColor getSecondColor();
|
||||
|
||||
/*!
|
||||
* \brief A function to set the primary color.
|
||||
* \param Color - The color to be set as primary.
|
||||
*/
|
||||
void setFirstColor(QColor Color);
|
||||
/*!
|
||||
* \brief A function to set the primary color.
|
||||
* \param Color - The color to be set as primary.
|
||||
*/
|
||||
void setFirstColor(QColor Color);
|
||||
|
||||
/*!
|
||||
* \brief A function to set the secondary color.
|
||||
* \param Color - The color to be set as secondary.
|
||||
*/
|
||||
void setSecondColor(QColor Color);
|
||||
/*!
|
||||
* \brief A function to set the secondary color.
|
||||
* \param Color - The color to be set as secondary.
|
||||
*/
|
||||
void setSecondColor(QColor Color);
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief The primary color.
|
||||
*/
|
||||
QColor firstColor;
|
||||
/*!
|
||||
* \brief The primary color.
|
||||
*/
|
||||
QColor firstColor;
|
||||
|
||||
/*!
|
||||
* \brief The secondary color.
|
||||
*/
|
||||
QColor secondColor;
|
||||
/*!
|
||||
* \brief The secondary color.
|
||||
*/
|
||||
QColor secondColor;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLSETCOLORTOOL_H
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
#include"IntelliHelper.h"
|
||||
#include<algorithm>
|
||||
#include<queue>
|
||||
#include<cmath>
|
||||
#include "IntelliHelper.h"
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
std::vector<Triangle> IntelliHelper::calculateTriangles(std::vector<QPoint> polyPoints){
|
||||
// helper for managing the triangle vertices and their state
|
||||
struct TriangleHelper{
|
||||
QPoint vertex;
|
||||
float interiorAngle;
|
||||
int index;
|
||||
bool isTip;
|
||||
};
|
||||
// helper for managing the triangle vertices and their state
|
||||
struct TriangleHelper {
|
||||
QPoint vertex;
|
||||
float interiorAngle;
|
||||
int index;
|
||||
bool isTip;
|
||||
};
|
||||
|
||||
// calculates the inner angle of 'point'
|
||||
auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){
|
||||
QPoint AP(point.x()-prev.x(), point.y()-prev.y());
|
||||
QPoint BP(point.x()-post.x(), point.y()-post.y());
|
||||
// calculates the inner angle of 'point'
|
||||
auto calculateInner = [](QPoint& point, QPoint& prev, QPoint& post){
|
||||
QPoint AP(point.x()-prev.x(), point.y()-prev.y());
|
||||
QPoint BP(point.x()-post.x(), point.y()-post.y());
|
||||
|
||||
float topSclar = AP.x()*BP.x()+AP.y()*BP.y();
|
||||
float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.));
|
||||
return acos(topSclar/absolute);
|
||||
};
|
||||
float topSclar = AP.x()*BP.x()+AP.y()*BP.y();
|
||||
float absolute = sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.));
|
||||
return acos(topSclar/absolute);
|
||||
};
|
||||
|
||||
// gets the first element of vec for which element.isTip == true holds
|
||||
auto getTip= [](const std::vector<TriangleHelper>& vec){
|
||||
size_t min = 0;
|
||||
for(size_t i=0; i<vec.size(); i++){
|
||||
if(vec[i].interiorAngle<vec[min].interiorAngle){
|
||||
min = i;
|
||||
}
|
||||
}
|
||||
return vec[min];
|
||||
};
|
||||
// gets the first element of vec for which element.isTip == true holds
|
||||
auto getTip= [](const std::vector<TriangleHelper>& vec){
|
||||
size_t min = 0;
|
||||
for(size_t i=0; i<vec.size(); i++) {
|
||||
if(vec[i].interiorAngle<vec[min].interiorAngle) {
|
||||
min = i;
|
||||
}
|
||||
}
|
||||
return vec[min];
|
||||
};
|
||||
|
||||
// get the vertex Index bevor index in relation to the container length
|
||||
auto getPrev = [](int index, int length){
|
||||
return (index-1)>=0?(index-1):(length-1);
|
||||
};
|
||||
// get the vertex Index bevor index in relation to the container length
|
||||
auto getPrev = [](int index, int length){
|
||||
return (index-1)>=0 ? (index-1) : (length-1);
|
||||
};
|
||||
|
||||
// get the vertex Index after index in relation to the container lenght
|
||||
auto getPost = [](int index, int length){
|
||||
return (index+1)%length;
|
||||
};
|
||||
// get the vertex Index after index in relation to the container lenght
|
||||
auto getPost = [](int index, int length){
|
||||
return (index+1)%length;
|
||||
};
|
||||
|
||||
// return if the vertex is a tip
|
||||
auto isTip = [](float angle){
|
||||
return static_cast<double>(angle)<(M_PI/2.);
|
||||
};
|
||||
// return if the vertex is a tip
|
||||
auto isTip = [](float angle){
|
||||
return static_cast<double>(angle)<(M_PI/2.);
|
||||
};
|
||||
|
||||
std::vector<TriangleHelper> Vertices;
|
||||
std::vector<Triangle> Triangles;
|
||||
std::vector<TriangleHelper> Vertices;
|
||||
std::vector<Triangle> Triangles;
|
||||
|
||||
// set up all vertices and calculate intirior angle
|
||||
for(int i=0; i<static_cast<int>(polyPoints.size()); i++){
|
||||
TriangleHelper helper;
|
||||
int prev = getPrev(i, static_cast<int>(polyPoints.size()));
|
||||
int post = getPost(i, static_cast<int>(polyPoints.size()));
|
||||
// set up all vertices and calculate intirior angle
|
||||
for(int i=0; i<static_cast<int>(polyPoints.size()); i++) {
|
||||
TriangleHelper helper;
|
||||
int prev = getPrev(i, static_cast<int>(polyPoints.size()));
|
||||
int post = getPost(i, static_cast<int>(polyPoints.size()));
|
||||
|
||||
helper.vertex = polyPoints[static_cast<size_t>(i)];
|
||||
helper.index = i;
|
||||
helper.vertex = polyPoints[static_cast<size_t>(i)];
|
||||
helper.index = i;
|
||||
|
||||
helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)],
|
||||
polyPoints[static_cast<size_t>(prev)],
|
||||
polyPoints[static_cast<size_t>(post)]);
|
||||
helper.isTip = isTip(helper.interiorAngle);
|
||||
Vertices.push_back(helper);
|
||||
}
|
||||
helper.interiorAngle = calculateInner(polyPoints[static_cast<size_t>(i)],
|
||||
polyPoints[static_cast<size_t>(prev)],
|
||||
polyPoints[static_cast<size_t>(post)]);
|
||||
helper.isTip = isTip(helper.interiorAngle);
|
||||
Vertices.push_back(helper);
|
||||
}
|
||||
|
||||
// search triangles based on the intirior angles of each vertey
|
||||
while(Triangles.size() != polyPoints.size()-2){
|
||||
Triangle tri;
|
||||
TriangleHelper smallest = getTip(Vertices);
|
||||
int prev = getPrev(smallest.index, static_cast<int>(Vertices.size()));
|
||||
int post = getPost(smallest.index, static_cast<int>(Vertices.size()));
|
||||
// search triangles based on the intirior angles of each vertey
|
||||
while(Triangles.size() != polyPoints.size()-2) {
|
||||
Triangle tri;
|
||||
TriangleHelper smallest = getTip(Vertices);
|
||||
int prev = getPrev(smallest.index, static_cast<int>(Vertices.size()));
|
||||
int post = getPost(smallest.index, static_cast<int>(Vertices.size()));
|
||||
|
||||
// set triangle and push it
|
||||
tri.A = Vertices[static_cast<size_t>(prev)].vertex;
|
||||
tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex;
|
||||
tri.C = Vertices[static_cast<size_t>(post)].vertex;
|
||||
Triangles.push_back(tri);
|
||||
// set triangle and push it
|
||||
tri.A = Vertices[static_cast<size_t>(prev)].vertex;
|
||||
tri.B = Vertices[static_cast<size_t>(smallest.index)].vertex;
|
||||
tri.C = Vertices[static_cast<size_t>(post)].vertex;
|
||||
Triangles.push_back(tri);
|
||||
|
||||
// update Vertice array
|
||||
Vertices.erase(Vertices.begin()+smallest.index);
|
||||
for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++){
|
||||
Vertices[i].index-=1;
|
||||
}
|
||||
// update Vertice array
|
||||
Vertices.erase(Vertices.begin()+smallest.index);
|
||||
for(size_t i=static_cast<size_t>(smallest.index); i<Vertices.size(); i++) {
|
||||
Vertices[i].index-=1;
|
||||
}
|
||||
|
||||
// update post und prev index
|
||||
post = post-1;
|
||||
prev = prev<smallest.index?prev:(prev-1);
|
||||
// update post und prev index
|
||||
post = post-1;
|
||||
prev = prev<smallest.index ? prev : (prev-1);
|
||||
|
||||
// calcultae neighboors of prev and post to calculate new interior angles
|
||||
int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size()));
|
||||
int postOfPrev = getPost(prev, static_cast<int>(Vertices.size()));
|
||||
// calcultae neighboors of prev and post to calculate new interior angles
|
||||
int prevOfPrev = getPrev(prev, static_cast<int>(Vertices.size()));
|
||||
int postOfPrev = getPost(prev, static_cast<int>(Vertices.size()));
|
||||
|
||||
int prevOfPost = getPrev(post, static_cast<int>(Vertices.size()));
|
||||
int postOfPost = getPost(post, static_cast<int>(Vertices.size()));
|
||||
int prevOfPost = getPrev(post, static_cast<int>(Vertices.size()));
|
||||
int postOfPost = getPost(post, static_cast<int>(Vertices.size()));
|
||||
|
||||
// update vertices with interior angles
|
||||
// updtae prev
|
||||
Vertices[static_cast<size_t>(prev)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(prev)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPrev)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPrev)].vertex);
|
||||
Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle);
|
||||
// update post
|
||||
Vertices[static_cast<size_t>(post)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(post)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPost)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPost)].vertex);
|
||||
Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle);
|
||||
}
|
||||
return Triangles;
|
||||
// update vertices with interior angles
|
||||
// updtae prev
|
||||
Vertices[static_cast<size_t>(prev)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(prev)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPrev)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPrev)].vertex);
|
||||
Vertices[static_cast<size_t>(prev)].isTip = isTip(Vertices[static_cast<size_t>(prev)].interiorAngle);
|
||||
// update post
|
||||
Vertices[static_cast<size_t>(post)].interiorAngle = calculateInner(Vertices[static_cast<size_t>(post)].vertex,
|
||||
Vertices[static_cast<size_t>(prevOfPost)].vertex,
|
||||
Vertices[static_cast<size_t>(postOfPost)].vertex);
|
||||
Vertices[static_cast<size_t>(post)].isTip = isTip(Vertices[static_cast<size_t>(post)].interiorAngle);
|
||||
}
|
||||
return Triangles;
|
||||
}
|
||||
|
||||
bool IntelliHelper::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
|
||||
for(auto triangle : triangles){
|
||||
if(IntelliHelper::isInTriangle(triangle, point)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
for(auto triangle : triangles) {
|
||||
if(IntelliHelper::isInTriangle(triangle, point)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
#ifndef INTELLIHELPER_H
|
||||
#define INTELLIHELPER_H
|
||||
|
||||
#include<QPoint>
|
||||
#include<vector>
|
||||
#include <QPoint>
|
||||
#include <vector>
|
||||
|
||||
/*!
|
||||
* \brief The Triangle struct holds the 3 vertices of a triangle.
|
||||
*/
|
||||
struct Triangle{
|
||||
QPoint A,B,C;
|
||||
struct Triangle {
|
||||
QPoint A,B,C;
|
||||
};
|
||||
|
||||
namespace IntelliHelper {
|
||||
|
||||
/*!
|
||||
* \brief A function to get the 2*area of a traingle, using its determinat.
|
||||
* \param p1 - The Point to check its side.
|
||||
* \param p2 - The first Point of the spanning Line
|
||||
* \param p3 - The second Point of the spanning line.
|
||||
* \return Returns the area of the traingle*2
|
||||
*/
|
||||
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());
|
||||
}
|
||||
/*!
|
||||
* \brief A function to get the 2*area of a traingle, using its determinat.
|
||||
* \param p1 - The Point to check its side.
|
||||
* \param p2 - The first Point of the spanning Line
|
||||
* \param p3 - The second Point of the spanning line.
|
||||
* \return Returns the area of the traingle*2
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \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 P - The point to check if it is in the triangle.
|
||||
* \return Returns true if the point is in the triangle, false otheriwse
|
||||
*/
|
||||
inline bool isInTriangle(Triangle& tri, QPoint& P){
|
||||
float val1, val2, val3;
|
||||
bool neg, pos;
|
||||
/*!
|
||||
* \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 P - The point to check if it is in the triangle.
|
||||
* \return Returns true if the point is in the triangle, false otheriwse
|
||||
*/
|
||||
inline bool isInTriangle(Triangle& tri, QPoint& P){
|
||||
float val1, val2, val3;
|
||||
bool neg, pos;
|
||||
|
||||
val1 = IntelliHelper::sign(P,tri.A,tri.B);
|
||||
val2 = IntelliHelper::sign(P,tri.B,tri.C);
|
||||
val3 = IntelliHelper::sign(P,tri.C,tri.A);
|
||||
val1 = IntelliHelper::sign(P,tri.A,tri.B);
|
||||
val2 = IntelliHelper::sign(P,tri.B,tri.C);
|
||||
val3 = IntelliHelper::sign(P,tri.C,tri.A);
|
||||
|
||||
neg = (val1<0.f) || (val2<0.f) || (val3<0.f);
|
||||
pos = (val1>0.f) || (val2>0.f) || (val3>0.f);
|
||||
neg = (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.
|
||||
* \param polyPoints - The Vertices of the polygon.
|
||||
* \return Returns a Container of disjoint Triangles, which desribe the polygon area.
|
||||
*/
|
||||
std::vector<Triangle> calculateTriangles(std::vector<QPoint> polyPoints);
|
||||
/*!
|
||||
* \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.
|
||||
* \return Returns a Container of disjoint Triangles, which desribe the polygon area.
|
||||
*/
|
||||
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.
|
||||
* \param triangles - The spanning triangles of the planar 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.
|
||||
*/
|
||||
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
||||
/*!
|
||||
* \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 point - The point to checl, if it lies in the polygon.
|
||||
* \return Returns true if the point lies in the üpolygon, otherwise false.
|
||||
*/
|
||||
bool isInPolygon(std::vector<Triangle> &triangles, QPoint &point);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -18,338 +18,338 @@
|
||||
#include "Tool/IntelliToolFloodFill.h"
|
||||
#include "Tool/IntelliToolPolygon.h"
|
||||
|
||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent)
|
||||
:QWidget(parent){
|
||||
this->Tool = nullptr;
|
||||
this->setUp(maxWidth, maxHeight);
|
||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
||||
std::vector<QPoint> polygon;
|
||||
polygon.push_back(QPoint(100,000));
|
||||
polygon.push_back(QPoint(200,100));
|
||||
polygon.push_back(QPoint(100,200));
|
||||
polygon.push_back(QPoint(000,100));
|
||||
layerBundle[0].image->setPolygon(polygon);
|
||||
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
|
||||
: QWidget(parent){
|
||||
this->Tool = nullptr;
|
||||
this->setUp(maxWidth, maxHeight);
|
||||
this->addLayer(200,200,0,0,ImageType::Shaped_Image);
|
||||
layerBundle[0].image->drawPlain(QColor(0,0,255,255));
|
||||
std::vector<QPoint> polygon;
|
||||
polygon.push_back(QPoint(100,000));
|
||||
polygon.push_back(QPoint(200,100));
|
||||
polygon.push_back(QPoint(100,200));
|
||||
polygon.push_back(QPoint(000,100));
|
||||
layerBundle[0].image->setPolygon(polygon);
|
||||
|
||||
this->addLayer(200,200,150,150);
|
||||
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
||||
layerBundle[1].alpha=200;
|
||||
this->addLayer(200,200,150,150);
|
||||
layerBundle[1].image->drawPlain(QColor(0,255,0,255));
|
||||
layerBundle[1].alpha=200;
|
||||
|
||||
activeLayer=0;
|
||||
activeLayer=0;
|
||||
}
|
||||
|
||||
PaintingArea::~PaintingArea(){
|
||||
delete Tool;
|
||||
delete Tool;
|
||||
}
|
||||
|
||||
void PaintingArea::setUp(int maxWidth, int maxHeight){
|
||||
//set standart parameter
|
||||
this->maxWidth = maxWidth;
|
||||
this->maxHeight = maxHeight;
|
||||
Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
|
||||
//set standart parameter
|
||||
this->maxWidth = maxWidth;
|
||||
this->maxHeight = maxHeight;
|
||||
Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32);
|
||||
|
||||
// Roots the widget to the top left even if resized
|
||||
setAttribute(Qt::WA_StaticContents);
|
||||
// Roots the widget to the top left even if resized
|
||||
setAttribute(Qt::WA_StaticContents);
|
||||
|
||||
}
|
||||
|
||||
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){
|
||||
LayerObject newLayer;
|
||||
newLayer.width = width;
|
||||
newLayer.height = height;
|
||||
newLayer.widthOffset = widthOffset;
|
||||
newLayer.heightOffset = heightOffset;
|
||||
if(type==ImageType::Raster_Image){
|
||||
newLayer.image = new IntelliRasterImage(width,height);
|
||||
}else if(type==ImageType::Shaped_Image){
|
||||
newLayer.image = new IntelliShapedImage(width, height);
|
||||
}
|
||||
newLayer.alpha = 255;
|
||||
this->layerBundle.push_back(newLayer);
|
||||
return static_cast<int>(layerBundle.size())-1;
|
||||
LayerObject newLayer;
|
||||
newLayer.width = width;
|
||||
newLayer.height = height;
|
||||
newLayer.widthOffset = widthOffset;
|
||||
newLayer.heightOffset = heightOffset;
|
||||
if(type==ImageType::Raster_Image) {
|
||||
newLayer.image = new IntelliRasterImage(width,height);
|
||||
}else if(type==ImageType::Shaped_Image) {
|
||||
newLayer.image = new IntelliShapedImage(width, height);
|
||||
}
|
||||
newLayer.alpha = 255;
|
||||
this->layerBundle.push_back(newLayer);
|
||||
return static_cast<int>(layerBundle.size())-1;
|
||||
}
|
||||
|
||||
|
||||
void PaintingArea::deleteLayer(int index){
|
||||
if(index<static_cast<int>(layerBundle.size())){
|
||||
this->layerBundle.erase(layerBundle.begin()+index);
|
||||
if(activeLayer>=index){
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
if(index<static_cast<int>(layerBundle.size())) {
|
||||
this->layerBundle.erase(layerBundle.begin()+index);
|
||||
if(activeLayer>=index) {
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::slotDeleteActiveLayer(){
|
||||
if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())){
|
||||
this->layerBundle.erase(layerBundle.begin()+activeLayer);
|
||||
activeLayer--;
|
||||
}
|
||||
if(activeLayer>=0 && activeLayer < static_cast<int>(layerBundle.size())) {
|
||||
this->layerBundle.erase(layerBundle.begin()+activeLayer);
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::setLayerToActive(int index){
|
||||
if(index>=0&&index<static_cast<int>(layerBundle.size())){
|
||||
this->activeLayer=index;
|
||||
}
|
||||
if(index>=0&&index<static_cast<int>(layerBundle.size())) {
|
||||
this->activeLayer=index;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::setAlphaOfLayer(int index, int alpha){
|
||||
if(index>=0&&index<static_cast<int>(layerBundle.size())){
|
||||
layerBundle[static_cast<size_t>(index)].alpha=alpha;
|
||||
}
|
||||
if(index>=0&&index<static_cast<int>(layerBundle.size())) {
|
||||
layerBundle[static_cast<size_t>(index)].alpha=alpha;
|
||||
}
|
||||
}
|
||||
|
||||
// Used to load the image and place it in the widget
|
||||
bool PaintingArea::open(const QString &fileName){
|
||||
if(this->activeLayer==-1){
|
||||
return false;
|
||||
}
|
||||
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
bool open = active->loadImage(fileName);
|
||||
active->calculateVisiblity();
|
||||
update();
|
||||
return open;
|
||||
if(this->activeLayer==-1) {
|
||||
return false;
|
||||
}
|
||||
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
bool open = active->loadImage(fileName);
|
||||
active->calculateVisiblity();
|
||||
update();
|
||||
return open;
|
||||
}
|
||||
|
||||
// Save the current image
|
||||
bool PaintingArea::save(const QString &fileName, const char *fileFormat){
|
||||
if(layerBundle.size()==0){
|
||||
return false;
|
||||
}
|
||||
this->assembleLayers(true);
|
||||
bool PaintingArea::save(const QString &fileName, const char*fileFormat){
|
||||
if(layerBundle.size()==0) {
|
||||
return false;
|
||||
}
|
||||
this->assembleLayers(true);
|
||||
|
||||
if(!strcmp(fileFormat,"PNG")){
|
||||
QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
|
||||
fileFormat = "png";
|
||||
if (visibleImage.save(fileName, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!strcmp(fileFormat,"PNG")) {
|
||||
QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8);
|
||||
fileFormat = "png";
|
||||
if (visibleImage.save(fileName, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (Canvas->save(fileName, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (Canvas->save(fileName, fileFormat)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Color the image area with white
|
||||
void PaintingArea::floodFill(int r, int g, int b, int a){
|
||||
if(this->activeLayer==-1){
|
||||
return;
|
||||
}
|
||||
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
active->drawPlain(QColor(r, g, b, a));
|
||||
update();
|
||||
if(this->activeLayer==-1) {
|
||||
return;
|
||||
}
|
||||
IntelliImage* active = layerBundle[static_cast<size_t>(activeLayer)].image;
|
||||
active->drawPlain(QColor(r, g, b, a));
|
||||
update();
|
||||
}
|
||||
|
||||
void PaintingArea::movePositionActive(int x, int y){
|
||||
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
|
||||
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
|
||||
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
|
||||
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
|
||||
}
|
||||
|
||||
void PaintingArea::moveActiveLayer(int idx){
|
||||
if(idx==1){
|
||||
this->activateUpperLayer();
|
||||
}else if(idx==-1){
|
||||
this->activateLowerLayer();
|
||||
}
|
||||
if(idx==1) {
|
||||
this->activateUpperLayer();
|
||||
}else if(idx==-1) {
|
||||
this->activateLowerLayer();
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::slotActivateLayer(int a){
|
||||
if(a>=0 && a < static_cast<int>(layerBundle.size())){
|
||||
this->setLayerToActive(a);
|
||||
}
|
||||
if(a>=0 && a < static_cast<int>(layerBundle.size())) {
|
||||
this->setLayerToActive(a);
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::colorPickerSetFirstColor(){
|
||||
QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color", QColorDialog::DontUseNativeDialog);
|
||||
this->colorPicker.setFirstColor(clr);
|
||||
QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color", QColorDialog::DontUseNativeDialog);
|
||||
this->colorPicker.setFirstColor(clr);
|
||||
}
|
||||
|
||||
void PaintingArea::colorPickerSetSecondColor(){
|
||||
QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color", QColorDialog::DontUseNativeDialog);
|
||||
this->colorPicker.setSecondColor(clr);
|
||||
QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color", QColorDialog::DontUseNativeDialog);
|
||||
this->colorPicker.setSecondColor(clr);
|
||||
}
|
||||
|
||||
void PaintingArea::colorPickerSwitchColor(){
|
||||
this->colorPicker.switchColors();
|
||||
this->colorPicker.switchColors();
|
||||
}
|
||||
|
||||
void PaintingArea::createPenTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPen(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPen(this, &colorPicker);
|
||||
}
|
||||
|
||||
void PaintingArea::createPlainTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPlainTool(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPlainTool(this, &colorPicker);
|
||||
}
|
||||
|
||||
void PaintingArea::createLineTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolLine(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolLine(this, &colorPicker);
|
||||
}
|
||||
|
||||
void PaintingArea::createRectangleTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolRectangle(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolRectangle(this, &colorPicker);
|
||||
}
|
||||
|
||||
void PaintingArea::createCircleTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolCircle(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolCircle(this, &colorPicker);
|
||||
}
|
||||
void PaintingArea::createPolygonTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPolygon(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolPolygon(this, &colorPicker);
|
||||
}
|
||||
|
||||
void PaintingArea::createFloodFillTool(){
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolFloodFill(this, &colorPicker);
|
||||
delete this->Tool;
|
||||
Tool = new IntelliToolFloodFill(this, &colorPicker);
|
||||
}
|
||||
|
||||
int PaintingArea::getWidthOfActive(){
|
||||
return this->layerBundle[activeLayer].width;
|
||||
return this->layerBundle[activeLayer].width;
|
||||
}
|
||||
|
||||
int PaintingArea::getHeightOfActive(){
|
||||
return this->layerBundle[activeLayer].height;
|
||||
return this->layerBundle[activeLayer].height;
|
||||
}
|
||||
|
||||
// If a mouse button is pressed check if it was the
|
||||
// left button and if so store the current position
|
||||
// Set that we are currently drawing
|
||||
void PaintingArea::mousePressEvent(QMouseEvent *event){
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].heightOffset;
|
||||
if(event->button() == Qt::LeftButton){
|
||||
Tool->onMouseLeftPressed(x, y);
|
||||
}else if(event->button() == Qt::RightButton){
|
||||
Tool->onMouseRightPressed(x, y);
|
||||
}
|
||||
update();
|
||||
void PaintingArea::mousePressEvent(QMouseEvent*event){
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].heightOffset;
|
||||
if(event->button() == Qt::LeftButton) {
|
||||
Tool->onMouseLeftPressed(x, y);
|
||||
}else if(event->button() == Qt::RightButton) {
|
||||
Tool->onMouseRightPressed(x, y);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
// When the mouse moves if the left button is clicked
|
||||
// we call the drawline function which draws a line
|
||||
// from the last position to the current
|
||||
void PaintingArea::mouseMoveEvent(QMouseEvent *event){
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].heightOffset;
|
||||
Tool->onMouseMoved(x, y);
|
||||
update();
|
||||
void PaintingArea::mouseMoveEvent(QMouseEvent*event){
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].heightOffset;
|
||||
Tool->onMouseMoved(x, y);
|
||||
update();
|
||||
}
|
||||
|
||||
// If the button is released we set variables to stop drawing
|
||||
void PaintingArea::mouseReleaseEvent(QMouseEvent *event){
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].heightOffset;
|
||||
if(event->button() == Qt::LeftButton){
|
||||
Tool->onMouseLeftReleased(x, y);
|
||||
}else if(event->button() == Qt::RightButton){
|
||||
Tool->onMouseRightReleased(x, y);
|
||||
}
|
||||
update();
|
||||
void PaintingArea::mouseReleaseEvent(QMouseEvent*event){
|
||||
if(Tool == nullptr)
|
||||
return;
|
||||
int x = event->x()-layerBundle[activeLayer].widthOffset;
|
||||
int y = event->y()-layerBundle[activeLayer].heightOffset;
|
||||
if(event->button() == Qt::LeftButton) {
|
||||
Tool->onMouseLeftReleased(x, y);
|
||||
}else if(event->button() == Qt::RightButton) {
|
||||
Tool->onMouseRightReleased(x, y);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void PaintingArea::wheelEvent(QWheelEvent *event){
|
||||
QPoint numDegrees = event->angleDelta() / 8;
|
||||
if(!numDegrees.isNull()){
|
||||
QPoint numSteps = numDegrees / 15;
|
||||
Tool->onWheelScrolled(numSteps.y()*-1);
|
||||
}
|
||||
void PaintingArea::wheelEvent(QWheelEvent*event){
|
||||
QPoint numDegrees = event->angleDelta() / 8;
|
||||
if(!numDegrees.isNull()) {
|
||||
QPoint numSteps = numDegrees / 15;
|
||||
Tool->onWheelScrolled(numSteps.y()* -1);
|
||||
}
|
||||
}
|
||||
|
||||
// QPainter provides functions to draw on the widget
|
||||
// The QPaintEvent is sent to widgets that need to
|
||||
// update themselves
|
||||
void PaintingArea::paintEvent(QPaintEvent *event){
|
||||
this->assembleLayers();
|
||||
void PaintingArea::paintEvent(QPaintEvent*event){
|
||||
this->assembleLayers();
|
||||
|
||||
QPainter painter(this);
|
||||
QRect dirtyRec = event->rect();
|
||||
painter.drawImage(dirtyRec, *Canvas, dirtyRec);
|
||||
update();
|
||||
QPainter painter(this);
|
||||
QRect dirtyRec = event->rect();
|
||||
painter.drawImage(dirtyRec, *Canvas, dirtyRec);
|
||||
update();
|
||||
}
|
||||
|
||||
// Resize the image to slightly larger then the main window
|
||||
// to cut down on the need to resize the image
|
||||
void PaintingArea::resizeEvent(QResizeEvent *event){
|
||||
//TODO wait till tool works
|
||||
update();
|
||||
void PaintingArea::resizeEvent(QResizeEvent*event){
|
||||
//TODO wait till tool works
|
||||
update();
|
||||
}
|
||||
|
||||
void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){
|
||||
//TODO implement
|
||||
void PaintingArea::resizeImage(QImage*image_res, const QSize &newSize){
|
||||
//TODO implement
|
||||
}
|
||||
|
||||
void PaintingArea::activateUpperLayer(){
|
||||
if(activeLayer!=-1 && activeLayer<layerBundle.size()-1){
|
||||
std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
|
||||
activeLayer++;
|
||||
}
|
||||
if(activeLayer!=-1 && activeLayer<layerBundle.size()-1) {
|
||||
std::swap(layerBundle[activeLayer], layerBundle[activeLayer+1]);
|
||||
activeLayer++;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::activateLowerLayer(){
|
||||
if(activeLayer!=-1 && activeLayer>0){
|
||||
std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
|
||||
activeLayer--;
|
||||
}
|
||||
if(activeLayer!=-1 && activeLayer>0) {
|
||||
std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]);
|
||||
activeLayer--;
|
||||
}
|
||||
}
|
||||
|
||||
void PaintingArea::assembleLayers(bool forSaving){
|
||||
if(forSaving){
|
||||
Canvas->fill(Qt::GlobalColor::transparent);
|
||||
}else{
|
||||
Canvas->fill(Qt::GlobalColor::black);
|
||||
}
|
||||
for(size_t i=0; i<layerBundle.size(); i++){
|
||||
LayerObject layer = layerBundle[i];
|
||||
QImage cpy = layer.image->getDisplayable(layer.alpha);
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<layer.height; y++){
|
||||
if(layer.heightOffset+y<0) continue;
|
||||
if(layer.heightOffset+y>=maxHeight) break;
|
||||
for(int x=0; x<layer.width; x++){
|
||||
if(layer.widthOffset+x<0) continue;
|
||||
if(layer.widthOffset+x>=maxWidth) break;
|
||||
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
|
||||
clr_1=cpy.pixelColor(x,y);
|
||||
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 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 a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
if(forSaving) {
|
||||
Canvas->fill(Qt::GlobalColor::transparent);
|
||||
}else{
|
||||
Canvas->fill(Qt::GlobalColor::black);
|
||||
}
|
||||
for(size_t i=0; i<layerBundle.size(); i++) {
|
||||
LayerObject layer = layerBundle[i];
|
||||
QImage cpy = layer.image->getDisplayable(layer.alpha);
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<layer.height; y++) {
|
||||
if(layer.heightOffset+y<0) continue;
|
||||
if(layer.heightOffset+y>=maxHeight) break;
|
||||
for(int x=0; x<layer.width; x++) {
|
||||
if(layer.widthOffset+x<0) continue;
|
||||
if(layer.widthOffset+x>=maxWidth) break;
|
||||
clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.heightOffset+y);
|
||||
clr_1=cpy.pixelColor(x,y);
|
||||
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 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 a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
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){
|
||||
if(idx>=0){
|
||||
LayerObject newLayer;
|
||||
newLayer.alpha = 255;
|
||||
newLayer.height = layerBundle[idx].height;
|
||||
newLayer.width = layerBundle[idx].width;
|
||||
newLayer.heightOffset = layerBundle[idx].heightOffset;
|
||||
newLayer.widthOffset = layerBundle[idx].widthOffset;
|
||||
newLayer.image = layerBundle[idx].image->getDeepCopy();
|
||||
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
|
||||
}
|
||||
if(idx>=0) {
|
||||
LayerObject newLayer;
|
||||
newLayer.alpha = 255;
|
||||
newLayer.height = layerBundle[idx].height;
|
||||
newLayer.width = layerBundle[idx].width;
|
||||
newLayer.heightOffset = layerBundle[idx].heightOffset;
|
||||
newLayer.widthOffset = layerBundle[idx].widthOffset;
|
||||
newLayer.image = layerBundle[idx].image->getDeepCopy();
|
||||
layerBundle.insert(layerBundle.begin()+idx+1,newLayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include "QDebug"
|
||||
|
||||
IntelliColorPicker::IntelliColorPicker(PaintingArea* Area)
|
||||
:IntelliTool(Area){
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,0,255,255};
|
||||
: IntelliTool(Area){
|
||||
firstColor = {255,0,0,255};
|
||||
secondColor = {0,0,255,255};
|
||||
}
|
||||
|
||||
IntelliColorPicker::~IntelliColorPicker(){
|
||||
@@ -12,25 +12,25 @@ IntelliColorPicker::~IntelliColorPicker(){
|
||||
}
|
||||
|
||||
void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){
|
||||
QString Titel;
|
||||
QColor newColor;
|
||||
if(firstOrSecondColor == 1){
|
||||
Titel = "Choose first Color";
|
||||
newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel);
|
||||
this->firstColor = newColor;
|
||||
qDebug() << "Firstcolor" << this->firstColor;
|
||||
}
|
||||
else{
|
||||
Titel = "Choose second Color";
|
||||
newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel);
|
||||
this->secondColor = newColor;
|
||||
}
|
||||
QString Titel;
|
||||
QColor newColor;
|
||||
if(firstOrSecondColor == 1) {
|
||||
Titel = "Choose first Color";
|
||||
newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel);
|
||||
this->firstColor = newColor;
|
||||
qDebug() << "Firstcolor" << this->firstColor;
|
||||
}
|
||||
else{
|
||||
Titel = "Choose second Color";
|
||||
newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel);
|
||||
this->secondColor = newColor;
|
||||
}
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getFirstColor(){
|
||||
return firstColor;
|
||||
return firstColor;
|
||||
}
|
||||
|
||||
QColor IntelliColorPicker::getSecondColor(){
|
||||
return secondColor;
|
||||
return secondColor;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include"IntelliTool.h"
|
||||
#include"Layer/PaintingArea.h"
|
||||
#include "IntelliTool.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
|
||||
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){
|
||||
this->Area=Area;
|
||||
this->colorPicker=colorPicker;
|
||||
this->Area=Area;
|
||||
this->colorPicker=colorPicker;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,71 +12,70 @@ IntelliTool::~IntelliTool(){
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseRightPressed(int x, int y){
|
||||
if(drawing){
|
||||
drawing=false;
|
||||
this->deleteToolLayer();
|
||||
}
|
||||
if(drawing) {
|
||||
drawing=false;
|
||||
this->deleteToolLayer();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseRightReleased(int x, int y){
|
||||
//optional for tool
|
||||
//optional for tool
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseLeftPressed(int x, int y){
|
||||
this->drawing=true;
|
||||
//create drawing layer
|
||||
this->createToolLayer();
|
||||
Canvas->image->calculateVisiblity();
|
||||
this->drawing=true;
|
||||
//create drawing layer
|
||||
this->createToolLayer();
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseLeftReleased(int x, int y){
|
||||
if(drawing){
|
||||
drawing=false;
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
Active->image->calculateVisiblity();
|
||||
}
|
||||
if(drawing) {
|
||||
drawing=false;
|
||||
this->mergeToolLayer();
|
||||
this->deleteToolLayer();
|
||||
Active->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::onMouseMoved(int x, int y){
|
||||
if(drawing)
|
||||
Canvas->image->calculateVisiblity();
|
||||
if(drawing)
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
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(){
|
||||
Area->createTempLayerAfter(Area->activeLayer);
|
||||
this->Active=&Area->layerBundle[Area->activeLayer];
|
||||
this->Canvas=&Area->layerBundle[Area->activeLayer+1];
|
||||
Area->createTempLayerAfter(Area->activeLayer);
|
||||
this->Active=&Area->layerBundle[Area->activeLayer];
|
||||
this->Canvas=&Area->layerBundle[Area->activeLayer+1];
|
||||
}
|
||||
|
||||
void IntelliTool::mergeToolLayer(){
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<Active->height; y++){
|
||||
for(int x=0; x<Active->width; x++){
|
||||
clr_0=Active->image->imageData.pixelColor(x,y);
|
||||
clr_1=Canvas->image->imageData.pixelColor(x,y);
|
||||
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 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 a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
QColor clr_0;
|
||||
QColor clr_1;
|
||||
for(int y=0; y<Active->height; y++) {
|
||||
for(int x=0; x<Active->width; x++) {
|
||||
clr_0=Active->image->imageData.pixelColor(x,y);
|
||||
clr_1=Canvas->image->imageData.pixelColor(x,y);
|
||||
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 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 a =std::min(clr_0.alpha()+clr_1.alpha(), 255);
|
||||
clr_0.setRed(r);
|
||||
clr_0.setGreen(g);
|
||||
clr_0.setBlue(b);
|
||||
clr_0.setAlpha(a);
|
||||
|
||||
Active->image->imageData.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
Active->image->imageData.setPixelColor(x, y, clr_0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliTool::deleteToolLayer(){
|
||||
Area->deleteLayer(Area->activeLayer+1);
|
||||
this->Canvas=nullptr;
|
||||
Area->deleteLayer(Area->activeLayer+1);
|
||||
this->Canvas=nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,101 +10,101 @@ class PaintingArea;
|
||||
/*!
|
||||
* \brief An abstract class that manages the basic events, like mouse clicks or scrolls events.
|
||||
*/
|
||||
class IntelliTool{
|
||||
class IntelliTool {
|
||||
private:
|
||||
/*!
|
||||
* \brief A function that creates a layer to draw on.
|
||||
*/
|
||||
void createToolLayer();
|
||||
/*!
|
||||
* \brief A function that creates a layer to draw on.
|
||||
*/
|
||||
void createToolLayer();
|
||||
|
||||
/*!
|
||||
* \brief A function that merges the drawing- and the active- layer.
|
||||
*/
|
||||
void mergeToolLayer();
|
||||
/*!
|
||||
* \brief A function that merges the drawing- and the active- layer.
|
||||
*/
|
||||
void mergeToolLayer();
|
||||
|
||||
/*!
|
||||
* \brief A function that deletes the drawinglayer.
|
||||
*/
|
||||
void deleteToolLayer();
|
||||
/*!
|
||||
* \brief A function that deletes the drawinglayer.
|
||||
*/
|
||||
void deleteToolLayer();
|
||||
protected:
|
||||
/*!
|
||||
* \brief A pointer to the general PaintingArea to interact with.
|
||||
*/
|
||||
PaintingArea* Area;
|
||||
/*!
|
||||
* \brief A pointer to the general PaintingArea to interact with.
|
||||
*/
|
||||
PaintingArea* Area;
|
||||
|
||||
/*!
|
||||
* \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
|
||||
*/
|
||||
IntelliColorPicker* colorPicker;
|
||||
/*!
|
||||
* \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors.
|
||||
*/
|
||||
IntelliColorPicker* colorPicker;
|
||||
|
||||
/*!
|
||||
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
|
||||
*/
|
||||
LayerObject* Active;
|
||||
/*!
|
||||
* \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews.
|
||||
*/
|
||||
LayerObject* Active;
|
||||
|
||||
/*!
|
||||
* \brief A pointer to the drawing canvas of the tool, work on this.
|
||||
*/
|
||||
LayerObject* Canvas;
|
||||
/*!
|
||||
* \brief A pointer to the drawing canvas of the tool, work on this.
|
||||
*/
|
||||
LayerObject* Canvas;
|
||||
|
||||
/*!
|
||||
* \brief A flag checking if the user is currently drawing or not.
|
||||
*/
|
||||
bool drawing = false;
|
||||
/*!
|
||||
* \brief A flag checking if the user is currently drawing or not.
|
||||
*/
|
||||
bool drawing = false;
|
||||
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general Painting Area and colorPicker.
|
||||
* \param Area - The general PaintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A constructor setting the general Painting Area and colorPicker.
|
||||
* \param Area - The general PaintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
|
||||
/*!
|
||||
* \brief An abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliTool() = 0;
|
||||
/*!
|
||||
* \brief An abstract Destructor.
|
||||
*/
|
||||
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!
|
||||
* \param x - The x 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);
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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!
|
||||
* \param x - The x 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);
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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!
|
||||
* \param x - The x 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);
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y);
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftReleased(int x, int y);
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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!
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value);
|
||||
/*!
|
||||
* \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.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value);
|
||||
|
||||
/*!
|
||||
* \brief A function managing the mouse moved event. Call this in child classes!
|
||||
* \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);
|
||||
/*!
|
||||
* \brief A function managing the mouse moved event. Call this in child classes!
|
||||
* \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);
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <cmath>
|
||||
|
||||
IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||
}
|
||||
|
||||
IntelliToolCircle::~IntelliToolCircle(){
|
||||
@@ -14,74 +14,74 @@ IntelliToolCircle::~IntelliToolCircle(){
|
||||
}
|
||||
|
||||
void IntelliToolCircle::drawCyrcle(int radius){
|
||||
int outer = radius+20;
|
||||
QColor inner = this->colorPicker->getSecondColor();
|
||||
inner.setAlpha(alphaInner);
|
||||
int yMin, yMax, xMin, xMax;
|
||||
yMin = Middle.y()-radius;
|
||||
yMax = Middle.y()+radius;
|
||||
// x = x0+-sqrt(r2-(y-y0)2)
|
||||
for(int i=yMin; i<=yMax; i++){
|
||||
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
|
||||
}
|
||||
int outer = radius+20;
|
||||
QColor inner = this->colorPicker->getSecondColor();
|
||||
inner.setAlpha(alphaInner);
|
||||
int yMin, yMax, xMin, xMax;
|
||||
yMin = Middle.y()-radius;
|
||||
yMax = Middle.y()+radius;
|
||||
// x = x0+-sqrt(r2-(y-y0)2)
|
||||
for(int i=yMin; i<=yMax; i++) {
|
||||
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1);
|
||||
}
|
||||
|
||||
//TODO implement circle drawing algorithm bresenham
|
||||
radius = radius +(this->edgeWidth/2.)-1.;
|
||||
yMin = (Middle.y()-radius);
|
||||
yMax = (Middle.y()+radius);
|
||||
for(int i=yMin; i<=yMax; i++){
|
||||
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
|
||||
}
|
||||
//TODO implement circle drawing algorithm bresenham
|
||||
radius = radius +(this->edgeWidth/2.)-1.;
|
||||
yMin = (Middle.y()-radius);
|
||||
yMax = (Middle.y()+radius);
|
||||
for(int i=yMin; i<=yMax; i++) {
|
||||
xMin = Middle.x()-sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
xMax = Middle.x()+sqrt(pow(radius,2)-pow(i-Middle.y(),2));
|
||||
this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),edgeWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),edgeWidth);
|
||||
}
|
||||
|
||||
xMin = (Middle.x()-radius);
|
||||
xMax = (Middle.x()+radius);
|
||||
for(int i=xMin; i<=xMax; i++){
|
||||
int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2));
|
||||
int yMax = Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2));
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
|
||||
}
|
||||
xMin = (Middle.x()-radius);
|
||||
xMax = (Middle.x()+radius);
|
||||
for(int i=xMin; i<=xMax; i++) {
|
||||
int yMin = Middle.y()-sqrt(pow(radius,2)-pow(i-Middle.x(),2));
|
||||
int yMax = Middle.y()+sqrt(pow(radius,2)-pow(i-Middle.x(),2));
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),edgeWidth);
|
||||
this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),edgeWidth);
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Middle=QPoint(x,y);
|
||||
int radius = 1;
|
||||
drawCyrcle(radius);
|
||||
Canvas->image->calculateVisiblity();
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Middle=QPoint(x,y);
|
||||
int radius = 1;
|
||||
drawCyrcle(radius);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->edgeWidth+=value;
|
||||
if(this->edgeWidth<=0){
|
||||
this->edgeWidth=1;
|
||||
}
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->edgeWidth+=value;
|
||||
if(this->edgeWidth<=0) {
|
||||
this->edgeWidth=1;
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolCircle::onMouseMoved(int x, int y){
|
||||
if(this->drawing){
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
|
||||
drawCyrcle(radius);
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
if(this->drawing) {
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
int radius = static_cast<int>(sqrt(pow((Middle.x()-x),2)+pow((Middle.y()-y),2)));
|
||||
drawCyrcle(radius);
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
@@ -7,80 +7,80 @@
|
||||
/*!
|
||||
* \brief The IntelliToolCircle class represents a tool to draw a circle.
|
||||
*/
|
||||
class IntelliToolCircle : public IntelliTool{
|
||||
/*!
|
||||
* \brief A function that implements a circle drawing algorithm.
|
||||
* \param radius - The radius of the circle.
|
||||
*/
|
||||
void drawCyrcle(int radius);
|
||||
class IntelliToolCircle : public IntelliTool {
|
||||
/*!
|
||||
* \brief A function that implements a circle drawing algorithm.
|
||||
* \param radius - The radius of the circle.
|
||||
*/
|
||||
void drawCyrcle(int radius);
|
||||
|
||||
/*!
|
||||
* \brief The center of the circle.
|
||||
*/
|
||||
QPoint Middle;
|
||||
/*!
|
||||
* \brief The center of the circle.
|
||||
*/
|
||||
QPoint Middle;
|
||||
|
||||
/*!
|
||||
* \brief The alpha value of the inner circle.
|
||||
*/
|
||||
int alphaInner;
|
||||
/*!
|
||||
* \brief The alpha value of the inner circle.
|
||||
*/
|
||||
int alphaInner;
|
||||
|
||||
/*!
|
||||
* \brief The width of the outer circle edge.
|
||||
*/
|
||||
int edgeWidth;
|
||||
/*!
|
||||
* \brief The width of the outer circle edge.
|
||||
*/
|
||||
int edgeWidth;
|
||||
public:
|
||||
/*!
|
||||
* \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 colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \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 colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolCircle() override;
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolCircle() override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the left click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the left click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event. Changing the edge Width relative to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
/*!
|
||||
* \brief A function managing the scroll event. Changing the edge Width relative to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
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.
|
||||
* \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. 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 y - The y coordinate of the new mouse position.
|
||||
*/
|
||||
virtual void onMouseMoved(int x, int y) override;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLCIRCLE_H
|
||||
|
||||
@@ -6,75 +6,74 @@
|
||||
#include <queue>
|
||||
|
||||
IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
: IntelliTool(Area, colorPicker){
|
||||
}
|
||||
|
||||
IntelliToolFloodFill::~IntelliToolFloodFill(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void IntelliToolFloodFill::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolFloodFill::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolFloodFill::onMouseLeftPressed(int x, int y){
|
||||
if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())){
|
||||
return;
|
||||
}
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
if(!(x>=0 && x<Area->getWidthOfActive() && y>=0 && y<Area->getHeightOfActive())) {
|
||||
return;
|
||||
}
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
|
||||
QPoint start(x,y);
|
||||
std::queue<QPoint> Q;
|
||||
Q.push(start);
|
||||
QPoint start(x,y);
|
||||
std::queue<QPoint> Q;
|
||||
Q.push(start);
|
||||
|
||||
QColor oldColor = this->Active->image->getPixelColor(start);
|
||||
QColor newColor = this->colorPicker->getFirstColor();
|
||||
Canvas->image->drawPixel(start,newColor);
|
||||
QColor oldColor = this->Active->image->getPixelColor(start);
|
||||
QColor newColor = this->colorPicker->getFirstColor();
|
||||
Canvas->image->drawPixel(start,newColor);
|
||||
|
||||
QPoint left, right, top, down;
|
||||
while(!Q.empty()){
|
||||
QPoint Current = Q.front();
|
||||
Q.pop();
|
||||
QPoint left, right, top, down;
|
||||
while(!Q.empty()) {
|
||||
QPoint Current = Q.front();
|
||||
Q.pop();
|
||||
|
||||
left = QPoint(Current.x()-1,Current.y() );
|
||||
right = QPoint(Current.x()+1,Current.y() );
|
||||
top = 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)){
|
||||
Canvas->image->drawPixel(right,newColor);
|
||||
Q.push(right);
|
||||
}
|
||||
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)){
|
||||
Canvas->image->drawPixel(left,newColor);
|
||||
Q.push(left);
|
||||
}
|
||||
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)){
|
||||
Canvas->image->drawPixel(top,newColor);
|
||||
Q.push(top);
|
||||
}
|
||||
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)){
|
||||
Canvas->image->drawPixel(down,newColor);
|
||||
Q.push(down);
|
||||
}
|
||||
}
|
||||
left = QPoint(Current.x()-1,Current.y() );
|
||||
right = QPoint(Current.x()+1,Current.y() );
|
||||
top = 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)) {
|
||||
Canvas->image->drawPixel(right,newColor);
|
||||
Q.push(right);
|
||||
}
|
||||
if((left.x() >= 0) && (Canvas->image->getPixelColor(left) != newColor) && (Active->image->getPixelColor(left) == oldColor)) {
|
||||
Canvas->image->drawPixel(left,newColor);
|
||||
Q.push(left);
|
||||
}
|
||||
if((top.y() >= 0) && (Canvas->image->getPixelColor(top) != newColor) && (Active->image->getPixelColor(top) == oldColor)) {
|
||||
Canvas->image->drawPixel(top,newColor);
|
||||
Q.push(top);
|
||||
}
|
||||
if((down.y() < Canvas->height) && (Canvas->image->getPixelColor(down) != newColor) && (Active->image->getPixelColor(down) == oldColor)) {
|
||||
Canvas->image->drawPixel(down,newColor);
|
||||
Q.push(down);
|
||||
}
|
||||
}
|
||||
|
||||
Canvas->image->calculateVisiblity();
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolFloodFill::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolFloodFill::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
|
||||
}
|
||||
|
||||
void IntelliToolFloodFill::onMouseMoved(int x, int y){
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
@@ -7,61 +7,61 @@
|
||||
/*!
|
||||
* \brief The IntelliToolFloodFill class represents a tool to flood FIll a certian area.
|
||||
*/
|
||||
class IntelliToolFloodFill : public IntelliTool{
|
||||
class IntelliToolFloodFill : public IntelliTool {
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolFloodFill() override;
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolFloodFill() override;
|
||||
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(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.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the left click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the left click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
/*!
|
||||
* \brief A function managing the scroll event.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLFLOODFILL_H
|
||||
|
||||
@@ -4,60 +4,59 @@
|
||||
#include "QInputDialog"
|
||||
|
||||
IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
|
||||
//create checkbox or scroll dialog to get line style
|
||||
this->lineStyle = LineStyle::SOLID_LINE;
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1);
|
||||
//create checkbox or scroll dialog to get line style
|
||||
this->lineStyle = LineStyle::SOLID_LINE;
|
||||
}
|
||||
|
||||
IntelliToolLine::~IntelliToolLine(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void IntelliToolLine::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolLine::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolLine::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->start=QPoint(x,y);
|
||||
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
|
||||
Canvas->image->calculateVisiblity();
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->start=QPoint(x,y);
|
||||
this->Canvas->image->drawPoint(start, colorPicker->getFirstColor(),lineWidth);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolLine::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolLine::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->lineWidth+=value;
|
||||
if(this->lineWidth<=0){
|
||||
this->lineWidth=1;
|
||||
}
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->lineWidth+=value;
|
||||
if(this->lineWidth<=0) {
|
||||
this->lineWidth=1;
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolLine::onMouseMoved(int x, int y){
|
||||
if(this->drawing){
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
switch(lineStyle){
|
||||
case LineStyle::SOLID_LINE:
|
||||
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
|
||||
break;
|
||||
case LineStyle::DOTTED_LINE:
|
||||
QPoint p1 =start.x() <= next.x() ? start : next;
|
||||
QPoint p2 =start.x() < next.x() ? next : start;
|
||||
int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f;
|
||||
int c = start.y()-start.x()*m;
|
||||
if(this->drawing) {
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
switch(lineStyle) {
|
||||
case LineStyle::SOLID_LINE:
|
||||
this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth);
|
||||
break;
|
||||
case LineStyle::DOTTED_LINE:
|
||||
QPoint p1 =start.x() <= next.x() ? start : next;
|
||||
QPoint p2 =start.x() < next.x() ? next : start;
|
||||
int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f;
|
||||
int c = start.y()-start.x()*m;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
@@ -7,83 +7,83 @@
|
||||
/*!
|
||||
* \brief The LineStyle enum classifing all ways of drawing a line.
|
||||
*/
|
||||
enum class LineStyle{
|
||||
SOLID_LINE,
|
||||
DOTTED_LINE
|
||||
enum class LineStyle {
|
||||
SOLID_LINE,
|
||||
DOTTED_LINE
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief The IntelliToolFloodFill class represents a tool to draw a line.
|
||||
*/
|
||||
class IntelliToolLine : public IntelliTool{
|
||||
/*!
|
||||
* \brief The starting point of the line.
|
||||
*/
|
||||
QPoint start;
|
||||
class IntelliToolLine : public IntelliTool {
|
||||
/*!
|
||||
* \brief The starting point of the line.
|
||||
*/
|
||||
QPoint start;
|
||||
|
||||
/*!
|
||||
* \brief The width of the line to draw.
|
||||
*/
|
||||
int lineWidth;
|
||||
/*!
|
||||
* \brief The width of the line to draw.
|
||||
*/
|
||||
int lineWidth;
|
||||
|
||||
/*!
|
||||
* \brief The style of the line. Apropriate to LineStyle.
|
||||
*/
|
||||
LineStyle lineStyle;
|
||||
/*!
|
||||
* \brief The style of the line. Apropriate to LineStyle.
|
||||
*/
|
||||
LineStyle lineStyle;
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \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 colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \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 colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
|
||||
/*!
|
||||
* \brief An abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolLine() override;
|
||||
/*!
|
||||
* \brief An abstract Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolLine() override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the left click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the left click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event. Changing the lineWidth relative to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
/*!
|
||||
* \brief A function managing the scroll event. Changing the lineWidth relative to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
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.
|
||||
* \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. Drawing a Line from the startpoint to the current mouse position.
|
||||
* \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;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLLINE_H
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "QInputDialog"
|
||||
|
||||
IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1);
|
||||
}
|
||||
|
||||
IntelliToolPen::~IntelliToolPen(){
|
||||
@@ -14,37 +14,37 @@ IntelliToolPen::~IntelliToolPen(){
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->point=QPoint(x,y);
|
||||
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
|
||||
Canvas->image->calculateVisiblity();
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->point=QPoint(x,y);
|
||||
this->Canvas->image->drawPixel(point, colorPicker->getFirstColor());
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPen::onMouseMoved(int x, int y){
|
||||
if(this->drawing){
|
||||
QPoint newPoint(x,y);
|
||||
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
|
||||
this->point=newPoint;
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
if(this->drawing) {
|
||||
QPoint newPoint(x,y);
|
||||
this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth);
|
||||
this->point=newPoint;
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPen::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->penWidth+=value;
|
||||
if(this->penWidth<=0){
|
||||
this->penWidth=1;
|
||||
}
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->penWidth+=value;
|
||||
if(this->penWidth<=0) {
|
||||
this->penWidth=1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
#ifndef INTELLITOOLPEN_H
|
||||
#define INTELLITOOLPEN_H
|
||||
|
||||
#include"IntelliTool.h"
|
||||
#include"QColor"
|
||||
#include"QPoint"
|
||||
#include "IntelliTool.h"
|
||||
#include "QColor"
|
||||
#include "QPoint"
|
||||
/*!
|
||||
* \brief The IntelliToolPen class represents a tool to draw a line.
|
||||
*/
|
||||
class IntelliToolPen : public IntelliTool{
|
||||
/*!
|
||||
* \brief penWidth - The width of the Pen while drawing.
|
||||
*/
|
||||
int penWidth;
|
||||
/*!
|
||||
* \brief point - Represents the previous point to help drawing a line.
|
||||
*/
|
||||
QPoint point;
|
||||
class IntelliToolPen : public IntelliTool {
|
||||
/*!
|
||||
* \brief penWidth - The width of the Pen while drawing.
|
||||
*/
|
||||
int penWidth;
|
||||
/*!
|
||||
* \brief point - Represents the previous point to help drawing a line.
|
||||
*/
|
||||
QPoint point;
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth.
|
||||
* \param Area - The general PaintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolPen() override;
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker. Reading the penWidth.
|
||||
* \param Area - The general PaintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolPen() override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftReleased(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event. Changing penWidth relativ to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
/*!
|
||||
* \brief A function managing the scroll event. Changing penWidth relativ to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the mouse moved event. To draw the line.
|
||||
* \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. To draw the line.
|
||||
* \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;
|
||||
};
|
||||
|
||||
#endif // INTELLITOOLPEN_H
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "QColorDialog"
|
||||
|
||||
IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
: IntelliTool(Area, colorPicker){
|
||||
}
|
||||
|
||||
IntelliToolPlainTool::~IntelliToolPlainTool(){
|
||||
@@ -11,28 +11,27 @@ IntelliToolPlainTool::~IntelliToolPlainTool(){
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Canvas->image->drawPlain(colorPicker->getFirstColor());
|
||||
Canvas->image->calculateVisiblity();
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->Canvas->image->drawPlain(colorPicker->getFirstColor());
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
|
||||
void IntelliToolPlainTool::onMouseMoved(int x, int y){
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPlainTool::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
}
|
||||
|
||||
@@ -6,59 +6,59 @@
|
||||
/*!
|
||||
* \brief The IntelliToolPlainTool class represents a tool to fill the whole canvas with one color.
|
||||
*/
|
||||
class IntelliToolPlainTool : public IntelliTool{
|
||||
class IntelliToolPlainTool : public IntelliTool {
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolPlainTool() override;
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolPlainTool(PaintingArea*Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolPlainTool() override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftReleased(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
/*!
|
||||
* \brief A function managing the scroll event.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
#include <QInputDialog>
|
||||
|
||||
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
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);;
|
||||
PointIsNearStart = false;
|
||||
isDrawing = false;
|
||||
: IntelliTool(Area, colorPicker){
|
||||
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);;
|
||||
PointIsNearStart = false;
|
||||
isDrawing = false;
|
||||
}
|
||||
|
||||
IntelliToolPolygon::~IntelliToolPolygon(){
|
||||
@@ -17,93 +17,93 @@ IntelliToolPolygon::~IntelliToolPolygon(){
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
|
||||
if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
QPoint drawingPoint = QPoint(x,y);
|
||||
if(!isDrawing && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
QPoint drawingPoint = QPoint(x,y);
|
||||
|
||||
isDrawing = true;
|
||||
QPointList.push_back(drawingPoint);
|
||||
isDrawing = true;
|
||||
QPointList.push_back(drawingPoint);
|
||||
|
||||
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing && isNearStart(x,y,QPointList.front())){
|
||||
PointIsNearStart = true;
|
||||
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing){
|
||||
QPoint drawingPoint(x,y);
|
||||
QPointList.push_back(drawingPoint);
|
||||
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing && isNearStart(x,y,QPointList.front())) {
|
||||
PointIsNearStart = true;
|
||||
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
else if(isDrawing) {
|
||||
QPoint drawingPoint(x,y);
|
||||
QPointList.push_back(drawingPoint);
|
||||
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth);
|
||||
this->Canvas->image->calculateVisiblity();
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseRightPressed(int x, int y){
|
||||
isDrawing = false;
|
||||
PointIsNearStart = false;
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
isDrawing = false;
|
||||
PointIsNearStart = false;
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
|
||||
if(PointIsNearStart && QPointList.size() > 1){
|
||||
PointIsNearStart = false;
|
||||
isDrawing = false;
|
||||
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
|
||||
QPoint Point;
|
||||
QColor colorTwo(colorPicker->getSecondColor());
|
||||
colorTwo.setAlpha(alphaInner);
|
||||
for(int i = 0; i < Active->width; i++){
|
||||
for(int j = 0; j < Active->height; j++){
|
||||
Point = QPoint(i,j);
|
||||
if(IntelliHelper::isInPolygon(Triangles,Point)){
|
||||
this->Canvas->image->drawPixel(Point, colorTwo);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<QPointList.size(); i++){
|
||||
int next = (i+1)%QPointList.size();
|
||||
this->Canvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth);
|
||||
}
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
if(PointIsNearStart && QPointList.size() > 1) {
|
||||
PointIsNearStart = false;
|
||||
isDrawing = false;
|
||||
std::vector<Triangle> Triangles = IntelliHelper::calculateTriangles(QPointList);
|
||||
QPoint Point;
|
||||
QColor colorTwo(colorPicker->getSecondColor());
|
||||
colorTwo.setAlpha(alphaInner);
|
||||
for(int i = 0; i < Active->width; i++) {
|
||||
for(int j = 0; j < Active->height; j++) {
|
||||
Point = QPoint(i,j);
|
||||
if(IntelliHelper::isInPolygon(Triangles,Point)) {
|
||||
this->Canvas->image->drawPixel(Point, colorTwo);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<QPointList.size(); i++) {
|
||||
int next = (i+1)%QPointList.size();
|
||||
this->Canvas->image->drawLine(QPointList[i], QPointList[next], colorPicker->getFirstColor(), lineWidth);
|
||||
}
|
||||
QPointList.clear();
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolPolygon::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
if(!isDrawing){
|
||||
if(lineWidth + value < 10){
|
||||
lineWidth += value;
|
||||
}
|
||||
if(lineWidth < 1){
|
||||
lineWidth = 1;
|
||||
}
|
||||
}
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
if(!isDrawing) {
|
||||
if(lineWidth + value < 10) {
|
||||
lineWidth += value;
|
||||
}
|
||||
if(lineWidth < 1) {
|
||||
lineWidth = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 isNear = false;
|
||||
int StartX = Startpoint.x();
|
||||
int StartY = Startpoint.y();
|
||||
int valueToNear = 10;
|
||||
bool isNear = false;
|
||||
int StartX = Startpoint.x();
|
||||
int StartY = Startpoint.y();
|
||||
int valueToNear = 10;
|
||||
|
||||
for(int i = StartX - valueToNear; i < StartX + valueToNear; i++){
|
||||
for(int j = StartY - valueToNear; j < StartY + valueToNear; j++){
|
||||
if((i == x) && (j == y)){
|
||||
isNear = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isNear;
|
||||
for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) {
|
||||
for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) {
|
||||
if((i == x) && (j == y)) {
|
||||
isNear = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isNear;
|
||||
}
|
||||
|
||||
@@ -10,92 +10,91 @@
|
||||
*/
|
||||
class IntelliToolPolygon : public IntelliTool
|
||||
{
|
||||
/*!
|
||||
* \brief Checks if the given Point lies near the starting Point.
|
||||
* \param x - x coordinate of a point.
|
||||
* \param y - y coordinate of a point.
|
||||
* \param Startpoint - The startingpoint to check for.
|
||||
* \return Returns true if the (x,y) point is near to the startpoint, otherwise false.
|
||||
*/
|
||||
bool isNearStart(int x, int y, QPoint Startpoint);
|
||||
/*!
|
||||
* \brief Checks if the given Point lies near the starting Point.
|
||||
* \param x - x coordinate of a point.
|
||||
* \param y - y coordinate of a point.
|
||||
* \param Startpoint - The startingpoint to check for.
|
||||
* \return Returns true if the (x,y) point is near to the startpoint, otherwise false.
|
||||
*/
|
||||
bool isNearStart(int x, int y, QPoint Startpoint);
|
||||
|
||||
/*!
|
||||
* \brief LineWidth of the drawing polygon.
|
||||
*/
|
||||
int lineWidth;
|
||||
/*!
|
||||
* \brief LineWidth of the drawing polygon.
|
||||
*/
|
||||
int lineWidth;
|
||||
|
||||
/*!
|
||||
* \brief IsDrawing true while drawing, else false.
|
||||
*/
|
||||
bool isDrawing;
|
||||
/*!
|
||||
* \brief IsDrawing true while drawing, else false.
|
||||
*/
|
||||
bool isDrawing;
|
||||
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||
*/
|
||||
bool PointIsNearStart;
|
||||
/*!
|
||||
* \brief PointIsNearStart true, when last click near startpoint, else false.
|
||||
*/
|
||||
bool PointIsNearStart;
|
||||
|
||||
/*!
|
||||
* \brief The alpha value of the inner circle.
|
||||
*/
|
||||
int alphaInner;
|
||||
/*!
|
||||
* \brief The alpha value of the inner circle.
|
||||
*/
|
||||
int alphaInner;
|
||||
|
||||
/*!
|
||||
* \brief QPointList list of all points of the polygon.
|
||||
*/
|
||||
std::vector<QPoint> QPointList;
|
||||
/*!
|
||||
* \brief QPointList list of all points of the polygon.
|
||||
*/
|
||||
std::vector<QPoint> QPointList;
|
||||
public:
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
~IntelliToolPolygon() override;
|
||||
/*!
|
||||
* \brief A constructor setting the general paintingArea and colorPicker.
|
||||
* \param Area - The general paintingArea used by the project.
|
||||
* \param colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
~IntelliToolPolygon() override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftReleased(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event. CHanging the lineWidth relative to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
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 scroll event. CHanging the lineWidth relative to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include"IntelliToolRectangle.h"
|
||||
#include "IntelliToolRectangle.h"
|
||||
#include "Layer/PaintingArea.h"
|
||||
#include "QInputDialog"
|
||||
|
||||
IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker)
|
||||
:IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||
: IntelliTool(Area, colorPicker){
|
||||
this->alphaInner = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1);
|
||||
this->edgeWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1);
|
||||
}
|
||||
|
||||
IntelliToolRectangle::~IntelliToolRectangle(){
|
||||
@@ -13,55 +13,55 @@ IntelliToolRectangle::~IntelliToolRectangle(){
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::drawRectangle(QPoint otherCornor){
|
||||
int xMin = std::min(originCornor.x(), otherCornor.x());
|
||||
int xMax = std::max(originCornor.x(), otherCornor.x());
|
||||
int xMin = std::min(originCornor.x(), otherCornor.x());
|
||||
int xMax = std::max(originCornor.x(), otherCornor.x());
|
||||
|
||||
int yMin = std::min(originCornor.y(), otherCornor.y());
|
||||
int yMax = std::max(originCornor.y(), otherCornor.y());
|
||||
int yMin = std::min(originCornor.y(), otherCornor.y());
|
||||
int yMax = std::max(originCornor.y(), otherCornor.y());
|
||||
|
||||
QColor clr = colorPicker->getSecondColor();
|
||||
clr.setAlpha(alphaInner);
|
||||
for(int y=yMin; y<=yMax; y++){
|
||||
this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1);
|
||||
}
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
QColor clr = colorPicker->getSecondColor();
|
||||
clr.setAlpha(alphaInner);
|
||||
for(int y=yMin; y<=yMax; y++) {
|
||||
this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1);
|
||||
}
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), edgeWidth);
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseRightPressed(int x, int y){
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
IntelliTool::onMouseRightPressed(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseRightReleased(int x, int y){
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
IntelliTool::onMouseRightReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseLeftPressed(int x, int y){
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->originCornor=QPoint(x,y);
|
||||
drawRectangle(originCornor);
|
||||
Canvas->image->calculateVisiblity();
|
||||
IntelliTool::onMouseLeftPressed(x,y);
|
||||
this->originCornor=QPoint(x,y);
|
||||
drawRectangle(originCornor);
|
||||
Canvas->image->calculateVisiblity();
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseLeftReleased(int x, int y){
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
IntelliTool::onMouseLeftReleased(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onMouseMoved(int x, int y){
|
||||
if(this->drawing){
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
drawRectangle(next);
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
if(this->drawing) {
|
||||
this->Canvas->image->drawPlain(Qt::transparent);
|
||||
QPoint next(x,y);
|
||||
drawRectangle(next);
|
||||
}
|
||||
IntelliTool::onMouseMoved(x,y);
|
||||
}
|
||||
|
||||
void IntelliToolRectangle::onWheelScrolled(int value){
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->edgeWidth+=value;
|
||||
if(this->edgeWidth<=0){
|
||||
this->edgeWidth=1;
|
||||
}
|
||||
IntelliTool::onWheelScrolled(value);
|
||||
this->edgeWidth+=value;
|
||||
if(this->edgeWidth<=0) {
|
||||
this->edgeWidth=1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,77 +8,77 @@
|
||||
/*!
|
||||
* \brief The IntelliToolRectangle class represents a tool to draw a rectangle.
|
||||
*/
|
||||
class IntelliToolRectangle : public IntelliTool{
|
||||
/*!
|
||||
* \brief A function that implements a rectagle drawing algorithm.
|
||||
* \param otherCornor - The second corner point of the rectangle.
|
||||
*/
|
||||
void drawRectangle(QPoint otherCornor);
|
||||
class IntelliToolRectangle : public IntelliTool {
|
||||
/*!
|
||||
* \brief A function that implements a rectagle drawing algorithm.
|
||||
* \param otherCornor - The second corner point of the rectangle.
|
||||
*/
|
||||
void drawRectangle(QPoint otherCornor);
|
||||
|
||||
/*!
|
||||
* \brief originCornor - The first corner point of the rectangle.
|
||||
*/
|
||||
QPoint originCornor;
|
||||
/*!
|
||||
* \brief alphaInner- Represents the alpha value of the inside.
|
||||
*/
|
||||
int alphaInner;
|
||||
/*!
|
||||
* \brief edgeWidth - The width of the rectangle edges.
|
||||
*/
|
||||
int edgeWidth;
|
||||
/*!
|
||||
* \brief originCornor - The first corner point of the rectangle.
|
||||
*/
|
||||
QPoint originCornor;
|
||||
/*!
|
||||
* \brief alphaInner- Represents the alpha value of the inside.
|
||||
*/
|
||||
int alphaInner;
|
||||
/*!
|
||||
* \brief edgeWidth - The width of the rectangle edges.
|
||||
*/
|
||||
int edgeWidth;
|
||||
public:
|
||||
/*!
|
||||
* \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 colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolRectangle() override;
|
||||
/*!
|
||||
* \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 colorPicker - The general colorPicker used by the project.
|
||||
*/
|
||||
IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker);
|
||||
/*!
|
||||
* \brief A Destructor.
|
||||
*/
|
||||
virtual ~IntelliToolRectangle() override;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseRightPressed(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \brief A function managing the right click released of a mouse.
|
||||
* \param x - The x 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;
|
||||
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftPressed(int x, int y) override;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
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.
|
||||
* \param x - The x 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;
|
||||
/*!
|
||||
* \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 y - The y coordinate relative to the active/canvas layer.
|
||||
*/
|
||||
virtual void onMouseLeftReleased(int x, int y) override;
|
||||
|
||||
/*!
|
||||
* \brief A function managing the scroll event.Changing edgeWidth relativ to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
/*!
|
||||
* \brief A function managing the scroll event.Changing edgeWidth relativ to value.
|
||||
* \param value - The absolute the scroll has changed.
|
||||
*/
|
||||
virtual void onWheelScrolled(int value) override;
|
||||
|
||||
/*!
|
||||
* \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 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.Drawing a rectangle to currrent mouse position.
|
||||
* \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;
|
||||
};
|
||||
|
||||
#endif // INTELLIRECTANGLETOOL_H
|
||||
|
||||
Reference in New Issue
Block a user