Merge branch 'dev' into UnitTesting

This commit is contained in:
2020-01-16 10:45:23 +01:00
14 changed files with 717 additions and 621 deletions

View File

@@ -1,6 +1,3 @@
src/GUI/IntelliPhotoGui.cpp:83:15: style: Variable 'layer' is assigned a value that is never used. [unreadVariable]
int layer = paintingArea->addLayer(width,height,0,0);
^
src/IntelliHelper/IntelliColorPicker.cpp:4:3: performance: Variable 'firstColor' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] src/IntelliHelper/IntelliColorPicker.cpp:4:3: performance: Variable 'firstColor' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
firstColor = {255,0,0,255}; firstColor = {255,0,0,255};
^ ^
@@ -10,7 +7,7 @@ src/IntelliHelper/IntelliColorPicker.cpp:5:3: performance: Variable 'secondColor
src/IntelliHelper/IntelliTriangulation.cpp:116:63: style: Parameter 'triangles' can be declared with const [constParameter] src/IntelliHelper/IntelliTriangulation.cpp:116:63: style: Parameter 'triangles' can be declared with const [constParameter]
bool IntelliTriangulation::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){ bool IntelliTriangulation::isInPolygon(std::vector<Triangle> &triangles, QPoint &point){
^ ^
src/Layer/PaintingArea.cpp:335:22: style: Redundant condition: If 'activeLayer > 0', the comparison 'activeLayer != -1' is always true. [redundantCondition] src/Layer/PaintingArea.cpp:334:28: style: Redundant condition: If 'activeLayer > 0', the comparison 'activeLayer != -1' is always true. [redundantCondition]
if(activeLayer!=-1 && activeLayer>0) { if(activeLayer!=-1 && activeLayer>0) {
^ ^
src/Tool/IntelliTool.cpp:4:14: warning: Member variable 'IntelliTool::ActiveType' is not initialized in the constructor. [uninitMemberVar] src/Tool/IntelliTool.cpp:4:14: warning: Member variable 'IntelliTool::ActiveType' is not initialized in the constructor. [uninitMemberVar]
@@ -22,34 +19,31 @@ IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, In
src/Tool/IntelliTool.cpp:4:14: warning: Member variable 'IntelliTool::Canvas' is not initialized in the constructor. [uninitMemberVar] src/Tool/IntelliTool.cpp:4:14: warning: Member variable 'IntelliTool::Canvas' is not initialized in the constructor. [uninitMemberVar]
IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){ IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){
^ ^
src/Tool/IntelliToolCircle.cpp:43:9: style: Local variable 'yMin' shadows outer variable [shadowVariable] src/Tool/IntelliToolCircle.cpp:42:9: style: Local variable 'yMin' shadows outer variable [shadowVariable]
int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
^ ^
src/Tool/IntelliToolCircle.cpp:19:7: note: Shadowed declaration src/Tool/IntelliToolCircle.cpp:18:7: note: Shadowed declaration
int yMin, yMax, xMin, xMax;
^
src/Tool/IntelliToolCircle.cpp:42:9: note: Shadow variable
int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
^
src/Tool/IntelliToolCircle.cpp:43:9: style: Local variable 'yMax' shadows outer variable [shadowVariable]
int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
^
src/Tool/IntelliToolCircle.cpp:18:13: note: Shadowed declaration
int yMin, yMax, xMin, xMax; int yMin, yMax, xMin, xMax;
^ ^
src/Tool/IntelliToolCircle.cpp:43:9: note: Shadow variable src/Tool/IntelliToolCircle.cpp:43:9: note: Shadow variable
int yMin = static_cast<int>(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
^
src/Tool/IntelliToolCircle.cpp:44:9: style: Local variable 'yMax' shadows outer variable [shadowVariable]
int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
^ ^
src/Tool/IntelliToolCircle.cpp:19:13: note: Shadowed declaration
int yMin, yMax, xMin, xMax;
^
src/Tool/IntelliToolCircle.cpp:44:9: note: Shadow variable
int yMax = static_cast<int>(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2)));
^
src/Tool/IntelliToolCircle.cpp:16:13: style: Variable 'outer' is assigned a value that is never used. [unreadVariable]
int outer = radius+20;
^
src/Tool/IntelliToolLine.cpp:51:13: style: Variable 'c' is assigned a value that is never used. [unreadVariable] src/Tool/IntelliToolLine.cpp:51:13: style: Variable 'c' is assigned a value that is never used. [unreadVariable]
int c = lineStartingPoint.y()-lineStartingPoint.x()*m; int c = lineStartingPoint.y()-lineStartingPoint.x()*m;
^ ^
src/Tool/IntelliToolPolygon.h:25:6: warning: The class 'IntelliToolPolygon' defines member variable with name 'isDrawing' also defined in its parent class 'IntelliTool'. [duplInheritedMember] src/Tool/IntelliToolPolygon.h:25:6: warning: The class 'IntelliToolPolygon' defines member variable with name 'isDrawing' also defined in its parent class 'IntelliTool'. [duplInheritedMember]
bool isDrawing; bool isDrawing;
^ ^
src/Tool/IntelliTool.h:68:6: note: Parent variable 'IntelliTool::isDrawing' src/Tool/IntelliTool.h:69:6: note: Parent variable 'IntelliTool::isDrawing'
bool isDrawing = false; bool isDrawing = false;
^ ^
src/Tool/IntelliToolPolygon.h:25:6: note: Derived variable 'IntelliToolPolygon::isDrawing' src/Tool/IntelliToolPolygon.h:25:6: note: Derived variable 'IntelliToolPolygon::isDrawing'
@@ -58,34 +52,31 @@ bool isDrawing;
src/GUI/IntelliPhotoGui.cpp:23:0: style: The function 'closeEvent' is never used. [unusedFunction] src/GUI/IntelliPhotoGui.cpp:23:0: style: The function 'closeEvent' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:271:0: style: The function 'mouseMoveEvent' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:261:0: style: The function 'mouseMoveEvent' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:255:0: style: The function 'mousePressEvent' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:242:0: style: The function 'mousePressEvent' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:281:0: style: The function 'mouseReleaseEvent' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:274:0: style: The function 'mouseReleaseEvent' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:307:0: style: The function 'paintEvent' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:304:0: style: The function 'paintEvent' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:318:0: style: The function 'resizeEvent' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:315:0: style: The function 'resizeEvent' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:323:0: style: The function 'resizeLayer' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:320:0: style: The function 'resizeLayer' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:175:0: style: The function 'slotActivateLayer' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:168:0: style: The function 'slotActivateLayer' is never used. [unusedFunction]
^ ^
src/GUI/IntelliPhotoGui.cpp:157:0: style: The function 'slotClearActiveLayer' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:88:0: style: The function 'slotDeleteActiveLayer' is never used. [unusedFunction]
^ ^
src/Layer/PaintingArea.cpp:83:0: style: The function 'slotDeleteActiveLayer' is never used. [unusedFunction] src/Layer/PaintingArea.cpp:289:0: style: The function 'wheelEvent' is never used. [unusedFunction]
^
src/Layer/PaintingArea.cpp:294:0: style: The function 'wheelEvent' is never used. [unusedFunction]
^ ^
nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude] nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude]

View File

@@ -46,7 +46,7 @@ void IntelliPhotoGui::slotOpen(){
// If we have a file name load the image and place // If we have a file name load the image and place
// it in the paintingArea // it in the paintingArea
if (!fileName.isEmpty()){ if (!fileName.isEmpty()) {
paintingArea->open(fileName); paintingArea->open(fileName);
UpdateGui(); UpdateGui();
} }
@@ -65,8 +65,8 @@ void IntelliPhotoGui::slotSave(){
saveFile(fileFormat); saveFile(fileFormat);
} }
// Opens a dialog that allows the user to create a New Layer // Opens a dialog that allows the user to create a New RASTER Layer
void IntelliPhotoGui::slotCreateNewLayer(){ void IntelliPhotoGui::slotCreateNewRasterLayer(){
// Stores button value // Stores button value
bool ok1, ok2; bool ok1, ok2;
@@ -84,8 +84,33 @@ void IntelliPhotoGui::slotCreateNewLayer(){
tr("Height:"), tr("Height:"),
200,1, 500, 1, &ok2); 200,1, 500, 1, &ok2);
// Create New Layer // Create New Layer
if (ok1&&ok2){ if (ok1&&ok2) {
paintingArea->addLayer(width,height,0,0); paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::RASTERIMAGE);
UpdateGui();
}
}
// Opens a dialog that allows the user to create a New SHAPED Layer
void IntelliPhotoGui::slotCreateNewShapedLayer(){
// Stores button value
bool ok1, ok2;
// "New Layer" is the title of the window
// the next tr is the text to display
// Define the standard Value, min, max, step and ok button
QInputDialog Input;
Input.setPalette(Palette);
int width = Input.getInt(this, tr("New Layer"),
tr("Width:"),
200,1, 500, 1, &ok1);
int height = QInputDialog::getInt(this, tr("New Layer"),
tr("Height:"),
200,1, 500, 1, &ok2);
// Create New Layer
if (ok1&&ok2) {
paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::SHAPEDIMAGE);
UpdateGui(); UpdateGui();
} }
} }
@@ -129,6 +154,24 @@ void IntelliPhotoGui::slotSetActiveAlpha(){
} }
} }
void IntelliPhotoGui::slotSetPolygon(){
// Stores button value
bool ok1;
// "Layer to set on" is the title of the window
// the next tr is the text to display
// Define the standard Value, min, max, step and ok button
int layer = QInputDialog::getInt(this, tr("Layer to set on"),
tr("Layer:"),
1,1,500,1, &ok1);
if (ok1)
{
paintingArea->setPolygon(layer-1);
UpdateGui();
}
}
void IntelliPhotoGui::slotPositionMoveUp(){ void IntelliPhotoGui::slotPositionMoveUp(){
paintingArea->movePositionActive(0,-20); paintingArea->movePositionActive(0,-20);
update(); update();
@@ -159,35 +202,6 @@ void IntelliPhotoGui::slotMoveLayerDown(){
update(); update();
} }
void IntelliPhotoGui::slotClearActiveLayer(){
// Stores button value
bool ok1, ok2, ok3, ok4;
// "Red Input" is the title of the window
// the next tr is the text to display
// Define the standard Value, min, max, step and ok button
int red = QInputDialog::getInt(this, tr("Red Input"),
tr("Red:"),
255,0, 255,1, &ok1);
// "Green Input" is the title of the window
int green = QInputDialog::getInt(this, tr("Green Input"),
tr("Green:"),
255,0, 255, 1, &ok2);
// "Blue Input" is the title of the window
int blue = QInputDialog::getInt(this, tr("Blue Input"),
tr("Blue:"),
255,0, 255, 1, &ok3);
// "Alpha Input" is the title of the window
int alpha = QInputDialog::getInt(this, tr("Alpha Input"),
tr("Alpha:"),
255,0, 255, 1, &ok4);
if (ok1&&ok2&&ok3&&ok4)
{
paintingArea->floodFill(red, green, blue, alpha);
UpdateGui();
}
}
void IntelliPhotoGui::slotSetActiveLayer(){ void IntelliPhotoGui::slotSetActiveLayer(){
// Stores button value // Stores button value
bool ok1; bool ok1;
@@ -343,10 +357,16 @@ void IntelliPhotoGui::createActions(){
actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O));
connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen()));
// Create New Layer action and tie to IntelliPhotoGui::newLayer() // Create New RASTER Layer action and tie to IntelliPhotoGui::newLayer()
actionCreateNewLayer = new QAction(tr("&New Layer..."), this); actionCreateNewRasterLayer = new QAction(tr("&Raster Image"), this);
actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); actionCreateNewRasterLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer())); connect(actionCreateNewRasterLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewRasterLayer()));
// Create New SHAPED Layer action and tie to IntelliPhotoGui::newLayer()
actionCreateNewShapedLayer = new QAction(tr("&Shaped Image"), this);
actionCreateNewShapedLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N + Qt::ALT));
connect(actionCreateNewShapedLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewShapedLayer()));
// Delete New Layer action and tie to IntelliPhotoGui::deleteLayer() // Delete New Layer action and tie to IntelliPhotoGui::deleteLayer()
actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); actionDeleteLayer = new QAction(tr("&Delete Layer..."), this);
@@ -361,6 +381,10 @@ void IntelliPhotoGui::createActions(){
actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A)); actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A));
connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha())); connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha()));
actionSetPolygon = new QAction(tr("&set new Polygondata"), this);
actionSetPolygon->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_P));
connect(actionSetPolygon, SIGNAL(triggered()), this, SLOT(slotSetPolygon()));
actionMovePositionUp = new QAction(tr("&move Up"), this); actionMovePositionUp = new QAction(tr("&move Up"), this);
actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up)); actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp())); connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp()));
@@ -510,12 +534,17 @@ void IntelliPhotoGui::createMenus(){
renderMenu->addAction(actionUpdateRenderSettingsOn); renderMenu->addAction(actionUpdateRenderSettingsOn);
renderMenu->addAction(actionUpdateRenderSettingsOff); renderMenu->addAction(actionUpdateRenderSettingsOff);
//Attach all Layer Creations to Menu
layerCreationMenu = new QMenu(tr("&Create new Layer"), this);
layerCreationMenu->addAction(actionCreateNewRasterLayer);
layerCreationMenu->addAction(actionCreateNewShapedLayer);
// Attach all actions to Layer // Attach all actions to Layer
layerMenu = new QMenu(tr("&Layer"), this); layerMenu = new QMenu(tr("&Layer"), this);
layerMenu->addAction(actionCreateNewLayer); layerMenu->addMenu(layerCreationMenu);
layerMenu->addSeparator(); layerMenu->addSeparator();
layerMenu->addAction(actionSetActiveAlpha); layerMenu->addAction(actionSetActiveAlpha);
layerMenu->addAction(actionSetActiveLayer); layerMenu->addAction(actionSetActiveLayer);
layerMenu->addAction(actionSetPolygon);
layerMenu->addSeparator(); layerMenu->addSeparator();
layerMenu->addAction(actionMovePositionUp); layerMenu->addAction(actionMovePositionUp);
layerMenu->addAction(actionMovePositionDown); layerMenu->addAction(actionMovePositionDown);
@@ -676,7 +705,7 @@ void IntelliPhotoGui::createGui(){
ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3); ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3);
IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); IntelliImage* activePicture = paintingArea->getImageOfActiveLayer();
if(activePicture){ if(activePicture) {
preview = preview.fromImage(activePicture->getImageData()); preview = preview.fromImage(activePicture->getImageData());
}else{ }else{
QImage tmp(1,1,QImage::Format_ARGB32); QImage tmp(1,1,QImage::Format_ARGB32);
@@ -730,6 +759,7 @@ void IntelliPhotoGui::setIntelliStyle(){
this->helpMenu->setPalette(Palette); this->helpMenu->setPalette(Palette);
this->renderMenu->setPalette(Palette); this->renderMenu->setPalette(Palette);
this->toolMenu->setPalette(Palette); this->toolMenu->setPalette(Palette);
this->layerCreationMenu->setPalette(Palette);
this->layerMenu->setPalette(Palette); this->layerMenu->setPalette(Palette);
this->colorMenu->setPalette(Palette); this->colorMenu->setPalette(Palette);
this->toolCreationMenu->setPalette(Palette); this->toolCreationMenu->setPalette(Palette);
@@ -804,7 +834,7 @@ void IntelliPhotoGui::UpdateGui(){
ActiveLayerLine->setText(string); ActiveLayerLine->setText(string);
IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); IntelliImage* activePicture = paintingArea->getImageOfActiveLayer();
if(activePicture){ if(activePicture) {
preview = preview.fromImage(activePicture->getImageData()); preview = preview.fromImage(activePicture->getImageData());
}else{ }else{
QImage tmp(1,1,QImage::Format_ARGB32); QImage tmp(1,1,QImage::Format_ARGB32);

View File

@@ -25,7 +25,7 @@ class IntelliColorPicker;
* \brief The IntelliPhotoGui class handles the graphical user interface for the intelliPhoto program * \brief The IntelliPhotoGui class handles the graphical user interface for the intelliPhoto program
*/ */
class IntelliPhotoGui : public QMainWindow { class IntelliPhotoGui : public QMainWindow {
friend UnitTest; friend UnitTest;
// Declares our class as a QObject which is the base class // Declares our class as a QObject which is the base class
// for all Qt objects // for all Qt objects
// QObjects handle events // QObjects handle events
@@ -48,11 +48,12 @@ void slotOpen();
void slotSave(); void slotSave();
// layer slots here // layer slots here
void slotCreateNewLayer(); void slotCreateNewRasterLayer();
void slotCreateNewShapedLayer();
void slotDeleteLayer(); void slotDeleteLayer();
void slotClearActiveLayer();
void slotSetActiveLayer(); void slotSetActiveLayer();
void slotSetActiveAlpha(); void slotSetActiveAlpha();
void slotSetPolygon();
void slotPositionMoveUp(); void slotPositionMoveUp();
void slotPositionMoveDown(); void slotPositionMoveDown();
void slotPositionMoveLeft(); void slotPositionMoveLeft();
@@ -133,16 +134,17 @@ QLabel* ActiveLayerImageLine;
QPalette Palette; QPalette Palette;
// The menu widgets // The menu widgets
QMenu* saveAsMenu; QMenu*saveAsMenu;
QMenu* fileMenu; QMenu*fileMenu;
QMenu* renderMenu; QMenu*renderMenu;
QMenu* optionMenu; QMenu*optionMenu;
QMenu* layerMenu; QMenu*layerCreationMenu;
QMenu* colorMenu; QMenu*layerMenu;
QMenu* toolCreationMenu; QMenu*colorMenu;
QMenu* toolSettingsMenu; QMenu*toolCreationMenu;
QMenu* toolMenu; QMenu*toolSettingsMenu;
QMenu* helpMenu; QMenu*toolMenu;
QMenu*helpMenu;
// All the actions that can occur // All the actions that can occur
// meta image actions (need further modularisation) // meta image actions (need further modularisation)
@@ -172,10 +174,12 @@ QAction* actionAboutDialog;
QAction* actionAboutQtDialog; QAction* actionAboutQtDialog;
// layer change actions // layer change actions
QAction* actionCreateNewLayer; QAction* actionCreateNewRasterLayer;
QAction* actionCreateNewShapedLayer;
QAction* actionDeleteLayer; QAction* actionDeleteLayer;
QAction* actionSetActiveLayer; QAction* actionSetActiveLayer;
QAction* actionSetActiveAlpha; QAction* actionSetActiveAlpha;
QAction* actionSetPolygon;
QAction* actionMovePositionUp; QAction* actionMovePositionUp;
QAction* actionMovePositionDown; QAction* actionMovePositionDown;
QAction* actionMovePositionLeft; QAction* actionMovePositionLeft;

View File

@@ -4,11 +4,11 @@
IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) IntelliImage::IntelliImage(int width, int height, bool fastRendererOn)
: imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){
if(fastRendererOn){ if(fastRendererOn) {
imageData = imageData.convertToFormat(QImage::Format_ARGB32); imageData = imageData.convertToFormat(QImage::Format_ARGB32);
} }
imageData.fill(QColor(255,255,255,255)); imageData.fill(QColor(255,255,255,255));
if(fastRendererOn){ if(fastRendererOn) {
imageData = imageData.convertToFormat(QImage::Format_Indexed8); imageData = imageData.convertToFormat(QImage::Format_Indexed8);
} }
this->fastRenderering = fastRendererOn; this->fastRenderering = fastRendererOn;
@@ -46,7 +46,7 @@ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){
// Draw the image // Draw the image
QPainter painter(&newImage); QPainter painter(&newImage);
painter.drawImage(QPoint(0, 0), *image); painter.drawImage(QPoint(0, 0), *image);
if(fastRenderering){ if(fastRenderering) {
*image = newImage.convertToFormat(QImage::Format_Indexed8); *image = newImage.convertToFormat(QImage::Format_Indexed8);
} }
else{ else{
@@ -55,7 +55,7 @@ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){
} }
void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
} }
// Used to draw on the widget // Used to draw on the widget
@@ -69,13 +69,13 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
delete painter; delete painter;
painter = nullptr; painter = nullptr;
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
} }
} }
void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
} }
// Used to draw on the widget // Used to draw on the widget
@@ -88,13 +88,13 @@ void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& p
delete painter; delete painter;
painter = nullptr; painter = nullptr;
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
} }
} }
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
} }
// Used to draw on the widget // Used to draw on the widget
@@ -108,23 +108,23 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co
delete painter; delete painter;
painter = nullptr; painter = nullptr;
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
} }
} }
void IntelliImage::drawPlain(const QColor& color){ void IntelliImage::drawPlain(const QColor& color){
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
} }
imageData.fill(color); imageData.fill(color);
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
} }
} }
QColor IntelliImage::getPixelColor(QPoint& point){ QColor IntelliImage::getPixelColor(QPoint& point){
if(fastRenderering){ if(fastRenderering) {
QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32); QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32);
return copy.pixelColor(point); return copy.pixelColor(point);
} }
@@ -133,7 +133,7 @@ QColor IntelliImage::getPixelColor(QPoint& point){
QImage IntelliImage::getImageData(){ QImage IntelliImage::getImageData(){
QImage copy = imageData; QImage copy = imageData;
if(fastRenderering){ if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_ARGB32); copy = copy.convertToFormat(QImage::Format_ARGB32);
} }
return copy; return copy;
@@ -141,7 +141,7 @@ QImage IntelliImage::getImageData(){
void IntelliImage::setImageData(const QImage& newData){ void IntelliImage::setImageData(const QImage& newData){
imageData = newData; imageData = newData;
if(fastRenderering){ if(fastRenderering) {
this->imageData = imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = imageData.convertToFormat(QImage::Format_Indexed8);
} }
else { else {
@@ -151,7 +151,7 @@ void IntelliImage::setImageData(const QImage& newData){
void IntelliImage::updateRendererSetting(bool fastRendererOn){ void IntelliImage::updateRendererSetting(bool fastRendererOn){
this->fastRenderering = fastRendererOn; this->fastRenderering = fastRendererOn;
if(fastRenderering){ if(fastRenderering) {
this->imageData = imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = imageData.convertToFormat(QImage::Format_Indexed8);
} }
else { else {

View File

@@ -30,7 +30,7 @@ QImage IntelliRasterImage::getDisplayable(int alpha){
QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
QImage copy = imageData; QImage copy = imageData;
if(fastRenderering){ if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_ARGB32); copy = copy.convertToFormat(QImage::Format_ARGB32);
} }
for(int y = 0; y<copy.height(); y++) { for(int y = 0; y<copy.height(); y++) {
@@ -40,7 +40,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){
copy.setPixelColor(x,y, clr); copy.setPixelColor(x,y, clr);
} }
} }
if(fastRenderering){ if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_Indexed8); copy = copy.convertToFormat(QImage::Format_Indexed8);
} }
return copy.scaled(displaySize,Qt::IgnoreAspectRatio); return copy.scaled(displaySize,Qt::IgnoreAspectRatio);

View File

@@ -27,7 +27,10 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){
} }
void IntelliShapedImage::calculateVisiblity(){ void IntelliShapedImage::calculateVisiblity(){
if(fastRenderering){ if(polygonData.size()<2) {
return;
}
if(fastRenderering) {
this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); this->imageData = imageData.convertToFormat(QImage::Format_ARGB32);
} }
@@ -40,7 +43,7 @@ void IntelliShapedImage::calculateVisiblity(){
imageData.setPixelColor(x,y,clr); imageData.setPixelColor(x,y,clr);
} }
} }
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
} }
return; return;
@@ -59,14 +62,14 @@ void IntelliShapedImage::calculateVisiblity(){
imageData.setPixelColor(x,y,clr); imageData.setPixelColor(x,y,clr);
} }
} }
if(fastRenderering){ if(fastRenderering) {
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
} }
} }
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
QImage copy = imageData; QImage copy = imageData;
if(fastRenderering){ if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_ARGB32); copy = copy.convertToFormat(QImage::Format_ARGB32);
} }
for(int y = 0; y<copy.height(); y++) { for(int y = 0; y<copy.height(); y++) {
@@ -76,7 +79,7 @@ QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){
copy.setPixelColor(x,y, clr); copy.setPixelColor(x,y, clr);
} }
} }
if(fastRenderering){ if(fastRenderering) {
copy = copy.convertToFormat(QImage::Format_Indexed8); copy = copy.convertToFormat(QImage::Format_Indexed8);
} }
return copy.scaled(displaySize,Qt::IgnoreAspectRatio); return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
@@ -91,6 +94,19 @@ void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
this->polygonData.push_back(QPoint(element.x(), element.y())); this->polygonData.push_back(QPoint(element.x(), element.y()));
} }
triangles = IntelliTriangulation::calculateTriangles(polygonData); triangles = IntelliTriangulation::calculateTriangles(polygonData);
if(fastRenderering) {
imageData = imageData.convertToFormat(QImage::Format_ARGB32);
}
for(int y = 0; y<imageData.height(); y++) {
for(int x = 0; x<imageData.width(); x++) {
QColor clr = imageData.pixelColor(x,y);
clr.setAlpha(255);
imageData.setPixelColor(x,y,clr);
}
}
if(fastRenderering) {
imageData = imageData.convertToFormat(QImage::Format_Indexed8);
}
} }
calculateVisiblity(); calculateVisiblity();
return; return;

