aboutsummaryrefslogtreecommitdiff
path: root/src/aoimage.cpp
blob: 3977c9792ca926ddba9b90bbf5035c1d6c5dac73 (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
#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;
}

AOImage::~AOImage() {}

bool AOImage::set_image(QString p_image)
{
  QString theme_image_path =
      ao_app->get_static_image_suffix(ao_app->get_theme_path(p_image));
  QString default_image_path =
      ao_app->get_static_image_suffix(ao_app->get_default_theme_path(p_image));

  QString final_image_path;

  if (file_exists(theme_image_path))
    final_image_path = theme_image_path;
  else if (file_exists(default_image_path))
    final_image_path = default_image_path;
  else {
    qDebug() << "Warning: Image" << p_image << "not found! Can't set!";
    return false;
  }

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

bool AOImage::set_chatbox(QString p_path)
{
  p_path = ao_app->get_static_image_suffix(p_path);
  if (!file_exists(p_path)) {
    qDebug() << "Warning: Chatbox" << p_path << "not found! Can't set!";
    return false;
  }

  QPixmap f_pixmap(p_path);

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