diff --git a/cppcheck_errors.txt b/cppcheck_errors.txt new file mode 100644 index 0000000..edc41a2 --- /dev/null +++ b/cppcheck_errors.txt @@ -0,0 +1,92 @@ +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}; + ^ +src/IntelliHelper/IntelliColorPicker.cpp:5:3: performance: Variable 'secondColor' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + secondColor = {0,255,255,255}; + ^ +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/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){ + ^ +src/Tool/IntelliTool.cpp:4:14: warning: Member variable 'IntelliTool::activeLayer' is not initialized in the constructor. [uninitMemberVar] +IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){ + ^ +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] + int yMin = static_cast(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); + ^ +src/Tool/IntelliToolCircle.cpp:19:7: note: Shadowed declaration + int yMin, yMax, xMin, xMax; + ^ +src/Tool/IntelliToolCircle.cpp:43: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] + int yMax = static_cast(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); + ^ +src/Tool/IntelliToolCircle.cpp:19:13: note: Shadowed declaration + int yMin, yMax, xMin, xMax; + ^ +src/Tool/IntelliToolCircle.cpp:44:9: note: Shadow variable + int yMax = static_cast(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' +bool isDrawing = false; + ^ +src/Tool/IntelliToolPolygon.h:25:6: note: Derived variable 'IntelliToolPolygon::isDrawing' +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:255: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:307: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:323:0: style: The function 'resizeLayer' is never used. [unusedFunction] + +^ +src/Layer/PaintingArea.cpp:175: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:83:0: style: The function 'slotDeleteActiveLayer' is never used. [unusedFunction] + +^ +src/Layer/PaintingArea.cpp:294:0: style: The function 'wheelEvent' is never used. [unusedFunction] + +^ +nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingInclude] + diff --git a/src/Bilder.qrc b/src/Bilder.qrc new file mode 100644 index 0000000..3e190f4 --- /dev/null +++ b/src/Bilder.qrc @@ -0,0 +1,13 @@ + + + icons/icon.png + icons/circle-tool.svg + icons/eraser-tool.svg + icons/flood-fill-tool.svg + icons/magic-wand-tool.svg + icons/pen-tool.svg + icons/polygon-tool.svg + icons/rectangle-tool.svg + icons/Wechselpfeile.png + + diff --git a/src/GUI/IntelliPhotoGui.cpp b/src/GUI/IntelliPhotoGui.cpp index b265400..283f7fb 100644 --- a/src/GUI/IntelliPhotoGui.cpp +++ b/src/GUI/IntelliPhotoGui.cpp @@ -1,8 +1,5 @@ // ---------- IntelliPhotoGui.cpp ---------- -#include -#include - #include "IntelliPhotoGui.h" #include "Layer/PaintingArea.h" @@ -19,7 +16,7 @@ IntelliPhotoGui::IntelliPhotoGui(){ // Size the app resize(600,600); showMaximized(); - + setDefaultToolValue(); } // User tried to close the app @@ -84,7 +81,7 @@ void IntelliPhotoGui::slotCreateNewLayer(){ if (ok1&&ok2) { int layer = paintingArea->addLayer(width,height,0,0); - paintingArea->slotActivateLayer(layer); + UpdateGui(); } } @@ -98,10 +95,12 @@ void IntelliPhotoGui::slotDeleteLayer(){ // Define the standard Value, min, max, step and ok button int layerNumber = QInputDialog::getInt(this, tr("delete Layer"), tr("Number:"), - 1,0, 500, 1, &ok); + paintingArea->getNumberOfActiveLayer(),0, 500, 1, &ok); // Create New Layer - if (ok) + if (ok) { paintingArea->deleteLayer(layerNumber); + UpdateGui(); + } } void IntelliPhotoGui::slotSetActiveAlpha(){ @@ -121,6 +120,7 @@ void IntelliPhotoGui::slotSetActiveAlpha(){ if (ok1&&ok2) { paintingArea->setLayerAlpha(layer,alpha); + UpdateGui(); } } @@ -179,6 +179,7 @@ void IntelliPhotoGui::slotClearActiveLayer(){ if (ok1&&ok2&&ok3&&ok4) { paintingArea->floodFill(red, green, blue, alpha); + UpdateGui(); } } @@ -195,46 +196,57 @@ void IntelliPhotoGui::slotSetActiveLayer(){ if (ok1) { paintingArea->setLayerActive(layer); + UpdateGui(); } } void IntelliPhotoGui::slotSetFirstColor(){ paintingArea->colorPickerSetFirstColor(); + UpdateGui(); } void IntelliPhotoGui::slotSetSecondColor(){ paintingArea->colorPickerSetSecondColor(); + UpdateGui(); } void IntelliPhotoGui::slotSwapColor(){ paintingArea->colorPickerSwapColors(); + UpdateGui(); } void IntelliPhotoGui::slotCreatePenTool(){ + PenButton->setChecked(true); paintingArea->createPenTool(); } void IntelliPhotoGui::slotCreatePlainTool(){ + PlainButton->setChecked(true); paintingArea->createPlainTool(); } void IntelliPhotoGui::slotCreateLineTool(){ + LineButton->setChecked(true); paintingArea->createLineTool(); } void IntelliPhotoGui::slotCreateRectangleTool(){ + RectangleButton->setChecked(true); paintingArea->createRectangleTool(); } void IntelliPhotoGui::slotCreateCircleTool(){ + CircleButton->setChecked(true); paintingArea->createCircleTool(); } void IntelliPhotoGui::slotCreatePolygonTool(){ + PolygonButton->setChecked(true); paintingArea->createPolygonTool(); } void IntelliPhotoGui::slotCreateFloodFillTool(){ + FloodFillButton->setChecked(true); paintingArea->createFloodFillTool(); } @@ -245,6 +257,29 @@ void IntelliPhotoGui::slotAboutDialog(){ tr("

IntelliPhotoPretty basic editor.

")); } +void IntelliPhotoGui::slotEnterPressed(){ + QString string = EditLineWidth->text(); + if(string.toInt() > 50) { + EditLineWidth->setText("50"); + } + paintingArea->Toolsettings.setLineWidth(string.toInt()); + string = EditLineInnerAlpha->text(); + if(string.toInt() > 255) { + EditLineInnerAlpha->setText("255"); + } + paintingArea->Toolsettings.setInnerAlpha(string.toInt()); +} + +void IntelliPhotoGui::slotResetTools(){ + CircleButton->setChecked(false); + FloodFillButton->setChecked(false); + LineButton->setChecked(false); + PenButton->setChecked(false); + PlainButton->setChecked(false); + PolygonButton->setChecked(false); + RectangleButton->setChecked(false); +} + // Define menu actions that call functions void IntelliPhotoGui::createActions(){ // Get a list of the supported file formats @@ -324,34 +359,45 @@ void IntelliPhotoGui::createActions(){ //Create Color Actions here actionColorPickerFirstColor = new QAction(tr("&Main"), this); connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor())); + connect(FirstColorButton, SIGNAL(clicked()), this, SLOT(slotSetFirstColor())); actionColorPickerSecondColor = new QAction(tr("&Secondary"), this); 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::SHIFT + 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); + connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool())); + actionCreatePenTool = new QAction(tr("&Pen"),this); + connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool())); actionCreateLineTool = new QAction(tr("&Line"), this); + connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool())); actionCreateCircleTool = new QAction(tr("&Circle"), this); + connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateCircleTool, SIGNAL(triggered()), this, SLOT(slotCreateCircleTool())); actionCreateRectangleTool = new QAction(tr("&Rectangle"), this); + connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateRectangleTool, SIGNAL(triggered()), this, SLOT(slotCreateRectangleTool())); actionCreatePolygonTool = new QAction(tr("&Polygon"), this); + connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreatePolygonTool, SIGNAL(triggered()), this, SLOT(slotCreatePolygonTool())); actionCreateFloodFillTool = new QAction(tr("&FloodFill"), this); + connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotResetTools())); connect(actionCreateFloodFillTool, SIGNAL(triggered()), this, SLOT(slotCreateFloodFillTool())); // Create about action and tie to IntelliPhotoGui::about() @@ -361,6 +407,30 @@ void IntelliPhotoGui::createActions(){ // Create about Qt action and tie to IntelliPhotoGui::aboutQt() actionAboutQtDialog = new QAction(tr("About &Qt"), this); connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + + connect(EditLineWidth, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed())); + connect(EditLineInnerAlpha, SIGNAL(returnPressed()), this, SLOT(slotEnterPressed())); + + connect(CircleButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(CircleButton, SIGNAL(clicked()), this, SLOT(slotCreateCircleTool())); + + connect(FloodFillButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(FloodFillButton, SIGNAL(clicked()), this, SLOT(slotCreateFloodFillTool())); + + connect(LineButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(LineButton, SIGNAL(clicked()), this, SLOT(slotCreateLineTool())); + + connect(PenButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(PenButton, SIGNAL(clicked()), this, SLOT(slotCreatePenTool())); + + connect(PlainButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(PlainButton, SIGNAL(clicked()), this, SLOT(slotCreatePlainTool())); + + connect(PolygonButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(PolygonButton, SIGNAL(clicked()), this, SLOT(slotCreatePolygonTool())); + + connect(RectangleButton,SIGNAL(pressed()), this, SLOT(slotResetTools())); + connect(RectangleButton, SIGNAL(clicked()), this, SLOT(slotCreateRectangleTool())); } // Create the menubar @@ -402,13 +472,13 @@ void IntelliPhotoGui::createMenus(){ //Attach all Tool Options toolMenu = new QMenu(tr("&Tools"), this); + toolMenu->addAction(actionCreateCircleTool); + toolMenu->addAction(actionCreateFloodFillTool); + toolMenu->addAction(actionCreateLineTool); toolMenu->addAction(actionCreatePenTool); toolMenu->addAction(actionCreatePlainTool); - toolMenu->addAction(actionCreateLineTool); - toolMenu->addAction(actionCreateRectangleTool); - toolMenu->addAction(actionCreateCircleTool); toolMenu->addAction(actionCreatePolygonTool); - toolMenu->addAction(actionCreateFloodFillTool); + toolMenu->addAction(actionCreateRectangleTool); toolMenu->addSeparator(); toolMenu->addMenu(colorMenu); @@ -436,9 +506,124 @@ void IntelliPhotoGui::createGui(){ // create Gui elements paintingArea = new PaintingArea(); + paintingArea->DumpyGui = this; + + p = QPixmap(":/Icons/Buttons/icons/circle-tool.svg"); + CircleButton = new QPushButton(); + CircleButton->setFixedSize(Buttonsize); + CircleButton->setIcon(p); + CircleButton->setIconSize(Buttonsize); + CircleButton->setCheckable(true); + + p = QPixmap(":/Icons/Buttons/icons/flood-fill-tool.svg"); + FloodFillButton = new QPushButton(); + FloodFillButton->setFixedSize(Buttonsize); + FloodFillButton->setIcon(p); + FloodFillButton->setIconSize(Buttonsize); + FloodFillButton->setCheckable(true); + + p = QPixmap(":/Icons/Buttons/icons/icon.png"); + LineButton = new QPushButton(); + LineButton->setFixedSize(Buttonsize); + LineButton->setIcon(p); + LineButton->setIconSize(Buttonsize); + LineButton->setCheckable(true); + + p = QPixmap(":/Icons/Buttons/icons/pen-tool.svg"); + PenButton = new QPushButton(); + PenButton->setFixedSize(Buttonsize); + PenButton->setIcon(p); + PenButton->setIconSize(Buttonsize); + PenButton->setCheckable(true); + + p = QPixmap(":/Icons/Buttons/icons/icon.png"); + PlainButton = new QPushButton(); + PlainButton->setFixedSize(Buttonsize); + PlainButton->setIcon(p); + PlainButton->setIconSize(Buttonsize); + PlainButton->setCheckable(true); + + p = QPixmap(":/Icons/Buttons/icons/polygon-tool.svg"); + PolygonButton = new QPushButton(); + PolygonButton->setFixedSize(Buttonsize); + PolygonButton->setIcon(p); + PolygonButton->setIconSize(Buttonsize); + PolygonButton->setCheckable(true); + + p = QPixmap(":/Icons/Buttons/icons/rectangle-tool.svg"); + RectangleButton = new QPushButton(); + RectangleButton->setFixedSize(Buttonsize); + RectangleButton->setIcon(p); + RectangleButton->setIconSize(Buttonsize); + RectangleButton->setCheckable(true); + + WidthLine = new QLabel(); + WidthLine->setText("Width"); + WidthLine->setFixedSize(Buttonsize.width(),Buttonsize.height()/3); + + EditLineWidth = new QLineEdit(); + EditLineWidth->setFixedSize(Buttonsize.width(),Buttonsize.height()/3); + EditLineWidth->setText("5"); + ValidatorLineWidth = new QIntValidator(); + ValidatorLineWidth->setTop(99); + ValidatorLineWidth->setBottom(1); + EditLineWidth->setValidator(ValidatorLineWidth); + + innerAlphaLine = new QLabel(); + innerAlphaLine->setText("Inner Alpha"); + innerAlphaLine->setFixedSize(Buttonsize.width(),Buttonsize.height()/3); + + EditLineInnerAlpha = new QLineEdit(); + EditLineInnerAlpha->setFixedSize(Buttonsize.width(),Buttonsize.height()/3); + EditLineInnerAlpha->setText("255"); + ValidatorInnerAlpha = new QIntValidator(); + ValidatorInnerAlpha->setTop(999); + ValidatorInnerAlpha->setBottom(0); + EditLineInnerAlpha->setValidator(ValidatorInnerAlpha); + + FirstColorButton = new QPushButton(); + FirstColorButton->setFixedSize(Buttonsize/2); + + SecondColorButton = new QPushButton(); + SecondColorButton->setFixedSize(Buttonsize/2); + + p = QPixmap(":/Icons/Buttons/icons/Wechselpfeile.png"); + SwitchColorButton = new QPushButton(); + SwitchColorButton->setFixedSize(Buttonsize.width(),Buttonsize.height()/2); + SwitchColorButton->setIcon(p); + SwitchColorButton->setIconSize(QSize(Buttonsize.width(),Buttonsize.height()/2)); + + ActiveLayerLine = new QLabel(); + QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer()); + ActiveLayerLine->setText(string); + ActiveLayerLine->setFixedSize(Buttonsize.width()+10,Buttonsize.height()/3); + + p = p.fromImage(paintingArea->getImageOfActiveLayer()->getImageData()); + + ActiveLayerImageButton = new QPushButton(); + ActiveLayerImageButton->setFixedSize(Buttonsize); + ActiveLayerImageButton->setIcon(p); + ActiveLayerImageButton->setIconSize(Buttonsize); // set gui elements - mainLayout->addWidget(paintingArea); + + mainLayout->addWidget(paintingArea,1,1,20,1); + mainLayout->addWidget(CircleButton,1,2,1,2); + mainLayout->addWidget(FloodFillButton,2,2,1,2); + mainLayout->addWidget(LineButton,3,2,1,2); + mainLayout->addWidget(PenButton,4,2,1,2); + mainLayout->addWidget(PlainButton,5,2,1,2); + mainLayout->addWidget(PolygonButton,6,2,1,2); + mainLayout->addWidget(RectangleButton,7,2,1,2); + mainLayout->addWidget(WidthLine,8,2,1,2); + mainLayout->addWidget(EditLineWidth,9,2,1,2); + mainLayout->addWidget(innerAlphaLine,10,2,1,2); + mainLayout->addWidget(EditLineInnerAlpha,11,2,1,2); + mainLayout->addWidget(FirstColorButton,12,2,1,1); + mainLayout->addWidget(SecondColorButton,12,3,1,1); + mainLayout->addWidget(SwitchColorButton,13,2,1,2); + mainLayout->addWidget(ActiveLayerLine,14,2,1,2); + mainLayout->addWidget(ActiveLayerImageButton,15,2,1,2); } void IntelliPhotoGui::setIntelliStyle(){ @@ -448,6 +633,10 @@ void IntelliPhotoGui::setIntelliStyle(){ this->setStyleSheet("background-color:rgb(64,64,64)"); this->centralGuiWidget->setStyleSheet("color:rgb(255,255,255)"); this->menuBar()->setStyleSheet("color:rgb(255,255,255)"); + QString string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); + FirstColorButton->setStyleSheet(string); + string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name()); + SecondColorButton->setStyleSheet(string); } bool IntelliPhotoGui::maybeSave(){ @@ -497,3 +686,20 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat){ return paintingArea->save(fileName, fileFormat.constData()); } } + +void IntelliPhotoGui::setDefaultToolValue(){ + slotEnterPressed(); +} + +void IntelliPhotoGui::UpdateGui(){ + QString string = QString("Active Layer: %1").arg(paintingArea->getNumberOfActiveLayer()); + ActiveLayerLine->setText(string); + p = p.fromImage(paintingArea->getImageOfActiveLayer()->getImageData()); + ActiveLayerImageButton->setIcon(p); + ActiveLayerImageButton->setIconSize(Buttonsize); + + string = QString("background-color: %1").arg(paintingArea->colorPicker.getFirstColor().name()); + FirstColorButton->setStyleSheet(string); + string = QString("background-color: %1").arg(paintingArea->colorPicker.getSecondColor().name()); + SecondColorButton->setStyleSheet(string); +} diff --git a/src/GUI/IntelliPhotoGui.h b/src/GUI/IntelliPhotoGui.h index e76485c..3b478b6 100644 --- a/src/GUI/IntelliPhotoGui.h +++ b/src/GUI/IntelliPhotoGui.h @@ -1,6 +1,8 @@ #ifndef IntelliPhotoGui_H #define IntelliPhotoGui_H +#include +#include #include #include #include @@ -30,6 +32,8 @@ public: */ IntelliPhotoGui(); +void UpdateGui(); + protected: // Function used to close an event void closeEvent(QCloseEvent*event) override; @@ -69,6 +73,10 @@ void slotCreateFloodFillTool(); // slots for dialogs void slotAboutDialog(); +void slotEnterPressed(); + +void slotResetTools(); + private: // Will tie user actions to functions void createActions(); @@ -83,9 +91,34 @@ bool maybeSave(); // Opens the Save dialog and saves bool saveFile(const QByteArray &fileFormat); +void setDefaultToolValue(); + // What we'll draw on PaintingArea* paintingArea; +const QSize Buttonsize = QSize(70,70); +QPixmap p; +QPushButton* CircleButton; +QPushButton* FloodFillButton; +QPushButton* LineButton; +QPushButton* PenButton; +QPushButton* PlainButton; +QPushButton* PolygonButton; +QPushButton* RectangleButton; +QLabel* WidthLine; +QLabel* innerAlphaLine; +QLineEdit* EditLineWidth; +QLineEdit* EditLineInnerAlpha; +QIntValidator* ValidatorLineWidth; +QIntValidator* ValidatorInnerAlpha; + +QPushButton* FirstColorButton; +QPushButton* SecondColorButton; +QPushButton* SwitchColorButton; + +QLabel* ActiveLayerLine; +QPushButton* ActiveLayerImageButton; + // The menu widgets QMenu*saveAsMenu; QMenu*fileMenu; @@ -135,7 +168,7 @@ QList actionSaveAs; // main GUI elements QWidget* centralGuiWidget; -QGridLayout*mainLayout; +QGridLayout* mainLayout; }; #endif diff --git a/src/Image/IntelliImage.cpp b/src/Image/IntelliImage.cpp index 4254f63..576a93d 100644 --- a/src/Image/IntelliImage.cpp +++ b/src/Image/IntelliImage.cpp @@ -2,9 +2,17 @@ #include #include -IntelliImage::IntelliImage(int weight, int height) - : imageData(QSize(weight, height), QImage::Format_ARGB32){ +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->fastRenderer = fastRendererOn; + } IntelliImage::~IntelliImage(){ @@ -16,13 +24,13 @@ bool IntelliImage::loadImage(const QString &filePath){ QImage loadedImage; // If the image wasn't loaded leave this function - if (!loadedImage.load(filePath)) + if (!loadedImage.load(filePath)) return false; // scaled Image to size of Layer loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); - imageData = loadedImage.convertToFormat(QImage::Format_ARGB32); + imageData = loadedImage.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32); return true; } @@ -39,9 +47,15 @@ void IntelliImage::resizeImage(QImage*image, const QSize &newSize){ QPainter painter(&newImage); painter.drawImage(QPoint(0, 0), *image); *image = newImage; + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } // Used to draw on the widget QPainter painter(&imageData); @@ -50,9 +64,15 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){ + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } // Used to draw on the widget QPainter painter(&imageData); @@ -60,9 +80,15 @@ void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& p 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(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } // Used to draw on the widget QPainter painter(&imageData); @@ -71,12 +97,34 @@ 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(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } void IntelliImage::drawPlain(const QColor& color){ + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32); + } imageData.fill(color); + if(fastRenderer) { + this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } QColor IntelliImage::getPixelColor(QPoint& point){ + if(fastRenderer) { + QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32); + return copy.pixelColor(point); + } return imageData.pixelColor(point); } + +QImage IntelliImage::getImageData(){ + return this->imageData; +} + +void IntelliImage::updateRendererSetting(bool fastRendererOn){ + this->fastRenderer = fastRendererOn; + this->imageData = this->imageData.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32); +} diff --git a/src/Image/IntelliImage.h b/src/Image/IntelliImage.h index be99c1d..8926990 100644 --- a/src/Image/IntelliImage.h +++ b/src/Image/IntelliImage.h @@ -8,13 +8,8 @@ #include #include -/*! - * \brief The Types, which an Image can be. - */ -enum class ImageType { - Raster_Image, - Shaped_Image -}; +#include "IntelliHelper/IntelliTriangulation.h" +#include "IntelliHelper/IntelliRenderSettings.h" class IntelliTool; @@ -23,6 +18,16 @@ class IntelliTool; */ class IntelliImage { friend IntelliTool; +public: + +/*! + * \brief The Types, which an Image can be. + */ +enum class ImageType { + RASTERIMAGE, + SHAPEDIMAGE +}; + protected: void resizeImage(QImage*image, const QSize &newSize); @@ -30,13 +35,25 @@ void resizeImage(QImage*image, const QSize &newSize); * \brief The underlying image data. */ QImage imageData; + +/*! + * \brief The Type, an Image is. + */ +ImageType TypeOfImage; + +/*! + * \brief fastRenderer is the flag that represents the usage of 8bit pictures. + */ +bool fastRenderer; + public: /*! * \brief The Construcor of the IntelliImage. Given the Image dimensions. * \param width - The width of the Image. * \param height - The height of the Image. + * \param fastRendererOn - Represents the flag for 8bit picture handelling. */ -IntelliImage(int width, int height); +IntelliImage(int width, int height, bool fastRendererOn); /*! * \brief An Abstract Destructor. @@ -114,6 +131,10 @@ virtual std::vector getPolygonData(){ return std::vector(); } +virtual ImageType getTypeOfImage(){ + return TypeOfImage; +} + /*! * \brief A function that loads and sclaes an image to the fitting dimensions. * \param filePath - The path+name of the image which to loaded. @@ -127,6 +148,18 @@ virtual bool loadImage(const QString &filePath); * \return The color of the Pixel as QColor. */ virtual QColor getPixelColor(QPoint& point); + +/*! + * \brief updateRendererSetting updates the existing image format to the new format. + * \param fastRendererOn flag for the 8bit image handeling. + */ +virtual void updateRendererSetting(bool fastRendererOn); + +/*! + * \brief getImageData returns the data of the current image. + */ +virtual QImage getImageData(); + }; #endif diff --git a/src/Image/IntelliRasterImage.cpp b/src/Image/IntelliRasterImage.cpp index c7b3d48..0d28e5d 100644 --- a/src/Image/IntelliRasterImage.cpp +++ b/src/Image/IntelliRasterImage.cpp @@ -3,9 +3,10 @@ #include #include -IntelliRasterImage::IntelliRasterImage(int weight, int height) - : IntelliImage(weight, height){ - +IntelliRasterImage::IntelliRasterImage(int width, int height, bool fastRendererOn) + : IntelliImage(width, height, fastRendererOn){ + TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; + this->fastRenderer = fastRendererOn; } IntelliRasterImage::~IntelliRasterImage(){ @@ -13,8 +14,9 @@ IntelliRasterImage::~IntelliRasterImage(){ } IntelliImage* IntelliRasterImage::getDeepCopy(){ - IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height()); + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height(), false); raster->imageData.fill(Qt::transparent); + raster->TypeOfImage = IntelliImage::ImageType::RASTERIMAGE; return raster; } @@ -28,6 +30,9 @@ QImage IntelliRasterImage::getDisplayable(int alpha){ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ QImage copy = imageData; + if(fastRenderer) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } for(int y = 0; y #include #include -IntelliShapedImage::IntelliShapedImage(int weight, int height) - : IntelliRasterImage(weight, height){ +IntelliShapedImage::IntelliShapedImage(int width, int height, bool fastRendererOn) + : IntelliRasterImage(width, height, fastRendererOn){ + TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; + this->fastRenderer = fastRendererOn; } IntelliShapedImage::~IntelliShapedImage(){ @@ -17,13 +19,18 @@ QImage IntelliShapedImage::getDisplayable(int alpha){ } IntelliImage* IntelliShapedImage::getDeepCopy(){ - IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height()); + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height(), false); shaped->setPolygon(this->polygonData); shaped->imageData.fill(Qt::transparent); + shaped->TypeOfImage = IntelliImage::ImageType::SHAPEDIMAGE; return shaped; } void IntelliShapedImage::calculateVisiblity(){ + if(fastRenderer) { + this->imageData = imageData.convertToFormat(QImage::Format_ARGB32); + } + if(polygonData.size()<=2) { QColor clr; for(int y=0; yimageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } return; } QColor clr; @@ -40,7 +50,7 @@ void IntelliShapedImage::calculateVisiblity(){ for(int x=0; ximageData = this->imageData.convertToFormat(QImage::Format_Indexed8); + } } QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ QImage copy = imageData; + if(fastRenderer) { + copy = copy.convertToFormat(QImage::Format_ARGB32); + } for(int y = 0; y& polygonData){ for(auto element:polygonData) { this->polygonData.push_back(QPoint(element.x(), element.y())); } - triangles = IntelliHelper::calculateTriangles(polygonData); + triangles = IntelliTriangulation::calculateTriangles(polygonData); } calculateVisiblity(); return; diff --git a/src/Image/IntelliShapedImage.h b/src/Image/IntelliShapedImage.h index 5d1288d..220ad75 100644 --- a/src/Image/IntelliShapedImage.h +++ b/src/Image/IntelliShapedImage.h @@ -3,7 +3,6 @@ #include "Image/IntelliRasterImage.h" #include -#include "IntelliHelper/IntelliHelper.h" /*! * \brief The IntelliShapedImage manages a Shapedimage. @@ -31,8 +30,9 @@ public: * \brief The Construcor of the IntelliShapedImage. Given the Image dimensions. * \param width - The width of the Image. * \param height - The height of the Image. + * \param fastRendererOn - Represents the flag for 8bit picture handelling. */ -IntelliShapedImage(int width, int height); +IntelliShapedImage(int width, int height, bool fastRendererOn); /*! * \brief An Destructor. diff --git a/src/IntelliHelper/IntelliRenderSettings.cpp b/src/IntelliHelper/IntelliRenderSettings.cpp new file mode 100644 index 0000000..3424bb6 --- /dev/null +++ b/src/IntelliHelper/IntelliRenderSettings.cpp @@ -0,0 +1,10 @@ +#include "IntelliRenderSettings.h" + +IntelliRenderSettings::IntelliRenderSettings() +{ + +} + +bool IntelliRenderSettings::getFastRenderer(){ + return fastRenderer; +} diff --git a/src/IntelliHelper/IntelliRenderSettings.h b/src/IntelliHelper/IntelliRenderSettings.h new file mode 100644 index 0000000..e932435 --- /dev/null +++ b/src/IntelliHelper/IntelliRenderSettings.h @@ -0,0 +1,20 @@ +#ifndef INTELLIRENDERSETTINGS_H +#define INTELLIRENDERSETTINGS_H + + +class IntelliRenderSettings +{ +public: +IntelliRenderSettings(); + +/*! + * \brief The getfastRenderer gets the value of the flag for the fastRenderer setting. + * \return Returns true if fastRenderer is active else false + */ +bool getFastRenderer(); + +private: +bool fastRenderer = true; +}; + +#endif // INTELLIRENDERSETTINGS_H diff --git a/src/IntelliHelper/IntelliToolsettings.cpp b/src/IntelliHelper/IntelliToolsettings.cpp new file mode 100644 index 0000000..7a4219c --- /dev/null +++ b/src/IntelliHelper/IntelliToolsettings.cpp @@ -0,0 +1,53 @@ +#include "IntelliToolsettings.h" +#include + +IntelliToolsettings::IntelliToolsettings() +{ + lineWidth = 1; + innerAlpha = 255; + Linestyle = LineStyle::SOLID_LINE; +} + +IntelliToolsettings::~IntelliToolsettings(){ + +} + +int IntelliToolsettings::getLineWidth(){ + return lineWidth; +} + +void IntelliToolsettings::setLineWidth(){ + lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); +} + +void IntelliToolsettings::setLineWidth(int LineWidth){ + if(LineWidth < 1) { + LineWidth = 1; + } + else if(LineWidth > 50) { + LineWidth = 50; + } + lineWidth = LineWidth; +} + +int IntelliToolsettings::getInnerAlpha(){ + return this->innerAlpha; +} + +void IntelliToolsettings::setInnerAlpha(){ + this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Aplha Input", "Value",0,0,255,1); +} + +void IntelliToolsettings::setInnerAlpha(int innerAlpha){ + if(innerAlpha < 0) { + innerAlpha = 0; + } + else if(innerAlpha > 255) { + innerAlpha = 255; + } + this->innerAlpha = innerAlpha; +} + +IntelliToolsettings::LineStyle IntelliToolsettings::getLinestyle(){ + return Linestyle; +} diff --git a/src/IntelliHelper/IntelliToolsettings.h b/src/IntelliHelper/IntelliToolsettings.h new file mode 100644 index 0000000..1a63bbc --- /dev/null +++ b/src/IntelliHelper/IntelliToolsettings.h @@ -0,0 +1,29 @@ +#ifndef INTELLITOOLSETTINGS_H +#define INTELLITOOLSETTINGS_H + +class IntelliToolsettings { +public: +/*! + * \brief The LineStyle enum classifing all ways of drawing a line. + */ +enum class LineStyle { + SOLID_LINE, + DOTTED_LINE +}; +IntelliToolsettings(); +virtual ~IntelliToolsettings(); +int getLineWidth(); +void setLineWidth(); +void setLineWidth(int LineWidth); +int getInnerAlpha(); +void setInnerAlpha(); +void setInnerAlpha(int innerAlpha); +LineStyle getLinestyle(); + +private: +int lineWidth; +int innerAlpha; +LineStyle Linestyle; +}; + +#endif // INTELLITOOLSETTINGS_H diff --git a/src/IntelliHelper/IntelliHelper.cpp b/src/IntelliHelper/IntelliTriangulation.cpp similarity index 72% rename from src/IntelliHelper/IntelliHelper.cpp rename to src/IntelliHelper/IntelliTriangulation.cpp index 867a139..d46288a 100644 --- a/src/IntelliHelper/IntelliHelper.cpp +++ b/src/IntelliHelper/IntelliTriangulation.cpp @@ -1,15 +1,15 @@ -#include "IntelliHelper.h" +#include "IntelliTriangulation.h" #include #include #include #define pi 3.1415926535897932384626433832795 -std::vector IntelliHelper::calculateTriangles(std::vector polyPoints){ +std::vector IntelliTriangulation::calculateTriangles(std::vector polyPoints){ // helper for managing the triangle vertices and their state struct TriangleHelper { QPoint vertex; float interiorAngle; - int index; + int idx; bool isTip; }; @@ -19,7 +19,7 @@ std::vector IntelliHelper::calculateTriangles(std::vector poly QPoint BP(point.x()-post.x(), point.y()-post.y()); float topSclar = AP.x()*BP.x()+AP.y()*BP.y(); - float absolute = static_cast(sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.))); + float absolute = static_cast(sqrt(pow(AP.x(),2.)+pow(AP.y(),2.))*sqrt(pow(BP.x(),2.)+pow(BP.y(),2.))); return acos(topSclar/absolute); }; @@ -34,19 +34,19 @@ std::vector IntelliHelper::calculateTriangles(std::vector poly return vec[min]; }; - // get the vertex Index bevor index in relation to the container length - auto getPrev = [](int index, int length){ - return (index-1)>=0 ? (index-1) : (length-1); + // get the vertex idx bevor idx in relation to the container length + auto getPrev = [](int idx, int length){ + return (idx-1)>=0 ? (idx-1) : (length-1); }; - // get the vertex Index after index in relation to the container lenght - auto getPost = [](int index, int length){ - return (index+1)%length; + // get the vertex idx after idx in relation to the container lenght + auto getPost = [](int idx, int length){ + return (idx+1)%length; }; // return if the vertex is a tip auto isTip = [](float angle){ - return static_cast(angle)<(pi/2.); + return static_cast(angle)<(pi/2.); }; std::vector Vertices; @@ -59,7 +59,7 @@ std::vector IntelliHelper::calculateTriangles(std::vector poly int post = getPost(i, static_cast(polyPoints.size())); helper.vertex = polyPoints[static_cast(i)]; - helper.index = i; + helper.idx = i; helper.interiorAngle = calculateInner(polyPoints[static_cast(i)], polyPoints[static_cast(prev)], @@ -72,24 +72,24 @@ std::vector IntelliHelper::calculateTriangles(std::vector poly while(Triangles.size() != polyPoints.size()-2) { Triangle tri; TriangleHelper smallest = getTip(Vertices); - int prev = getPrev(smallest.index, static_cast(Vertices.size())); - int post = getPost(smallest.index, static_cast(Vertices.size())); + int prev = getPrev(smallest.idx, static_cast(Vertices.size())); + int post = getPost(smallest.idx, static_cast(Vertices.size())); // set triangle and push it tri.A = Vertices[static_cast(prev)].vertex; - tri.B = Vertices[static_cast(smallest.index)].vertex; + tri.B = Vertices[static_cast(smallest.idx)].vertex; tri.C = Vertices[static_cast(post)].vertex; Triangles.push_back(tri); // update Vertice array - Vertices.erase(Vertices.begin()+smallest.index); - for(size_t i=static_cast(smallest.index); i(smallest.idx); i(Vertices.size())); @@ -113,9 +113,9 @@ std::vector IntelliHelper::calculateTriangles(std::vector poly return Triangles; } -bool IntelliHelper::isInPolygon(std::vector &triangles, QPoint &point){ +bool IntelliTriangulation::isInPolygon(std::vector &triangles, QPoint &point){ for(auto triangle : triangles) { - if(IntelliHelper::isInTriangle(triangle, point)) { + if(IntelliTriangulation::isInTriangle(triangle, point)) { return true; } } diff --git a/src/IntelliHelper/IntelliHelper.h b/src/IntelliHelper/IntelliTriangulation.h similarity index 87% rename from src/IntelliHelper/IntelliHelper.h rename to src/IntelliHelper/IntelliTriangulation.h index 2af1748..21ebfa3 100644 --- a/src/IntelliHelper/IntelliHelper.h +++ b/src/IntelliHelper/IntelliTriangulation.h @@ -1,5 +1,5 @@ -#ifndef INTELLIHELPER_H -#define INTELLIHELPER_H +#ifndef INTELLITRIANGULATION_H +#define INTELLITRIANGULATION_H #include #include @@ -11,7 +11,7 @@ struct Triangle { QPoint A,B,C; }; -namespace IntelliHelper { +namespace IntelliTriangulation { /*! * \brief A function to get the 2*area of a traingle, using its determinat. @@ -34,9 +34,9 @@ inline bool isInTriangle(Triangle& tri, QPoint& P){ float val1, val2, val3; bool neg, pos; - val1 = IntelliHelper::sign(P,tri.A,tri.B); - val2 = IntelliHelper::sign(P,tri.B,tri.C); - val3 = IntelliHelper::sign(P,tri.C,tri.A); + val1 = IntelliTriangulation::sign(P,tri.A,tri.B); + val2 = IntelliTriangulation::sign(P,tri.B,tri.C); + val3 = IntelliTriangulation::sign(P,tri.C,tri.A); neg = (val1<0.f) || (val2<0.f) || (val3<0.f); pos = (val1>0.f) || (val2>0.f) || (val3>0.f); diff --git a/src/IntelliPhoto.pro b/src/IntelliPhoto.pro index fe7264d..13b6975 100644 --- a/src/IntelliPhoto.pro +++ b/src/IntelliPhoto.pro @@ -21,7 +21,9 @@ SOURCES += \ Image/IntelliRasterImage.cpp \ Image/IntelliShapedImage.cpp \ IntelliHelper/IntelliColorPicker.cpp \ - IntelliHelper/IntelliHelper.cpp \ + IntelliHelper/IntelliRenderSettings.cpp \ + IntelliHelper/IntelliToolsettings.cpp \ + IntelliHelper/IntelliTriangulation.cpp \ Layer/PaintingArea.cpp \ Tool/IntelliTool.cpp \ Tool/IntelliToolCircle.cpp \ @@ -39,7 +41,9 @@ HEADERS += \ Image/IntelliRasterImage.h \ Image/IntelliShapedImage.h \ IntelliHelper/IntelliColorPicker.h \ - IntelliHelper/IntelliHelper.h \ + IntelliHelper/IntelliRenderSettings.h \ + IntelliHelper/IntelliToolsettings.h \ + IntelliHelper/IntelliTriangulation.h \ Layer/PaintingArea.h \ Tool/IntelliTool.h \ Tool/IntelliToolCircle.h \ @@ -63,3 +67,6 @@ ICON = icon.icns qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + Bilder.qrc diff --git a/src/Layer/PaintingArea.cpp b/src/Layer/PaintingArea.cpp index f4f92f9..7dd3e01 100644 --- a/src/Layer/PaintingArea.cpp +++ b/src/Layer/PaintingArea.cpp @@ -21,8 +21,8 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) : QWidget(parent){ this->Tool = nullptr; - this->setLayerDimensions(maxWidth, maxHeight); - this->addLayer(200,200,0,0,ImageType::Shaped_Image); + 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)); @@ -31,7 +31,7 @@ PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget*parent) polygon.push_back(QPoint(000,100)); layerBundle[0].image->setPolygon(polygon); - this->addLayer(200,200,150,150); + this->addLayer(200,200,150,150,IntelliImage::ImageType::RASTERIMAGE); layerBundle[1].image->drawPlain(QColor(0,255,0,255)); layerBundle[1].alpha=200; @@ -53,27 +53,28 @@ void PaintingArea::setLayerDimensions(int maxWidth, int maxHeight){ } -int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){ +int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, IntelliImage::ImageType type){ LayerObject newLayer; newLayer.width = width; newLayer.height = height; newLayer.widthOffset = widthOffset; newLayer.heightOffset = heightOffset; - if(type==ImageType::Raster_Image) { - newLayer.image = new IntelliRasterImage(width,height); - }else if(type==ImageType::Shaped_Image) { - newLayer.image = new IntelliShapedImage(width, height); + if(type==IntelliImage::ImageType::RASTERIMAGE) { + newLayer.image = new IntelliRasterImage(width,height,renderSettings.getFastRenderer()); + }else if(type==IntelliImage::ImageType::SHAPEDIMAGE) { + newLayer.image = new IntelliShapedImage(width, height, renderSettings.getFastRenderer()); } newLayer.alpha = 255; this->layerBundle.push_back(newLayer); - return static_cast(layerBundle.size())-1; + activeLayer = static_cast(layerBundle.size())-1; + return activeLayer; } -void PaintingArea::deleteLayer(int index){ - if(index(layerBundle.size())) { - this->layerBundle.erase(layerBundle.begin()+index); - if(activeLayer>=index) { +void PaintingArea::deleteLayer(int idx){ + if(idx(layerBundle.size())) { + this->layerBundle.erase(layerBundle.begin()+idx); + if(activeLayer>=idx && activeLayer != 0) { activeLayer--; } } @@ -86,15 +87,15 @@ void PaintingArea::slotDeleteActiveLayer(){ } } -void PaintingArea::setLayerActive(int index){ - if(index>=0&&index(layerBundle.size())) { - this->activeLayer=index; +void PaintingArea::setLayerActive(int idx){ + if(idx>=0&&idx(layerBundle.size())) { + this->activeLayer=idx; } } -void PaintingArea::setLayerAlpha(int index, int alpha){ - if(index>=0&&index(layerBundle.size())) { - layerBundle[static_cast(index)].alpha=alpha; +void PaintingArea::setLayerAlpha(int idx, int alpha){ + if(idx>=0&&idx(layerBundle.size())) { + layerBundle[static_cast(idx)].alpha=alpha; } } @@ -104,7 +105,7 @@ bool PaintingArea::open(const QString &filePath){ return false; } IntelliImage* active = layerBundle[static_cast(activeLayer)].image; - bool open = active->loadImage(filePath); + bool open = active->loadImage(filePath); active->calculateVisiblity(); update(); return open; @@ -115,19 +116,19 @@ bool PaintingArea::save(const QString &filePath, const char*fileFormat){ if(layerBundle.size()==0) { return false; } - this->drawLayers(true); + this->drawLayers(true); if(!strcmp(fileFormat,"PNG")) { QImage visibleImage = Canvas->convertToFormat(QImage::Format_Indexed8); fileFormat = "png"; - if (visibleImage.save(filePath, fileFormat)) { + if (visibleImage.save(filePath, fileFormat)) { return true; } else { return false; } } - if (Canvas->save(filePath, fileFormat)) { + if (Canvas->save(filePath, fileFormat)) { return true; } else { return false; @@ -145,11 +146,25 @@ void PaintingArea::floodFill(int r, int g, int b, int a){ } void PaintingArea::movePositionActive(int x, int y){ + if(Tool!=nullptr) { + if(Tool->getIsDrawing()) { + IntelliTool* temp = copyActiveTool(); + delete this->Tool; + this->Tool = temp; + } + } 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; + } + } if(idx==1) { this->selectLayerUp(); }else if(idx==-1) { @@ -158,6 +173,13 @@ 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())) { this->setLayerActive(a); } @@ -179,44 +201,52 @@ void PaintingArea::colorPickerSwapColors(){ void PaintingArea::createPenTool(){ delete this->Tool; - Tool = new IntelliToolPen(this, &colorPicker); + Tool = new IntelliToolPen(this, &colorPicker, &Toolsettings); } void PaintingArea::createPlainTool(){ delete this->Tool; - Tool = new IntelliToolPlainTool(this, &colorPicker); + Tool = new IntelliToolPlainTool(this, &colorPicker, &Toolsettings); } void PaintingArea::createLineTool(){ delete this->Tool; - Tool = new IntelliToolLine(this, &colorPicker); + Tool = new IntelliToolLine(this, &colorPicker, &Toolsettings); } void PaintingArea::createRectangleTool(){ delete this->Tool; - Tool = new IntelliToolRectangle(this, &colorPicker); + Tool = new IntelliToolRectangle(this, &colorPicker, &Toolsettings); } void PaintingArea::createCircleTool(){ delete this->Tool; - Tool = new IntelliToolCircle(this, &colorPicker); + Tool = new IntelliToolCircle(this, &colorPicker, &Toolsettings); } void PaintingArea::createPolygonTool(){ delete this->Tool; - Tool = new IntelliToolPolygon(this, &colorPicker); + Tool = new IntelliToolPolygon(this, &colorPicker, &Toolsettings); } void PaintingArea::createFloodFillTool(){ delete this->Tool; - Tool = new IntelliToolFloodFill(this, &colorPicker); + Tool = new IntelliToolFloodFill(this, &colorPicker, &Toolsettings); } int PaintingArea::getWidthOfActive(){ - return this->layerBundle[static_cast(activeLayer)].width; + return this->layerBundle[static_cast(activeLayer)].width; } int PaintingArea::getHeightOfActive(){ - return this->layerBundle[static_cast(activeLayer)].height; + return this->layerBundle[static_cast(activeLayer)].height; +} + +IntelliImage::ImageType PaintingArea::getTypeOfImageRealLayer(){ + return this->layerBundle[static_cast(activeLayer)].image->getTypeOfImage(); +} + +std::vector PaintingArea::getPolygonDataOfRealLayer(){ + return this->layerBundle[static_cast(activeLayer)].image->getPolygonData(); } // If a mouse button is pressed check if it was the @@ -225,8 +255,8 @@ int PaintingArea::getHeightOfActive(){ void PaintingArea::mousePressEvent(QMouseEvent*event){ if(Tool == nullptr) return; - int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; - int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; + int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; + int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; if(event->button() == Qt::LeftButton) { Tool->onMouseLeftPressed(x, y); }else if(event->button() == Qt::RightButton) { @@ -241,8 +271,8 @@ void PaintingArea::mousePressEvent(QMouseEvent*event){ void PaintingArea::mouseMoveEvent(QMouseEvent*event){ if(Tool == nullptr) return; - int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; - int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; + int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; + int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; Tool->onMouseMoved(x, y); update(); } @@ -251,8 +281,8 @@ void PaintingArea::mouseMoveEvent(QMouseEvent*event){ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){ if(Tool == nullptr) return; - int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; - int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; + int x = event->x()-layerBundle[static_cast(activeLayer)].widthOffset; + int y = event->y()-layerBundle[static_cast(activeLayer)].heightOffset; if(event->button() == Qt::LeftButton) { Tool->onMouseLeftReleased(x, y); }else if(event->button() == Qt::RightButton) { @@ -262,10 +292,12 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent*event){ } void PaintingArea::wheelEvent(QWheelEvent*event){ - QPoint numDegrees = event->angleDelta() / 8; - if(!numDegrees.isNull()) { - QPoint numSteps = numDegrees / 15; - Tool->onWheelScrolled(numSteps.y()* -1); + if(this->Tool != nullptr) { + QPoint numDegrees = event->angleDelta() / 8; + if(!numDegrees.isNull()) { + QPoint numSteps = numDegrees / 15; + Tool->onWheelScrolled(numSteps.y()* -1); + } } } @@ -273,7 +305,7 @@ void PaintingArea::wheelEvent(QWheelEvent*event){ // The QPaintEvent is sent to widgets that need to // update themselves void PaintingArea::paintEvent(QPaintEvent*event){ - this->drawLayers(); + this->drawLayers(); QPainter painter(this); QRect dirtyRec = event->rect(); @@ -293,15 +325,15 @@ void PaintingArea::resizeLayer(QImage*image_res, const QSize &newSize){ } void PaintingArea::selectLayerUp(){ - if(activeLayer!=-1 && static_cast(activeLayer)(activeLayer)], layerBundle[static_cast(activeLayer+1)]); + if(activeLayer!=-1 && static_cast(activeLayer)(activeLayer)], layerBundle[static_cast(activeLayer+1)]); activeLayer++; } } void PaintingArea::selectLayerDown(){ if(activeLayer!=-1 && activeLayer>0) { - std::swap(layerBundle[static_cast(activeLayer)], layerBundle[static_cast(activeLayer-1)]); + std::swap(layerBundle[static_cast(activeLayer)], layerBundle[static_cast(activeLayer-1)]); activeLayer--; } } @@ -345,11 +377,32 @@ void PaintingArea::createTempTopLayer(int idx){ if(idx>=0) { LayerObject newLayer; newLayer.alpha = 255; - newLayer.height = layerBundle[static_cast(idx)].height; - newLayer.width = layerBundle[static_cast(idx)].width; - newLayer.heightOffset = layerBundle[static_cast(idx)].heightOffset; - newLayer.widthOffset = layerBundle[static_cast(idx)].widthOffset; - newLayer.image = layerBundle[static_cast(idx)].image->getDeepCopy(); + newLayer.height = layerBundle[static_cast(idx)].height; + newLayer.width = layerBundle[static_cast(idx)].width; + newLayer.heightOffset = layerBundle[static_cast(idx)].heightOffset; + newLayer.widthOffset = layerBundle[static_cast(idx)].widthOffset; + newLayer.image = layerBundle[static_cast(idx)].image->getDeepCopy(); layerBundle.insert(layerBundle.begin()+idx+1,newLayer); } } + +IntelliTool* PaintingArea::copyActiveTool(){ + switch(Tool->getTooltype()) { + case IntelliTool::Tooltype::CIRCLE: return new IntelliToolCircle(this,&colorPicker, &Toolsettings); + case IntelliTool::Tooltype::FLOODFILL: return new IntelliToolFloodFill(this,&colorPicker, &Toolsettings); + case IntelliTool::Tooltype::LINE: return new IntelliToolLine(this,&colorPicker, &Toolsettings); + case IntelliTool::Tooltype::PEN: return new IntelliToolPen(this,&colorPicker, &Toolsettings); + case IntelliTool::Tooltype::PLAIN: return new IntelliToolPlainTool(this,&colorPicker, &Toolsettings); + case IntelliTool::Tooltype::POLYGON: return new IntelliToolPolygon(this,&colorPicker, &Toolsettings); + case IntelliTool::Tooltype::RECTANGLE: return new IntelliToolRectangle(this,&colorPicker, &Toolsettings); + default: return nullptr; + } +} + +int PaintingArea::getNumberOfActiveLayer(){ + return activeLayer; +} + +IntelliImage* PaintingArea::getImageOfActiveLayer(){ + return layerBundle[activeLayer].image; +} diff --git a/src/Layer/PaintingArea.h b/src/Layer/PaintingArea.h index 05267c8..7bb1ee6 100644 --- a/src/Layer/PaintingArea.h +++ b/src/Layer/PaintingArea.h @@ -7,6 +7,7 @@ #include #include #include +#include "GUI/IntelliPhotoGui.h" #include "Image/IntelliImage.h" #include "Image/IntelliRasterImage.h" #include "Image/IntelliShapedImage.h" @@ -21,13 +22,13 @@ * \param widthOffset - Stores the number of pixles from the left side of the painting area * \param heightOffset - Stores the number of pixles from the top of the painting area */ -struct LayerObject{ - IntelliImage* image; - int width; - int height; - int widthOffset; - int heightOffset; - int alpha=255; +struct LayerObject { + IntelliImage* image; + int width; + int height; + int widthOffset; + int heightOffset; + int alpha=255; }; /*! @@ -35,179 +36,193 @@ struct LayerObject{ */ class PaintingArea : public QWidget { - // Declares our class as a QObject which is the base class - // for all Qt objects - // QObjects handle events - Q_OBJECT - friend IntelliTool; +// Declares our class as a QObject which is the base class +// for all Qt objects +// QObjects handle events +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 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, ImageType type = ImageType::Raster_Image); - /*! - * \brief The addLayerAt adds a layer to the current project/ painting area at a specific position in the layer stack - * \param idx - ID 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, ImageType type = ImageType::Raster_Image); - /*! - * \brief The deleteLayer method removes a layer at a given index - * \param index - The index of the layer to be removed - */ - void deleteLayer(int index); - /*! - * \brief The setLayerToActive method marks a specific layer as active - * \param index - Index of the layer to be active - */ - void setLayerActive(int index); - /*! - * \brief The setAlphaOfLayer method sets the alpha value of a specific layer - * \param index - Index of the layer where the change should be applied - * \param alpha - New alpha value of the layer - */ - void setLayerAlpha(int index, 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 id 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(); + +std::vector getPolygonDataOfRealLayer(); + +int getNumberOfActiveLayer(); + +IntelliImage* getImageOfActiveLayer(); + +IntelliToolsettings Toolsettings; +IntelliColorPicker colorPicker; public slots: - // Events to handle - /*! - * \brief The slotActivateLayer method handles the event of selecting one layer as active - * \param a - Index of the layer to be active - */ - void slotActivateLayer(int a); - /*! - * \brief The slotDeleteActiveLayer method handles the deletion of the active layer - */ - void slotDeleteActiveLayer(); +// Events to handle +/*! + * \brief The slotActivateLayer method handles the event of selecting one layer as active + * \param a - idx of the layer to be active + */ +void slotActivateLayer(int a); +/*! + * \brief The slotDeleteActiveLayer method handles the deletion of the active layer + */ +void slotDeleteActiveLayer(); protected: - void mousePressEvent(QMouseEvent *event) override; - void mouseMoveEvent(QMouseEvent *event) override; - void mouseReleaseEvent(QMouseEvent *event) override; +void mousePressEvent(QMouseEvent*event) override; +void mouseMoveEvent(QMouseEvent*event) override; +void mouseReleaseEvent(QMouseEvent*event) override; - void wheelEvent(QWheelEvent *event) override; - // Updates the painting area where we are painting - void paintEvent(QPaintEvent *event) override; +void wheelEvent(QWheelEvent*event) override; +// Updates the painting area where we are painting +void paintEvent(QPaintEvent*event) override; - // Makes sure the area we are drawing on remains - // as large as the widget - void resizeEvent(QResizeEvent *event) override; +// Makes sure the area we are drawing on remains +// as large as the widget +void resizeEvent(QResizeEvent*event) override; private: - void setLayerDimensions(int maxWidth, int maxHeight); - void selectLayerUp(); - void selectLayerDown(); +void setLayerDimensions(int maxWidth, int maxHeight); +void selectLayerUp(); +void selectLayerDown(); +IntelliTool* copyActiveTool(); - QImage* Canvas; - int maxWidth; - int maxHeight; +QImage* Canvas; +int maxWidth; +int maxHeight; - IntelliTool* Tool; - IntelliColorPicker colorPicker; +IntelliRenderSettings renderSettings; +IntelliTool* Tool; +IntelliPhotoGui* DumpyGui; - std::vector layerBundle; - int activeLayer=-1; +std::vector layerBundle; +int activeLayer=-1; - void drawLayers(bool forSaving=false); +void drawLayers(bool forSaving=false); - void resizeLayer(QImage *image_res, const QSize &newSize); +void resizeLayer(QImage*image_res, const QSize &newSize); - // Helper for Tool - // TODO: Always create this layer on top and return the id here! - void createTempTopLayer(int idx); +// Helper for Tool +// TODO: Always create this layer on top and return the id here! +void createTempTopLayer(int idx); }; #endif diff --git a/src/Tool/IntelliTool.cpp b/src/Tool/IntelliTool.cpp index b20c4d1..91979e3 100644 --- a/src/Tool/IntelliTool.cpp +++ b/src/Tool/IntelliTool.cpp @@ -1,9 +1,10 @@ #include "IntelliTool.h" #include "Layer/PaintingArea.h" -IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){ +IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings){ this->Area=Area; this->colorPicker=colorPicker; + this->Toolsettings=Toolsettings; } @@ -49,8 +50,8 @@ void IntelliTool::onWheelScrolled(int value){ void IntelliTool::createToolLayer(){ Area->createTempTopLayer(Area->activeLayer); - this->activeLayer=&Area->layerBundle[static_cast(Area->activeLayer)]; - this->Canvas=&Area->layerBundle[static_cast(Area->activeLayer+1)]; + this->activeLayer=&Area->layerBundle[static_cast(Area->activeLayer)]; + this->Canvas=&Area->layerBundle[static_cast(Area->activeLayer+1)]; } void IntelliTool::mergeToolLayer(){ @@ -73,9 +74,18 @@ void IntelliTool::mergeToolLayer(){ activeLayer->image->imageData.setPixelColor(x, y, clr_0); } } + Area->DumpyGui->UpdateGui(); } void IntelliTool::deleteToolLayer(){ Area->deleteLayer(Area->activeLayer+1); this->Canvas=nullptr; } + +IntelliTool::Tooltype IntelliTool::getTooltype(){ + return ActiveType; +} + +bool IntelliTool::getIsDrawing(){ + return isDrawing; +} diff --git a/src/Tool/IntelliTool.h b/src/Tool/IntelliTool.h index 26b89be..4353018 100644 --- a/src/Tool/IntelliTool.h +++ b/src/Tool/IntelliTool.h @@ -2,6 +2,7 @@ #define Intelli_Tool_H #include "IntelliHelper/IntelliColorPicker.h" +#include "IntelliHelper/IntelliToolsettings.h" #include struct LayerObject; @@ -11,6 +12,16 @@ class PaintingArea; * \brief An abstract class that manages the basic events, like mouse clicks or scrolls events. */ class IntelliTool { +public: +enum class Tooltype { + CIRCLE, + FLOODFILL, + LINE, + PEN, + PLAIN, + POLYGON, + RECTANGLE +}; private: /*! * \brief A function that creates a layer to draw on. @@ -32,11 +43,15 @@ protected: */ PaintingArea* Area; +Tooltype ActiveType; + /*! * \brief A pointer to the IntelliColorPicker of the PaintingArea to interact with, and get the colors. */ IntelliColorPicker* colorPicker; +IntelliToolsettings* Toolsettings; + /*! * \brief A pointer to the underlying active Layer, do not work on this. This is used for data grabbing or previews. */ @@ -58,7 +73,7 @@ public: * \param Area - The general PaintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief An abstract Destructor. @@ -106,6 +121,9 @@ virtual void onWheelScrolled(int value); */ virtual void onMouseMoved(int x, int y); +Tooltype getTooltype(); + +bool getIsDrawing(); }; #endif diff --git a/src/Tool/IntelliToolCircle.cpp b/src/Tool/IntelliToolCircle.cpp index 33a5016..b8e9d59 100644 --- a/src/Tool/IntelliToolCircle.cpp +++ b/src/Tool/IntelliToolCircle.cpp @@ -3,48 +3,47 @@ #include "QInputDialog" #include -IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ - this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); - this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1); +IntelliToolCircle::IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::CIRCLE; } IntelliToolCircle::~IntelliToolCircle(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolCircle::drawCircle(int radius){ int outer = radius+20; QColor inner = this->colorPicker->getSecondColor(); - inner.setAlpha(innerAlpha); + inner.setAlpha(Toolsettings->getInnerAlpha()); int yMin, yMax, xMin, xMax; yMin = centerPoint.y()-radius; yMax = centerPoint.y()+radius; // x = x0+-sqrt(r2-(y-y0)2) for(int i=yMin; i<=yMax; i++) { - xMin = static_cast(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); - xMax = static_cast(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); + xMin = static_cast(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); + xMax = static_cast(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); this->Canvas->image->drawLine(QPoint(xMin,i), QPoint(xMax,i),inner,1); } //TODO implement circle drawing algorithm bresenham - radius = static_cast(radius +(this->borderWidth/2.)-1.); + radius = static_cast(radius +(Toolsettings->getLineWidth()/2.)-1.); yMin = (centerPoint.y()-radius); yMax = (centerPoint.y()+radius); for(int i=yMin; i<=yMax; i++) { - xMin = static_cast(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); - xMax = static_cast(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); - this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),borderWidth); - this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),borderWidth); + xMin = static_cast(centerPoint.x()-sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); + xMax = static_cast(centerPoint.x()+sqrt(pow(radius,2)-pow(i-centerPoint.y(),2))); + this->Canvas->image->drawPoint(QPoint(xMin,i), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); + this->Canvas->image->drawPoint(QPoint(xMax,i), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); } xMin = (centerPoint.x()-radius); xMax = (centerPoint.x()+radius); for(int i=xMin; i<=xMax; i++) { - int yMin = static_cast(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); - int yMax = static_cast(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); - this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),borderWidth); - this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),borderWidth); + int yMin = static_cast(centerPoint.y()-sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); + int yMax = static_cast(centerPoint.y()+sqrt(pow(radius,2)-pow(i-centerPoint.x(),2))); + this->Canvas->image->drawPoint(QPoint(i, yMin), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); + this->Canvas->image->drawPoint(QPoint(i, yMax), colorPicker->getFirstColor(),Toolsettings->getLineWidth()); } } @@ -70,10 +69,7 @@ void IntelliToolCircle::onMouseLeftReleased(int x, int y){ void IntelliToolCircle::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->borderWidth+=value; - if(this->borderWidth<=0) { - this->borderWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } void IntelliToolCircle::onMouseMoved(int x, int y){ diff --git a/src/Tool/IntelliToolCircle.h b/src/Tool/IntelliToolCircle.h index 94f34e1..d75665d 100644 --- a/src/Tool/IntelliToolCircle.h +++ b/src/Tool/IntelliToolCircle.h @@ -19,22 +19,13 @@ void drawCircle(int radius); */ QPoint centerPoint; -/*! - * \brief The alpha value of the inner circle. - */ -int innerAlpha; - -/*! - * \brief The width of the outer circle edge. - */ -int borderWidth; public: /*! * \brief A constructor setting the general paintingArea and colorPicker. And reading in the inner alpha and edgeWidth. * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliToolCircle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief A Destructor. diff --git a/src/Tool/IntelliToolFloodFill.cpp b/src/Tool/IntelliToolFloodFill.cpp index d0dcc34..cb135f8 100644 --- a/src/Tool/IntelliToolFloodFill.cpp +++ b/src/Tool/IntelliToolFloodFill.cpp @@ -5,12 +5,13 @@ #include #include -IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ +IntelliToolFloodFill::IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::FLOODFILL; } IntelliToolFloodFill::~IntelliToolFloodFill(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolFloodFill::onMouseRightPressed(int x, int y){ diff --git a/src/Tool/IntelliToolFloodFill.h b/src/Tool/IntelliToolFloodFill.h index 81412ba..3e93699 100644 --- a/src/Tool/IntelliToolFloodFill.h +++ b/src/Tool/IntelliToolFloodFill.h @@ -14,7 +14,7 @@ public: * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliToolFloodFill(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief A Destructor. diff --git a/src/Tool/IntelliToolLine.cpp b/src/Tool/IntelliToolLine.cpp index 71f67c0..97daa85 100644 --- a/src/Tool/IntelliToolLine.cpp +++ b/src/Tool/IntelliToolLine.cpp @@ -3,15 +3,13 @@ #include "QColorDialog" #include "QInputDialog" -IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ - this->lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); - //create checkbox or scroll dialog to get line style - this->lineStyle = LineStyle::SOLID_LINE; +IntelliToolLine::IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::LINE; } IntelliToolLine::~IntelliToolLine(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolLine::onMouseRightPressed(int x, int y){ @@ -25,7 +23,7 @@ void IntelliToolLine::onMouseRightReleased(int x, int y){ void IntelliToolLine::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->lineStartingPoint=QPoint(x,y); - this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),lineWidth); + this->Canvas->image->drawPoint(lineStartingPoint, colorPicker->getFirstColor(),Toolsettings->getLineWidth()); Canvas->image->calculateVisiblity(); } @@ -35,24 +33,21 @@ void IntelliToolLine::onMouseLeftReleased(int x, int y){ void IntelliToolLine::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->lineWidth+=value; - if(this->lineWidth<=0) { - this->lineWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } void IntelliToolLine::onMouseMoved(int x, int y){ if(this->isDrawing) { this->Canvas->image->drawPlain(Qt::transparent); QPoint next(x,y); - switch(lineStyle) { - case LineStyle::SOLID_LINE: - this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),lineWidth); + switch(Toolsettings->getLinestyle()) { + case IntelliToolsettings::LineStyle::SOLID_LINE: + this->Canvas->image->drawLine(lineStartingPoint,next,colorPicker->getFirstColor(),Toolsettings->getLineWidth()); break; - case LineStyle::DOTTED_LINE: + case IntelliToolsettings::LineStyle::DOTTED_LINE: QPoint p1 =lineStartingPoint.x() <= next.x() ? lineStartingPoint : next; 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 m = static_cast(static_cast(p2.y()-p1.y())/static_cast(p2.x()-p1.x())+0.5f); int c = lineStartingPoint.y()-lineStartingPoint.x()*m; break; diff --git a/src/Tool/IntelliToolLine.h b/src/Tool/IntelliToolLine.h index c134c34..1bae946 100644 --- a/src/Tool/IntelliToolLine.h +++ b/src/Tool/IntelliToolLine.h @@ -4,14 +4,6 @@ #include "QPoint" -/*! - * \brief The LineStyle enum classifing all ways of drawing a line. - */ -enum class LineStyle { - SOLID_LINE, - DOTTED_LINE -}; - /*! * \brief The IntelliToolFloodFill class represents a tool to draw a line. */ @@ -21,15 +13,6 @@ class IntelliToolLine : public IntelliTool { */ QPoint lineStartingPoint; -/*! - * \brief The width of the line to draw. - */ -int lineWidth; - -/*! - * \brief The style of the line. Apropriate to LineStyle. - */ -LineStyle lineStyle; public: /*! @@ -37,7 +20,7 @@ public: * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief An abstract Destructor. diff --git a/src/Tool/IntelliToolPen.cpp b/src/Tool/IntelliToolPen.cpp index 30ff5fe..70f2dc3 100644 --- a/src/Tool/IntelliToolPen.cpp +++ b/src/Tool/IntelliToolPen.cpp @@ -4,13 +4,13 @@ #include "QColorDialog" #include "QInputDialog" -IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ - this->penWidth = QInputDialog::getInt(nullptr, "Pen width", "Width:", 1,0, 50, 1); +IntelliToolPen::IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::PEN; } IntelliToolPen::~IntelliToolPen(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolPen::onMouseRightPressed(int x, int y){ @@ -24,7 +24,7 @@ void IntelliToolPen::onMouseRightReleased(int x, int y){ void IntelliToolPen::onMouseLeftPressed(int x, int y){ IntelliTool::onMouseLeftPressed(x,y); this->previousPoint=QPoint(x,y); - this->Canvas->image->drawPixel(previousPoint, colorPicker->getFirstColor()); + this->Canvas->image->drawPoint(previousPoint, colorPicker->getFirstColor(), Toolsettings->getLineWidth()); Canvas->image->calculateVisiblity(); } @@ -35,7 +35,7 @@ void IntelliToolPen::onMouseLeftReleased(int x, int y){ void IntelliToolPen::onMouseMoved(int x, int y){ if(this->isDrawing) { QPoint newPoint(x,y); - this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), penWidth); + this->Canvas->image->drawLine(this->previousPoint, newPoint, colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->previousPoint=newPoint; } IntelliTool::onMouseMoved(x,y); @@ -43,8 +43,5 @@ void IntelliToolPen::onMouseMoved(int x, int y){ void IntelliToolPen::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->penWidth+=value; - if(this->penWidth<=0) { - this->penWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } diff --git a/src/Tool/IntelliToolPen.h b/src/Tool/IntelliToolPen.h index 1a8985e..39aab9e 100644 --- a/src/Tool/IntelliToolPen.h +++ b/src/Tool/IntelliToolPen.h @@ -4,14 +4,11 @@ #include "IntelliTool.h" #include "QColor" #include "QPoint" + /*! * \brief The IntelliToolPen class represents a tool to draw a line. */ class IntelliToolPen : public IntelliTool { -/*! - * \brief penWidth - The width of the Pen while drawing. - */ -int penWidth; /*! * \brief point - Represents the previous point to help drawing a line. */ @@ -22,7 +19,7 @@ public: * \param Area - The general PaintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief A Destructor. */ diff --git a/src/Tool/IntelliToolPlain.cpp b/src/Tool/IntelliToolPlain.cpp index 092c3c8..13bce09 100644 --- a/src/Tool/IntelliToolPlain.cpp +++ b/src/Tool/IntelliToolPlain.cpp @@ -2,12 +2,13 @@ #include "Layer/PaintingArea.h" #include "QColorDialog" -IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ +IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::PLAIN; } IntelliToolPlainTool::~IntelliToolPlainTool(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){ diff --git a/src/Tool/IntelliToolPlain.h b/src/Tool/IntelliToolPlain.h index 08a79fc..c4b294c 100644 --- a/src/Tool/IntelliToolPlain.h +++ b/src/Tool/IntelliToolPlain.h @@ -13,7 +13,7 @@ public: * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolPlainTool(PaintingArea*Area, IntelliColorPicker* colorPicker); +IntelliToolPlainTool(PaintingArea*Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief A Destructor. */ diff --git a/src/Tool/IntelliToolPolygon.cpp b/src/Tool/IntelliToolPolygon.cpp index e834126..452c2bc 100644 --- a/src/Tool/IntelliToolPolygon.cpp +++ b/src/Tool/IntelliToolPolygon.cpp @@ -1,46 +1,67 @@ #include "IntelliToolPolygon.h" #include "Layer/PaintingArea.h" -#include #include #include +#include -IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ - this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); - lineWidth = QInputDialog::getInt(nullptr,"Line Width Input", "Width",1,1,50,1); +IntelliToolPolygon::IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ isPointNearStart = false; isDrawing = false; + isInside = false; + this->ActiveType = Tooltype::POLYGON; } IntelliToolPolygon::~IntelliToolPolygon(){ - + if(isDrawing) { + IntelliTool::onMouseRightPressed(0,0); + } } void IntelliToolPolygon::onMouseLeftPressed(int x, int y){ - if(!isDrawing && 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); + } + else if(!isDrawing && Area->getTypeOfImageRealLayer() == IntelliImage::ImageType::RASTERIMAGE && x > 0 && y > 0 && xgetWidthOfActive() && ygetHeightOfActive()) { + isInside = true; + } + + if(isInside && !isDrawing) { IntelliTool::onMouseLeftPressed(x,y); QPoint drawingPoint = QPoint(x,y); isDrawing = true; QPointList.push_back(drawingPoint); - this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawPoint(QPointList.back(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->calculateVisiblity(); } else if(isDrawing && isNearStart(x,y,QPointList.front())) { - isPointNearStart = true; - this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), lineWidth); - this->Canvas->image->calculateVisiblity(); + if(QPointList.size() > 2) { + isPointNearStart = true; + this->Canvas->image->drawLine(QPointList.back(), QPointList.front(), colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->calculateVisiblity(); + } + else{ + isInside = false; + isDrawing = false; + QPointList.clear(); + IntelliTool::onMouseRightPressed(x,y); + } + } else if(isDrawing) { QPoint drawingPoint(x,y); QPointList.push_back(drawingPoint); - this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), lineWidth); + this->Canvas->image->drawLine(QPointList[QPointList.size() - 2], QPointList[QPointList.size() - 1], colorPicker->getFirstColor(), Toolsettings->getLineWidth()); this->Canvas->image->calculateVisiblity(); } } void IntelliToolPolygon::onMouseRightPressed(int x, int y){ + isInside = false; isDrawing = false; isPointNearStart = false; QPointList.clear(); @@ -48,24 +69,25 @@ void IntelliToolPolygon::onMouseRightPressed(int x, int y){ } void IntelliToolPolygon::onMouseLeftReleased(int x, int y){ - if(isPointNearStart && QPointList.size() > 1) { + if(isPointNearStart) { + isInside = false; isPointNearStart = false; isDrawing = false; - std::vector Triangles = IntelliHelper::calculateTriangles(QPointList); + std::vector Triangles = IntelliTriangulation::calculateTriangles(QPointList); QPoint Point; QColor colorTwo(colorPicker->getSecondColor()); - colorTwo.setAlpha(innerAlpha); + 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(IntelliHelper::isInPolygon(Triangles,Point)) { + 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(), lineWidth); + 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); @@ -79,12 +101,7 @@ void IntelliToolPolygon::onMouseRightReleased(int x, int y){ void IntelliToolPolygon::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); if(!isDrawing) { - if(lineWidth + value < 10) { - lineWidth += value; - } - if(lineWidth < 1) { - lineWidth = 1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth() + value); } } @@ -96,7 +113,7 @@ bool IntelliToolPolygon::isNearStart(int x, int y, QPoint Startpoint){ bool isNear = false; int StartX = Startpoint.x(); int StartY = Startpoint.y(); - int valueToNear = 10; + int valueToNear = 5; for(int i = StartX - valueToNear; i < StartX + valueToNear; i++) { for(int j = StartY - valueToNear; j < StartY + valueToNear; j++) { diff --git a/src/Tool/IntelliToolPolygon.h b/src/Tool/IntelliToolPolygon.h index 297173f..920a556 100644 --- a/src/Tool/IntelliToolPolygon.h +++ b/src/Tool/IntelliToolPolygon.h @@ -2,7 +2,7 @@ #define INTELLITOOLPOLYGON_H #include "IntelliTool.h" -#include "IntelliHelper/IntelliHelper.h" +#include "IntelliHelper/IntelliTriangulation.h" #include #include /*! @@ -19,26 +19,21 @@ class IntelliToolPolygon : public IntelliTool */ bool isNearStart(int x, int y, QPoint Startpoint); -/*! - * \brief LineWidth of the drawing polygon. - */ -int lineWidth; - /*! * \brief IsDrawing true while drawing, else false. */ bool isDrawing; +/*! + * \brief isInside Checks if Point is inside Image + */ +bool isInside; + /*! * \brief PointIsNearStart true, when last click near startpoint, else false. */ bool isPointNearStart; -/*! - * \brief The alpha value of the inner circle. - */ -int innerAlpha; - /*! * \brief QPointList list of all points of the polygon. */ @@ -49,7 +44,7 @@ public: * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliToolPolygon(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief A Destructor. */ diff --git a/src/Tool/IntelliToolRectangle.cpp b/src/Tool/IntelliToolRectangle.cpp index 8a429fa..29fa038 100644 --- a/src/Tool/IntelliToolRectangle.cpp +++ b/src/Tool/IntelliToolRectangle.cpp @@ -2,32 +2,31 @@ #include "Layer/PaintingArea.h" #include "QInputDialog" -IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker) - : IntelliTool(Area, colorPicker){ - this->innerAlpha = QInputDialog::getInt(nullptr,"Inner Alpha Value", "Value:", 0,0,255,1); - this->borderWidth = QInputDialog::getInt(nullptr,"Outer edge width", "Value:", 0,1,255,1); +IntelliToolRectangle::IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings) + : IntelliTool(Area, colorPicker, Toolsettings){ + this->ActiveType = Tooltype::RECTANGLE; } IntelliToolRectangle::~IntelliToolRectangle(){ - + IntelliTool::onMouseRightPressed(0,0); } void IntelliToolRectangle::drawRectangle(QPoint otherCorner){ - int xMin = std::min(originCorner.x(), otherCorner.x()); - int xMax = std::max(originCorner.x(), otherCorner.x()); + int xMin = std::min(originCorner.x(), otherCorner.x()); + int xMax = std::max(originCorner.x(), otherCorner.x()); - int yMin = std::min(originCorner.y(), otherCorner.y()); - int yMax = std::max(originCorner.y(), otherCorner.y()); + int yMin = std::min(originCorner.y(), otherCorner.y()); + int yMax = std::max(originCorner.y(), otherCorner.y()); QColor clr = colorPicker->getSecondColor(); - clr.setAlpha(innerAlpha); + clr.setAlpha(Toolsettings->getInnerAlpha()); for(int y=yMin; y<=yMax; y++) { this->Canvas->image->drawLine(QPoint(xMin,y), QPoint(xMax, y), clr, 1); } - this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth); - this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth); - this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), borderWidth); - this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), borderWidth); + this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->drawLine(QPoint(xMin, yMin),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMin, yMax), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); + this->Canvas->image->drawLine(QPoint(xMax, yMax),QPoint(xMax, yMin), this->colorPicker->getFirstColor(), Toolsettings->getLineWidth()); } void IntelliToolRectangle::onMouseRightPressed(int x, int y){ @@ -60,8 +59,5 @@ void IntelliToolRectangle::onMouseMoved(int x, int y){ void IntelliToolRectangle::onWheelScrolled(int value){ IntelliTool::onWheelScrolled(value); - this->borderWidth+=value; - if(this->borderWidth<=0) { - this->borderWidth=1; - } + Toolsettings->setLineWidth(Toolsettings->getLineWidth()+value); } diff --git a/src/Tool/IntelliToolRectangle.h b/src/Tool/IntelliToolRectangle.h index 31d9edd..041e860 100644 --- a/src/Tool/IntelliToolRectangle.h +++ b/src/Tool/IntelliToolRectangle.h @@ -19,21 +19,13 @@ void drawRectangle(QPoint otherCorner); * \brief origincorner - The first corner point of the rectangle. */ QPoint originCorner; -/*! - * \brief alphaInner- Represents the alpha value of the inside. - */ -int innerAlpha; -/*! - * \brief edgeWidth - The width of the rectangle edges. - */ -int borderWidth; public: /*! * \brief A constructor setting the general paintingArea and colorPicker. And reading in the alphaInner and edgeWidth. * \param Area - The general paintingArea used by the project. * \param colorPicker - The general colorPicker used by the project. */ -IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker); +IntelliToolRectangle(PaintingArea* Area, IntelliColorPicker* colorPicker, IntelliToolsettings* Toolsettings); /*! * \brief A Destructor. */ diff --git a/src/icons/Wechselpfeile.png b/src/icons/Wechselpfeile.png new file mode 100644 index 0000000..505fcdd Binary files /dev/null and b/src/icons/Wechselpfeile.png differ diff --git a/src/icons/circle-tool.svg b/src/icons/circle-tool.svg new file mode 100644 index 0000000..a6cc0e4 --- /dev/null +++ b/src/icons/circle-tool.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/src/icons/eraser-tool.svg b/src/icons/eraser-tool.svg new file mode 100644 index 0000000..cdc518d --- /dev/null +++ b/src/icons/eraser-tool.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/icons/flood-fill-tool.svg b/src/icons/flood-fill-tool.svg new file mode 100644 index 0000000..980bb7a --- /dev/null +++ b/src/icons/flood-fill-tool.svg @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + diff --git a/src/icons/icon.png b/src/icons/icon.png new file mode 100644 index 0000000..2829667 Binary files /dev/null and b/src/icons/icon.png differ diff --git a/src/icons/magic-wand-tool.svg b/src/icons/magic-wand-tool.svg new file mode 100644 index 0000000..71f019d --- /dev/null +++ b/src/icons/magic-wand-tool.svg @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/src/icons/pen-tool.svg b/src/icons/pen-tool.svg new file mode 100644 index 0000000..5dd9782 --- /dev/null +++ b/src/icons/pen-tool.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/icons/polygon-tool.svg b/src/icons/polygon-tool.svg new file mode 100644 index 0000000..7602729 --- /dev/null +++ b/src/icons/polygon-tool.svg @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/src/icons/rectangle-tool.svg b/src/icons/rectangle-tool.svg new file mode 100644 index 0000000..3056a02 --- /dev/null +++ b/src/icons/rectangle-tool.svg @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/main.cpp b/src/main.cpp index bcd7ae6..30adab2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,6 @@ #include "GUI/IntelliPhotoGui.h" #include #include -#include "IntelliHelper/IntelliHelper.h" #include int main(int argc, char*argv[]){