diff --git a/Abgabe/Abgabe 4/Painting/GUI/IntelliPhotoGui.cpp b/Abgabe/Abgabe 4/Painting/GUI/IntelliPhotoGui.cpp new file mode 100644 index 0000000..29af67e --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/GUI/IntelliPhotoGui.cpp @@ -0,0 +1,281 @@ +// ---------- IntelliPhotoGui.cpp ---------- + +#include + +#include "IntelliPhotoGui.h" +#include "Layer/PaintingArea.h" + +// IntelliPhotoGui constructor +IntelliPhotoGui::IntelliPhotoGui() +{ + //create Gui elemnts and lay them out + createGui(); + // Create actions + createActions(); + //create Menus + createMenus(); + //set style of the gui + setIntelliStyle(); + + // Size the app + resize(500, 500); +} + + +// User tried to close the app +void IntelliPhotoGui::closeEvent(QCloseEvent *event) +{ + // If they try to close maybeSave() returns true + // if no changes have been made and the app closes + if (maybeSave()) { + event->accept(); + } else { + + // If there have been changes ignore the event + event->ignore(); + } +} + +// Check if the current image has been changed and then +// open a dialog to open a file +void IntelliPhotoGui::open() +{ + // Check if changes have been made since last save + // maybeSave() returns true if no changes have been made + if (maybeSave()) { + + // Get the file to open from a dialog + // tr sets the window title to Open File + // QDir opens the current dirctory + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open File"), QDir::currentPath()); + + // If we have a file name load the image and place + // it in the paintingArea + if (!fileName.isEmpty()) + paintingArea->openImage(fileName); + } +} + +// Called when the user clicks Save As in the menu +void IntelliPhotoGui::save() +{ + // A QAction represents the action of the user clicking + QAction *action = qobject_cast(sender()); + + // Stores the array of bytes of the users data + QByteArray fileFormat = action->data().toByteArray(); + + // Pass it to be saved + 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); +} + +// Open an about dialog +void IntelliPhotoGui::about() +{ + // Window title and text to display + QMessageBox::about(this, tr("About Painting"), + tr("

IntelliPhoto Some nice ass looking software

