File indexing completed on 2024-05-12 08:34:05
0001 /******************************************************************************* 0002 * Copyright (C) 2020 by Steve Allewell * 0003 * steve.allewell@gmail.com * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ******************************************************************************/ 0010 0011 0012 #include "Thumbnail.h" 0013 0014 #include <QPainter> 0015 0016 0017 Thumbnail::Thumbnail(Poppler::Page *pdfPage, QListWidget *parent) 0018 : QListWidgetItem(parent, QListWidgetItem::UserType), 0019 m_pdfPage(pdfPage) 0020 { 0021 } 0022 0023 0024 Thumbnail::~Thumbnail() 0025 { 0026 delete m_pdfPage; 0027 } 0028 0029 0030 QImage Thumbnail::image() const 0031 { 0032 return m_image; 0033 } 0034 0035 0036 int Thumbnail::heightForWidth(int width) const 0037 { 0038 QSize pageSize = m_pdfPage->pageSize(); 0039 0040 return (int)((double)width * pageSize.height() / pageSize.width()); 0041 } 0042 0043 0044 void Thumbnail::renderPage() 0045 { 0046 QSize pageSize = m_pdfPage->pageSize(); 0047 QSize iconSize = listWidget()->iconSize(); 0048 0049 double dpi = (double)(iconSize.width()) * 72 / pageSize.width(); 0050 m_image = m_pdfPage->renderToImage(dpi, dpi); 0051 0052 QPainter p(&m_image); 0053 p.setRenderHint(QPainter::Antialiasing, true); 0054 p.drawRect(m_image.rect()); 0055 p.end(); 0056 0057 setImage(m_image); 0058 } 0059 0060 0061 void Thumbnail::setImage(const QImage &image) 0062 { 0063 setIcon(QPixmap::fromImage(image)); 0064 }