From 6fec7c26bf8b3c8bad3b1aeddefe2ce3d68b15d2 Mon Sep 17 00:00:00 2001 From: Conrad Date: Mon, 13 Jan 2020 19:59:30 +0100 Subject: [PATCH 1/6] Uncrustified Files --- src/GUI/IntelliPhotoGui.cpp | 344 ++++++++++---------- src/Image/IntelliImage.cpp | 136 ++++---- src/Image/IntelliRasterImage.cpp | 18 +- src/Image/IntelliShapedImage.cpp | 36 +- src/IntelliHelper/IntelliRenderSettings.cpp | 4 +- src/Layer/PaintingArea.cpp | 62 ++-- src/Layer/PaintingArea.h | 250 +++++++------- src/Tool/IntelliTool.cpp | 32 +- src/Tool/IntelliToolCircle.cpp | 14 +- src/Tool/IntelliToolLine.cpp | 2 +- 10 files changed, 449 insertions(+), 449 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 1c4e009..4e506da 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -46,10 +46,10 @@ void IntelliPhotoGui::slotOpen(){ // If we have a file name load the image and place // it in the paintingArea - if (!fileName.isEmpty()){ + if (!fileName.isEmpty()) { paintingArea->open(fileName); - UpdateGui(); - } + UpdateGui(); + } } } @@ -73,19 +73,19 @@ void IntelliPhotoGui::slotCreateNewLayer(){ // "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); + QInputDialog Input; + Input.setPalette(Palette); - int width = Input.getInt(this, tr("New Layer"), - tr("Width:"), - 200,1, 500, 1, &ok1); + 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); + if (ok1&&ok2) { + paintingArea->addLayer(width,height,0,0); UpdateGui(); } } @@ -100,10 +100,10 @@ void IntelliPhotoGui::slotDeleteLayer(){ // Define the standard Value, min, max, step and ok button int layerNumber = QInputDialog::getInt(this, tr("delete Layer"), tr("Number:"), - paintingArea->getNumberOfActiveLayer()+1,1, 501, 1, &ok); + paintingArea->getNumberOfActiveLayer()+1,1, 501, 1, &ok); // Create New Layer if (ok) { - paintingArea->deleteLayer(layerNumber-1); + paintingArea->deleteLayer(layerNumber-1); UpdateGui(); } } @@ -117,14 +117,14 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ // 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); + 1,1,500,1, &ok1); // "New Alpha" is the title of the window int alpha = QInputDialog::getInt(this, tr("New Alpha"), tr("Alpha:"), 255,0, 255, 1, &ok2); if (ok1&&ok2) { - paintingArea->setLayerAlpha(layer-1,alpha); + paintingArea->setLayerAlpha(layer-1,alpha); UpdateGui(); } } @@ -194,25 +194,25 @@ void IntelliPhotoGui::slotSetActiveLayer(){ // "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) + // 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->setLayerActive(layer-1); + paintingArea->setLayerActive(layer-1); UpdateGui(); } } void IntelliPhotoGui::slotUpdateRenderSettingsOn(){ - paintingArea->setRenderSettings(true); - UpdateGui(); + paintingArea->setRenderSettings(true); + UpdateGui(); } void IntelliPhotoGui::slotUpdateRenderSettingsOff(){ - paintingArea->setRenderSettings(false); - UpdateGui(); + paintingArea->setRenderSettings(false); + UpdateGui(); } void IntelliPhotoGui::slotSetFirstColor(){ @@ -269,7 +269,7 @@ void IntelliPhotoGui::slotCreateFloodFillTool(){ void IntelliPhotoGui::slotAboutDialog(){ // Window title and text to display QMessageBox::about(this, tr("About Painting"), - tr("

IntelliPhoto - A Pretty basic editor.


Developed by Team 7.")); + tr("

IntelliPhoto - A Pretty basic editor.


Developed by Team 7.")); } void IntelliPhotoGui::slotEnterPressed(){ @@ -296,13 +296,13 @@ void IntelliPhotoGui::slotResetTools(){ } void IntelliPhotoGui::slotSetWidth(){ - paintingArea->Toolsettings.setLineWidth(); - EditLineWidth->setText(QString("%1").arg(paintingArea->Toolsettings.getLineWidth())); + paintingArea->Toolsettings.setLineWidth(); + EditLineWidth->setText(QString("%1").arg(paintingArea->Toolsettings.getLineWidth())); } void IntelliPhotoGui::slotSetInnerAlpha(){ - paintingArea->Toolsettings.setInnerAlpha(); - EditLineInnerAlpha->setText(QString("%1").arg(paintingArea->Toolsettings.getInnerAlpha())); + paintingArea->Toolsettings.setInnerAlpha(); + EditLineInnerAlpha->setText(QString("%1").arg(paintingArea->Toolsettings.getInnerAlpha())); } // Define menu actions that call functions @@ -332,7 +332,7 @@ void IntelliPhotoGui::createActions(){ connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave())); // Attach each PNG in save Menu actionSaveAs.append(pngSaveAction); - pngSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)); + pngSaveAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)); // Create exit action and tie to IntelliPhotoGui::close() actionExit = new QAction(tr("&Exit"), this); @@ -350,15 +350,15 @@ void IntelliPhotoGui::createActions(){ // Delete New Layer action and tie to IntelliPhotoGui::deleteLayer() actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); - actionDeleteLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_D)); + actionDeleteLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_D)); connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer())); actionSetActiveLayer = new QAction(tr("&set Active"), this); - actionSetActiveLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A)); + actionSetActiveLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A)); connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer())); - actionSetActiveAlpha = new QAction(tr("&set Alpha"), this); - actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A)); + actionSetActiveAlpha = new QAction(tr("&set Alpha"), this); + actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A)); connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha())); actionMovePositionUp = new QAction(tr("&move Up"), this); @@ -385,76 +385,76 @@ void IntelliPhotoGui::createActions(){ actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down)); connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown())); - //Create Update RenderSettings Actions here - actionUpdateRenderSettingsOn = new QAction(tr("&On"), this); - actionUpdateRenderSettingsOn->setShortcut(QKeySequence(Qt::ALT +Qt::SHIFT + +Qt::Key_A)); - connect(actionUpdateRenderSettingsOn, SIGNAL(triggered()),this, SLOT(slotUpdateRenderSettingsOn())); + //Create Update RenderSettings Actions here + actionUpdateRenderSettingsOn = new QAction(tr("&On"), this); + actionUpdateRenderSettingsOn->setShortcut(QKeySequence(Qt::ALT +Qt::SHIFT + +Qt::Key_A)); + connect(actionUpdateRenderSettingsOn, SIGNAL(triggered()),this, SLOT(slotUpdateRenderSettingsOn())); - actionUpdateRenderSettingsOff = new QAction(tr("&Off"), this); - actionUpdateRenderSettingsOff->setShortcut(QKeySequence(Qt::ALT +Qt::SHIFT + +Qt::Key_D)); - connect(actionUpdateRenderSettingsOff, SIGNAL(triggered()),this, SLOT(slotUpdateRenderSettingsOff())); + actionUpdateRenderSettingsOff = new QAction(tr("&Off"), this); + actionUpdateRenderSettingsOff->setShortcut(QKeySequence(Qt::ALT +Qt::SHIFT + +Qt::Key_D)); + connect(actionUpdateRenderSettingsOff, SIGNAL(triggered()),this, SLOT(slotUpdateRenderSettingsOff())); //Create Color Actions here actionColorPickerFirstColor = new QAction(tr("&Main"), this); - actionColorPickerFirstColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_N)); + actionColorPickerFirstColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_N)); connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor())); connect(FirstColorButton, SIGNAL(clicked()), this, SLOT(slotSetFirstColor())); actionColorPickerSecondColor = new QAction(tr("&Secondary"), this); - actionColorPickerSecondColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_M)); + actionColorPickerSecondColor->setShortcut(QKeySequence(Qt::ALT + Qt::Key_M)); connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetSecondColor())); connect(SecondColorButton, SIGNAL(clicked()), this, SLOT(slotSetSecondColor())); actionColorSwap = new QAction(tr("&Switch"), this); - actionColorSwap->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S)); + actionColorSwap->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_S)); connect(actionColorSwap, SIGNAL(triggered()), this, SLOT(slotSwapColor())); connect(SwitchColorButton, SIGNAL(clicked()), this, SLOT(slotSwapColor())); //Create Tool actions down here actionCreatePlainTool = new QAction(tr("&Plain"), this); - actionCreatePlainTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_P)); + actionCreatePlainTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_P)); connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool())); actionCreatePenTool = new QAction(tr("&Pen"),this); - actionCreatePenTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_S)); + actionCreatePenTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_S)); connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool())); actionCreateLineTool = new QAction(tr("&Line"), this); - actionCreateLineTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_L)); + actionCreateLineTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_L)); connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool())); actionCreateCircleTool = new QAction(tr("&Circle"), this); - actionCreateCircleTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_C)); + actionCreateCircleTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_C)); connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool())); actionCreateRectangleTool = new QAction(tr("&Rectangle"), this); - actionCreateRectangleTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_R)); + actionCreateRectangleTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_R)); connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool())); actionCreatePolygonTool = new QAction(tr("&Polygon"), this); - actionCreatePolygonTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_V)); + actionCreatePolygonTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_V)); connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool())); actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this); - actionCreateFloodFillTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_F)); + actionCreateFloodFillTool->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::SHIFT +Qt::Key_F)); connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool())); // Create about action and tie to IntelliPhotoGui::about() actionAboutDialog = new QAction(tr("&About"), this); - actionAboutDialog->setShortcut(Qt::Key_F2); + actionAboutDialog->setShortcut(Qt::Key_F2); connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog())); // Create about Qt action and tie to IntelliPhotoGui::aboutQt() actionAboutQtDialog = new QAction(tr("About &Qt"), this); - actionAboutQtDialog->setShortcut(Qt::Key_F3); + actionAboutQtDialog->setShortcut(Qt::Key_F3); connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(EditLineWidth, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed())); @@ -481,13 +481,13 @@ void IntelliPhotoGui::createActions(){ connect(RectangleButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); connect(RectangleButton, SIGNAL(clicked()), this, SLOT(slotCreateRectangleTool())); - actionSetWidth = new QAction(tr("&Set Width"),this); - actionSetWidth->setShortcut(QKeySequence(Qt::ALT + Qt::Key_W)); - connect(actionSetWidth, SIGNAL(triggered()), this, SLOT(slotSetWidth())); + actionSetWidth = new QAction(tr("&Set Width"),this); + actionSetWidth->setShortcut(QKeySequence(Qt::ALT + Qt::Key_W)); + connect(actionSetWidth, SIGNAL(triggered()), this, SLOT(slotSetWidth())); - actionSetInnerAlpha = new QAction(tr("&Set Inner Alpha"),this); - actionSetInnerAlpha->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A)); - connect(actionSetInnerAlpha, SIGNAL(triggered()), this, SLOT(slotSetInnerAlpha())); + actionSetInnerAlpha = new QAction(tr("&Set Inner Alpha"),this); + actionSetInnerAlpha->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A)); + connect(actionSetInnerAlpha, SIGNAL(triggered()), this, SLOT(slotSetInnerAlpha())); } // Create the menubar @@ -505,61 +505,61 @@ void IntelliPhotoGui::createMenus(){ fileMenu->addSeparator(); fileMenu->addAction(actionExit); - //Attach all actions to Render Settings - renderMenu = new QMenu(tr("&Fast Renderer"), this); - renderMenu->addAction(actionUpdateRenderSettingsOn); - renderMenu->addAction(actionUpdateRenderSettingsOff); + //Attach all actions to Render Settings + renderMenu = new QMenu(tr("&Fast Renderer"), this); + renderMenu->addAction(actionUpdateRenderSettingsOn); + renderMenu->addAction(actionUpdateRenderSettingsOff); - // Attach all actions to Layer - layerMenu = new QMenu(tr("&Layer"), this); - layerMenu->addAction(actionCreateNewLayer); - layerMenu->addSeparator(); - layerMenu->addAction(actionSetActiveAlpha); - layerMenu->addAction(actionSetActiveLayer); - layerMenu->addSeparator(); - layerMenu->addAction(actionMovePositionUp); - layerMenu->addAction(actionMovePositionDown); - layerMenu->addAction(actionMovePositionLeft); - layerMenu->addAction(actionMovePositionRight); - layerMenu->addAction(actionMoveLayerUp); - layerMenu->addAction(actionMoveLayerDown); - layerMenu->addSeparator(); - layerMenu->addAction(actionDeleteLayer); + // Attach all actions to Layer + layerMenu = new QMenu(tr("&Layer"), this); + layerMenu->addAction(actionCreateNewLayer); + layerMenu->addSeparator(); + layerMenu->addAction(actionSetActiveAlpha); + layerMenu->addAction(actionSetActiveLayer); + layerMenu->addSeparator(); + layerMenu->addAction(actionMovePositionUp); + layerMenu->addAction(actionMovePositionDown); + layerMenu->addAction(actionMovePositionLeft); + layerMenu->addAction(actionMovePositionRight); + layerMenu->addAction(actionMoveLayerUp); + layerMenu->addAction(actionMoveLayerDown); + layerMenu->addSeparator(); + layerMenu->addAction(actionDeleteLayer); - //Attach all Color Options - colorMenu = new QMenu(tr("&Color"), this); - colorMenu->addAction(actionColorPickerFirstColor); - colorMenu->addAction(actionColorPickerSecondColor); - colorMenu->addAction(actionColorSwap); + //Attach all Color Options + colorMenu = new QMenu(tr("&Color"), this); + colorMenu->addAction(actionColorPickerFirstColor); + colorMenu->addAction(actionColorPickerSecondColor); + colorMenu->addAction(actionColorSwap); - //Attach all Tool Creation Actions - toolCreationMenu = new QMenu(tr("&Drawingtools"), this); - toolCreationMenu->addAction(actionCreateCircleTool); - toolCreationMenu->addAction(actionCreateFloodFillTool); - toolCreationMenu->addAction(actionCreateLineTool); - toolCreationMenu->addAction(actionCreatePenTool); - toolCreationMenu->addAction(actionCreatePlainTool); - toolCreationMenu->addAction(actionCreatePolygonTool); - toolCreationMenu->addAction(actionCreateRectangleTool); + //Attach all Tool Creation Actions + toolCreationMenu = new QMenu(tr("&Drawingtools"), this); + toolCreationMenu->addAction(actionCreateCircleTool); + toolCreationMenu->addAction(actionCreateFloodFillTool); + toolCreationMenu->addAction(actionCreateLineTool); + toolCreationMenu->addAction(actionCreatePenTool); + toolCreationMenu->addAction(actionCreatePlainTool); + toolCreationMenu->addAction(actionCreatePolygonTool); + toolCreationMenu->addAction(actionCreateRectangleTool); - //Attach all Tool Setting Actions - toolSettingsMenu = new QMenu(tr("&Toolsettings"), this); - toolSettingsMenu->addAction(actionSetWidth); - toolSettingsMenu->addAction(actionSetInnerAlpha); + //Attach all Tool Setting Actions + toolSettingsMenu = new QMenu(tr("&Toolsettings"), this); + toolSettingsMenu->addAction(actionSetWidth); + toolSettingsMenu->addAction(actionSetInnerAlpha); - //Attach all Tool Options - toolMenu = new QMenu(tr("&Tools"), this); - toolMenu->addMenu(toolCreationMenu); - toolMenu->addMenu(toolSettingsMenu); - toolMenu->addSeparator(); - toolMenu->addMenu(colorMenu); + //Attach all Tool Options + toolMenu = new QMenu(tr("&Tools"), this); + toolMenu->addMenu(toolCreationMenu); + toolMenu->addMenu(toolSettingsMenu); + toolMenu->addSeparator(); + toolMenu->addMenu(colorMenu); // Attach all actions to Options optionMenu = new QMenu(tr("&Options"), this); - optionMenu->addMenu(layerMenu); - optionMenu->addMenu(toolMenu); - optionMenu->addSeparator(); - optionMenu->addMenu(renderMenu); + optionMenu->addMenu(layerMenu); + optionMenu->addMenu(toolMenu); + optionMenu->addSeparator(); + optionMenu->addMenu(renderMenu); // Attach all actions to Help helpMenu = new QMenu(tr("&Help"), this); @@ -583,54 +583,54 @@ void IntelliPhotoGui::createGui(){ // create Gui elements paintingArea = new PaintingArea(); - paintingArea->DummyGui = this; + paintingArea->DummyGui = this; - preview = QPixmap(":/Icons/Buttons/icons/circle-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/circle-tool.svg"); CircleButton = new QPushButton(); CircleButton->setFixedSize(Buttonsize); - CircleButton->setIcon(preview); + CircleButton->setIcon(preview); CircleButton->setIconSize(Buttonsize); CircleButton->setCheckable(true); - preview = QPixmap(":/Icons/Buttons/icons/flood-fill-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/flood-fill-tool.svg"); FloodFillButton = new QPushButton(); FloodFillButton->setFixedSize(Buttonsize); - FloodFillButton->setIcon(preview); + FloodFillButton->setIcon(preview); FloodFillButton->setIconSize(Buttonsize); FloodFillButton->setCheckable(true); - preview = QPixmap(":/Icons/Buttons/icons/line-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/line-tool.svg"); LineButton = new QPushButton(); LineButton->setFixedSize(Buttonsize); - LineButton->setIcon(preview); + LineButton->setIcon(preview); LineButton->setIconSize(Buttonsize); LineButton->setCheckable(true); - preview = QPixmap(":/Icons/Buttons/icons/pen-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/pen-tool.svg"); PenButton = new QPushButton(); PenButton->setFixedSize(Buttonsize); - PenButton->setIcon(preview); + PenButton->setIcon(preview); PenButton->setIconSize(Buttonsize); PenButton->setCheckable(true); - preview = QPixmap(":/Icons/Buttons/icons/plain-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/plain-tool.svg"); PlainButton = new QPushButton(); PlainButton->setFixedSize(Buttonsize); - PlainButton->setIcon(preview); + PlainButton->setIcon(preview); PlainButton->setIconSize(Buttonsize); PlainButton->setCheckable(true); - preview = QPixmap(":/Icons/Buttons/icons/polygon-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/polygon-tool.svg"); PolygonButton = new QPushButton(); PolygonButton->setFixedSize(Buttonsize); - PolygonButton->setIcon(preview); + PolygonButton->setIcon(preview); PolygonButton->setIconSize(Buttonsize); PolygonButton->setCheckable(true); - preview = QPixmap(":/Icons/Buttons/icons/rectangle-tool.svg"); + preview = QPixmap(":/Icons/Buttons/icons/rectangle-tool.svg"); RectangleButton = new QPushButton(); RectangleButton->setFixedSize(Buttonsize); - RectangleButton->setIcon(preview); + RectangleButton->setIcon(preview); RectangleButton->setIconSize(Buttonsize); RectangleButton->setCheckable(true); @@ -664,29 +664,29 @@ void IntelliPhotoGui::createGui(){ SecondColorButton = new QPushButton(); SecondColorButton->setFixedSize(Buttonsize/2); - preview = QPixmap(":/Icons/Buttons/icons/Wechselpfeile.png"); + preview = QPixmap(":/Icons/Buttons/icons/Wechselpfeile.png"); SwitchColorButton = new QPushButton(); SwitchColorButton->setFixedSize(Buttonsize.width(),Buttonsize.height()/2); - SwitchColorButton->setIcon(preview); + SwitchColorButton->setIcon(preview); SwitchColorButton->setIconSize(QSize(Buttonsize.width(),Buttonsize.height()/2)); ActiveLayerLine = new QLabel(); - QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1); + QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1); ActiveLayerLine->setText(string); ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3); - IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); - if(activePicture){ - preview = preview.fromImage(activePicture->getImageData()); - }else{ - QImage tmp(1,1,QImage::Format_ARGB32); - tmp.fill(Qt::transparent); - preview = preview.fromImage(tmp); - } + IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); + if(activePicture) { + preview = preview.fromImage(activePicture->getImageData()); + }else{ + QImage tmp(1,1,QImage::Format_ARGB32); + tmp.fill(Qt::transparent); + preview = preview.fromImage(tmp); + } - ActiveLayerImageLine = new QLabel(); - ActiveLayerImageLine->setFixedSize(Buttonsize); - ActiveLayerImageLine->setPixmap(preview.scaled(Buttonsize)); + ActiveLayerImageLine = new QLabel(); + ActiveLayerImageLine->setFixedSize(Buttonsize); + ActiveLayerImageLine->setPixmap(preview.scaled(Buttonsize)); // set gui elements @@ -706,40 +706,40 @@ void IntelliPhotoGui::createGui(){ mainLayout->addWidget(SecondColorButton,12,3,1,1); mainLayout->addWidget(SwitchColorButton,13,2,1,2); mainLayout->addWidget(ActiveLayerLine,14,2,1,2); - mainLayout->addWidget(ActiveLayerImageLine,15,2,1,2); + mainLayout->addWidget(ActiveLayerImageLine,15,2,1,2); } void IntelliPhotoGui::setIntelliStyle(){ // Set the title setWindowTitle("IntelliPhoto Prototype"); - Palette.setBrush(QPalette::HighlightedText, QColor(200, 10, 10)); - Palette.setBrush(QPalette::Highlight, QColor(100, 5, 5)); - Palette.setBrush(QPalette::ButtonText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::Button, QColor(64, 64, 64)); - Palette.setBrush(QPalette::Window, QColor(0, 0, 0)); - Palette.setBrush(QPalette::WindowText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::PlaceholderText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255)); - Palette.setBrush(QPalette::Text, QColor(255, 255, 255)); + Palette.setBrush(QPalette::HighlightedText, QColor(200, 10, 10)); + Palette.setBrush(QPalette::Highlight, QColor(100, 5, 5)); + Palette.setBrush(QPalette::ButtonText, QColor(255, 255, 255)); + Palette.setBrush(QPalette::Button, QColor(64, 64, 64)); + Palette.setBrush(QPalette::Window, QColor(0, 0, 0)); + Palette.setBrush(QPalette::WindowText, QColor(255, 255, 255)); + Palette.setBrush(QPalette::PlaceholderText, QColor(255, 255, 255)); + Palette.setBrush(QPalette::ToolTipText, QColor(255, 255, 255)); + Palette.setBrush(QPalette::Text, QColor(255, 255, 255)); // Set style sheet - this->setStyleSheet("background-color:rgb(64,64,64)"); - this->menuBar()->setPalette(Palette); - this->fileMenu->setPalette(Palette); - this->saveAsMenu->setPalette(Palette); - this->optionMenu->setPalette(Palette); - this->helpMenu->setPalette(Palette); - this->renderMenu->setPalette(Palette); - this->toolMenu->setPalette(Palette); - this->layerMenu->setPalette(Palette); - this->colorMenu->setPalette(Palette); - this->toolCreationMenu->setPalette(Palette); - this->toolSettingsMenu->setPalette(Palette); + this->setStyleSheet("background-color:rgb(64,64,64)"); + this->menuBar()->setPalette(Palette); + this->fileMenu->setPalette(Palette); + this->saveAsMenu->setPalette(Palette); + this->optionMenu->setPalette(Palette); + this->helpMenu->setPalette(Palette); + this->renderMenu->setPalette(Palette); + this->toolMenu->setPalette(Palette); + this->layerMenu->setPalette(Palette); + this->colorMenu->setPalette(Palette); + this->toolCreationMenu->setPalette(Palette); + this->toolSettingsMenu->setPalette(Palette); - this->WidthLine->setPalette(Palette); - this->EditLineWidth->setPalette(Palette); - this->innerAlphaLine->setPalette(Palette); - this->EditLineInnerAlpha->setPalette(Palette); - this->ActiveLayerLine->setPalette(Palette); + this->WidthLine->setPalette(Palette); + this->EditLineWidth->setPalette(Palette); + this->innerAlphaLine->setPalette(Palette); + this->EditLineInnerAlpha->setPalette(Palette); + this->ActiveLayerLine->setPalette(Palette); QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); FirstColorButton->setStyleSheet(string); @@ -800,18 +800,18 @@ void IntelliPhotoGui::setDefaultToolValue(){ } void IntelliPhotoGui::UpdateGui(){ - QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1); + QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer() + 1); ActiveLayerLine->setText(string); - IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); - if(activePicture){ - preview = preview.fromImage(activePicture->getImageData()); - }else{ - QImage tmp(1,1,QImage::Format_ARGB32); - tmp.fill(Qt::transparent); - preview = preview.fromImage(tmp); - } - ActiveLayerImageLine->setPixmap(preview.scaled(Buttonsize)); + IntelliImage* activePicture = paintingArea->getImageOfActiveLayer(); + if(activePicture) { + preview = preview.fromImage(activePicture->getImageData()); + }else{ + QImage tmp(1,1,QImage::Format_ARGB32); + tmp.fill(Qt::transparent); + preview = preview.fromImage(tmp); + } + ActiveLayerImageLine->setPixmap(preview.scaled(Buttonsize)); string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); FirstColorButton->setStyleSheet(string); diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 0fa97b2..aa12450 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -3,15 +3,15 @@ #include IntelliImage::IntelliImage(int width, int height, bool fastRendererOn) - : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ - if(fastRendererOn){ - imageData = imageData.convertToFormat(QImage::Format_ARGB32); - } - imageData.fill(QColor(255,255,255,255)); - if(fastRendererOn){ - imageData = imageData.convertToFormat(QImage::Format_Indexed8); - } - this->fastRenderering = fastRendererOn; + : imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){ + if(fastRendererOn) { + imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + imageData.fill(QColor(255,255,255,255)); + if(fastRendererOn) { + imageData = imageData.convertToFormat(QImage::Format_Indexed8); + } + this->fastRenderering = fastRendererOn; } @@ -30,7 +30,7 @@ bool IntelliImage::loadImage(const QString &filePath){ // scaled Image to size of Layer loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); - imageData = loadedImage.convertToFormat(fastRenderering ? QImage::Format_Indexed8 : QImage::Format_ARGB32); + imageData = loadedImage.convertToFormat(fastRenderering ? QImage::Format_Indexed8 : QImage::Format_ARGB32); return true; } @@ -46,19 +46,19 @@ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){ // Draw the image QPainter painter(&newImage); painter.drawImage(QPoint(0, 0), *image); - if(fastRenderering){ - *image = newImage.convertToFormat(QImage::Format_Indexed8); - } - else{ - *image = newImage; - } + if(fastRenderering) { + *image = newImage.convertToFormat(QImage::Format_Indexed8); + } + else{ + *image = newImage; + } } void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); - } - // Used to draw on the widget + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + // Used to draw on the widget QPainter painter(&imageData); // Set the current settings for the pen @@ -66,32 +66,32 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); - } + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); - } - // Used to draw on the widget + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + // 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); - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); - } + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); - } - // Used to draw on the widget + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + // Used to draw on the widget QPainter painter(&imageData); // Set the current settings for the pen @@ -99,53 +99,53 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co // Draw a line from the last registered point to the current painter.drawLine(p1, p2); - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); - } + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPlain(const QColor& color){ - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); - } - imageData.fill(color); - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); - } + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } + imageData.fill(color); + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } QColor IntelliImage::getPixelColor(QPoint& point){ - if(fastRenderering){ - QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32); - return copy.pixelColor(point); - } - return imageData.pixelColor(point); + if(fastRenderering) { + QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32); + return copy.pixelColor(point); + } + return imageData.pixelColor(point); } QImage IntelliImage::getImageData(){ - QImage copy = imageData; - if(fastRenderering){ - copy = copy.convertToFormat(QImage::Format_ARGB32); - } - return copy; + QImage copy = imageData; + if(fastRenderering) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } + return copy; } void IntelliImage::setImageData(const QImage& newData){ - imageData = newData; - if(fastRenderering){ - this->imageData = imageData.convertToFormat(QImage::Format_Indexed8); - } - else { - this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); - } + imageData = newData; + if(fastRenderering) { + this->imageData = imageData.convertToFormat(QImage::Format_Indexed8); + } + else { + this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } } void IntelliImage::updateRendererSetting(bool fastRendererOn){ - this->fastRenderering = fastRendererOn; - if(fastRenderering){ - this->imageData = imageData.convertToFormat(QImage::Format_Indexed8); - } - else { - this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); - } + this->fastRenderering = fastRendererOn; + if(fastRenderering) { + this->imageData = imageData.convertToFormat(QImage::Format_Indexed8); + } + else { + this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } } diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index 8872cff..b055f3f 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -4,9 +4,9 @@ #include IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) - : IntelliImage(width, height, fastRendererOn){ - TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; - this->fastRenderering = fastRendererOn; + : IntelliImage(width, height, fastRendererOn){ + TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; + this->fastRenderering = fastRendererOn; } IntelliRasterImage::~IntelliRasterImage(){ @@ -30,9 +30,9 @@ QImage IntelliRasterImage::getDisplayable(int alpha){ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ QImage copy = imageData; - if(fastRenderering){ - copy = copy.convertToFormat(QImage::Format_ARGB32); - } + if(fastRenderering) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } for(int y = 0; y IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) - : IntelliRasterImage(width, height, fastRendererOn){ - TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; - this->fastRenderering = fastRendererOn; + : IntelliRasterImage(width, height, fastRendererOn){ + TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; + this->fastRenderering = fastRendererOn; } IntelliShapedImage::~IntelliShapedImage(){ @@ -27,9 +27,9 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){ } void IntelliShapedImage::calculateVisiblity(){ - if(fastRenderering){ - this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); - } + if(fastRenderering) { + this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } if(polygonData.size()<=2) { QColor clr; @@ -40,9 +40,9 @@ void IntelliShapedImage::calculateVisiblity(){ imageData.setPixelColor(x,y,clr); } } - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); - } + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } return; } QColor clr; @@ -59,16 +59,16 @@ void IntelliShapedImage::calculateVisiblity(){ imageData.setPixelColor(x,y,clr); } } - if(fastRenderering){ - this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); - } + if(fastRenderering) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ QImage copy = imageData; - if(fastRenderering){ - copy = copy.convertToFormat(QImage::Format_ARGB32); - } + if(fastRenderering) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } for(int y = 0; yfastRenderering = Updatedsetting; + this->fastRenderering = Updatedsetting; } bool IntelliRenderSettings::isFastRenderering(){ - return fastRenderering; + return fastRenderering; } diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 779c2bb..7b93abc 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -43,12 +43,12 @@ PaintingArea::~PaintingArea(){ } void PaintingArea::setRenderSettings(bool isFastRenderingOn){ - if(isFastRenderingOn != renderSettings.isFastRenderering()){ - renderSettings.setFastRendering(isFastRenderingOn); - for(auto& layer : layerBundle){ - layer.image->updateRendererSetting(isFastRenderingOn); - } - } + if(isFastRenderingOn != renderSettings.isFastRenderering()) { + renderSettings.setFastRendering(isFastRenderingOn); + for(auto& layer : layerBundle) { + layer.image->updateRendererSetting(isFastRenderingOn); + } + } } void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ @@ -68,10 +68,10 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff newLayer.height = height; newLayer.widthOffset = widthOffset; newLayer.heightOffset = heightOffset; - if(type==IntelliImage::ImageType::RASTERIMAGE) { - newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering()); - }else if(type==IntelliImage::ImageType::SHAPEDIMAGE) { - newLayer.image = new IntelliShapedImage(width, height, renderSettings.isFastRenderering()); + if(type==IntelliImage::ImageType::RASTERIMAGE) { + newLayer.image = new IntelliRasterImage(width,height,renderSettings.isFastRenderering()); + }else if(type==IntelliImage::ImageType::SHAPEDIMAGE) { + newLayer.image = new IntelliShapedImage(width, height, renderSettings.isFastRenderering()); } newLayer.alpha = 255; this->layerBundle.push_back(newLayer); @@ -83,12 +83,12 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff void PaintingArea::deleteLayer(int idx){ if(idx(layerBundle.size())) { this->layerBundle.erase(layerBundle.begin()+idx); - if(activeLayer>=idx) { + if(activeLayer>=idx) { activeLayer--; } - if(activeLayer < 0 && layerBundle.size()){ - activeLayer=0; - } + if(activeLayer < 0 && layerBundle.size()) { + activeLayer=0; + } } } @@ -265,9 +265,9 @@ std::vector PaintingArea::getPolygonDataOfRealLayer(){ // left button and if so store the current position // Set that we are currently drawing void PaintingArea::mousePressEvent(QMouseEvent*event){ - if(this->activeLayer < 0){ - return; - } + if(this->activeLayer < 0) { + return; + } if(Tool == nullptr) return; int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; @@ -284,9 +284,9 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){ // we call the drawline function which draws a line // from the last position to the current void PaintingArea::mouseMoveEvent(QMouseEvent*event){ - if(this->activeLayer < 0){ - return; - } + if(this->activeLayer < 0) { + return; + } if(Tool == nullptr) return; int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; @@ -297,9 +297,9 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){ // If the button is released we set variables to stop drawing void PaintingArea::mouseReleaseEvent(QMouseEvent*event){ - if(this->activeLayer < 0) - return; - if(Tool == nullptr) + if(this->activeLayer < 0) + return; + if(Tool == nullptr) return; int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; @@ -312,9 +312,9 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){ } void PaintingArea::wheelEvent(QWheelEvent*event){ - if(this->activeLayer < 0) - return; - if(this->Tool != nullptr) { + if(this->activeLayer < 0) + return; + if(this->Tool != nullptr) { QPoint numDegrees = event->angleDelta() / 8; if(!numDegrees.isNull()) { QPoint numSteps = numDegrees / 15; @@ -405,9 +405,9 @@ bool PaintingArea::createTempTopLayer(int idx){ newLayer.widthOffset = layerBundle[static_cast(idx)].widthOffset; newLayer.image = layerBundle[static_cast(idx)].image->getDeepCopy(); layerBundle.insert(layerBundle.begin()+idx+1,newLayer); - return true; + return true; } - return false; + return false; } IntelliTool* PaintingArea::copyActiveTool(){ @@ -428,8 +428,8 @@ int PaintingArea::getNumberOfActiveLayer(){ } IntelliImage* PaintingArea::getImageOfActiveLayer(){ - if(activeLayer<0){ - return nullptr; - } + if(activeLayer<0) { + return nullptr; + } return layerBundle[activeLayer].image; } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index fad58dd..95eef55 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -43,142 +43,142 @@ Q_OBJECT friend IntelliTool; friend IntelliPhotoGui; public: - /*! - * \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 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) - */ - PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr); +/*! + * \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 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) + */ +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 - */ - ~PaintingArea() override; +/*! + * \brief This deconstructor is used to clear up the memory and remove the currently active window + */ +~PaintingArea() override; - // Handles all events +// Handles all events - /*! - * \brief setRenderSettings updates all Images to the new Rendersetting. - * \param isFastRenderingOn is the new given flag for the FastRenderer. - */ - void setRenderSettings(bool isFastRenderingOn); +/*! + * \brief setRenderSettings updates all Images to the new Rendersetting. + * \param isFastRenderingOn is the new given flag for the FastRenderer. + */ +void setRenderSettings(bool isFastRenderingOn); - /*! - * \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 - * \return Returns a boolean variable whether the file was successfully opened or not - */ - bool open(const QString &filePath); - /*! - * \brief The save method is used for exporting the current project as one picture - * \param fileName - * \param fileFormat - * \return Returns a boolean variable, true if the file was saved successfully, false if not - */ - bool save(const QString &filePath, const char *fileFormat); +/*! + * \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 + * \return Returns a boolean variable whether the file was successfully opened or not + */ +bool open(const QString &filePath); +/*! + * \brief The save method is used for exporting the current project as one picture + * \param fileName + * \param fileFormat + * \return Returns a boolean variable, true if the file was saved successfully, false if not + */ +bool save(const QString &filePath, const char*fileFormat); - /*! - * \brief The addLayer adds a layer to the current project/ painting area - * \param width - Width of the layer in pixles - * \param height - Height of the layer in pixles - * \param widthOffset - Offset of the layer measured to the left border of the painting area in pixles - * \param heightOffset - Offset of the layer measured to the top border of the painting area in pixles - * \param type - Defining the ImageType of the new layer - * \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); - /*! - * \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 width - Width of the layer in pixles - * \param height - Height of the layer in pixles - * \param widthOffset - Offset of the layer measured to the left border of the painting area in pixles - * \param heightOffset - Offset of the layer measured to the top border of the painting area in pixles - * \param type - Defining the ImageType of the new layer - * \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); - /*! - * \brief The deleteLayer method removes a layer at a given idx - * \param idx - The index of the layer to be removed - */ - void deleteLayer(int idx); - /*! - * \brief The setLayerToActive method marks a specific layer as active - * \param idx - The index of the layer to be active - */ - void setLayerActive(int idx); - /*! - * \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 alpha - New alpha value of the layer - */ - void setLayerAlpha(int idx, int alpha); - /*! - * \brief The floodFill method fills a the active layer with a given color - * \param r - Red value of the color the layer should be filled with - * \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); - /*! - * \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 y - The y value the new center of the layer should be at - */ - void movePositionActive(int x, int y); - /*! - * \brief The moveActiveLayer moves the active layer to a specific position in the layer stack - * \param idx - The index of the new position the layer should be in - */ - void moveActiveLayer(int idx); +/*! + * \brief The addLayer adds a layer to the current project/ painting area + * \param width - Width of the layer in pixles + * \param height - Height of the layer in pixles + * \param widthOffset - Offset of the layer measured to the left border of the painting area in pixles + * \param heightOffset - Offset of the layer measured to the top border of the painting area in pixles + * \param type - Defining the ImageType of the new layer + * \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); +/*! + * \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 width - Width of the layer in pixles + * \param height - Height of the layer in pixles + * \param widthOffset - Offset of the layer measured to the left border of the painting area in pixles + * \param heightOffset - Offset of the layer measured to the top border of the painting area in pixles + * \param type - Defining the ImageType of the new layer + * \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); +/*! + * \brief The deleteLayer method removes a layer at a given idx + * \param idx - The index of the layer to be removed + */ +void deleteLayer(int idx); +/*! + * \brief The setLayerToActive method marks a specific layer as active + * \param idx - The index of the layer to be active + */ +void setLayerActive(int idx); +/*! + * \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 alpha - New alpha value of the layer + */ +void setLayerAlpha(int idx, int alpha); +/*! + * \brief The floodFill method fills a the active layer with a given color + * \param r - Red value of the color the layer should be filled with + * \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); +/*! + * \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 y - The y value the new center of the layer should be at + */ +void movePositionActive(int x, int y); +/*! + * \brief The moveActiveLayer moves the active layer to a specific position in the layer stack + * \param idx - The index of the new position the layer should be in + */ +void moveActiveLayer(int idx); - //change properties of colorPicker - /*! - * \brief The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color - */ - void colorPickerSetFirstColor(); - /*! - * \brief The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color - */ - void colorPickerSetSecondColor(); - /*! - * \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color - */ - void colorPickerSwapColors(); +//change properties of colorPicker +/*! + * \brief The colorPickerSetFirstColor calls the QTColorPicker to determine the primary drawing color + */ +void colorPickerSetFirstColor(); +/*! + * \brief The colorPickerSetSecondColor calls the QTColorPicker to determine the secondary drawing color + */ +void colorPickerSetSecondColor(); +/*! + * \brief The colorPickerSwitchColor swaps the primary color with the secondary drawing color + */ +void colorPickerSwapColors(); - // Create tools - void createPenTool(); - void createPlainTool(); - void createLineTool(); - void createRectangleTool(); - void createCircleTool(); - void createPolygonTool(); - void createFloodFillTool(); +// Create tools +void createPenTool(); +void createPlainTool(); +void createLineTool(); +void createRectangleTool(); +void createCircleTool(); +void createPolygonTool(); +void createFloodFillTool(); - /*! - * \brief The getWidthOfActive gets the horizontal dimensions of the active layer - * \return Returns the horizontal pixle count of the active layer - */ - int getWidthOfActive(); - /*! - * \brief The getHeightOfActive gets the vertical dimensions of the active layer - * \return Returns the vertical pixle count of the active layer - */ - int getHeightOfActive(); +/*! + * \brief The getWidthOfActive gets the horizontal dimensions of the active layer + * \return Returns the horizontal pixle count of the active layer + */ +int getWidthOfActive(); +/*! + * \brief The getHeightOfActive gets the vertical dimensions of the active layer + * \return Returns the vertical pixle count of the active layer + */ +int getHeightOfActive(); - IntelliImage::ImageType getTypeOfImageRealLayer(); +IntelliImage::ImageType getTypeOfImageRealLayer(); - std::vector getPolygonDataOfRealLayer(); +std::vector getPolygonDataOfRealLayer(); - int getNumberOfActiveLayer(); +int getNumberOfActiveLayer(); - IntelliImage* getImageOfActiveLayer(); +IntelliImage* getImageOfActiveLayer(); - IntelliToolsettings Toolsettings; - IntelliColorPicker colorPicker; +IntelliToolsettings Toolsettings; +IntelliColorPicker colorPicker; public slots: // Events to handle @@ -226,8 +226,8 @@ void drawLayers(bool forSaving=false); void resizeLayer(QImage*image_res, const QSize &newSize); - // Helper for Tool - bool createTempTopLayer(int idx); +// Helper for Tool +bool createTempTopLayer(int idx); }; #endif diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 2dd2272..7d85547 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -24,10 +24,10 @@ void IntelliTool::onMouseRightReleased(int x, int y){ } void IntelliTool::onMouseLeftPressed(int x, int y){ - this->isDrawing=this->createToolLayer(); - if(isDrawing){ - Canvas->image->calculateVisiblity(); - } + this->isDrawing=this->createToolLayer(); + if(isDrawing) { + Canvas->image->calculateVisiblity(); + } } void IntelliTool::onMouseLeftReleased(int x, int y){ @@ -49,22 +49,22 @@ void IntelliTool::onWheelScrolled(int value){ } bool IntelliTool::createToolLayer(){ - if(Area->createTempTopLayer(Area->activeLayer)){ - this->activeLayer=&Area->layerBundle[static_cast(Area->activeLayer)]; - this->Canvas=&Area->layerBundle[static_cast(Area->activeLayer+1)]; - return true; - } - return false; + if(Area->createTempTopLayer(Area->activeLayer)) { + this->activeLayer=&Area->layerBundle[static_cast(Area->activeLayer)]; + this->Canvas=&Area->layerBundle[static_cast(Area->activeLayer+1)]; + return true; + } + return false; } void IntelliTool::mergeToolLayer(){ QColor clr_0; QColor clr_1; - QImage updatedImage = activeLayer->image->getImageData(); + QImage updatedImage = activeLayer->image->getImageData(); for(int y=0; yheight; y++) { - for(int x=0; xwidth; x++) { - clr_0=updatedImage.pixelColor(x,y); + for(int x=0; xwidth; x++) { + clr_0=updatedImage.pixelColor(x,y); clr_1=Canvas->image->imageData.pixelColor(x,y); float t = static_cast(clr_1.alpha())/255.f; int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); @@ -76,11 +76,11 @@ void IntelliTool::mergeToolLayer(){ clr_0.setBlue(b); clr_0.setAlpha(a); - updatedImage.setPixelColor(x, y, clr_0); + updatedImage.setPixelColor(x, y, clr_0); } } - activeLayer->image->setImageData(updatedImage); - Area->DummyGui->UpdateGui(); + activeLayer->image->setImageData(updatedImage); + Area->DummyGui->UpdateGui(); } void IntelliTool::deleteToolLayer(){ diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp index cde5da6..d2a09d1 100644 --- a/src/Tool/IntelliToolCircle.cpp +++ b/src/Tool/IntelliToolCircle.cpp @@ -26,7 +26,7 @@ void IntelliToolCircle::drawCircle(int radius){ } //TODO implement circle drawing algorithm bresenham - radius = static_cast(radius +(Toolsettings->getLineWidth()/2.)); + radius = static_cast(radius +(Toolsettings->getLineWidth()/2.)); yMin = (centerPoint.y()-radius); yMax = (centerPoint.y()+radius); for(int i=yMin; i<=yMax; i++) { @@ -56,12 +56,12 @@ void IntelliToolCircle::onMouseRightReleased(int x, int y){ void IntelliToolCircle::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); - if(this->isDrawing){ - this->centerPoint=QPoint(x,y); - int radius = 1; - drawCircle(radius); - Canvas->image->calculateVisiblity(); - } + if(this->isDrawing) { + this->centerPoint=QPoint(x,y); + int radius = 1; + drawCircle(radius); + Canvas->image->calculateVisiblity(); + } } void IntelliToolCircle::onMouseLeftReleased(int x, int y){ diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index 45194de..120d3a2 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -49,7 +49,7 @@ void IntelliToolLine::onMouseMoved(int x, int y){ QPoint p2 =lineStartingPoint.x() < next.x() ? next : lineStartingPoint; int m = static_cast(static_cast(p2.y()-p1.y())/static_cast(p2.x()-p1.x())+0.5f); int c = lineStartingPoint.y()-lineStartingPoint.x()*m; - //TODO implement dotted algorithm + //TODO implement dotted algorithm break; } } From d8f6f0f8f7e3999db493acb033471f509fd517a6 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Tue, 14 Jan 2020 21:02:03 +0100 Subject: [PATCH 2/6] implemented creation of certain image type and alo button for setting poylgon data TODO implement setPolygon function --- src/GUI/IntelliPhotoGui.cpp | 74 +++++++++++++++++++++++++++++++++---- src/GUI/IntelliPhotoGui.h | 11 ++++-- src/Layer/PaintingArea.cpp | 7 ++++ src/Layer/PaintingArea.h | 5 +++ 4 files changed, 86 insertions(+), 11 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 4e506da..01913b4 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -65,8 +65,8 @@ void IntelliPhotoGui::slotSave(){ saveFile(fileFormat); } -// Opens a dialog that allows the user to create a New Layer -void IntelliPhotoGui::slotCreateNewLayer(){ +// Opens a dialog that allows the user to create a New RASTER Layer +void IntelliPhotoGui::slotCreateNewRasterLayer(){ // Stores button value bool ok1, ok2; @@ -85,11 +85,36 @@ void IntelliPhotoGui::slotCreateNewLayer(){ 200,1, 500, 1, &ok2); // Create New Layer 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(); + } +} + // Opens a dialog that allows the user to delete a Layer void IntelliPhotoGui::slotDeleteLayer(){ // Stores button value @@ -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(){ paintingArea->movePositionActive(0,-20); update(); @@ -343,10 +386,16 @@ void IntelliPhotoGui::createActions(){ actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); - // Create New Layer action and tie to IntelliPhotoGui::newLayer() - actionCreateNewLayer = new QAction(tr("&New Layer..."), this); - actionCreateNewLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); - connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer())); + // Create New RASTER Layer action and tie to IntelliPhotoGui::newLayer() + actionCreateNewRasterLayer = new QAction(tr("&Raster Image"), this); + actionCreateNewRasterLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); + 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() actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); @@ -361,6 +410,10 @@ void IntelliPhotoGui::createActions(){ actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A)); 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->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up)); connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp())); @@ -510,12 +563,17 @@ void IntelliPhotoGui::createMenus(){ renderMenu->addAction(actionUpdateRenderSettingsOn); 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 layerMenu = new QMenu(tr("&Layer"), this); - layerMenu->addAction(actionCreateNewLayer); + layerMenu->addMenu(layerCreationMenu); layerMenu->addSeparator(); layerMenu->addAction(actionSetActiveAlpha); layerMenu->addAction(actionSetActiveLayer); + layerMenu->addAction(actionSetPolygon); layerMenu->addSeparator(); layerMenu->addAction(actionMovePositionUp); layerMenu->addAction(actionMovePositionDown); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 43aa03e..6d32933 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -44,11 +44,13 @@ void slotOpen(); void slotSave(); // layer slots here -void slotCreateNewLayer(); +void slotCreateNewRasterLayer(); +void slotCreateNewShapedLayer(); void slotDeleteLayer(); void slotClearActiveLayer(); void slotSetActiveLayer(); void slotSetActiveAlpha(); +void slotSetPolygon(); void slotPositionMoveUp(); void slotPositionMoveDown(); void slotPositionMoveLeft(); @@ -133,6 +135,7 @@ QMenu*saveAsMenu; QMenu*fileMenu; QMenu*renderMenu; QMenu*optionMenu; +QMenu*layerCreationMenu; QMenu*layerMenu; QMenu*colorMenu; QMenu*toolCreationMenu; @@ -168,10 +171,12 @@ QAction*actionAboutDialog; QAction*actionAboutQtDialog; // layer change actions -QAction*actionCreateNewLayer; -QAction*actionDeleteLayer; +QAction* actionCreateNewRasterLayer; +QAction* actionCreateNewShapedLayer; +QAction* actionDeleteLayer; QAction* actionSetActiveLayer; QAction* actionSetActiveAlpha; +QAction* actionSetPolygon; QAction* actionMovePositionUp; QAction* actionMovePositionDown; QAction* actionMovePositionLeft; diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index 7b93abc..d16aace 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -110,6 +110,13 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){ layerBundle[static_cast(idx)].alpha=alpha; } } +void PaintingArea::setPolygon(int idx){ + if(idx>=0&&idx(layerBundle.size())) { + if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ + qDebug() << "Todo Implement here set Polygon"; + } + } +} // Used to load the image and place it in the widget bool PaintingArea::open(const QString &filePath){ diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 95eef55..5e3d03a 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -115,6 +115,11 @@ void setLayerActive(int idx); * \param alpha - New alpha value of the layer */ void setLayerAlpha(int idx, int alpha); +/*! + * \brief setPolygon is used for setting polygondata, it only works on RASTER images + * \param idx - represents the number of the layer with should be transformed + */ +void setPolygon(int idx); /*! * \brief The floodFill method fills a the active layer with a given color * \param r - Red value of the color the layer should be filled with From 2a1561ecfb071e3c0dcebd24813db5494605ebac Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 15 Jan 2020 11:14:01 +0100 Subject: [PATCH 3/6] updated functionality and set true to test. Todo: Cleanub and make it activalable --- src/Tool/IntelliTool.cpp | 5 +++- src/Tool/IntelliToolPolygon.cpp | 42 +++++++++++++++++++-------------- src/Tool/IntelliToolPolygon.h | 1 - 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 7d85547..995c37e 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -79,7 +79,10 @@ void IntelliTool::mergeToolLayer(){ updatedImage.setPixelColor(x, y, clr_0); } } - activeLayer->image->setImageData(updatedImage); + activeLayer->image->setImageData(updatedImage); + if(Canvas->image->getPolygonData().size() != 0){ + activeLayer->image->setPolygon(Canvas->image->getPolygonData()); + } Area->DummyGui->UpdateGui(); } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 452c2bc..84923c3 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -73,24 +73,30 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ isInside = false; isPointNearStart = false; isDrawing = false; - std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); - QPoint Point; - QColor colorTwo(colorPicker->getSecondColor()); - colorTwo.setAlpha(Toolsettings->getInnerAlpha()); - for(int i = 0; i < activeLayer->width; i++) { - for(int j = 0; j < activeLayer->height; j++) { - Point = QPoint(i,j); - if(IntelliTriangulation::isInPolygon(Triangles,Point)) { - this->Canvas->image->drawPixel(Point, colorTwo); - } - } - } - for(int i=0; i(QPointList.size()); i++) { - int next = static_cast((i+static_cast(1))%static_cast(QPointList.size())); - this->Canvas->image->drawLine(QPointList[static_cast(i)], QPointList[static_cast(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - } - QPointList.clear(); - IntelliTool::onMouseLeftReleased(x,y); + if(false){ + std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); + QPoint Point; + QColor colorTwo(colorPicker->getSecondColor()); + colorTwo.setAlpha(Toolsettings->getInnerAlpha()); + for(int i = 0; i < activeLayer->width; i++) { + for(int j = 0; j < activeLayer->height; j++) { + Point = QPoint(i,j); + if(IntelliTriangulation::isInPolygon(Triangles,Point)) { + this->Canvas->image->drawPixel(Point, colorTwo); + } + } + } + for(int i=0; i(QPointList.size()); i++) { + int next = static_cast((i+static_cast(1))%static_cast(QPointList.size())); + this->Canvas->image->drawLine(QPointList[static_cast(i)], QPointList[static_cast(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + } + + } + else{ + Canvas->image->setPolygon(QPointList); + } + IntelliTool::onMouseLeftReleased(x,y); + QPointList.clear(); } } diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index 920a556..d4a7561 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -91,7 +91,6 @@ virtual void onWheelScrolled(int value) override; */ virtual void onMouseMoved(int x, int y) override; - }; #endif // INTELLITOOLPOLYGON_H From f575da20d7b93b1b45055863b9462f58a21cfc52 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 15 Jan 2020 12:35:29 +0100 Subject: [PATCH 4/6] Updated it works kinda TOdo: fix BUGS --- src/Image/IntelliShapedImage.cpp | 22 ++++++++++++++++--- src/Layer/PaintingArea.cpp | 20 ++++++++++++++++-- src/Layer/PaintingArea.h | 6 ++++++ src/Tool/IntelliTool.cpp | 36 ++++++++++++++++---------------- src/Tool/IntelliToolPolygon.cpp | 25 +++++++++++++++------- src/Tool/IntelliToolPolygon.h | 8 ++++++- 6 files changed, 86 insertions(+), 31 deletions(-) diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 359768e..0911288 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -27,14 +27,17 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){ } void IntelliShapedImage::calculateVisiblity(){ - if(fastRenderering) { + if(polygonData.size()<2){ + return; + } + if(fastRenderering) { this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); } if(polygonData.size()<=2) { QColor clr; for(int y=0; y& polygonData){ this->polygonData.push_back(QPoint(element.x(), element.y())); } triangles = IntelliTriangulation::calculateTriangles(polygonData); + if(fastRenderering){ + imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + for(int y = 0; y=0&&idx(layerBundle.size())) { if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ - qDebug() << "Todo Implement here set Polygon"; + delete this->Tool; + this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); } } } @@ -438,5 +439,20 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){ if(activeLayer<0) { return nullptr; } - return layerBundle[activeLayer].image; + return layerBundle[static_cast(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(activeLayer)].image->getImageData(); + if(renderSettings.isFastRenderering()){ + returnImage = returnImage.convertToFormat(QImage::Format_ARGB32); + } + } + return returnImage; } diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 5e3d03a..ac394f5 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -182,6 +182,12 @@ int getNumberOfActiveLayer(); IntelliImage* getImageOfActiveLayer(); +/*! + * \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; diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 995c37e..1ec2d0c 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -33,7 +33,7 @@ void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){ if(isDrawing) { isDrawing=false; - this->mergeToolLayer(); + this->mergeToolLayer(); this->deleteToolLayer(); activeLayer->image->calculateVisiblity(); } @@ -62,25 +62,25 @@ void IntelliTool::mergeToolLayer(){ QColor clr_1; QImage updatedImage = activeLayer->image->getImageData(); - for(int y=0; yheight; y++) { - for(int x=0; xwidth; x++) { - clr_0=updatedImage.pixelColor(x,y); - clr_1=Canvas->image->imageData.pixelColor(x,y); - float t = static_cast(clr_1.alpha())/255.f; - int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); - int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); - int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(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); + for(int y=0; yheight; y++) { + for(int x=0; xwidth; x++) { + clr_0=updatedImage.pixelColor(x,y); + clr_1=Canvas->image->imageData.pixelColor(x,y); + float t = static_cast(clr_1.alpha())/255.f; + int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); + int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); + int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(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); - updatedImage.setPixelColor(x, y, clr_0); - } - } + updatedImage.setPixelColor(x, y, clr_0); + } + } activeLayer->image->setImageData(updatedImage); - if(Canvas->image->getPolygonData().size() != 0){ + if(Canvas->image->getPolygonData().size() > 0){ activeLayer->image->setPolygon(Canvas->image->getPolygonData()); } Area->DummyGui->UpdateGui(); diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 84923c3..32c416f 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -4,11 +4,12 @@ #include #include -IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) +IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings, bool isSettingPolygon) : IntelliTool(Area, colorPicker, Toolsettings){ isPointNearStart = false; isDrawing = false; isInside = false; + this->isSettingPolygon = isSettingPolygon; this->ActiveType = Tooltype::POLYGON; } @@ -19,10 +20,13 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); QPoint Point(x,y); isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + if(isSettingPolygon){ + isInside = true; + } } else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; @@ -36,14 +40,18 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ QPointList.push_back(drawingPoint); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - this->Canvas->image->calculateVisiblity(); + if(!isSettingPolygon){ + this->Canvas->image->calculateVisiblity(); + } } else if(isDrawing && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2) { isPointNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - this->Canvas->image->calculateVisiblity(); - } + if(!isSettingPolygon){ + this->Canvas->image->calculateVisiblity(); + } + } else{ isInside = false; isDrawing = false; @@ -56,7 +64,9 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - this->Canvas->image->calculateVisiblity(); + if(!isSettingPolygon){ + this->Canvas->image->calculateVisiblity(); + } } } @@ -73,7 +83,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ isInside = false; isPointNearStart = false; isDrawing = false; - if(false){ + if(!isSettingPolygon){ std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; QColor colorTwo(colorPicker->getSecondColor()); @@ -94,6 +104,7 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ } else{ Canvas->image->setPolygon(QPointList); + Canvas->image->setImageData(Area->getImageDataOfActiveLayer()); } IntelliTool::onMouseLeftReleased(x,y); QPointList.clear(); diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index d4a7561..d50adc4 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -29,6 +29,11 @@ bool isDrawing; */ bool isInside; +/*! + * \brief isSettingPolygon is the flag for calling the setPolygon method. + */ +bool isSettingPolygon; + /*! * \brief PointIsNearStart true, when last click near startpoint, else false. */ @@ -43,8 +48,9 @@ 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. + * \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. */ From 1f0b856079353fd638cd47aa73136720953ffcb2 Mon Sep 17 00:00:00 2001 From: Jan Schuffenhauer Date: Wed, 15 Jan 2020 14:23:14 +0100 Subject: [PATCH 5/6] FIxed all bugs and removed dead code my job is done here ready to be merge --- src/GUI/IntelliPhotoGui.cpp | 30 +----------- src/GUI/IntelliPhotoGui.h | 1 - src/Layer/PaintingArea.cpp | 84 +++++++++++++-------------------- src/Layer/PaintingArea.h | 16 +++---- src/Tool/IntelliTool.cpp | 5 +- src/Tool/IntelliToolPolygon.cpp | 11 +++-- 6 files changed, 53 insertions(+), 94 deletions(-) diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index 01913b4..d7b207b 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -202,35 +202,6 @@ void IntelliPhotoGui::slotMoveLayerDown(){ 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(){ // Stores button value bool ok1; @@ -788,6 +759,7 @@ void IntelliPhotoGui::setIntelliStyle(){ this->helpMenu->setPalette(Palette); this->renderMenu->setPalette(Palette); this->toolMenu->setPalette(Palette); + this->layerCreationMenu->setPalette(Palette); this->layerMenu->setPalette(Palette); this->colorMenu->setPalette(Palette); this->toolCreationMenu->setPalette(Palette); diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index 6d32933..52a022a 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -47,7 +47,6 @@ void slotSave(); void slotCreateNewRasterLayer(); void slotCreateNewShapedLayer(); void slotDeleteLayer(); -void slotClearActiveLayer(); void slotSetActiveLayer(); void slotSetActiveAlpha(); void slotSetPolygon(); diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index a9faacf..9a99f78 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -18,24 +18,13 @@ #include "Tool/IntelliToolFloodFill.h" #include "Tool/IntelliToolPolygon.h" + PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ this->Tool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); - this->addLayer(200,200,0,0,IntelliImage::ImageType::SHAPEDIMAGE); - layerBundle[0].image->drawPlain(QColor(0,0,255,255)); - std::vector 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,IntelliImage::ImageType::RASTERIMAGE); - layerBundle[1].image->drawPlain(QColor(0,255,0,255)); - layerBundle[1].alpha=200; - - activeLayer=0; + activeLayer=-1; } PaintingArea::~PaintingArea(){ @@ -64,6 +53,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ LayerObject newLayer; + updateTools(); newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; @@ -80,7 +70,10 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff } -void PaintingArea::deleteLayer(int idx){ +void PaintingArea::deleteLayer(int idx, bool isTool){ + if(!isTool){ + updateTools(); + } if(idx(layerBundle.size())) { this->layerBundle.erase(layerBundle.begin()+idx); if(activeLayer>=idx) { @@ -100,7 +93,8 @@ void PaintingArea::slotDeleteActiveLayer(){ } void PaintingArea::setLayerActive(int idx){ - if(idx>=0&&idx(layerBundle.size())) { + updateTools(); + if(idx>=0&&idx(layerBundle.size())) { this->activeLayer=idx; } } @@ -115,6 +109,7 @@ void PaintingArea::setPolygon(int idx){ if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ delete this->Tool; this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); + isSettingPolygon = true; } } } @@ -155,36 +150,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; - } - IntelliImage* active = layerBundle[static_cast(activeLayer)].image; - active->drawPlain(QColor(r, g, b, a)); - update(); -} - void PaintingArea::movePositionActive(int x, int y){ - if(Tool!=nullptr) { - if(Tool->getIsDrawing()) { - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } - } + updateTools(); layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; } void PaintingArea::moveActiveLayer(int idx){ - if(Tool != nullptr) { - if(Tool->getIsDrawing()) { - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } - } + updateTools(); if(idx==1) { this->selectLayerUp(); }else if(idx==-1) { @@ -193,14 +166,8 @@ void PaintingArea::moveActiveLayer(int idx){ } void PaintingArea::slotActivateLayer(int a){ - if(Tool != nullptr) { - if(Tool->getIsDrawing()) { - IntelliTool* temp = copyActiveTool(); - delete this->Tool; - this->Tool = temp; - } - } - if(a>=0 && a < static_cast(layerBundle.size())) { + updateTools(); + if(a>=0 && a < static_cast(layerBundle.size())) { this->setLayerActive(a); } } @@ -343,7 +310,7 @@ void PaintingArea::paintEvent(QPaintEvent*event){ 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 void PaintingArea::resizeEvent(QResizeEvent*event){ //TODO wait till tool works @@ -355,14 +322,16 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){ } void PaintingArea::selectLayerUp(){ - if(activeLayer!=-1 && static_cast(activeLayer)(activeLayer)(activeLayer)], layerBundle[static_cast(activeLayer+1)]); activeLayer++; } } void PaintingArea::selectLayerDown(){ - if(activeLayer!=-1 && activeLayer>0) { + updateTools(); + if(activeLayer!=-1 && activeLayer>0) { std::swap(layerBundle[static_cast(activeLayer)], layerBundle[static_cast(activeLayer-1)]); activeLayer--; } @@ -456,3 +425,18 @@ QImage PaintingArea::getImageDataOfActiveLayer(){ } 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; + } + } +} diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index ac394f5..782a1b7 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -102,8 +102,9 @@ int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffs /*! * \brief The deleteLayer method removes a layer at a given idx * \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 * \param idx - The index of the layer to be active @@ -120,14 +121,6 @@ void setLayerAlpha(int idx, int alpha); * \param idx - represents the number of the layer with should be transformed */ void setPolygon(int idx); -/*! - * \brief The floodFill method fills a the active layer with a given color - * \param r - Red value of the color the layer should be filled with - * \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); /*! * \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 @@ -226,6 +219,8 @@ QImage* Canvas; int maxWidth; int maxHeight; +bool isSettingPolygon = false; + IntelliRenderSettings renderSettings; IntelliTool* Tool; IntelliPhotoGui* DummyGui; @@ -239,6 +234,9 @@ void resizeLayer(QImage*image_res, const QSize &newSize); // Helper for Tool bool createTempTopLayer(int idx); + +//this function is needed to avoid errors in inputhandeling if a layer has changed +void updateTools(); }; #endif diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index 1ec2d0c..a41ee21 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -32,10 +32,11 @@ void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){ if(isDrawing) { - isDrawing=false; + isDrawing=false; this->mergeToolLayer(); this->deleteToolLayer(); activeLayer->image->calculateVisiblity(); + } } @@ -87,7 +88,7 @@ void IntelliTool::mergeToolLayer(){ } void IntelliTool::deleteToolLayer(){ - Area->deleteLayer(Area->activeLayer+1); + Area->deleteLayer(Area->activeLayer+1, true); this->Canvas=nullptr; } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index 32c416f..f4f5105 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -21,9 +21,14 @@ IntelliToolPolygon::~IntelliToolPolygon(){ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { - std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); - QPoint Point(x,y); - isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + if(Area->getPolygonDataOfRealLayer().size()>2){ + std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); + QPoint Point(x,y); + isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + } + else{ + isInside = true; + } if(isSettingPolygon){ isInside = true; } From cf3c542250218283b00a29721fa5cadc609a4c22 Mon Sep 17 00:00:00 2001 From: Conrad Date: Wed, 15 Jan 2020 14:48:50 +0100 Subject: [PATCH 6/6] Uncrustified Commits and Updated Errors --- cppcheck_errors.txt | 47 ++++++--------- src/GUI/IntelliPhotoGui.cpp | 100 +++++++++++++++---------------- src/Image/IntelliShapedImage.cpp | 38 ++++++------ src/Layer/PaintingArea.cpp | 94 ++++++++++++++--------------- src/Tool/IntelliTool.cpp | 46 +++++++------- src/Tool/IntelliToolPolygon.cpp | 94 ++++++++++++++--------------- 6 files changed, 205 insertions(+), 214 deletions(-) diff --git a/cppcheck_errors.txt b/cppcheck_errors.txt index edc41a2..e5f712f 100644 --- a/cppcheck_errors.txt +++ b/cppcheck_errors.txt @@ -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] firstColor = {255,0,0,255}; ^ @@ -10,9 +7,9 @@ src/IntelliHelper/IntelliColorPicker.cpp:5:3: performance: Variable 'secondColor src/IntelliHelper/IntelliTriangulation.cpp:116:63: style: Parameter 'triangles' can be declared with const [constParameter] bool IntelliTriangulation::isInPolygon(std::vector &triangles, QPoint &point){ ^ -src/Layer/PaintingArea.cpp:335:22: style: Redundant condition: If 'activeLayer > 0', the comparison 'activeLayer != -1' is always true. [redundantCondition] - if(activeLayer!=-1 && activeLayer>0) { - ^ +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) { + ^ src/Tool/IntelliTool.cpp:4:14: warning: Member variable 'IntelliTool::ActiveType' is not initialized in the constructor. [uninitMemberVar] IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){ ^ @@ -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] 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(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:43:9: note: Shadow variable +src/Tool/IntelliToolCircle.cpp:42:9: note: Shadow variable int yMin = static_cast(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] +src/Tool/IntelliToolCircle.cpp:43:9: style: Local variable 'yMax' shadows outer variable [shadowVariable] int yMax = static_cast(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); ^ -src/Tool/IntelliToolCircle.cpp:19:13: note: Shadowed declaration +src/Tool/IntelliToolCircle.cpp:18:13: note: Shadowed declaration int yMin, yMax, xMin, xMax; ^ -src/Tool/IntelliToolCircle.cpp:44:9: note: Shadow variable +src/Tool/IntelliToolCircle.cpp:43:9: note: Shadow variable int yMax = static_cast(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] 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] 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; ^ 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/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:294:0: style: The function 'wheelEvent' is never used. [unusedFunction] +src/Layer/PaintingArea.cpp:289: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] diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index d7b207b..c05fce8 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -85,34 +85,34 @@ void IntelliPhotoGui::slotCreateNewRasterLayer(){ 200,1, 500, 1, &ok2); // Create New Layer if (ok1&&ok2) { - paintingArea->addLayer(width,height,0,0,IntelliImage::ImageType::RASTERIMAGE); + 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; + // 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); + // "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 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(); - } + 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(); + } } // Opens a dialog that allows the user to delete a Layer @@ -155,21 +155,21 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ } void IntelliPhotoGui::slotSetPolygon(){ - // Stores button value - bool ok1; + // 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); + // "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(); - } + if (ok1) + { + paintingArea->setPolygon(layer-1); + UpdateGui(); + } } void IntelliPhotoGui::slotPositionMoveUp(){ @@ -357,16 +357,16 @@ void IntelliPhotoGui::createActions(){ actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); - // Create New RASTER Layer action and tie to IntelliPhotoGui::newLayer() - actionCreateNewRasterLayer = new QAction(tr("&Raster Image"), this); - actionCreateNewRasterLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); - connect(actionCreateNewRasterLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewRasterLayer())); + // Create New RASTER Layer action and tie to IntelliPhotoGui::newLayer() + actionCreateNewRasterLayer = new QAction(tr("&Raster Image"), this); + actionCreateNewRasterLayer->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N)); + 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())); + // 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() actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); @@ -381,9 +381,9 @@ void IntelliPhotoGui::createActions(){ actionSetActiveAlpha->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A)); 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())); + 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->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up)); @@ -534,17 +534,17 @@ void IntelliPhotoGui::createMenus(){ renderMenu->addAction(actionUpdateRenderSettingsOn); 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 Layer Creations to Menu + layerCreationMenu = new QMenu(tr("&Create new Layer"), this); + layerCreationMenu->addAction(actionCreateNewRasterLayer); + layerCreationMenu->addAction(actionCreateNewShapedLayer); // Attach all actions to Layer layerMenu = new QMenu(tr("&Layer"), this); - layerMenu->addMenu(layerCreationMenu); + layerMenu->addMenu(layerCreationMenu); layerMenu->addSeparator(); layerMenu->addAction(actionSetActiveAlpha); layerMenu->addAction(actionSetActiveLayer); - layerMenu->addAction(actionSetPolygon); + layerMenu->addAction(actionSetPolygon); layerMenu->addSeparator(); layerMenu->addAction(actionMovePositionUp); layerMenu->addAction(actionMovePositionDown); @@ -759,7 +759,7 @@ void IntelliPhotoGui::setIntelliStyle(){ this->helpMenu->setPalette(Palette); this->renderMenu->setPalette(Palette); this->toolMenu->setPalette(Palette); - this->layerCreationMenu->setPalette(Palette); + this->layerCreationMenu->setPalette(Palette); this->layerMenu->setPalette(Palette); this->colorMenu->setPalette(Palette); this->toolCreationMenu->setPalette(Palette); diff --git a/src/Image/IntelliShapedImage.cpp b/src/Image/IntelliShapedImage.cpp index 0911288..b8a7bec 100644 --- a/src/Image/IntelliShapedImage.cpp +++ b/src/Image/IntelliShapedImage.cpp @@ -27,17 +27,17 @@ IntelliImage* IntelliShapedImage::getDeepCopy(){ } void IntelliShapedImage::calculateVisiblity(){ - if(polygonData.size()<2){ - return; - } - if(fastRenderering) { + if(polygonData.size()<2) { + return; + } + if(fastRenderering) { this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); } if(polygonData.size()<=2) { QColor clr; for(int y=0; y& polygonData){ this->polygonData.push_back(QPoint(element.x(), element.y())); } triangles = IntelliTriangulation::calculateTriangles(polygonData); - if(fastRenderering){ - imageData = imageData.convertToFormat(QImage::Format_ARGB32); - } - for(int y = 0; yTool = nullptr; this->setLayerDimensions(maxWidth, maxHeight); - activeLayer=-1; + activeLayer=-1; } PaintingArea::~PaintingArea(){ @@ -53,7 +53,7 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ LayerObject newLayer; - updateTools(); + updateTools(); newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; @@ -71,9 +71,9 @@ int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOff void PaintingArea::deleteLayer(int idx, bool isTool){ - if(!isTool){ - updateTools(); - } + if(!isTool) { + updateTools(); + } if(idx(layerBundle.size())) { this->layerBundle.erase(layerBundle.begin()+idx); if(activeLayer>=idx) { @@ -93,8 +93,8 @@ void PaintingArea::slotDeleteActiveLayer(){ } void PaintingArea::setLayerActive(int idx){ - updateTools(); - if(idx>=0&&idx(layerBundle.size())) { + updateTools(); + if(idx>=0&&idx(layerBundle.size())) { this->activeLayer=idx; } } @@ -105,13 +105,13 @@ void PaintingArea::setLayerAlpha(int idx, int alpha){ } } void PaintingArea::setPolygon(int idx){ - if(idx>=0&&idx(layerBundle.size())) { - if(layerBundle[static_cast(idx)].image->getTypeOfImage()==IntelliImage::ImageType::SHAPEDIMAGE){ - delete this->Tool; - this->Tool = new IntelliToolPolygon(this,&colorPicker,&Toolsettings, true); - isSettingPolygon = true; - } - } + if(idx>=0&&idx(layerBundle.size())) { + if(layerBundle[static_cast(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 @@ -151,13 +151,13 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){ } void PaintingArea::movePositionActive(int x, int y){ - updateTools(); + updateTools(); layerBundle[static_cast(activeLayer)].widthOffset += x; layerBundle[static_cast(activeLayer)].heightOffset += y; } void PaintingArea::moveActiveLayer(int idx){ - updateTools(); + updateTools(); if(idx==1) { this->selectLayerUp(); }else if(idx==-1) { @@ -166,8 +166,8 @@ void PaintingArea::moveActiveLayer(int idx){ } void PaintingArea::slotActivateLayer(int a){ - updateTools(); - if(a>=0 && a < static_cast(layerBundle.size())) { + updateTools(); + if(a>=0 && a < static_cast(layerBundle.size())) { this->setLayerActive(a); } } @@ -322,16 +322,16 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){ } void PaintingArea::selectLayerUp(){ - updateTools(); - if(activeLayer!=-1 && static_cast(activeLayer)(activeLayer)(activeLayer)], layerBundle[static_cast(activeLayer+1)]); activeLayer++; } } void PaintingArea::selectLayerDown(){ - updateTools(); - if(activeLayer!=-1 && activeLayer>0) { + updateTools(); + if(activeLayer!=-1 && activeLayer>0) { std::swap(layerBundle[static_cast(activeLayer)], layerBundle[static_cast(activeLayer-1)]); activeLayer--; } @@ -408,35 +408,35 @@ IntelliImage* PaintingArea::getImageOfActiveLayer(){ if(activeLayer<0) { return nullptr; } - return layerBundle[static_cast(activeLayer)].image; + return layerBundle[static_cast(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(activeLayer)].image->getImageData(); - if(renderSettings.isFastRenderering()){ - returnImage = returnImage.convertToFormat(QImage::Format_ARGB32); - } - } - return returnImage; + 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(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; - } - } + 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; + } + } } diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index a41ee21..e09f2c7 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -32,8 +32,8 @@ void IntelliTool::onMouseLeftPressed(int x, int y){ void IntelliTool::onMouseLeftReleased(int x, int y){ if(isDrawing) { - isDrawing=false; - this->mergeToolLayer(); + isDrawing=false; + this->mergeToolLayer(); this->deleteToolLayer(); activeLayer->image->calculateVisiblity(); @@ -63,32 +63,32 @@ void IntelliTool::mergeToolLayer(){ QColor clr_1; QImage updatedImage = activeLayer->image->getImageData(); - for(int y=0; yheight; y++) { - for(int x=0; xwidth; x++) { - clr_0=updatedImage.pixelColor(x,y); - clr_1=Canvas->image->imageData.pixelColor(x,y); - float t = static_cast(clr_1.alpha())/255.f; - int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); - int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); - int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(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); + for(int y=0; yheight; y++) { + for(int x=0; xwidth; x++) { + clr_0=updatedImage.pixelColor(x,y); + clr_1=Canvas->image->imageData.pixelColor(x,y); + float t = static_cast(clr_1.alpha())/255.f; + int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); + int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); + int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(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); - updatedImage.setPixelColor(x, y, clr_0); - } - } - activeLayer->image->setImageData(updatedImage); - if(Canvas->image->getPolygonData().size() > 0){ - activeLayer->image->setPolygon(Canvas->image->getPolygonData()); - } + updatedImage.setPixelColor(x, y, clr_0); + } + } + activeLayer->image->setImageData(updatedImage); + if(Canvas->image->getPolygonData().size() > 0) { + activeLayer->image->setPolygon(Canvas->image->getPolygonData()); + } Area->DummyGui->UpdateGui(); } void IntelliTool::deleteToolLayer(){ - Area->deleteLayer(Area->activeLayer+1, true); + Area->deleteLayer(Area->activeLayer+1, true); this->Canvas=nullptr; } diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index f4f5105..c784669 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -9,7 +9,7 @@ IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* c isPointNearStart = false; isDrawing = false; isInside = false; - this->isSettingPolygon = isSettingPolygon; + this->isSettingPolygon = isSettingPolygon; this->ActiveType = Tooltype::POLYGON; } @@ -20,18 +20,18 @@ IntelliToolPolygon::~IntelliToolPolygon(){ } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { - if(Area->getPolygonDataOfRealLayer().size()>2){ - std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); - QPoint Point(x,y); - isInside = IntelliTriangulation::isInPolygon(Triangles,Point); - } - else{ - isInside = true; - } - if(isSettingPolygon){ - isInside = true; - } + if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::SHAPEDIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + if(Area->getPolygonDataOfRealLayer().size()>2) { + std::vector Triangles = IntelliTriangulation::calculateTriangles(Area->getPolygonDataOfRealLayer()); + QPoint Point(x,y); + isInside = IntelliTriangulation::isInPolygon(Triangles,Point); + } + else{ + isInside = true; + } + if(isSettingPolygon) { + isInside = true; + } } else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { isInside = true; @@ -45,18 +45,18 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ QPointList.push_back(drawingPoint); this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - if(!isSettingPolygon){ - this->Canvas->image->calculateVisiblity(); - } + if(!isSettingPolygon) { + this->Canvas->image->calculateVisiblity(); + } } else if(isDrawing && isNearStart(x,y,QPointList.front())) { if(QPointList.size() > 2) { isPointNearStart = true; this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - if(!isSettingPolygon){ - this->Canvas->image->calculateVisiblity(); - } - } + if(!isSettingPolygon) { + this->Canvas->image->calculateVisiblity(); + } + } else{ isInside = false; isDrawing = false; @@ -69,9 +69,9 @@ void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - if(!isSettingPolygon){ - this->Canvas->image->calculateVisiblity(); - } + if(!isSettingPolygon) { + this->Canvas->image->calculateVisiblity(); + } } } @@ -88,31 +88,31 @@ void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ isInside = false; isPointNearStart = false; isDrawing = false; - if(!isSettingPolygon){ - std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); - QPoint Point; - QColor colorTwo(colorPicker->getSecondColor()); - colorTwo.setAlpha(Toolsettings->getInnerAlpha()); - for(int i = 0; i < activeLayer->width; i++) { - for(int j = 0; j < activeLayer->height; j++) { - Point = QPoint(i,j); - if(IntelliTriangulation::isInPolygon(Triangles,Point)) { - this->Canvas->image->drawPixel(Point, colorTwo); - } - } - } - for(int i=0; i(QPointList.size()); i++) { - int next = static_cast((i+static_cast(1))%static_cast(QPointList.size())); - this->Canvas->image->drawLine(QPointList[static_cast(i)], QPointList[static_cast(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); - } + if(!isSettingPolygon) { + std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); + QPoint Point; + QColor colorTwo(colorPicker->getSecondColor()); + colorTwo.setAlpha(Toolsettings->getInnerAlpha()); + for(int i = 0; i < activeLayer->width; i++) { + for(int j = 0; j < activeLayer->height; j++) { + Point = QPoint(i,j); + if(IntelliTriangulation::isInPolygon(Triangles,Point)) { + this->Canvas->image->drawPixel(Point, colorTwo); + } + } + } + for(int i=0; i(QPointList.size()); i++) { + int next = static_cast((i+static_cast(1))%static_cast(QPointList.size())); + this->Canvas->image->drawLine(QPointList[static_cast(i)], QPointList[static_cast(next)], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + } - } - else{ - Canvas->image->setPolygon(QPointList); - Canvas->image->setImageData(Area->getImageDataOfActiveLayer()); - } - IntelliTool::onMouseLeftReleased(x,y); - QPointList.clear(); + } + else{ + Canvas->image->setPolygon(QPointList); + Canvas->image->setImageData(Area->getImageDataOfActiveLayer()); + } + IntelliTool::onMouseLeftReleased(x,y); + QPointList.clear(); } }