diff --git a/.gitignore b/.gitignore index 0ec0492..f4c35fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Build folders -src/*-debug/ -src/*-release/ +src/build-*/ # QT Creator Files *.creator.user* @@ -17,5 +16,9 @@ CMakeLists.txt.user* app_version.h phony.c +# Ignore User Files except for the pro file +IntelliPhoto.* +!IntelliPhoto.pro + # macOS Environment Files .DS_STORE diff --git a/src/Painting/GUI/IntelliPhotoGui.cpp b/src/Painting/GUI/IntelliPhotoGui.cpp index 65a03d5..119bbfd 100644 --- a/src/Painting/GUI/IntelliPhotoGui.cpp +++ b/src/Painting/GUI/IntelliPhotoGui.cpp @@ -19,7 +19,7 @@ IntelliPhotoGui::IntelliPhotoGui() setIntelliStyle(); // Size the app - resize(500, 500); + showMaximized(); } @@ -39,7 +39,7 @@ void IntelliPhotoGui::closeEvent(QCloseEvent *event) // Check if the current image has been changed and then // open a dialog to open a file -void IntelliPhotoGui::open() +void IntelliPhotoGui::slotOpen() { // Check if changes have been made since last save // maybeSave() returns true if no changes have been made @@ -54,12 +54,12 @@ void IntelliPhotoGui::open() // If we have a file name load the image and place // it in the paintingArea if (!fileName.isEmpty()) - paintingArea->openImage(fileName); + paintingArea->open(fileName); } } // Called when the user clicks Save As in the menu -void IntelliPhotoGui::save() +void IntelliPhotoGui::slotSave() { // A QAction represents the action of the user clicking QAction *action = qobject_cast(sender()); @@ -71,61 +71,31 @@ void IntelliPhotoGui::save() saveFile(fileFormat); } -// Opens a dialog to change the pen color -void IntelliPhotoGui::penColor() -{ - // Store the chosen color from the dialog - QColor newColor = QColorDialog::getColor(paintingArea->penColor()); - - // If a valid color set it - if (newColor.isValid()) - paintingArea->setPenColor(newColor); -} - -// Opens a dialog that allows the user to change the pen width -void IntelliPhotoGui::penWidth() -{ - // Stores button value - bool ok; - - // tr("Painting") is the title - // the next tr is the text to display - // Get the current pen width - // Define the min, max, step and ok button - int newWidth = QInputDialog::getInt(this, tr("Painting"), - tr("Select pen width:"), - paintingArea->penWidth(), - 1, 500, 1, &ok); - // Change the pen width - if (ok) - paintingArea->setPenWidth(newWidth); -} - // Opens a dialog that allows the user to create a New Layer -void IntelliPhotoGui::newLayer() +void IntelliPhotoGui::slotCreateNewLayer() { // Stores button value - bool ok; + bool ok1, ok2; // tr("New Layer") is the title // the next tr is the text to display // Define the standard Value, min, max, step and ok button int width = QInputDialog::getInt(this, tr("New Layer"), tr("Width:"), - 200,1, 500, 1, &ok); + 200,1, 500, 1, &ok1); int height = QInputDialog::getInt(this, tr("New Layer"), tr("Height:"), - 200,1, 500, 1, &ok); + 200,1, 500, 1, &ok2); // Create New Layer - if (ok) + if (ok1&&ok2) { - int layer = paintingArea->addLayer(width,height,100,100); - paintingArea->activate(layer); + int layer = paintingArea->addLayer(width,height,0,0); + paintingArea->slotActivateLayer(layer); } } // Opens a dialog that allows the user to delete a Layer -void IntelliPhotoGui::deleteLayer() +void IntelliPhotoGui::slotDeleteLayer() { // Stores button value bool ok; @@ -135,110 +105,151 @@ void IntelliPhotoGui::deleteLayer() // Define the standard Value, min, max, step and ok button int layerNumber = QInputDialog::getInt(this, tr("delete Layer"), tr("Number:"), - 1,1, 500, 1, &ok); + 1,0, 500, 1, &ok); // Create New Layer if (ok) - paintingArea->deleteLayer(layerNumber-1); + paintingArea->deleteLayer(layerNumber); +} + +void slotCreatePenTool(){ + +} + +void slotCreateFloodFillTool(){ + +} + + +void IntelliPhotoGui::slotSetActiveAlpha(){ + // Stores button value + bool ok1, ok2; + + // tr("Layer to set on") is the title + // the next tr is the text to display + // Define the standard Value, min, max, step and ok button + int layer = QInputDialog::getInt(this, tr("Layer to set on"), + tr("Layer:"), + -1,-1,100,1, &ok1); + // tr("New Alpha") is the title + int alpha = QInputDialog::getInt(this, tr("New Alpha"), + tr("Alpha:"), + 255,0, 255, 1, &ok2); + if (ok1&&ok2) + { + paintingArea->setAlphaOfLayer(layer,alpha); + } +} + +void IntelliPhotoGui::slotPositionMoveUp(){ + paintingArea->movePositionActive(0,-20); + update(); +} + +void IntelliPhotoGui::slotPositionMoveDown(){ + paintingArea->movePositionActive(0,20); + update(); +} + +void IntelliPhotoGui::slotPositionMoveLeft(){ + paintingArea->movePositionActive(-20,0); + update(); +} + +void IntelliPhotoGui::slotPositionMoveRight(){ + paintingArea->movePositionActive(20,0); + update(); +} + +void IntelliPhotoGui::slotMoveLayerUp(){ + paintingArea->moveActiveLayer(1); + update(); +} + +void IntelliPhotoGui::slotMoveLayerDown(){ + paintingArea->moveActiveLayer(-1); + update(); +} + +void IntelliPhotoGui::slotClearActiveLayer(){ + // Stores button value + bool ok1, ok2, ok3, ok4; + + // tr("Red Input") is the title + // the next tr is the text to display + // Define the standard Value, min, max, step and ok button + int red = QInputDialog::getInt(this, tr("Red Input"), + tr("Red:"), + 255,0, 255,1, &ok1); + // tr("Green Input") is the title + int green = QInputDialog::getInt(this, tr("Green Input"), + tr("Green:"), + 255,0, 255, 1, &ok2); + // tr("Blue Input") is the title + int blue = QInputDialog::getInt(this, tr("Blue Input"), + tr("Blue:"), + 255,0, 255, 1, &ok3); + // tr("Alpha Input") is the title + int alpha = QInputDialog::getInt(this, tr("Alpha Input"), + tr("Alpha:"), + 255,0, 255, 1, &ok4); + if (ok1&&ok2&&ok3&&ok4) + { + paintingArea->floodFill(red, green, blue, alpha); + } +} + +void IntelliPhotoGui::slotSetActiveLayer(){ + // Stores button value + bool ok1; + + // tr("Layer to set on") is the title + // the next tr is the text to display + // Define the standard Value, min, max, step and ok button + int layer = QInputDialog::getInt(this, tr("Layer to set on"), + tr("Layer:"), + -1,0,255,1, &ok1); + if (ok1) + { + paintingArea->setLayerToActive(layer); + } +}; + +void IntelliPhotoGui::slotSetFirstColor(){ + paintingArea->colorPickerSetFirstColor(); +} + +void IntelliPhotoGui::slotSetSecondColor(){ + paintingArea->colorPickerSetSecondColor(); +} + +void IntelliPhotoGui::slotSwitchColor(){ + paintingArea->colorPickerSwitchColor(); +} + +void IntelliPhotoGui::slotCreatePenTool(){ + paintingArea->createPenTool(); +} + +void IntelliPhotoGui::slotCreatePlainTool(){ + paintingArea->createPlainTool(); +} + +void IntelliPhotoGui::slotCreateLineTool(){ + paintingArea->createLineTool(); } // Open an about dialog -void IntelliPhotoGui::about() +void IntelliPhotoGui::slotAboutDialog() { // Window title and text to display QMessageBox::about(this, tr("About Painting"), tr("

IntelliPhoto Some nice ass looking software