")); +} + +// Define menu actions that call functions +void IntelliPhotoGui::createActions() +{ + //connect signal and slots of gui element + connect(this->clearButton, SIGNAL(clicked()), paintingArea, SLOT(clearImage())); + + // 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 + foreach (QByteArray format, QImageWriter::supportedImageFormats()) { + QString text = tr("%1...").arg(QString(format).toUpper()); + + // Create an action for each file format + QAction *action = new QAction(text, this); + + // Set an action for each file format + action->setData(format); + + // When clicked call IntelliPhotoGui::save() + connect(action, SIGNAL(triggered()), this, SLOT(save())); + + // 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("E&xit"), this); + exitAct->setShortcuts(QKeySequence::Quit); + connect(exitAct, 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()), + paintingArea, SLOT(clearImage())); + + // Create about action and tie to IntelliPhotoGui::about() + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + // Create about Qt action and tie to IntelliPhotoGui::aboutQt() + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +// Create the menubar +void IntelliPhotoGui::createMenus() +{ + // Create Save As option and the list of file types + saveAsMenu = new QMenu(tr("&Save As"), this); + foreach (QAction *action, saveAsActs) + saveAsMenu->addAction(action); + + // Attach all actions to File + fileMenu = new QMenu(tr("&File"), this); + fileMenu->addAction(openAct); + fileMenu->addMenu(saveAsMenu); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + // Attach all actions to Options + optionMenu = new QMenu(tr("&Options"), this); + optionMenu->addAction(penColorAct); + optionMenu->addAction(penWidthAct); + optionMenu->addSeparator(); + optionMenu->addAction(clearScreenAct); + + // Attach all actions to Help + helpMenu = new QMenu(tr("&Help"), this); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); + + // Add menu items to the menubar + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(optionMenu); + menuBar()->addMenu(helpMenu); +} + +void IntelliPhotoGui::createGui(){ + //create a central widget to work on + centralGuiWidget = new QWidget(this); + setCentralWidget(centralGuiWidget); + + //create the grid for the layout + mainLayout = new QGridLayout(centralGuiWidget); + centralGuiWidget->setLayout(mainLayout); + + //create Gui elements + clearButton = new QPushButton("Clear"); + paintingArea = new PaintingArea(); + + //set gui elemtns position + mainLayout->addWidget(paintingArea,0,0,10,10); + mainLayout->addWidget(clearButton,0,10,1,1); +} + +void IntelliPhotoGui::setIntelliStyle(){ + // Set the title + setWindowTitle("IntelliPhoto Prototype"); + //set style sheet + this->setStyleSheet("background-color:rgb(64,64,64)"); + this->centralGuiWidget->setStyleSheet("color:rgb(255,255,255)"); + this->menuBar()->setStyleSheet("color:rgb(255,255,255)"); +} + +bool IntelliPhotoGui::maybeSave() +{ + // Check for changes since last save + if (paintingArea->isModified()) { + QMessageBox::StandardButton ret; + + // Painting is the title + // Add text and the buttons + ret = QMessageBox::warning(this, tr("Painting"), + tr("The image has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); + + // If save button clicked call for file to be saved + if (ret == QMessageBox::Save) { + return saveFile("png"); + + // If cancel do nothing + } else if (ret == QMessageBox::Cancel) { + return false; + } + } + return true; +} + +bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat) +{ + // Define path, name and default file type + QString initialPath = QDir::currentPath() + "/untitled." + fileFormat; + + // Get selected file from dialog + // Add the proper file formats and extensions + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), + initialPath, + tr("%1 Files (*.%2);;All Files (*)") + .arg(QString::fromLatin1(fileFormat.toUpper())) + .arg(QString::fromLatin1(fileFormat))); + + // If no file do nothing + if (fileName.isEmpty()) { + return false; + } else { + + // Call for the file to be saved + return paintingArea->saveImage(fileName, fileFormat.constData()); + } +} + diff --git a/Abgabe/Abgabe 4/Painting/GUI/IntelliPhotoGui.h b/Abgabe/Abgabe 4/Painting/GUI/IntelliPhotoGui.h new file mode 100644 index 0000000..7e77cef --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/GUI/IntelliPhotoGui.h @@ -0,0 +1,77 @@ +#ifndef IntelliPhotoGui_H +#define IntelliPhotoGui_H + +#include +#include +#include +#include + +// PaintingArea used to paint the image +class PaintingArea; + +class IntelliPhotoGui : public QMainWindow +{ + // Declares our class as a QObject which is the base class + // for all Qt objects + // QObjects handle events + Q_OBJECT + +public: + 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 about(); + +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; + + // The menu widgets + QMenu *saveAsMenu; + QMenu *fileMenu; + QMenu *optionMenu; + QMenu *helpMenu; + + // All the actions that can occur + QAction *openAct; + + // Actions tied to specific file formats + QList saveAsActs; + QAction *exitAct; + QAction *penColorAct; + QAction *penWidthAct; + QAction *clearScreenAct; + QAction *aboutAct; + QAction *aboutQtAct; + + //main GUI elements + QWidget* centralGuiWidget; + QGridLayout *mainLayout; + QPushButton *clearButton; +}; + +#endif diff --git a/Abgabe/Abgabe 4/Painting/Image/IntelliImage.cpp b/Abgabe/Abgabe 4/Painting/Image/IntelliImage.cpp new file mode 100644 index 0000000..42be65d --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Image/IntelliImage.cpp @@ -0,0 +1,79 @@ +#include"Image/IntelliImage.h" +#include +#include + +IntelliImage::IntelliImage(int weight, int height) + :imageData(QSize(weight, height), QImage::Format_ARGB32){ + imageData.fill(QColor(255,255,255,255)); +} + +IntelliImage::~IntelliImage(){ + +} + +bool IntelliImage::loadImage(const QString &fileName){ + // Holds the image + QImage loadedImage; + + // If the image wasn't loaded leave this function + if (!loadedImage.load(fileName)) + return false; + + loadedImage =loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); + imageData= loadedImage.convertToFormat(QImage::Format_ARGB32); + return true; +} + +void IntelliImage::resizeImage(QImage *image, const QSize &newSize){ + // Check if we need to redraw the image + if (image->size() == newSize) + return; + + // Create a new image to display and fill it with white + QImage newImage(newSize, QImage::Format_ARGB32); + newImage.fill(qRgb(255, 255, 255)); + + // Draw the image + QPainter painter(&newImage); + painter.drawImage(QPoint(0, 0), *image); + *image = newImage; +} + +void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ + // Used to draw on the widget + QPainter painter(&imageData); + + // Set the current settings for the pen + painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + + // 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){ + // Used to draw on the widget + QPainter painter(&imageData); + + // Set the current settings for the pen + painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + + // Draw a line from the last registered point to the current + painter.drawLine(p1, p2); + +} + +void IntelliImage::floodFill(const QColor& color){ + imageData.fill(color); + +} + +int IntelliImage::x(){ + return imageData.size().width(); +} + +int IntelliImage::y(){ + return imageData.size().height(); +} diff --git a/Abgabe/Abgabe 4/Painting/Image/IntelliImage.h b/Abgabe/Abgabe 4/Painting/Image/IntelliImage.h new file mode 100644 index 0000000..030e3be --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Image/IntelliImage.h @@ -0,0 +1,46 @@ +#ifndef INTELLIIMAGE_H +#define INTELLIIMAGE_H + +#include +#include +#include +#include +#include +#include + +enum class ImageType{ + Raster_Image, + Shaped_Image +}; + +class IntelliImage{ + +protected: + void resizeImage(QImage *image, const QSize &newSize); + + QImage imageData; +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); + + //returns the filtered output + virtual QImage getDisplayable(const QSize& displaySize)=0; + virtual QImage getDisplayable()=0; + + //returns the filtered output + + //sets the data for the visible image + virtual void setPolygon(const std::vector& polygonData)=0; + + virtual bool loadImage(const QString &fileName); + + int x(); + int y(); +}; + +#endif diff --git a/Abgabe/Abgabe 4/Painting/Image/IntelliRasterImage.cpp b/Abgabe/Abgabe 4/Painting/Image/IntelliRasterImage.cpp new file mode 100644 index 0000000..50eaa33 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Image/IntelliRasterImage.cpp @@ -0,0 +1,27 @@ +#include"Image/IntelliRasterImage.h" +#include +#include +#include + +IntelliRasterImage::IntelliRasterImage(int weight, int height) + :IntelliImage(weight, height){ + +} + +IntelliRasterImage::~IntelliRasterImage(){ + +} + +QImage IntelliRasterImage::getDisplayable(){ + return getDisplayable(imageData.size()); +} + +QImage IntelliRasterImage::getDisplayable(const QSize& displaySize){ + QImage copy = imageData; + return copy.scaled(displaySize,Qt::IgnoreAspectRatio); +} + +void IntelliRasterImage::setPolygon(const std::vector& polygonData){ + qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n"; + return; +} diff --git a/Abgabe/Abgabe 4/Painting/Image/IntelliRasterImage.h b/Abgabe/Abgabe 4/Painting/Image/IntelliRasterImage.h new file mode 100644 index 0000000..0e50087 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Image/IntelliRasterImage.h @@ -0,0 +1,21 @@ +#ifndef INTELLIRASTER_H +#define INTELLIRASTER_H + +#include"Image/IntelliImage.h" + +class IntelliRasterImage : public IntelliImage{ + +public: + IntelliRasterImage(int weight, int height); + virtual ~IntelliRasterImage() override; + + //returns the filtered output + virtual QImage getDisplayable(const QSize& displaySize) override; + virtual QImage getDisplayable() override; + + + //sets the data for the visible image + virtual void setPolygon(const std::vector& polygonData) override; +}; + +#endif diff --git a/Abgabe/Abgabe 4/Painting/Image/IntelliShapedImage.cpp b/Abgabe/Abgabe 4/Painting/Image/IntelliShapedImage.cpp new file mode 100644 index 0000000..9b9abb1 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Image/IntelliShapedImage.cpp @@ -0,0 +1,53 @@ +#include"Image/IntelliShapedImage.h" +#include"IntelliHelper/IntelliHelper.h" +#include +#include +#include + +IntelliShapedImage::IntelliShapedImage(int weight, int height) + :IntelliImage(weight, height){ +} + +IntelliShapedImage::~IntelliShapedImage(){ + +} + +QImage IntelliShapedImage::getDisplayable(){ + return getDisplayable(imageData.size()); +} + +QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){ + QImage copy = imageData; + QPoint startPoint; + QPoint extrem(0,copy.width()+1); + for(int y = 0; y not in Polygon + if(!(cutNumberX&1)){ + QColor tmpColor(0,0,0); + tmpColor.setAlpha(0); + copy.setPixelColor(startPoint,tmpColor); + } + } + } + + return copy.scaled(displaySize,Qt::IgnoreAspectRatio); +} + +void IntelliShapedImage::setPolygon(const std::vector& polygonData){ + for(auto element:polygonData){ + this->polygonData.push_back(QPoint(element.x(), element.y())); + } + return; +} diff --git a/Abgabe/Abgabe 4/Painting/Image/IntelliShapedImage.h b/Abgabe/Abgabe 4/Painting/Image/IntelliShapedImage.h new file mode 100644 index 0000000..a290b4f --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Image/IntelliShapedImage.h @@ -0,0 +1,22 @@ +#ifndef INTELLISHAPE_H +#define INTELLISHAPE_H + +#include"Image/IntelliImage.h" + +class IntelliShapedImage : public IntelliImage{ + +protected: + std::vector polygonData; +public: + IntelliShapedImage(int weight, int height); + virtual ~IntelliShapedImage() override; + + //returns the filtered output + virtual QImage getDisplayable(const QSize& displaySize) override; + virtual QImage getDisplayable() override; + + //sets the data for the visible image + virtual void setPolygon(const std::vector& polygonData) override; +}; + +#endif diff --git a/Abgabe/Abgabe 4/Painting/IntelliHelper/IntelliHelper.cpp b/Abgabe/Abgabe 4/Painting/IntelliHelper/IntelliHelper.cpp new file mode 100644 index 0000000..ef0e8fb --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/IntelliHelper/IntelliHelper.cpp @@ -0,0 +1,39 @@ +#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/Abgabe/Abgabe 4/Painting/IntelliHelper/IntelliHelper.h b/Abgabe/Abgabe 4/Painting/IntelliHelper/IntelliHelper.h new file mode 100644 index 0000000..9e273f6 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/IntelliHelper/IntelliHelper.h @@ -0,0 +1,22 @@ +#ifndef INTELLIHELPER_H +#define INTELLIHELPER_H + +#include + + +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); + + //cheks if p1-q1 intersects with p2-q2 + static bool hasIntersection(QPoint& p1, QPoint& q1, QPoint& p2, QPoint& q2); +}; + +#endif diff --git a/Abgabe/Abgabe 4/Painting/IntelliPhoto.87de10b b/Abgabe/Abgabe 4/Painting/IntelliPhoto.87de10b new file mode 100644 index 0000000..934c6c1 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/IntelliPhoto.87de10b @@ -0,0 +1,337 @@ + + + + + + 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/Abgabe/Abgabe 4/Painting/IntelliPhoto.pro b/Abgabe/Abgabe 4/Painting/IntelliPhoto.pro new file mode 100644 index 0000000..3d35323 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/IntelliPhoto.pro @@ -0,0 +1,47 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + GUI/IntelliPhotoGui.cpp \ + Image/IntelliImage.cpp \ + Image/IntelliRasterImage.cpp \ + Image/IntelliShapedImage.cpp \ + IntelliHelper/IntelliHelper.cpp \ + Layer/PaintingArea.cpp \ + main.cpp + +HEADERS += \ + GUI/IntelliPhotoGui.h \ + Image/IntelliImage.h \ + Image/IntelliRasterImage.h \ + Image/IntelliShapedImage.h \ + IntelliHelper/IntelliHelper.h \ + Layer/PaintingArea.h + +FORMS += \ + widget.ui + + +QMAKE_CXXFLAGS += -fopenmp +QMAKE_LFLAGS += -fopenmp + +RC_ICONS = icon.ico + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/Abgabe/Abgabe 4/Painting/IntelliPhoto.pro.user b/Abgabe/Abgabe 4/Painting/IntelliPhoto.pro.user new file mode 100644 index 0000000..8c0d660 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/IntelliPhoto.pro.user @@ -0,0 +1,342 @@ + + + + + + EnvironmentId + {426164d9-3771-4235-8f83-cb0b49423ffc} + + + 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 + true + + + + 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 + 1 + 0 + 0 + + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-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/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-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/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-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 + + IntelliPhoto + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/Painting/IntelliPhoto.pro + + 3768 + false + true + true + false + false + true + + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Abgabe/Abgabe 4/Painting/IntelliPhoto.user b/Abgabe/Abgabe 4/Painting/IntelliPhoto.user new file mode 100644 index 0000000..574e287 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/IntelliPhoto.user @@ -0,0 +1,337 @@ + + + + + + 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/Abgabe/Abgabe 4/Painting/Layer/PaintingArea.cpp b/Abgabe/Abgabe 4/Painting/Layer/PaintingArea.cpp new file mode 100644 index 0000000..7c7f085 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Layer/PaintingArea.cpp @@ -0,0 +1,164 @@ +// ---------- PaintingArea.cpp ---------- + +#include +#include +#include "PaintingArea.h" +#include "Image/IntelliRasterImage.h" +#include "Image/IntelliShapedImage.h" + +#include +#include + +PaintingArea::PaintingArea(QWidget *parent) + : QWidget(parent) +{ + //create standart image + this->image = new IntelliRasterImage(400,400); + std::vector poly; + poly.push_back(QPoint(200,0)); + poly.push_back(QPoint(400,300)); + poly.push_back(QPoint(0,300)); + poly.push_back(QPoint(200,0)); + image->setPolygon(poly); + + this->setUp(); +} + +void PaintingArea::setUp(){ + // 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; + +} + +PaintingArea::PaintingArea(int width, int height, ImageType type, QWidget *parent) + : QWidget(parent){ + if(type==ImageType::Raster_Image){ + this->image = new IntelliRasterImage(width, height); + }else if(type==ImageType::Shaped_Image){ + this->image = new IntelliShapedImage(width, height); + }else{ + qDebug() << "No valid Image type error"; + return; + } + this->setUp(); +} + + +// Used to load the image and place it in the widget +bool PaintingArea::openImage(const QString &fileName) +{ + bool open = image->loadImage(fileName); + update(); + return open; +} + +// Save the current image +bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) +{ + // Created to hold the image + QImage visibleImage = image->getDisplayable(); + + if (visibleImage.save(fileName, fileFormat)) { + return true; + } else { + return false; + } +} + +// 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() +{ + image->floodFill(qRgb(255, 255, 255)); + update(); +} + +// If a mouse button is pressed check if it was the +// left button and if so store the current position +// Set that we are currently drawing +void PaintingArea::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + int x = event->x()*(float)image->x()/(float)size().width(); + int y = event->y()*(float)image->y()/(float)size().height(); + lastPoint=QPoint(x,y); + scribbling = true; + } +} + + +// When the mouse moves if the left button is clicked +// we call the drawline function which draws a line +// from the last position to the current +void PaintingArea::mouseMoveEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) && scribbling){ + int x = event->x()*(float)image->x()/(float)size().width(); + int y = event->y()*(float)image->y()/(float)size().height(); + drawLineTo(QPoint(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) { + int x = event->x()*(float)image->x()/(float)size().width(); + int y = event->y()*(float)image->y()/(float)size().height(); + drawLineTo(QPoint(x,y)); + update(); + scribbling = false; + } +} + +// QPainter provides functions to draw on the widget +// The QPaintEvent is sent to widgets that need to +// update themselves +void PaintingArea::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + QRect dirtyRec = event->rect(); + painter.drawImage(dirtyRec, image->getDisplayable(dirtyRec.size()), dirtyRec); + update(); +} + +// Resize the image to slightly larger then the main window +// to cut down on the need to resize the image +void PaintingArea::resizeEvent(QResizeEvent *event) +{ + QPainter painter(this); + QRect dirtyRec(QPoint(0,0), event->size()); + painter.drawImage(dirtyRec, image->getDisplayable(event->size()), dirtyRec); + update(); + //QWidget::resizeEvent(event); +} + +void PaintingArea::drawLineTo(const QPoint &endPoint) +{ + // Used to draw on the widget + image->drawLine(lastPoint, endPoint,myPenColor, myPenWidth); + lastPoint = endPoint; + update(); +} + +void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){ + image_res->scaled(newSize,Qt::IgnoreAspectRatio); +} + diff --git a/Abgabe/Abgabe 4/Painting/Layer/PaintingArea.h b/Abgabe/Abgabe 4/Painting/Layer/PaintingArea.h new file mode 100644 index 0000000..c3e1ea9 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Layer/PaintingArea.h @@ -0,0 +1,77 @@ + +#ifndef PaintingArea_H +#define PaintingArea_H + +#include +#include +#include"Image/IntelliImage.h" +#include +#include + +class PaintingArea : public QWidget +{ + // Declares our class as a QObject which is the base class + // for all Qt objects + // QObjects handle events + Q_OBJECT + +public: + //create raster image 400*200 + PaintingArea(QWidget *parent = nullptr); + PaintingArea(int width, int height, ImageType type, QWidget *parent = nullptr); + + // Handles all events + bool openImage(const QString &fileName); + bool saveImage(const QString &fileName, const char *fileFormat); + void setPenColor(const QColor &newColor); + void setPenWidth(int newWidth); + + // Has the image been modified since last save + bool isModified() const { return modified; } + QColor penColor() const { return myPenColor; } + int penWidth() const { return myPenWidth; } + +public slots: + + // Events to handle + void clearImage(); + + //void setUp helper for konstruktor + void setUp(); +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *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; + +private: + 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 + IntelliImage* image; + + // Stores the location at the current mouse event + QPoint lastPoint; +}; + +#endif + diff --git a/Abgabe/Abgabe 4/Painting/Scribble.pro.user.426164d b/Abgabe/Abgabe 4/Painting/Scribble.pro.user.426164d new file mode 100644 index 0000000..572799d --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/Scribble.pro.user.426164d @@ -0,0 +1,337 @@ + + + + + + EnvironmentId + {426164d9-3771-4235-8f83-cb0b49423ffc} + + + 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/OneDrive/Desktop/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/OneDrive/Desktop/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/OneDrive/Desktop/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 + Scribble2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/Scribble/Scribble.pro + + 3768 + false + true + true + false + false + true + + C:/Users/jonas/OneDrive/Desktop/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/Abgabe/Abgabe 4/Painting/icon.ico b/Abgabe/Abgabe 4/Painting/icon.ico new file mode 100644 index 0000000..f21cd00 Binary files /dev/null and b/Abgabe/Abgabe 4/Painting/icon.ico differ diff --git a/Abgabe/Abgabe 4/Painting/main.cpp b/Abgabe/Abgabe 4/Painting/main.cpp new file mode 100644 index 0000000..829aa52 --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/main.cpp @@ -0,0 +1,20 @@ +#include "GUI/IntelliPhotoGui.h" +#include +#include + +int main(int argc, char *argv[]) +{ + // The main application + QApplication app(argc, argv); + + + // Create and open the main window + IntelliPhotoGui window; + window.show(); + + return app.exec(); +} + + + + diff --git a/Abgabe/Abgabe 4/Painting/widget.ui b/Abgabe/Abgabe 4/Painting/widget.ui new file mode 100644 index 0000000..b90248d --- /dev/null +++ b/Abgabe/Abgabe 4/Painting/widget.ui @@ -0,0 +1,19 @@ + + + Widget + + + + 0 + 0 + 800 + 600 + + + + Widget + + + + + diff --git a/Painting/GUI/IntelliPhotoGui.cpp b/Painting/GUI/IntelliPhotoGui.cpp new file mode 100644 index 0000000..29af67e --- /dev/null +++ b/Painting/GUI/IntelliPhotoGui.cpp @@ -0,0 +1,281 @@ +// ---------- IntelliPhotoGui.cpp ---------- + +#include + +#include "IntelliPhotoGui.h" +#include "Layer/PaintingArea.h" + +// IntelliPhotoGui constructor +IntelliPhotoGui::IntelliPhotoGui() +{ + //create Gui elemnts and lay them out + createGui(); + // Create actions + createActions(); + //create Menus + createMenus(); + //set style of the gui + setIntelliStyle(); + + // Size the app + resize(500, 500); +} + + +// User tried to close the app +void IntelliPhotoGui::closeEvent(QCloseEvent *event) +{ + // If they try to close maybeSave() returns true + // if no changes have been made and the app closes + if (maybeSave()) { + event->accept(); + } else { + + // If there have been changes ignore the event + event->ignore(); + } +} + +// Check if the current image has been changed and then +// open a dialog to open a file +void IntelliPhotoGui::open() +{ + // Check if changes have been made since last save + // maybeSave() returns true if no changes have been made + if (maybeSave()) { + + // Get the file to open from a dialog + // tr sets the window title to Open File + // QDir opens the current dirctory + QString fileName = QFileDialog::getOpenFileName(this, + tr("Open File"), QDir::currentPath()); + + // If we have a file name load the image and place + // it in the paintingArea + if (!fileName.isEmpty()) + paintingArea->openImage(fileName); + } +} + +// Called when the user clicks Save As in the menu +void IntelliPhotoGui::save() +{ + // A QAction represents the action of the user clicking + QAction *action = qobject_cast(sender()); + + // Stores the array of bytes of the users data + QByteArray fileFormat = action->data().toByteArray(); + + // Pass it to be saved + 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); +} + +// Open an about dialog +void IntelliPhotoGui::about() +{ + // Window title and text to display + QMessageBox::about(this, tr("About Painting"), + tr("

