aboutsummaryrefslogtreecommitdiff
path: root/src/aoimage.cpp
blob: e737ffb3ec4128c3a119e099212b8d3101af2341 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "file_functions.h"

#include "aoimage.h"
#include "options.h"

#include <QBitmap>

AOImage::AOImage(QWidget *parent, AOApplication *p_ao_app, bool make_static) : QLabel(parent)
{
  m_parent = parent;
  ao_app = p_ao_app;
  is_static = make_static;
  if (!is_static) // Only create the QMovie if we're non-static
  {
    movie = new QMovie(this);
    connect(movie, &QMovie::frameChanged, [this]{
      QPixmap f_pixmap = movie->currentPixmap();
      f_pixmap =
          f_pixmap.scaled(this->size(), Qt::IgnoreAspectRatio);
      this->setPixmap(f_pixmap);
      if (masked) {
        this->setMask(f_pixmap.mask());
      }
    });
  }
}

AOImage::~AOImage() {}

bool AOImage::set_image(QString p_image, QString p_misc)
{
  QString p_image_resolved = ao_app->get_image(p_image, Options::getInstance().theme(), Options::getInstance().subTheme(),
                                               ao_app->default_theme, p_misc, "", "",
                                               is_static || !Options::getInstance().animatedThemeEnabled());

  if (!file_exists(p_image_resolved)) {
    qWarning() << "could not find image" << p_image;
    return false;
  }

  path = p_image_resolved;
  if (!is_static) {
    movie->stop();
    movie->setFileName(path);
    if (Options::getInstance().animatedThemeEnabled() && movie->frameCount() > 1) {
      movie->start();
    }
  }
  if (is_static || !Options::getInstance().animatedThemeEnabled() || movie->frameCount() <= 1) {
    QPixmap f_pixmap(path);

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