-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGifLoader.cpp
More file actions
executable file
·54 lines (39 loc) · 1.31 KB
/
Copy pathGifLoader.cpp
File metadata and controls
executable file
·54 lines (39 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Copyright (c) 2017-2019 by Ilya Barykin
Released under the MIT License.
See the provided LICENSE.TXT file for details.
*/
#include "GifLoader.h"
GifLoader::GifLoader(ImageProvider *p) : prv(p) {
g_mov = new QMovie;
connect(g_mov, &QMovie::frameChanged, this, &GifLoader::nextFrame);
}
void GifLoader::loadImage(QString file) {
prv->getWnd()->resetCoord();
QString text;
g_mov->setFileName(file);
g_mov->start();
text = QString("File: %1 | %2/%3 ");
text = text.arg(file.remove(0, file.lastIndexOf('/') + 1))
.arg(prv->getCurrent() + 1)
.arg(prv->getSize());
prv->setText(text);
}
void GifLoader::stop() {
g_mov->stop();
}
void GifLoader::nextFrame(int i) {
Q_UNUSED(i)
QImage orig = g_mov->currentImage(), simg;
simg = (orig.width() > prv->getWnd()->width() || orig.height() > prv->getWnd()->height()) ?
orig.scaled(prv->getWnd()->size(), Qt::KeepAspectRatio, Qt::FastTransformation) : orig;
int wH = prv->getWnd()->height();
int wW = prv->getWnd()->width();
float s1 = float(wH) / orig.height(), s2 = float(wW) / orig.width(), scale;
scale = qMin(s1, s2);
scale = scale > 1.0f ? 1.0f : scale;
prv->setScale(scale);
prv->setOriginalScale(scale);
prv->setOriginal(orig);
prv->setScaled(simg);
}