View File

@@ -18,10 +18,13 @@
#include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolFloodFill.h"
#include "Tool/IntelliToolPolygon.h" #include "Tool/IntelliToolPolygon.h"
PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent)
: QWidget(parent){ : QWidget(parent){
this->Tool = nullptr; this->Tool = nullptr;
this->setLayerDimensions(maxWidth, maxHeight); this->setLayerDimensions(maxWidth, maxHeight);
activeLayer=-1;
} }
PaintingArea::~PaintingArea(){ PaintingArea::~PaintingArea(){
@@ -29,9 +32,9 @@ PaintingArea::~PaintingArea(){
} }
void PaintingArea::setRenderSettings(bool isFastRenderingOn){ void PaintingArea::setRenderSettings(bool isFastRenderingOn){
if(isFastRenderingOn != renderSettings.isFastRenderering()){ if(isFastRenderingOn != renderSettings.isFastRenderering()) {
renderSettings.setFastRendering(isFastRenderingOn); renderSettings.setFastRendering(isFastRenderingOn);
for(auto& layer : layerBundle){ for(auto& layer : layerBundle) {
layer.image->updateRendererSetting(isFastRenderingOn); layer.image->updateRendererSetting(isFastRenderingOn);
} }
} }
@@ -50,6 +53,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){
int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){
LayerObject newLayer; LayerObject newLayer;
updateTools();
newLayer.width = width; newLayer.width = width;
newLayer.height = height; newLayer.height = height;
newLayer.widthOffset = widthOffset; newLayer.widthOffset = widthOffset;
@@ -66,13 +70,16 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff
} }
void PaintingArea::deleteLayer(int idx){ void PaintingArea::deleteLayer(int idx, bool isTool){
if(idx < static_cast<int>(layerBundle.size())&&idx>=0) { if(!isTool) {
updateTools();
}
if(idx<static_cast<int>(layerBundle.size())&&idx>=0) {
this->layerBundle.erase(layerBundle.begin()+idx); this->layerBundle.erase(layerBundle.begin()+idx);
if(activeLayer>=idx) { if(activeLayer>=idx) {
activeLayer--; activeLayer--;
} }
if(activeLayer < 0 && layerBundle.size()){ if(activeLayer < 0 && layerBundle.size()) {
activeLayer=0; activeLayer=0;
} }
} }
@@ -86,6 +93,7 @@ void PaintingArea::slotDeleteActiveLayer(){
} }
void PaintingArea::setLayerActive(int idx){ void PaintingArea::setLayerActive(int idx){
updateTools();
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) { if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
this->activeLayer=idx; this->activeLayer=idx;
} }
@@ -98,6 +106,15 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){
} }
} }
} }
void PaintingArea::setPolygon(int idx){
if(idx>=0&&idx<static_cast<int>(layerBundle.size())) {
if(layerBundle[static_cast<size_t>(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE) {
delete this->Tool;
this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true);
isSettingPolygon = true;
}
}
}
// Used to load the image and place it in the widget // Used to load the image and place it in the widget
bool PaintingArea::open(const QString &filePath){ bool PaintingArea::open(const QString &filePath){
@@ -135,42 +152,14 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){
} }
} }
// Color the image area with white
void PaintingArea::floodFill(int r, int g, int b, int a){
if(this->activeLayer==-1) {
return;
}
if(r >255 || g>255|| b>255 || a>255){
return;
}
if(r < 0 || g < 0|| b < 0 || a < 0){
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){ void PaintingArea::movePositionActive(int x, int y){
if(Tool!=nullptr) { updateTools();
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x; layerBundle[static_cast<size_t>(activeLayer)].widthOffset += x;
layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y; layerBundle[static_cast<size_t>(activeLayer)].heightOffset += y;
} }
void PaintingArea::moveActiveLayer(int idx){ void PaintingArea::moveActiveLayer(int idx){
if(Tool != nullptr) { updateTools();
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
if(idx==1) { if(idx==1) {
this->selectLayerUp(); this->selectLayerUp();
}else if(idx==-1) { }else if(idx==-1) {
@@ -179,13 +168,7 @@ void PaintingArea::moveActiveLayer(int idx){
} }
void PaintingArea::slotActivateLayer(int a){ void PaintingArea::slotActivateLayer(int a){
if(Tool != nullptr) { updateTools();
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
}
if(a>=0 && a < static_cast<int>(layerBundle.size())) { if(a>=0 && a < static_cast<int>(layerBundle.size())) {
this->setLayerActive(a); this->setLayerActive(a);
} }
@@ -259,7 +242,7 @@ std::vector<QPoint> PaintingArea::getPolygonDataOfRealLayer(){
// left button and if so store the current position // left button and if so store the current position
// Set that we are currently drawing // Set that we are currently drawing
void PaintingArea::mousePressEvent(QMouseEvent*event){ void PaintingArea::mousePressEvent(QMouseEvent*event){
if(this->activeLayer < 0){ if(this->activeLayer < 0) {
return; return;
} }
if(Tool == nullptr) if(Tool == nullptr)
@@ -278,7 +261,7 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){
// we call the drawline function which draws a line // we call the drawline function which draws a line
// from the last position to the current // from the last position to the current
void PaintingArea::mouseMoveEvent(QMouseEvent*event){ void PaintingArea::mouseMoveEvent(QMouseEvent*event){
if(this->activeLayer < 0){ if(this->activeLayer < 0) {
return; return;
} }
if(Tool == nullptr) if(Tool == nullptr)
@@ -329,7 +312,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){
update(); update();
} }
// Resize the image to slightly larger then the main window //TODOJ Resize the image to slightly larger then the main window
// to cut down on the need to resize the image // to cut down on the need to resize the image
void PaintingArea::resizeEvent(QResizeEvent*event){ void PaintingArea::resizeEvent(QResizeEvent*event){
//TODO wait till tool works //TODO wait till tool works
@@ -341,6 +324,7 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){
} }
void PaintingArea::selectLayerUp(){ void PaintingArea::selectLayerUp(){
updateTools();
if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) { if(activeLayer!=-1 && static_cast<unsigned long long>(activeLayer)<layerBundle.size()-1) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]); std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer+1)]);
activeLayer++; activeLayer++;
@@ -348,6 +332,7 @@ void PaintingArea::selectLayerUp(){
} }
void PaintingArea::selectLayerDown(){ void PaintingArea::selectLayerDown(){
updateTools();
if(activeLayer!=-1 && activeLayer>0) { if(activeLayer!=-1 && activeLayer>0) {
std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]); std::swap(layerBundle[static_cast<unsigned long long>(activeLayer)], layerBundle[static_cast<unsigned long long>(activeLayer-1)]);
activeLayer--; activeLayer--;
@@ -422,8 +407,38 @@ int PaintingArea::getNumberOfActiveLayer(){
} }
IntelliImage* PaintingArea::getImageOfActiveLayer(){ IntelliImage* PaintingArea::getImageOfActiveLayer(){
if(activeLayer<0){ if(activeLayer<0) {
return nullptr; return nullptr;
} }
return layerBundle[activeLayer].image; return layerBundle[static_cast<size_t>(activeLayer)].image;
}
QImage PaintingArea::getImageDataOfActiveLayer(){
QImage returnImage;
if(activeLayer<0) {
returnImage = QImage(QSize(10,10),QImage::Format_ARGB32);
returnImage.fill(QColor(255,255,255,255));
}
else{
returnImage = layerBundle[static_cast<size_t>(activeLayer)].image->getImageData();
if(renderSettings.isFastRenderering()) {
returnImage = returnImage.convertToFormat(QImage::Format_ARGB32);
}
}
return returnImage;
}
void PaintingArea::updateTools(){
if(Tool!=nullptr) {
if(Tool->getIsDrawing()) {
IntelliTool* temp = copyActiveTool();
delete this->Tool;
this->Tool = temp;
}
if(isSettingPolygon) {
delete this->Tool;
this->Tool = nullptr;
isSettingPolygon = false;
}
}
} }

View File

@@ -39,7 +39,7 @@ struct LayerObject {
*/ */
class PaintingArea : public QWidget class PaintingArea : public QWidget
{ {
friend UnitTest; friend UnitTest;
// Declares our class as a QObject which is the base class // Declares our class as a QObject which is the base class
// for all Qt objects // for all Qt objects
// QObjects handle events // QObjects handle events
@@ -47,42 +47,42 @@ Q_OBJECT
friend IntelliTool; friend IntelliTool;
friend IntelliPhotoGui; friend IntelliPhotoGui;
public: public:
/*! /*!
* \brief PaintingArea is the constructor of the PaintingArea class, which initiates the working environment * \brief PaintingArea is the constructor of the PaintingArea class, which initiates the working environment
* \param maxWidth - The maximum amount of pixles that are inside painting area from left to right (default=600px) * \param maxWidth - The maximum amount of pixles that are inside painting area from left to right (default=600px)
* \param maxHeight - The maximum amount of pixles that are inside painting area from top to bottom (default=600px) * \param maxHeight - The maximum amount of pixles that are inside painting area from top to bottom (default=600px)
* \param parent - The parent window of the main window (default=nullptr) * \param parent - The parent window of the main window (default=nullptr)
*/ */
PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr); PaintingArea(int maxWidth=600, int maxHeight=600, QWidget*parent = nullptr);
/*! /*!
* \brief This deconstructor is used to clear up the memory and remove the currently active window * \brief This deconstructor is used to clear up the memory and remove the currently active window
*/ */
~PaintingArea() override; ~PaintingArea() override;
// Handles all events // Handles all events
/*! /*!
* \brief setRenderSettings updates all Images to the new Rendersetting. * \brief setRenderSettings updates all Images to the new Rendersetting.
* \param isFastRenderingOn is the new given flag for the FastRenderer. * \param isFastRenderingOn is the new given flag for the FastRenderer.
*/ */
void setRenderSettings(bool isFastRenderingOn); void setRenderSettings(bool isFastRenderingOn);
/*! /*!
* \brief The open method is used for loading a picture into the current layer * \brief The open method is used for loading a picture into the current layer
* \param fileName - Path and filename which are used to determine where the to-be-opened file is stored * \param fileName - Path and filename which are used to determine where the to-be-opened file is stored
* \return Returns a boolean variable whether the file was successfully opened or not * \return Returns a boolean variable whether the file was successfully opened or not
*/ */
bool open(const QString &filePath); bool open(const QString &filePath);
/*! /*!
* \brief The save method is used for exporting the current project as one picture * \brief The save method is used for exporting the current project as one picture
* \param fileName * \param fileName
* \param fileFormat * \param fileFormat
* \return Returns a boolean variable, true if the file was saved successfully, false if not * \return Returns a boolean variable, true if the file was saved successfully, false if not
*/ */
bool save(const QString &filePath, const char *fileFormat); bool save(const QString &filePath, const char*fileFormat);
/*! /*!
* \brief The addLayer adds a layer to the current project/ painting area * \brief The addLayer adds a layer to the current project/ painting area
* \param width - Width of the layer in pixles * \param width - Width of the layer in pixles
* \param height - Height of the layer in pixles * \param height - Height of the layer in pixles
@@ -91,8 +91,8 @@ public:
* \param type - Defining the ImageType of the new layer * \param type - Defining the ImageType of the new layer
* \return Returns the number of layers in the project * \return Returns the number of layers in the project
*/ */
int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE); int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
/*! /*!
* \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack * \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack
* \param idx - Index of the position the new layer should be added * \param idx - Index of the position the new layer should be added
* \param width - Width of the layer in pixles * \param width - Width of the layer in pixles
@@ -102,87 +102,91 @@ public:
* \param type - Defining the ImageType of the new layer * \param type - Defining the ImageType of the new layer
* \return Returns the id of the layer position * \return Returns the id of the layer position
*/ */
int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE); int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, IntelliImage::ImageType type = IntelliImage::ImageType::RASTERIMAGE);
/*! /*!
* \brief The deleteLayer method removes a layer at a given idx * \brief The deleteLayer method removes a layer at a given idx
* \param idx - The index of the layer to be removed * \param idx - The index of the layer to be removed
* \param isTool - Is the flag for when a tool uses this function.
*/ */
void deleteLayer(int idx); void deleteLayer(int idx, bool isTool = false);
/*! /*!
* \brief The setLayerToActive method marks a specific layer as active * \brief The setLayerToActive method marks a specific layer as active
* \param idx - The index of the layer to be active * \param idx - The index of the layer to be active
*/ */
void setLayerActive(int idx); void setLayerActive(int idx);
/*! /*!
* \brief The setAlphaOfLayer method sets the alpha value of a specific layer * \brief The setAlphaOfLayer method sets the alpha value of a specific layer
* \param idx - The index of the layer where the change should be applied * \param idx - The index of the layer where the change should be applied
* \param alpha - New alpha value of the layer * \param alpha - New alpha value of the layer
*/ */
void setLayerAlpha(int idx, int alpha); void setLayerAlpha(int idx, int alpha);
/*! /*!
* \brief The floodFill method fills a the active layer with a given color * \brief setPolygon is used for setting polygondata, it only works on RASTER images
* \param r - Red value of the color the layer should be filled with * \param idx - represents the number of the layer with should be transformed
* \param g - Green value of the color the layer should be filled with
* \param b - Blue value of the color the layer should be filled with
* \param a - Alpha value of the color the layer should be filled with
*/ */
void floodFill(int r, int g, int b, int a); void setPolygon(int idx);
/*! /*!
* \brief The movePositionActive method moves the active layer to certain position * \brief The movePositionActive method moves the active layer to certain position
* \param x - The x value the new center of the layer should be at * \param x - The x value the new center of the layer should be at
* \param y - The y value the new center of the layer should be at * \param y - The y value the new center of the layer should be at
*/ */
void movePositionActive(int x, int y); void movePositionActive(int x, int y);
/*! /*!
* \brief The moveActiveLayer moves the active layer to a specific position in the layer stack * \brief The moveActiveLayer moves the active layer to a specific position in the layer stack
* \param idx - The direction the layer should move * \param idx - The index of the new position the layer should be in
*/ */
void moveActiveLayer(int idx); void moveActiveLayer(int idx);
//change properties of colorPicker //change properties of colorPicker
/*! /*!
* \brief The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color * \brief The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color
*/ */
void colorPickerSetFirstColor(); void colorPickerSetFirstColor();
/*! /*!
* \brief The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color * \brief The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color
*/ */
void colorPickerSetSecondColor(); void colorPickerSetSecondColor();
/*! /*!
* \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color * \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color
*/ */
void colorPickerSwapColors(); void colorPickerSwapColors();
// Create tools // Create tools
void createPenTool(); void createPenTool();
void createPlainTool(); void createPlainTool();
void createLineTool(); void createLineTool();
void createRectangleTool(); void createRectangleTool();
void createCircleTool(); void createCircleTool();
void createPolygonTool(); void createPolygonTool();
void createFloodFillTool(); void createFloodFillTool();
/*! /*!
* \brief The getWidthOfActive gets the horizontal dimensions of the active layer * \brief The getWidthOfActive gets the horizontal dimensions of the active layer
* \return Returns the horizontal pixle count of the active layer * \return Returns the horizontal pixle count of the active layer
*/ */
int getWidthOfActive(); int getWidthOfActive();
/*! /*!
* \brief The getHeightOfActive gets the vertical dimensions of the active layer * \brief The getHeightOfActive gets the vertical dimensions of the active layer
* \return Returns the vertical pixle count of the active layer * \return Returns the vertical pixle count of the active layer
*/ */
int getHeightOfActive(); int getHeightOfActive();
IntelliImage::ImageType getTypeOfImageRealLayer(); IntelliImage::ImageType getTypeOfImageRealLayer();
std::vector<QPoint> getPolygonDataOfRealLayer(); std::vector<QPoint> getPolygonDataOfRealLayer();
int getNumberOfActiveLayer(); int getNumberOfActiveLayer();
IntelliImage* getImageOfActiveLayer(); IntelliImage* getImageOfActiveLayer();
IntelliToolsettings Toolsettings; /*!
IntelliColorPicker colorPicker; * \brief getImageDataOfActiveLayer used to get the currents active imageData (if there isn't any active layer it return a 10*10 white picture)
* \return return the image as an rgba32bit qImage
*/
QImage getImageDataOfActiveLayer();
IntelliToolsettings Toolsettings;
IntelliColorPicker colorPicker;
public slots: public slots:
// Events to handle // Events to handle
@@ -219,6 +223,8 @@ QImage* Canvas;
int maxWidth; int maxWidth;
int maxHeight; int maxHeight;
bool isSettingPolygon = false;
IntelliRenderSettings renderSettings; IntelliRenderSettings renderSettings;
IntelliTool* Tool; IntelliTool* Tool;
IntelliPhotoGui* DummyGui; IntelliPhotoGui* DummyGui;
@@ -230,8 +236,11 @@ void drawLayers(bool forSaving=false);
void resizeLayer(QImage*image_res, const QSize &newSize); void resizeLayer(QImage*image_res, const QSize &newSize);
// Helper for Tool // Helper for Tool
bool createTempTopLayer(int idx); bool createTempTopLayer(int idx);
//this function is needed to avoid errors in inputhandeling if a layer has changed
void updateTools();
}; };
#endif #endif

View File

@@ -25,7 +25,7 @@ void IntelliTool::onMouseRightReleased(int x, int y){
void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftPressed(int x, int y){
this->isDrawing=this->createToolLayer(); this->isDrawing=this->createToolLayer();
if(isDrawing){ if(isDrawing) {
Canvas->image->calculateVisiblity(); Canvas->image->calculateVisiblity();
} }
} }
@@ -36,6 +36,7 @@ void IntelliTool::onMouseLeftReleased(int x, int y){
this->mergeToolLayer(); this->mergeToolLayer();
this->deleteToolLayer(); this->deleteToolLayer();
activeLayer->image->calculateVisiblity(); activeLayer->image->calculateVisiblity();
} }
} }
@@ -49,7 +50,7 @@ void IntelliTool::onWheelScrolled(int value){
} }
bool IntelliTool::createToolLayer(){ bool IntelliTool::createToolLayer(){
if(Area->createTempTopLayer(Area->activeLayer)){ if(Area->createTempTopLayer(Area->activeLayer)) {
this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)]; this->activeLayer=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer)];
this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)]; this->Canvas=&Area->layerBundle[static_cast<unsigned long long>(Area->activeLayer+1)];
return true; return true;
@@ -80,11 +81,14 @@ void IntelliTool::mergeToolLayer(){
} }
} }
activeLayer->image->setImageData(updatedImage); activeLayer->image->setImageData(updatedImage);
if(Canvas->image->getPolygonData().size() > 0) {
activeLayer->image->setPolygon(Canvas->image->getPolygonData());
}
Area->DummyGui->UpdateGui(); Area->DummyGui->UpdateGui();
} }
void IntelliTool::deleteToolLayer(){ void IntelliTool::deleteToolLayer(){
Area->deleteLayer(Area->activeLayer+1); Area->deleteLayer(Area->activeLayer+1, true);
this->Canvas=nullptr; this->Canvas=nullptr;
} }

