From 1caa737c59e8f17f8e37c7b22b24b8845d7bfe48 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 30 Jun 2007 19:06:55 +0200 Subject: [PATCH] ComicImageView now uses an array of ImlibImageList instead of an array of ImlibImage to hold the images being displayed --- src/imgview.cpp | 86 +++++++++++++++++++++++------------------------- src/imgview.h | 3 +- src/imlibimage.h | 3 ++ 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/imgview.cpp b/src/imgview.cpp index 888e75a..b584bc9 100644 --- a/src/imgview.cpp +++ b/src/imgview.cpp @@ -26,7 +26,6 @@ const int ComicImageView::EXTRA_WHEEL_SPIN = 2; ComicImageView::ComicImageView(QWidget *parent, Size size, const QColor &color): QScrollView(parent), isize(size), iangle(0), xoff(0), yoff(0), lx(-1), wheelupcnt(0), wheeldowncnt(0), smallcursor(NULL) { - orgimage[0] = orgimage[1] = NULL; context_menu = new QPopupMenu(this); viewport()->setPaletteBackgroundColor(color); setFocusPolicy(QWidget::StrongFocus); @@ -34,27 +33,27 @@ ComicImageView::ComicImageView(QWidget *parent, Size size, const QColor &color): ComicImageView::~ComicImageView() { - delete orgimage[0]; - delete orgimage[1]; + orgimage[0].clear(); + orgimage[1].clear(); } void ComicImageView::drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph) { - if (orgimage[0] == NULL) + if (orgimage[0].isEmpty()) return; ImlibImage *image1, *image2; - if (iangle > 1 && orgimage[1]) //switch image pointers to reflect rotation angle + if (iangle > 1 && !orgimage[1].isEmpty()) //switch image pointers to reflect rotation angle { - image1 = orgimage[1]; - image2 = orgimage[0]; + image1 = orgimage[1].current(); + image2 = orgimage[0].current(); } else { - image1 = orgimage[0]; - image2 = orgimage[1]; + image1 = orgimage[0].current(); + image2 = orgimage[1].current(); } int px = clipx - xoff; @@ -151,7 +150,7 @@ bool ComicImageView::onBottom() void ComicImageView::contentsContextMenuEvent(QContextMenuEvent *e) { - if (orgimage[0]) + if (!orgimage[0].isEmpty()) context_menu->popup(e->globalPos()); } @@ -160,13 +159,12 @@ void ComicImageView::setImage(ImlibImage *img, bool preserveangle) if (!preserveangle) iangle = 0; - delete orgimage[0]; - delete orgimage[1]; - orgimage[0] = img; - orgimage[1] = NULL; + orgimage[0].clear(); + orgimage[1].clear(); + orgimage[0].append(img); - if (iangle != 0 && orgimage[0]) - orgimage[0]->rotate(iangle); + if (iangle != 0 && !orgimage[0].isEmpty()) + orgimage[0].current()->rotate(iangle); updateImageSize(); ensureVisible(1, 1); @@ -179,18 +177,18 @@ void ComicImageView::setImage(ImlibImage *img1, ImlibImage *img2, bool preservea if (!preserveangle) iangle = 0; - delete orgimage[0]; - delete orgimage[1]; + orgimage[0].clear(); + orgimage[1].clear(); - orgimage[0] = img1; - orgimage[1] = img2; + orgimage[0].append(img1); + orgimage[1].append(img2); if (iangle != 0) { - if (orgimage[0]) - orgimage[0]->rotate(iangle); - if (orgimage[1]) - orgimage[1]->rotate(iangle); + if (!orgimage[0].isEmpty()) + orgimage[0].current()->rotate(iangle); + if (!orgimage[1].isEmpty()) + orgimage[1].current()->rotate(iangle); } updateImageSize(); @@ -274,9 +272,9 @@ void ComicImageView::contentsMouseDoubleClickEvent(QMouseEvent *e) void ComicImageView::updateImageSize() { - if (orgimage[0] == NULL) + if (orgimage[0].isEmpty()) return; - if (orgimage[0]->width() * orgimage[0]->height() == 0) + if (orgimage[0].current()->width() * orgimage[0].current()->height() == 0) return; Size size = isize; @@ -284,22 +282,22 @@ void ComicImageView::updateImageSize() // // 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]->width(); - double ih = orgimage[0]->height(); + double iw = orgimage[0].current()->width(); + double ih = orgimage[0].current()->height(); - if (orgimage[1]) + if (!orgimage[1].isEmpty()) { if (iangle & 1) { - ih += orgimage[1]->height(); - if (orgimage[1]->width() > iw) - iw = orgimage[1]->width(); + ih += orgimage[1].current()->height(); + if (orgimage[1].current()->width() > iw) + iw = orgimage[1].current()->width(); } else { - iw += orgimage[1]->width(); - if (orgimage[1]->height() > ih) - ih = orgimage[1]->height(); + iw += orgimage[1].current()->width(); + if (orgimage[1].current()->height() > ih) + ih = orgimage[1].current()->height(); } } @@ -390,15 +388,15 @@ void ComicImageView::setRotation(Rotation r) iangle &= 3; for (int i=0; i<2; i++) - if (orgimage[i]) + if (!orgimage[i].isEmpty()) { if (r == QComicBook::Right) - orgimage[i]->rotate(1); + orgimage[i].current()->rotate(1); else if (r == QComicBook::Left) - orgimage[i]->rotate(3); + orgimage[i].current()->rotate(3); else if (r == QComicBook::None && iangle != 0) { - orgimage[i]->rotate(4-iangle); + orgimage[i].current()->rotate(4-iangle); iangle = 0; } } @@ -582,10 +580,8 @@ void ComicImageView::setSmallCursor(bool f) void ComicImageView::clear() { - if (orgimage[0]) - orgimage[0]->reset(); - if (orgimage[1]) - orgimage[1]->reset(); + orgimage[0].clear(); + orgimage[1].clear(); resizeContents(0, 0); } @@ -596,8 +592,8 @@ Size ComicImageView::getSize() const int ComicImageView::imageWidth() const { - if (orgimage[0]) - return orgimage[0]->width(); + if (!orgimage[0].isEmpty()) + return orgimage[0].current()->width(); return 0; } diff --git a/src/imgview.h b/src/imgview.h index 205f5a3..5d9d93d 100644 --- a/src/imgview.h +++ b/src/imgview.h @@ -13,6 +13,7 @@ #ifndef __IMGVIEW_H #define __IMGVIEW_H +#include "imlibimage.h" #include class QPopupMenu; @@ -35,7 +36,7 @@ namespace QComicBook private: QPopupMenu *context_menu; - ImlibImage *orgimage[2]; + ImlibImageList orgimage[2]; Size isize; //Scaling iscaling; int iangle; //rotation angle, 0..3, multipled by 90 diff --git a/src/imlibimage.h b/src/imlibimage.h index 9b56781..0498a14 100644 --- a/src/imlibimage.h +++ b/src/imlibimage.h @@ -16,6 +16,7 @@ /*! \file imlibimage.h */ #include +#include class QPaintDevice; class QString; @@ -53,6 +54,8 @@ namespace QComicBook static void setCacheSize(int bytes); }; + + typedef QPtrList ImlibImageList; }; #endif -- 2.32.0.93.g670b81a890