IntelliPhoto Some nice ass looking software

")); +} + +// Define menu actions that call functions +void IntelliPhotoGui::createActions() +{ + //connect signal and slots of gui element + connect(this->clearButton, SIGNAL(clicked()), paintingArea, SLOT(clearImage())); + + // 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 + foreach (QByteArray format, QImageWriter::supportedImageFormats()) { + QString text = tr("%1...").arg(QString(format).toUpper()); + + // Create an action for each file format + QAction *action = new QAction(text, this); + + // Set an action for each file format + action->setData(format); + + // When clicked call IntelliPhotoGui::save() + connect(action, SIGNAL(triggered()), this, SLOT(save())); + + // 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("E&xit"), this); + exitAct->setShortcuts(QKeySequence::Quit); + connect(exitAct, 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()), + paintingArea, SLOT(clearImage())); + + // Create about action and tie to IntelliPhotoGui::about() + aboutAct = new QAction(tr("&About"), this); + connect(aboutAct, SIGNAL(triggered()), this, SLOT(about())); + + // Create about Qt action and tie to IntelliPhotoGui::aboutQt() + aboutQtAct = new QAction(tr("About &Qt"), this); + connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); +} + +// Create the menubar +void IntelliPhotoGui::createMenus() +{ + // Create Save As option and the list of file types + saveAsMenu = new QMenu(tr("&Save As"), this); + foreach (QAction *action, saveAsActs) + saveAsMenu->addAction(action); + + // Attach all actions to File + fileMenu = new QMenu(tr("&File"), this); + fileMenu->addAction(openAct); + fileMenu->addMenu(saveAsMenu); + fileMenu->addSeparator(); + fileMenu->addAction(exitAct); + + // Attach all actions to Options + optionMenu = new QMenu(tr("&Options"), this); + optionMenu->addAction(penColorAct); + optionMenu->addAction(penWidthAct); + optionMenu->addSeparator(); + optionMenu->addAction(clearScreenAct); + + // Attach all actions to Help + helpMenu = new QMenu(tr("&Help"), this); + helpMenu->addAction(aboutAct); + helpMenu->addAction(aboutQtAct); + + // Add menu items to the menubar + menuBar()->addMenu(fileMenu); + menuBar()->addMenu(optionMenu); + menuBar()->addMenu(helpMenu); +} + +void IntelliPhotoGui::createGui(){ + //create a central widget to work on + centralGuiWidget = new QWidget(this); + setCentralWidget(centralGuiWidget); + + //create the grid for the layout + mainLayout = new QGridLayout(centralGuiWidget); + centralGuiWidget->setLayout(mainLayout); + + //create Gui elements + clearButton = new QPushButton("Clear"); + paintingArea = new PaintingArea(); + + //set gui elemtns position + mainLayout->addWidget(paintingArea,0,0,10,10); + mainLayout->addWidget(clearButton,0,10,1,1); +} + +void IntelliPhotoGui::setIntelliStyle(){ + // Set the title + setWindowTitle("IntelliPhoto Prototype"); + //set style sheet + this->setStyleSheet("background-color:rgb(64,64,64)"); + this->centralGuiWidget->setStyleSheet("color:rgb(255,255,255)"); + this->menuBar()->setStyleSheet("color:rgb(255,255,255)"); +} + +bool IntelliPhotoGui::maybeSave() +{ + // Check for changes since last save + if (paintingArea->isModified()) { + QMessageBox::StandardButton ret; + + // Painting is the title + // Add text and the buttons + ret = QMessageBox::warning(this, tr("Painting"), + tr("The image has been modified.\n" + "Do you want to save your changes?"), + QMessageBox::Save | QMessageBox::Discard + | QMessageBox::Cancel); + + // If save button clicked call for file to be saved + if (ret == QMessageBox::Save) { + return saveFile("png"); + + // If cancel do nothing + } else if (ret == QMessageBox::Cancel) { + return false; + } + } + return true; +} + +bool IntelliPhotoGui::saveFile(const QByteArray &fileFormat) +{ + // Define path, name and default file type + QString initialPath = QDir::currentPath() + "/untitled." + fileFormat; + + // Get selected file from dialog + // Add the proper file formats and extensions + QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), + initialPath, + tr("%1 Files (*.%2);;All Files (*)") + .arg(QString::fromLatin1(fileFormat.toUpper())) + .arg(QString::fromLatin1(fileFormat))); + + // If no file do nothing + if (fileName.isEmpty()) { + return false; + } else { + + // Call for the file to be saved + return paintingArea->saveImage(fileName, fileFormat.constData()); + } +} + diff --git a/Painting/GUI/IntelliPhotoGui.h b/Painting/GUI/IntelliPhotoGui.h new file mode 100644 index 0000000..7e77cef --- /dev/null +++ b/Painting/GUI/IntelliPhotoGui.h @@ -0,0 +1,77 @@ +#ifndef IntelliPhotoGui_H +#define IntelliPhotoGui_H + +#include +#include +#include +#include + +// PaintingArea used to paint the image +class PaintingArea; + +class IntelliPhotoGui : public QMainWindow +{ + // Declares our class as a QObject which is the base class + // for all Qt objects + // QObjects handle events + Q_OBJECT + +public: + 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 about(); + +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; + + // The menu widgets + QMenu *saveAsMenu; + QMenu *fileMenu; + QMenu *optionMenu; + QMenu *helpMenu; + + // All the actions that can occur + QAction *openAct; + + // Actions tied to specific file formats + QList saveAsActs; + QAction *exitAct; + QAction *penColorAct; + QAction *penWidthAct; + QAction *clearScreenAct; + QAction *aboutAct; + QAction *aboutQtAct; + + //main GUI elements + QWidget* centralGuiWidget; + QGridLayout *mainLayout; + QPushButton *clearButton; +}; + +#endif diff --git a/Painting/Image/IntelliImage.cpp b/Painting/Image/IntelliImage.cpp new file mode 100644 index 0000000..42be65d --- /dev/null +++ b/Painting/Image/IntelliImage.cpp @@ -0,0 +1,79 @@ +#include"Image/IntelliImage.h" +#include +#include + +IntelliImage::IntelliImage(int weight, int height) + :imageData(QSize(weight, height), QImage::Format_ARGB32){ + imageData.fill(QColor(255,255,255,255)); +} + +IntelliImage::~IntelliImage(){ + +} + +bool IntelliImage::loadImage(const QString &fileName){ + // Holds the image + QImage loadedImage; + + // If the image wasn't loaded leave this function + if (!loadedImage.load(fileName)) + return false; + + loadedImage =loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); + imageData= loadedImage.convertToFormat(QImage::Format_ARGB32); + return true; +} + +void IntelliImage::resizeImage(QImage *image, const QSize &newSize){ + // Check if we need to redraw the image + if (image->size() == newSize) + return; + + // Create a new image to display and fill it with white + QImage newImage(newSize, QImage::Format_ARGB32); + newImage.fill(qRgb(255, 255, 255)); + + // Draw the image + QPainter painter(&newImage); + painter.drawImage(QPoint(0, 0), *image); + *image = newImage; +} + +void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){ + // Used to draw on the widget + QPainter painter(&imageData); + + // Set the current settings for the pen + painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + + // 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){ + // Used to draw on the widget + QPainter painter(&imageData); + + // Set the current settings for the pen + painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + + // Draw a line from the last registered point to the current + painter.drawLine(p1, p2); + +} + +void IntelliImage::floodFill(const QColor& color){ + imageData.fill(color); + +} + +int IntelliImage::x(){ + return imageData.size().width(); +} + +int IntelliImage::y(){ + return imageData.size().height(); +} diff --git a/Painting/Image/IntelliImage.h b/Painting/Image/IntelliImage.h new file mode 100644 index 0000000..030e3be --- /dev/null +++ b/Painting/Image/IntelliImage.h @@ -0,0 +1,46 @@ +#ifndef INTELLIIMAGE_H +#define INTELLIIMAGE_H + +#include +#include +#include +#include +#include +#include + +enum class ImageType{ + Raster_Image, + Shaped_Image +}; + +class IntelliImage{ + +protected: + void resizeImage(QImage *image, const QSize &newSize); + + QImage imageData; +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); + + //returns the filtered output + virtual QImage getDisplayable(const QSize& displaySize)=0; + virtual QImage getDisplayable()=0; + + //returns the filtered output + + //sets the data for the visible image + virtual void setPolygon(const std::vector& polygonData)=0; + + virtual bool loadImage(const QString &fileName); + + int x(); + int y(); +}; + +#endif diff --git a/Painting/Image/IntelliRasterImage.cpp b/Painting/Image/IntelliRasterImage.cpp new file mode 100644 index 0000000..50eaa33 --- /dev/null +++ b/Painting/Image/IntelliRasterImage.cpp @@ -0,0 +1,27 @@ +#include"Image/IntelliRasterImage.h" +#include +#include +#include + +IntelliRasterImage::IntelliRasterImage(int weight, int height) + :IntelliImage(weight, height){ + +} + +IntelliRasterImage::~IntelliRasterImage(){ + +} + +QImage IntelliRasterImage::getDisplayable(){ + return getDisplayable(imageData.size()); +} + +QImage IntelliRasterImage::getDisplayable(const QSize& displaySize){ + QImage copy = imageData; + return copy.scaled(displaySize,Qt::IgnoreAspectRatio); +} + +void IntelliRasterImage::setPolygon(const std::vector& polygonData){ + qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n"; + return; +} diff --git a/Painting/Image/IntelliRasterImage.h b/Painting/Image/IntelliRasterImage.h new file mode 100644 index 0000000..0e50087 --- /dev/null +++ b/Painting/Image/IntelliRasterImage.h @@ -0,0 +1,21 @@ +#ifndef INTELLIRASTER_H +#define INTELLIRASTER_H + +#include"Image/IntelliImage.h" + +class IntelliRasterImage : public IntelliImage{ + +public: + IntelliRasterImage(int weight, int height); + virtual ~IntelliRasterImage() override; + + //returns the filtered output + virtual QImage getDisplayable(const QSize& displaySize) override; + virtual QImage getDisplayable() override; + + + //sets the data for the visible image + virtual void setPolygon(const std::vector& polygonData) override; +}; + +#endif diff --git a/Painting/Image/IntelliShapedImage.cpp b/Painting/Image/IntelliShapedImage.cpp new file mode 100644 index 0000000..9b9abb1 --- /dev/null +++ b/Painting/Image/IntelliShapedImage.cpp @@ -0,0 +1,53 @@ +#include"Image/IntelliShapedImage.h" +#include"IntelliHelper/IntelliHelper.h" +#include +#include +#include + +IntelliShapedImage::IntelliShapedImage(int weight, int height) + :IntelliImage(weight, height){ +} + +IntelliShapedImage::~IntelliShapedImage(){ + +} + +QImage IntelliShapedImage::getDisplayable(){ + return getDisplayable(imageData.size()); +} + +QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){ + QImage copy = imageData; + QPoint startPoint; + QPoint extrem(0,copy.width()+1); + for(int y = 0; y not in Polygon + if(!(cutNumberX&1)){ + QColor tmpColor(0,0,0); + tmpColor.setAlpha(0); + copy.setPixelColor(startPoint,tmpColor); + } + } + } + + return copy.scaled(displaySize,Qt::IgnoreAspectRatio); +} + +void IntelliShapedImage::setPolygon(const std::vector& polygonData){ + for(auto element:polygonData){ + this->polygonData.push_back(QPoint(element.x(), element.y())); + } + return; +} diff --git a/Painting/Image/IntelliShapedImage.h b/Painting/Image/IntelliShapedImage.h new file mode 100644 index 0000000..a290b4f --- /dev/null +++ b/Painting/Image/IntelliShapedImage.h @@ -0,0 +1,22 @@ +#ifndef INTELLISHAPE_H +#define INTELLISHAPE_H + +#include"Image/IntelliImage.h" + +class IntelliShapedImage : public IntelliImage{ + +protected: + std::vector polygonData; +public: + IntelliShapedImage(int weight, int height); + virtual ~IntelliShapedImage() override; + + //returns the filtered output + virtual QImage getDisplayable(const QSize& displaySize) override; + virtual QImage getDisplayable() override; + + //sets the data for the visible image + virtual void setPolygon(const std::vector& polygonData) override; +}; + +#endif diff --git a/Painting/IntelliHelper/IntelliHelper.cpp b/Painting/IntelliHelper/IntelliHelper.cpp new file mode 100644 index 0000000..ef0e8fb --- /dev/null +++ b/Painting/IntelliHelper/IntelliHelper.cpp @@ -0,0 +1,39 @@ +#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/Painting/IntelliHelper/IntelliHelper.h b/Painting/IntelliHelper/IntelliHelper.h new file mode 100644 index 0000000..9e273f6 --- /dev/null +++ b/Painting/IntelliHelper/IntelliHelper.h @@ -0,0 +1,22 @@ +#ifndef INTELLIHELPER_H +#define INTELLIHELPER_H + +#include + + +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); + + //cheks if p1-q1 intersects with p2-q2 + static bool hasIntersection(QPoint& p1, QPoint& q1, QPoint& p2, QPoint& q2); +}; + +#endif diff --git a/Painting/IntelliPhoto.87de10b b/Painting/IntelliPhoto.87de10b new file mode 100644 index 0000000..934c6c1 --- /dev/null +++ b/Painting/IntelliPhoto.87de10b @@ -0,0 +1,337 @@ + + + + + + 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/Painting/IntelliPhoto.pro b/Painting/IntelliPhoto.pro new file mode 100644 index 0000000..3d35323 --- /dev/null +++ b/Painting/IntelliPhoto.pro @@ -0,0 +1,47 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + GUI/IntelliPhotoGui.cpp \ + Image/IntelliImage.cpp \ + Image/IntelliRasterImage.cpp \ + Image/IntelliShapedImage.cpp \ + IntelliHelper/IntelliHelper.cpp \ + Layer/PaintingArea.cpp \ + main.cpp + +HEADERS += \ + GUI/IntelliPhotoGui.h \ + Image/IntelliImage.h \ + Image/IntelliRasterImage.h \ + Image/IntelliShapedImage.h \ + IntelliHelper/IntelliHelper.h \ + Layer/PaintingArea.h + +FORMS += \ + widget.ui + + +QMAKE_CXXFLAGS += -fopenmp +QMAKE_LFLAGS += -fopenmp + +RC_ICONS = icon.ico + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/Painting/IntelliPhoto.pro.user b/Painting/IntelliPhoto.pro.user new file mode 100644 index 0000000..8c0d660 --- /dev/null +++ b/Painting/IntelliPhoto.pro.user @@ -0,0 +1,342 @@ + + + + + + EnvironmentId + {426164d9-3771-4235-8f83-cb0b49423ffc} + + + 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 + true + + + + 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 + 1 + 0 + 0 + + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-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/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-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/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-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 + + IntelliPhoto + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/Painting/IntelliPhoto.pro + + 3768 + false + true + true + false + false + true + + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Painting/IntelliPhoto.user b/Painting/IntelliPhoto.user new file mode 100644 index 0000000..574e287 --- /dev/null +++ b/Painting/IntelliPhoto.user @@ -0,0 +1,337 @@ + + + + + + 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/Painting/Layer/PaintingArea.cpp b/Painting/Layer/PaintingArea.cpp new file mode 100644 index 0000000..7c7f085 --- /dev/null +++ b/Painting/Layer/PaintingArea.cpp @@ -0,0 +1,164 @@ +// ---------- PaintingArea.cpp ---------- + +#include +#include +#include "PaintingArea.h" +#include "Image/IntelliRasterImage.h" +#include "Image/IntelliShapedImage.h" + +#include +#include + +PaintingArea::PaintingArea(QWidget *parent) + : QWidget(parent) +{ + //create standart image + this->image = new IntelliRasterImage(400,400); + std::vector poly; + poly.push_back(QPoint(200,0)); + poly.push_back(QPoint(400,300)); + poly.push_back(QPoint(0,300)); + poly.push_back(QPoint(200,0)); + image->setPolygon(poly); + + this->setUp(); +} + +void PaintingArea::setUp(){ + // 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; + +} + +PaintingArea::PaintingArea(int width, int height, ImageType type, QWidget *parent) + : QWidget(parent){ + if(type==ImageType::Raster_Image){ + this->image = new IntelliRasterImage(width, height); + }else if(type==ImageType::Shaped_Image){ + this->image = new IntelliShapedImage(width, height); + }else{ + qDebug() << "No valid Image type error"; + return; + } + this->setUp(); +} + + +// Used to load the image and place it in the widget +bool PaintingArea::openImage(const QString &fileName) +{ + bool open = image->loadImage(fileName); + update(); + return open; +} + +// Save the current image +bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat) +{ + // Created to hold the image + QImage visibleImage = image->getDisplayable(); + + if (visibleImage.save(fileName, fileFormat)) { + return true; + } else { + return false; + } +} + +// 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() +{ + image->floodFill(qRgb(255, 255, 255)); + update(); +} + +// If a mouse button is pressed check if it was the +// left button and if so store the current position +// Set that we are currently drawing +void PaintingArea::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) { + int x = event->x()*(float)image->x()/(float)size().width(); + int y = event->y()*(float)image->y()/(float)size().height(); + lastPoint=QPoint(x,y); + scribbling = true; + } +} + + +// When the mouse moves if the left button is clicked +// we call the drawline function which draws a line +// from the last position to the current +void PaintingArea::mouseMoveEvent(QMouseEvent *event) +{ + if ((event->buttons() & Qt::LeftButton) && scribbling){ + int x = event->x()*(float)image->x()/(float)size().width(); + int y = event->y()*(float)image->y()/(float)size().height(); + drawLineTo(QPoint(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) { + int x = event->x()*(float)image->x()/(float)size().width(); + int y = event->y()*(float)image->y()/(float)size().height(); + drawLineTo(QPoint(x,y)); + update(); + scribbling = false; + } +} + +// QPainter provides functions to draw on the widget +// The QPaintEvent is sent to widgets that need to +// update themselves +void PaintingArea::paintEvent(QPaintEvent *event) +{ + QPainter painter(this); + QRect dirtyRec = event->rect(); + painter.drawImage(dirtyRec, image->getDisplayable(dirtyRec.size()), dirtyRec); + update(); +} + +// Resize the image to slightly larger then the main window +// to cut down on the need to resize the image +void PaintingArea::resizeEvent(QResizeEvent *event) +{ + QPainter painter(this); + QRect dirtyRec(QPoint(0,0), event->size()); + painter.drawImage(dirtyRec, image->getDisplayable(event->size()), dirtyRec); + update(); + //QWidget::resizeEvent(event); +} + +void PaintingArea::drawLineTo(const QPoint &endPoint) +{ + // Used to draw on the widget + image->drawLine(lastPoint, endPoint,myPenColor, myPenWidth); + lastPoint = endPoint; + update(); +} + +void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){ + image_res->scaled(newSize,Qt::IgnoreAspectRatio); +} + diff --git a/Painting/Layer/PaintingArea.h b/Painting/Layer/PaintingArea.h new file mode 100644 index 0000000..c3e1ea9 --- /dev/null +++ b/Painting/Layer/PaintingArea.h @@ -0,0 +1,77 @@ + +#ifndef PaintingArea_H +#define PaintingArea_H + +#include +#include +#include"Image/IntelliImage.h" +#include +#include + +class PaintingArea : public QWidget +{ + // Declares our class as a QObject which is the base class + // for all Qt objects + // QObjects handle events + Q_OBJECT + +public: + //create raster image 400*200 + PaintingArea(QWidget *parent = nullptr); + PaintingArea(int width, int height, ImageType type, QWidget *parent = nullptr); + + // Handles all events + bool openImage(const QString &fileName); + bool saveImage(const QString &fileName, const char *fileFormat); + void setPenColor(const QColor &newColor); + void setPenWidth(int newWidth); + + // Has the image been modified since last save + bool isModified() const { return modified; } + QColor penColor() const { return myPenColor; } + int penWidth() const { return myPenWidth; } + +public slots: + + // Events to handle + void clearImage(); + + //void setUp helper for konstruktor + void setUp(); +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *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; + +private: + 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 + IntelliImage* image; + + // Stores the location at the current mouse event + QPoint lastPoint; +}; + +#endif + diff --git a/Painting/Scribble.pro.user.426164d b/Painting/Scribble.pro.user.426164d new file mode 100644 index 0000000..572799d --- /dev/null +++ b/Painting/Scribble.pro.user.426164d @@ -0,0 +1,337 @@ + + + + + + EnvironmentId + {426164d9-3771-4235-8f83-cb0b49423ffc} + + + 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/OneDrive/Desktop/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/OneDrive/Desktop/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/OneDrive/Desktop/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 + Scribble2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/Scribble/Scribble.pro + + 3768 + false + true + true + false + false + true + + C:/Users/jonas/OneDrive/Desktop/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/Painting/icon.ico b/Painting/icon.ico new file mode 100644 index 0000000..f21cd00 Binary files /dev/null and b/Painting/icon.ico differ diff --git a/Painting/main.cpp b/Painting/main.cpp new file mode 100644 index 0000000..829aa52 --- /dev/null +++ b/Painting/main.cpp @@ -0,0 +1,20 @@ +#include "GUI/IntelliPhotoGui.h" +#include +#include + +int main(int argc, char *argv[]) +{ + // The main application + QApplication app(argc, argv); + + + // Create and open the main window + IntelliPhotoGui window; + window.show(); + + return app.exec(); +} + + + + diff --git a/Painting/widget.ui b/Painting/widget.ui new file mode 100644 index 0000000..b90248d --- /dev/null +++ b/Painting/widget.ui @@ -0,0 +1,19 @@ + + + Widget + + + + 0 + 0 + 800 + 600 + + + + Widget + + + + +