File indexing completed on 2024-05-19 16:01:22

0001 /*
0002  * This file is part of Calligra
0003  *
0004  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
0005  *
0006  * Contact: Thorsten Zachmann thorsten.zachmann@nokia.com
0007  *
0008  * This library is free software; you can redistribute it and/or
0009  * modify it under the terms of the GNU Lesser General Public License
0010  * version 2.1 as published by the Free Software Foundation.
0011  *
0012  * This library is distributed in the hope that it will be useful, but
0013  * WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library; if not, write to the Free Software
0019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020  * 02110-1301 USA
0021  *
0022  */
0023 
0024 #include "CSThumbProviderStage.h"
0025 
0026 #include <KoPADocument.h>
0027 #include <KoPAPageBase.h>
0028 
0029 #include <QApplication>
0030 #include <QEventLoop>
0031 
0032 CSThumbProviderStage::CSThumbProviderStage(KoPADocument *doc)
0033 : m_doc(doc)
0034 {
0035 }
0036 
0037 CSThumbProviderStage::~CSThumbProviderStage()
0038 {
0039 }
0040 
0041 QVector<QImage> CSThumbProviderStage::createThumbnails(const QSize &thumbSize)
0042 {
0043     // make sure all is rendered before painting
0044     int i = 100;
0045     while (QCoreApplication::hasPendingEvents() && i > 0) {
0046         --i;
0047         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
0048     }
0049 
0050     QVector<QImage> thumbnails;
0051     foreach(KoPAPageBase *page, m_doc->pages(false)) {
0052         thumbnails.append(m_doc->pageThumbImage(page, thumbSize));
0053     }
0054 
0055     // make sure there are no events this fixes a crash on shutdown
0056     i = 100;
0057     while (QCoreApplication::hasPendingEvents() && i > 0) {
0058         --i;
0059         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
0060     }
0061     return thumbnails;
0062 }