aboutsummaryrefslogtreecommitdiff
path: root/src/aoevidencebutton.cpp
blob: 85809654dd952f3ca304bc1c117fcad2b82c6335 (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
103
104
105
106
107
108
109
110
111
#include "aoevidencebutton.h"

#include "file_functions.h"

AOEvidenceButton::AOEvidenceButton(int id, int width, int height, AOApplication *ao_app, QWidget *parent)
    : QPushButton(parent)
    , ao_app(ao_app)
    , m_id(id)
{
  resize(width, height);

  ui_selected = new AOImage(ao_app, this);
  ui_selected->resize(width, height);
  ui_selected->setImage("evidence_selected");
  ui_selected->setAttribute(Qt::WA_TransparentForMouseEvents);
  ui_selected->hide();

  ui_selector = new AOImage(ao_app, this);
  ui_selector->resize(width, height);
  ui_selector->setImage("evidence_selector");
  ui_selector->setAttribute(Qt::WA_TransparentForMouseEvents);
  ui_selector->hide();

  connect(this, &AOEvidenceButton::clicked, this, &AOEvidenceButton::on_clicked);
}

void AOEvidenceButton::setImage(QString fileName)
{
  QString image_path = ao_app->get_real_path(ao_app->get_evidence_path(fileName));
  if (file_exists(fileName))
  {
    setText("");
    setStyleSheet("QPushButton { border-image: url(\"" + fileName +
                  "\") 0 0 0 0 stretch stretch; }"
                  "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }");
  }
  else if (file_exists(image_path))
  {
    setText("");
    setStyleSheet("QPushButton { border-image: url(\"" + image_path +
                  "\") 0 0 0 0 stretch stretch; }"
                  "QToolTip { color: #000000; background-color: #ffffff; border: 0px; }");
  }
  else
  {
    setText(fileName);
    setStyleSheet("QPushButton { border-image: url(); }"
                  "QToolTip { background-image: url(); color: #000000; "
                  "background-color: #ffffff; border: 0px; }");
  }
}

void AOEvidenceButton::setThemeImage(QString fileName)
{
  QString theme_image_path = ao_app->get_real_path(ao_app->get_theme_path(fileName));
  QString default_image_path = ao_app->get_real_path(ao_app->get_theme_path(fileName, ao_app->default_theme));

  QString final_image_path;

  if (file_exists(theme_image_path))
  {
    final_image_path = theme_image_path;
  }
  else
  {
    final_image_path = default_image_path;
  }

  setImage(final_image_path);
}

void AOEvidenceButton::setSelected(bool p_selected)
{
  if (p_selected)
  {
    ui_selected->show();
  }
  else
  {
    ui_selected->hide();
  }
}

void AOEvidenceButton::on_clicked()
{
  Q_EMIT evidenceClicked(m_id);
}

void AOEvidenceButton::mouseDoubleClickEvent(QMouseEvent *e)
{
  QPushButton::mouseDoubleClickEvent(e);
  Q_EMIT evidenceDoubleClicked(m_id);
}

void AOEvidenceButton::enterEvent(QEnterEvent *e)
{
  ui_selector->show();

  Q_EMIT mouseoverUpdated(m_id, true);

  setFlat(false);
  QPushButton::enterEvent(e);
}

void AOEvidenceButton::leaveEvent(QEvent *e)
{
  ui_selector->hide();

  Q_EMIT mouseoverUpdated(m_id, false);
  QPushButton::leaveEvent(e);
}