mirror of
https://github.com/creyD/intelliphoto.git
synced 2026-04-15 21:00:37 +02:00
Image structure
This commit is contained in:
9
IntelliPhoto/.gitignore
vendored
Normal file
9
IntelliPhoto/.gitignore
vendored
Normal file
@@ -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
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
#include<QPainter>
|
#include<QPainter>
|
||||||
|
|
||||||
IntelliImage::IntelliImage(int weight, int height)
|
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(){
|
IntelliImage::~IntelliImage(){
|
||||||
@@ -19,9 +19,8 @@ bool IntelliImage::loadImage(const QString &fileName){
|
|||||||
if (!loadedImage.load(fileName))
|
if (!loadedImage.load(fileName))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QSize newSize = loadedImage.size().expandedTo(imageData.size());
|
loadedImage =loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
|
||||||
resizeImage(&loadedImage, newSize);
|
imageData= loadedImage.convertToFormat(QImage::Format_ARGB32);
|
||||||
imageData = loadedImage;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ void IntelliImage::resizeImage(QImage *image, const QSize &newSize){
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Create a new image to display and fill it with white
|
// 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));
|
newImage.fill(qRgb(255, 255, 255));
|
||||||
|
|
||||||
// Draw the image
|
// 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){
|
void IntelliImage::floodFill(const QColor& color){
|
||||||
imageData.fill(color);
|
imageData.fill(color);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int IntelliImage::x(){
|
||||||
|
return imageData.size().width();
|
||||||
|
}
|
||||||
|
|
||||||
|
int IntelliImage::y(){
|
||||||
|
return imageData.size().height();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include<QPoint>
|
#include<QPoint>
|
||||||
#include<QColor>
|
#include<QColor>
|
||||||
#include<QSize>
|
#include<QSize>
|
||||||
|
#include<QWidget>
|
||||||
#include<vector>
|
#include<vector>
|
||||||
|
|
||||||
enum class ImageType{
|
enum class ImageType{
|
||||||
@@ -13,6 +14,7 @@ enum class ImageType{
|
|||||||
};
|
};
|
||||||
|
|
||||||
class IntelliImage{
|
class IntelliImage{
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeImage(QImage *image, const QSize &newSize);
|
void resizeImage(QImage *image, const QSize &newSize);
|
||||||
|
|
||||||
@@ -28,11 +30,17 @@ public:
|
|||||||
|
|
||||||
//returns the filtered output
|
//returns the filtered output
|
||||||
virtual QImage getDisplayable(const QSize& displaySize)=0;
|
virtual QImage getDisplayable(const QSize& displaySize)=0;
|
||||||
|
virtual QImage getDisplayable()=0;
|
||||||
|
|
||||||
|
//returns the filtered output
|
||||||
|
|
||||||
//sets the data for the visible image
|
//sets the data for the visible image
|
||||||
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
|
virtual void setPolygon(const std::vector<QPoint>& polygonData)=0;
|
||||||
|
|
||||||
virtual bool loadImage(const QString &fileName);
|
virtual bool loadImage(const QString &fileName);
|
||||||
|
|
||||||
|
int x();
|
||||||
|
int y();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,23 +3,25 @@
|
|||||||
#include<QRect>
|
#include<QRect>
|
||||||
#include<QDebug>
|
#include<QDebug>
|
||||||
|
|
||||||
IntelliRasterimage::IntelliRasterimage(int weight, int height)
|
IntelliRasterImage::IntelliRasterImage(int weight, int height)
|
||||||
:IntelliImage(weight, 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;
|
QImage copy = imageData;
|
||||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliRasterimage::setPolygon(const std::vector<QPoint>& polygonData){
|
void IntelliRasterImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||||
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
|
qDebug() << "Raster Image has no polygon data " << polygonData.size() <<"\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,16 @@
|
|||||||
|
|
||||||
#include"Image/IntelliImage.h"
|
#include"Image/IntelliImage.h"
|
||||||
|
|
||||||
class IntelliRasterimage : public IntelliImage{
|
class IntelliRasterImage : public IntelliImage{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IntelliRasterimage(int weight, int height);
|
IntelliRasterImage(int weight, int height);
|
||||||
virtual ~IntelliRasterimage() override;
|
virtual ~IntelliRasterImage() override;
|
||||||
|
|
||||||
//returns the filtered output
|
//returns the filtered output
|
||||||
virtual QImage getDisplayable(const QSize& displaySize) override;
|
virtual QImage getDisplayable(const QSize& displaySize) override;
|
||||||
|
virtual QImage getDisplayable() override;
|
||||||
|
|
||||||
|
|
||||||
//sets the data for the visible image
|
//sets the data for the visible image
|
||||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ IntelliShapedImage::~IntelliShapedImage(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QImage IntelliShapedImage::getDisplayable(){
|
||||||
|
return getDisplayable(imageData.size());
|
||||||
|
}
|
||||||
|
|
||||||
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){
|
QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){
|
||||||
QImage copy = imageData;
|
QImage copy = imageData;
|
||||||
QPoint extrem(copy.width()+1, 0);
|
QPoint startPoint;
|
||||||
QPoint startPoint(0,0);
|
QPoint extrem(0,copy.width()+1);
|
||||||
//traverse through y direction
|
|
||||||
for(int y = 0; y<copy.height(); y++){
|
for(int y = 0; y<copy.height(); y++){
|
||||||
extrem.setY(y);
|
extrem.setY(y);
|
||||||
startPoint.setY(y);
|
startPoint.setY(y);
|
||||||
@@ -25,24 +27,27 @@ QImage IntelliShapedImage::getDisplayable(const QSize& displaySize){
|
|||||||
for(int x=0; x<copy.width(); x++){
|
for(int x=0; x<copy.width(); x++){
|
||||||
startPoint.setX(x);
|
startPoint.setX(x);
|
||||||
//traverse all edges
|
//traverse all edges
|
||||||
int cutNumber = 0;
|
int cutNumberX = 0;
|
||||||
for(size_t i=0; i<polygonData.size()-1; i++){
|
for(size_t i=0; i<polygonData.size()-1; i++){
|
||||||
QPoint& start = polygonData[i];
|
QPoint& start = polygonData[i];
|
||||||
QPoint& end = polygonData[i+1];
|
QPoint& end = polygonData[i+1];
|
||||||
cutNumber += IntelliHelper::hasIntersection(startPoint, extrem, start, end);
|
cutNumberX+=IntelliHelper::hasIntersection(startPoint, extrem, start, end);
|
||||||
}
|
}
|
||||||
//check if zhe cutNumber is Even -> not in Polygon
|
//check if zhe cutNumber is Even -> not in Polygon
|
||||||
if(!(cutNumber&1)){
|
if(!(cutNumberX&1)){
|
||||||
QColor tmpColor(copy.color(y*copy.width()+x));
|
QColor tmpColor(0,0,0);
|
||||||
tmpColor.setAlpha(0);
|
tmpColor.setAlpha(0);
|
||||||
copy.setPixelColor(startPoint,tmpColor);
|
copy.setPixelColor(startPoint,tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
return copy.scaled(displaySize,Qt::IgnoreAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
void IntelliShapedImage::setPolygon(const std::vector<QPoint>& polygonData){
|
||||||
this->polygonData=polygonData;
|
for(auto element:polygonData){
|
||||||
|
this->polygonData.push_back(QPoint(element.x(), element.y()));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include"Image/IntelliImage.h"
|
#include"Image/IntelliImage.h"
|
||||||
|
|
||||||
class IntelliShapedImage : public IntelliImage{
|
class IntelliShapedImage : public IntelliImage{
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<QPoint> polygonData;
|
std::vector<QPoint> polygonData;
|
||||||
public:
|
public:
|
||||||
@@ -12,6 +13,7 @@ public:
|
|||||||
|
|
||||||
//returns the filtered output
|
//returns the filtered output
|
||||||
virtual QImage getDisplayable(const QSize& displaySize) override;
|
virtual QImage getDisplayable(const QSize& displaySize) override;
|
||||||
|
virtual QImage getDisplayable() override;
|
||||||
|
|
||||||
//sets the data for the visible image
|
//sets the data for the visible image
|
||||||
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
virtual void setPolygon(const std::vector<QPoint>& polygonData) override;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include"IntelliHelper.h"
|
#include"IntelliHelper.h"
|
||||||
#include<algorithm>
|
#include<algorithm>
|
||||||
|
|
||||||
int IntelliHelper::orientation(QPoint& p1, QPoint& p2, QPoint& p3){
|
int IntelliHelper::orientation(QPoint& p, QPoint& q, QPoint& r){
|
||||||
int value = (p2.x()-p1.x())*(p3.x()-p2.x())-
|
int value = (q.y()-p.y())*(r.x()-q.x())-
|
||||||
(p2.y()-p1.y())*(p3.y()-p2.y());
|
(q.x()-p.x())*(r.y()-q.y());
|
||||||
if(value==0) return 0;
|
if(value==0) return 0;
|
||||||
return (value>0)?1:2;
|
return (value>0)?1:2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ HEADERS += \
|
|||||||
FORMS += \
|
FORMS += \
|
||||||
widget.ui
|
widget.ui
|
||||||
|
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS += -fopenmp
|
||||||
|
QMAKE_LFLAGS += -fopenmp
|
||||||
|
|
||||||
RC_ICONS = icon.ico
|
RC_ICONS = icon.ico
|
||||||
|
|
||||||
# Default rules for deployment.
|
# Default rules for deployment.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.10.2, 2019-11-26T13:44:45. -->
|
<!-- Written by QtCreator 4.10.2, 2019-11-28T16:32:32. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.5 MinGW 64-bit</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.5 MinGW 64-bit</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.5 MinGW 64-bit</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.5 MinGW 64-bit</value>
|
||||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5125.win64_mingw73_kit</value>
|
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5125.win64_mingw73_kit</value>
|
||||||
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
|
||||||
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||||
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||||
@@ -322,7 +322,7 @@
|
|||||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||||
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
|
||||||
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Debug</value>
|
<value type="QString" key="RunConfiguration.WorkingDirectory.default">C:/Users/jonas/OneDrive/Documents/GitHub/intelliphoto/IntelliPhoto/build-IntelliPhoto-Desktop_Qt_5_12_5_MinGW_64_bit-Release</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||||
</valuemap>
|
</valuemap>
|
||||||
|
|||||||
@@ -1,57 +1,69 @@
|
|||||||
// ---------- PaintingArea.cpp ----------
|
// ---------- PaintingArea.cpp ----------
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
#include<QRect>
|
||||||
#include "PaintingArea.h"
|
#include "PaintingArea.h"
|
||||||
#include "Image/IntelliRasterImage.h"
|
#include "Image/IntelliRasterImage.h"
|
||||||
#include "Image/IntelliShapedimage.h"
|
#include "Image/IntelliShapedImage.h"
|
||||||
|
|
||||||
|
#include<vector>
|
||||||
|
#include<QPoint>
|
||||||
|
|
||||||
PaintingArea::PaintingArea(QWidget *parent)
|
PaintingArea::PaintingArea(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
//create standart image
|
//create standart image
|
||||||
this->image = new IntelliRasterimage(400,200);
|
this->image = new IntelliRasterImage(400,400);
|
||||||
|
std::vector<QPoint> 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();
|
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(){
|
void PaintingArea::setUp(){
|
||||||
// Roots the widget to the top left even if resized
|
// Roots the widget to the top left even if resized
|
||||||
setAttribute(Qt::WA_StaticContents);
|
setAttribute(Qt::WA_StaticContents);
|
||||||
|
|
||||||
// Set defaults for the monitored variables
|
// Set defaults for the monitored variables
|
||||||
modified = false;
|
|
||||||
scribbling = false;
|
scribbling = false;
|
||||||
myPenWidth = 1;
|
myPenWidth = 1;
|
||||||
myPenColor = Qt::blue;
|
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
|
// Used to load the image and place it in the widget
|
||||||
bool PaintingArea::openImage(const QString &fileName)
|
bool PaintingArea::openImage(const QString &fileName)
|
||||||
{
|
{
|
||||||
return image->loadImage(fileName);
|
bool open = image->loadImage(fileName);
|
||||||
|
update();
|
||||||
|
return open;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the current image
|
// Save the current image
|
||||||
bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat)
|
bool PaintingArea::saveImage(const QString &fileName, const char *fileFormat)
|
||||||
{
|
{
|
||||||
// Created to hold the image
|
// Created to hold the image
|
||||||
QImage visibleImage = image->getDisplayable(size());
|
QImage visibleImage = image->getDisplayable();
|
||||||
resizeImage(&visibleImage, size());
|
|
||||||
|
|
||||||
if (visibleImage.save(fileName, fileFormat)) {
|
if (visibleImage.save(fileName, fileFormat)) {
|
||||||
modified = false;
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -74,7 +86,6 @@ void PaintingArea::setPenWidth(int newWidth)
|
|||||||
void PaintingArea::clearImage()
|
void PaintingArea::clearImage()
|
||||||
{
|
{
|
||||||
image->floodFill(qRgb(255, 255, 255));
|
image->floodFill(qRgb(255, 255, 255));
|
||||||
modified = true;
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,25 +95,35 @@ void PaintingArea::clearImage()
|
|||||||
void PaintingArea::mousePressEvent(QMouseEvent *event)
|
void PaintingArea::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
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;
|
scribbling = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// When the mouse moves if the left button is clicked
|
// When the mouse moves if the left button is clicked
|
||||||
// we call the drawline function which draws a line
|
// we call the drawline function which draws a line
|
||||||
// from the last position to the current
|
// from the last position to the current
|
||||||
void PaintingArea::mouseMoveEvent(QMouseEvent *event)
|
void PaintingArea::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if ((event->buttons() & Qt::LeftButton) && scribbling)
|
if ((event->buttons() & 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the button is released we set variables to stop drawing
|
// If the button is released we set variables to stop drawing
|
||||||
void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
|
void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton && scribbling) {
|
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;
|
scribbling = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,62 +134,31 @@ void PaintingArea::mouseReleaseEvent(QMouseEvent *event)
|
|||||||
void PaintingArea::paintEvent(QPaintEvent *event)
|
void PaintingArea::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
QRect dirtyRec = event->rect();
|
||||||
// Returns the rectangle that needs to be updated
|
painter.drawImage(dirtyRec, image->getDisplayable(dirtyRec.size()), dirtyRec);
|
||||||
QRect dirtyRect = event->rect();
|
update();
|
||||||
|
|
||||||
// Draws the rectangle where the image needs to
|
|
||||||
// be updated
|
|
||||||
//painter.drawImage(dirtyRect, image, dirtyRect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize the image to slightly larger then the main window
|
// Resize the image to slightly larger then the main window
|
||||||
// to cut down on the need to resize the image
|
// to cut down on the need to resize the image
|
||||||
void PaintingArea::resizeEvent(QResizeEvent *event)
|
void PaintingArea::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
//resizing done here
|
QPainter painter(this);
|
||||||
//if (width() > image.width() || height() > image.height()) {
|
QRect dirtyRec(QPoint(0,0), event->size());
|
||||||
// int newWidth = qMax(width() + 128, image.width());
|
painter.drawImage(dirtyRec, image->getDisplayable(event->size()), dirtyRec);
|
||||||
// int newHeight = qMax(height() + 128, image.height());
|
update();
|
||||||
// resizeImage(&image, QSize(newWidth, newHeight));
|
//QWidget::resizeEvent(event);
|
||||||
// update();
|
|
||||||
//}
|
|
||||||
QWidget::resizeEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaintingArea::drawLineTo(const QPoint &endPoint)
|
void PaintingArea::drawLineTo(const QPoint &endPoint)
|
||||||
{
|
{
|
||||||
// Used to draw on the widget
|
// Used to draw on the widget
|
||||||
image->drawLine(lastPoint, endPoint,myPenColor, myPenWidth);
|
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;
|
lastPoint = endPoint;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the app is resized create a new image using
|
void PaintingArea::resizeImage(QImage *image_res, const QSize &newSize){
|
||||||
// the changes made to the image
|
image_res->scaled(newSize,Qt::IgnoreAspectRatio);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void drawLineTo(const QPoint &endPoint);
|
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
|
// Will be marked true or false depending on if
|
||||||
// we have saved after a change
|
// we have saved after a change
|
||||||
bool modified;
|
bool modified=false;
|
||||||
|
|
||||||
// Marked true or false depending on if the user
|
// Marked true or false depending on if the user
|
||||||
// is drawing
|
// is drawing
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
#include "GUI/IntelliPhotoGui.h"
|
#include "GUI/IntelliPhotoGui.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
// The main application
|
// The main application
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
|
||||||
// Create and open the main window
|
// Create and open the main window
|
||||||
IntelliPhotoGui window;
|
IntelliPhotoGui window;
|
||||||
window.show();
|
window.show();
|
||||||
|
|
||||||
// Display the main window
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user