Improve resolution of profile export

The way we export the profile image (as direct export but
also used for printing) is that we render the profile
from the screen to a Pixmap and save that to a file. Unfortunately
this results in very bad resultion and a blurred image.

This is an attempt to improve that situation but it's still far
from perfect: Rather than a QPixmap and grab, I now use a QImage
(where I can set the size) and render, and indeed the picture resolution
(when vied at fixed size) get's better this way. The disadvantage
is that icons get smaller at the same rate und so
there is a natural limit on how big we can get. Maybe somebody
with better Qt knowledge can take off from here. In my opinion
this is already a step in the right direction.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2020-08-07 11:43:49 +02:00 committed by Dirk Hohndel
parent 8f6d054140
commit c6fa415880
2 changed files with 11 additions and 2 deletions

View file

@ -4,6 +4,7 @@ core: add support for Shearwater Peregrine (requires firmware V79 or newer)
core: fix renumbering of imported dives [#2731]
mobile: fix editing tank information
planner: Handle zero length segments gracefully when replanning
profile: improve resolution in printing and export
mobile: disable download button if no connection is selected
mobile: fix incorrect time stamps on GPS track points created via location service
core: correctly recognize A1 as BLE dive computer

View file

@ -227,7 +227,15 @@ void exportProfile(const struct dive *dive, const QString filename)
ProfileWidget2 *profile = MainWindow::instance()->graphics;
profile->plotDive(dive, true, false, true);
profile->setToolTipVisibile(false);
QPixmap pix = profile->grab();
profile->setPrintMode(true);
double scale = profile->getFontPrintScale();
profile->setFontPrintScale(4 * scale);
QImage image = QImage(profile->size() * 4, QImage::Format_RGB32);
QPainter paint;
paint.begin(&image);
profile->render(&paint);
image.save(filename);
profile->setToolTipVisibile(true);
pix.save(filename);
profile->setFontPrintScale(scale);
profile->setPrintMode(false);
}