bring the fastrenderer back again...

hihihi
This commit is contained in:
Jan Schuffenhauer
2020-01-09 10:35:01 +01:00
parent 72b235689e
commit 67b623a63a
7 changed files with 119 additions and 31 deletions

View File

@@ -2,9 +2,16 @@
#include <QSize>
#include <QPainter>
IntelliImage::IntelliImage(int weight, int height)
: imageData(QSize(weight, height), QImage::Format_ARGB32){
imageData.fill(QColor(255,255,255,255));
IntelliImage::IntelliImage(int width, int height, bool fastRendererOn)
: imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){
if(fastRendererOn){
imageData = imageData.convertToFormat(QImage::Format_ARGB32);
}
imageData.fill(QColor(255,255,255,255));
if(fastRendererOn){
imageData = imageData.convertToFormat(QImage::Format_Indexed8);
}
this->fastRenderer = fastRendererOn;
}
@@ -23,7 +30,7 @@ bool IntelliImage::loadImage(const QString &filePath){
// scaled Image to size of Layer
loadedImage = loadedImage.scaled(imageData.size(),Qt::IgnoreAspectRatio);
imageData = loadedImage.convertToFormat(QImage::Format_ARGB32);
imageData = loadedImage.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32);
return true;
}
@@ -33,17 +40,23 @@ 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_ARGB32);
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;
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
}
void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
// Used to draw on the widget
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
}
// Used to draw on the widget
QPainter painter(&imageData);
// Set the current settings for the pen
@@ -51,20 +64,32 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
// Draw a line from the last registered point to the current
painter.drawPoint(p1);
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
}
void IntelliImage::drawPoint(const QPoint &p1, const QColor& color, const int& penWidth){
// Used to draw on the widget
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
}
// 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.drawPoint(p1);
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
}
void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& color, const int& penWidth){
// Used to draw on the widget
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
}
// Used to draw on the widget
QPainter painter(&imageData);
// Set the current settings for the pen
@@ -72,16 +97,34 @@ void IntelliImage::drawLine(const QPoint &p1, const QPoint& p2, const QColor& co
// Draw a line from the last registered point to the current
painter.drawLine(p1, p2);
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
}
void IntelliImage::drawPlain(const QColor& color){
imageData.fill(color);
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
}
imageData.fill(color);
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_Indexed8);
}
}
QColor IntelliImage::getPixelColor(QPoint& point){
return imageData.pixelColor(point);
if(fastRenderer){
QImage copy = this->imageData.convertToFormat(QImage::Format_ARGB32);
return copy.pixelColor(point);
}
return imageData.pixelColor(point);
}
QImage IntelliImage::getImageData(){
return imageData;
return this->imageData;
}
void IntelliImage::updateRendererSetting(bool fastRendererOn){
this->fastRenderer = fastRendererOn;
this->imageData = this->imageData.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32);
}