[W.I.P.] Added a FasterRenderOption

Still completly buggy. and it crashes imediatly after input
This commit is contained in:
Jan Schuffenhauer
2020-01-08 19:01:05 +01:00
parent dd55a7158d
commit c04d8d6815
12 changed files with 131 additions and 22 deletions

View File

@@ -2,9 +2,10 @@
#include <QSize>
#include <QPainter>
IntelliImage::IntelliImage(int weight, int height)
: imageData(QSize(weight, height), QImage::Format_ARGB32){
IntelliImage::IntelliImage(int width, int height, bool fastRendererOn)
: imageData(QSize(width, height), fastRendererOn ? QImage::Format_Indexed8 : QImage::Format_ARGB32){
imageData.fill(QColor(255,255,255,255));
this->fastRenderer = fastRendererOn;
}
@@ -23,7 +24,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 +34,21 @@ 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;
updateRendererSetting(fastRenderer);
}
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 +56,28 @@ void IntelliImage::drawPixel(const QPoint &p1, const QColor& color){
// Draw a line from the last registered point to the current
painter.drawPoint(p1);
updateRendererSetting(fastRenderer);
}
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);
updateRendererSetting(fastRenderer);
}
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,12 +85,22 @@ 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);
updateRendererSetting(fastRenderer);
}
void IntelliImage::drawPlain(const QColor& color){
imageData.fill(color);
if(fastRenderer){
this->imageData = this->imageData.convertToFormat(QImage::Format_ARGB32);
}
imageData.fill(color);
updateRendererSetting(fastRenderer);
}
QColor IntelliImage::getPixelColor(QPoint& point){
return imageData.pixelColor(point);
}
void IntelliImage::updateRendererSetting(bool fastRendererOn){
this->fastRenderer = fastRendererOn;
this->imageData = this->imageData.convertToFormat(fastRenderer ? QImage::Format_Indexed8 : QImage::Format_ARGB32);
}