From 6edf7696956587d41813fd81900cd24d0d22fb80 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 1 Jul 2007 18:01:29 +0200 Subject: [PATCH] updateImageSize() now takes the whole ImlibImageList into consideration --- src/imgview.cpp | 126 +++++++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 44 deletions(-) diff --git a/src/imgview.cpp b/src/imgview.cpp index 2d8c959..fde5c35 100644 --- a/src/imgview.cpp +++ b/src/imgview.cpp @@ -49,13 +49,13 @@ void ComicImageView::drawContents(QPainter *p, int clipx, int clipy, int clipw, if (iangle > 1 && !orgimage[1].isEmpty()) //switch image pointers to reflect rotation angle { - image1 = orgimage[1].current(); - image2 = orgimage[0].current(); + image1 = orgimage[1].getFirst(); + image2 = orgimage[0].getFirst(); } else { - image1 = orgimage[0].current(); - image2 = orgimage[1].current(); + image1 = orgimage[0].getFirst(); + image2 = orgimage[1].getFirst(); } int px = clipx - xoff; @@ -166,7 +166,7 @@ void ComicImageView::setImage(ImlibImage *img, bool preserveangle) orgimage[0].append(img); if (iangle != 0 && !orgimage[0].isEmpty()) - orgimage[0].current()->rotate(iangle); + orgimage[0].getFirst()->rotate(iangle); updateImageSize(); ensureVisible(1, 1); @@ -185,7 +185,7 @@ void ComicImageView::setImage(ImlibImageList &imglist, bool preserveangle) orgimage[0] = imglist; if (iangle != 0 && !orgimage[0].isEmpty()) - orgimage[0].current()->rotate(iangle); + orgimage[0].getFirst()->rotate(iangle); updateImageSize(); ensureVisible(1, 1); @@ -207,9 +207,9 @@ void ComicImageView::setImage(ImlibImage *img1, ImlibImage *img2, bool preservea if (iangle != 0) { if (!orgimage[0].isEmpty()) - orgimage[0].current()->rotate(iangle); + orgimage[0].getFirst()->rotate(iangle); if (!orgimage[1].isEmpty()) - orgimage[1].current()->rotate(iangle); + orgimage[1].getFirst()->rotate(iangle); } updateImageSize(); @@ -232,9 +232,9 @@ void ComicImageView::setImage(ImlibImageList &imglist1, ImlibImageList &imglist2 if (iangle != 0) { if (!orgimage[0].isEmpty()) - orgimage[0].current()->rotate(iangle); + orgimage[0].getFirst()->rotate(iangle); if (!orgimage[1].isEmpty()) - orgimage[1].current()->rotate(iangle); + orgimage[1].getFirst()->rotate(iangle); } updateImageSize(); @@ -320,50 +320,88 @@ void ComicImageView::updateImageSize() { if (orgimage[0].isEmpty()) return; - if (orgimage[0].current()->width() * orgimage[0].current()->height() == 0) - return; Size size = isize; + ImlibImage *img; - // // calculate iw, ih - the size of total image(s) area without scaling; // roatation angle of 2nd image is taken into account - double iw = orgimage[0].current()->width(); - double ih = orgimage[0].current()->height(); + double lw(0), lh(0); + double rw(0), rh(0); + double iw(0), ih(0); + + // We calculate the width and height of the left column of images: + // the width is the maximum width of the components. + for (img = orgimage[0].first(); img != NULL; img = orgimage[0].next()) + { + if (img->width() > lw) + lw = img->width(); + } + if (lw == 0) + return; + + // The height is the sum of all the heights when the items have been + // scaled to have all the same (maximum) width + for (img = orgimage[0].first(); img != NULL; img = orgimage[0].next()) + { + if (img->width() > 0) + lh += img->height()*lw/img->width(); + } + + // Total area is initially the same as the left area + iw = lw; + ih = lh; if (!orgimage[1].isEmpty()) { - if (iangle & 1) + // If we have a second column of images too, first we + // calculate its width and height, as we did for the left side + for (img = orgimage[1].first(); img != NULL; img = orgimage[1].next()) + { + if (img->width() > rw) + rw = img->width(); + } + if (rw != 0) + { + for (img = orgimage[1].first(); img != NULL; img = orgimage[1].next()) + { + if (img->width() > 0) + rh += img->height()*rw/img->width(); + } + + + if (iangle & 1) + { + ih += rh; + if (rw > iw) + iw = rw; + } + else + { + iw += rw; + if (rh > ih) + ih = rh; + } + } + } + + if (size == BestFit) + { + if (iw > ih) { - ih += orgimage[1].current()->height(); - if (orgimage[1].current()->width() > iw) - iw = orgimage[1].current()->width(); + if (iangle&1) + size = FitWidth; + else + size = FitHeight; } else { - iw += orgimage[1].current()->width(); - if (orgimage[1].current()->height() > ih) - ih = orgimage[1].current()->height(); + if (iangle&1) + size = FitHeight; + else + size = FitWidth; } } - - if (size == BestFit) - { - if (iw > ih) - { - if (iangle&1) - size = FitWidth; - else - size = FitHeight; - } - else - { - if (iangle&1) - size = FitHeight; - else - size = FitWidth; - } - } int dw, dh; @@ -437,12 +475,12 @@ void ComicImageView::setRotation(Rotation r) if (!orgimage[i].isEmpty()) { if (r == QComicBook::Right) - orgimage[i].current()->rotate(1); + orgimage[i].getFirst()->rotate(1); else if (r == QComicBook::Left) - orgimage[i].current()->rotate(3); + orgimage[i].getFirst()->rotate(3); else if (r == QComicBook::None && iangle != 0) { - orgimage[i].current()->rotate(4-iangle); + orgimage[i].getFirst()->rotate(4-iangle); iangle = 0; } } @@ -639,7 +677,7 @@ Size ComicImageView::getSize() const int ComicImageView::imageWidth() const { if (!orgimage[0].isEmpty()) - return orgimage[0].current()->width(); + return orgimage[0].getFirst()->width(); return 0; } -- 2.32.0.93.g670b81a890