View File

@@ -56,7 +56,7 @@ void IntelliToolCircle::onMouseRightReleased(int x, int y){
void IntelliToolCircle::onMouseLeftPressed(int x, int y){ void IntelliToolCircle::onMouseLeftPressed(int x, int y){
IntelliTool::onMouseLeftPressed(x,y); IntelliTool::onMouseLeftPressed(x,y);
if(this->isDrawing){ if(this->isDrawing) {
this->centerPoint=QPoint(x,y); this->centerPoint=QPoint(x,y);
int radius = 1; int radius = 1;
drawCircle(radius); drawCircle(radius);

View File

@@ -4,11 +4,12 @@
#include <QInputDialog> #include <QInputDialog>
#include <QDebug> #include <QDebug>
IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon)
: IntelliTool(Area, colorPicker, Toolsettings){ : IntelliTool(Area, colorPicker, Toolsettings){
isPointNearStart = false; isPointNearStart = false;
drawingOfPolygon = false; drawingOfPolygon = false;
isInside = false; isInside = false;
this->isSettingPolygon = isSettingPolygon;
this->ActiveType = Tooltype::POLYGON; this->ActiveType = Tooltype::POLYGON;
} }
@@ -19,11 +20,19 @@ IntelliToolPolygon::~IntelliToolPolygon(){
} }
void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) { if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
if(Area->getPolygonDataOfRealLayer().size()>2) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer());
QPoint Point(x,y); QPoint Point(x,y);
isInside = IntelliTriangulation::isInPolygon(Triangles,Point); isInside = IntelliTriangulation::isInPolygon(Triangles,Point);
} }
else{
isInside = true;
}
if(isSettingPolygon) {
isInside = true;
}
}
else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) { else if(!drawingOfPolygon && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x >= 0 && y >= 0 && x<Area->getWidthOfActive() && y<Area->getHeightOfActive()) {
isInside = true; isInside = true;
} }
@@ -36,14 +45,18 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
QPointList.push_back(drawingPoint); QPointList.push_back(drawingPoint);
this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
if(!isSettingPolygon) {
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
}
else if(drawingOfPolygon && isNearStart(x,y,QPointList.front())) { else if(drawingOfPolygon && isNearStart(x,y,QPointList.front())) {
if(QPointList.size() > 2) { if(QPointList.size() > 2) {
isPointNearStart = true; isPointNearStart = true;
this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth());
if(!isSettingPolygon) {
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
}
else{ else{
isInside = false; isInside = false;
drawingOfPolygon = false; drawingOfPolygon = false;
@@ -57,8 +70,10 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){
QPoint drawingPoint(x,y); QPoint drawingPoint(x,y);
QPointList.push_back(drawingPoint); QPointList.push_back(drawingPoint);
this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
if(!isSettingPolygon) {
this->Canvas->image->calculateVisiblity(); this->Canvas->image->calculateVisiblity();
} }
}
} }
void IntelliToolPolygon::onMouseRightPressed(int x, int y){ void IntelliToolPolygon::onMouseRightPressed(int x, int y){
@@ -72,7 +87,8 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
if(isPointNearStart) { if(isPointNearStart) {
isInside = false; isInside = false;
isPointNearStart = false; isPointNearStart = false;
drawingOfPolygon = false; isDrawing = false;
if(!isSettingPolygon) {
std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList); std::vector<Triangle> Triangles = IntelliTriangulation::calculateTriangles(QPointList);
QPoint Point; QPoint Point;
QColor colorTwo(colorPicker->getSecondColor()); QColor colorTwo(colorPicker->getSecondColor());
@@ -89,8 +105,14 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){
int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size())); int next = static_cast<int>((i+static_cast<int>(1))%static_cast<int>(QPointList.size()));
this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->drawLine(QPointList[static_cast<unsigned long long>(i)], QPointList[static_cast<unsigned long long>(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth());
} }
QPointList.clear();
}
else{
Canvas->image->setPolygon(QPointList);
Canvas->image->setImageData(Area->getImageDataOfActiveLayer());
}
IntelliTool::onMouseLeftReleased(x,y); IntelliTool::onMouseLeftReleased(x,y);
QPointList.clear();
} }
} }

View File

@@ -34,6 +34,11 @@ bool drawingOfPolygon;
*/ */
bool isInside; bool isInside;
/*!
* \brief isSettingPolygon is the flag for calling the setPolygon method.
*/
bool isSettingPolygon;
/*! /*!
* \brief PointIsNearStart true, when last click near startpoint, else false. * \brief PointIsNearStart true, when last click near startpoint, else false.
*/ */
@@ -48,8 +53,9 @@ public:
* \brief A constructor setting the general paintingArea and colorPicker. * \brief A constructor setting the general paintingArea and colorPicker.
* \param Area - The general paintingArea used by the project. * \param Area - The general paintingArea used by the project.
* \param colorPicker - The general colorPicker used by the project. * \param colorPicker - The general colorPicker used by the project.
* \param isSettingPolygon - The flag for the set polygon method, standart is false
*/ */
IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon = false);
/*! /*!
* \brief A Destructor. * \brief A Destructor.
*/ */
@@ -96,7 +102,6 @@ virtual void onWheelScrolled(int value) override;
*/ */
virtual void onMouseMoved(int x, int y) override; virtual void onMouseMoved(int x, int y) override;
}; };
#endif // INTELLITOOLPOLYGON_H #endif // INTELLITOOLPOLYGON_H