1 /*
2 * This file is part of Converseen, an open-source batch image converter
3 * and resizer.
4 *
5 * (C) Francesco Mondello 2009 - 2021
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * Contact e-mail: Francesco Mondello <faster3ck@gmail.com>
21 *
22 */
23
24 #include <QMovie>
25 #include "mylabelpreviewer.h"
26 #include "formats.h"
27
myLabelPreviewer(QWidget * parent)28 myLabelPreviewer::myLabelPreviewer(QWidget *parent) : QLabel(parent)
29 {
30 thumbGen = new ThumbnailGeneratorThread(this);
31
32 connect(thumbGen, SIGNAL(pixmapGenerated(QImage, int, int, double, double)), this, SLOT(showPreview(QImage, int, int, double, double)));
33 }
34
loadPreview(QString fileName,bool generateThumbnail)35 void myLabelPreviewer::loadPreview(QString fileName, bool generateThumbnail)
36 {
37 m_generateThumbnail = generateThumbnail;
38
39 if (generateThumbnail)
40 showLoadingAnimation();
41
42 thumbGen->setFileName(fileName);
43 thumbGen->setThumbnailGeneration(generateThumbnail);
44 thumbGen->start();
45 }
46
showPreview(QImage thumbnail,int orig_w,int orig_h,double orig_dens_x,double orig_dens_y)47 void myLabelPreviewer::showPreview(QImage thumbnail, int orig_w, int orig_h, double orig_dens_x, double orig_dens_y)
48 {
49 if (thumbnail.isNull() || !m_generateThumbnail) {
50 setText(tr("Preview"));
51 }
52 else {
53 QPixmap pixmap = QPixmap::fromImage(thumbnail);
54 this->setPixmap(pixmap);
55 }
56
57 emit previewReady(orig_w, orig_h, orig_dens_x, orig_dens_y);
58 }
59
showLoadingAnimation()60 void myLabelPreviewer::showLoadingAnimation()
61 {
62 QMovie *movie = new QMovie;
63 movie->setFileName(":/movies/res/loading.gif");
64
65 setMovie(movie);
66 movie->start();
67 }
68