")); } -void IntelliPhotoGui::onSetAlpha(){ - int a = this->setAlphaEdit->text().toInt(); - if (a >= 0 && a < 256) - emit this->sendAlpha(a); -} - -void IntelliPhotoGui::onMoveUp(){ - int a = 5; - emit this->moveUp(a); -} - -void IntelliPhotoGui::onMoveDown(){ - int a = 5; - emit this->moveDown(a); -} - -void IntelliPhotoGui::onMoveLeft(){ - int a = 5; - emit this->moveLeft(a); -} - -void IntelliPhotoGui::onMoveRight(){ - int a = 5; - emit this->moveRight(a); -} - -void IntelliPhotoGui::onMoveLayerUp(){ - emit this->moveLayerUp(); -} - -void IntelliPhotoGui::onMoveLayerDown(){ - emit this->moveLayerDown(); -} - -void IntelliPhotoGui::onClearedPressed(){ - int r = this->RedEdit->text().toInt(); - int g = this->GreenEdit->text().toInt(); - int b = this->BlueEdit->text().toInt(); - if(r < 256 && r >= 0 && g < 256 && g >= 0 && b < 256 && b >= 0) - emit this->sendClearColor(r,g,b); -} - -void IntelliPhotoGui::onActivePressed(){ - int a = this->selectActiveEdit->text().toInt(); - emit this->sendActiveLayer(a-1); -}; - - - // Define menu actions that call functions void IntelliPhotoGui::createActions() { - //connect signal and slots of gui element - connect(this->clearButton, SIGNAL(clicked()), this, SLOT(onClearedPressed())); - connect(this, SIGNAL(sendClearColor(int,int,int)), paintingArea, SLOT(clearImage(int, int, int))); - connect(this->selectActiveButton, SIGNAL(clicked()), this, SLOT(onActivePressed())); - connect(this, SIGNAL(sendActiveLayer(int)),paintingArea, SLOT(activate(int))); - - connect(this->setAlphaButton, SIGNAL(clicked()), this, SLOT(onSetAlpha())); - connect(this, SIGNAL(sendAlpha(int)), paintingArea, SLOT(setAlpha(int))); - - connect(this->moveActiveUpButton, SIGNAL(clicked()), this, SLOT(onMoveUp())); - connect(this, SIGNAL(moveUp(int)), paintingArea, SLOT(getMoveUp(int))); - - connect(this->moveActiveDownButton, SIGNAL(clicked()), this, SLOT(onMoveDown())); - connect(this, SIGNAL(moveDown(int)), paintingArea, SLOT(getMoveDown(int))); - - connect(this->moveActiveLeftButton, SIGNAL(clicked()), this, SLOT(onMoveLeft())); - connect(this, SIGNAL(moveLeft(int)), paintingArea, SLOT(getMoveLeft(int))); - - connect(this->moveActiveRightButton, SIGNAL(clicked()), this, SLOT(onMoveRight())); - connect(this, SIGNAL(moveRight(int)), paintingArea, SLOT(getMoveRight(int))); - - connect(this->layerMoveActiveDownButton, SIGNAL(clicked()), this, SLOT(onMoveLayerDown())); - connect(this, SIGNAL(moveLayerDown()), paintingArea, SLOT(getMoveLayerDown())); - - connect(this->layerMoveActiveUpButton, SIGNAL(clicked()), this, SLOT(onMoveLayerUp())); - connect(this, SIGNAL(moveLayerUp()), paintingArea, SLOT(getMoveLayerUp())); - - - - // Create the action tied to the menu - openAct = new QAction(tr("&Open..."), this); - - // Define the associated shortcut key - openAct->setShortcuts(QKeySequence::Open); - - // Tie the action to IntelliPhotoGui::open() - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); // Get a list of the supported file formats // QImageWriter is used to write images to files @@ -252,62 +263,97 @@ void IntelliPhotoGui::createActions() action->setData(format); // When clicked call IntelliPhotoGui::save() - connect(action, SIGNAL(triggered()), this, SLOT(save())); + connect(action, SIGNAL(triggered()), this, SLOT(slotSave())); // Attach each file format option menu item to Save As - saveAsActs.append(action); + actionSaveAs.append(action); } - QAction *action = new QAction("PNG-8", this); - - // Set an action for each file format - action->setData("PNG"); - + //set exporter to actions + QAction *pngSaveAction = new QAction("PNG-8", this); + pngSaveAction->setData("PNG"); // When clicked call IntelliPhotoGui::save() - connect(action, SIGNAL(triggered()), this, SLOT(save())); + connect(pngSaveAction, SIGNAL(triggered()), this, SLOT(slotSave())); + // Attach each PNG in save Menu + actionSaveAs.append(pngSaveAction); - // Attach each file format option menu item to Save As - saveAsActs.append(action); // Create exit action and tie to IntelliPhotoGui::close() - exitAct = new QAction(tr("&Exit"), this); - exitAct->setShortcuts(QKeySequence::Quit); - connect(exitAct, SIGNAL(triggered()), this, SLOT(close())); + actionExit = new QAction(tr("&Exit"), this); + actionExit->setShortcuts(QKeySequence::Quit); + connect(actionExit, SIGNAL(triggered()), this, SLOT(close())); - // Create pen color action and tie to IntelliPhotoGui::penColor() - penColorAct = new QAction(tr("&Pen Color..."), this); - connect(penColorAct, SIGNAL(triggered()), this, SLOT(penColor())); - - // Create pen width action and tie to IntelliPhotoGui::penWidth() - penWidthAct = new QAction(tr("Pen &Width..."), this); - connect(penWidthAct, SIGNAL(triggered()), this, SLOT(penWidth())); - - // Create clear screen action and tie to IntelliPhotoGui::clearImage() - clearScreenAct = new QAction(tr("&Clear Screen"), this); - clearScreenAct->setShortcut(tr("Ctrl+L")); - connect(clearScreenAct, SIGNAL(triggered()), - this, SLOT(onClearedPressed())); + actionOpen = new QAction(tr("&Open"), this); + actionOpen->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_O)); + connect(actionOpen, SIGNAL(triggered()), this, SLOT(slotOpen())); // Create New Layer action and tie to IntelliPhotoGui::newLayer() - newLayerAct = new QAction(tr("&New Layer..."), this); - connect(newLayerAct, SIGNAL(triggered()), this, SLOT(newLayer())); + actionCreateNewLayer = new QAction(tr("&New Layer..."), this); + connect(actionCreateNewLayer, SIGNAL(triggered()), this, SLOT(slotCreateNewLayer())); // Delete New Layer action and tie to IntelliPhotoGui::deleteLayer() - deleteLayerAct = new QAction(tr("&Delete Layer..."), this); - connect(deleteLayerAct, SIGNAL(triggered()), this, SLOT(deleteLayer())); + actionDeleteLayer = new QAction(tr("&Delete Layer..."), this); + connect(actionDeleteLayer, SIGNAL(triggered()), this, SLOT(slotDeleteLayer())); - // Delete Active Layer action and tie to paintingArea::deleteActiveLayerLayer() - deleteActiveLayerAct = new QAction(tr("&Delete active Layer"), this); - connect(deleteActiveLayerAct, SIGNAL(triggered()), paintingArea, SLOT(deleteActiveLayer())); + actionSetActiveLayer = new QAction(tr("&set Active"), this); + connect(actionSetActiveLayer, SIGNAL(triggered()), this, SLOT(slotSetActiveLayer())); + + actionSetActiveAlpha = new QAction(tr("&set Alpha"), this); + connect(actionSetActiveAlpha, SIGNAL(triggered()), this, SLOT(slotSetActiveAlpha())); + + actionMovePositionUp = new QAction(tr("&move Up"), this); + actionMovePositionUp->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up)); + connect(actionMovePositionUp, SIGNAL(triggered()), this, SLOT(slotPositionMoveUp())); + + actionMovePositionDown = new QAction(tr("&move Down"), this); + actionMovePositionDown->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down)); + connect(actionMovePositionDown, SIGNAL(triggered()), this, SLOT(slotPositionMoveDown())); + + actionMovePositionLeft = new QAction(tr("&move Left"), this); + actionMovePositionLeft->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left)); + connect(actionMovePositionLeft, SIGNAL(triggered()), this, SLOT(slotPositionMoveLeft())); + + actionMovePositionRight = new QAction(tr("&move Right"), this); + actionMovePositionRight->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right)); + connect(actionMovePositionRight, SIGNAL(triggered()), this, SLOT(slotPositionMoveRight())); + + actionMoveLayerUp = new QAction(tr("&move Layer Up"), this); + actionMoveLayerUp->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Up)); + connect(actionMoveLayerUp, SIGNAL(triggered()), this, SLOT(slotMoveLayerUp())); + + actionMoveLayerDown= new QAction(tr("&move Layer Down"), this); + actionMoveLayerDown->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Down)); + connect(actionMoveLayerDown, SIGNAL(triggered()), this, SLOT(slotMoveLayerDown())); + + //Create Color Actions here + actionColorPickerFirstColor = new QAction(tr("&Main"), this); + connect(actionColorPickerFirstColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor())); + + actionColorPickerSecondColor = new QAction(tr("&Secondary"), this); + connect(actionColorPickerSecondColor, SIGNAL(triggered()), this, SLOT(slotSetFirstColor())); + + actionColorSwitch = new QAction(tr("&Switch"), this); + actionColorSwitch->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_S)); + connect(actionColorSwitch, SIGNAL(triggered()), this, SLOT(slotSwitchColor())); + + //Create Tool actions down here + actionCreatePlainTool = new QAction(tr("&Plain"), this); + connect(actionCreatePlainTool, SIGNAL(triggered()), this, SLOT(slotCreatePlainTool())); + + actionCreatePenTool = new QAction(tr("&Pen"),this); + connect(actionCreatePenTool, SIGNAL(triggered()), this, SLOT(slotCreatePenTool())); + + actionCreateLineTool = new QAction(tr("&Line"), this); + connect(actionCreateLineTool, SIGNAL(triggered()), this, SLOT(slotCreateLineTool())); // Create about action and tie to IntelliPhotoGui::about() - aboutAct = new QAction(tr("&About"), this); - connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + actionAboutDialog = new QAction(tr("&About"), this); + connect(actionAboutDialog, SIGNAL(triggered()), this, SLOT(slotAboutDialog())); // Create about Qt action and tie to IntelliPhotoGui::aboutQt() - aboutQtAct = new QAction(tr("About &Qt"), this); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + actionAboutQtDialog = new QAction(tr("About &Qt"), this); + connect(actionAboutQtDialog, SIGNAL(triggered()), qApp, SLOT(aboutQt())); } // Create the menubar @@ -315,39 +361,57 @@ void IntelliPhotoGui::createMenus() { // Create Save As option and the list of file types saveAsMenu = new QMenu(tr("&Save As"), this); - foreach (QAction *action, saveAsActs) + foreach (QAction *action, actionSaveAs) saveAsMenu->addAction(action); // Attach all actions to File fileMenu = new QMenu(tr("&File"), this); - fileMenu->addAction(openAct); + fileMenu->addAction(actionOpen); fileMenu->addMenu(saveAsMenu); fileMenu->addSeparator(); - fileMenu->addAction(exitAct); + fileMenu->addAction(actionExit); // Attach all actions to Options optionMenu = new QMenu(tr("&Options"), this); - optionMenu->addAction(penColorAct); - optionMenu->addAction(penWidthAct); - optionMenu->addSeparator(); - optionMenu->addAction(clearScreenAct); + optionMenu->addAction(actionSetActiveLayer); + optionMenu->addAction(actionSetActiveAlpha); + optionMenu->addAction(actionMovePositionUp); + optionMenu->addAction(actionMovePositionDown); + optionMenu->addAction(actionMovePositionLeft); + optionMenu->addAction(actionMovePositionRight); + optionMenu->addAction(actionMoveLayerUp); + optionMenu->addAction(actionMoveLayerDown); // Attach all actions to Layer layerMenu = new QMenu(tr("&Layer"), this); - layerMenu->addAction(newLayerAct); - layerMenu->addAction(deleteLayerAct); - layerMenu->addAction(deleteActiveLayerAct); + layerMenu->addAction(actionCreateNewLayer); + layerMenu->addAction(actionDeleteLayer); + + //Attach all Color Options + colorMenu = new QMenu(tr("&Color"), this); + colorMenu->addAction(actionColorPickerFirstColor); + colorMenu->addAction(actionColorPickerSecondColor); + colorMenu->addAction(actionColorSwitch); + + //Attach all Tool Options + toolMenu = new QMenu(tr("&Tools"), this); + toolMenu->addAction(actionCreatePenTool); + toolMenu->addAction(actionCreatePlainTool); + toolMenu->addAction(actionCreateLineTool); + toolMenu->addSeparator(); + toolMenu->addMenu(colorMenu); // Attach all actions to Help helpMenu = new QMenu(tr("&Help"), this); - helpMenu->addAction(aboutAct); - helpMenu->addAction(aboutQtAct); + helpMenu->addAction(actionAboutDialog); + helpMenu->addAction(actionAboutQtDialog); // Add menu items to the menubar menuBar()->addMenu(fileMenu); menuBar()->addMenu(optionMenu); menuBar()->addMenu(layerMenu); + menuBar()->addMenu(toolMenu); menuBar()->addMenu(helpMenu); } @@ -361,67 +425,10 @@ void IntelliPhotoGui::createGui(){ centralGuiWidget->setLayout(mainLayout); //create Gui elements - clearButton = new QPushButton("set Color"); paintingArea = new PaintingArea(); - - RedLabel = new QLabel("Red:"); - GreenLabel = new QLabel("Green"); - BlueLabel = new QLabel("Blue:"); - RedEdit = new QLineEdit("255"); - GreenEdit = new QLineEdit("255"); - BlueEdit = new QLineEdit("255"); - RedEdit->setMaximumSize(150,20); - GreenEdit->setMaximumSize(150,20); - BlueEdit->setMaximumSize(150,20); - - selectActiveButton = new QPushButton("select Active"); - selectActiveLabel = new QLabel("Active:"); - selectActiveEdit = new QLineEdit("1"); - selectActiveLabel->setMaximumSize(150,20); - selectActiveEdit->setMaximumSize(150,20); - - setAlphaButton = new QPushButton("set Alpha"); - setAlphaLabel = new QLabel("Alpha:"); - setAlphaEdit = new QLineEdit("255"); - setAlphaEdit->setMaximumSize(150,20); - - moveActiveUpButton = new QPushButton("move 5 Up"); - moveActiveDownButton = new QPushButton("move 5 Down"); - moveActiveLeftButton = new QPushButton("move 5 Left"); - moveActiveRightButton = new QPushButton("move 5 Right"); - - layerMoveActiveDownButton = new QPushButton("Active Layer Down"); - layerMoveActiveUpButton = new QPushButton("Active Layer Up"); - - //set gui elemtns position - mainLayout->addWidget(clearButton,0,25,1,1); - mainLayout->addWidget(paintingArea,0,0,25,25); - - mainLayout->addWidget(RedLabel,1,25,1,1); - mainLayout->addWidget(RedEdit,2,25,1,1); - mainLayout->addWidget(GreenLabel,3,25,1,1); - mainLayout->addWidget(GreenEdit,4,25,1,1); - mainLayout->addWidget(BlueLabel,5,25,1,1); - mainLayout->addWidget(BlueEdit,6,25,1,1); - - mainLayout->addWidget(selectActiveButton,7,25,1,1); - mainLayout->addWidget(selectActiveLabel,8,25,1,1); - mainLayout->addWidget(selectActiveEdit,9,25,1,1); - - mainLayout->addWidget(setAlphaButton,10,25,1,1); - mainLayout->addWidget(setAlphaLabel,11,25,1,1); - mainLayout->addWidget(setAlphaEdit,12,25,1,1); - - mainLayout->addWidget(moveActiveUpButton,13,25,1,1); - mainLayout->addWidget(moveActiveDownButton,14,25,1,1); - mainLayout->addWidget(moveActiveLeftButton,15,25,1,1); - mainLayout->addWidget(moveActiveRightButton,16,25,1,1); - - mainLayout->addWidget(layerMoveActiveDownButton,17,25,1,1); - mainLayout->addWidget(layerMoveActiveUpButton,18,25,1,1); - - + //set gui elements + mainLayout->addWidget(paintingArea); } void IntelliPhotoGui::setIntelliStyle(){ @@ -436,7 +443,9 @@ void IntelliPhotoGui::setIntelliStyle(){ bool IntelliPhotoGui::maybeSave() { // Check for changes since last save - if (paintingArea->isModified()) { + + //TODO insert variable for modified status here to make an save exit message + if (false) { QMessageBox::StandardButton ret; // Painting is the title @@ -478,7 +487,7 @@ bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat) } else { // Call for the file to be saved - return paintingArea->saveImage(fileName, fileFormat.constData()); + return paintingArea->save(fileName, fileFormat.constData()); } } diff --git a/src/Painting/GUI/IntelliPhotoGui.h b/src/Painting/GUI/IntelliPhotoGui.h index fa36326..c204cce 100644 --- a/src/Painting/GUI/IntelliPhotoGui.h +++ b/src/Painting/GUI/IntelliPhotoGui.h @@ -12,119 +12,119 @@ // PaintingArea used to paint the image class PaintingArea; +class IntelliTool; + +class IntelliColorPicker; + class IntelliPhotoGui : public QMainWindow { // Declares our class as a QObject which is the base class // for all Qt objects // QObjects handle events Q_OBJECT -signals: - void sendClearColor(int r, int g, int b); - void sendActiveLayer(int a); - void sendAlpha(int a); - void moveUp(int a); - void moveDown(int a); - void moveRight(int a); - void moveLeft(int a); - void moveLayerUp(); - void moveLayerDown(); - public: IntelliPhotoGui(); + protected: // Function used to close an event void closeEvent(QCloseEvent *event) override; -// The events that can be triggered private slots: - void open(); - void save(); - void penColor(); - void penWidth(); - void newLayer(); - void deleteLayer(); - void about(); + //meta slots here (need further ) + void slotOpen(); + void slotSave(); - void onClearedPressed(); - void onActivePressed(); - void onSetAlpha(); - void onMoveUp(); - void onMoveDown(); - void onMoveLeft(); - void onMoveRight(); - void onMoveLayerUp(); - void onMoveLayerDown(); + //layer slots here + void slotCreateNewLayer(); + void slotDeleteLayer(); + void slotClearActiveLayer(); + void slotSetActiveLayer(); + void slotSetActiveAlpha(); + void slotPositionMoveUp(); + void slotPositionMoveDown(); + void slotPositionMoveLeft(); + void slotPositionMoveRight(); + void slotMoveLayerUp(); + void slotMoveLayerDown(); + + //color Picker slots here + void slotSetFirstColor(); + void slotSetSecondColor(); + void slotSwitchColor(); + + //tool slots here + void slotCreatePenTool(); + void slotCreatePlainTool(); + void slotCreateLineTool(); + + //slots for dialogs + void slotAboutDialog(); private: // Will tie user actions to functions void createActions(); void createMenus(); - //setup GUI elements void createGui(); - //set style of the GUI void setIntelliStyle(); + // Will check if changes have occurred since last save bool maybeSave(); - // Opens the Save dialog and saves bool saveFile(const QByteArray &fileFormat); // What we'll draw on - PaintingArea *paintingArea; + PaintingArea* paintingArea; // The menu widgets QMenu *saveAsMenu; QMenu *fileMenu; QMenu *optionMenu; QMenu *layerMenu; + QMenu *colorMenu; + QMenu *toolMenu; QMenu *helpMenu; - // All the actions that can occur - QAction *openAct; + + //meta image actions (need further modularisation) + QAction *actionOpen; + QAction *actionExit; + + //color Picker actions + QAction *actionColorPickerFirstColor; + QAction *actionColorPickerSecondColor; + QAction *actionColorSwitch; + + //tool actions + QAction *actionCreatePenTool; + QAction *actionCreatePlainTool; + QAction *actionCreateLineTool; + + //dialog actions + QAction *actionAboutDialog; + QAction *actionAboutQtDialog; + + //layer change actions + QAction *actionCreateNewLayer; + QAction *actionDeleteLayer; + QAction* actionSetActiveLayer; + QAction* actionSetActiveAlpha; + QAction* actionMovePositionUp; + QAction* actionMovePositionDown; + QAction* actionMovePositionLeft; + QAction* actionMovePositionRight; + QAction* actionMoveLayerUp; + QAction* actionMoveLayerDown; // Actions tied to specific file formats - QList saveAsActs; - QAction *exitAct; - QAction *penColorAct; - QAction *penWidthAct; - QAction *clearScreenAct; - QAction *newLayerAct; - QAction *deleteLayerAct; - QAction *deleteActiveLayerAct; - QAction *aboutAct; - QAction *aboutQtAct; + QList actionSaveAs; //main GUI elements QWidget* centralGuiWidget; QGridLayout *mainLayout; - QPushButton *clearButton; - - QLabel *RedLabel; - QLabel *GreenLabel; - QLabel *BlueLabel; - QLineEdit *RedEdit; - QLineEdit *GreenEdit; - QLineEdit *BlueEdit; - - QPushButton *selectActiveButton; - QLabel *selectActiveLabel; - QLineEdit *selectActiveEdit; - - QPushButton *setAlphaButton; - QLabel *setAlphaLabel; - QLineEdit *setAlphaEdit; - - QPushButton *moveActiveUpButton; - QPushButton *moveActiveDownButton; - QPushButton *moveActiveLeftButton; - QPushButton *moveActiveRightButton; - - QPushButton *layerMoveActiveDownButton; - QPushButton *layerMoveActiveUpButton; }; diff --git a/src/Painting/Image/IntelliImage.cpp b/src/Painting/Image/IntelliImage.cpp index 879e8c7..74b7891 100644 --- a/src/Painting/Image/IntelliImage.cpp +++ b/src/Painting/Image/IntelliImage.cpp @@ -20,7 +20,7 @@ bool IntelliImage::loadImage(const QString &fileName){ return false; // scaled Image to size of Layer - // loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); + loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); imageData = loadedImage.convertToFormat(QImage::Format_ARGB32); return true; @@ -50,9 +50,6 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ // Draw a line from the last registered point to the current painter.drawPoint(p1); - - // Call to update the rectangular space where we drew - //update(QRect(p1, p2)); } void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){ @@ -67,15 +64,6 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co } -void IntelliImage::floodFill(const QColor& color){ +void IntelliImage::drawPlain(const QColor& color){ imageData.fill(color); - -} - -int IntelliImage::x(){ - return imageData.size().width(); -} - -int IntelliImage::y(){ - return imageData.size().height(); } diff --git a/src/Painting/Image/IntelliImage.h b/src/Painting/Image/IntelliImage.h index a2fb3c0..14e9ec2 100644 --- a/src/Painting/Image/IntelliImage.h +++ b/src/Painting/Image/IntelliImage.h @@ -13,34 +13,42 @@ enum class ImageType{ Shaped_Image }; -class IntelliImage{ +class IntelliTool; +class IntelliImage{ + friend IntelliTool; protected: void resizeImage(QImage *image, const QSize &newSize); QImage imageData; + + //calculate with polygon public: IntelliImage(int weight, int height); virtual ~IntelliImage() = 0; + //start on top left virtual void drawPixel(const QPoint &p1, const QColor& color); virtual void drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth); - virtual void floodFill(const QColor& color); + virtual void drawPlain(const QColor& color); //returns the filtered output virtual QImage getDisplayable(const QSize& displaySize, int alpha)=0; virtual QImage getDisplayable(int alpha=255)=0; + //gets a copy of the image !allocated + virtual IntelliImage* getDeepCopy()=0; + virtual void calculateVisiblity()=0; + //returns the filtered output //sets the data for the visible image virtual void setPolygon(const std::vector& polygonData)=0; + virtual std::vector getPolygonData(){ return std::vector();} + //loads an image to the ColorBuffer virtual bool loadImage(const QString &fileName); - - int x(); - int y(); }; #endif diff --git a/src/Painting/Image/IntelliRasterImage.cpp b/src/Painting/Image/IntelliRasterImage.cpp index b73c264..d92260f 100644 --- a/src/Painting/Image/IntelliRasterImage.cpp +++ b/src/Painting/Image/IntelliRasterImage.cpp @@ -12,6 +12,16 @@ IntelliRasterImage::~IntelliRasterImage(){ } +IntelliImage* IntelliRasterImage::getDeepCopy(){ + IntelliRasterImage* raster = new IntelliRasterImage(imageData.width(), imageData.height()); + raster->imageData.fill(Qt::transparent); + return raster; +} + +void IntelliRasterImage::calculateVisiblity(){ + //not used in raster image +} + QImage IntelliRasterImage::getDisplayable(int alpha){ return getDisplayable(imageData.size(), alpha); } @@ -21,7 +31,7 @@ QImage IntelliRasterImage::getDisplayable(const QSize& displaySize, int alpha){ for(int y = 0; y& polygonData) override; diff --git a/src/Painting/Image/IntelliShapedImage.cpp b/src/Painting/Image/IntelliShapedImage.cpp index 6b7a829..0dbc807 100644 --- a/src/Painting/Image/IntelliShapedImage.cpp +++ b/src/Painting/Image/IntelliShapedImage.cpp @@ -5,7 +5,7 @@ #include IntelliShapedImage::IntelliShapedImage(int weight, int height) - :IntelliImage(weight, height){ + :IntelliRasterImage(weight, height){ } IntelliShapedImage::~IntelliShapedImage(){ @@ -13,59 +13,73 @@ IntelliShapedImage::~IntelliShapedImage(){ } QImage IntelliShapedImage::getDisplayable(int alpha){ - return getDisplayable(imageData.size()); + return getDisplayable(imageData.size(),alpha); +} + +IntelliImage* IntelliShapedImage::getDeepCopy(){ + IntelliShapedImage* shaped = new IntelliShapedImage(imageData.width(), imageData.height()); + shaped->setPolygon(this->polygonData); + shaped->imageData.fill(Qt::transparent); + return shaped; +} + +void IntelliShapedImage::calculateVisiblity(){ + if(polygonData.size()<=2){ + QColor clr; + for(int y=0; y(polygonData.size()-1); i++){ + QPoint B = polygonData[static_cast(i)]; + QPoint C = polygonData[static_cast(i+1)]; + QPoint P(x,y); + cutNumeber+=IntelliHelper::isInTriangle(A,B,C,P); + } + if(cutNumeber%2==0){ + clr = imageData.pixelColor(x,y); + clr.setAlpha(0); + imageData.setPixelColor(x,y,clr); + }else{ + clr = imageData.pixelColor(x,y); + clr.setAlpha(std::min(255, clr.alpha())); + imageData.setPixelColor(x,y,clr); + } + } + } } QImage IntelliShapedImage::getDisplayable(const QSize& displaySize, int alpha){ - if(polygonData.size()==0){ - QImage copy = imageData; - for(int y = 0; y not in Polygon - if(!(cutNumberX&1)){ - QColor tmpColor(0,0,0); - tmpColor.setAlpha(0); - copy.setPixelColor(startPoint,tmpColor); - }else{ - QColor clr = copy.pixelColor(x,y); - clr.setAlpha(alpha); - copy.setPixelColor(x,y,clr); - } + for(int x = 0; x& polygonData){ if(polygonData.size()<3){ - return; - } - for(auto element:polygonData){ - this->polygonData.push_back(QPoint(element.x(), element.y())); + this->polygonData.clear(); + }else{ + this->polygonData.clear(); + for(auto element:polygonData){ + this->polygonData.push_back(QPoint(element.x(), element.y())); + } } + calculateVisiblity(); return; } diff --git a/src/Painting/Image/IntelliShapedImage.h b/src/Painting/Image/IntelliShapedImage.h index 6c38366..0a3598e 100644 --- a/src/Painting/Image/IntelliShapedImage.h +++ b/src/Painting/Image/IntelliShapedImage.h @@ -1,20 +1,27 @@ #ifndef INTELLISHAPE_H #define INTELLISHAPE_H -#include"Image/IntelliImage.h" - -class IntelliShapedImage : public IntelliImage{ +#include"Image/IntelliRasterImage.h" +class IntelliShapedImage : public IntelliRasterImage{ + friend IntelliTool; protected: + std::vector polygonData; public: IntelliShapedImage(int weight, int height); virtual ~IntelliShapedImage() override; + virtual void calculateVisiblity() override; + //returns the filtered output virtual QImage getDisplayable(const QSize& displaySize, int alpha=255) override; virtual QImage getDisplayable(int alpha=255) override; + //gets a copy of the image !allocated + virtual IntelliImage* getDeepCopy() override; + virtual std::vector getPolygonData() override{return polygonData;} + //sets the data for the visible image virtual void setPolygon(const std::vector& polygonData) override; }; diff --git a/src/Painting/IntelliHelper/IntelliColorPicker.cpp b/src/Painting/IntelliHelper/IntelliColorPicker.cpp new file mode 100644 index 0000000..76ba561 --- /dev/null +++ b/src/Painting/IntelliHelper/IntelliColorPicker.cpp @@ -0,0 +1,30 @@ +#include "IntelliColorPicker.h" + +IntelliColorPicker::IntelliColorPicker(){ + firstColor = {255,0,0,255}; + secondColor = {0,0,255,255}; +} + +IntelliColorPicker::~IntelliColorPicker(){ + +} + +void IntelliColorPicker::switchColors(){ + std::swap(firstColor, secondColor); +} + +QColor IntelliColorPicker::getFirstColor(){ + return this->firstColor; +} + +QColor IntelliColorPicker::getSecondColor(){ + return this->secondColor; +} + +void IntelliColorPicker::setFirstColor(QColor Color){ + this->firstColor = Color; +} + +void IntelliColorPicker::setSecondColor(QColor Color){ + this->secondColor = Color; +} diff --git a/src/Painting/IntelliHelper/IntelliColorPicker.h b/src/Painting/IntelliHelper/IntelliColorPicker.h new file mode 100644 index 0000000..64f23e5 --- /dev/null +++ b/src/Painting/IntelliHelper/IntelliColorPicker.h @@ -0,0 +1,26 @@ +#ifndef INTELLITOOLSETCOLORTOOL_H +#define INTELLITOOLSETCOLORTOOL_H + +#include"QColor" +#include"QPoint" +#include"QColorDialog" + +class IntelliColorPicker{ +public: + IntelliColorPicker(); + virtual ~IntelliColorPicker(); + + void switchColors(); + + QColor getFirstColor(); + QColor getSecondColor(); + + void setFirstColor(QColor Color); + void setSecondColor(QColor Color); + +private: + QColor firstColor; + QColor secondColor; +}; + +#endif // INTELLITOOLSETCOLORTOOL_H diff --git a/src/Painting/IntelliHelper/IntelliHelper.cpp b/src/Painting/IntelliHelper/IntelliHelper.cpp index ef0e8fb..0cd9460 100644 --- a/src/Painting/IntelliHelper/IntelliHelper.cpp +++ b/src/Painting/IntelliHelper/IntelliHelper.cpp @@ -1,39 +1,4 @@ #include"IntelliHelper.h" #include -int IntelliHelper::orientation(QPoint& p, QPoint& q, QPoint& r){ - int value = (q.y()-p.y())*(r.x()-q.x())- - (q.x()-p.x())*(r.y()-q.y()); - if(value==0) return 0; - return (value>0)?1:2; -} -bool IntelliHelper::onSegment(QPoint& p1, QPoint& q, QPoint& p2){ - return (q.x() >= std::min(p1.x(),p2.x()) && q.x() <= std::max(p1.x(), p2.x()) && - q.y() >= std::min(p1.y(),p2.y()) && q.y() <= std::max(p1.y(), p2.y())); -} - -bool IntelliHelper::hasIntersection(QPoint& p1, QPoint& q1, QPoint& p2, QPoint& q2){ - int o1 = IntelliHelper::orientation(p1,q1,p2); - int o2 = IntelliHelper::orientation(p1,q1,q2); - int o3 = IntelliHelper::orientation(p2,q2,p1); - int o4 = IntelliHelper::orientation(p2,q2,q1); - - // General case - if (o1 != o2 && o3 != o4) - return true; - - // p1, q1 and p2 are colinear and p2 lies on segment p1q1 - if (o1 == 0 && onSegment(p1, p2, q1)) return true; - - // p1, q1 and q2 are colinear and q2 lies on segment p1q1 - if (o2 == 0 && onSegment(p1, q2, q1)) return true; - - // p2, q2 and p1 are colinear and p1 lies on segment p2q2 - if (o3 == 0 && onSegment(p2, p1, q2)) return true; - - // p2, q2 and q1 are colinear and q1 lies on segment p2q2 - if (o4 == 0 && onSegment(p2, q1, q2)) return true; - - return false; // Doesn't fall in any of the above cases -} diff --git a/src/Painting/IntelliHelper/IntelliHelper.h b/src/Painting/IntelliHelper/IntelliHelper.h index 9e273f6..ef6b32a 100644 --- a/src/Painting/IntelliHelper/IntelliHelper.h +++ b/src/Painting/IntelliHelper/IntelliHelper.h @@ -5,18 +5,27 @@ class IntelliHelper{ + public: - //checks for orientation: - // 0 - colinear - // 1 - clockwise - // 2 - counter clockwise - static int orientation(QPoint& p1, QPoint& p2, QPoint& p3); - //checks if q is on segment p1-p2 - static bool onSegment(QPoint& p1, QPoint& q, QPoint& p2); + static inline float sign(QPoint& p1, QPoint& p2, QPoint& p3){ + return (p1.x()-p3.x())*(p2.y()-p3.y())-(p2.x()-p3.x())*(p1.y()-p3.y()); + } - //cheks if p1-q1 intersects with p2-q2 - static bool hasIntersection(QPoint& p1, QPoint& q1, QPoint& p2, QPoint& q2); + + static inline bool isInTriangle(QPoint& A, QPoint& B, QPoint& C, QPoint& P){ + float val1, val2, val3; + bool neg, pos; + + val1 = IntelliHelper::sign(P,A,B); + val2 = IntelliHelper::sign(P,B,C); + val3 = IntelliHelper::sign(P,C,A); + + neg = (val1<0.f) || (val2<0.f) || (val3<0.f); + pos = (val1>0.f) || (val2>0.f) || (val3>0.f); + + return !(neg && pos); + } }; #endif diff --git a/src/Painting/IntelliPhoto.87de10b b/src/Painting/IntelliPhoto.87de10b deleted file mode 100644 index 934c6c1..0000000 --- a/src/Painting/IntelliPhoto.87de10b +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - EnvironmentId - {87de10b7-9dd6-4379-8674-fd04613e186e} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.12.5 MinGW 64-bit - Desktop Qt 5.12.5 MinGW 64-bit - qt.qt5.5125.win64_mingw73_kit - 0 - 0 - 0 - - C:/Users/Jonas/Documents/QML/build-Scribble-Desktop_Qt_5_12_5_MinGW_64_bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Erstellen - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - C:/Users/Jonas/Documents/QML/build-Scribble-Desktop_Qt_5_12_5_MinGW_64_bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Erstellen - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - C:/Users/Jonas/Documents/QML/build-Scribble-Desktop_Qt_5_12_5_MinGW_64_bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Erstellen - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deployment - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deployment-Konfiguration - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Scribble - - Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Jonas/Documents/QML/Scribble/Scribble.pro - - 3768 - false - true - true - false - false - true - - C:/Users/Jonas/Documents/QML/build-Scribble-Desktop_Qt_5_12_5_MinGW_64_bit-Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/src/Painting/IntelliPhoto.pro b/src/Painting/IntelliPhoto.pro index d1dc823..7d3580d 100644 --- a/src/Painting/IntelliPhoto.pro +++ b/src/Painting/IntelliPhoto.pro @@ -1,4 +1,4 @@ -QT += core gui +QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -20,8 +20,13 @@ SOURCES += \ Image/IntelliImage.cpp \ Image/IntelliRasterImage.cpp \ Image/IntelliShapedImage.cpp \ + IntelliHelper/IntelliColorPicker.cpp \ IntelliHelper/IntelliHelper.cpp \ Layer/PaintingArea.cpp \ + Tool/IntelliTool.cpp \ + Tool/IntelliToolLine.cpp \ + Tool/IntelliToolPen.cpp \ + Tool/IntelliToolPlain.cpp \ main.cpp HEADERS += \ @@ -29,18 +34,22 @@ HEADERS += \ Image/IntelliImage.h \ Image/IntelliRasterImage.h \ Image/IntelliShapedImage.h \ + IntelliHelper/IntelliColorPicker.h \ IntelliHelper/IntelliHelper.h \ Layer/PaintingArea.h \ - Tool/IntelliTool.h + Tool/IntelliTool.h \ + Tool/IntelliToolLine.h \ + Tool/IntelliToolPen.h \ + Tool/IntelliToolPlain.h FORMS += \ widget.ui - QMAKE_CXXFLAGS QMAKE_LFLAGS RC_ICONS = icon.ico +ICON = icon.icns # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/src/Painting/IntelliPhoto.user b/src/Painting/IntelliPhoto.user deleted file mode 100644 index 574e287..0000000 --- a/src/Painting/IntelliPhoto.user +++ /dev/null @@ -1,337 +0,0 @@ - - - - - - EnvironmentId - {39e188fc-db7d-4dae-b6b7-f93e7e62e580} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - -fno-delayed-template-parsing - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.12.6 MinGW 32-bit - Desktop Qt 5.12.6 MinGW 32-bit - qt.qt5.5126.win32_mingw73_kit - 0 - 0 - 0 - - E:/Users/pauln/Documents/intelliphoto/IntelliPhoto/build-Scribble-Desktop_Qt_5_12_6_MinGW_32_bit-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Erstellen - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - E:/Users/pauln/Documents/intelliphoto/IntelliPhoto/build-Scribble-Desktop_Qt_5_12_6_MinGW_32_bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Erstellen - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - E:/Users/pauln/Documents/intelliphoto/IntelliPhoto/build-Scribble-Desktop_Qt_5_12_6_MinGW_32_bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - true - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Erstellen - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Bereinigen - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deployment - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deployment-Konfiguration - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - dwarf - - cpu-cycles - - - 250 - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - Scribble - - Qt4ProjectManager.Qt4RunConfiguration:E:/Users/pauln/Documents/intelliphoto/IntelliPhoto/Scribble/Scribble.pro - - 3768 - false - true - true - false - false - true - - E:/Users/pauln/Documents/intelliphoto/IntelliPhoto/build-Scribble-Desktop_Qt_5_12_6_MinGW_32_bit-Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/src/Painting/Layer/PaintingArea.cpp b/src/Painting/Layer/PaintingArea.cpp index 58fc159..7fff2a9 100644 --- a/src/Painting/Layer/PaintingArea.cpp +++ b/src/Painting/Layer/PaintingArea.cpp @@ -1,124 +1,120 @@ // ---------- PaintingArea.cpp ---------- +#include "string.h" + +#include #include +#include #include -#include "string.h" + #include "PaintingArea.h" #include "Image/IntelliRasterImage.h" #include "Image/IntelliShapedImage.h" +#include "Tool/IntelliToolPen.h" +#include "Tool/IntelliToolPlain.h" +#include "Tool/IntelliToolLine.h" -#include -#include - -#define EXPORT PaintingArea::PaintingArea(int maxWidth, int maxHeight, QWidget *parent) :QWidget(parent){ + this->Tool = nullptr; this->setUp(maxWidth, maxHeight); - -#ifdef EXPORT - this->addLayer(maxWidth, maxHeight); - layerStructure[0].image->floodFill(QColor(255,255,255,255)); - activeLayer=0; -#endif -#ifndef EXPORT //tetsing this->addLayer(200,200,0,0,ImageType::Shaped_Image); - layerStructure[0].image->floodFill(QColor(255,0,0,255)); + layerBundle[0].image->drawPlain(QColor(255,0,0,255)); std::vector polygon; - polygon.push_back(QPoint(100,0)); - polygon.push_back(QPoint(200,200)); - polygon.push_back(QPoint(0,200)); - polygon.push_back(QPoint(100,0)); - layerStructure[0].image->setPolygon(polygon); + polygon.push_back(QPoint(100,000)); + polygon.push_back(QPoint(200,100)); + polygon.push_back(QPoint(100,200)); + polygon.push_back(QPoint(000,100)); + layerBundle[0].image->setPolygon(polygon); this->addLayer(200,200,150,150); - layerStructure[1].image->floodFill(QColor(0,255,0,255)); - layerStructure[1].alpha=200; + layerBundle[1].image->drawPlain(QColor(0,255,0,255)); + layerBundle[1].alpha=200; - activeLayer=1; -#endif + activeLayer=0; } +PaintingArea::~PaintingArea(){ + delete Tool; +} + + void PaintingArea::setUp(int maxWidth, int maxHeight){ //set standart parameter this->maxWidth = maxWidth; this->maxHeight = maxHeight; Canvas = new QImage(maxWidth,maxHeight, QImage::Format_ARGB32); - Canvas->fill(Qt::GlobalColor::white); // Roots the widget to the top left even if resized setAttribute(Qt::WA_StaticContents); - // Set defaults for the monitored variables - scribbling = false; - myPenWidth = 1; - myPenColor = Qt::blue; } int PaintingArea::addLayer(int width, int height, int widthOffset, int heightOffset, ImageType type){ LayerObject newLayer; newLayer.width = width; - newLayer.height = height; + newLayer.hight = height; newLayer.widthOffset = widthOffset; - newLayer.heightOffset = heightOffset; + newLayer.hightOffset = heightOffset; if(type==ImageType::Raster_Image){ newLayer.image = new IntelliRasterImage(width,height); }else if(type==ImageType::Shaped_Image){ newLayer.image = new IntelliShapedImage(width, height); } newLayer.alpha = 255; - this->layerStructure.push_back(newLayer); - return layerStructure.size()-1; + this->layerBundle.push_back(newLayer); + return static_cast(layerBundle.size())-1; } + void PaintingArea::deleteLayer(int index){ - if(indexlayerStructure.erase(layerStructure.begin()+index); + if(index(layerBundle.size())){ + this->layerBundle.erase(layerBundle.begin()+index); if(activeLayer>=index){ activeLayer--; } } } -void PaintingArea::deleteActiveLayer(){ - this->layerStructure.erase(layerStructure.begin()+activeLayer); +void PaintingArea::slotDeleteActiveLayer(){ + if(activeLayer>=0 && activeLayer < static_cast(layerBundle.size())){ + this->layerBundle.erase(layerBundle.begin()+activeLayer); activeLayer--; + } } void PaintingArea::setLayerToActive(int index) { - if(index=0&&index(layerBundle.size())){ this->activeLayer=index; } } -void PaintingArea::setAlphaToLayer(int index, int alpha){ - if(index=0&&index(layerBundle.size())){ + layerBundle[static_cast(index)].alpha=alpha; } } -QPixmap PaintingArea::getAsPixmap(){ - assembleLayers(); - return QPixmap::fromImage(*Canvas); -} // Used to load the image and place it in the widget -bool PaintingArea::openImage(const QString &fileName) +bool PaintingArea::open(const QString &fileName) { if(this->activeLayer==-1){ return false; } - IntelliImage* active = layerStructure[activeLayer].image; + IntelliImage* active = layerBundle[static_cast(activeLayer)].image; bool open = active->loadImage(fileName); + active->calculateVisiblity(); update(); return open; } // Save the current image -bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) +bool PaintingArea::save(const QString &fileName, const char *fileFormat) { - if(layerStructure.size()==0){ + if(layerBundle.size()==0){ return false; } this->assembleLayers(true); @@ -133,7 +129,6 @@ bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) } } - if (Canvas->save(fileName, fileFormat)) { return true; } else { @@ -141,67 +136,63 @@ bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) } } -// Used to change the pen color -void PaintingArea::setPenColor(const QColor &newColor) -{ - myPenColor = newColor; -} - -// Used to change the pen width -void PaintingArea::setPenWidth(int newWidth) -{ - myPenWidth = newWidth; -} // Color the image area with white -void PaintingArea::clearImage(int r, int g, int b){ +void PaintingArea::floodFill(int r, int g, int b, int a){ if(this->activeLayer==-1){ return; } - IntelliImage* active = layerStructure[activeLayer].image; - active->floodFill(QColor(r, g, b, 255)); - + IntelliImage* active = layerBundle[static_cast(activeLayer)].image; + active->drawPlain(QColor(r, g, b, a)); update(); } -void PaintingArea::activate(int a){ - this->setLayerToActive(a); +void PaintingArea::movePositionActive(int x, int y){ + layerBundle[static_cast(activeLayer)].widthOffset += x; + layerBundle[static_cast(activeLayer)].hightOffset += y; } -void PaintingArea::setAlpha(int a){ - if(activeLayer>=0){ - layerStructure[activeLayer].alpha=a; +void PaintingArea::moveActiveLayer(int idx){ + if(idx==1){ + this->activateUpperLayer(); + }else if(idx==-1){ + this->activateLowerLayer(); } } -void PaintingArea::getMoveUp(int a){ - layerStructure[activeLayer].heightOffset-=a; -} - -void PaintingArea::getMoveDown(int a){ - layerStructure[activeLayer].heightOffset+=a; -} - -void PaintingArea::getMoveRight(int a){ - layerStructure[activeLayer].widthOffset+=a; -} - -void PaintingArea::getMoveLeft(int a){ - layerStructure[activeLayer].widthOffset-=a; -} - -void PaintingArea::getMoveLayerUp(){ - if(activeLayer=0){ - std::swap(layerStructure[activeLayer], layerStructure[activeLayer+1]); - activeLayer++; +void PaintingArea::slotActivateLayer(int a){ + if(a>=0 && a < static_cast(layerBundle.size())){ + this->setLayerToActive(a); } } -void PaintingArea::getMoveLayerDown(){ - if(activeLayer>0){ - std::swap(layerStructure[activeLayer], layerStructure[activeLayer-1]); - activeLayer--; - } +void PaintingArea::colorPickerSetFirstColor(){ + QColor clr = QColorDialog::getColor(colorPicker.getFirstColor(), nullptr, "Main Color"); + this->colorPicker.setFirstColor(clr); +} + +void PaintingArea::colorPickerSetSecondColor(){ + QColor clr = QColorDialog::getColor(colorPicker.getSecondColor(), nullptr, "Secondary Color"); + this->colorPicker.setSecondColor(clr); +} + +void PaintingArea::colorPickerSwitchColor(){ + this->colorPicker.switchColors(); +} + +void PaintingArea::createPenTool(){ + delete this->Tool; + Tool = new IntelliToolPen(this, &colorPicker); +} + +void PaintingArea::createPlainTool(){ + delete this->Tool; + Tool = new IntelliToolPlainTool(this, &colorPicker); +} + +void PaintingArea::createLineTool(){ + delete this->Tool; + Tool = new IntelliToolLine(this, &colorPicker); } // If a mouse button is pressed check if it was the @@ -209,18 +200,16 @@ void PaintingArea::getMoveLayerDown(){ // Set that we are currently drawing void PaintingArea::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { - if(this->activeLayer==-1){ - return; - } - LayerObject& active = layerStructure[activeLayer]; - - int x = event->x()-active.widthOffset; - int y = event->y()-active.heightOffset; - //TODO CALCULATE LAST POINT - lastPoint=QPoint(x,y); - scribbling = true; + if(Tool == nullptr) + return; + int x = event->x()-layerBundle[activeLayer].widthOffset; + int y = event->y()-layerBundle[activeLayer].hightOffset; + if(event->button() == Qt::LeftButton){ + Tool->onMouseLeftPressed(x, y); + }else if(event->button() == Qt::RightButton){ + Tool->onMouseRightPressed(x, y); } + update(); } @@ -229,38 +218,27 @@ void PaintingArea::mousePressEvent(QMouseEvent *event) // from the last position to the current void PaintingArea::mouseMoveEvent(QMouseEvent *event) { - if ((event->buttons() & Qt::LeftButton) && scribbling){ - if(this->activeLayer==-1){ - return; - } - LayerObject& active = layerStructure[activeLayer]; - - int x = event->x()-active.widthOffset; - int y = event->y()-active.heightOffset; - - //TODO CALCULATE NEW POINT - drawLineTo(QPoint(x,y)); - update(); - } + if(Tool == nullptr) + return; + int x = event->x()-layerBundle[activeLayer].widthOffset; + int y = event->y()-layerBundle[activeLayer].hightOffset; + Tool->onMouseMoved(x, y); + update(); } // If the button is released we set variables to stop drawing void PaintingArea::mouseReleaseEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton && scribbling) { - if(this->activeLayer==-1){ - return; - } - LayerObject& active = layerStructure[activeLayer]; - - int x = event->x()-active.widthOffset; - int y = event->y()-active.heightOffset; - - //TODO CALCULATE NEW POINT - drawLineTo(QPoint(x,y)); - update(); - scribbling = false; + if(Tool == nullptr) + return; + int x = event->x()-layerBundle[activeLayer].widthOffset; + int y = event->y()-layerBundle[activeLayer].hightOffset; + if(event->button() == Qt::LeftButton){ + Tool->onMouseLeftReleased(x, y); + }else if(event->button() == Qt::RightButton){ + Tool->onMouseRightReleased(x, y); } + update(); } // QPainter provides functions to draw on the widget @@ -280,62 +258,74 @@ void PaintingArea::paintEvent(QPaintEvent *event) // to cut down on the need to resize the image void PaintingArea::resizeEvent(QResizeEvent *event) { - if(this->activeLayer==-1){ - return; - } - LayerObject active = layerStructure[activeLayer]; - - QPainter painter(this); - QRect dirtyRec(QPoint(0,0), event->size()); - painter.drawImage(dirtyRec, active.image->getDisplayable(event->size(), active.alpha), dirtyRec); + //TODO wait till tool works update(); } -void PaintingArea::drawLineTo(const QPoint &endPoint) -{ - //// Used to draw on the widget - if(this->activeLayer==-1){ - return; - } - LayerObject active = layerStructure[activeLayer]; - - active.image->drawLine(lastPoint, endPoint,myPenColor, myPenWidth); - lastPoint = endPoint; - update(); -} void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){ - image_res->scaled(newSize,Qt::IgnoreAspectRatio); + //TODO implement } +void PaintingArea::activateUpperLayer(){ + if(activeLayer!=-1 && activeLayer0){ + std::swap(layerBundle[activeLayer], layerBundle[activeLayer-1]); + activeLayer--; + } +} + + void PaintingArea::assembleLayers(bool forSaving){ if(forSaving){ Canvas->fill(Qt::GlobalColor::transparent); }else{ Canvas->fill(Qt::GlobalColor::black); } - //TODO interpolation of alpha for saving - for(size_t i=0; igetDisplayable(layer.alpha); QColor clr_0; QColor clr_1; - for(int y=0; y=maxHeight) break; for(int x=0; xpixelColor(layer.widthOffset+x, layer.heightOffset+y); + if(layer.widthOffset+x<0) continue; + if(layer.widthOffset+x>=maxWidth) break; + clr_0=Canvas->pixelColor(layer.widthOffset+x, layer.hightOffset+y); clr_1=cpy.pixelColor(x,y); - float t = (float)clr_1.alpha()/255.f; - int r =(float)clr_1.red()*(t)+(float)clr_0.red()*(1.-t); - int g =(float)clr_1.green()*(t)+(float)clr_0.green()*(1.-t); - int b =(float)clr_1.blue()*(t)+(float)clr_0.blue()*(1.-t); + float t = static_cast(clr_1.alpha())/255.f; + int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); + int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); + int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(clr_0.blue()*(1.f-t))+0.5f); int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); clr_0.setRed(r); clr_0.setGreen(g); clr_0.setBlue(b); clr_0.setAlpha(a); - Canvas->setPixelColor(layer.widthOffset+x, layer.heightOffset+y, clr_0); + Canvas->setPixelColor(layer.widthOffset+x, layer.hightOffset+y, clr_0); } } } } + +void PaintingArea::createTempLayerAfter(int idx){ + if(idx>=0){ + LayerObject newLayer; + newLayer.alpha = 255; + newLayer.hight = layerBundle[idx].hight; + newLayer.width = layerBundle[idx].width; + newLayer.hightOffset = layerBundle[idx].hightOffset; + newLayer.widthOffset = layerBundle[idx].widthOffset; + newLayer.image = layerBundle[idx].image->getDeepCopy(); + layerBundle.insert(layerBundle.begin()+idx+1,newLayer); + } +} diff --git a/src/Painting/Layer/PaintingArea.h b/src/Painting/Layer/PaintingArea.h index febf33b..a4ec3fa 100644 --- a/src/Painting/Layer/PaintingArea.h +++ b/src/Painting/Layer/PaintingArea.h @@ -4,18 +4,25 @@ #include #include -#include"Image/IntelliImage.h" #include #include #include +#include "Image/IntelliImage.h" +#include "Image/IntelliRasterImage.h" +#include "Image/IntelliShapedImage.h" +#include "Tool/IntelliTool.h" +#include "IntelliHelper/IntelliColorPicker.h" + struct LayerObject{ IntelliImage* image; int width; - int height; + int hight; int widthOffset; - int heightOffset; + int hightOffset; int alpha=255; + + }; class PaintingArea : public QWidget @@ -24,46 +31,40 @@ class PaintingArea : public QWidget // for all Qt objects // QObjects handle events Q_OBJECT - + friend IntelliTool; public: PaintingArea(int maxWidth=600, int maxHeight=600, QWidget *parent = nullptr); + ~PaintingArea(); // Handles all events - bool openImage(const QString &fileName); - bool saveImage(const QString &fileName, const char *fileFormat); + bool open(const QString &fileName); + bool save(const QString &fileName, const char *fileFormat); int addLayer(int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image); + int addLayerAt(int idx, int width, int height, int widthOffset=0, int heightOffset=0, ImageType type = ImageType::Raster_Image); void deleteLayer(int index); void setLayerToActive(int index); - void setAlphaToLayer(int index, int alpha); + void setAlphaOfLayer(int index, int alpha); + void floodFill(int r, int g, int b, int a); + void movePositionActive(int x, int y); + void moveActiveLayer(int idx); - // Has the image been modified since last save - bool isModified() const { return modified; } + //change properties of colorPicker + void colorPickerSetFirstColor(); + void colorPickerSetSecondColor(); + void colorPickerSwitchColor(); - void setPenColor(const QColor &newColor); - QColor penColor() const { return myPenColor; } + //create tools + void createPenTool(); + void createPlainTool(); + void createLineTool(); - void setPenWidth(int newWidth); - int penWidth() const { return myPenWidth; } - - - QPixmap getAsPixmap(); public slots: // Events to handle - void clearImage(int r, int g, int b); - void activate(int a); - void deleteActiveLayer(); + void slotActivateLayer(int a); + void slotDeleteActiveLayer(); - void setAlpha(int a); - void getMoveUp(int a); - void getMoveDown(int a); - void getMoveRight(int a); - void getMoveLeft(int a); - void getMoveLayerUp(); - void getMoveLayerDown(); - //void setUp helper for konstruktor - void setUp(int maxWidth, int maxHeight); protected: void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; @@ -77,36 +78,28 @@ protected: void resizeEvent(QResizeEvent *event) override; private: + void setUp(int maxWidth, int maxHeight); + void activateUpperLayer(); + void activateLowerLayer(); QImage* Canvas; int maxWidth; int maxHeight; - std::vector layerStructure; + IntelliTool* Tool; + IntelliColorPicker colorPicker; + + std::vector layerBundle; int activeLayer=-1; void assembleLayers(bool forSaving=false); - void drawLineTo(const QPoint &endPoint); void resizeImage(QImage *image_res, const QSize &newSize); - // Will be marked true or false depending on if - // we have saved after a change - bool modified=false; - // Marked true or false depending on if the user - // is drawing - bool scribbling; - - // Holds the current pen width & color - int myPenWidth; - QColor myPenColor; - - // Stores the image being drawn - - // Stores the location at the current mouse event - QPoint lastPoint; + //Helper for Tool + void createTempLayerAfter(int idx); }; #endif diff --git a/src/Painting/Tool/IntelliColorPicker.cpp b/src/Painting/Tool/IntelliColorPicker.cpp new file mode 100644 index 0000000..55af5b9 --- /dev/null +++ b/src/Painting/Tool/IntelliColorPicker.cpp @@ -0,0 +1,36 @@ +#include "IntelliColorPicker.h" +#include "QDebug" + +IntelliColorPicker::IntelliColorPicker(PaintingArea* Area) + :IntelliTool(Area){ + firstColor = {255,0,0,255}; + secondColor = {0,0,255,255}; +} + +IntelliColorPicker::~IntelliColorPicker(){ + +} + +void IntelliColorPicker::getColorbar(int firstOrSecondColor = 1){ + QString Titel; + QColor newColor; + if(firstOrSecondColor == 1){ + Titel = "Choose first Color"; + newColor = QColorDialog::getColor(this->firstColor,nullptr,Titel); + this->firstColor = newColor; + qDebug() << "Firstcolor" << this->firstColor; + } + else{ + Titel = "Choose second Color"; + newColor = QColorDialog::getColor(this->secondColor,nullptr,Titel); + this->secondColor = newColor; + } +} + +QColor IntelliColorPicker::getFirstColor(){ + return firstColor; +} + +QColor IntelliColorPicker::getSecondColor(){ + return secondColor; +} diff --git a/src/Painting/Tool/IntelliTool.cpp b/src/Painting/Tool/IntelliTool.cpp new file mode 100644 index 0000000..606459c --- /dev/null +++ b/src/Painting/Tool/IntelliTool.cpp @@ -0,0 +1,77 @@ +#include"IntelliTool.h" +#include"Layer/PaintingArea.h" + +IntelliTool::IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker){ + this->Area=Area; + this->colorPicker=colorPicker; +} + + +IntelliTool::~IntelliTool(){ + +} + +void IntelliTool::onMouseRightPressed(int x, int y){ + if(drawing){ + drawing=false; + this->deleteToolLayer(); + } +} + +void IntelliTool::onMouseRightReleased(int x, int y){ + //optional for tool +} + +void IntelliTool::onMouseLeftPressed(int x, int y){ + this->drawing=true; + //create drawing layer + this->createToolLayer(); + Canvas->image->calculateVisiblity(); +} + +void IntelliTool::onMouseLeftReleased(int x, int y){ + if(drawing){ + drawing=false; + this->mergeToolLayer(); + this->deleteToolLayer(); + Active->image->calculateVisiblity(); + } +} + +void IntelliTool::onMouseMoved(int x, int y){ + if(drawing) + Canvas->image->calculateVisiblity(); +} + +void IntelliTool::createToolLayer(){ + Area->createTempLayerAfter(Area->activeLayer); + this->Active=&Area->layerBundle[Area->activeLayer]; + this->Canvas=&Area->layerBundle[Area->activeLayer+1]; +} + +void IntelliTool::mergeToolLayer(){ + QColor clr_0; + QColor clr_1; + for(int y=0; yhight; y++){ + for(int x=0; xwidth; x++){ + clr_0=Active->image->imageData.pixelColor(x,y); + clr_1=Canvas->image->imageData.pixelColor(x,y); + float t = static_cast(clr_1.alpha())/255.f; + int r =static_cast(static_cast(clr_1.red())*(t)+static_cast(clr_0.red())*(1.f-t)+0.5f); + int g =static_cast(static_cast(clr_1.green())*(t)+static_cast(clr_0.green())*(1.f-t)+0.5f); + int b =static_cast(static_cast(clr_1.blue())*(t)+static_cast(clr_0.blue()*(1.f-t))+0.5f); + int a =std::min(clr_0.alpha()+clr_1.alpha(), 255); + clr_0.setRed(r); + clr_0.setGreen(g); + clr_0.setBlue(b); + clr_0.setAlpha(a); + + Active->image->imageData.setPixelColor(x, y, clr_0); + } + } +} + +void IntelliTool::deleteToolLayer(){ + Area->deleteLayer(Area->activeLayer+1); + this->Canvas=nullptr; +} diff --git a/src/Painting/Tool/IntelliTool.h b/src/Painting/Tool/IntelliTool.h index b30b007..b534257 100644 --- a/src/Painting/Tool/IntelliTool.h +++ b/src/Painting/Tool/IntelliTool.h @@ -1,18 +1,34 @@ #ifndef Intelli_Tool_H #define Intelli_Tool_H -#include"Layer/PaintingArea.h" +#include "IntelliHelper/IntelliColorPicker.h" +#include + +class LayerObject; +class PaintingArea; class IntelliTool{ private: - LayerObject* DataValue; - LayerObject* Preview; + void createToolLayer(); + void mergeToolLayer(); + void deleteToolLayer(); +protected: + PaintingArea* Area; + IntelliColorPicker* colorPicker; + + LayerObject* Active; + LayerObject* Canvas; + bool drawing = false; + public: - IntelliTool(LayerObject* DataValue, LayerObject* Preview); + IntelliTool(PaintingArea* Area, IntelliColorPicker* colorPicker); virtual ~IntelliTool() = 0; - virtual void onMousePressed(QMouseEvent *event) = 0; - virtual void onMouseMoved(QMouseEvent* event)=0; - virtual void onMouseReleased(QMouseEvent* event)=0; + virtual void onMouseRightPressed(int x, int y); + virtual void onMouseRightReleased(int x, int y); + virtual void onMouseLeftPressed(int x, int y); + virtual void onMouseLeftReleased(int x, int y); + + virtual void onMouseMoved(int x, int y); }; #endif diff --git a/src/Painting/Tool/IntelliToolLine.cpp b/src/Painting/Tool/IntelliToolLine.cpp new file mode 100644 index 0000000..b3f1bf7 --- /dev/null +++ b/src/Painting/Tool/IntelliToolLine.cpp @@ -0,0 +1,56 @@ +#include "IntelliToolLine.h" +#include "Layer/PaintingArea.h" +#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(){ + +} + + +void IntelliToolLine::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolLine::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolLine::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + this->start=QPoint(x,y); + this->Canvas->image->drawLine(start, start, colorPicker->getFirstColor(),lineWidth); + Canvas->image->calculateVisiblity(); +} + +void IntelliToolLine::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolLine::onMouseMoved(int x, int y){ + IntelliTool::onMouseMoved(x,y); + if(this->drawing){ + this->Canvas->image->drawPlain(Qt::transparent); + QPoint next(x,y); + switch(lineStyle){ + case LineStyle::SOLID_LINE: + this->Canvas->image->drawLine(start,next,colorPicker->getFirstColor(),lineWidth); + break; + case LineStyle::DOTTED_LINE: + QPoint p1 =start.x() <= next.x() ? start : next; + QPoint p2 =start.x() < next.x() ? next : start; + int m = (float)(p2.y()-p1.y())/(float)(p2.x()-p1.x())+0.5f; + int c = start.y()-start.x()*m; + + break; + } + } + IntelliTool::onMouseMoved(x,y); +} diff --git a/src/Painting/Tool/IntelliToolLine.h b/src/Painting/Tool/IntelliToolLine.h new file mode 100644 index 0000000..637eb73 --- /dev/null +++ b/src/Painting/Tool/IntelliToolLine.h @@ -0,0 +1,31 @@ +#ifndef INTELLITOOLLINE_H +#define INTELLITOOLLINE_H +#include "IntelliTool.h" + +#include "QColor" +#include "QPoint" + +enum class LineStyle{ + SOLID_LINE, + DOTTED_LINE +}; + +class IntelliToolLine : public IntelliTool +{ + QPoint start; + int lineWidth; + LineStyle lineStyle; +public: + IntelliToolLine(PaintingArea* Area, IntelliColorPicker* colorPicker); + virtual ~IntelliToolLine() override; + + + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; + + virtual void onMouseMoved(int x, int y) override; +}; + +#endif // INTELLITOOLLINE_H diff --git a/src/Painting/Tool/IntelliToolPen.cpp b/src/Painting/Tool/IntelliToolPen.cpp new file mode 100644 index 0000000..14db6dd --- /dev/null +++ b/src/Painting/Tool/IntelliToolPen.cpp @@ -0,0 +1,42 @@ +#include "IntelliToolPen.h" +#include "Layer/PaintingArea.h" +#include "QDebug" +#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(){ + +} + +void IntelliToolPen::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolPen::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + +void IntelliToolPen::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + this->point=QPoint(x,y); + this->Canvas->image->drawPixel(point, colorPicker->getFirstColor()); + Canvas->image->calculateVisiblity(); +} + +void IntelliToolPen::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolPen::onMouseMoved(int x, int y){ + if(this->drawing){ + QPoint newPoint(x,y); + this->Canvas->image->drawLine(this->point, newPoint, colorPicker->getFirstColor(), penWidth); + this->point=newPoint; + } + IntelliTool::onMouseMoved(x,y); +} diff --git a/src/Painting/Tool/IntelliToolPen.h b/src/Painting/Tool/IntelliToolPen.h new file mode 100644 index 0000000..a5acc49 --- /dev/null +++ b/src/Painting/Tool/IntelliToolPen.h @@ -0,0 +1,23 @@ +#ifndef INTELLITOOLPEN_H +#define INTELLITOOLPEN_H + +#include"IntelliTool.h" +#include"QColor" +#include"QPoint" + +class IntelliToolPen : public IntelliTool{ + int penWidth; + QPoint point; +public: + IntelliToolPen(PaintingArea* Area, IntelliColorPicker* colorPicker); + virtual ~IntelliToolPen() override; + + virtual void onMouseRightPressed(int x, int y) override; + virtual void onMouseRightReleased(int x, int y) override; + virtual void onMouseLeftPressed(int x, int y) override; + virtual void onMouseLeftReleased(int x, int y) override; + + virtual void onMouseMoved(int x, int y) override; +}; + +#endif // INTELLITOOLPEN_H diff --git a/src/Painting/Tool/IntelliToolPlain.cpp b/src/Painting/Tool/IntelliToolPlain.cpp new file mode 100644 index 0000000..aaa2a02 --- /dev/null +++ b/src/Painting/Tool/IntelliToolPlain.cpp @@ -0,0 +1,30 @@ +#include "IntelliToolPlain.h" +#include "Layer/PaintingArea.h" +#include "QColorDialog" + +IntelliToolPlainTool::IntelliToolPlainTool(PaintingArea* Area, IntelliColorPicker* colorPicker) + :IntelliTool(Area, colorPicker){ +} + +void IntelliToolPlainTool::onMouseLeftPressed(int x, int y){ + IntelliTool::onMouseLeftPressed(x,y); + this->Canvas->image->drawPlain(colorPicker->getFirstColor()); + Canvas->image->calculateVisiblity(); +} + +void IntelliToolPlainTool::onMouseLeftReleased(int x, int y){ + IntelliTool::onMouseLeftReleased(x,y); +} + +void IntelliToolPlainTool::onMouseRightPressed(int x, int y){ + IntelliTool::onMouseRightPressed(x,y); +} + +void IntelliToolPlainTool::onMouseRightReleased(int x, int y){ + IntelliTool::onMouseRightReleased(x,y); +} + + +void IntelliToolPlainTool::onMouseMoved(int x, int y){ + IntelliTool::onMouseMoved(x,y); +} diff --git a/src/Painting/Tool/IntelliToolPlain.h b/src/Painting/Tool/IntelliToolPlain.h new file mode 100644 index 0000000..9e468f4 --- /dev/null +++ b/src/Painting/Tool/IntelliToolPlain.h @@ -0,0 +1,20 @@ +#ifndef INTELLITOOLFLOODFILLTOOL_H +#define INTELLITOOLFLOODFILLTOOL_H + +#include "IntelliTool.h" +#include "QColor" + +class IntelliToolPlainTool : public IntelliTool +{ +public: + IntelliToolPlainTool(PaintingArea *Area, IntelliColorPicker* colorPicker); + + void onMouseLeftPressed(int x, int y) override; + void onMouseLeftReleased(int x, int y) override; + void onMouseRightPressed(int x, int y) override; + void onMouseRightReleased(int x, int y) override; + void onMouseMoved(int x, int y) override; + +}; + +#endif // INTELLITOOLFLOODFILLTOOL_H diff --git a/src/Painting/icon.icns b/src/Painting/icon.icns new file mode 100644 index 0000000..791b4ae Binary files /dev/null and b/src/Painting/icon.icns differ diff --git a/src/Painting/widget.ui b/src/Painting/widget.ui index b90248d..b1d4c7b 100644 --- a/src/Painting/widget.ui +++ b/src/Painting/widget.ui @@ -6,8 +6,8 @@ 0 0 - 800 - 600 + 360 + 206