From 4c25365ea4347e1ac4eca339a88ff1420c342560 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 Jul 2010 19:58:19 -0600 Subject: [PATCH] Cover browser: Fix rendering of center cover when width of cover browser is less than the width of a single cover --- src/calibre/gui2/pictureflow/pictureflow.cpp | 23 +++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/pictureflow/pictureflow.cpp b/src/calibre/gui2/pictureflow/pictureflow.cpp index 8b58e03a11..450608cf6b 100644 --- a/src/calibre/gui2/pictureflow/pictureflow.cpp +++ b/src/calibre/gui2/pictureflow/pictureflow.cpp @@ -795,17 +795,20 @@ QRect PictureFlowPrivate::renderCenterSlide(const SlideInfo &slide) { int sw = src->height(); int sh = src->width(); int h = buffer.height(); - QRect rect(buffer.width()/2 - sw/2, 0, sw, h-1); - int left = rect.left(); - - if (left >= 0) { - int xcon = MIN(h-1, sh-1); - int ycon = MIN(sw, buffer.width() - left); - - for(int x = 0; x < xcon; x++) - for(int y = 0; y < ycon; y++) - buffer.setPixel(left + y, 1+x, src->pixel(x, y)); + int srcoff = 0; + int left = buffer.width()/2 - sw/2; + if (left < 0) { + srcoff = -left; + sw += left; + left = 0; } + QRect rect(left, 0, sw, h-1); + int xcon = MIN(h-1, sh-1); + int ycon = MIN(sw, buffer.width() - left); + + for(int x = 0; x < xcon; x++) + for(int y = 0; y < ycon; y++) + buffer.setPixel(left + y, 1+x, src->pixel(x, srcoff+y)); return rect; }