aboutsummaryrefslogtreecommitdiff
path: root/src/aocharbutton.cpp
blob: fe87041f8d3e72c2c9c893dbb1a204a95578a299 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "aocharbutton.h"

#include "file_functions.h"

AOCharButton::AOCharButton(AOApplication *ao_app, QWidget *parent)
    : QPushButton(parent)
    , ao_app(ao_app)
{
  int size = 60 * Options::getInstance().themeScalingFactor();
  int selector_size = 62 * Options::getInstance().themeScalingFactor();

  resize(size, size);

  ui_passworded = new AOImage(ao_app, this);
  ui_passworded->setAttribute(Qt::WA_TransparentForMouseEvents);
  ui_passworded->resize(size, size);
  ui_passworded->setImage("char_passworded");
  ui_passworded->hide();

  ui_taken = new AOImage(ao_app, this);
  ui_taken->setAttribute(Qt::WA_TransparentForMouseEvents);
  ui_taken->resize(size, size);
  ui_taken->setImage("char_taken");
  ui_taken->hide();

  ui_selector = new AOImage(ao_app, parent);
  ui_selector->setAttribute(Qt::WA_TransparentForMouseEvents);
  ui_selector->resize(selector_size, selector_size);
  ui_selector->setImage("char_selector");
  ui_selector->hide();
}

void AOCharButton::setPassworded(bool enabled)
{
  if (enabled)
  {
    ui_passworded->move(0, 0);
    ui_passworded->show();
  }
  else
  {
    ui_passworded->hide();
  }
}

void AOCharButton::setTaken(bool enabled)
{
  if (enabled)
  {
    ui_taken->move(0, 0);
    ui_taken->show();
  }
  else
  {
    ui_taken->hide();
  }
}

void AOCharButton::setCharacter(QString character)
{
  QString image_path = ao_app->get_image_suffix(ao_app->get_character_path(character, "char_icon"), true);

  setText(QString());

  if (file_exists(image_path))
  {
    setStyleSheet("QPushButton { border-image: url(\"" + image_path +
                  "\") 0 0 0 0 stretch stretch; }"
                  "QToolTip { background-image: url(); color: #000000; "
                  "background-color: #ffffff; border: 0px; }");
  }
  else
  {
    setStyleSheet("QPushButton { border-image: url(); }"
                  "QToolTip { background-image: url(); color: #000000; "
                  "background-color: #ffffff; border: 0px; }");
    setText(character);
  }
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void AOCharButton::enterEvent(QEvent *event)
#else
void AOCharButton::enterEvent(QEnterEvent *event)
#endif
{
  int offset = Options::getInstance().themeScalingFactor();
  ui_selector->move(x() - offset, y() - offset);
  ui_selector->raise();
  ui_selector->show();

  setFlat(false);

  QPushButton::enterEvent(event);
}

void AOCharButton::leaveEvent(QEvent *event)
{
  ui_selector->hide();

  QPushButton::leaveEvent(event);
}