File indexing completed on 2024-05-12 16:28:26
0001 /* 0002 * This file is part of Calligra 0003 * 0004 * Copyright (C) 2011 Jan Hambrecht <jaham@gmx.net> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public License 0008 * version 2.1 as published by the Free Software Foundation. 0009 * 0010 * This library is distributed in the hope that it will be useful, but 0011 * WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 0018 * 02110-1301 USA 0019 * 0020 */ 0021 0022 #include "CSThumbProviderKarbon.h" 0023 0024 #include <KarbonPart.h> 0025 #include <KarbonDocument.h> 0026 0027 #include <QApplication> 0028 #include <QEventLoop> 0029 #include <QPixmap> 0030 #include <QPainter> 0031 0032 void processEvents() 0033 { 0034 int i = 100; 0035 while (QCoreApplication::hasPendingEvents() && i > 0) { 0036 --i; 0037 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 0038 } 0039 } 0040 0041 CSThumbProviderKarbon::CSThumbProviderKarbon(KarbonDocument *doc) 0042 : m_doc(doc) 0043 { 0044 } 0045 0046 CSThumbProviderKarbon::~CSThumbProviderKarbon() 0047 { 0048 } 0049 0050 QVector<QImage> CSThumbProviderKarbon::createThumbnails(const QSize &thumbSize) 0051 { 0052 // make sure everything is rendered before painting 0053 processEvents(); 0054 0055 QImage thumbnail(thumbSize, QImage::Format_RGB32); 0056 thumbnail.fill(QColor(Qt::white).rgb()); 0057 QPainter thumbPainter(&thumbnail); 0058 m_doc->paintContent(thumbPainter, QRect(QPoint(0, 0), thumbSize)); 0059 0060 // make sure there are no events; this fixes a crash on shutdown 0061 processEvents(); 0062 0063 return QVector<QImage>() << thumbnail; 0064 }