316
316
QImage KWPage::thumbnail(const QSize &size, KoShapeManager *shapeManager)
319
318
KoZoomHandler zoomHandler;
320
qreal zoom = size.width() / (zoomHandler.resolutionX() * width());
321
zoom = qMin(zoom, size.height() / (zoomHandler.resolutionY() * height()));
319
const qreal realWidth = zoomHandler.resolutionX() * width();
320
const qreal realHeight = zoomHandler.resolutionX() * height();
322
const qreal widthScale = size.width() / realWidth;
323
const qreal heightScale = size.height() / realHeight;
325
const qreal zoom = (widthScale > heightScale) ? heightScale : widthScale;
326
// adapt thumbnailSize to match the rendered page
327
QSize thumbnailSize(size);
328
if (widthScale > heightScale) {
329
const int thumbnailWidth = qMin(thumbnailSize.width(), qRound(realWidth*heightScale));
330
thumbnailSize.setWidth(thumbnailWidth);
332
const int thumbnailHeight = qMin(thumbnailSize.height(), qRound(realHeight*widthScale));
333
thumbnailSize.setHeight(thumbnailHeight);
322
336
zoomHandler.setZoom(zoom);
324
338
foreach(KoShape* shape, shapeManager->shapes()) {
325
339
shape->waitUntilReady(zoomHandler, false);
328
QImage img(size, QImage::Format_ARGB32);
342
QImage img(thumbnailSize, QImage::Format_ARGB32);
343
// paint white as default page background
344
img.fill(QColor(Qt::white).rgb());
330
345
QPainter gc(&img);
331
gc.fillRect(0, 0, img.width(), img.height(), QBrush(Qt::white));
346
gc.setRenderHint(QPainter::Antialiasing, true);
332
347
gc.translate(0, -zoomHandler.documentToViewY(offsetInDocument()));
333
348
gc.setClipRect(zoomHandler.documentToView(rect()));
334
349
shapeManager->paint(gc, zoomHandler, false);