aboutsummaryrefslogtreecommitdiff
path: root/src/aoimage.cpp
blob: fbf8c9926518d6102ed014101a6aedea8952eeef (plain)
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
#include "file_functions.h"

#include "aoimage.h"

#include <QBitmap>

AOImage::AOImage(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent)
{
  m_parent = parent;
  ao_app = p_ao_app;
  movie = new QMovie();
  connect(movie, &QMovie::frameChanged, [=]{
    QPixmap f_pixmap = movie->currentPixmap();
    f_pixmap =
        f_pixmap.scaled(this->size(), Qt::IgnoreAspectRatio);
    this->setPixmap(f_pixmap);
    this->setMask(f_pixmap.mask());
  });
}

AOImage::~AOImage() {}

bool AOImage::set_image(QString p_image, QString p_misc)
{
  p_image = ao_app->get_image(p_image, ao_app->current_theme, ao_app->get_subtheme(),
                             ao_app->default_theme, p_misc, "", "", !ao_app->get_animated_theme());

  if (!file_exists(p_image)) {
    qDebug() << "Warning: Image" << p_image << "not found! Can't set!";
    return false;
  }
  path = p_image;
  movie->stop();
  movie->setFileName(path);
  if (ao_app->get_animated_theme() && movie->frameCount() > 1) {
    movie->start();
  }
  else {
    QPixmap f_pixmap(path);

    f_pixmap =
        f_pixmap.scaled(this->size(), Qt::IgnoreAspectRatio);
    this->setPixmap(f_pixmap);
    this->setMask(f_pixmap.mask());
  }
  return true;
}