if (scaled_pixmap)
delete scaled_pixmap;
float width_f = float(width()) / float(pixmap->width());
float height_f = float(height()) / float(pixmap->height());
float zoom_f = (width_f < height_f ? width_f : height_f);
scaled_pixmap = pixmap->scaled(zoom_f, zoom_f, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
if (!scaled_pixmap) {
resizeEvent(&event);
}
painter.save();
painter.
fillRect(event
->rect
(),
QColor("black"));
// the zooming in resizeEvent() ensures that only one of these is non-zero
h_offset = (width() - scaled_pixmap->width()) / 2; // if frame is wider than image
v_offset = (height() - scaled_pixmap->height()) / 2; // if frame is taller
painter.drawPixmap(h_offset, v_offset, scaled_pixmap);
painter.restore();
}