mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: remove need for MainWindow when rendering the profile
Very annoyingly, to render the profile for printing / export, the profile still had to be show()n, thus requiring a parent window. Analysis of qmlprofile.c showed that this was due to the transformation matrix not being properly set up on non-show()n scenes. Instead, we can simply render via the QGraphicsScene (circumventing the QGraphicsView). The code was factored out into the ProfileWidget2::draw() function. This will hopefully make it easier to change the size-code of the profile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
13d4f595cb
commit
b39e88b8c6
5 changed files with 51 additions and 48 deletions
|
@ -2161,3 +2161,39 @@ 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, isGrayscale));
|
||||
|
||||
QPainter imgPainter(&image);
|
||||
imgPainter.setRenderHint(QPainter::Antialiasing);
|
||||
imgPainter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
scene()->render(&imgPainter, QRect(QPoint(), size), sceneRect, Qt::IgnoreAspectRatio);
|
||||
imgPainter.end();
|
||||
|
||||
if (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);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ public:
|
|||
bool isPlanner() const;
|
||||
double getFontPrintScale() const;
|
||||
void setFontPrintScale(double scale);
|
||||
void draw(QPainter *painter, const QRect &pos);
|
||||
QImage toImage(QSize size);
|
||||
#ifndef SUBSURFACE_MOBILE
|
||||
bool eventFilter(QObject *, QEvent *) override;
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue