aboutsummaryrefslogtreecommitdiff
path: root/aocharbutton.cpp
blob: 41a4f402ce95071a5286a3a7857620880fddd66e (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
#include "aocharbutton.h"

#include "path_functions.h"
#include "file_functions.h"

#include <QFile>

AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app) : QPushButton(parent)
{
  m_parent = parent;

  ao_app = p_ao_app;

  this->resize(60, 60);
}

void AOCharButton::set_image(QString p_character)
{
  QString image_path = ao_app->get_character_path(p_character) + "char_icon.png";
  QString legacy_path = ao_app->get_demothings_path() + p_character.toLower() + "_char_icon.png";

  if (file_exists(image_path))
    this->setStyleSheet("border-image:url(\"" + image_path + "\")");
  else if (file_exists(legacy_path))
  {
    this->setStyleSheet("border-image:url(\"" + legacy_path + "\")");
    //ninja optimization
    QFile::copy(legacy_path, image_path);
  }
  else
  {
    this->setStyleSheet("border-image:url()");
    this->setText(p_character);
  }
}