diff --git a/IntelliPhoto/.gitignore b/IntelliPhoto/.gitignore new file mode 100644 index 0000000..73e7536 --- /dev/null +++ b/IntelliPhoto/.gitignore @@ -0,0 +1,9 @@ + +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmp0l4rts +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmp0l4rts +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmp0l4rts +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmpcvzqoi +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmpu6gfxp +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmpqakvqm +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmpcvzqoi +IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug/usersjonasappdatalocaltemptmp0l4rts diff --git a/IntelliPhoto/Painting/Image/IntelliImage.cpp b/IntelliPhoto/Painting/Image/IntelliImage.cpp index b5bed6d..42be65d 100644 --- a/IntelliPhoto/Painting/Image/IntelliImage.cpp +++ b/IntelliPhoto/Painting/Image/IntelliImage.cpp @@ -3,8 +3,8 @@ #include IntelliImage::IntelliImage(int weight, int height) - :imageData(QSize(weight, height), QImage::Format_RGB32){ - + :imageData(QSize(weight, height), QImage::Format_ARGB32){ + imageData.fill(QColor(255,255,255,255)); } IntelliImage::~IntelliImage(){ @@ -19,9 +19,8 @@ bool IntelliImage::loadImage(const QString &fileName){ if (!loadedImage.load(fileName)) return false; - QSize newSize = loadedImage.size().expandedTo(imageData.size()); - resizeImage(&loadedImage, newSize); - imageData = loadedImage; + loadedImage =loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio); + imageData= loadedImage.convertToFormat(QImage::Format_ARGB32); return true; } @@ -31,7 +30,7 @@ void IntelliImage::resizeImage(QImage *image, const QSize &newSize){ return; // Create a new image to display and fill it with white - QImage newImage(newSize, QImage::Format_RGB32); + QImage newImage(newSize, QImage::Format_ARGB32); newImage.fill(qRgb(255, 255, 255)); // Draw the image @@ -68,4 +67,13 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co 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/IntelliPhoto/Painting/Image/IntelliImage.h b/IntelliPhoto/Painting/Image/IntelliImage.h index 6b15333..030e3be 100644 --- a/IntelliPhoto/Painting/Image/IntelliImage.h +++ b/IntelliPhoto/Painting/Image/IntelliImage.h @@ -5,6 +5,7 @@ #include #include #include +#include #include enum class ImageType{ @@ -13,6 +14,7 @@ enum class ImageType{ }; class IntelliImage{ + protected: void resizeImage(QImage *image, const QSize &newSize); @@ -28,11 +30,17 @@ public: //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/IntelliPhoto/Painting/Image/IntelliRasterImage.cpp b/IntelliPhoto/Painting/Image/IntelliRasterImage.cpp index eedeaf1..50eaa33 100644 --- a/IntelliPhoto/Painting/Image/IntelliRasterImage.cpp +++ b/IntelliPhoto/Painting/Image/IntelliRasterImage.cpp @@ -3,23 +3,25 @@ #include #include -IntelliRasterimage::IntelliRasterimage(int weight, int height) +IntelliRasterImage::IntelliRasterImage(int weight, int height) :IntelliImage(weight, height){ } -IntelliRasterimage::~IntelliRasterimage(){ +IntelliRasterImage::~IntelliRasterImage(){ } +QImage IntelliRasterImage::getDisplayable(){ + return getDisplayable(imageData.size()); +} - -QImage IntelliRasterimage::getDisplayable(const QSize& displaySize){ +QImage IntelliRasterImage::getDisplayable(const QSize& displaySize){ QImage copy = imageData; return copy.scaled(displaySize,Qt::IgnoreAspectRatio); } -void IntelliRasterimage::setPolygon(const std::vector& polygonData){ +void IntelliRasterImage::setPolygon(const std::vector& polygonData){ qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n"; return; } diff --git a/IntelliPhoto/Painting/Image/IntelliRasterImage.h b/IntelliPhoto/Painting/Image/IntelliRasterImage.h index 92ab05d..0e50087 100644 --- a/IntelliPhoto/Painting/Image/IntelliRasterImage.h +++ b/IntelliPhoto/Painting/Image/IntelliRasterImage.h @@ -3,13 +3,16 @@ #include"Image/IntelliImage.h" -class IntelliRasterimage : public IntelliImage{ +class IntelliRasterImage : public IntelliImage{ + public: - IntelliRasterimage(int weight, int height); - virtual ~IntelliRasterimage() override; + 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; diff --git a/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp b/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp index 7b9f9b5..9b9abb1 100644 --- a/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp +++ b/IntelliPhoto/Painting/Image/IntelliShapedImage.cpp @@ -12,12 +12,14 @@ IntelliShapedImage::~IntelliShapedImage(){ } +QImage IntelliShapedImage::getDisplayable(){ + return getDisplayable(imageData.size()); +} QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){ QImage copy = imageData; - QPoint extrem(copy.width()+1, 0); - QPoint startPoint(0,0); - //traverse through y direction + QPoint startPoint; + QPoint extrem(0,copy.width()+1); for(int y = 0; y not in Polygon - if(!(cutNumber&1)){ - QColor tmpColor(copy.color(y*copy.width()+x)); + 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){ - this->polygonData=polygonData; + for(auto element:polygonData){ + this->polygonData.push_back(QPoint(element.x(), element.y())); + } return; } diff --git a/IntelliPhoto/Painting/Image/IntelliShapedImage.h b/IntelliPhoto/Painting/Image/IntelliShapedImage.h index df6b916..a290b4f 100644 --- a/IntelliPhoto/Painting/Image/IntelliShapedImage.h +++ b/IntelliPhoto/Painting/Image/IntelliShapedImage.h @@ -4,6 +4,7 @@ #include"Image/IntelliImage.h" class IntelliShapedImage : public IntelliImage{ + protected: std::vector polygonData; public: @@ -12,6 +13,7 @@ public: //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; diff --git a/IntelliPhoto/Painting/IntelliHelper/IntelliHelper.cpp b/IntelliPhoto/Painting/IntelliHelper/IntelliHelper.cpp index cf42c3b..ef0e8fb 100644 --- a/IntelliPhoto/Painting/IntelliHelper/IntelliHelper.cpp +++ b/IntelliPhoto/Painting/IntelliHelper/IntelliHelper.cpp @@ -1,9 +1,9 @@ #include"IntelliHelper.h" #include -int IntelliHelper::orientation(QPoint& p1, QPoint& p2, QPoint& p3){ - int value = (p2.x()-p1.x())*(p3.x()-p2.x())- - (p2.y()-p1.y())*(p3.y()-p2.y()); +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; } diff --git a/IntelliPhoto/Painting/IntelliPhoto.pro b/IntelliPhoto/Painting/IntelliPhoto.pro index 9dd61a6..3d35323 100644 --- a/IntelliPhoto/Painting/IntelliPhoto.pro +++ b/IntelliPhoto/Painting/IntelliPhoto.pro @@ -35,6 +35,10 @@ HEADERS += \ FORMS += \ widget.ui + +QMAKE_CXXFLAGS += -fopenmp +QMAKE_LFLAGS += -fopenmp + RC_ICONS = icon.ico # Default rules for deployment. diff --git a/IntelliPhoto/Painting/IntelliPhoto.pro.user b/IntelliPhoto/Painting/IntelliPhoto.pro.user index bca451d..551135b 100644 --- a/IntelliPhoto/Painting/IntelliPhoto.pro.user +++ b/IntelliPhoto/Painting/IntelliPhoto.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -72,7 +72,7 @@ Desktop Qt 5.12.5 MinGW 64-bit Desktop Qt 5.12.5 MinGW 64-bit qt.qt5.5125.win64_mingw73_kit - 0 + 1 0 0 @@ -322,7 +322,7 @@ false true - C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug + C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release 1 diff --git a/IntelliPhoto/Painting/Layer/PaintingArea.cpp b/IntelliPhoto/Painting/Layer/PaintingArea.cpp index 616db7e..7c7f085 100644 --- a/IntelliPhoto/Painting/Layer/PaintingArea.cpp +++ b/IntelliPhoto/Painting/Layer/PaintingArea.cpp @@ -1,57 +1,69 @@ // ---------- PaintingArea.cpp ---------- #include +#include #include "PaintingArea.h" #include "Image/IntelliRasterImage.h" -#include "Image/IntelliShapedimage.h" +#include "Image/IntelliShapedImage.h" + +#include +#include PaintingArea::PaintingArea(QWidget *parent) : QWidget(parent) { //create standart image - this->image = new IntelliRasterimage(400,200); + 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(); } -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; - } -} - void PaintingArea::setUp(){ // Roots the widget to the top left even if resized setAttribute(Qt::WA_StaticContents); // Set defaults for the monitored variables - modified = false; 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) { - return image->loadImage(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(size()); - resizeImage(&visibleImage, size()); + QImage visibleImage = image->getDisplayable(); if (visibleImage.save(fileName, fileFormat)) { - modified = false; return true; } else { return false; @@ -74,7 +86,6 @@ void PaintingArea::setPenWidth(int newWidth) void PaintingArea::clearImage() { image->floodFill(qRgb(255, 255, 255)); - modified = true; update(); } @@ -84,25 +95,35 @@ void PaintingArea::clearImage() void PaintingArea::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { - lastPoint = event->pos(); + 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) - drawLineTo(event->pos()); + 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) { - drawLineTo(event->pos()); + 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; } } @@ -113,62 +134,31 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event) void PaintingArea::paintEvent(QPaintEvent *event) { QPainter painter(this); - - // Returns the rectangle that needs to be updated - QRect dirtyRect = event->rect(); - - // Draws the rectangle where the image needs to - // be updated - //painter.drawImage(dirtyRect, image, dirtyRect); + 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) { - //resizing done here - //if (width() > image.width() || height() > image.height()) { - // int newWidth = qMax(width() + 128, image.width()); - // int newHeight = qMax(height() + 128, image.height()); - // resizeImage(&image, QSize(newWidth, newHeight)); - // update(); - //} - QWidget::resizeEvent(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); - - // Set that the image hasn't been saved - modified = true; - - int rad = (myPenWidth / 2) + 2; - - // Call to update the rectangular space where we drew - update(QRect(lastPoint, endPoint).normalized() - .adjusted(-rad, -rad, +rad, +rad)); - - // Update the last position where we left off drawing lastPoint = endPoint; + update(); } -// When the app is resized create a new image using -// the changes made to the image -void PaintingArea::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_RGB32); - newImage.fill(qRgb(255, 255, 255)); - - // Draw the image - QPainter painter(&newImage); - painter.drawImage(QPoint(0, 0), *image); - *image = newImage; +void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){ + image_res->scaled(newSize,Qt::IgnoreAspectRatio); } diff --git a/IntelliPhoto/Painting/Layer/PaintingArea.h b/IntelliPhoto/Painting/Layer/PaintingArea.h index a2e6578..c3e1ea9 100644 --- a/IntelliPhoto/Painting/Layer/PaintingArea.h +++ b/IntelliPhoto/Painting/Layer/PaintingArea.h @@ -52,11 +52,11 @@ protected: private: void drawLineTo(const QPoint &endPoint); - void resizeImage(QImage *image, const QSize &newSize); + 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; + bool modified=false; // Marked true or false depending on if the user // is drawing diff --git a/IntelliPhoto/Painting/main.cpp b/IntelliPhoto/Painting/main.cpp index 7da03be..829aa52 100644 --- a/IntelliPhoto/Painting/main.cpp +++ b/IntelliPhoto/Painting/main.cpp @@ -1,16 +1,17 @@ #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(); - // Display the main window return app.exec(); }