~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to words/part/KWPage.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-07-16 10:51:29 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120716105129-es1ebubwiwlsfvv0
Tags: 1:2.4.92-0ubuntu1
New upstream RC release

Show diffs side-by-side

added added

removed removed

Lines of Context:
315
315
 
316
316
QImage KWPage::thumbnail(const QSize &size, KoShapeManager *shapeManager)
317
317
{
318
 
 
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();
 
321
 
 
322
    const qreal widthScale = size.width() / realWidth;
 
323
    const qreal heightScale = size.height() / realHeight;
 
324
 
 
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);
 
331
    } else {
 
332
        const int thumbnailHeight = qMin(thumbnailSize.height(), qRound(realHeight*widthScale));
 
333
        thumbnailSize.setHeight(thumbnailHeight);
 
334
    }
 
335
 
322
336
    zoomHandler.setZoom(zoom);
323
337
 
324
338
    foreach(KoShape* shape, shapeManager->shapes()) {
325
339
        shape->waitUntilReady(zoomHandler, false);
326
340
    }
327
341
 
328
 
    QImage img(size, QImage::Format_ARGB32);
329
 
 
 
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);