IntelliPhoto 0.5

IntelliImage.cpp
Go to the documentation of this file.
1 #include "Image/IntelliImage.h"
2 #include <QSize>
3 #include <QPainter>
4
5 IntelliImage::IntelliImage(int weight, int height)
6 : imageData(QSize(weight, height), QImage::Format_ARGB32){
7 imageData.fill(QColor(255,255,255,255));
8 }
9
10 IntelliImage::~IntelliImage(){
11
12 }
13
14 bool IntelliImage::loadImage(const QString &fileName){
15 // Holds the image
16 QImage loadedImage;
17
18 // If the image wasn't loaded leave this function
19 if (!loadedImage.load(fileName))
20 return false;
21
22 // scaled Image to size of Layer
23 loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
24
25 imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
26 return true;
27 }
28
29 void IntelliImage::resizeImage(QImage*image, const QSize &newSize){
30 // Check if we need to redraw the image
31 if (image->size() == newSize)
32 return;
33
34 // Create a new image to display and fill it with white
35 QImage newImage(newSize, QImage::Format_ARGB32);
36 newImage.fill(qRgb(255, 255, 255));
37
38 // Draw the image
39 QPainter painter(&newImage);
40 painter.drawImage(QPoint(0, 0), *image);
41 *image = newImage;
42 }
43
44 void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
45 // Used to draw on the widget
46 QPainter painter(&imageData);
47
48 // Set the current settings for the pen
49 painter.setPen(QPen(color, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
50
51 // Draw a line from the last registered point to the current
52 painter.drawPoint(p1);
53 }
54
55 void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
56 // Used to draw on the widget
57 QPainter painter(&imageData);
58
59 // Set the current settings for the pen
60 painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
61 // Draw a line from the last registered point to the current
62 painter.drawPoint(p1);
63 }
64
65 void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
66 // Used to draw on the widget
67 QPainter painter(&imageData);
68
69 // Set the current settings for the pen
70 painter.setPen(QPen(color, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
71
72 // Draw a line from the last registered point to the current
73 painter.drawLine(p1, p2);
74 }
75
76 void IntelliImage::drawPlain(const QColor& color){
77 imageData.fill(color);
78 }
79
80 QColor IntelliImage::getPixelColor(QPoint& point){
81 return imageData.pixelColor(point);
82 }
IntelliImage::drawLine
virtual void drawLine(const QPoint &p1, const QPoint &p2, const QColor &color, const int &penWidth)
A function that draws A Line between two given Points in a given color.
Definition: IntelliImage.cpp:65
IntelliImage.h
IntelliImage::~IntelliImage
virtual ~IntelliImage()=0
An Abstract Destructor.
Definition: IntelliImage.cpp:10
IntelliImage::drawPixel
virtual void drawPixel(const QPoint &p1, const QColor &color)
A funtcion used to draw a pixel on the Image with the given Color.
Definition: IntelliImage.cpp:44
IntelliImage::loadImage
virtual bool loadImage(const QString &fileName)
A function that loads and sclaes an image to the fitting dimensions.
Definition: IntelliImage.cpp:14
IntelliImage::drawPoint
virtual void drawPoint(const QPoint &p1, const QColor &color, const int &penWidth)
A.
Definition: IntelliImage.cpp:55
IntelliImage::IntelliImage
IntelliImage(int weight, int height)
The Construcor of the IntelliImage. Given the Image dimensions.
Definition: IntelliImage.cpp:5
IntelliImage::resizeImage
void resizeImage(QImage *image, const QSize &newSize)
Definition: IntelliImage.cpp:29
IntelliImage::getPixelColor
virtual QColor getPixelColor(QPoint &point)
A function that returns the pixelcolor at a certain point.
Definition: IntelliImage.cpp:80
IntelliImage::imageData
QImage imageData
The underlying image data.
Definition: IntelliImage.h:32
IntelliImage::drawPlain
virtual void drawPlain(const QColor &color)
A function that clears the whole image in a given Color.
Definition: IntelliImage.cpp:76