profile: for printing/mobile access ProfileScene directly

Instead of using the interactive ProfileWidget2, just
use the ProfileScene to render the profile for printing,
export and mobile. One layer (QWidget) less.

This removes all the kludges for handling DPR on mobile.
Thus, the rendering will now be off and have to be fixed
by redoing the scaling code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-08-04 07:27:41 +02:00 committed by Dirk Hohndel
parent 84ebd1d67a
commit 51dc5113c2
10 changed files with 70 additions and 136 deletions

View file

@ -1428,39 +1428,3 @@ struct dive *ProfileWidget2::mutable_dive() const
{
return const_cast<dive *>(d);
}
QImage ProfileWidget2::toImage(QSize size)
{
// The size of chart with respect to the scene is fixed - by convention - to 100.0.
// We add 2% to the height so that the dive computer name is not cut off.
QRectF sceneRect(0.0, 0.0, 100.0, 102.0);
QImage image(size, QImage::Format_ARGB32);
image.fill(getColor(::BACKGROUND, profileScene->isGrayscale));
QPainter imgPainter(&image);
imgPainter.setRenderHint(QPainter::Antialiasing);
imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
scene()->render(&imgPainter, QRect(QPoint(), size), sceneRect, Qt::IgnoreAspectRatio);
imgPainter.end();
if (profileScene->isGrayscale) {
// convert QImage to grayscale before rendering
for (int i = 0; i < image.height(); i++) {
QRgb *pixel = reinterpret_cast<QRgb *>(image.scanLine(i));
QRgb *end = pixel + image.width();
for (; pixel != end; pixel++) {
int gray_val = qGray(*pixel);
*pixel = QColor(gray_val, gray_val, gray_val).rgb();
}
}
}
return image;
}
void ProfileWidget2::draw(QPainter *painter, const QRect &pos)
{
QImage img = toImage(pos.size());
painter->drawImage(pos, img);
}