File indexing completed on 2025-01-05 03:51:59
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-11-13 0007 * Description : printer thread. 0008 * 0009 * SPDX-FileCopyrightText: 2008 by Orgad Shaneh <orgads at gmail dot com> 0010 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "calprinter.h" 0017 0018 // Qt includes 0019 0020 #include <QPrinter> 0021 0022 // Local includes 0023 0024 #include "calpainter.h" 0025 0026 namespace DigikamGenericCalendarPlugin 0027 { 0028 0029 class Q_DECL_HIDDEN CalPrinter::Private 0030 { 0031 public: 0032 0033 explicit Private() 0034 : cancelled(false), 0035 printer (nullptr), 0036 painter (nullptr) 0037 { 0038 } 0039 0040 bool cancelled; 0041 0042 QMap<int, QUrl> months; 0043 QPrinter* printer; 0044 0045 CalPainter* painter; 0046 }; 0047 0048 CalPrinter::CalPrinter(QPrinter* const printer, 0049 const QMap<int, QUrl>& months, 0050 QObject* const parent) 0051 : QThread(parent), 0052 d (new Private) 0053 { 0054 d->printer = printer; 0055 d->painter = new CalPainter(d->printer); 0056 d->months = months; 0057 d->cancelled = false; 0058 } 0059 0060 CalPrinter::~CalPrinter() 0061 { 0062 delete d->painter; 0063 delete d; 0064 } 0065 0066 void CalPrinter::run() 0067 { 0068 connect(d->painter, SIGNAL(signalTotal(int)), 0069 this, SIGNAL(totalBlocks(int))); 0070 0071 connect(d->painter, SIGNAL(signalProgress(int)), 0072 this, SIGNAL(blocksFinished(int))); 0073 0074 int currPage = 0; 0075 0076 Q_FOREACH (const int month, d->months.keys()) 0077 { 0078 Q_EMIT pageChanged(currPage); 0079 0080 // cppcheck-suppress knownConditionTrueFalse 0081 if (currPage) 0082 { 0083 d->printer->newPage(); 0084 } 0085 0086 ++currPage; 0087 0088 d->painter->setImage(d->months.value(month)); 0089 d->painter->paint(month); 0090 0091 if (d->cancelled) 0092 { 0093 break; 0094 } 0095 } 0096 0097 d->painter->end(); 0098 0099 Q_EMIT pageChanged(currPage); 0100 } 0101 0102 void CalPrinter::cancel() 0103 { 0104 d->painter->cancel(); 0105 d->cancelled = true; 0106 } 0107 0108 } // namespace Digikam 0109 0110 #include "moc_calprinter.cpp"